summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src
diff options
context:
space:
mode:
authorShreyas Siravara <sshreyas@fb.com>2017-09-07 16:36:29 -0700
committerShreyas Siravara <sshreyas@fb.com>2017-09-08 00:13:22 +0000
commit5c2015a5d84f176d68d704c21602d7131ca7dfda (patch)
treee1faace4f0342f0d94a1e818b82bb28a200d03b1 /xlators/storage/posix/src
parent9423bc2223227661453a8afd5ab940048abeb008 (diff)
storage/posix: Add limit to number of hard links.
Summary: Too may hard links blow up btrfs by exceeding max xattr size (recordign pgfid for each hardlink). Add a limit to prevent this explosion. This is a port D4682329 to 3.8 Reviewed By: sshreyas Change-Id: I614a247834fb8f2b2743c0c67d11cefafff0dbaa Reviewed-on: https://review.gluster.org/18232 Reviewed-by: Shreyas Siravara <sshreyas@fb.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Smoke: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'xlators/storage/posix/src')
-rw-r--r--xlators/storage/posix/src/posix.c30
-rw-r--r--xlators/storage/posix/src/posix.h1
2 files changed, 29 insertions, 2 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 4105bff323f..d4b8effd6da 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -2785,6 +2785,16 @@ posix_link (call_frame_t *frame, xlator_t *this,
goto out;
}
+ if (priv->max_hardlinks && stbuf.ia_nlink >= priv->max_hardlinks) {
+ op_ret = -1;
+ op_errno = EMLINK;
+ gf_log (this->name, GF_LOG_ERROR,
+ "hardlink failed: %s exceeds max link count (%u/%u).",
+ real_oldpath, stbuf.ia_nlink, priv->max_hardlinks);
+ goto out;
+ }
+
+
MAKE_ENTRY_HANDLE (real_newpath, par_newpath, this, newloc, &stbuf);
if (!real_newpath || !par_newpath) {
op_ret = -1;
@@ -6883,7 +6893,13 @@ struct posix_private *priv = NULL;
}
pthread_mutex_unlock (&priv->freespace_check_lock);
- ret = 0;
+ GF_OPTION_RECONF ("fadvise-random", priv->fadvise_random,
+ options, bool, out);
+
+ GF_OPTION_RECONF ("max-hardlinks", priv->max_hardlinks,
+ options, uint32, out);
+
+ ret = 0;
out:
return ret;
}
@@ -7506,6 +7522,8 @@ init (xlator_t *this)
GF_OPTION_INIT ("fadvise-random", _private->fadvise_random, bool, out);
+ GF_OPTION_INIT ("max-hardlinks", _private->max_hardlinks, uint32, out);
+
pthread_mutex_init (&_private->freespace_check_lock, NULL);
sys_statvfs (_private->base_path, &_private->freespace_stats);
clock_gettime (CLOCK_MONOTONIC, &_private->freespace_check_last);
@@ -7712,6 +7730,14 @@ struct volume_options options[] = {
.description = "fadvise fd's with POSIX_FADV_RANDOM to bypass "
"read-ahead limits",
},
-
+ {
+ .key = {"max-hardlinks"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0,
+ .default_value = "100",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .description = "max number of hardlinks allowed on any one inode.\n"
+ "0 is unlimited, 1 prevents any hardlinking at all."
+ },
{ .key = {NULL} }
};
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index 6dde604cc0c..794f06c8ada 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -183,6 +183,7 @@ struct posix_private {
uint32_t freespace_check_interval;
gf_boolean_t freespace_check_passed;
gf_boolean_t fadvise_random;
+ uint32_t max_hardlinks;
};
typedef struct {