From 71c66d9c9a36a28107cfc202aa38f51b3dde8731 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Fri, 3 Sep 2010 14:00:51 +0000 Subject: gfid: handling of gfids in storage/posix Signed-off-by: Anand V. Avati Signed-off-by: Anand V. Avati Signed-off-by: Vijay Bellur BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971 --- xlators/storage/posix/src/posix.c | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 0730dc2cd..aad52096b 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -251,6 +251,34 @@ out: } +int +posix_fill_gfid_path (xlator_t *this, const char *path, struct iatt *iatt) +{ + int ret = 0; + + if (!iatt) + return 0; + + ret = sys_lgetxattr (path, "trusted.gfid", iatt->ia_gfid, 16); + + return ret; +} + + +int +posix_fill_gfid_fd (xlator_t *this, int fd, struct iatt *iatt) +{ + int ret = 0; + + if (!iatt) + return 0; + + ret = sys_fgetxattr (fd, "trusted.gfid", iatt->ia_gfid, 16); + + return ret; +} + + int posix_lstat_with_gen (xlator_t *this, const char *path, struct iatt *stbuf_p) { @@ -292,6 +320,8 @@ posix_lstat_with_gen (xlator_t *this, const char *path, struct iatt *stbuf_p) } #endif /* !GF_LINUX_HOST_OS */ + ret = posix_fill_gfid_path (this, path, &stbuf); + ret = snprintf (gen_key, 1024, "trusted.%s.gen", this->name); if (ret == 1024) @@ -361,6 +391,8 @@ posix_fstat_with_gen (xlator_t *this, int fd, struct iatt *stbuf_p) } #endif /* !GF_LINUX_HOST_OS */ + ret = posix_fill_gfid_fd (this, fd, &stbuf); + ret = snprintf (gen_key, 1024, "trusted.%s.gen", this->name); if (ret == 1024) @@ -472,6 +504,36 @@ out: } +int +posix_gfid_set (xlator_t *this, const char *path, dict_t *xattr_req) +{ + void *uuid_req = NULL; + uuid_t uuid_curr; + int ret = 0; + struct stat stat = {0, }; + + if (!xattr_req) + return 0; + + if (sys_lstat (path, &stat) != 0) + return 0; + + ret = sys_lgetxattr (path, "trusted.gfid", uuid_curr, 16); + + if (ret == 16) + return 0; + + ret = dict_get_ptr (xattr_req, "gfid-req", &uuid_req); + if (ret) + goto out; + + ret = sys_lsetxattr (path, "trusted.gfid", uuid_req, 16, XATTR_CREATE); + +out: + return ret; +} + + int32_t posix_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req) @@ -493,6 +555,8 @@ posix_lookup (call_frame_t *frame, xlator_t *this, MAKE_REAL_PATH (real_path, this, loc->path); + posix_gfid_set (this, real_path, xattr_req); + op_ret = posix_lstat_with_gen (this, real_path, &buf); op_errno = errno; @@ -1134,6 +1198,8 @@ posix_mknod (call_frame_t *frame, xlator_t *this, } } + op_ret = posix_gfid_set (this, real_path, params); + #ifndef HAVE_SET_FSID op_ret = lchown (real_path, frame->root->uid, gid); if (op_ret == -1) { @@ -1389,6 +1455,8 @@ posix_mkdir (call_frame_t *frame, xlator_t *this, goto out; } + op_ret = posix_gfid_set (this, real_path, params); + #ifndef HAVE_SET_FSID op_ret = chown (real_path, frame->root->uid, gid); if (op_ret == -1) { @@ -1663,6 +1731,8 @@ posix_symlink (call_frame_t *frame, xlator_t *this, goto out; } + op_ret = posix_gfid_set (this, real_path, params); + #ifndef HAVE_SET_FSID op_ret = lchown (real_path, frame->root->uid, gid); if (op_ret == -1) { @@ -2080,6 +2150,8 @@ posix_create (call_frame_t *frame, xlator_t *this, goto out; } + op_ret = posix_gfid_set (this, real_path, params); + #ifndef HAVE_SET_FSID op_ret = chown (real_path, frame->root->uid, gid); if (op_ret == -1) { -- cgit