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