Skip to content

Commit

Permalink
Auditlog Feature
Browse files Browse the repository at this point in the history
Record the responses of all the requests for the operations
Create/Delete/Modify/Replace on gluster-block.
The logging format is:

In case of success:
[time] INFO: <command string> <function details>
[time] INFO: Response string <function details>

In case of failure:
[time] INFO: <command string> <function details>
[time] ERROR: Response string <function details>

Reviewed-by: Prasanna Kumar Kalever <[email protected]>
Reviewed-by: Xiubo Li <[email protected]>
Signed-off-by: Bhumika Goyal <[email protected]>
  • Loading branch information
bhumikagoyal authored and pkalever committed Sep 25, 2018
1 parent fbb5cc4 commit 8416247
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
31 changes: 31 additions & 0 deletions cli/gluster-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,26 @@ glusterBlockParseVolumeBlock(char *volumeblock, char *volume, char *block,
return ret;
}

void
getCommandString(char **cmd, int argcount, char **options)
{
int total_length = 0;
int i;

for(i = 1; i < argcount; i++){
total_length = total_length + strlen(options[i])+1;
}

if (GB_ALLOC_N(*cmd, (total_length + 1))) {
LOG("cmdlog", GB_LOG_ERROR, "%s", "Could not allocate memory for command string");
return;
}
for (i = 1; i < argcount; i++) {
strcat(*cmd, options[i]);
strcat(*cmd, " ");
}
}

static int
glusterBlockModify(int argcount, char **options, int json)
{
Expand Down Expand Up @@ -397,6 +417,7 @@ glusterBlockModify(int argcount, char **options, int json)
GB_STRCPYSTATIC(mobj.volume, volume);
GB_STRCPYSTATIC(mobj.block_name, block);
mobj.json_resp = json;
getCommandString(&mobj.cmd, argcount, options);

ret = glusterBlockCliRPC_1(&mobj, MODIFY_CLI);
if (ret) {
Expand Down Expand Up @@ -430,6 +451,7 @@ glusterBlockModify(int argcount, char **options, int json)
GB_STRCPYSTATIC(msobj.block_name, block);
msobj.size = sparse_ret; /* size is unsigned long long */
msobj.json_resp = json;
getCommandString(&msobj.cmd, argcount, options);

ret = glusterBlockCliRPC_1(&msobj, MODIFY_SIZE_CLI);
if (ret) {
Expand All @@ -443,6 +465,8 @@ glusterBlockModify(int argcount, char **options, int json)
}

out:
GB_FREE(msobj.cmd);
GB_FREE(mobj.cmd);

return ret;
}
Expand Down Expand Up @@ -585,6 +609,7 @@ glusterBlockCreate(int argcount, char **options, int json)
cobj.size = sparse_ret; /* size is unsigned long long */
}

getCommandString(&cobj.cmd, argcount, options);
ret = glusterBlockCliRPC_1(&cobj, CREATE_CLI);
if (ret) {
LOG("cli", GB_LOG_ERROR,
Expand All @@ -594,6 +619,7 @@ glusterBlockCreate(int argcount, char **options, int json)

out:
GB_FREE(cobj.block_hosts);
GB_FREE(cobj.cmd);

return ret;
}
Expand Down Expand Up @@ -673,13 +699,16 @@ glusterBlockDelete(int argcount, char **options, int json)
goto out;
}

getCommandString(&dobj.cmd, argcount, options);

ret = glusterBlockCliRPC_1(&dobj, DELETE_CLI);
if (ret) {
LOG("cli", GB_LOG_ERROR, "failed deleting block %s on volume %s",
dobj.block_name, dobj.volume);
}

out:
GB_FREE(dobj.cmd);

return ret;
}
Expand Down Expand Up @@ -763,13 +792,15 @@ glusterBlockReplace(int argcount, char **options, int json)
}
}

getCommandString(&robj.cmd, argcount, options);
ret = glusterBlockCliRPC_1(&robj, REPLACE_CLI);
if (ret) {
LOG("cli", GB_LOG_ERROR, "failed replace on volume %s",
robj.volume);
}

out:
GB_FREE(robj.cmd);

return ret;
}
Expand Down
10 changes: 10 additions & 0 deletions rpc/block_svc_routines.c
Original file line number Diff line number Diff line change
Expand Up @@ -2406,6 +2406,7 @@ block_replace_cli_1_svc_st(blockReplaceCli *blk, struct svc_req *rqstp)
}

GB_METALOCK_OR_GOTO(lkfd, blk->volume, errCode, errMsg, optfail);
LOG("cmdlog", GB_LOG_INFO, "%s", blk->cmd);

if (glfs_access(glfs, blk->block_name, F_OK)) {
errCode = errno;
Expand Down Expand Up @@ -2469,6 +2470,7 @@ block_replace_cli_1_svc_st(blockReplaceCli *blk, struct svc_req *rqstp)
out:
GB_METAUNLOCK(lkfd, blk->volume, errCode, errMsg);
blockReplaceNodeCliFormatResponse(blk, errCode, errMsg, savereply, reply);
LOG("cmdlog", errCode?GB_LOG_ERROR:GB_LOG_INFO, "%s", reply->out);
blockServerDefFree(list);
blockRemoteReplaceRespFree(savereply);

Expand Down Expand Up @@ -3186,6 +3188,7 @@ block_modify_cli_1_svc_st(blockModifyCli *blk, struct svc_req *rqstp)
}

GB_METALOCK_OR_GOTO(lkfd, blk->volume, ret, errMsg, nolock);
LOG("cmdlog", GB_LOG_INFO, "%s", blk->cmd);

if (glfs_access(glfs, blk->block_name, F_OK)) {
errCode = errno;
Expand Down Expand Up @@ -3318,6 +3321,7 @@ block_modify_cli_1_svc_st(blockModifyCli *blk, struct svc_req *rqstp)
initfail:
blockModifyCliFormatResponse (blk, &mobj, asyncret?asyncret:errCode,
errMsg, savereply, info, reply, rollback);
LOG("cmdlog", errCode?GB_LOG_ERROR:GB_LOG_INFO, "%s", reply->out);
blockFreeMetaInfo(info);

if (savereply) {
Expand Down Expand Up @@ -3485,6 +3489,7 @@ block_modify_size_cli_1_svc_st(blockModifySizeCli *blk, struct svc_req *rqstp)
}

GB_METALOCK_OR_GOTO(lkfd, blk->volume, ret, errMsg, nolock);
LOG("cmdlog", GB_LOG_INFO, "%s", blk->cmd);

if (glfs_access(glfs, blk->block_name, F_OK)) {
errCode = errno;
Expand Down Expand Up @@ -3589,6 +3594,7 @@ block_modify_size_cli_1_svc_st(blockModifySizeCli *blk, struct svc_req *rqstp)
initfail:
blockModifySizeCliFormatResponse(blk, &mobj, asyncret?asyncret:errCode,
errMsg, savereply, info, reply);
LOG("cmdlog", errCode?GB_LOG_ERROR:GB_LOG_INFO, "%s", reply->out);
blockFreeMetaInfo(info);

blockRemoteRespFree(savereply);
Expand Down Expand Up @@ -3827,6 +3833,7 @@ block_create_cli_1_svc_st(blockCreateCli *blk, struct svc_req *rqstp)
}

GB_METALOCK_OR_GOTO(lkfd, blk->volume, errCode, errMsg, out);
LOG("cmdlog", GB_LOG_INFO, "%s", blk->cmd);

if (!glfs_access(glfs, blk->block_name, F_OK)) {
LOG("mgmt", GB_LOG_ERROR,
Expand Down Expand Up @@ -3923,6 +3930,7 @@ block_create_cli_1_svc_st(blockCreateCli *blk, struct svc_req *rqstp)

optfail:
blockCreateCliFormatResponse(glfs, blk, &cobj, errCode, errMsg, savereply, reply);
LOG("cmdlog", errCode?GB_LOG_ERROR:GB_LOG_INFO, "%s", reply->out);
GB_FREE(errMsg);
blockServerDefFree(list);
blockCreateParsedRespFree(savereply);
Expand Down Expand Up @@ -4516,6 +4524,7 @@ block_delete_cli_1_svc_st(blockDeleteCli *blk, struct svc_req *rqstp)
}

GB_METALOCK_OR_GOTO(lkfd, blk->volume, errCode, errMsg, optfail);
LOG("cmdlog", GB_LOG_INFO, "%s", blk->cmd);

if (glfs_access(glfs, blk->block_name, F_OK)) {
errCode = errno;
Expand Down Expand Up @@ -4581,6 +4590,7 @@ block_delete_cli_1_svc_st(blockDeleteCli *blk, struct svc_req *rqstp)


blockDeleteCliFormatResponse(blk, errCode, errMsg, savereply, reply);
LOG("cmdlog", errCode?GB_LOG_ERROR:GB_LOG_INFO, "%s", reply->out);

if (savereply) {
GB_FREE(savereply->d_attempt);
Expand Down
5 changes: 5 additions & 0 deletions rpc/rpcl/block.x
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct blockCreateCli {
char storage[255];
char block_name[255];
string block_hosts<>;
string cmd<>;
enum JsonResponseFormat json_resp;
};

Expand All @@ -80,6 +81,7 @@ struct blockDeleteCli {
char volume[255];
bool unlink;
bool force;
string cmd<>;
enum JsonResponseFormat json_resp;
};

Expand All @@ -104,6 +106,7 @@ struct blockModifyCli {
char block_name[255];
char volume[255];
bool auth_mode;
string cmd<>;
enum JsonResponseFormat json_resp;
};

Expand All @@ -112,6 +115,7 @@ struct blockModifySizeCli {
char volume[255];
u_quad_t size;
bool force;
string cmd<>;
enum JsonResponseFormat json_resp;
};

Expand All @@ -121,6 +125,7 @@ struct blockReplaceCli {
char old_node[255];
char new_node[255];
bool force;
string cmd<>;
enum JsonResponseFormat json_resp;
};

Expand Down
4 changes: 3 additions & 1 deletion utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# include "config.h"


struct gbConf gbConf = {LRU_COUNT_DEF, GB_LOG_INFO, GB_LOGDIR, '\0', '\0', '\0', '\0'};
struct gbConf gbConf = {LRU_COUNT_DEF, GB_LOG_INFO, GB_LOGDIR, '\0', '\0', '\0', '\0', '\0'};

const char *argp_program_version = "" \
PACKAGE_NAME" ("PACKAGE_VERSION")" \
Expand Down Expand Up @@ -261,6 +261,8 @@ initLogging(void)
"%s/gluster-block-gfapi.log", logDir);
snprintf(gbConf.configShellLogFile, PATH_MAX,
"%s/gluster-block-configshell.log", logDir);
snprintf(gbConf.cmdhistoryLogFile, PATH_MAX,
"%s/cmd_history.log", logDir);

if(!glusterBlockLogdirCreate()) {
return EXIT_FAILURE;
Expand Down
3 changes: 3 additions & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ struct gbConf {
char gfapiLogFile[PATH_MAX];
char configShellLogFile[PATH_MAX];
pthread_mutex_t lock;
char cmdhistoryLogFile[PATH_MAX];
};

extern struct gbConf gbConf;
Expand All @@ -158,6 +159,8 @@ extern struct gbConf gbConf;
fd = fopen (gbConf.cliLogFile, "a"); \
else if (!strcmp(str, "gfapi")) \
fd = fopen (gbConf.gfapiLogFile, "a"); \
else if (!strcmp(str, "cmdlog")) \
fd = fopen (gbConf.cmdhistoryLogFile, "a"); \
else \
fd = stderr; \
if (fd == NULL) { \
Expand Down

0 comments on commit 8416247

Please sign in to comment.