summaryrefslogtreecommitdiffstats
path: root/api/src/glfs-fops.c
diff options
context:
space:
mode:
authorSoumya Koduri <skoduri@redhat.com>2015-07-08 12:08:25 +0530
committerKaleb KEITHLEY <kkeithle@redhat.com>2015-07-10 03:06:48 -0700
commitdecf3c9fe0d4f1f636e337aa313694251341b685 (patch)
treee88b70e42d436ca5f95faf1ad95de0a173fe1a3c /api/src/glfs-fops.c
parent555301094fff111c92034ee5103a059a4be5872c (diff)
gfapi: Update loc->inode accordingly in 'glfs_loc_link'
In case if the inode already exits in the cache, inode_link returns the pointer to the exiting one instead of using loc->inode. This will result in issues if that invalid inodei(loc->inode) is referenced further. Fixed the same. This is backport of the below fix - http://review.gluster.org/#/c/11572/ BUG: 1241666 Change-Id: I1a89932397f7d2b70d619eeaf862c0a5d7f6b91c Signed-off-by: Soumya Koduri <skoduri@redhat.com> Reviewed-on: http://review.gluster.org/11572 Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com> Reviewed-on: http://review.gluster.org/11606 Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'api/src/glfs-fops.c')
-rw-r--r--api/src/glfs-fops.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
index b66f336338d..2997452e5c3 100644
--- a/api/src/glfs-fops.c
+++ b/api/src/glfs-fops.c
@@ -76,17 +76,23 @@ int
glfs_loc_link (loc_t *loc, struct iatt *iatt)
{
int ret = -1;
- inode_t *linked_inode = NULL;
+ inode_t *old_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);
+ old_inode = loc->inode;
+
+ /* If the inode already exists in the cache, the inode
+ * returned here points to the existing one. We need
+ * to update loc.inode accordingly.
+ */
+ loc->inode = inode_link (loc->inode, loc->parent, loc->name, iatt);
+ if (loc->inode) {
+ inode_lookup (loc->inode);
+ inode_unref (old_inode);
ret = 0;
} else {
ret = -1;