cb8e9e
From bddbe778a64dd826d074f4008f3c8b1a4a495996 Mon Sep 17 00:00:00 2001
cb8e9e
From: Soumya Koduri <skoduri@redhat.com>
cb8e9e
Date: Wed, 8 Jul 2015 12:08:25 +0530
cb8e9e
Subject: [PATCH 224/234] gfapi: Update loc->inode accordingly in 'glfs_loc_link'
cb8e9e
cb8e9e
In case if the inode already exits in the cache, inode_link
cb8e9e
returns the pointer to the exiting one instead of using loc->inode.
cb8e9e
This will result in issues if that invalid inodei(loc->inode) is referenced
cb8e9e
further. Fixed the same.
cb8e9e
cb8e9e
This is backport of the below fix -
cb8e9e
http://review.gluster.org/#/c/11572/
cb8e9e
cb8e9e
Change-Id: I7d4a06043e4e731c8404532c47d482175dc2c277
cb8e9e
BUG: 1235121
cb8e9e
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
cb8e9e
Reviewed-on: http://review.gluster.org/11572
cb8e9e
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
cb8e9e
Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/52713
cb8e9e
Reviewed-by: Kaleb Keithley <kkeithle@redhat.com>
cb8e9e
Tested-by: Kaleb Keithley <kkeithle@redhat.com>
cb8e9e
---
cb8e9e
 api/src/glfs-fops.c      |   16 +++++++++++-----
cb8e9e
 api/src/glfs-handleops.c |   10 ----------
cb8e9e
 2 files changed, 11 insertions(+), 15 deletions(-)
cb8e9e
cb8e9e
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
cb8e9e
index e1762ae..9d829a1 100644
cb8e9e
--- a/api/src/glfs-fops.c
cb8e9e
+++ b/api/src/glfs-fops.c
cb8e9e
@@ -76,17 +76,23 @@ int
cb8e9e
 glfs_loc_link (loc_t *loc, struct iatt *iatt)
cb8e9e
 {
cb8e9e
 	int ret = -1;
cb8e9e
-	inode_t *linked_inode = NULL;
cb8e9e
+        inode_t *old_inode = NULL;
cb8e9e
 
cb8e9e
 	if (!loc->inode) {
cb8e9e
 		errno = EINVAL;
cb8e9e
 		return -1;
cb8e9e
 	}
cb8e9e
 
cb8e9e
-	linked_inode = inode_link (loc->inode, loc->parent, loc->name, iatt);
cb8e9e
-	if (linked_inode) {
cb8e9e
-		inode_lookup (linked_inode);
cb8e9e
-		inode_unref (linked_inode);
cb8e9e
+        old_inode = loc->inode;
cb8e9e
+
cb8e9e
+        /* If the inode already exists in the cache, the inode
cb8e9e
+         * returned here points to the existing one. We need
cb8e9e
+         * to update loc.inode accordingly.
cb8e9e
+         */
cb8e9e
+	loc->inode = inode_link (loc->inode, loc->parent, loc->name, iatt);
cb8e9e
+	if (loc->inode) {
cb8e9e
+		inode_lookup (loc->inode);
cb8e9e
+                inode_unref (old_inode);
cb8e9e
 		ret = 0;
cb8e9e
 	} else {
cb8e9e
 		ret = -1;
cb8e9e
diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c
cb8e9e
index 47f2139..9a85f19 100644
cb8e9e
--- a/api/src/glfs-handleops.c
cb8e9e
+++ b/api/src/glfs-handleops.c
cb8e9e
@@ -746,11 +746,6 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path,
cb8e9e
 
cb8e9e
         /* populate out args */
cb8e9e
         if (ret == 0) {
cb8e9e
-                /* TODO: If the inode existed in the cache (say file already
cb8e9e
-                   exists), then the glfs_loc_link will not update the
cb8e9e
-                   loc.inode, as a result we will have a 0000 GFID that we
cb8e9e
-                   would copy out to the object, this needs to be fixed.
cb8e9e
-                */
cb8e9e
                 ret = glfs_loc_link (&loc, &iatt);
cb8e9e
                 if (ret != 0) {
cb8e9e
                         goto out;
cb8e9e
@@ -1466,11 +1461,6 @@ pub_glfs_h_symlink (struct glfs *fs, struct glfs_object *parent,
cb8e9e
 
cb8e9e
         /* populate out args */
cb8e9e
         if (ret == 0) {
cb8e9e
-                /* TODO: If the inode existed in the cache (say file already
cb8e9e
-                 * exists), then the glfs_loc_link will not update the
cb8e9e
-                 * loc.inode, as a result we will have a 0000 GFID that we
cb8e9e
-                 * would copy out to the object, this needs to be fixed.
cb8e9e
-                 */
cb8e9e
                 ret = glfs_loc_link (&loc, &iatt);
cb8e9e
                 if (ret != 0) {
cb8e9e
                         goto out;
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e