From 046cb49f20476ed900ae6dbe6f6ab7fad53d71a9 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Tue, 10 Dec 2013 14:28:22 -0800 Subject: posix: if brick-uid or brick-gid is not specified, do not set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: http://review.gluster.org/6476 Tested-by: Gluster Build System Tested-by: Lukáš Bezdička Reviewed-by: Krishnan Parthasarathi Reviewed-by: Vijay Bellur Reviewed-on: http://review.gluster.org/6519 Reviewed-by: Lukáš Bezdička --- xlators/storage/posix/src/posix.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index fb78bc86d07..189780decc2 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -4133,9 +4133,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 " @@ -4150,14 +4163,15 @@ 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; 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 ("linux-aio", priv->aio_configured, options, bool, out); @@ -4194,8 +4208,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; dir_data = dict_get (this->options, "directory"); @@ -4511,9 +4525,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); @@ -4634,11 +4649,13 @@ struct volume_options options[] = { { .key = {"brick-uid"}, .type = GF_OPTION_TYPE_INT, + .default_value = "-1", .description = "Support for setting uid of brick's owner" }, { .key = {"brick-gid"}, .type = GF_OPTION_TYPE_INT, + .default_value = "-1", .description = "Support for setting gid of brick's owner" }, { .key = {NULL} } -- cgit