diff options
author | Anand Avati <avati@redhat.com> | 2013-04-28 12:22:54 -0700 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2013-06-08 14:51:04 -0700 |
commit | 40b3bf9c15d4144fa768df061fbbbd15f9e8c8fc (patch) | |
tree | 67d542a7980b758a86606dcf75d7f0d50669847c /api | |
parent | 9f6cb68802c197cc9b788a589c97c8bb71be2804 (diff) |
gfapi: link inodes in relevant entry FOPs
Do not let inode linking to happen only in lookup(). While
that works, it is inefficient.
Change-Id: I51bbfb6255ec4324ab17ff00566375f49d120c06
BUG: 953694
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/5162
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'api')
-rw-r--r-- | api/src/glfs-fops.c | 73 |
1 files changed, 69 insertions, 4 deletions
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index fe230e6a9bf..0bea82a04cb 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -26,6 +26,41 @@ } \ } while (0) + +static int +glfs_loc_link (loc_t *loc, struct iatt *iatt) +{ + int ret = -1; + inode_t *linked_inode = NULL; + + if (!loc->inode) { + errno = EINVAL; + return -1; + } + + linked_inode = inode_link (loc->inode, loc->parent, loc->name, iatt); + if (linked_inode) { + inode_lookup (linked_inode); + inode_unref (linked_inode); + ret = 0; + } else { + ret = -1; + errno = ENOMEM; + } + + return ret; +} + + +static int +glfs_loc_unlink (loc_t *loc) +{ + inode_unlink (loc->inode, loc->parent, loc->name); + + return 0; +} + + struct glfs_fd * glfs_open (struct glfs *fs, const char *path, int flags) { @@ -302,9 +337,13 @@ retry: goto out; } - ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, xattr_req); + ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, + xattr_req, &iatt); ESTALE_RETRY (ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_link (&loc, &iatt); out: loc_wipe (&loc); @@ -998,9 +1037,12 @@ retry: goto out; } - ret = syncop_symlink (subvol, &loc, data, xattr_req); + ret = syncop_symlink (subvol, &loc, data, xattr_req, &iatt); ESTALE_RETRY (ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_link (&loc, &iatt); out: loc_wipe (&loc); @@ -1115,9 +1157,12 @@ retry: goto out; } - ret = syncop_mknod (subvol, &loc, mode, dev, xattr_req); + ret = syncop_mknod (subvol, &loc, mode, dev, xattr_req, &iatt); ESTALE_RETRY (ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_link (&loc, &iatt); out: loc_wipe (&loc); @@ -1191,9 +1236,12 @@ retry: goto out; } - ret = syncop_mkdir (subvol, &loc, mode, xattr_req); + ret = syncop_mkdir (subvol, &loc, mode, xattr_req, &iatt); ESTALE_RETRY (ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_link (&loc, &iatt); out: loc_wipe (&loc); @@ -1238,6 +1286,9 @@ retry: ret = syncop_unlink (subvol, &loc); ESTALE_RETRY (ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_unlink (&loc); out: loc_wipe (&loc); @@ -1279,6 +1330,9 @@ retry: ret = syncop_rmdir (subvol, &loc); ESTALE_RETRY (ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_unlink (&loc); out: loc_wipe (&loc); @@ -1341,6 +1395,11 @@ retrynew: goto retry; } } + + if (ret == 0) + inode_rename (oldloc.parent->table, oldloc.parent, oldloc.name, + newloc.parent, newloc.name, oldloc.inode, + &oldiatt); out: loc_wipe (&oldloc); loc_wipe (&newloc); @@ -1401,6 +1460,8 @@ retrynew: goto retry; } + if (ret == 0) + ret = glfs_loc_link (&newloc, &oldiatt); out: loc_wipe (&oldloc); loc_wipe (&newloc); @@ -1570,6 +1631,10 @@ glfd_entry_refresh (struct glfs_fd *glfd, int plus) /* spurious errno is dangerous for glfd_entry_next() */ errno = 0; + if (plus) + gf_link_inodes_from_dirent (THIS, glfd->fd->inode, + &entries); + list_splice_init (&glfd->entries, &old.list); list_splice_init (&entries.list, &glfd->entries); } |