'gluster volume defrag' related bug fixes
Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1073 ('gluster defrag <VOLNAME>' fails in mainline) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1073
This commit is contained in:
parent
d257c6ba46
commit
00b1846823
@ -46,24 +46,33 @@ rsync_filename()
|
||||
relocate_file()
|
||||
{
|
||||
path=$1;
|
||||
|
||||
# Make sure we don't 'defrag' valid file.
|
||||
stat_info=$(stat -c '%a' "$path");
|
||||
if [ $stat_info -lt 1000 ] ; then
|
||||
return;
|
||||
fi
|
||||
|
||||
flag=0;
|
||||
linknode=$(getfattr --only-values -n trusted.distribute.linkinfo $path 2>/dev/null);
|
||||
if [ -z $linknode ] ; then
|
||||
return;
|
||||
fi
|
||||
# If there are some entries in added_bricks, then check
|
||||
# if the link file is present on those nodes, if not,
|
||||
# set flag=1, so full defrag happens
|
||||
|
||||
flag=0;
|
||||
for bricks in ${added_bricks}; do
|
||||
linknode=$(getfattr --only-values -n trusted.distribute.linkinfo $path 2>/dev/null);
|
||||
if [ -z $linknode ] ; then
|
||||
return;
|
||||
fi
|
||||
current_brick=${linknode:0:${#bricks}};
|
||||
if [ "${bricks}" == "${current_brick}" ]; then
|
||||
flag=1;
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z ${added_bricks} ] ; then
|
||||
flag=1;
|
||||
fi
|
||||
|
||||
if [ $flag -ne 1 ]; then
|
||||
return;
|
||||
fi
|
||||
|
@ -268,8 +268,6 @@ xdr_gf1_cli_defrag_vol_rsp (XDR *xdrs, gf1_cli_defrag_vol_rsp *objp)
|
||||
return FALSE;
|
||||
if (!xdr_int (xdrs, &objp->op_errno))
|
||||
return FALSE;
|
||||
if (!xdr_string (xdrs, &objp->volname, ~0))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,6 @@ typedef struct gf1_cli_defrag_vol_req gf1_cli_defrag_vol_req;
|
||||
struct gf1_cli_defrag_vol_rsp {
|
||||
int op_ret;
|
||||
int op_errno;
|
||||
char *volname;
|
||||
};
|
||||
typedef struct gf1_cli_defrag_vol_rsp gf1_cli_defrag_vol_rsp;
|
||||
|
||||
|
@ -593,6 +593,55 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
glusterd_handle_defrag_volume (rpcsvc_request_t *req)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
gf1_cli_defrag_vol_req cli_req = {0,};
|
||||
glusterd_conf_t *priv = NULL;
|
||||
char cmd_str[4096] = {0,};
|
||||
|
||||
GF_ASSERT (req);
|
||||
|
||||
priv = THIS->private;
|
||||
if (!gf_xdr_to_cli_defrag_vol_req (req->msg[0], &cli_req)) {
|
||||
//failed to decode msg;
|
||||
req->rpc_err = GARBAGE_ARGS;
|
||||
goto out;
|
||||
}
|
||||
|
||||
gf_log ("glusterd", GF_LOG_NORMAL, "Received defrag volume on %s",
|
||||
cli_req.volname);
|
||||
|
||||
glusterd_op_set_op (GD_OP_DEFRAG_VOLUME);
|
||||
|
||||
glusterd_op_set_ctx (GD_OP_DEFRAG_VOLUME, cli_req.volname);
|
||||
|
||||
/* TODO: make it more generic.. */
|
||||
/* Create a directory, mount glusterfs over it, start glusterfs-defrag */
|
||||
snprintf (cmd_str, 4096, "mkdir -p %s/mount/%s",
|
||||
priv->workdir, cli_req.volname);
|
||||
system (cmd_str);
|
||||
|
||||
snprintf (cmd_str, 4096, "glusterfs -f %s/vols/%s/%s-tcp.vol "
|
||||
"--xlator-option distribute.unhashed-sticky-bit=yes "
|
||||
"--xlator-option distribute.lookup-unhashed=on %s/mount/%s",
|
||||
priv->workdir, cli_req.volname, cli_req.volname,
|
||||
priv->workdir, cli_req.volname);
|
||||
system (cmd_str);
|
||||
|
||||
snprintf (cmd_str, 4096,
|
||||
"$(glusterfs-defrag %s/mount/%s; umount %s/mount/%s) &",
|
||||
priv->workdir, cli_req.volname, priv->workdir, cli_req.volname);
|
||||
system (cmd_str);
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
glusterd_handle_cli_get_volume (rpcsvc_request_t *req)
|
||||
{
|
||||
|
@ -151,6 +151,9 @@ glusterd_handle_cli_probe (rpcsvc_request_t *req);
|
||||
int
|
||||
glusterd_handle_create_volume (rpcsvc_request_t *req);
|
||||
|
||||
int
|
||||
glusterd_handle_defrag_volume (rpcsvc_request_t *req);
|
||||
|
||||
int
|
||||
glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,
|
||||
int32_t op_errno, char *hostname);
|
||||
|
@ -1088,6 +1088,10 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req)
|
||||
ret = glusterd_handle_cli_get_volume (req);
|
||||
break;
|
||||
|
||||
case GD_MGMT_CLI_DEFRAG_VOLUME:
|
||||
ret = glusterd_handle_defrag_volume (req);
|
||||
break;
|
||||
|
||||
default:
|
||||
GF_ASSERT (0);
|
||||
}
|
||||
@ -1112,7 +1116,8 @@ rpcsvc_actor_t glusterd1_mgmt_actors[] = {
|
||||
[GD_MGMT_STAGE_OP] = { "STAGE_OP", GD_MGMT_STAGE_OP, glusterd_handle_rpc_msg, NULL, NULL},
|
||||
[GD_MGMT_COMMIT_OP] = { "COMMIT_OP", GD_MGMT_COMMIT_OP, glusterd_handle_rpc_msg, NULL, NULL},
|
||||
[GD_MGMT_CLI_PROBE] = { "CLI_PROBE", GD_MGMT_CLI_PROBE, glusterd_handle_rpc_msg, NULL, NULL},
|
||||
[GD_MGMT_CLI_CREATE_VOLUME] = { "CLI_CREATE_VOLUME", GD_MGMT_CLI_CREATE_VOLUME, glusterd_handle_rpc_msg, NULL, NULL},
|
||||
[GD_MGMT_CLI_CREATE_VOLUME] = { "CLI_CREATE_VOLUME", GD_MGMT_CLI_CREATE_VOLUME, glusterd_handle_rpc_msg, NULL,NULL},
|
||||
[GD_MGMT_CLI_DEFRAG_VOLUME] = { "CLI_DEFRAG_VOLUME", GD_MGMT_CLI_DEFRAG_VOLUME, glusterd_handle_rpc_msg, NULL,NULL},
|
||||
[GD_MGMT_CLI_DEPROBE] = { "FRIEND_REMOVE", GD_MGMT_CLI_DEPROBE, glusterd_handle_rpc_msg, NULL, NULL},
|
||||
[GD_MGMT_CLI_LIST_FRIENDS] = { "LIST_FRIENDS", GD_MGMT_CLI_LIST_FRIENDS, glusterd_handle_rpc_msg, NULL, NULL},
|
||||
[GD_MGMT_CLI_START_VOLUME] = { "START_VOLUME", GD_MGMT_CLI_START_VOLUME, glusterd_handle_rpc_msg, NULL, NULL},
|
||||
@ -1139,7 +1144,6 @@ struct rpcsvc_program glusterd1_mop_prog = {
|
||||
.progver = GLUSTERD1_MGMT_VERSION,
|
||||
.numactors = GLUSTERD1_MGMT_PROCCNT,
|
||||
.actors = glusterd1_mgmt_actors,
|
||||
.progport = 4284,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user