diff options
Diffstat (limited to 'xlators/storage/posix/src/posix.c')
-rw-r--r-- | xlators/storage/posix/src/posix.c | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 180da9e2c08..ceb9d448025 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -735,6 +735,7 @@ posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd, struct posix_fd *pfd = NULL; gf_boolean_t locked = _gf_false; posix_inode_ctx_t *ctx = NULL; + struct posix_private *priv = NULL; DECLARE_OLD_FS_ID_VAR; @@ -744,6 +745,9 @@ posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd, VALIDATE_OR_GOTO (this, out); VALIDATE_OR_GOTO (fd, out); + priv = this->private; + DISK_SPACE_CHECK_AND_GOTO (frame, priv, ret, ret, out); + ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno); if (ret < 0) { gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd); @@ -1042,19 +1046,27 @@ posix_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, int32_t ret = 0; struct iatt statpre = {0,}; struct iatt statpost = {0,}; + struct posix_private *priv = NULL; + int op_ret = -1; + int op_errno = -1; + + 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); ret = posix_do_zerofill (frame, this, fd, offset, len, &statpre, &statpost, xdata); if (ret < 0) - goto err; + goto out; STACK_UNWIND_STRICT(zerofill, frame, 0, 0, &statpre, &statpost, NULL); return 0; -err: - STACK_UNWIND_STRICT(zerofill, frame, -1, -ret, NULL, NULL, NULL); +out: + STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, NULL, NULL, NULL); return 0; - } static int32_t @@ -1320,6 +1332,7 @@ posix_mknod (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); MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL); @@ -1538,6 +1551,7 @@ posix_mkdir (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); MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL); if (!real_path || !par_path) { @@ -2351,6 +2365,7 @@ posix_symlink (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); MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf); @@ -2509,6 +2524,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); SET_FS_ID (frame->root->uid, frame->root->gid); MAKE_ENTRY_HANDLE (real_oldpath, par_oldpath, this, oldloc, NULL); @@ -2791,6 +2807,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); SET_FS_ID (frame->root->uid, frame->root->gid); MAKE_INODE_HANDLE (real_oldpath, this, oldloc, &stbuf); @@ -2998,6 +3015,7 @@ posix_create (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); MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf); @@ -3185,6 +3203,9 @@ posix_open (call_frame_t *frame, xlator_t *this, priv = this->private; VALIDATE_OR_GOTO (priv, out); + if (flags & O_CREAT) + DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out); + MAKE_INODE_HANDLE (real_path, this, loc, &stbuf); if (!real_path) { op_ret = -1; @@ -3508,6 +3529,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); ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno); if (ret < 0) { @@ -3647,6 +3669,7 @@ posix_statfs (call_frame_t *frame, xlator_t *this, struct statvfs buf = {0, }; struct posix_private * priv = NULL; int shared_by = 1; + int percent = 0; VALIDATE_OR_GOTO (frame, out); VALIDATE_OR_GOTO (this, out); @@ -3671,6 +3694,9 @@ posix_statfs (call_frame_t *frame, xlator_t *this, goto out; } + percent = priv->disk_threshhold; + buf.f_bfree = (buf.f_bfree - ((buf.f_blocks * percent) / 100)); + shared_by = priv->shared_brick_count; if (shared_by > 1) { buf.f_blocks /= shared_by; @@ -3828,6 +3854,7 @@ posix_fsync (call_frame_t *frame, xlator_t *this, #endif priv = this->private; + if (priv->batch_fsync_mode && xdata && dict_get (xdata, "batch-fsync")) { posix_batch_fsync (frame, this, fd, datasync, xdata); return 0; @@ -3932,6 +3959,7 @@ posix_setxattr (call_frame_t *frame, xlator_t *this, ssize_t acl_size = 0; dict_t *xattr = NULL; posix_xattr_filler_t filler = {0,}; + struct posix_private *priv = NULL; DECLARE_OLD_FS_ID_VAR; SET_FS_ID (frame->root->uid, frame->root->gid); @@ -3941,6 +3969,9 @@ posix_setxattr (call_frame_t *frame, xlator_t *this, VALIDATE_OR_GOTO (loc, out); VALIDATE_OR_GOTO (dict, out); + priv = this->private; + DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out); + MAKE_INODE_HANDLE (real_path, this, loc, NULL); if (!real_path) { op_ret = -1; @@ -5278,6 +5309,7 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this, struct iatt stbuf = {0,}; dict_t *xattr = NULL; posix_xattr_filler_t filler = {0,}; + struct posix_private *priv = NULL; DECLARE_OLD_FS_ID_VAR; SET_FS_ID (frame->root->uid, frame->root->gid); @@ -5287,6 +5319,9 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this, VALIDATE_OR_GOTO (fd, out); VALIDATE_OR_GOTO (dict, out); + priv = this->private; + DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out); + ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno); if (ret < 0) { gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL, @@ -5950,11 +5985,17 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, dict_t *xattr_rsp = NULL; dict_t *xdata_rsp = NULL; struct iatt stbuf = {0}; + struct posix_private *priv = NULL; + VALIDATE_OR_GOTO (frame, out); VALIDATE_OR_GOTO (xattr, out); VALIDATE_OR_GOTO (this, out); + priv = this->private; + DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out); + + if (fd) { op_ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno); if (op_ret < 0) { @@ -6052,7 +6093,6 @@ posix_fxattrop (call_frame_t *frame, xlator_t *this, return 0; } - int posix_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask, dict_t *xdata) @@ -6876,6 +6916,11 @@ notify (xlator_t *this, pthread_cancel (priv->health_check); priv->health_check = 0; } + if (priv->disk_space_check) { + priv->disk_space_check_active = _gf_false; + pthread_cancel (priv->disk_space_check); + priv->disk_space_check = 0; + } if (priv->janitor) { (void) gf_thread_cleanup_xint (priv->janitor); priv->janitor = 0; @@ -7051,6 +7096,11 @@ reconfigure (xlator_t *this, dict_t *options) " fallback to <hostname>:<export>"); } + GF_OPTION_RECONF ("reserve", priv->disk_threshhold, + options, uint32, out); + if (priv->disk_threshhold) + posix_spawn_disk_space_check_thread (this); + GF_OPTION_RECONF ("health-check-interval", priv->health_check_interval, options, uint32, out); posix_spawn_health_check_thread (this); @@ -7660,6 +7710,13 @@ init (xlator_t *this) " fallback to <hostname>:<export>"); } + _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) + posix_spawn_disk_space_check_thread (this); + _private->health_check_active = _gf_false; GF_OPTION_INIT ("health-check-interval", _private->health_check_interval, uint32, out); @@ -7853,6 +7910,16 @@ struct volume_options options[] = { .description = "Interval in seconds for a filesystem health check, " "set to 0 to disable" }, + { + .key = {"reserve"}, + .type = GF_OPTION_TYPE_INT, + .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" + }, { .key = {"batch-fsync-mode"}, .type = GF_OPTION_TYPE_STR, .default_value = "reverse-fsync", |