From f948a24e51e447642c35bff881057f306768a5e0 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 23 Jun 2011 01:51:47 +0000 Subject: bring in strict check on export directory being re-used for different volume Signed-off-by: Amar Tumballi Signed-off-by: Anand Avati BUG: 3065 (make sure the export directories are not re-used as part of another volume) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=3065 --- xlators/storage/posix/src/posix.c | 43 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'xlators/storage/posix/src/posix.c') diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 524b700f0..95926bbf5 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -4355,6 +4355,8 @@ init (xlator_t *this) int ret = 0; int op_ret = -1; int32_t janitor_sleep = 0; + uuid_t old_uuid; + uuid_t dict_uuid; dir_data = dict_get (this->options, "directory"); @@ -4389,7 +4391,6 @@ init (xlator_t *this) goto out; } - /* Check for Extended attribute support, if not present, log it */ op_ret = sys_lsetxattr (dir_data->data, "trusted.glusterfs.test", "working", 8, 0); @@ -4426,6 +4427,46 @@ init (xlator_t *this) } } + tmp_data = dict_get (this->options, "volume-id"); + if (tmp_data) { + op_ret = uuid_parse (tmp_data->data, dict_uuid); + if (op_ret < 0) { + gf_log (this->name, GF_LOG_ERROR, + "wrong volume-id (%s) set in volume file", + tmp_data->data); + ret = -1; + goto out; + } + op_ret = sys_lgetxattr (dir_data->data, + "trusted.glusterfs.volume-id", old_uuid, 16); + if (op_ret == 16) { + if (uuid_compare (old_uuid, dict_uuid)) { + gf_log (this->name, GF_LOG_ERROR, + "mismatching volume-id (%s) recieved. " + "already is a part of volume %s ", + tmp_data->data, uuid_utoa (old_uuid)); + ret = -1; + goto out; + } + } else if (op_ret == -1) { + /* Using the export for first time */ + op_ret = sys_lsetxattr (dir_data->data, + "trusted.glusterfs.volume-id", + dict_uuid, 16, 0); + if (op_ret == -1) { + gf_log (this->name, GF_LOG_ERROR, + "failed to set volume id on export"); + ret = -1; + goto out; + } + } else { + ret = -1; + gf_log (this->name, GF_LOG_ERROR, + "failed to fetch volume id from export"); + goto out; + } + } + _private = GF_CALLOC (1, sizeof (*_private), gf_posix_mt_posix_private); if (!_private) { -- cgit