summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrutika Dhananjay <kdhananj@redhat.com>2013-09-04 16:07:08 +0530
committerKrutika Dhananjay <kdhananj@redhat.com>2013-09-06 14:57:09 +0530
commit08c555680d4aa0ec800ce617fdb119e83f9cd1f8 (patch)
tree9affb88545f8d95bef2ec29cea082b5f103c1f92
parentaa1da9c3207b9b1a1d91d09e5faf92510e7b61d7 (diff)
glusterd: add quota conf to probe payload
also fix FILE* leak in cli Original-author: Krishnan Parthasarathi <kparthas@redhat.com> Change-Id: Icb9b58ef065ce1a150d98b4c26bbcddeeb390e44 Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
-rw-r--r--cli/src/cli-cmd-volume.c24
-rw-r--r--cli/src/cli-rpc-ops.c48
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c140
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h2
4 files changed, 205 insertions, 9 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 7dc26144..17663091 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -1096,6 +1096,20 @@ print_quota_list_header (void)
}
int
+cli_get_soft_limit (call_frame_t *frame, cli_local_t *local, dict_t *options,
+ const char **words)
+{
+ rpc_clnt_procedure_t *proc = NULL;
+ int ret = -1;
+
+ CLI_LOCAL_INIT (local, words, frame, options);
+ proc = &cli_rpc_prog->proctable[GLUSTER_CLI_QUOTA];
+ ret = proc->fn (frame, THIS, options);
+
+ return ret;
+}
+
+int
cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
const char **words, int wordcount)
{
@@ -1112,6 +1126,7 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
char *volname = NULL;
dict_t *xdata = NULL;
char buf[256] = {0};
+ FILE *fp = NULL;
const char *question = "Disabling quota will delete all the quota "
"configuration. Do you want to continue?";
@@ -1152,6 +1167,12 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
if (type == GF_QUOTA_OPTION_TYPE_LIST && wordcount == 4) {
+ ret = cli_get_soft_limit (frame, local, options, words);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to fetch default "
+ "soft-limit");
+ goto out;
+ }
proc = &cli_quotad_clnt.proctable[GF_AGGREGATOR_GETLIMIT];
xdata = dict_new ();
if (!xdata) {
@@ -1166,7 +1187,6 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
//TODO: fix hardcoding
sprintf (quota_conf_file, "/var/lib/glusterd/vols/%s/quota.conf",
volname);
- FILE *fp = NULL;
fp = fopen (quota_conf_file, "r");
if (!fp) {
gf_log ("cli", GF_LOG_ERROR, "Failed to open quota.conf");
@@ -1197,6 +1217,8 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
ret = proc->fn (frame, THIS, options);
out:
+ if (fp)
+ fclose (fp);
if (ret) {
cli_cmd_sent_status_get (&sent);
if (sent == 0 && parse_err == 0)
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 9c533af6..3edcd0d6 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -2457,8 +2457,8 @@ out:
return ret;
}
-static int
-print_quota_list_from_quotad (dict_t *rsp_dict)
+int
+print_quota_list_from_quotad (call_frame_t *frame, dict_t *rsp_dict)
{
int64_t used_space = 0;
int64_t avail = 0;
@@ -2469,7 +2469,13 @@ print_quota_list_from_quotad (dict_t *rsp_dict)
char *hl_str = NULL;
char *sl_final = NULL;
char *path = NULL;
+ char *default_sl = NULL;
int ret = -1;
+ cli_local_t *local = NULL;
+ dict_t *gd_rsp_dict = NULL;
+
+ local = frame->local;
+ gd_rsp_dict = local->dict;
struct quota_limit {
int64_t hl;
@@ -2489,6 +2495,13 @@ print_quota_list_from_quotad (dict_t *rsp_dict)
"limit key not present in dict");
goto out;
}
+
+ ret = dict_get_str (gd_rsp_dict, "default-soft-limit", &default_sl);
+ if (ret) {
+ gf_log (frame->this->name, GF_LOG_ERROR, "failed to "
+ "get default soft limit");
+ goto out;
+ }
existing_limits = (struct quota_limit *)limit;
existing_limits->hl = ntoh64 (existing_limits->hl);
existing_limits->sl = ntoh64 (existing_limits->sl);
@@ -2496,8 +2509,7 @@ print_quota_list_from_quotad (dict_t *rsp_dict)
hl_str = gf_uint64_2human_readable (existing_limits->hl);
if (existing_limits->sl == 0) {
- //TODO: need to fix this by fetching default sl from glusterd
- sl_final = "80%";
+ sl_final = default_sl;
} else {
snprintf (percent_str, sizeof (percent_str), "%"PRIu64"%%",
existing_limits->sl);
@@ -2582,7 +2594,7 @@ cli_quotad_getlimit_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
}
- print_quota_list_from_quotad (dict);
+ print_quota_list_from_quotad (frame, dict);
out:
cli_cmd_broadcast_response (ret);
@@ -2658,12 +2670,17 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov,
call_frame_t *frame = NULL;
char *default_sl = NULL;
char *limit_list = NULL;
-
+ cli_local_t *local = NULL;
+ dict_t *aggr = NULL;
+ char *default_sl_dup = NULL;
+ int32_t entry_count = 0;
if (-1 == req->rpc_status) {
goto out;
}
frame = myframe;
+ local = frame->local;
+ aggr = local->dict;
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
@@ -2708,12 +2725,27 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov,
gf_log (frame->this->name, GF_LOG_TRACE, "failed to get "
"default soft limit");
+ if (default_sl) {
+ default_sl_dup = gf_strdup (default_sl);
+ if (!default_sl_dup) {
+ ret = -1;
+ goto out;
+ }
+ ret = dict_set_dynstr (aggr, "default-soft-limit",
+ default_sl_dup);
+ if (ret) {
+ gf_log (frame->this->name, GF_LOG_TRACE,
+ "failed to set default soft limit");
+ GF_FREE (default_sl_dup);
+ }
+ }
+
ret = dict_get_int32 (dict, "type", &type);
if (ret)
gf_log (frame->this->name, GF_LOG_TRACE,
"failed to get type");
- ret = dict_get_int32 (dict, "count", &count);
+ ret = dict_get_int32 (dict, "count", &entry_count);
if (ret)
gf_log (frame->this->name, GF_LOG_TRACE, "failed to get count");
@@ -2728,7 +2760,7 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
- gf_cli_quota_list (volname, dict, count, rsp.op_errstr,
+ gf_cli_quota_list (volname, dict, entry_count, rsp.op_errstr,
default_sl);
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index bb6bcf83..000a6b10 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1929,6 +1929,62 @@ out:
return ret;
}
+int
+glusterd_vol_add_quota_conf_to_dict (glusterd_volinfo_t *volinfo, dict_t* load,
+ int vol_idx)
+{
+ FILE *fp = NULL;
+ char *gfid_str = NULL;
+ char buf[256] = {0};
+ char key[PATH_MAX] = {0};
+ int gfid_idx = 0;
+ int ret = -1;
+
+ ret = glusterd_store_create_quota_conf_sh_on_absence (volinfo);
+ if (ret)
+ goto out;
+
+ fp = fopen (volinfo->quota_conf_shandle->path, "r");
+ if (!fp) {
+ ret = -1;
+ goto out;
+ }
+
+ gfid_idx = 0;
+ while (fscanf (fp, "%s", buf) != EOF) {
+
+ gfid_str = gf_strdup (buf);
+ if (!gfid_str) {
+ ret = -1;
+ goto out;
+ }
+
+ snprintf (key, sizeof(key)-1, "volume%d.gfid%d", vol_idx,
+ gfid_idx);
+ key[sizeof(key)-1] = '\0';
+ ret = dict_set_dynstr (load, key, gfid_str);
+ if (ret) {
+ goto out;
+ }
+
+ gfid_str = NULL;
+ gfid_idx++;
+ }
+
+ snprintf (key, sizeof(key)-1, "volume%d.gfid-count", vol_idx);
+ key[sizeof(key)-1] = '\0';
+ ret = dict_set_int32 (load, key, gfid_idx);
+ if (ret)
+ goto out;
+
+ ret = 0;
+out:
+ if (fp)
+ fclose (fp);
+ GF_FREE (gfid_str);
+ return ret;
+}
+
int32_t
glusterd_build_volume_dict (dict_t **vols)
{
@@ -1951,6 +2007,11 @@ glusterd_build_volume_dict (dict_t **vols)
ret = glusterd_add_volume_to_dict (volinfo, dict, count);
if (ret)
goto out;
+ if (!glusterd_is_volume_quota_enabled (volinfo))
+ continue;
+ ret = glusterd_vol_add_quota_conf_to_dict (volinfo, dict, count);
+ if (ret)
+ goto out;
}
@@ -2492,6 +2553,80 @@ out:
return ret;
}
+static int
+glusterd_import_quota_conf (dict_t *vols, int vol_idx,
+ glusterd_volinfo_t *new_volinfo)
+{
+ int gfid_idx = 0;
+ int gfid_count = 0;
+ int ret = -1;
+ int fd = -1;
+ FILE *tmp_fp = NULL;
+ char key[PATH_MAX] = {0};
+ char *gfid_str = NULL;
+
+ if (!glusterd_is_volume_quota_enabled (new_volinfo))
+ return 0;
+
+ ret = glusterd_store_create_quota_conf_sh_on_absence (new_volinfo);
+ if (ret)
+ goto out;
+
+ fd = gf_store_mkstemp (new_volinfo->quota_conf_shandle);
+ if (fd < 0) {
+ ret = -1;
+ goto out;
+ }
+ tmp_fp = fdopen (fd, "r+");
+ if (!tmp_fp) {
+ ret = -1;
+ goto out;
+ }
+
+ snprintf (key, sizeof (key)-1, "volume%d.gfid-count", vol_idx);
+ key[sizeof(key)-1] = '\0';
+ ret = dict_get_int32 (vols, key, &gfid_count);
+ if (ret)
+ goto out;
+
+ gfid_idx = 0;
+ for (gfid_idx = 0; gfid_idx < gfid_count; gfid_idx++) {
+
+ snprintf (key, sizeof (key)-1, "volume%d.gfid%d",
+ vol_idx, gfid_idx);
+ key[sizeof(key)-1] = '\0';
+ ret = dict_get_str (vols, key, &gfid_str);
+ if (ret)
+ goto out;
+
+ ret = fprintf (tmp_fp, "%s\n", gfid_str);
+ if (ret < 0) {
+ goto out;
+ }
+
+ }
+
+ ret = gf_store_rename_tmppath (new_volinfo->quota_conf_shandle);
+
+out:
+ if (tmp_fp) {
+ fclose (tmp_fp);
+
+ } else if (fd >= 0) {
+ close (fd);
+
+ }
+
+ if (ret && (fd > 0)) {
+ gf_store_unlink_tmppath (new_volinfo->quota_conf_shandle);
+ (void) gf_store_handle_destroy
+ (new_volinfo->quota_conf_shandle);
+ new_volinfo->quota_conf_shandle = NULL;
+ }
+
+ return ret;
+}
+
int32_t
glusterd_import_volinfo (dict_t *vols, int count,
glusterd_volinfo_t **volinfo)
@@ -2737,6 +2872,7 @@ glusterd_import_volinfo (dict_t *vols, int count,
ret = glusterd_import_bricks (vols, count, new_volinfo);
if (ret)
goto out;
+
*volinfo = new_volinfo;
out:
if (msg[0])
@@ -2908,6 +3044,10 @@ glusterd_import_friend_volume (dict_t *vols, size_t count)
if (ret)
goto out;
+ ret = glusterd_import_quota_conf (vols, count, new_volinfo);
+ if (ret)
+ goto out;
+
list_add_tail (&new_volinfo->vol_list, &priv->volumes);
out:
gf_log ("", GF_LOG_DEBUG, "Returning with ret: %d", ret);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 9fe08d06..1074c46d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -499,6 +499,8 @@ glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict);
int
glusterd_volume_heal_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict);
+int32_t
+glusterd_check_if_quota_trans_enabled (glusterd_volinfo_t *volinfo);
int
glusterd_volume_quota_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp);
int