diff options
-rw-r--r-- | extras/glusterfs-defrag.in | 19 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.c | 2 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.h | 1 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 49 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 3 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd3_1-mops.c | 8 |
6 files changed, 72 insertions, 10 deletions
diff --git a/extras/glusterfs-defrag.in b/extras/glusterfs-defrag.in index 982878bdbe9..8bdaf3d8252 100644 --- a/extras/glusterfs-defrag.in +++ b/extras/glusterfs-defrag.in @@ -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 diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c index 832f762ecdb..e5dd310f1dd 100644 --- a/rpc/xdr/src/cli1-xdr.c +++ b/rpc/xdr/src/cli1-xdr.c @@ -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; } diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h index 56dbef091f3..b2060e187d3 100644 --- a/rpc/xdr/src/cli1-xdr.h +++ b/rpc/xdr/src/cli1-xdr.h @@ -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; diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 36dc83f4a51..cd23362a6c9 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -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) { diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index a998ce4492b..1c483920aac 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -152,6 +152,9 @@ 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); diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c index 3ea0f66fadd..2dff9d654c7 100644 --- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c +++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c @@ -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, }; |