12a457
From 7bf42aafad24b945acf0affa3bf7387ebaab4ea4 Mon Sep 17 00:00:00 2001
12a457
From: Pranith Kumar K <pkarampu@redhat.com>
12a457
Date: Wed, 4 May 2016 19:05:28 +0530
12a457
Subject: [PATCH 130/139] cluster/afr: Do heals with shd pid
12a457
12a457
Multi-threaded healing doesn't create synctask with shd pid, this
12a457
leads to healing problems when quota exceeds.
12a457
12a457
 >BUG: 1332994
12a457
 >Change-Id: I80f57c1923756f3298730b8820498127024e1209
12a457
 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
12a457
 >Reviewed-on: http://review.gluster.org/14211
12a457
 >Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
 >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
 >CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
 >Reviewed-by: Ravishankar N <ravishankar@redhat.com>
12a457
12a457
BUG: 1332199
12a457
Change-Id: I8979b80067214804a24d5a25ae0cd3e3e15faacc
12a457
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/73766
12a457
---
12a457
 libglusterfs/src/syncop-utils.c          |   19 ++++++++-------
12a457
 libglusterfs/src/syncop-utils.h          |    6 ++--
12a457
 tests/basic/afr/heal-quota.t             |   35 ++++++++++++++++++++++++++++++
12a457
 xlators/cluster/afr/src/afr-self-heald.c |   11 ++++++++-
12a457
 4 files changed, 58 insertions(+), 13 deletions(-)
12a457
 create mode 100644 tests/basic/afr/heal-quota.t
12a457
12a457
diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c
12a457
index 5e6b9fa..8998c06 100644
12a457
--- a/libglusterfs/src/syncop-utils.c
12a457
+++ b/libglusterfs/src/syncop-utils.c
12a457
@@ -289,10 +289,11 @@ _dir_scan_job_fn (void *data)
12a457
 }
12a457
 
12a457
 static int
12a457
-_run_dir_scan_task (xlator_t *subvol, loc_t *parent, gf_dirent_t *q,
12a457
-                    gf_dirent_t *entry, int *retval, pthread_mutex_t *mut,
12a457
-                    pthread_cond_t *cond, uint32_t *jobs_running,
12a457
-                    uint32_t *qlen, syncop_dir_scan_fn_t fn, void *data)
12a457
+_run_dir_scan_task (call_frame_t *frame, xlator_t *subvol, loc_t *parent,
12a457
+                    gf_dirent_t *q, gf_dirent_t *entry, int *retval,
12a457
+                    pthread_mutex_t *mut, pthread_cond_t *cond,
12a457
+                    uint32_t *jobs_running, uint32_t *qlen,
12a457
+                    syncop_dir_scan_fn_t fn, void *data)
12a457
 {
12a457
         int     ret = 0;
12a457
         struct syncop_dir_scan_data *scan_data = NULL;
12a457
@@ -318,7 +319,7 @@ _run_dir_scan_task (xlator_t *subvol, loc_t *parent, gf_dirent_t *q,
12a457
         scan_data->retval       = retval;
12a457
 
12a457
         ret = synctask_new (subvol->ctx->env, _dir_scan_job_fn,
12a457
-                            _dir_scan_job_fn_cbk, NULL, scan_data);
12a457
+                            _dir_scan_job_fn_cbk, frame, scan_data);
12a457
 out:
12a457
         if (ret < 0) {
12a457
                 gf_dirent_entry_free (entry);
12a457
@@ -334,9 +335,9 @@ out:
12a457
 }
12a457
 
12a457
 int
12a457
-syncop_mt_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data,
12a457
-                    syncop_dir_scan_fn_t fn, dict_t *xdata, uint32_t max_jobs,
12a457
-                    uint32_t max_qlen)
12a457
+syncop_mt_dir_scan (call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid,
12a457
+                    void *data, syncop_dir_scan_fn_t fn, dict_t *xdata,
12a457
+                    uint32_t max_jobs, uint32_t max_qlen)
12a457
 {
12a457
         fd_t        *fd    = NULL;
12a457
         uint64_t    offset = 0;
12a457
@@ -433,7 +434,7 @@ syncop_mt_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data,
12a457
                         if (!entry)
12a457
                                 continue;
12a457
 
12a457
-                        ret = _run_dir_scan_task (subvol, loc, &q, entry,
12a457
+                        ret = _run_dir_scan_task (frame, subvol, loc, &q, entry,
12a457
                                                   &retval, &mut, &cond,
12a457
                                                 &jobs_running, &qlen, fn, data);
12a457
                         if (ret)
12a457
diff --git a/libglusterfs/src/syncop-utils.h b/libglusterfs/src/syncop-utils.h
12a457
index 52bcfd9..3968d75 100644
12a457
--- a/libglusterfs/src/syncop-utils.h
12a457
+++ b/libglusterfs/src/syncop-utils.h
12a457
@@ -19,9 +19,9 @@ syncop_ftw (xlator_t *subvol, loc_t *loc, int pid, void *data,
12a457
                        void *data));
12a457
 
12a457
 int
12a457
-syncop_mt_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data,
12a457
-                    syncop_dir_scan_fn_t fn, dict_t *xdata, uint32_t max_jobs,
12a457
-                    uint32_t max_qlen);
12a457
+syncop_mt_dir_scan (call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid,
12a457
+                    void *data, syncop_dir_scan_fn_t fn, dict_t *xdata,
12a457
+                    uint32_t max_jobs, uint32_t max_qlen);
12a457
 
12a457
 int
12a457
 syncop_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data,
12a457
diff --git a/tests/basic/afr/heal-quota.t b/tests/basic/afr/heal-quota.t
12a457
new file mode 100644
12a457
index 0000000..2663906
12a457
--- /dev/null
12a457
+++ b/tests/basic/afr/heal-quota.t
12a457
@@ -0,0 +1,35 @@
12a457
+#!/bin/bash
12a457
+
12a457
+#This file tests that heal succeeds even when quota is exceeded
12a457
+
12a457
+. $(dirname $0)/../../include.rc
12a457
+. $(dirname $0)/../../volume.rc
12a457
+
12a457
+cleanup;
12a457
+
12a457
+TEST glusterd
12a457
+TEST pidof glusterd
12a457
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{0,1}
12a457
+TEST $CLI volume set $V0 cluster.self-heal-daemon off
12a457
+TEST $CLI volume start $V0
12a457
+
12a457
+TEST glusterfs --attribute-timeout=0 --entry-timeout=0 --volfile-id=/$V0 --volfile-server=$H0 $M0;
12a457
+TEST $CLI volume quota $V0 enable
12a457
+TEST $CLI volume quota $V0 limit-usage / 10MB
12a457
+TEST $CLI volume quota $V0 soft-timeout 0
12a457
+TEST $CLI volume quota $V0 hard-timeout 0
12a457
+
12a457
+TEST touch $M0/a $M0/b
12a457
+dd if=/dev/zero of=$M0/b bs=1M count=7
12a457
+TEST kill_brick $V0 $H0 $B0/${V0}0
12a457
+dd if=/dev/zero of=$M0/a bs=1M count=12 #This shall fail
12a457
+TEST $CLI volume start $V0 force
12a457
+TEST $CLI volume set $V0 cluster.self-heal-daemon on
12a457
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "Y" glustershd_up_status
12a457
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 0
12a457
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 1
12a457
+
12a457
+TEST $CLI volume heal $V0
12a457
+EXPECT_WITHIN $HEAL_TIMEOUT "0" get_pending_heal_count $V0
12a457
+
12a457
+cleanup
12a457
diff --git a/xlators/cluster/afr/src/afr-self-heald.c b/xlators/cluster/afr/src/afr-self-heald.c
12a457
index d89692d..2fc1b63 100644
12a457
--- a/xlators/cluster/afr/src/afr-self-heald.c
12a457
+++ b/xlators/cluster/afr/src/afr-self-heald.c
12a457
@@ -435,10 +435,17 @@ afr_shd_index_sweep (struct subvol_healer *healer, char *vgfid)
12a457
 	int           ret     = 0;
12a457
 	xlator_t      *subvol = NULL;
12a457
 	dict_t        *xdata  = NULL;
12a457
+        call_frame_t  *frame  = NULL;
12a457
 
12a457
 	priv = healer->this->private;
12a457
 	subvol = priv->children[healer->subvol];
12a457
 
12a457
+        frame = afr_frame_create (healer->this);
12a457
+        if (!frame) {
12a457
+                ret = -ENOMEM;
12a457
+                goto out;
12a457
+        }
12a457
+
12a457
 	loc.inode = afr_shd_index_inode (healer->this, subvol, vgfid);
12a457
 	if (!loc.inode) {
12a457
 	        gf_msg (healer->this->name, GF_LOG_WARNING,
12a457
@@ -454,7 +461,7 @@ afr_shd_index_sweep (struct subvol_healer *healer, char *vgfid)
12a457
                 goto out;
12a457
         }
12a457
 
12a457
-        ret = syncop_mt_dir_scan (subvol, &loc, GF_CLIENT_PID_SELF_HEALD,
12a457
+        ret = syncop_mt_dir_scan (frame, subvol, &loc, GF_CLIENT_PID_SELF_HEALD,
12a457
                                   healer, afr_shd_index_heal, xdata,
12a457
                                  priv->shd.max_threads, priv->shd.wait_qlength);
12a457
 
12a457
@@ -466,6 +473,8 @@ out:
12a457
 
12a457
         if (xdata)
12a457
                 dict_unref (xdata);
12a457
+        if (frame)
12a457
+                AFR_STACK_DESTROY (frame);
12a457
 	return ret;
12a457
 }
12a457
 
12a457
-- 
12a457
1.7.1
12a457