diff options
author | Krutika Dhananjay <kdhananj@redhat.com> | 2012-11-09 10:48:29 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-12-11 16:06:08 -0800 |
commit | 179e7333740fe990cac6fc2e63fbace844b17b8d (patch) | |
tree | 556f36b1cf3b2658263c976bf42d3d680fff0e6e /xlators | |
parent | 448b59e60b0ea5e085769283e89893176b86659f (diff) |
glusterd: log appropriate message when locking fails
PROBLEM:
When a transaction is already in progress, and the user tries to
execute another glusterd operation, the second operation fails as
glusterd fails to acquire lock. But to the user, a message like
"Operation failed" does not give ample information about why the
operation failed.
FIX:
Made glusterd_op_txn_begin use and initialise error string, which is
needed to capture failure in the "lock" phase.
Also made gd_sync_task_begin set error string appropriately when
locking fails.
In the process, I had to introduce error string in some glusterd_handle_*
functions. And because I introduced error string in these handlers, I
decided to also set them in places where these handlers could possibly
fail.
HOW I TESTED IT:
For want of a better idea, I "commented out" the call to
"glusterd_unlock", recompiled glusterd and ran two glusterd volume
operations, one after the other. The second operation fails with the
message "Another transaction is in progress. Please try again after
sometime." as expected.
The tests were performed on two volume ops : one of them
synctask'ized (volume start) and the other NOT (volume create).
Change-Id: Ia862972929872ae2f053707a544824d9cadc37be
BUG: 873549
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-on: http://review.gluster.org/4197
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 122 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 33 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 163 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-log-ops.c | 19 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.h | 3 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-quota.c | 25 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rebalance.c | 40 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 34 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-syncop.c | 6 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 128 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 3 |
11 files changed, 379 insertions, 197 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index cdf23ae8b17..1ca52bc5fc4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -367,7 +367,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received add brick req"); + gf_log (this->name, GF_LOG_INFO, "Received add brick req"); if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ @@ -377,11 +377,11 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); snprintf (err_str, sizeof (err_str), "Unable to decode " - "the buffer"); + "the command"); goto out; } } @@ -389,36 +389,37 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get volume name"); snprintf (err_str, sizeof (err_str), "Unable to get volume " "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } if (!(ret = glusterd_check_volume_exists (volname))) { ret = -1; - snprintf(err_str, 2048, "Volume %s does not exist", volname); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); + snprintf (err_str, sizeof (err_str), "Volume %s does not exist", + volname); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_int32 (dict, "count", &brick_count); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get count"); snprintf (err_str, sizeof (err_str), "Unable to get volume " "brick count"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_int32 (dict, "replica-count", &replica_count); if (!ret) { - gf_log (THIS->name, GF_LOG_INFO, "replica-count is %d", + gf_log (this->name, GF_LOG_INFO, "replica-count is %d", replica_count); } ret = dict_get_int32 (dict, "stripe-count", &stripe_count); if (!ret) { - gf_log (THIS->name, GF_LOG_INFO, "stripe-count is %d", + gf_log (this->name, GF_LOG_INFO, "stripe-count is %d", stripe_count); } @@ -427,7 +428,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volinfo " "for volume name %s", volname); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } @@ -443,10 +444,10 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) goto brick_val; if ((brick_count % volinfo->dist_leaf_count) != 0) { - snprintf(err_str, 2048, "Incorrect number of bricks" - " supplied %d with count %d", + snprintf (err_str, sizeof (err_str), "Incorrect number " + "of bricks supplied %d with count %d", brick_count, volinfo->dist_leaf_count); - gf_log("glusterd", GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); ret = -1; goto out; } @@ -462,7 +463,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) err_str, sizeof (err_str)); if (ret == -1) { - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } @@ -472,7 +473,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) ret = dict_set_int32 (dict, "stripe-count", stripe_count); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to set the stripe-count in dict"); goto out; } @@ -484,7 +485,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) &type, err_str, sizeof (err_str)); if (ret == -1) { - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } @@ -494,7 +495,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) ret = dict_set_int32 (dict, "replica-count", replica_count); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to set the replica-count in dict"); goto out; } @@ -504,14 +505,14 @@ brick_val: if (ret) { snprintf (err_str, sizeof (err_str), "Unable to get volume " "bricks"); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } if (type != volinfo->type) { ret = dict_set_int32 (dict, "type", type); if (ret) - gf_log (THIS->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to set the new type in dict"); } @@ -566,19 +567,22 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) int found = 0; int diff_count = 0; char *volname = 0; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; + snprintf (err_str, sizeof (err_str), "Received garbage args"); goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received rem brick req"); + gf_log (this->name, GF_LOG_INFO, "Received rem brick req"); if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ @@ -588,36 +592,42 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); goto out; } } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "Unable to get volname"); + snprintf (err_str, sizeof (err_str), "Unable to get volume " + "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_int32 (dict, "count", &count); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get count"); + snprintf (err_str, sizeof (err_str), "Unable to get brick " + "count"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { - snprintf (err_str, 2048, "Volume %s does not exist", - volname); - gf_log ("", GF_LOG_ERROR, "%s", err_str); + snprintf (err_str, sizeof (err_str),"Volume %s does not exist", + volname); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_int32 (dict, "replica-count", &replica_count); if (!ret) { - gf_log (THIS->name, GF_LOG_INFO, + gf_log (this->name, GF_LOG_INFO, "request to change replica-count to %d", replica_count); ret = gd_rmbr_validate_replica_count (volinfo, replica_count, count, err_str, @@ -634,7 +644,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) ret = dict_set_int32 (dict, "replica-count", replica_count); if (ret) { - gf_log (THIS->name, GF_LOG_WARNING, + gf_log (this->name, GF_LOG_WARNING, "failed to set the replica_count " "in dict"); goto out; @@ -656,9 +666,9 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) /* Do not allow remove-brick if the volume is plain stripe */ if ((volinfo->type == GF_CLUSTER_TYPE_STRIPE) && (volinfo->brick_count == volinfo->stripe_count)) { - snprintf (err_str, 2048, + snprintf (err_str, sizeof (err_str), "Removing brick from a plain stripe is not allowed"); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); ret = -1; goto out; } @@ -666,11 +676,11 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) if (!replica_count && (volinfo->type == GF_CLUSTER_TYPE_STRIPE_REPLICATE) && (volinfo->brick_count == volinfo->dist_leaf_count)) { - snprintf (err_str, 2048, + snprintf (err_str, sizeof(err_str), "Removing bricks from stripe-replicate" " configuration is not allowed without reducing " "replica or stripe count explicitly."); - gf_log (THIS->name, GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); ret = -1; goto out; } @@ -678,11 +688,11 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) if (!replica_count && (volinfo->type == GF_CLUSTER_TYPE_REPLICATE) && (volinfo->brick_count == volinfo->dist_leaf_count)) { - snprintf (err_str, 2048, + snprintf (err_str, sizeof (err_str), "Removing bricks from replicate configuration " "is not allowed without reducing replica count " "explicitly."); - gf_log (THIS->name, GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); ret = -1; goto out; } @@ -692,10 +702,10 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) if (!replica_count && (volinfo->type != GF_CLUSTER_TYPE_NONE)) { if (volinfo->dist_leaf_count && (count % volinfo->dist_leaf_count)) { - snprintf (err_str, 2048, "Remove brick incorrect" - " brick count of %d for %s %d", + snprintf (err_str, sizeof (err_str), "Remove brick " + "incorrect brick count of %d for %s %d", count, vol_type, volinfo->dist_leaf_count); - gf_log ("", GF_LOG_ERROR, "%s", err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); ret = -1; goto out; } @@ -710,21 +720,23 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) strcpy (brick_list, " "); while ( i <= count) { - snprintf (key, 256, "brick%d", i); + snprintf (key, sizeof (key), "brick%d", i); ret = dict_get_str (dict, key, &brick); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get %s", key); + snprintf (err_str, sizeof (err_str), "Unable to get %s", + key); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - gf_log ("", GF_LOG_DEBUG, "Remove brick count %d brick: %s", - i, brick); + gf_log (this->name, GF_LOG_DEBUG, "Remove brick count %d brick:" + " %s", i, brick); ret = glusterd_volume_brickinfo_get_by_brick(brick, volinfo, &brickinfo); if (ret) { - snprintf(err_str, 2048,"Incorrect brick %s for volume" - " %s", brick, volname); - gf_log ("", GF_LOG_ERROR, "%s", err_str); + snprintf (err_str, sizeof (err_str), "Incorrect brick " + "%s for volume %s", brick, volname); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } strcat(brick_list, brick); @@ -745,7 +757,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) found = 0; list_for_each_entry (tmp, &volinfo->bricks, brick_list) { tmp_brick_idx++; - gf_log (THIS->name, GF_LOG_TRACE, + gf_log (this->name, GF_LOG_TRACE, "validate brick %s:%s (%d %d %d)", tmp->hostname, tmp->path, tmp_brick_idx, brick_index, volinfo->replica_count); @@ -763,8 +775,9 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) if (found) continue; - snprintf(err_str, 2048,"Bricks are from same subvol"); - gf_log (THIS->name, GF_LOG_INFO, + snprintf (err_str, sizeof (err_str), "Bricks are from " + "same subvol"); + gf_log (this->name, GF_LOG_INFO, "failed to validate brick %s:%s (%d %d %d)", tmp->hostname, tmp->path, tmp_brick_idx, brick_index, volinfo->replica_count); @@ -782,7 +795,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) continue; } - gf_log ("", GF_LOG_INFO, "Found brick"); + gf_log (this->name, GF_LOG_INFO, "Found brick"); if (!sub_volume && (volinfo->dist_leaf_count > 1)) { sub_volume = (pos / volinfo->dist_leaf_count) + 1; sub_volume_start = (volinfo->dist_leaf_count * @@ -793,10 +806,10 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) if (pos < sub_volume_start || pos >sub_volume_end) { ret = -1; - snprintf(err_str, 2048,"Bricks not from" - " same subvol for %s", - vol_type); - gf_log ("", GF_LOG_ERROR, + snprintf (err_str, sizeof (err_str), + "Bricks not from same subvol " + "for %s", vol_type); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } @@ -812,8 +825,9 @@ out: rsp.op_ret = -1; rsp.op_errno = 0; if (err_str[0] == '\0') - snprintf (err_str, sizeof (err_str), "Operation failed"); - gf_log ("", GF_LOG_ERROR, "%s", err_str); + snprintf (err_str, sizeof (err_str), + "Operation failed"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); rsp.op_errstr = err_str; cli_rsp = &rsp; glusterd_to_cli (req, cli_rsp, NULL, 0, NULL, diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index 20c697aa4a2..eeb8e940db8 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -48,12 +48,15 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req) int type = 0; glusterd_conf_t *priv = NULL; char *host_uuid = NULL; + char err_str[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); GF_ASSERT (THIS); GF_ASSERT (THIS->private); - priv = THIS->private; + this = THIS; + priv = this->private; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); @@ -71,8 +74,10 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to " + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -80,8 +85,8 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req) host_uuid = gf_strdup (uuid_utoa(MY_UUID)); if (host_uuid == NULL) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to get" - "the uuid of the host machine"); + snprintf (err_str, sizeof (err_str), "Failed to get " + "the uuid of local glusterd"); ret = -1; goto out; } @@ -93,22 +98,23 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req) ret = dict_get_str (dict, "master", &master); if (ret < 0) { - gf_log ("", GF_LOG_INFO, "master not found, while handling" - GEOREP" options"); + gf_log (this->name, GF_LOG_INFO, "master not found, while " + "handling"GEOREP" options"); master = "(No Master)"; } ret = dict_get_str (dict, "slave", &slave); if (ret < 0) { - gf_log ("", GF_LOG_INFO, "slave not not found, while" + gf_log (this->name, GF_LOG_INFO, "slave not not found, while" "handling "GEOREP" options"); slave = "(No Slave)"; } ret = dict_get_int32 (dict, "type", &type); if (ret < 0) { - gf_log ("", GF_LOG_WARNING, "command type not found, while" - "handling "GEOREP" options"); + snprintf (err_str, sizeof (err_str), "Command type not found " + "while handling "GEOREP" options"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } @@ -134,15 +140,20 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req) break; } - ret = glusterd_op_begin (req, GD_OP_GSYNC_SET, dict); + ret = glusterd_op_begin (req, GD_OP_GSYNC_SET, dict, + err_str, sizeof (err_str)); out: glusterd_friend_sm (); glusterd_op_sm (); + if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); if (dict) dict_unref (dict); } diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index ff8fe32255e..ff2c8e71c1e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -445,7 +445,8 @@ out: } int32_t -glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx) +glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx, + char *err_str, size_t err_len) { int32_t ret = -1; xlator_t *this = NULL; @@ -464,6 +465,8 @@ glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx) if (ret) { gf_log (this->name, GF_LOG_ERROR, "Unable to acquire local lock, ret: %d", ret); + snprintf (err_str, err_len, "Another transaction is in progress. " + "Please try again after sometime."); goto out; } @@ -951,7 +954,7 @@ glusterd_handle_cli_bd_op (rpcsvc_request_t *req) gf_cli_req cli_req = { {0,} }; dict_t *dict = NULL; char *volname = NULL; - char *op_errstr = NULL; + char op_errstr[2048] = {0,}; glusterd_op_t cli_op = GD_OP_BD_OP; GF_ASSERT (req); @@ -989,7 +992,8 @@ glusterd_handle_cli_bd_op (rpcsvc_request_t *req) goto out; } - ret = glusterd_op_begin (req, GD_OP_BD_OP, dict); + ret = glusterd_op_begin (req, GD_OP_BD_OP, dict, op_errstr, + sizeof (op_errstr)); gf_cmd_log ("bd op: %s", ((ret == 0) ? "SUCCESS": "FAILED")); out: if (ret && dict) @@ -999,11 +1003,11 @@ out: glusterd_op_sm (); if (ret) { - if (!op_errstr) - op_errstr = gf_strdup ("operation failed"); + if (op_errstr[0] == '\0') + snprintf (op_errstr, sizeof (op_errstr), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, op_errstr); - GF_FREE (op_errstr); } return ret; @@ -1171,11 +1175,12 @@ out: } int32_t -glusterd_op_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx) +glusterd_op_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx, + char *err_str, size_t err_len) { int ret = -1; - ret = glusterd_op_txn_begin (req, op, ctx); + ret = glusterd_op_txn_begin (req, op, ctx, err_str, err_len); return ret; } @@ -1188,8 +1193,11 @@ glusterd_handle_reset_volume (rpcsvc_request_t *req) dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_RESET_VOLUME; char *volname = NULL; + char err_str[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -1206,8 +1214,10 @@ glusterd_handle_reset_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to " + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -1216,18 +1226,24 @@ glusterd_handle_reset_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); + snprintf (err_str, sizeof (err_str), "Failed to get volume " + "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - ret = glusterd_op_begin (req, GD_OP_RESET_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_RESET_VOLUME, dict, + err_str, sizeof (err_str)); out: glusterd_friend_sm (); glusterd_op_sm (); if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); if (dict) dict_unref (dict); } @@ -1248,6 +1264,8 @@ glusterd_handle_set_volume (rpcsvc_request_t *req) char *volname = NULL; char *op_errstr = NULL; gf_boolean_t help = _gf_false; + char err_str[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); @@ -1266,9 +1284,11 @@ glusterd_handle_set_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -1277,8 +1297,9 @@ glusterd_handle_set_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get volume name, while" - "handling volume set command"); + snprintf (err_str, sizeof (err_str), "Failed to get volume " + "name while handling volume set command"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } @@ -1291,19 +1312,22 @@ glusterd_handle_set_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "key1", &key); if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get key, while " - "handling volume set for %s",volname); + snprintf (err_str, sizeof (err_str), "Failed to get key while" + " handling volume set for %s", volname); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_str (dict, "value1", &value); if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get value, while" - "handling volume set for %s",volname); + snprintf (err_str, sizeof (err_str), "Failed to get value while" + " handling volume set for %s", volname); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - ret = glusterd_op_begin (req, GD_OP_SET_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_SET_VOLUME, dict, + err_str, sizeof (err_str)); out: glusterd_friend_sm (); @@ -1312,9 +1336,13 @@ out: if (help) ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, dict, (op_errstr)? op_errstr:""); - else if (ret) + else if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); + } if (op_errstr) GF_FREE (op_errstr); @@ -1332,8 +1360,10 @@ glusterd_handle_sync_volume (rpcsvc_request_t *req) char *volname = NULL; gf1_cli_sync_volume flags = 0; char *hostname = NULL; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -1350,9 +1380,11 @@ glusterd_handle_sync_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (msg, sizeof (msg), "Unable to decode the " + "command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -1361,7 +1393,8 @@ glusterd_handle_sync_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "hostname", &hostname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get hostname"); + snprintf (msg, sizeof (msg), "Failed to get hostname"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } @@ -1369,24 +1402,26 @@ glusterd_handle_sync_volume (rpcsvc_request_t *req) if (ret) { ret = dict_get_int32 (dict, "flags", (int32_t*)&flags); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "Unable to get volume" - "name, or flags"); + snprintf (msg, sizeof (msg), "Failed to get volume name" + " or flags"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } } - gf_log ("glusterd", GF_LOG_INFO, "Received volume sync req " - "for volume %s", - (flags & GF_CLI_SYNC_ALL) ? "all" : volname); + gf_log (this->name, GF_LOG_INFO, "Received volume sync req " + "for volume %s", (flags & GF_CLI_SYNC_ALL) ? "all" : volname); if (!glusterd_is_local_addr (hostname)) { ret = -1; snprintf (msg, sizeof (msg), "sync from localhost" " not allowed"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } - ret = glusterd_op_begin (req, GD_OP_SYNC_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_SYNC_VOLUME, dict, + msg, sizeof (msg)); out: if (ret) { @@ -2017,8 +2052,11 @@ glusterd_handle_cli_profile_volume (rpcsvc_request_t *req) glusterd_op_t cli_op = GD_OP_PROFILE_VOLUME; char *volname = NULL; int32_t op = 0; + char err_str[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -2037,19 +2075,22 @@ glusterd_handle_cli_profile_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); + snprintf (err_str, sizeof (err_str), "Unable to get volume " + "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - gf_log (THIS->name, GF_LOG_INFO, "Received volume profile req " + gf_log (this->name, GF_LOG_INFO, "Received volume profile req " "for volume %s", volname); ret = dict_get_int32 (dict, "op", &op); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get op"); + snprintf (err_str, sizeof (err_str), "Unable to get operation"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - ret = glusterd_op_begin (req, cli_op, dict); + ret = glusterd_op_begin (req, cli_op, dict, err_str, sizeof (err_str)); out: glusterd_friend_sm (); @@ -2057,13 +2098,16 @@ out: free (cli_req.dict.dict_val); if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); if (dict) dict_unref (dict); } - gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret); + gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); return ret; } @@ -2845,8 +2889,11 @@ glusterd_handle_status_volume (rpcsvc_request_t *req) char *volname = 0; gf_cli_req cli_req = {{0,}}; glusterd_op_t cli_op = GD_OP_STATUS_VOLUME; + char err_str[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -2862,8 +2909,10 @@ glusterd_handle_status_volume (rpcsvc_request_t *req) ret = dict_unserialize (cli_req.dict.dict_val, cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to " + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize buffer"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); goto out; } @@ -2876,25 +2925,29 @@ glusterd_handle_status_volume (rpcsvc_request_t *req) if (!(cmd & GF_CLI_STATUS_ALL)) { ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "failed to get volname"); + snprintf (err_str, sizeof (err_str), "Unable to get " + "volume name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - gf_log (THIS->name, GF_LOG_INFO, - "Received status volume req " - "for volume %s", volname); + gf_log (this->name, GF_LOG_INFO, + "Received status volume req for volume %s", volname); } - ret = glusterd_op_begin (req, GD_OP_STATUS_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_STATUS_VOLUME, dict, + err_str, sizeof (err_str)); out: glusterd_friend_sm (); glusterd_op_sm (); if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); if (dict) dict_unref (dict); } @@ -2911,8 +2964,11 @@ glusterd_handle_cli_clearlocks_volume (rpcsvc_request_t *req) glusterd_op_t cli_op = GD_OP_CLEARLOCKS_VOLUME; char *volname = NULL; dict_t *dict = NULL; + char err_str[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = -1; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); @@ -2928,36 +2984,43 @@ glusterd_handle_cli_clearlocks_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log (THIS->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to unserialize req-buffer to" " dictionary"); + snprintf (err_str, sizeof (err_str), "unable to decode " + "the command"); goto out; } } else { ret = -1; - gf_log (THIS->name, GF_LOG_ERROR, "Empty cli request."); + gf_log (this->name, GF_LOG_ERROR, "Empty cli request."); goto out; } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); + snprintf (err_str, sizeof (err_str), "Unable to get volume " + "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - gf_log (THIS->name, GF_LOG_INFO, "Received clear-locks volume req " + gf_log (this->name, GF_LOG_INFO, "Received clear-locks volume req " "for volume %s", volname); - ret = glusterd_op_begin (req, cli_op, dict); + ret = glusterd_op_begin (req, cli_op, dict, err_str, sizeof (err_str)); out: glusterd_friend_sm (); glusterd_op_sm (); if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); if (dict) dict_unref (dict); } diff --git a/xlators/mgmt/glusterd/src/glusterd-log-ops.c b/xlators/mgmt/glusterd/src/glusterd-log-ops.c index eba28d42c86..d4367a69a15 100644 --- a/xlators/mgmt/glusterd/src/glusterd-log-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-log-ops.c @@ -31,8 +31,11 @@ glusterd_handle_log_rotate (rpcsvc_request_t *req) dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_LOG_ROTATE; char *volname = NULL; + char msg[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -49,35 +52,41 @@ glusterd_handle_log_rotate (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (msg, sizeof (msg), "Unable to decode the " + "command"); goto out; } } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); + snprintf (msg, sizeof (msg), "Failed to get volume name"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received log rotate req " + gf_log (this->name, GF_LOG_INFO, "Received log rotate req " "for volume %s", volname); ret = dict_set_uint64 (dict, "rotate-key", (uint64_t)time (NULL)); if (ret) goto out; - ret = glusterd_op_begin (req, GD_OP_LOG_ROTATE, dict); + ret = glusterd_op_begin (req, GD_OP_LOG_ROTATE, dict, + msg, sizeof (msg)); out: glusterd_friend_sm (); glusterd_op_sm (); if (ret) { + if (msg[0] == '\0') + snprintf (msg, sizeof (msg), "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, msg); if (dict) dict_unref (dict); } diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 610b6471a08..4d89dcea21c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -193,7 +193,8 @@ glusterd_op_commit_perform (glusterd_op_t op, dict_t *req, char **op_errstr, dict_t* dict); int32_t -glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx); +glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx, + char *err_str, size_t err_len); int32_t glusterd_op_txn_complete (); diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index d2387b21298..7b793f6f051 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -34,8 +34,11 @@ glusterd_handle_quota (rpcsvc_request_t *req) char operation[256] = {0, }; char *volname = NULL; int32_t type = 0; + char msg[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -52,8 +55,10 @@ glusterd_handle_quota (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to " + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (msg, sizeof (msg), "Unable to decode the " + "command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -62,16 +67,18 @@ glusterd_handle_quota (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get volume name, while" - "handling quota command"); + snprintf (msg, sizeof (msg), "Unable to get volume name"); + gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name, " + "while handling quota command"); goto out; } ret = dict_get_int32 (dict, "type", &type); if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get type of cmd. , while" - "handling quota command"); - goto out; + snprintf (msg, sizeof (msg), "Unable to get type of command"); + gf_log (this->name, GF_LOG_ERROR, "Unable to get type of cmd, " + "while handling quota command"); + goto out; } switch (type) { @@ -91,15 +98,17 @@ glusterd_handle_quota (rpcsvc_request_t *req) strncpy (operation, "remove", sizeof (operation)); break; } - ret = glusterd_op_begin (req, GD_OP_QUOTA, dict); + ret = glusterd_op_begin (req, GD_OP_QUOTA, dict, msg, sizeof (msg)); out: glusterd_friend_sm (); glusterd_op_sm (); if (ret) { + if (msg[0] == '\0') + snprintf (msg, sizeof (msg), "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, msg); if (dict) dict_unref (dict); } diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c index d942baa5502..3698b82cff0 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c +++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c @@ -371,16 +371,19 @@ out: int glusterd_handle_defrag_volume (rpcsvc_request_t *req) { - int32_t ret = -1; - gf_cli_req cli_req = {{0,}}; - glusterd_conf_t *priv = NULL; - dict_t *dict = NULL; - char *volname = NULL; - gf_cli_defrag_type cmd = 0; + int32_t ret = -1; + gf_cli_req cli_req = {{0,}}; + glusterd_conf_t *priv = NULL; + dict_t *dict = NULL; + char *volname = NULL; + gf_cli_defrag_type cmd = 0; + char msg[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; - priv = THIS->private; + priv = this->private; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -396,24 +399,26 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (msg, sizeof (msg), "Unable to decode the " + "command"); goto out; } } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "Failed to get volname"); + snprintf (msg, sizeof (msg), "Failed to get volume name"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } ret = dict_get_int32 (dict, "rebalance-command", (int32_t*)&cmd); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "Failed to get command"); + snprintf (msg, sizeof (msg), "Failed to get command"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } @@ -424,9 +429,10 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req) if ((cmd == GF_DEFRAG_CMD_STATUS) || (cmd == GF_DEFRAG_CMD_STOP)) { ret = glusterd_op_begin (req, GD_OP_DEFRAG_BRICK_VOLUME, - dict); + dict, msg, sizeof (msg)); } else - ret = glusterd_op_begin (req, GD_OP_REBALANCE, dict); + ret = glusterd_op_begin (req, GD_OP_REBALANCE, dict, + msg, sizeof (msg)); out: @@ -434,8 +440,10 @@ out: glusterd_op_sm (); if (ret) { - ret = glusterd_op_send_cli_response (GD_OP_REBALANCE, ret, 0, req, - dict, "operation failed"); + if (msg[0] == '\0') + snprintf (msg, sizeof (msg), "Operation failed"); + ret = glusterd_op_send_cli_response (GD_OP_REBALANCE, ret, 0, + req, dict, msg); if (dict) dict_unref (dict); } diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c index fbbf46ff3a7..73e94781717 100644 --- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c @@ -80,8 +80,11 @@ glusterd_handle_replace_brick (rpcsvc_request_t *req) char operation[256]; glusterd_op_t cli_op = GD_OP_REPLACE_BRICK; char *volname = NULL; + char msg[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { @@ -90,7 +93,7 @@ glusterd_handle_replace_brick (rpcsvc_request_t *req) goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received replace brick req"); + gf_log (this->name, GF_LOG_INFO, "Received replace brick req"); if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ @@ -100,48 +103,55 @@ glusterd_handle_replace_brick (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (msg, sizeof (msg), "Unable to decode the " + "command"); goto out; } } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "could not get volname"); + snprintf (msg, sizeof (msg), "Could not get volume name"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } ret = dict_get_int32 (dict, "operation", &op); if (ret) { - gf_log ("", GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_DEBUG, "dict_get on operation failed"); + snprintf (msg, sizeof (msg), "Could not get operation"); goto out; } ret = dict_get_str (dict, "src-brick", &src_brick); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get src brick"); + snprintf (msg, sizeof (msg), "Failed to get src brick"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } - gf_log ("", GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_DEBUG, "src brick=%s", src_brick); ret = dict_get_str (dict, "dst-brick", &dst_brick); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get dest brick"); + snprintf (msg, sizeof (msg), "Failed to get dest brick"); + gf_log (this->name, GF_LOG_ERROR, "%s", msg); goto out; } (void) glusterd_get_replace_op_str (op, operation); - gf_log ("", GF_LOG_DEBUG, "dst brick=%s", dst_brick); - gf_log ("glusterd", GF_LOG_INFO, "Received replace brick %s request", + gf_log (this->name, GF_LOG_DEBUG, "dst brick=%s", dst_brick); + gf_log (this->name, GF_LOG_INFO, "Received replace brick %s request", operation); - ret = glusterd_op_begin (req, GD_OP_REPLACE_BRICK, dict); + ret = glusterd_op_begin (req, GD_OP_REPLACE_BRICK, dict, + msg, sizeof (msg)); out: free (cli_req.dict.dict_val);//malloced by xdr @@ -150,8 +160,10 @@ out: glusterd_op_sm (); if (ret) { + if (msg[0] == '\0') + snprintf (msg, sizeof (msg), "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, msg); if (dict) dict_unref (dict); } diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c index 89c26418315..80d6f33f067 100644 --- a/xlators/mgmt/glusterd/src/glusterd-syncop.c +++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c @@ -500,8 +500,12 @@ gd_sync_task_begin (dict_t *op_ctx, rpcsvc_request_t * req) /* Lock everything */ ret = glusterd_lock (MY_UUID); - if (ret) + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "Unable to acquire lock"); + gf_asprintf (&op_errstr, "Another transaction is in progress. " + "Please try again after sometime."); goto out; + } /* successful lock in local node */ local_locked = _gf_true; diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index e13f705d4d4..4b6fdc2197a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -73,7 +73,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received create volume req"); + gf_log (this->name, GF_LOG_INFO, "Received create volume req"); if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ @@ -83,11 +83,11 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); snprintf (err_str, sizeof (err_str), "Unable to decode " - "the buffer"); + "the command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -97,46 +97,47 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get volume name"); snprintf (err_str, sizeof (err_str), "Unable to get volume " "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } if ((ret = glusterd_check_volume_exists (volname))) { - snprintf(err_str, 2048, "Volume %s already exists", volname); - gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str); + snprintf (err_str, sizeof (err_str), "Volume %s already exists", + volname); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_int32 (dict, "count", &brick_count); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get count"); snprintf (err_str, sizeof (err_str), "Unable to get volume " "brick count"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_int32 (dict, "type", &type); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get type"); snprintf (err_str, sizeof (err_str), "Unable to get volume " "type"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_str (dict, "transport", &trans_type); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get transport-type"); snprintf (err_str, sizeof (err_str), "Unable to get volume " "transport-type"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_str (dict, "bricks", &bricks); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get bricks"); snprintf (err_str, sizeof (err_str), "Unable to get volume " "bricks"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } @@ -144,9 +145,9 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) free_ptr = gf_strdup (uuid_utoa (volume_id)); ret = dict_set_dynstr (dict, "volume-id", free_ptr); if (ret) { - gf_log ("", GF_LOG_ERROR, "unable to set volume-id"); snprintf (err_str, sizeof (err_str), "Unable to set volume " "id"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } free_ptr = NULL; @@ -190,14 +191,16 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) if (ret) goto out; - ret = glusterd_op_begin (req, GD_OP_CREATE_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_CREATE_VOLUME, dict, err_str, + sizeof (err_str)); out: if (ret) { rsp.op_ret = -1; rsp.op_errno = 0; if (err_str[0] == '\0') - snprintf (err_str, sizeof (err_str), "Operation failed"); + snprintf (err_str, sizeof (err_str), + "Operation failed"); rsp.op_errstr = err_str; cli_rsp = &rsp; glusterd_to_cli (req, cli_rsp, NULL, 0, NULL, @@ -228,6 +231,7 @@ glusterd_handle_cli_start_volume (rpcsvc_request_t *req) char *volname = NULL; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_START_VOLUME; + char errstr[2048] = {0,}; xlator_t *this = NULL; this = THIS; @@ -237,6 +241,7 @@ glusterd_handle_cli_start_volume (rpcsvc_request_t *req) if (ret < 0) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; + snprintf (errstr, sizeof (errstr), "Received garbage args"); goto out; } @@ -248,16 +253,19 @@ glusterd_handle_cli_start_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log (THIS->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (errstr, sizeof (errstr), "Unable to decode " + "the command"); goto out; } } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (this->name, GF_LOG_ERROR, "dict get failed"); + snprintf (errstr, sizeof (errstr), "Unable to get volume name"); + gf_log (this->name, GF_LOG_ERROR, "%s", errstr); goto out; } @@ -270,8 +278,10 @@ out: free (cli_req.dict.dict_val); //its malloced by xdr if (ret) { + if(errstr[0] == '\0') + snprintf (errstr, sizeof (errstr), "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, errstr); if (dict) dict_unref (dict); } @@ -289,6 +299,7 @@ glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_STOP_VOLUME; xlator_t *this = NULL; + char err_str[2048] = {0,}; this = THIS; GF_ASSERT (req); @@ -310,6 +321,8 @@ glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); goto out; } } @@ -317,14 +330,17 @@ glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &dup_volname); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get volume name"); + snprintf (err_str, sizeof (err_str), "Failed to get volume " + "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } gf_log (this->name, GF_LOG_INFO, "Received stop vol req " "for volume %s", dup_volname); - ret = glusterd_op_begin (req, GD_OP_STOP_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_STOP_VOLUME, dict, + err_str, sizeof (err_str)); out: free (cli_req.dict.dict_val); //its malloced by xdr @@ -333,8 +349,11 @@ out: glusterd_op_sm (); if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); if (dict) dict_unref (dict); } @@ -350,6 +369,10 @@ glusterd_handle_cli_delete_volume (rpcsvc_request_t *req) glusterd_op_t cli_op = GD_OP_DELETE_VOLUME; dict_t *dict = NULL; char *volname = NULL; + char err_str[2048]= {0,}; + xlator_t *this = NULL; + + this = THIS; GF_ASSERT (req); @@ -368,25 +391,29 @@ glusterd_handle_cli_delete_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log (THIS->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); goto out; } } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "Failed to get volname"); + snprintf (err_str, sizeof (err_str), "Failed to get volume " + "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); req->rpc_err = GARBAGE_ARGS; goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received delete vol req" + gf_log (this->name, GF_LOG_INFO, "Received delete vol req" "for volume %s", volname); - ret = glusterd_op_begin (req, GD_OP_DELETE_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_DELETE_VOLUME, dict, + err_str, sizeof (err_str)); out: free (cli_req.dict.dict_val); //its malloced by xdr @@ -395,8 +422,11 @@ out: glusterd_op_sm (); if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); + dict, err_str); if (dict) dict_unref (dict); } @@ -414,7 +444,7 @@ glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) char *volname = NULL; glusterd_volinfo_t *volinfo = NULL; xlator_t *this = NULL; - char *op_errstr = NULL; + char op_errstr[2048] = {0,}; GF_ASSERT (req); @@ -438,6 +468,8 @@ glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (op_errstr, sizeof (op_errstr), + "Unable to decode the command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -446,8 +478,9 @@ glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (this->name, GF_LOG_ERROR, "failed to get volname"); - gf_asprintf (&op_errstr, "Unable to find volume name"); + snprintf (op_errstr, sizeof (op_errstr), "Unable to find " + "volume name"); + gf_log (this->name, GF_LOG_ERROR, "%s", op_errstr); goto out; } @@ -456,7 +489,9 @@ glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { - gf_asprintf (&op_errstr, "Volume %s does not exist", volname); + snprintf (op_errstr, sizeof (op_errstr), + "Volume %s does not exist", volname); + gf_log (this->name, GF_LOG_ERROR, "%s", op_errstr); goto out; } @@ -468,15 +503,17 @@ glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) if (ret) goto out; - ret = glusterd_op_begin (req, GD_OP_HEAL_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_HEAL_VOLUME, dict, + op_errstr, sizeof (op_errstr)); out: glusterd_friend_sm (); glusterd_op_sm (); if (ret) { - if (!op_errstr) - op_errstr = gf_strdup ("operation failed"); + if (op_errstr[0] == '\0') + snprintf (op_errstr, sizeof (op_errstr), + "operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, dict, op_errstr); if (dict) @@ -497,6 +534,8 @@ glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) dict_t *dict = NULL; int32_t option_cnt = 0; glusterd_op_t cli_op = GD_OP_STATEDUMP_VOLUME; + char err_str[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); @@ -514,40 +553,51 @@ glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log (THIS->name, GF_LOG_ERROR, + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to " + "decode the command"); goto out; } } ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); + snprintf (err_str, sizeof (err_str), "Unable to get the volume " + "name"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_str (dict, "options", &options); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get options"); + snprintf (err_str, sizeof (err_str), "Unable to get options"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = dict_get_int32 (dict, "option_cnt", &option_cnt); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get option cnt"); + snprintf (err_str , sizeof (err_str), "Unable to get option " + "count"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received statedump request for " + gf_log (this->name, GF_LOG_INFO, "Received statedump request for " "volume %s with options %s", volname, options); - ret = glusterd_op_begin (req, GD_OP_STATEDUMP_VOLUME, dict); + ret = glusterd_op_begin (req, GD_OP_STATEDUMP_VOLUME, dict, + err_str, sizeof (err_str)); out: if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "Operation failed"); + dict, err_str); if (dict) dict_unref (dict); } diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 66adff741bf..b80964346b8 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -634,7 +634,8 @@ glusterd_rpc_create (struct rpc_clnt **rpc, dict_t *options, /* handler functions */ -int32_t glusterd_op_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx); +int32_t glusterd_op_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx, + char *err_str, size_t size); /* removed other definitions as they have been defined elsewhere in this file*/ |