|
|
a3470f |
From 3b1c45188c7260ae3dda4bcedd7cb81566f1f2ea Mon Sep 17 00:00:00 2001
|
|
|
a3470f |
From: Mohit Agrawal <moagrawa@redhat.com>
|
|
|
a3470f |
Date: Sat, 15 Jul 2017 17:55:14 +0530
|
|
|
a3470f |
Subject: [PATCH 092/128] posix: Needs to reserve disk space to prevent the
|
|
|
a3470f |
brick from getting full
|
|
|
a3470f |
|
|
|
a3470f |
Problem: Currently there is no option available at posix xlator to save the
|
|
|
a3470f |
disk from getting full
|
|
|
a3470f |
|
|
|
a3470f |
Solution: Introduce a new option storage.reserve at posix xlator to
|
|
|
a3470f |
configure disk threshold.posix xlator spawn a thread to update the
|
|
|
a3470f |
disk space status in posix private structure and same flag is checked
|
|
|
a3470f |
by every posix fop before start operation.If flag value is 1 then
|
|
|
a3470f |
it sets op_errno to ENOSPC and goto out from the fop.
|
|
|
a3470f |
|
|
|
a3470f |
> BUG: 1471366
|
|
|
a3470f |
> Change-Id: I98287cd409860f4c754fc69a332e0521bfb1b67e
|
|
|
a3470f |
> Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
|
|
|
a3470f |
> Reviewed-on: https://review.gluster.org/17780
|
|
|
a3470f |
> Smoke: Gluster Build System <jenkins@build.gluster.org>
|
|
|
a3470f |
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
|
|
|
a3470f |
> Reviewed-by: Amar Tumballi <amarts@redhat.com>
|
|
|
a3470f |
> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
|
|
|
a3470f |
|
|
|
a3470f |
BUG: 1464350
|
|
|
a3470f |
Change-Id: I98287cd409860f4c754fc69a332e0521bfb1b67e
|
|
|
a3470f |
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
|
|
|
a3470f |
Reviewed-on: https://code.engineering.redhat.com/gerrit/124629
|
|
|
a3470f |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
a3470f |
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
a3470f |
---
|
|
|
a3470f |
xlators/mgmt/glusterd/src/glusterd-volume-set.c | 4 +
|
|
|
a3470f |
xlators/storage/posix/src/posix-aio.c | 1 +
|
|
|
a3470f |
xlators/storage/posix/src/posix-helpers.c | 115 ++++++++++++++++++++++++
|
|
|
a3470f |
xlators/storage/posix/src/posix-messages.h | 11 ++-
|
|
|
a3470f |
xlators/storage/posix/src/posix.c | 80 +++++++++++++++--
|
|
|
a3470f |
xlators/storage/posix/src/posix.h | 19 ++++
|
|
|
a3470f |
6 files changed, 222 insertions(+), 8 deletions(-)
|
|
|
a3470f |
|
|
|
a3470f |
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
|
|
|
a3470f |
index b15a5af..a57eb9e 100644
|
|
|
a3470f |
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
|
|
|
a3470f |
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
|
|
|
a3470f |
@@ -2805,6 +2805,10 @@ struct volopt_map_entry glusterd_volopt_map[] = {
|
|
|
a3470f |
.voltype = "storage/posix",
|
|
|
a3470f |
.op_version = GD_OP_VERSION_3_12_0,
|
|
|
a3470f |
},
|
|
|
a3470f |
+ { .key = "storage.reserve",
|
|
|
a3470f |
+ .voltype = "storage/posix",
|
|
|
a3470f |
+ .op_version = GD_OP_VERSION_3_13_0,
|
|
|
a3470f |
+ },
|
|
|
a3470f |
{ .key = "storage.bd-aio",
|
|
|
a3470f |
.voltype = "storage/bd",
|
|
|
a3470f |
.op_version = GD_OP_VERSION_RHS_3_0
|
|
|
a3470f |
diff --git a/xlators/storage/posix/src/posix-aio.c b/xlators/storage/posix/src/posix-aio.c
|
|
|
a3470f |
index b5ac1b9..2adafeb 100644
|
|
|
a3470f |
--- a/xlators/storage/posix/src/posix-aio.c
|
|
|
a3470f |
+++ b/xlators/storage/posix/src/posix-aio.c
|
|
|
a3470f |
@@ -330,6 +330,7 @@ posix_aio_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
|
|
|
a3470f |
VALIDATE_OR_GOTO (fd, err);
|
|
|
a3470f |
|
|
|
a3470f |
priv = this->private;
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_errno, op_errno, err);
|
|
|
a3470f |
|
|
|
a3470f |
ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
|
|
|
a3470f |
if (ret < 0) {
|
|
|
a3470f |
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
|
|
|
a3470f |
index f97c90b..826441f 100644
|
|
|
a3470f |
--- a/xlators/storage/posix/src/posix-helpers.c
|
|
|
a3470f |
+++ b/xlators/storage/posix/src/posix-helpers.c
|
|
|
a3470f |
@@ -1977,6 +1977,121 @@ unlock:
|
|
|
a3470f |
UNLOCK (&priv->lock);
|
|
|
a3470f |
}
|
|
|
a3470f |
|
|
|
a3470f |
+void
|
|
|
a3470f |
+posix_disk_space_check (xlator_t *this)
|
|
|
a3470f |
+{
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
+ char *subvol_path = NULL;
|
|
|
a3470f |
+ int op_ret = 0;
|
|
|
a3470f |
+ int percent = 0;
|
|
|
a3470f |
+ struct statvfs buf = {0};
|
|
|
a3470f |
+ uint64_t totsz = 0;
|
|
|
a3470f |
+ uint64_t freesz = 0;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ GF_VALIDATE_OR_GOTO (this->name, this, out);
|
|
|
a3470f |
+ priv = this->private;
|
|
|
a3470f |
+ GF_VALIDATE_OR_GOTO ("posix-helpers", priv, out);
|
|
|
a3470f |
+
|
|
|
a3470f |
+ subvol_path = priv->base_path;
|
|
|
a3470f |
+ percent = priv->disk_threshhold;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ op_ret = sys_statvfs (subvol_path, &buf;;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ if (op_ret == -1) {
|
|
|
a3470f |
+ gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_STATVFS_FAILED,
|
|
|
a3470f |
+ "statvfs failed on %s", subvol_path);
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+ totsz = (buf.f_blocks * buf.f_bsize);
|
|
|
a3470f |
+ freesz = (buf.f_bfree * buf.f_bsize);
|
|
|
a3470f |
+
|
|
|
a3470f |
+ if (freesz <= ((totsz * percent) / 100)) {
|
|
|
a3470f |
+ priv->disk_space_full = 1;
|
|
|
a3470f |
+ } else {
|
|
|
a3470f |
+ priv->disk_space_full = 0;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+out:
|
|
|
a3470f |
+ return;
|
|
|
a3470f |
+}
|
|
|
a3470f |
+
|
|
|
a3470f |
+
|
|
|
a3470f |
+static void *
|
|
|
a3470f |
+posix_disk_space_check_thread_proc (void *data)
|
|
|
a3470f |
+{
|
|
|
a3470f |
+ xlator_t *this = NULL;
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
+ uint32_t interval = 0;
|
|
|
a3470f |
+ int ret = -1;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ this = data;
|
|
|
a3470f |
+ priv = this->private;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ interval = 5;
|
|
|
a3470f |
+ gf_msg_debug (this->name, 0, "disk-space thread started, "
|
|
|
a3470f |
+ "interval = %d seconds", interval);
|
|
|
a3470f |
+ while (1) {
|
|
|
a3470f |
+ /* aborting sleep() is a request to exit this thread, sleep()
|
|
|
a3470f |
+ * will normally not return when cancelled */
|
|
|
a3470f |
+ ret = sleep (interval);
|
|
|
a3470f |
+ if (ret > 0)
|
|
|
a3470f |
+ break;
|
|
|
a3470f |
+ /* prevent thread errors while doing the health-check(s) */
|
|
|
a3470f |
+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
|
|
|
a3470f |
+
|
|
|
a3470f |
+ /* Do the disk-check.*/
|
|
|
a3470f |
+ posix_disk_space_check (this);
|
|
|
a3470f |
+ if (!priv->disk_space_check_active)
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+out:
|
|
|
a3470f |
+ gf_msg_debug (this->name, 0, "disk space check thread exiting");
|
|
|
a3470f |
+ LOCK (&priv->lock);
|
|
|
a3470f |
+ {
|
|
|
a3470f |
+ priv->disk_space_check_active = _gf_false;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+ UNLOCK (&priv->lock);
|
|
|
a3470f |
+
|
|
|
a3470f |
+
|
|
|
a3470f |
+ return NULL;
|
|
|
a3470f |
+}
|
|
|
a3470f |
+
|
|
|
a3470f |
+void
|
|
|
a3470f |
+posix_spawn_disk_space_check_thread (xlator_t *xl)
|
|
|
a3470f |
+{
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
+ int ret = -1;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ priv = xl->private;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ LOCK (&priv->lock);
|
|
|
a3470f |
+ {
|
|
|
a3470f |
+ /* cancel the running thread */
|
|
|
a3470f |
+ if (priv->disk_space_check_active == _gf_true) {
|
|
|
a3470f |
+ pthread_cancel (priv->disk_space_check);
|
|
|
a3470f |
+ priv->disk_space_check_active = _gf_false;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+ ret = gf_thread_create (&priv->disk_space_check, NULL,
|
|
|
a3470f |
+ posix_disk_space_check_thread_proc,
|
|
|
a3470f |
+ xl, "posix_reserve");
|
|
|
a3470f |
+ if (ret < 0) {
|
|
|
a3470f |
+ priv->disk_space_check_active = _gf_false;
|
|
|
a3470f |
+ gf_msg (xl->name, GF_LOG_ERROR, errno,
|
|
|
a3470f |
+ P_MSG_DISK_SPACE_CHECK_FAILED,
|
|
|
a3470f |
+ "unable to setup disk space check thread");
|
|
|
a3470f |
+ goto unlock;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+ /* run the thread detached, resources will be freed on exit */
|
|
|
a3470f |
+ pthread_detach (priv->disk_space_check);
|
|
|
a3470f |
+ priv->disk_space_check_active = _gf_true;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+unlock:
|
|
|
a3470f |
+ UNLOCK (&priv->lock);
|
|
|
a3470f |
+}
|
|
|
a3470f |
+
|
|
|
a3470f |
int
|
|
|
a3470f |
posix_fsyncer_pick (xlator_t *this, struct list_head *head)
|
|
|
a3470f |
{
|
|
|
a3470f |
diff --git a/xlators/storage/posix/src/posix-messages.h b/xlators/storage/posix/src/posix-messages.h
|
|
|
a3470f |
index ee06d6f..20cf1f0 100644
|
|
|
a3470f |
--- a/xlators/storage/posix/src/posix-messages.h
|
|
|
a3470f |
+++ b/xlators/storage/posix/src/posix-messages.h
|
|
|
a3470f |
@@ -45,7 +45,7 @@
|
|
|
a3470f |
*/
|
|
|
a3470f |
|
|
|
a3470f |
#define POSIX_COMP_BASE GLFS_MSGID_COMP_POSIX
|
|
|
a3470f |
-#define GLFS_NUM_MESSAGES 110
|
|
|
a3470f |
+#define GLFS_NUM_MESSAGES 111
|
|
|
a3470f |
#define GLFS_MSGID_END (POSIX_COMP_BASE + GLFS_NUM_MESSAGES + 1)
|
|
|
a3470f |
/* Messaged with message IDs */
|
|
|
a3470f |
#define glfs_msg_start_x POSIX_COMP_BASE, "Invalid: Start of messages"
|
|
|
a3470f |
@@ -955,6 +955,15 @@
|
|
|
a3470f |
*/
|
|
|
a3470f |
|
|
|
a3470f |
|
|
|
a3470f |
+#define P_MSG_DISK_SPACE_CHECK_FAILED (POSIX_COMP_BASE + 112)
|
|
|
a3470f |
+
|
|
|
a3470f |
+/*!
|
|
|
a3470f |
+ * @messageid
|
|
|
a3470f |
+ * @diagnosis
|
|
|
a3470f |
+ * @recommendedaction
|
|
|
a3470f |
+ *
|
|
|
a3470f |
+ */
|
|
|
a3470f |
+
|
|
|
a3470f |
/*------------*/
|
|
|
a3470f |
#define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
|
|
|
a3470f |
|
|
|
a3470f |
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
|
|
|
a3470f |
index d858878..1cb0fef 100644
|
|
|
a3470f |
--- a/xlators/storage/posix/src/posix.c
|
|
|
a3470f |
+++ b/xlators/storage/posix/src/posix.c
|
|
|
a3470f |
@@ -766,6 +766,7 @@ posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
|
|
|
a3470f |
struct posix_fd *pfd = NULL;
|
|
|
a3470f |
gf_boolean_t locked = _gf_false;
|
|
|
a3470f |
posix_inode_ctx_t *ctx = NULL;
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
|
|
|
a3470f |
DECLARE_OLD_FS_ID_VAR;
|
|
|
a3470f |
|
|
|
a3470f |
@@ -775,6 +776,9 @@ posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
|
|
|
a3470f |
VALIDATE_OR_GOTO (this, out);
|
|
|
a3470f |
VALIDATE_OR_GOTO (fd, out);
|
|
|
a3470f |
|
|
|
a3470f |
+ priv = this->private;
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, ret, ret, out);
|
|
|
a3470f |
+
|
|
|
a3470f |
ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
|
|
|
a3470f |
if (ret < 0) {
|
|
|
a3470f |
gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd);
|
|
|
a3470f |
@@ -1073,20 +1077,27 @@ posix_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
|
|
|
a3470f |
int32_t ret = 0;
|
|
|
a3470f |
struct iatt statpre = {0,};
|
|
|
a3470f |
struct iatt statpost = {0,};
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
+ int op_ret = -1;
|
|
|
a3470f |
+ int op_errno = -1;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ VALIDATE_OR_GOTO (frame, out);
|
|
|
a3470f |
+ VALIDATE_OR_GOTO (this, out);
|
|
|
a3470f |
+
|
|
|
a3470f |
+ priv = this->private;
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
ret = posix_do_zerofill (frame, this, fd, offset, len,
|
|
|
a3470f |
&statpre, &statpost, xdata);
|
|
|
a3470f |
- if (ret < 0) {
|
|
|
a3470f |
- goto err;
|
|
|
a3470f |
- }
|
|
|
a3470f |
+ if (ret < 0)
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
|
|
|
a3470f |
STACK_UNWIND_STRICT(zerofill, frame, 0, 0, &statpre, &statpost, NULL);
|
|
|
a3470f |
return 0;
|
|
|
a3470f |
|
|
|
a3470f |
-err:
|
|
|
a3470f |
- STACK_UNWIND_STRICT(zerofill, frame, -1, -ret, NULL, NULL, NULL);
|
|
|
a3470f |
+out:
|
|
|
a3470f |
+ STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, NULL, NULL, NULL);
|
|
|
a3470f |
return 0;
|
|
|
a3470f |
-
|
|
|
a3470f |
}
|
|
|
a3470f |
|
|
|
a3470f |
static int32_t
|
|
|
a3470f |
@@ -1354,6 +1365,7 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
|
|
|
a3470f |
out);
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
|
|
|
a3470f |
|
|
|
a3470f |
@@ -1574,6 +1586,7 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
|
|
|
a3470f |
out);
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
|
|
|
a3470f |
if (!real_path || !par_path) {
|
|
|
a3470f |
@@ -2400,6 +2413,7 @@ posix_symlink (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
|
|
|
a3470f |
out);
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
|
|
|
a3470f |
|
|
|
a3470f |
@@ -2558,6 +2572,7 @@ posix_rename (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
|
|
|
a3470f |
priv = this->private;
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
SET_FS_ID (frame->root->uid, frame->root->gid);
|
|
|
a3470f |
MAKE_ENTRY_HANDLE (real_oldpath, par_oldpath, this, oldloc, NULL);
|
|
|
a3470f |
@@ -2840,6 +2855,7 @@ posix_link (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
|
|
|
a3470f |
priv = this->private;
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
SET_FS_ID (frame->root->uid, frame->root->gid);
|
|
|
a3470f |
MAKE_INODE_HANDLE (real_oldpath, this, oldloc, &stbuf);
|
|
|
a3470f |
@@ -3049,6 +3065,7 @@ posix_create (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
|
|
|
a3470f |
out);
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
|
|
|
a3470f |
|
|
|
a3470f |
@@ -3236,6 +3253,9 @@ posix_open (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
priv = this->private;
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
|
|
|
a3470f |
+ if (flags & O_CREAT)
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
+
|
|
|
a3470f |
MAKE_INODE_HANDLE (real_path, this, loc, &stbuf);
|
|
|
a3470f |
if (!real_path) {
|
|
|
a3470f |
op_ret = -1;
|
|
|
a3470f |
@@ -3559,6 +3579,7 @@ posix_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
|
|
|
a3470f |
priv = this->private;
|
|
|
a3470f |
|
|
|
a3470f |
VALIDATE_OR_GOTO (priv, out);
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
|
|
|
a3470f |
ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
|
|
|
a3470f |
if (ret < 0) {
|
|
|
a3470f |
@@ -3698,6 +3719,7 @@ posix_statfs (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
struct statvfs buf = {0, };
|
|
|
a3470f |
struct posix_private * priv = NULL;
|
|
|
a3470f |
int shared_by = 1;
|
|
|
a3470f |
+ int percent = 0;
|
|
|
a3470f |
|
|
|
a3470f |
VALIDATE_OR_GOTO (frame, out);
|
|
|
a3470f |
VALIDATE_OR_GOTO (this, out);
|
|
|
a3470f |
@@ -3722,6 +3744,9 @@ posix_statfs (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
goto out;
|
|
|
a3470f |
}
|
|
|
a3470f |
|
|
|
a3470f |
+ percent = priv->disk_threshhold;
|
|
|
a3470f |
+ buf.f_bfree = (buf.f_bfree - ((buf.f_blocks * percent) / 100));
|
|
|
a3470f |
+
|
|
|
a3470f |
shared_by = priv->shared_brick_count;
|
|
|
a3470f |
if (shared_by > 1) {
|
|
|
a3470f |
buf.f_blocks /= shared_by;
|
|
|
a3470f |
@@ -3879,6 +3904,7 @@ posix_fsync (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
#endif
|
|
|
a3470f |
|
|
|
a3470f |
priv = this->private;
|
|
|
a3470f |
+
|
|
|
a3470f |
if (priv->batch_fsync_mode && xdata && dict_get (xdata, "batch-fsync")) {
|
|
|
a3470f |
posix_batch_fsync (frame, this, fd, datasync, xdata);
|
|
|
a3470f |
return 0;
|
|
|
a3470f |
@@ -3983,6 +4009,7 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
ssize_t acl_size = 0;
|
|
|
a3470f |
dict_t *xattr = NULL;
|
|
|
a3470f |
posix_xattr_filler_t filler = {0,};
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
|
|
|
a3470f |
DECLARE_OLD_FS_ID_VAR;
|
|
|
a3470f |
SET_FS_ID (frame->root->uid, frame->root->gid);
|
|
|
a3470f |
@@ -3992,6 +4019,9 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
VALIDATE_OR_GOTO (loc, out);
|
|
|
a3470f |
VALIDATE_OR_GOTO (dict, out);
|
|
|
a3470f |
|
|
|
a3470f |
+ priv = this->private;
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
+
|
|
|
a3470f |
MAKE_INODE_HANDLE (real_path, this, loc, NULL);
|
|
|
a3470f |
if (!real_path) {
|
|
|
a3470f |
op_ret = -1;
|
|
|
a3470f |
@@ -5346,6 +5376,7 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
struct iatt stbuf = {0,};
|
|
|
a3470f |
dict_t *xattr = NULL;
|
|
|
a3470f |
posix_xattr_filler_t filler = {0,};
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
|
|
|
a3470f |
DECLARE_OLD_FS_ID_VAR;
|
|
|
a3470f |
SET_FS_ID (frame->root->uid, frame->root->gid);
|
|
|
a3470f |
@@ -5355,6 +5386,9 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
VALIDATE_OR_GOTO (fd, out);
|
|
|
a3470f |
VALIDATE_OR_GOTO (dict, out);
|
|
|
a3470f |
|
|
|
a3470f |
+ priv = this->private;
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
+
|
|
|
a3470f |
ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
|
|
|
a3470f |
if (ret < 0) {
|
|
|
a3470f |
gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
|
|
|
a3470f |
@@ -6018,11 +6052,17 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
|
|
|
a3470f |
dict_t *xattr_rsp = NULL;
|
|
|
a3470f |
dict_t *xdata_rsp = NULL;
|
|
|
a3470f |
struct iatt stbuf = {0};
|
|
|
a3470f |
+ struct posix_private *priv = NULL;
|
|
|
a3470f |
+
|
|
|
a3470f |
|
|
|
a3470f |
VALIDATE_OR_GOTO (frame, out);
|
|
|
a3470f |
VALIDATE_OR_GOTO (xattr, out);
|
|
|
a3470f |
VALIDATE_OR_GOTO (this, out);
|
|
|
a3470f |
|
|
|
a3470f |
+ priv = this->private;
|
|
|
a3470f |
+ DISK_SPACE_CHECK_AND_GOTO (frame, priv, op_ret, op_errno, out);
|
|
|
a3470f |
+
|
|
|
a3470f |
+
|
|
|
a3470f |
if (fd) {
|
|
|
a3470f |
op_ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
|
|
|
a3470f |
if (op_ret < 0) {
|
|
|
a3470f |
@@ -6120,7 +6160,6 @@ posix_fxattrop (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
return 0;
|
|
|
a3470f |
}
|
|
|
a3470f |
|
|
|
a3470f |
-
|
|
|
a3470f |
int
|
|
|
a3470f |
posix_access (call_frame_t *frame, xlator_t *this,
|
|
|
a3470f |
loc_t *loc, int32_t mask, dict_t *xdata)
|
|
|
a3470f |
@@ -6944,6 +6983,11 @@ notify (xlator_t *this,
|
|
|
a3470f |
pthread_cancel (priv->health_check);
|
|
|
a3470f |
priv->health_check = 0;
|
|
|
a3470f |
}
|
|
|
a3470f |
+ if (priv->disk_space_check) {
|
|
|
a3470f |
+ priv->disk_space_check_active = _gf_false;
|
|
|
a3470f |
+ pthread_cancel (priv->disk_space_check);
|
|
|
a3470f |
+ priv->disk_space_check = 0;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
if (priv->janitor) {
|
|
|
a3470f |
(void) gf_thread_cleanup_xint (priv->janitor);
|
|
|
a3470f |
priv->janitor = 0;
|
|
|
a3470f |
@@ -7140,6 +7184,11 @@ reconfigure (xlator_t *this, dict_t *options)
|
|
|
a3470f |
" fallback to <hostname>:<export>");
|
|
|
a3470f |
}
|
|
|
a3470f |
|
|
|
a3470f |
+ GF_OPTION_RECONF ("reserve", priv->disk_threshhold,
|
|
|
a3470f |
+ options, uint32, out);
|
|
|
a3470f |
+ if (priv->disk_threshhold)
|
|
|
a3470f |
+ posix_spawn_disk_space_check_thread (this);
|
|
|
a3470f |
+
|
|
|
a3470f |
GF_OPTION_RECONF ("health-check-interval", priv->health_check_interval,
|
|
|
a3470f |
options, uint32, out);
|
|
|
a3470f |
posix_spawn_health_check_thread (this);
|
|
|
a3470f |
@@ -7738,6 +7787,13 @@ init (xlator_t *this)
|
|
|
a3470f |
" fallback to <hostname>:<export>");
|
|
|
a3470f |
}
|
|
|
a3470f |
|
|
|
a3470f |
+ _private->disk_space_check_active = _gf_false;
|
|
|
a3470f |
+ _private->disk_space_full = 0;
|
|
|
a3470f |
+ GF_OPTION_INIT ("reserve",
|
|
|
a3470f |
+ _private->disk_threshhold, uint32, out);
|
|
|
a3470f |
+ if (_private->disk_threshhold)
|
|
|
a3470f |
+ posix_spawn_disk_space_check_thread (this);
|
|
|
a3470f |
+
|
|
|
a3470f |
_private->health_check_active = _gf_false;
|
|
|
a3470f |
GF_OPTION_INIT ("health-check-interval",
|
|
|
a3470f |
_private->health_check_interval, uint32, out);
|
|
|
a3470f |
@@ -7940,6 +7996,16 @@ struct volume_options options[] = {
|
|
|
a3470f |
.description = "Interval in seconds for a filesystem health check, "
|
|
|
a3470f |
"set to 0 to disable"
|
|
|
a3470f |
},
|
|
|
a3470f |
+ {
|
|
|
a3470f |
+ .key = {"reserve"},
|
|
|
a3470f |
+ .type = GF_OPTION_TYPE_INT,
|
|
|
a3470f |
+ .min = 0,
|
|
|
a3470f |
+ .default_value = "1",
|
|
|
a3470f |
+ .validate = GF_OPT_VALIDATE_MIN,
|
|
|
a3470f |
+ .description = "Value in percentage in integer form required "
|
|
|
a3470f |
+ "to set reserve disk, "
|
|
|
a3470f |
+ "set to 0 to disable"
|
|
|
a3470f |
+ },
|
|
|
a3470f |
{ .key = {"batch-fsync-mode"},
|
|
|
a3470f |
.type = GF_OPTION_TYPE_STR,
|
|
|
a3470f |
.default_value = "reverse-fsync",
|
|
|
a3470f |
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
|
|
|
a3470f |
index c2dcfda..21c7d36 100644
|
|
|
a3470f |
--- a/xlators/storage/posix/src/posix.h
|
|
|
a3470f |
+++ b/xlators/storage/posix/src/posix.h
|
|
|
a3470f |
@@ -63,6 +63,18 @@
|
|
|
a3470f |
#define GF_UNLINK_TRUE 0x0000000000000001
|
|
|
a3470f |
#define GF_UNLINK_FALSE 0x0000000000000000
|
|
|
a3470f |
|
|
|
a3470f |
+#define DISK_SPACE_CHECK_AND_GOTO(frame, priv, op_ret, op_errno, out) do { \
|
|
|
a3470f |
+ if (frame->root->pid >= 0 && priv->disk_space_full) { \
|
|
|
a3470f |
+ op_ret = -1; \
|
|
|
a3470f |
+ op_errno = ENOSPC; \
|
|
|
a3470f |
+ gf_msg_debug ("posix", ENOSPC, \
|
|
|
a3470f |
+ "disk space utilization reached limits" \
|
|
|
a3470f |
+ " for path %s ", priv->base_path); \
|
|
|
a3470f |
+ goto out; \
|
|
|
a3470f |
+ } \
|
|
|
a3470f |
+ } while (0)
|
|
|
a3470f |
+
|
|
|
a3470f |
+
|
|
|
a3470f |
/**
|
|
|
a3470f |
* posix_fd - internal structure common to file and directory fd's
|
|
|
a3470f |
*/
|
|
|
a3470f |
@@ -197,6 +209,11 @@ struct posix_private {
|
|
|
a3470f |
pthread_t health_check;
|
|
|
a3470f |
gf_boolean_t health_check_active;
|
|
|
a3470f |
|
|
|
a3470f |
+ uint32_t disk_threshhold;
|
|
|
a3470f |
+ uint32_t disk_space_full;
|
|
|
a3470f |
+ pthread_t disk_space_check;
|
|
|
a3470f |
+ gf_boolean_t disk_space_check_active;
|
|
|
a3470f |
+
|
|
|
a3470f |
#ifdef GF_DARWIN_HOST_OS
|
|
|
a3470f |
enum {
|
|
|
a3470f |
XATTR_NONE = 0,
|
|
|
a3470f |
@@ -304,6 +321,8 @@ __posix_fd_set_odirect (fd_t *fd, struct posix_fd *pfd, int opflags,
|
|
|
a3470f |
off_t offset, size_t size);
|
|
|
a3470f |
void posix_spawn_health_check_thread (xlator_t *this);
|
|
|
a3470f |
|
|
|
a3470f |
+void posix_spawn_disk_space_check_thread (xlator_t *this);
|
|
|
a3470f |
+
|
|
|
a3470f |
void *posix_fsyncer (void *);
|
|
|
a3470f |
int
|
|
|
a3470f |
posix_get_ancestry (xlator_t *this, inode_t *leaf_inode,
|
|
|
a3470f |
--
|
|
|
a3470f |
1.8.3.1
|
|
|
a3470f |
|