12a457
From 0a9973d627e623406dfd6199609bc89902942513 Mon Sep 17 00:00:00 2001
12a457
From: Mohammed Rafi KC <rkavunga@redhat.com>
12a457
Date: Wed, 1 Jun 2016 23:01:37 +0530
12a457
Subject: [PATCH 182/183] glusterd/snapshot: remove quota related options from snap volfile
12a457
12a457
enabling inode-quota on a snapshot volume is unnecessary, because
12a457
snapshot is a read-only volume. So we don't need to enforce quota
12a457
on a snapshot volume.
12a457
12a457
This patch will remove the quota related options from snapshot
12a457
volfile.
12a457
12a457
Back port of>
12a457
>Change-Id: Iddabcb83820dac2384924a01d45abe1ef1e95600
12a457
>BUG: 1341796
12a457
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
12a457
>Reviewed-on: http://review.gluster.org/14608
12a457
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
12a457
>Reviewed-by: N Balachandran <nbalacha@redhat.com>
12a457
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
>Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
>CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
>Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
12a457
12a457
Change-Id: I1bad0903c5f57df1a5b0aa4d4b2508e4b0b99a85
12a457
BUG: 1341034
12a457
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/75814
12a457
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
12a457
Tested-by: Atin Mukherjee <amukherj@redhat.com>
12a457
---
12a457
 xlators/mgmt/glusterd/src/glusterd-snapshot.c |  153 ++++++++++++++++++++++---
12a457
 1 files changed, 137 insertions(+), 16 deletions(-)
12a457
12a457
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
12a457
index 072e22f..67cfbb8 100644
12a457
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
12a457
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
12a457
@@ -79,6 +79,15 @@ struct snap_create_args_ {
12a457
         int32_t               brickcount;
12a457
         int32_t               brickorder;
12a457
 };
12a457
+
12a457
+/* This structure is used to store unsupported options and thier values
12a457
+ * for snapshotted volume.
12a457
+ */
12a457
+struct gd_snap_unsupported_opt_t {
12a457
+        char                  *key;
12a457
+        char                  *value;
12a457
+};
12a457
+
12a457
 typedef struct snap_create_args_ snap_create_args_t;
12a457
 
12a457
 /* This function is called to get the device path of the snap lvm. Usually
12a457
@@ -5149,24 +5158,113 @@ out:
12a457
         return ret;
12a457
 }
12a457
 
12a457
+static int
12a457
+glusterd_snap_clear_unsupported_opt (glusterd_volinfo_t *volinfo,
12a457
+                              struct gd_snap_unsupported_opt_t *unsupported_opt)
12a457
+{
12a457
+        int      ret          = -1;
12a457
+        int      i            = 0;
12a457
+
12a457
+        GF_VALIDATE_OR_GOTO ("glusterd", volinfo, out);
12a457
+
12a457
+        for (i = 0; unsupported_opt[i].key; i++) {
12a457
+                glusterd_volinfo_get (volinfo, unsupported_opt[i].key,
12a457
+                                      &unsupported_opt[i].value);
12a457
+
12a457
+                if (unsupported_opt[i].value) {
12a457
+                        unsupported_opt[i].value = gf_strdup (
12a457
+                                                      unsupported_opt[i].value);
12a457
+                        if (!unsupported_opt[i].value) {
12a457
+                                ret = -1;
12a457
+                                goto out;
12a457
+                        }
12a457
+                        dict_del (volinfo->dict, unsupported_opt[i].key);
12a457
+                }
12a457
+        }
12a457
+
12a457
+        ret = 0;
12a457
+out:
12a457
+        if (ret) {
12a457
+                for (i = 0; unsupported_opt[i].key; i++) {
12a457
+                        if (unsupported_opt[i].value) {
12a457
+                                /* Freeing the memory */
12a457
+                                GF_FREE (unsupported_opt[i].value);
12a457
+                                unsupported_opt[i].value = NULL;
12a457
+                        }
12a457
+                }
12a457
+        }
12a457
+
12a457
+        return ret;
12a457
+}
12a457
+
12a457
+static int
12a457
+glusterd_snap_set_unsupported_opt (glusterd_volinfo_t *volinfo,
12a457
+                              struct gd_snap_unsupported_opt_t *unsupported_opt)
12a457
+{
12a457
+        int       ret       = -1;
12a457
+        int       i         = 0;
12a457
+
12a457
+        GF_VALIDATE_OR_GOTO ("glusterd", volinfo, out);
12a457
+
12a457
+        for (i = 0; unsupported_opt[i].key; i++) {
12a457
+                if (!unsupported_opt[i].value)
12a457
+                        continue;
12a457
+
12a457
+                ret = dict_set_dynstr (volinfo->dict, unsupported_opt[i].key,
12a457
+                                       unsupported_opt[i].value);
12a457
+                if (ret) {
12a457
+                        gf_msg ("glusterd", GF_LOG_ERROR, errno,
12a457
+                                GD_MSG_DICT_SET_FAILED, "dict set failed");
12a457
+                        goto out;
12a457
+                }
12a457
+        }
12a457
+
12a457
+        ret = 0;
12a457
+out:
12a457
+        if (ret) {
12a457
+                for (; unsupported_opt[i].key; i++) {
12a457
+                        if (unsupported_opt[i].value) {
12a457
+                                /* Freeing the memory */
12a457
+                                GF_FREE (unsupported_opt[i].value);
12a457
+                                unsupported_opt[i].value = NULL;
12a457
+                        }
12a457
+                }
12a457
+        }
12a457
+
12a457
+        return ret;
12a457
+}
12a457
+
12a457
 glusterd_volinfo_t *
12a457
 glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap,
12a457
                       dict_t *dict, dict_t *rsp_dict, int64_t volcount,
12a457
                       int clone)
12a457
 {
12a457
-        char                    key[PATH_MAX]                   = "";
12a457
-        char                   *username                        = NULL;
12a457
-        char                   *password                        = NULL;
12a457
-        glusterd_brickinfo_t   *brickinfo                       = NULL;
12a457
-        glusterd_conf_t        *priv                            = NULL;
12a457
-        glusterd_volinfo_t     *snap_vol                        = NULL;
12a457
-        uuid_t                 *snap_volid                      = NULL;
12a457
-        int32_t                 ret                             = -1;
12a457
-        int32_t                 brick_count                     = 0;
12a457
-        xlator_t               *this                            = NULL;
12a457
-        int64_t                 brick_order                     = 0;
12a457
-        char                    *clonename                      = NULL;
12a457
-        gf_boolean_t            conf_present                    = _gf_false;
12a457
+        char                         key[PATH_MAX]           = "";
12a457
+        char                        *username                = NULL;
12a457
+        char                        *password                = NULL;
12a457
+        glusterd_brickinfo_t        *brickinfo               = NULL;
12a457
+        glusterd_conf_t             *priv                    = NULL;
12a457
+        glusterd_volinfo_t          *snap_vol                = NULL;
12a457
+        uuid_t                      *snap_volid              = NULL;
12a457
+        int32_t                      ret                     = -1;
12a457
+        int32_t                      brick_count             = 0;
12a457
+        xlator_t                    *this                    = NULL;
12a457
+        int64_t                      brick_order             = 0;
12a457
+        char                        *clonename               = NULL;
12a457
+        gf_boolean_t                 conf_present            = _gf_false;
12a457
+
12a457
+       struct  gd_snap_unsupported_opt_t  unsupported_opt[]  = {
12a457
+                                         {.key   = VKEY_FEATURES_QUOTA,
12a457
+                                          .value = NULL},
12a457
+                                         {.key   = VKEY_FEATURES_INODE_QUOTA,
12a457
+                                          .value = NULL},
12a457
+                                         {.key   = "feature.deem-statfs",
12a457
+                                          .value = NULL},
12a457
+                                         {.key   = "features.quota-deem-statfs",
12a457
+                                          .value = NULL},
12a457
+                                         {.key   = NULL,
12a457
+                                          .value = NULL}
12a457
+                                                         };
12a457
 
12a457
         this = THIS;
12a457
         GF_ASSERT (this);
12a457
@@ -5323,13 +5421,25 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap,
12a457
                 goto out;
12a457
         }
12a457
 
12a457
+        if (snap_vol->is_snap_volume) {
12a457
+                ret = glusterd_snap_clear_unsupported_opt (snap_vol,
12a457
+                                                           unsupported_opt);
12a457
+                if (ret) {
12a457
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
+                                GD_MSG_VOL_OP_FAILED, "Failed to clear quota "
12a457
+                                "option for the snap %s (volume: %s)",
12a457
+                                snap->snapname, origin_vol->volname);
12a457
+                        goto out;
12a457
+                }
12a457
+        }
12a457
+
12a457
         ret = generate_brick_volfiles (snap_vol);
12a457
         if (ret) {
12a457
                 gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
                         GD_MSG_VOLFILE_CREATE_FAIL, "generating the brick "
12a457
                         "volfiles for the snap %s (volume: %s) failed",
12a457
                         snap->snapname, origin_vol->volname);
12a457
-                goto out;
12a457
+                goto reset_option;
12a457
         }
12a457
 
12a457
         ret = generate_client_volfiles (snap_vol, GF_CLIENT_TRUSTED);
12a457
@@ -5338,7 +5448,7 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap,
12a457
                         GD_MSG_VOLFILE_CREATE_FAIL, "generating the trusted "
12a457
                         "client volfiles for the snap %s (volume: %s) failed",
12a457
                         snap->snapname, origin_vol->volname);
12a457
-                goto out;
12a457
+                goto reset_option;
12a457
         }
12a457
 
12a457
         ret = generate_client_volfiles (snap_vol, GF_CLIENT_OTHER);
12a457
@@ -5347,9 +5457,20 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap,
12a457
                         GD_MSG_VOLFILE_CREATE_FAIL, "generating the client "
12a457
                         "volfiles for the snap %s (volume: %s) failed",
12a457
                         snap->snapname, origin_vol->volname);
12a457
-                goto out;
12a457
+                goto reset_option;
12a457
         }
12a457
 
12a457
+reset_option:
12a457
+        if (snap_vol->is_snap_volume) {
12a457
+                if (glusterd_snap_set_unsupported_opt (snap_vol,
12a457
+                                                       unsupported_opt)) {
12a457
+                        ret = -1;
12a457
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
+                                GD_MSG_VOL_OP_FAILED, "Failed to reset quota "
12a457
+                                "option for the snap %s (volume: %s)",
12a457
+                                snap->snapname, origin_vol->volname);
12a457
+                }
12a457
+        }
12a457
 out:
12a457
         if (ret) {
12a457
                 if (snap_vol)
12a457
-- 
12a457
1.7.1
12a457