diff options
author | Shreyas Siravara <sshreyas@fb.com> | 2017-09-07 16:36:29 -0700 |
---|---|---|
committer | Shreyas Siravara <sshreyas@fb.com> | 2017-09-08 00:13:22 +0000 |
commit | 5c2015a5d84f176d68d704c21602d7131ca7dfda (patch) | |
tree | e1faace4f0342f0d94a1e818b82bb28a200d03b1 | |
parent | 9423bc2223227661453a8afd5ab940048abeb008 (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>
-rw-r--r-- | tests/basic/hardlink-limit.t | 44 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 4 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix.c | 30 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix.h | 1 |
4 files changed, 77 insertions, 2 deletions
diff --git a/tests/basic/hardlink-limit.t b/tests/basic/hardlink-limit.t new file mode 100644 index 00000000000..e90a3ce427c --- /dev/null +++ b/tests/basic/hardlink-limit.t @@ -0,0 +1,44 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc +. $(dirname $0)/../dht.rc + +cleanup; + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume info; + +TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2,3,4}; + +EXPECT "$V0" volinfo_field $V0 'Volume Name'; +EXPECT 'Created' volinfo_field $V0 'Status'; +EXPECT '4' brick_count $V0 + +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; +TEST $CLI volume set $V0 storage.max-hardlinks 3 +TEST glusterfs -s $H0 --volfile-id $V0 $M0; + +TEST dd if=/dev/zero of=$M0/testfile count=1 + +# max-hardlinks is 3, should be able to create 2 links. +TEST link $M0/testfile $M0/testfile.link1 +TEST link $M0/testfile $M0/testfile.link2 + +# But not 3. +TEST ! link $M0/testfile $M0/testfile.link3 +# If we remove one... +TEST rm $M0/testfile.link1 +# Now we can add one. +TEST link $M0/testfile $M0/testfile.link3 + +# But not another +TEST ! link $M0/testfile $M0/testfile.link4 + +# Unless we disable the limit... +TEST $CLI volume set $V0 storage.max-hardlinks 0 +TEST link $M0/testfile $M0/testfile.link4 + +cleanup; diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index a4a0096d17d..7345dd714d3 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -2579,6 +2579,10 @@ struct volopt_map_entry glusterd_volopt_map[] = { .voltype = "storage/posix", .op_version = 2, }, + { .key = "storage.max-hardlinks", + .voltype = "storage/posix", + .op_version = 2, + }, { .key = "storage.bd-aio", .voltype = "storage/bd", .op_version = 3 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 { |