From 44cf0aa02bf081d0b94d0174493cbf162dd957b8 Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Tue, 10 May 2016 13:03:42 +0530 Subject: libglusterfs/gfapi: set appropriate errno for inode_link failures We do not seem to be setting errno appropriately in case of inode_link failures. This errno may be used by any application (for eg., nfs-ganesha) to determine the error encountered. This patch addresses the same. This is backport of below mainline fix - http://review.gluster.org/14278 Change-Id: I674f747c73369d0597a9c463e6ea4c85b9091355 BUG: 1335016 Signed-off-by: Soumya Koduri Reviewed-on: http://review.gluster.org/14278 Reviewed-by: Niels de Vos Reviewed-by: jiffin tony Thottan Reviewed-by: Kaleb KEITHLEY Reviewed-on: http://review.gluster.org/14287 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System --- libglusterfs/src/inode.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index c45e7d1e85b..b70b4a93957 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -934,27 +934,34 @@ __inode_link (inode_t *inode, inode_t *parent, const char *name, inode_table_t *table = NULL; inode_t *link_inode = NULL; - if (!inode) + if (!inode) { + errno = EINVAL; return NULL; + } table = inode->table; - if (!table) + if (!table) { + errno = EINVAL; return NULL; + } if (parent) { /* We should prevent inode linking between different inode tables. This can cause errors which is very hard to catch/debug. */ if (inode->table != parent->table) { + errno = EINVAL; GF_ASSERT (!"link attempted b/w inodes of diff table"); } if (parent->ia_type != IA_IFDIR) { + errno = EINVAL; GF_ASSERT (!"link attempted on non-directory parent"); return NULL; } if (!name || strlen (name) == 0) { + errno = EINVAL; GF_ASSERT (!"link attempted with no basename on " "parent"); return NULL; @@ -964,11 +971,15 @@ __inode_link (inode_t *inode, inode_t *parent, const char *name, link_inode = inode; if (!__is_inode_hashed (inode)) { - if (!iatt) + if (!iatt) { + errno = EINVAL; return NULL; + } - if (gf_uuid_is_null (iatt->ia_gfid)) + if (gf_uuid_is_null (iatt->ia_gfid)) { + errno = EINVAL; return NULL; + } old_inode = __inode_find (table, iatt->ia_gfid); @@ -1015,9 +1026,11 @@ __inode_link (inode_t *inode, inode_t *parent, const char *name, "inode %s with parent %s", uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid)); + errno = ENOMEM; return NULL; } if (old_inode && __is_dentry_cyclic (dentry)) { + errno = ELOOP; __dentry_unset (dentry); return NULL; } -- cgit