summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand Avati <avati@redhat.com>2013-12-10 14:28:22 -0800
committerVijay Bellur <vbellur@redhat.com>2013-12-12 23:49:52 -0800
commit8bdc329e892f35ca19dfd07b542aa81afd855fce (patch)
treee9e51a6ccc36d682d011df211fe728e866413df1
parentb198e072cda4bbb98e19701399c4bb4f0743cf20 (diff)
posix: if brick-uid or brick-gid is not specified, do not set
Current code would set owner uid/gid explicitly to 0/0 on start even if none was specified. Fix it. Change-Id: I72dec9e79c51bd1eb3af5334c42b7c23b01d0258 BUG: 1040275 Signed-off-by: Anand Avati <avati@redhat.com> Reviewed-on: http://review.gluster.org/6476 Tested-by: Gluster Build System <jenkins@build.gluster.com> Tested-by: Lukáš Bezdička <lukas.bezdicka@gooddata.com> Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rwxr-xr-xtests/bugs/brick-uid-reset-on-volume-restart.t47
-rw-r--r--xlators/storage/posix/src/posix.c41
2 files changed, 76 insertions, 12 deletions
diff --git a/tests/bugs/brick-uid-reset-on-volume-restart.t b/tests/bugs/brick-uid-reset-on-volume-restart.t
new file mode 100755
index 00000000000..99629733f9b
--- /dev/null
+++ b/tests/bugs/brick-uid-reset-on-volume-restart.t
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.rc
+. $(dirname $0)/../volume.rc
+
+function get_uid() {
+ stat -c '%u' $1;
+}
+
+function get_gid() {
+ stat -c '%g' $1;
+}
+
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+
+TEST $CLI volume create $V0 replica 2 stripe 2 $H0:$B0/${V0}{1,2,3,4,5,6,7,8};
+
+EXPECT "$V0" volinfo_field $V0 'Volume Name';
+EXPECT 'Created' volinfo_field $V0 'Status';
+EXPECT '8' brick_count $V0
+
+TEST $CLI volume start $V0;
+EXPECT 'Started' volinfo_field $V0 'Status';
+
+TEST glusterfs -s $H0 --volfile-id $V0 $M0;
+
+EXPECT 0 get_uid $M0;
+EXPECT 0 get_gid $M0;
+
+TEST chown 100:101 $M0;
+
+EXPECT 100 get_uid $M0;
+EXPECT 101 get_gid $M0;
+
+TEST $CLI volume stop $V0;
+TEST $CLI volume start $V0;
+
+sleep 10;
+
+EXPECT 100 get_uid $M0;
+EXPECT 101 get_gid $M0;
+
+cleanup;
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index b72cd5e0f3d..1ebf42150a7 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -5093,9 +5093,22 @@ posix_set_owner (xlator_t *this, uid_t uid, gid_t gid)
{
struct posix_private *priv = NULL;
int ret = -1;
+ struct stat st = {0,};
priv = this->private;
+ ret = sys_lstat (priv->base_path, &st);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to stat "
+ "brick path %s (%s)",
+ priv->base_path, strerror (errno));
+ return ret;
+ }
+
+ if ((uid == -1 || st.st_uid == uid) &&
+ (gid == -1 || st.st_gid == gid))
+ return 0;
+
ret = sys_chown (priv->base_path, uid, gid);
if (ret)
gf_log (this->name, GF_LOG_ERROR, "Failed to set "
@@ -5131,15 +5144,16 @@ reconfigure (xlator_t *this, dict_t *options)
{
int ret = -1;
struct posix_private *priv = NULL;
- uid_t uid = -1;
- gid_t gid = -1;
+ int32_t uid = -1;
+ int32_t gid = -1;
char *batch_fsync_mode_str = NULL;
priv = this->private;
- GF_OPTION_RECONF ("brick-uid", uid, options, uint32, out);
- GF_OPTION_RECONF ("brick-gid", gid, options, uint32, out);
- posix_set_owner (this, uid, gid);
+ GF_OPTION_RECONF ("brick-uid", uid, options, int32, out);
+ GF_OPTION_RECONF ("brick-gid", gid, options, int32, out);
+ if (uid != -1 || gid != -1)
+ posix_set_owner (this, uid, gid);
GF_OPTION_RECONF ("batch-fsync-delay-usec", priv->batch_fsync_delay_usec,
options, uint32, out);
@@ -5205,8 +5219,8 @@ init (xlator_t *this)
uuid_t gfid = {0,};
uuid_t rootgfid = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
char *guuid = NULL;
- uid_t uid = -1;
- gid_t gid = -1;
+ int32_t uid = -1;
+ int32_t gid = -1;
char *batch_fsync_mode_str;
dir_data = dict_get (this->options, "directory");
@@ -5541,9 +5555,10 @@ init (xlator_t *this)
_private->aio_init_done = _gf_false;
_private->aio_capable = _gf_false;
- GF_OPTION_INIT ("brick-uid", uid, uint32, out);
- GF_OPTION_INIT ("brick-gid", gid, uint32, out);
- posix_set_owner (this, uid, gid);
+ GF_OPTION_INIT ("brick-uid", uid, int32, out);
+ GF_OPTION_INIT ("brick-gid", gid, int32, out);
+ if (uid != -1 || gid != -1)
+ posix_set_owner (this, uid, gid);
GF_OPTION_INIT ("linux-aio", _private->aio_configured, bool, out);
@@ -5704,15 +5719,17 @@ struct volume_options options[] = {
{
.key = {"brick-uid"},
.type = GF_OPTION_TYPE_INT,
- .min = 0,
+ .min = -1,
.validate = GF_OPT_VALIDATE_MIN,
+ .default_value = "-1",
.description = "Support for setting uid of brick's owner"
},
{
.key = {"brick-gid"},
.type = GF_OPTION_TYPE_INT,
- .min = 0,
+ .min = -1,
.validate = GF_OPT_VALIDATE_MIN,
+ .default_value = "-1",
.description = "Support for setting gid of brick's owner"
},
{ .key = {"node-uuid-pathinfo"},