d1681e
From 9ced91d6064b0cdea9090fe6ebddbf36a492b585 Mon Sep 17 00:00:00 2001
d1681e
From: Mohit Agrawal <moagrawa@redhat.com>
d1681e
Date: Sat, 15 Jul 2017 17:55:14 +0530
d1681e
Subject: [PATCH 093/128] posix:  Ignore disk space reserve check for internal
d1681e
 FOPS
d1681e
d1681e
Problem: Currently disk space reserve check is applicable for internal FOP
d1681e
         also it needs to be ignore for internal FOP.
d1681e
d1681e
Solution: Update the DISK_SPACE_CHECK_AND_GOTO macro at posix component.
d1681e
          Macro will call only while key "GLUSTERFS_INTERNAL_FOP_KEY"
d1681e
          exists in xdata.
d1681e
d1681e
> BUG: 1506083
d1681e
> Change-Id: I2b0840bbf4fa14bc247855b024ca136773d68d16
d1681e
> Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
d1681e
> Reviwed on https://review.gluster.org/#/c/18567
d1681e
> (cherry picked from commit a320f2021ee4dcab85483dbe10d85e797bd6b3b4)
d1681e
d1681e
BUG: 1464350
d1681e
Change-Id: I2b0840bbf4fa14bc247855b024ca136773d68d16
d1681e
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/124878
d1681e
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d1681e
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
d1681e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
d1681e
---
d1681e
 xlators/storage/posix/src/posix-aio.c      |  2 +-
d1681e
 xlators/storage/posix/src/posix-helpers.c  | 12 +++----
d1681e
 xlators/storage/posix/src/posix-messages.h |  2 +-
d1681e
 xlators/storage/posix/src/posix.c          | 52 ++++++++++++++++--------------
d1681e
 xlators/storage/posix/src/posix.h          |  7 ++--
d1681e
 5 files changed, 38 insertions(+), 37 deletions(-)
d1681e
d1681e
diff --git a/xlators/storage/posix/src/posix-aio.c b/xlators/storage/posix/src/posix-aio.c
d1681e
index 2adafeb..47460bc 100644
d1681e
--- a/xlators/storage/posix/src/posix-aio.c
d1681e
+++ b/xlators/storage/posix/src/posix-aio.c
d1681e
@@ -330,7 +330,7 @@ posix_aio_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
d1681e
         VALIDATE_OR_GOTO (fd, err);
d1681e
 
d1681e
         priv = this->private;
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_errno, op_errno, err);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_errno, op_errno, err);
d1681e
 
d1681e
         ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
d1681e
         if (ret < 0) {
d1681e
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
d1681e
index 826441f..77affc4 100644
d1681e
--- a/xlators/storage/posix/src/posix-helpers.c
d1681e
+++ b/xlators/storage/posix/src/posix-helpers.c
d1681e
@@ -1990,10 +1990,10 @@ posix_disk_space_check (xlator_t *this)
d1681e
 
d1681e
         GF_VALIDATE_OR_GOTO (this->name, this, out);
d1681e
         priv = this->private;
d1681e
-        GF_VALIDATE_OR_GOTO ("posix-helpers", priv, out);
d1681e
+        GF_VALIDATE_OR_GOTO (this->name, priv, out);
d1681e
 
d1681e
         subvol_path = priv->base_path;
d1681e
-        percent = priv->disk_threshhold;
d1681e
+        percent = priv->disk_reserve;
d1681e
 
d1681e
         op_ret = sys_statvfs (subvol_path, &buf;;
d1681e
 
d1681e
@@ -2073,9 +2073,9 @@ posix_spawn_disk_space_check_thread (xlator_t *xl)
d1681e
                         priv->disk_space_check_active = _gf_false;
d1681e
                 }
d1681e
 
d1681e
-                ret = gf_thread_create (&priv->disk_space_check, NULL,
d1681e
-                                        posix_disk_space_check_thread_proc,
d1681e
-                                        xl, "posix_reserve");
d1681e
+                ret = gf_thread_create_detached (&priv->disk_space_check,
d1681e
+                                                 posix_disk_space_check_thread_proc,
d1681e
+                                                 xl, "posix_reserve");
d1681e
                 if (ret < 0) {
d1681e
                         priv->disk_space_check_active = _gf_false;
d1681e
                         gf_msg (xl->name, GF_LOG_ERROR, errno,
d1681e
@@ -2084,8 +2084,6 @@ posix_spawn_disk_space_check_thread (xlator_t *xl)
d1681e
                         goto unlock;
d1681e
                 }
d1681e
 
d1681e
-                /* run the thread detached, resources will be freed on exit */
d1681e
-                pthread_detach (priv->disk_space_check);
d1681e
                 priv->disk_space_check_active = _gf_true;
d1681e
         }
d1681e
 unlock:
d1681e
diff --git a/xlators/storage/posix/src/posix-messages.h b/xlators/storage/posix/src/posix-messages.h
d1681e
index 20cf1f0..fbae4d8 100644
d1681e
--- a/xlators/storage/posix/src/posix-messages.h
d1681e
+++ b/xlators/storage/posix/src/posix-messages.h
d1681e
@@ -45,7 +45,7 @@
d1681e
  */
d1681e
 
d1681e
 #define POSIX_COMP_BASE         GLFS_MSGID_COMP_POSIX
d1681e
-#define GLFS_NUM_MESSAGES       111
d1681e
+#define GLFS_NUM_MESSAGES       112
d1681e
 #define GLFS_MSGID_END          (POSIX_COMP_BASE + GLFS_NUM_MESSAGES + 1)
d1681e
 /* Messaged with message IDs */
d1681e
 #define glfs_msg_start_x POSIX_COMP_BASE, "Invalid: Start of messages"
d1681e
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
d1681e
index 1cb0fef..d0433ec 100644
d1681e
--- a/xlators/storage/posix/src/posix.c
d1681e
+++ b/xlators/storage/posix/src/posix.c
d1681e
@@ -777,7 +777,7 @@ posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
d1681e
         VALIDATE_OR_GOTO (fd, out);
d1681e
 
d1681e
         priv = this->private;
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, ret, ret, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, ret, ret, out);
d1681e
 
d1681e
         ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
d1681e
         if (ret < 0) {
d1681e
@@ -824,6 +824,8 @@ out:
d1681e
                 locked = _gf_false;
d1681e
         }
d1681e
         SET_TO_OLD_FS_ID ();
d1681e
+        if (ret == ENOSPC)
d1681e
+                ret = -ENOSPC;
d1681e
 
d1681e
         return ret;
d1681e
 }
d1681e
@@ -1079,18 +1081,21 @@ posix_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
d1681e
         struct  iatt statpost            = {0,};
d1681e
         struct  posix_private *priv      = NULL;
d1681e
         int     op_ret                   = -1;
d1681e
-        int     op_errno                 = -1;
d1681e
+        int     op_errno                 = -EINVAL;
d1681e
 
d1681e
         VALIDATE_OR_GOTO (frame, out);
d1681e
         VALIDATE_OR_GOTO (this, out);
d1681e
 
d1681e
         priv = this->private;
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         ret = posix_do_zerofill (frame, this, fd, offset, len,
d1681e
                                  &statpre, &statpost, xdata);
d1681e
-        if (ret < 0)
d1681e
+        if (ret < 0) {
d1681e
+                op_ret = -1;
d1681e
+                op_errno = -ret;
d1681e
                 goto out;
d1681e
+        }
d1681e
 
d1681e
         STACK_UNWIND_STRICT(zerofill, frame, 0, 0, &statpre, &statpost, NULL);
d1681e
         return 0;
d1681e
@@ -1365,13 +1370,12 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
         GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
d1681e
                                   out);
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
-
d1681e
         MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
d1681e
 
d1681e
         gid = frame->root->gid;
d1681e
 
d1681e
         SET_FS_ID (frame->root->uid, gid);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         if (!real_path || !par_path) {
d1681e
                 op_ret = -1;
d1681e
@@ -1586,7 +1590,7 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
         GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
d1681e
                                   out);
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
d1681e
         if (!real_path || !par_path) {
d1681e
@@ -2413,7 +2417,7 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
         GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
d1681e
                                   out);
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
d1681e
 
d1681e
@@ -2572,7 +2576,7 @@ posix_rename (call_frame_t *frame, xlator_t *this,
d1681e
 
d1681e
         priv = this->private;
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         SET_FS_ID (frame->root->uid, frame->root->gid);
d1681e
         MAKE_ENTRY_HANDLE (real_oldpath, par_oldpath, this, oldloc, NULL);
d1681e
@@ -2855,7 +2859,7 @@ posix_link (call_frame_t *frame, xlator_t *this,
d1681e
 
d1681e
         priv = this->private;
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         SET_FS_ID (frame->root->uid, frame->root->gid);
d1681e
         MAKE_INODE_HANDLE (real_oldpath, this, oldloc, &stbuf);
d1681e
@@ -3065,7 +3069,7 @@ posix_create (call_frame_t *frame, xlator_t *this,
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
         GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
d1681e
                                   out);
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
d1681e
 
d1681e
@@ -3254,7 +3258,7 @@ posix_open (call_frame_t *frame, xlator_t *this,
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
 
d1681e
         if (flags & O_CREAT)
d1681e
-                DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+                DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         MAKE_INODE_HANDLE (real_path, this, loc, &stbuf);
d1681e
         if (!real_path) {
d1681e
@@ -3579,7 +3583,7 @@ posix_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
d1681e
         priv = this->private;
d1681e
 
d1681e
         VALIDATE_OR_GOTO (priv, out);
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
d1681e
         if (ret < 0) {
d1681e
@@ -3744,7 +3748,7 @@ posix_statfs (call_frame_t *frame, xlator_t *this,
d1681e
                 goto out;
d1681e
         }
d1681e
 
d1681e
-        percent = priv->disk_threshhold;
d1681e
+        percent = priv->disk_reserve;
d1681e
         buf.f_bfree = (buf.f_bfree - ((buf.f_blocks * percent) / 100));
d1681e
 
d1681e
         shared_by = priv->shared_brick_count;
d1681e
@@ -4020,7 +4024,7 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
d1681e
         VALIDATE_OR_GOTO (dict, out);
d1681e
 
d1681e
         priv = this->private;
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         MAKE_INODE_HANDLE (real_path, this, loc, NULL);
d1681e
         if (!real_path) {
d1681e
@@ -5387,7 +5391,7 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
d1681e
         VALIDATE_OR_GOTO (dict, out);
d1681e
 
d1681e
         priv = this->private;
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
d1681e
         if (ret < 0) {
d1681e
@@ -6060,8 +6064,7 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
d1681e
         VALIDATE_OR_GOTO (this, out);
d1681e
 
d1681e
         priv = this->private;
d1681e
-        DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
d1681e
-
d1681e
+        DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
d1681e
 
d1681e
         if (fd) {
d1681e
                 op_ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
d1681e
@@ -7184,9 +7187,9 @@ reconfigure (xlator_t *this, dict_t *options)
d1681e
                         " fallback to <hostname>:<export>");
d1681e
         }
d1681e
 
d1681e
-        GF_OPTION_RECONF ("reserve", priv->disk_threshhold,
d1681e
+        GF_OPTION_RECONF ("reserve", priv->disk_reserve,
d1681e
                           options, uint32, out);
d1681e
-        if (priv->disk_threshhold)
d1681e
+        if (priv->disk_reserve)
d1681e
                 posix_spawn_disk_space_check_thread (this);
d1681e
 
d1681e
         GF_OPTION_RECONF ("health-check-interval", priv->health_check_interval,
d1681e
@@ -7790,8 +7793,8 @@ init (xlator_t *this)
d1681e
         _private->disk_space_check_active = _gf_false;
d1681e
         _private->disk_space_full          = 0;
d1681e
         GF_OPTION_INIT ("reserve",
d1681e
-                        _private->disk_threshhold, uint32, out);
d1681e
-        if (_private->disk_threshhold)
d1681e
+                        _private->disk_reserve, uint32, out);
d1681e
+        if (_private->disk_reserve)
d1681e
                 posix_spawn_disk_space_check_thread (this);
d1681e
 
d1681e
         _private->health_check_active = _gf_false;
d1681e
@@ -8002,9 +8005,8 @@ struct volume_options options[] = {
d1681e
           .min = 0,
d1681e
           .default_value = "1",
d1681e
           .validate = GF_OPT_VALIDATE_MIN,
d1681e
-          .description = "Value in percentage in integer form required "
d1681e
-           "to set reserve disk, "
d1681e
-           "set to 0 to disable"
d1681e
+          .description = "Percentage of disk space to be reserved."
d1681e
+           " Set to 0 to disable"
d1681e
         },
d1681e
 	{ .key = {"batch-fsync-mode"},
d1681e
 	  .type = GF_OPTION_TYPE_STR,
d1681e
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
d1681e
index 21c7d36..777adac 100644
d1681e
--- a/xlators/storage/posix/src/posix.h
d1681e
+++ b/xlators/storage/posix/src/posix.h
d1681e
@@ -63,8 +63,9 @@
d1681e
 #define GF_UNLINK_TRUE 0x0000000000000001
d1681e
 #define GF_UNLINK_FALSE 0x0000000000000000
d1681e
 
d1681e
-#define DISK_SPACE_CHECK_AND_GOTO(frame, priv, op_ret, op_errno, out)  do {   \
d1681e
-               if (frame->root->pid >= 0 && priv->disk_space_full) {          \
d1681e
+#define DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out)  do {   \
d1681e
+               if (frame->root->pid >= 0 && priv->disk_space_full &&          \
d1681e
+                        !dict_get (xdata, GLUSTERFS_INTERNAL_FOP_KEY)) {      \
d1681e
                         op_ret = -1;                                          \
d1681e
                         op_errno = ENOSPC;                                    \
d1681e
                         gf_msg_debug ("posix", ENOSPC,                        \
d1681e
@@ -209,7 +210,7 @@ struct posix_private {
d1681e
         pthread_t       health_check;
d1681e
         gf_boolean_t    health_check_active;
d1681e
 
d1681e
-        uint32_t        disk_threshhold;
d1681e
+        uint32_t        disk_reserve;
d1681e
         uint32_t        disk_space_full;
d1681e
         pthread_t       disk_space_check;
d1681e
         gf_boolean_t    disk_space_check_active;
d1681e
-- 
d1681e
1.8.3.1
d1681e