From 5cbc87d8b8f1287e81c38b793b8d13b057208c62 Mon Sep 17 00:00:00 2001 From: Sheetal Pamecha Date: Wed, 19 Jun 2019 15:08:58 +0530 Subject: posix: modify storage.reserve option to take size and percent * reverting changes made in https://review.gluster.org/#/c/glusterfs/+/21686/ * Now storage.reserve can take value in percent or bytes fixes: bz#1651445 Change-Id: Id4826210ec27991c55b17d1fecd90356bff3e036 Signed-off-by: Sheetal Pamecha --- xlators/storage/posix/src/posix-common.c | 33 ++++++++++++-------------- xlators/storage/posix/src/posix-helpers.c | 26 ++++++++++---------- xlators/storage/posix/src/posix-inode-fd-ops.c | 15 +++++++----- xlators/storage/posix/src/posix.h | 4 ++-- 4 files changed, 39 insertions(+), 39 deletions(-) (limited to 'xlators/storage/posix') diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c index a2b94256e3f..a80cf963d89 100644 --- a/xlators/storage/posix/src/posix-common.c +++ b/xlators/storage/posix/src/posix-common.c @@ -335,12 +335,14 @@ posix_reconfigure(xlator_t *this, dict_t *options) " fallback to :"); } - GF_OPTION_RECONF("reserve-size", priv->disk_reserve_size, options, size, + GF_OPTION_RECONF("reserve", priv->disk_reserve, options, percent_or_size, out); + /* option can be any one of percent or bytes */ + priv->disk_unit = 0; + if (priv->disk_reserve < 100.0) + priv->disk_unit = 'p'; - GF_OPTION_RECONF("reserve", priv->disk_reserve_percent, options, uint32, - out); - if (priv->disk_reserve_size || priv->disk_reserve_percent) { + if (priv->disk_reserve) { ret = posix_spawn_disk_space_check_thread(this); if (ret) { gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_DISK_SPACE_CHECK_FAILED, @@ -964,11 +966,15 @@ posix_init(xlator_t *this) _private->disk_space_check_active = _gf_false; _private->disk_space_full = 0; - GF_OPTION_INIT("reserve-size", _private->disk_reserve_size, size, out); - GF_OPTION_INIT("reserve", _private->disk_reserve_percent, uint32, out); + GF_OPTION_INIT("reserve", _private->disk_reserve, percent_or_size, out); + + /* option can be any one of percent or bytes */ + _private->disk_unit = 0; + if (_private->disk_reserve < 100.0) + _private->disk_unit = 'p'; - if (_private->disk_reserve_size || _private->disk_reserve_percent) { + if (_private->disk_reserve) { ret = posix_spawn_disk_space_check_thread(this); if (ret) { gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_DISK_SPACE_CHECK_FAILED, @@ -1210,23 +1216,14 @@ struct volume_options posix_options[] = { .op_version = {GD_OP_VERSION_4_0_0}, .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, {.key = {"reserve"}, - .type = GF_OPTION_TYPE_INT, + .type = GF_OPTION_TYPE_PERCENT_OR_SIZET, .min = 0, .default_value = "1", .validate = GF_OPT_VALIDATE_MIN, - .description = "Percentage of disk space to be reserved." + .description = "Percentage/Size of disk space to be reserved." " Set to 0 to disable", .op_version = {GD_OP_VERSION_3_13_0}, .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, - {.key = {"reserve-size"}, - .type = GF_OPTION_TYPE_SIZET, - .min = 0, - .default_value = "0", - .validate = GF_OPT_VALIDATE_MIN, - .description = "size in megabytes to be reserved for disk space." - " Set to 0 to disable", - .op_version = {GD_OP_VERSION_7_0}, - .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC}, {.key = {"batch-fsync-mode"}, .type = GF_OPTION_TYPE_STR, .default_value = "reverse-fsync", diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index a0c273fa772..5fa73bff7cd 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -2257,11 +2257,11 @@ posix_disk_space_check(xlator_t *this) struct posix_private *priv = NULL; char *subvol_path = NULL; int op_ret = 0; - uint64_t size = 0; - int percent = 0; + double size = 0; + double percent = 0; struct statvfs buf = {0}; - uint64_t totsz = 0; - uint64_t freesz = 0; + double totsz = 0; + double freesz = 0; GF_VALIDATE_OR_GOTO(this->name, this, out); priv = this->private; @@ -2269,14 +2269,6 @@ posix_disk_space_check(xlator_t *this) subvol_path = priv->base_path; - if (priv->disk_reserve_size) { - size = priv->disk_reserve_size; - } else { - percent = priv->disk_reserve_percent; - totsz = (buf.f_blocks * buf.f_bsize); - size = ((totsz * percent) / 100); - } - op_ret = sys_statvfs(subvol_path, &buf); if (op_ret == -1) { @@ -2284,8 +2276,16 @@ posix_disk_space_check(xlator_t *this) "statvfs failed on %s", subvol_path); goto out; } - freesz = (buf.f_bfree * buf.f_bsize); + if (priv->disk_unit == 'p') { + percent = priv->disk_reserve; + totsz = (buf.f_blocks * buf.f_bsize); + size = ((totsz * percent) / 100); + } else { + size = priv->disk_reserve; + } + + freesz = (buf.f_bfree * buf.f_bsize); if (freesz <= size) { priv->disk_space_full = 1; } else { diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c index cf74327e1f5..09018165f91 100644 --- a/xlators/storage/posix/src/posix-inode-fd-ops.c +++ b/xlators/storage/posix/src/posix-inode-fd-ops.c @@ -719,7 +719,7 @@ posix_do_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, thread after every 5 sec sleep to working correctly storage.reserve option behaviour */ - if (priv->disk_reserve_size || priv->disk_reserve_percent) + if (priv->disk_reserve) posix_disk_space_check(this); DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, ret, ret, out); @@ -2313,7 +2313,7 @@ posix_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) }; struct posix_private *priv = NULL; int shared_by = 1; - int percent = 0; + double percent = 0; uint64_t reserved_blocks = 0; VALIDATE_OR_GOTO(frame, out); @@ -2340,11 +2340,14 @@ posix_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) goto out; } - if (priv->disk_reserve_size) { - reserved_blocks = priv->disk_reserve_size / buf.f_bsize; + if (priv->disk_unit == 'p') { + percent = priv->disk_reserve; + reserved_blocks = (((buf.f_blocks * percent) / 100) + 0.5); } else { - percent = priv->disk_reserve_percent; - reserved_blocks = (buf.f_blocks * percent) / 100; + if (buf.f_bsize) { + reserved_blocks = (priv->disk_reserve + buf.f_bsize - 1) / + buf.f_bsize; + } } if (buf.f_bfree > reserved_blocks) { diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index da590b53e1b..963daf3f148 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -222,8 +222,8 @@ struct posix_private { pthread_t health_check; gf_boolean_t health_check_active; - uint32_t disk_reserve_percent; - uint64_t disk_reserve_size; + double disk_reserve; + char disk_unit; uint32_t disk_space_full; pthread_t disk_space_check; gf_boolean_t disk_space_check_active; -- cgit