summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-volume.c
diff options
context:
space:
mode:
authorvmallika <vmallika@redhat.com>2015-04-15 17:35:07 +0530
committerVijay Bellur <vbellur@redhat.com>2015-05-07 23:54:33 -0700
commitffbe47e0ec8411313b666a8705f31a67d3862763 (patch)
treea161fdbec2678aea5329fae1dcb932cefe4d8395 /cli/src/cli-cmd-volume.c
parent753a603ce3259f3c6667a48ff4001512941f9128 (diff)
quota: support for inode quota in quota.conf
Currently when quota limit is set, corresponding gfid is set in quota.conf. This patch supports storing inode-quota limits in quota.conf and also stores additional byte for each gfid to differentiate between usage quota limit and inode quota limit. Change-Id: I444d7399407594edd280e640681679a784d4c46a BUG: 1218170 Signed-off-by: vmallika <vmallika@redhat.com> Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/10069 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com> Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/10524
Diffstat (limited to 'cli/src/cli-cmd-volume.c')
-rw-r--r--cli/src/cli-cmd-volume.c81
1 files changed, 47 insertions, 34 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index c9c6b65f35f..72a789de56c 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -1111,28 +1111,20 @@ out:
return ret;
}
-#define QUOTA_CONF_HEADER \
- "GlusterFS Quota conf | version: v%d.%d\n"
-int
-cli_cmd_quota_conf_skip_header (int fd)
-{
- char buf[PATH_MAX] = {0,};
-
- snprintf (buf, sizeof(buf)-1, QUOTA_CONF_HEADER, 1, 1);
- return gf_skip_header_section (fd, strlen (buf));
-}
-
/* Checks if at least one limit has been set on the volume
*
* Returns true if at least one limit is set. Returns false otherwise.
*/
gf_boolean_t
-_limits_set_on_volume (char *volname) {
- gf_boolean_t limits_set = _gf_false;
- int ret = -1;
+_limits_set_on_volume (char *volname, int type) {
+ gf_boolean_t limits_set = _gf_false;
+ int ret = -1;
char quota_conf_file[PATH_MAX] = {0,};
- int fd = -1;
- char buf[16] = {0,};
+ int fd = -1;
+ char buf[16] = {0,};
+ float version = 0.0f;
+ char gfid_type_stored = 0;
+ char gfid_type = 0;
/* TODO: fix hardcoding; Need to perform an RPC call to glusterd
* to fetch working directory
@@ -1144,17 +1136,31 @@ _limits_set_on_volume (char *volname) {
if (fd == -1)
goto out;
- ret = cli_cmd_quota_conf_skip_header (fd);
+ ret = quota_conf_read_version (fd, &version);
if (ret)
goto out;
- /* Try to read atleast one gfid */
- ret = read (fd, (void *)buf, 16);
- if (ret == 16)
- limits_set = _gf_true;
+ if (type == GF_QUOTA_OPTION_TYPE_LIST)
+ gfid_type = GF_QUOTA_CONF_TYPE_USAGE;
+ else
+ gfid_type = GF_QUOTA_CONF_TYPE_OBJECTS;
+
+ /* Try to read atleast one gfid of type 'gfid_type' */
+ while (1) {
+ ret = quota_conf_read_gfid (fd, buf, &gfid_type_stored,
+ version);
+ if (ret <= 0)
+ break;
+
+ if (gfid_type_stored == gfid_type) {
+ limits_set = _gf_true;
+ break;
+ }
+ }
out:
if (fd != -1)
close (fd);
+
return limits_set;
}
@@ -1213,6 +1219,8 @@ cli_cmd_quota_handle_list_all (const char **words, dict_t *options)
gf_boolean_t xml_err_flag = _gf_false;
char err_str[NAME_MAX] = {0,};
int32_t type = 0;
+ char gfid_type = 0;
+ float version = 0.0f;
xdata = dict_new ();
if (!xdata) {
@@ -1248,9 +1256,11 @@ cli_cmd_quota_handle_list_all (const char **words, dict_t *options)
/* Check if at least one limit is set on volume. No need to check for
* quota enabled as cli_get_soft_limit() handles that
*/
- if (!_limits_set_on_volume (volname)) {
- snprintf (err_str, sizeof (err_str), "No quota configured on "
- "volume %s", volname);
+ if (!_limits_set_on_volume (volname, type)) {
+ snprintf (err_str, sizeof (err_str), "No%s quota configured on"
+ " volume %s",
+ (type == GF_QUOTA_OPTION_TYPE_LIST) ? "" : " inode",
+ volname);
if (global_state->mode & GLUSTER_MODE_XML) {
xml_err_flag = _gf_true;
} else {
@@ -1299,10 +1309,10 @@ cli_cmd_quota_handle_list_all (const char **words, dict_t *options)
goto out;
}
- ret = cli_cmd_quota_conf_skip_header (fd);
- if (ret) {
+ ret = quota_conf_read_version (fd, &version);
+ if (ret)
goto out;
- }
+
CLI_LOCAL_INIT (local, words, frame, xdata);
proc = &cli_quotad_clnt.proctable[GF_AGGREGATOR_GETLIMIT];
@@ -1324,18 +1334,21 @@ cli_cmd_quota_handle_list_all (const char **words, dict_t *options)
goto out;
}
for (count = 0;; count++) {
- ret = read (fd, (void*) buf, 16);
- if (ret <= 0) {
- //Finished reading all entries in the conf file
+ ret = quota_conf_read_gfid (fd, buf, &gfid_type, version);
+ if (ret == 0) {
break;
- }
- if (ret < 16) {
- //This should never happen. We must have a multiple of
- //entry_sz bytes in our configuration file.
+ } else if (ret < 0) {
gf_log (THIS->name, GF_LOG_CRITICAL, "Quota "
"configuration store may be corrupt.");
goto out;
}
+
+ if ((type == GF_QUOTA_OPTION_TYPE_LIST &&
+ gfid_type == GF_QUOTA_CONF_TYPE_OBJECTS) ||
+ (type == GF_QUOTA_OPTION_TYPE_LIST_OBJECTS &&
+ gfid_type == GF_QUOTA_CONF_TYPE_USAGE))
+ continue;
+
uuid_utoa_r (buf, gfid_str);
ret = dict_set_str (xdata, "gfid", gfid_str);
if (ret) {