summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/storage/posix')
-rw-r--r--xlators/storage/posix/src/posix-common.c16
-rw-r--r--xlators/storage/posix/src/posix-entry-ops.c9
-rw-r--r--xlators/storage/posix/src/posix.h1
3 files changed, 26 insertions, 0 deletions
diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c
index 011bef8a720..1b2bb609fb0 100644
--- a/xlators/storage/posix/src/posix-common.c
+++ b/xlators/storage/posix/src/posix-common.c
@@ -398,6 +398,8 @@ posix_reconfigure (xlator_t *this, dict_t *options)
options, int32, out);
priv->create_directory_mask = create_directory_mask;
+ GF_OPTION_RECONF ("max-hardlinks", priv->max_hardlinks,
+ options, uint32, out);
ret = 0;
out:
return ret;
@@ -1075,6 +1077,8 @@ posix_init (xlator_t *this)
GF_OPTION_INIT ("create-directory-mask",
create_directory_mask, int32, out);
_private->create_directory_mask = create_directory_mask;
+
+ GF_OPTION_INIT ("max-hardlinks", _private->max_hardlinks, uint32, out);
out:
if (ret) {
if (_private) {
@@ -1322,5 +1326,17 @@ struct volume_options options[] = {
.description = "Any bit not set here will be removed from the"
"modes set on a directory when it is created"
},
+ {
+ .key = {"max-hardlinks"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0,
+ .default_value = "100",
+ .op_version = {GD_OP_VERSION_4_0_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
+ .tags = {"posix"},
+ .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-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c
index 7a83eb3dfba..e7658e46543 100644
--- a/xlators/storage/posix/src/posix-entry-ops.c
+++ b/xlators/storage/posix/src/posix-entry-ops.c
@@ -1814,6 +1814,15 @@ 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;
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index 36348767870..afb4b4413f6 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -239,6 +239,7 @@ struct posix_private {
mode_t force_directory_mode;
mode_t create_mask;
mode_t create_directory_mask;
+ uint32_t max_hardlinks;
};
typedef struct {