diff options
| author | Soumya Koduri <skoduri@redhat.com> | 2016-05-10 13:03:42 +0530 | 
|---|---|---|
| committer | Kaleb KEITHLEY <kkeithle@redhat.com> | 2016-05-11 07:36:33 -0700 | 
| commit | 44cf0aa02bf081d0b94d0174493cbf162dd957b8 (patch) | |
| tree | d73194806d593d997810c55421cbcae2126d582d | |
| parent | a0ae826a7413e1ad0a5796201d156d8d915c93ad (diff) | |
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 <skoduri@redhat.com>
Reviewed-on: http://review.gluster.org/14278
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-on: http://review.gluster.org/14287
Smoke: Gluster Build System <jenkins@build.gluster.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
| -rw-r--r-- | api/src/gfapi-messages.h | 3 | ||||
| -rw-r--r-- | api/src/glfs-fops.c | 1 | ||||
| -rw-r--r-- | api/src/glfs-handleops.c | 8 | ||||
| -rw-r--r-- | api/src/glfs-resolve.c | 14 | ||||
| -rw-r--r-- | libglusterfs/src/inode.c | 21 | 
5 files changed, 35 insertions, 12 deletions
diff --git a/api/src/gfapi-messages.h b/api/src/gfapi-messages.h index c54d821efc7..d15e914dd06 100644 --- a/api/src/gfapi-messages.h +++ b/api/src/gfapi-messages.h @@ -45,7 +45,7 @@   */  #define GLFS_GFAPI_BASE             GLFS_MSGID_COMP_API -#define GLFS_NUM_MESSAGES           47 +#define GLFS_NUM_MESSAGES           48  #define GLFS_MSGID_END              (GLFS_GFAPI_BASE + GLFS_NUM_MESSAGESi + 1)  /* Messages with message IDs */  #define glfs_msg_start_x GLFS_GFAPI_BASE, "Invalid: Start of messages" @@ -98,6 +98,7 @@  #define API_MSG_NEW_GRAPH                       (GLFS_GFAPI_BASE + 45)  #define API_MSG_ALLOC_FAILED                    (GLFS_GFAPI_BASE + 46)  #define API_MSG_CREATE_HANDLE_FAILED            (GLFS_GFAPI_BASE + 47) +#define API_MSG_INODE_LINK_FAILED               (GLFS_GFAPI_BASE + 48)  /*------------*/  #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index f01d6adf0ba..0031061620f 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -127,7 +127,6 @@ glfs_loc_link (loc_t *loc, struct iatt *iatt)  		ret = 0;  	} else {  		ret = -1; -		errno = ENOMEM;  	}  	return ret; diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index 72aa7de146e..721187f8342 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -1332,11 +1332,9 @@ pub_glfs_h_create_from_handle (struct glfs *fs, unsigned char *handle, int len,                  }                  inode_lookup (newinode);          } else { -                gf_msg (subvol->name, GF_LOG_WARNING, EINVAL, -                        API_MSG_INVALID_ENTRY, -                        "inode linking of %s failed: %s", -                        uuid_utoa (loc.gfid), strerror (errno)); -                errno = EINVAL; +                gf_msg (subvol->name, GF_LOG_WARNING, errno, +                        API_MSG_INODE_LINK_FAILED, +                        "inode linking of %s failed", uuid_utoa (loc.gfid));                  goto out;          } diff --git a/api/src/glfs-resolve.c b/api/src/glfs-resolve.c index f8933326433..c2c6e64fb9d 100644 --- a/api/src/glfs-resolve.c +++ b/api/src/glfs-resolve.c @@ -134,6 +134,11 @@ glfs_refresh_inode_safe (xlator_t *subvol, inode_t *oldinode,                  if (newinode == loc.inode)                          inode_ctx_set (newinode, THIS, &ctx_value);                  inode_lookup (newinode); +        } else { +                gf_msg (subvol->name, GF_LOG_WARNING, errno, +                        API_MSG_INODE_LINK_FAILED, +                        "inode linking of %s failed", +                        uuid_utoa ((unsigned char *)&iatt.ia_gfid));          }  	loc_wipe (&loc); @@ -346,7 +351,14 @@ glfs_resolve_component (struct glfs *fs, xlator_t *subvol, inode_t *parent,  		goto out;  	inode = inode_link (loc.inode, loc.parent, component, &ciatt); -        if (inode == loc.inode) + +        if (!inode) { +                gf_msg (subvol->name, GF_LOG_WARNING, errno, +                        API_MSG_INODE_LINK_FAILED, +                        "inode linking of %s failed", +                        uuid_utoa ((unsigned char *)&ciatt.ia_gfid)); +                goto out; +        } else if (inode == loc.inode)                  inode_ctx_set (inode, THIS, &ctx_value);  found:  	if (inode) 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;                          }  | 
