From bddbe778a64dd826d074f4008f3c8b1a4a495996 Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Wed, 8 Jul 2015 12:08:25 +0530 Subject: [PATCH 224/234] 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/ Change-Id: I7d4a06043e4e731c8404532c47d482175dc2c277 BUG: 1235121 Signed-off-by: Soumya Koduri Reviewed-on: http://review.gluster.org/11572 Reviewed-by: Kaleb KEITHLEY Reviewed-by: Shyamsundar Ranganathan Reviewed-on: https://code.engineering.redhat.com/gerrit/52713 Reviewed-by: Kaleb Keithley Tested-by: Kaleb Keithley --- api/src/glfs-fops.c | 16 +++++++++++----- api/src/glfs-handleops.c | 10 ---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index e1762ae..9d829a1 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; diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index 47f2139..9a85f19 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -746,11 +746,6 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, /* populate out args */ if (ret == 0) { - /* TODO: If the inode existed in the cache (say file already - exists), then the glfs_loc_link will not update the - loc.inode, as a result we will have a 0000 GFID that we - would copy out to the object, this needs to be fixed. - */ ret = glfs_loc_link (&loc, &iatt); if (ret != 0) { goto out; @@ -1466,11 +1461,6 @@ pub_glfs_h_symlink (struct glfs *fs, struct glfs_object *parent, /* populate out args */ if (ret == 0) { - /* TODO: If the inode existed in the cache (say file already - * exists), then the glfs_loc_link will not update the - * loc.inode, as a result we will have a 0000 GFID that we - * would copy out to the object, this needs to be fixed. - */ ret = glfs_loc_link (&loc, &iatt); if (ret != 0) { goto out; -- 1.7.1