summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrutika Dhananjay <kdhananj@redhat.com>2013-09-04 16:09:19 +0530
committerKrutika Dhananjay <kdhananj@redhat.com>2013-09-06 14:57:10 +0530
commit9e78640d658e0de9f29cfa7755adaf49770e55d1 (patch)
treeb872580462b7e24c79180ec24d1825c015717b66
parent51a02dc600bf4711e291247d271e87bd9f319fba (diff)
glusterd: probe quota.conf format changes
Original-author: Krishnan Parthasarathi <kparthas@redhat.com> Change-Id: Iff4ea98276ffdba5b39cadceff63739107eafd77 Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-quota.c34
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c108
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h7
3 files changed, 93 insertions, 56 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c
index e67208cf..e02f149a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-quota.c
+++ b/xlators/mgmt/glusterd/src/glusterd-quota.c
@@ -673,40 +673,6 @@ out:
return ret;
}
-#define QUOTA_CONF_HEADER \
- "GlusterFS Quota conf | version: v%d.%d\n"
-
-static int
-glusterd_store_quota_conf_skip_header (xlator_t *this, 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));
-}
-
-static int
-glusterd_store_quota_conf_stamp_header (xlator_t *this, int fd)
-{
- char buf[PATH_MAX] = {0,};
- int buf_len = 0;
- ssize_t ret = -1;
- ssize_t written = 0;
-
- snprintf (buf, sizeof(buf)-1, QUOTA_CONF_HEADER, 1, 1);
- buf_len = strlen (buf);
- for (written = 0; written != buf_len; written += ret) {
- ret = write (fd, buf + written, buf_len - written);
- if (ret == -1) {
- goto out;
- }
- }
-
- ret = 0;
-out:
- return ret;
-}
-
static int
glusterd_update_quota_conf_version (glusterd_volinfo_t *volinfo)
{
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 66f4c971..9a761d74 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1977,27 +1977,47 @@ 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};
+ int fd = -1;
+ char *gfid_str = NULL;
+ unsigned char buf[16] = {0};
char key[PATH_MAX] = {0};
int gfid_idx = 0;
int ret = -1;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
ret = glusterd_store_create_quota_conf_sh_on_absence (volinfo);
if (ret)
goto out;
- fp = fopen (volinfo->quota_conf_shandle->path, "r");
- if (!fp) {
+ fd = open (volinfo->quota_conf_shandle->path, O_RDONLY);
+ if (fd == -1) {
ret = -1;
goto out;
}
- gfid_idx = 0;
- while (fscanf (fp, "%s", buf) != EOF) {
+ ret = glusterd_store_quota_conf_skip_header (this, fd);
+ if (ret)
+ goto out;
- gfid_str = gf_strdup (buf);
+ for (gfid_idx=0; ; gfid_idx++) {
+
+ ret = read (fd, (void*)&buf, 16) ;
+ if (ret <= 0) {
+ //Finished reading all entries in the conf file
+ break;
+ }
+ if (ret != 16) {
+ //This should never happen. We must have a multiple of
+ //entry_sz bytes in our configuration file.
+ gf_log (this->name, GF_LOG_CRITICAL, "Quota "
+ "configuration store may be corrupt.");
+ goto out;
+ }
+
+ gfid_str = gf_strdup (uuid_utoa (buf));
if (!gfid_str) {
ret = -1;
goto out;
@@ -2012,7 +2032,6 @@ glusterd_vol_add_quota_conf_to_dict (glusterd_volinfo_t *volinfo, dict_t* load,
}
gfid_str = NULL;
- gfid_idx++;
}
snprintf (key, sizeof(key)-1, "volume%d.gfid-count", vol_idx);
@@ -2035,8 +2054,8 @@ glusterd_vol_add_quota_conf_to_dict (glusterd_volinfo_t *volinfo, dict_t* load,
ret = 0;
out:
- if (fp)
- fclose (fp);
+ if (fd != -1)
+ close (fd);
GF_FREE (gfid_str);
return ret;
}
@@ -2672,9 +2691,13 @@ glusterd_import_quota_conf (dict_t *vols, int vol_idx,
int gfid_count = 0;
int ret = -1;
int fd = -1;
- FILE *tmp_fp = NULL;
char key[PATH_MAX] = {0};
char *gfid_str = NULL;
+ uuid_t gfid = {0,};
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
if (!glusterd_is_volume_quota_enabled (new_volinfo)) {
(void) glusterd_clean_up_quota_store (new_volinfo);
@@ -2690,23 +2713,18 @@ glusterd_import_quota_conf (dict_t *vols, int vol_idx,
ret = -1;
goto out;
}
- tmp_fp = fdopen (fd, "r+");
- if (!tmp_fp) {
- ret = -1;
- goto out;
- }
snprintf (key, sizeof (key)-1, "volume%d.quota-cksum", vol_idx);
key[sizeof(key)-1] = '\0';
ret = dict_get_uint32 (vols, key, &new_volinfo->quota_conf_cksum);
if (ret)
- gf_log (THIS->name, GF_LOG_DEBUG, "Failed to get quota cksum");
+ gf_log (this->name, GF_LOG_DEBUG, "Failed to get quota cksum");
snprintf (key, sizeof (key)-1, "volume%d.quota-version", vol_idx);
key[sizeof(key)-1] = '\0';
ret = dict_get_uint32 (vols, key, &new_volinfo->quota_conf_version);
if (ret)
- gf_log (THIS->name, GF_LOG_DEBUG, "Failed to get quota "
+ gf_log (this->name, GF_LOG_DEBUG, "Failed to get quota "
"version");
snprintf (key, sizeof (key)-1, "volume%d.gfid-count", vol_idx);
@@ -2715,6 +2733,13 @@ glusterd_import_quota_conf (dict_t *vols, int vol_idx,
if (ret)
goto out;
+ ret = glusterd_store_quota_conf_stamp_header (this, fd);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to add header to tmp "
+ "file");
+ goto out;
+ }
+
gfid_idx = 0;
for (gfid_idx = 0; gfid_idx < gfid_count; gfid_idx++) {
@@ -2725,9 +2750,14 @@ glusterd_import_quota_conf (dict_t *vols, int vol_idx,
if (ret)
goto out;
- ret = fprintf (tmp_fp, "%s\n", gfid_str);
- if (ret < 0) {
- goto out;
+ uuid_parse (gfid_str, gfid);
+ ret = write (fd, (void*)gfid, 16);
+ if (ret != 16) {
+ gf_log (this->name, GF_LOG_CRITICAL, "Unable to write "
+ "gfid %s into quota.conf for %s", gfid_str,
+ new_volinfo->volname);
+ ret = -1;
+ goto out;
}
}
@@ -8289,3 +8319,37 @@ glusterd_clean_up_quota_store (glusterd_volinfo_t *volinfo)
volinfo->quota_conf_version = 0;
}
+
+#define QUOTA_CONF_HEADER \
+ "GlusterFS Quota conf | version: v%d.%d\n"
+
+int
+glusterd_store_quota_conf_skip_header (xlator_t *this, 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));
+}
+
+int
+glusterd_store_quota_conf_stamp_header (xlator_t *this, int fd)
+{
+ char buf[PATH_MAX] = {0,};
+ int buf_len = 0;
+ ssize_t ret = -1;
+ ssize_t written = 0;
+
+ snprintf (buf, sizeof(buf)-1, QUOTA_CONF_HEADER, 1, 1);
+ buf_len = strlen (buf);
+ for (written = 0; written != buf_len; written += ret) {
+ ret = write (fd, buf + written, buf_len - written);
+ if (ret == -1) {
+ goto out;
+ }
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 3be5458d..4a5fc10e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -597,4 +597,11 @@ glusterd_reconfigure_quotad ();
void
glusterd_clean_up_quota_store (glusterd_volinfo_t *volinfo);
+
+int
+glusterd_store_quota_conf_skip_header (xlator_t *this, int fd);
+
+int
+glusterd_store_quota_conf_stamp_header (xlator_t *this, int fd);
+
#endif