From 6f4a9f43e4d18c42f5eb8db65f364620a85c7fd2 Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Mon, 22 Oct 2012 17:20:26 +0530 Subject: mount/fuse: migrate posix locks after a graph-switch Each posix-lock is associated with an fd and a transport. After a graph switch, this lock-state has to be associated with new fd and transport corresponding to new client graph. Change-Id: Ia0855e15600c85ef902bf612738f7d96557145be BUG: 808400 Signed-off-by: Raghavendra Reviewed-on: http://review.gluster.org/4122 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/mount/fuse/src/fuse-bridge.c | 98 +++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 8 deletions(-) (limited to 'xlators/mount/fuse/src/fuse-bridge.c') diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index 544dec0c3..68f9e7541 100644 --- a/xlators/mount/fuse/src/fuse-bridge.c +++ b/xlators/mount/fuse/src/fuse-bridge.c @@ -3716,7 +3716,8 @@ out: int fuse_migrate_fd_open (xlator_t *this, fd_t *basefd, fd_t *oldfd, - xlator_t *old_subvol, xlator_t *new_subvol) + xlator_t *old_subvol, xlator_t *new_subvol, + fd_t **newfdptr) { loc_t loc = {0, }; fd_t *newfd = NULL, *old_activefd = NULL; @@ -3808,17 +3809,77 @@ fuse_migrate_fd_open (xlator_t *this, fd_t *basefd, fd_t *oldfd, fd_unref (old_activefd); } - gf_log ("glusterfs-fuse", GF_LOG_WARNING, - "migrated basefd (%p) to newfd (%p) " + gf_log ("glusterfs-fuse", GF_LOG_INFO, + "migrated basefd (%p) to newfd (%p) (inode-gfid:%s)" "(old-subvolume:%s-%d new-subvolume:%s-%d)", basefd, newfd, - old_subvol->name, old_subvol->graph->id, + uuid_utoa (basefd->inode->gfid), + old_subvol->name, old_subvol->graph->id, new_subvol->name, new_subvol->graph->id); - newfd = NULL; + if (newfdptr != NULL) { + *newfdptr = newfd; + } + ret = 0; + out: loc_wipe (&loc); + fd_unref (newfd); + return ret; +} + +int +fuse_migrate_locks (xlator_t *this, fd_t *oldfd, fd_t *newfd, + xlator_t *old_subvol, xlator_t *new_subvol) +{ + int ret = -1; + dict_t *lockinfo = NULL; + void *ptr = NULL; + + ret = syncop_fgetxattr (old_subvol, oldfd, &lockinfo, + GF_XATTR_LOCKINFO_KEY); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "getting lockinfo failed while migrating locks" + "(oldfd:%p newfd:%p inode-gfid:%s)" + "(old-subvol:%s-%d new-subvol:%s-%d)", + oldfd, newfd, uuid_utoa (newfd->inode->gfid), + old_subvol->name, old_subvol->graph->id, + new_subvol->name, new_subvol->graph->id); + goto out; + } + + ret = dict_get_ptr (lockinfo, GF_XATTR_LOCKINFO_KEY, &ptr); + if (ptr == NULL) { + ret = 0; + gf_log (this->name, GF_LOG_INFO, + "No lockinfo present on any of the bricks " + "(oldfd: %p newfd:%p inode-gfid:%s) " + "(old-subvol:%s-%d new-subvol:%s-%d)", + oldfd, newfd, uuid_utoa (newfd->inode->gfid), + old_subvol->name, old_subvol->graph->id, + new_subvol->name, new_subvol->graph->id); + + goto out; + } + + ret = syncop_fsetxattr (new_subvol, newfd, lockinfo, 0); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "migrating locks failed (oldfd:%p newfd:%p " + "inode-gfid:%s) (old-subvol:%s-%d new-subvol:%s-%d)", + oldfd, newfd, uuid_utoa (newfd->inode->gfid), + old_subvol->name, old_subvol->graph->id, + new_subvol->name, new_subvol->graph->id); + goto out; + } + +out: + if (lockinfo != NULL) { + dict_unref (lockinfo); + } + return ret; } @@ -3829,8 +3890,8 @@ fuse_migrate_fd (xlator_t *this, fd_t *basefd, xlator_t *old_subvol, { int ret = -1; char create_in_progress = 0; - fuse_fd_ctx_t *basefd_ctx = NULL; - fd_t *oldfd = NULL; + fuse_fd_ctx_t *basefd_ctx = NULL; + fd_t *oldfd = NULL, *newfdptr = NULL; basefd_ctx = fuse_fd_ctx_get (this, basefd); GF_VALIDATE_OR_GOTO ("glusterfs-fuse", basefd_ctx, out); @@ -3891,7 +3952,28 @@ fuse_migrate_fd (xlator_t *this, fd_t *basefd, xlator_t *old_subvol, } ret = fuse_migrate_fd_open (this, basefd, oldfd, old_subvol, - new_subvol); + new_subvol, &newfdptr); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, "open corresponding to " + "basefd (ptr:%p inode-gfid:%s) in new graph failed " + "(old-subvolume:%s-%d new-subvolume:%s-%d)", basefd, + uuid_utoa (basefd->inode->gfid), old_subvol->name, + old_subvol->graph->id, new_subvol->name, + new_subvol->graph->id); + goto out; + } + + ret = fuse_migrate_locks (this, oldfd, newfdptr, old_subvol, + new_subvol); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "migrating locks from old-subvolume (%s-%d) to " + "new-subvolume (%s-%d) failed (inode-gfid:%s oldfd:%p " + "newfd:%p)", old_subvol->name, old_subvol->graph->id, + new_subvol->name, new_subvol->graph->id, + uuid_utoa (basefd->inode->gfid), oldfd, newfdptr); + + } out: if (ret < 0) { gf_log (this->name, GF_LOG_WARNING, "migration of basefd " -- cgit