summaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@redhat.com>2014-01-21 13:49:08 +0000
committerJeff Darcy <jdarcy@redhat.com>2014-01-21 13:49:08 +0000
commit6bcbf03b5aa4448832645a29ec2bc4b2fc5f2eaf (patch)
tree750f73a40aa62c20d66a2532fef6fd158cebb9c4 /api/src
parent0225d7bc712609232d592d48116ec771cd97c2cf (diff)
parent17c4fb2d04f84b5632983866e8bddfbd7d77a054 (diff)
Merge branch 'upstream'
Conflicts: api/src/glfs-fops.c api/src/glfs-handleops.c Change-Id: I6811674cc4ec4be6fa6e4cdebb4bc428194bebd8
Diffstat (limited to 'api/src')
-rw-r--r--api/src/Makefile.am1
-rw-r--r--api/src/glfs-fops.c38
-rw-r--r--api/src/glfs-handleops.c15
-rw-r--r--api/src/glfs-internal.h20
-rw-r--r--api/src/glfs-resolve.c10
5 files changed, 83 insertions, 1 deletions
diff --git a/api/src/Makefile.am b/api/src/Makefile.am
index 7c5df3e20..c9992d1d3 100644
--- a/api/src/Makefile.am
+++ b/api/src/Makefile.am
@@ -15,6 +15,7 @@ libgfapi_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \
-I$(top_srcdir)/rpc/rpc-lib/src \
-I$(top_srcdir)/rpc/xdr/src
+libgfapi_la_LDFLAGS = -version-info $(GFAPI_LT_VERSION)
xlator_LTLIBRARIES = api.la
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/mount
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
index e1fa697f9..aa359a992 100644
--- a/api/src/glfs-fops.c
+++ b/api/src/glfs-fops.c
@@ -124,6 +124,7 @@ retry:
}
ret = syncop_open (subvol, &loc, flags, glfd->fd);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
out:
@@ -169,6 +170,7 @@ glfs_close_with_xdata (struct glfs_fd *glfd, dict_t *dict)
}
ret = syncop_flush_with_xdata (subvol, fd, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
fs = glfd->fs;
glfs_fd_destroy (glfd);
@@ -278,6 +280,7 @@ glfs_fstat_with_xdata (struct glfs_fd *glfd, struct stat *stat, dict_t *dict)
}
ret = syncop_fstat_with_xdata (subvol, fd, &iatt, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret == 0 && stat)
glfs_iatt_to_stat (glfd->fs, &iatt, stat);
@@ -393,9 +396,11 @@ retry:
if (ret == 0) {
ret = syncop_open (subvol, &loc, flags, glfd->fd);
+ DECODE_SYNCOP_ERR (ret);
} else {
ret = syncop_create (subvol, &loc, flags, mode, glfd->fd,
xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
}
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -507,6 +512,7 @@ glfs_preadv_with_xdata (struct glfs_fd *glfd, const struct iovec *iovec, int iov
size = iov_length (iovec, iovcnt);
ret = syncop_readv_with_xdata (subvol, fd, size, offset, 0, &iov, &cnt, &iobref, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret <= 0)
goto out;
@@ -881,6 +887,7 @@ glfs_pwritev_with_xdata (struct glfs_fd *glfd, const struct iovec *iovec, int io
iov.iov_len = size;
ret = syncop_writev_with_xdata (subvol, fd, &iov, 1, offset, iobref, flags, dict);
+ DECODE_SYNCOP_ERR (ret);
iobuf_unref (iobuf);
iobref_unref (iobref);
@@ -1077,6 +1084,7 @@ glfs_fsync_with_xdata (struct glfs_fd *glfd, dict_t *dict)
}
ret = syncop_fsync_with_xdata (subvol, fd, 0, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref (fd);
@@ -1156,6 +1164,7 @@ glfs_fdatasync (struct glfs_fd *glfd)
}
ret = syncop_fsync (subvol, fd, 1);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref (fd);
@@ -1197,6 +1206,7 @@ glfs_ftruncate_with_xdata (struct glfs_fd *glfd, off_t offset, dict_t *dict)
}
ret = syncop_ftruncate_with_xdata (subvol, fd, offset, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref (fd);
@@ -1270,6 +1280,7 @@ retry:
goto out;
ret = syncop_access (subvol, &loc, mode);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
out:
@@ -1335,6 +1346,7 @@ retry:
}
ret = syncop_symlink (subvol, &loc, data, xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -1401,6 +1413,7 @@ retry:
}
ret = syncop_readlink (subvol, &loc, &linkval, bufsiz);
+ DECODE_SYNCOP_ERR (ret);
if (ret > 0) {
memcpy (buf, linkval, ret);
GF_FREE (linkval);
@@ -1471,6 +1484,7 @@ retry:
}
ret = syncop_mknod (subvol, &loc, mode, dev, xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -1558,6 +1572,7 @@ retry:
}
ret = syncop_mkdir (subvol, &loc, mode, xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -1623,6 +1638,7 @@ retry:
}
ret = syncop_unlink_with_xdata (subvol, &loc, dict);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -1674,6 +1690,7 @@ retry:
}
ret = syncop_rmdir_with_xdata (subvol, &loc, 0, dict);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -1742,6 +1759,7 @@ retrynew:
/* TODO: check if new or old is a prefix of the other, and fail EINVAL */
ret = syncop_rename_with_xdata (subvol, &oldloc, &newloc, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret == -1 && errno == ESTALE) {
if (reval < DEFAULT_REVAL_COUNT) {
@@ -1825,6 +1843,7 @@ retrynew:
newloc.inode = inode_ref (oldloc.inode);
ret = syncop_link_with_xdata (subvol, &oldloc, &newloc, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret == -1 && errno == ESTALE) {
loc_wipe (&oldloc);
@@ -1904,6 +1923,7 @@ retry:
}
ret = syncop_opendir (subvol, &loc, glfd->fd);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
out:
@@ -1912,7 +1932,7 @@ out:
if (ret && glfd) {
glfs_fd_destroy (glfd);
glfd = NULL;
- } else {
+ } else if (glfd) {
fd_bind (glfd->fd);
glfs_fd_bind (glfd);
}
@@ -2094,6 +2114,7 @@ glfd_entry_refresh (struct glfs_fd *glfd, int plus)
else
ret = syncop_readdir (subvol, fd, 131072, glfd->offset,
&entries);
+ DECODE_SYNCOP_ERR (ret);
if (ret >= 0) {
if (plus)
gf_link_inodes_from_dirent (THIS, fd->inode, &entries);
@@ -2272,6 +2293,7 @@ retry:
goto out;
ret = syncop_statfs (subvol, &loc, buf);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
out:
@@ -2313,6 +2335,7 @@ retry:
goto out;
ret = syncop_setattr_with_xdata (subvol, &loc, iatt, valid, 0, 0, dict);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
out:
@@ -2354,6 +2377,7 @@ glfs_fsetattr_with_xdata (struct glfs_fd *glfd, struct iatt *iatt, int valid, di
}
ret = syncop_fsetattr_with_xdata (subvol, fd, iatt, valid, 0, 0, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref (fd);
@@ -2575,6 +2599,7 @@ retry:
goto out;
ret = syncop_getxattr (subvol, &loc, &xattr, name);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -2633,6 +2658,7 @@ glfs_fgetxattr_with_xdata (struct glfs_fd *glfd, const char *name, void *value,
}
ret = syncop_fgetxattr_with_xdata (subvol, fd, &xattr, name, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret)
goto out;
@@ -2709,6 +2735,7 @@ retry:
goto out;
ret = syncop_getxattr (subvol, &loc, &xattr, NULL);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -2764,6 +2791,7 @@ glfs_flistxattr_with_xdata (struct glfs_fd *glfd, void *value, size_t size,dict_
}
ret = syncop_fgetxattr_with_xdata (subvol, fd, &xattr, NULL, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret)
goto out;
@@ -2842,6 +2870,7 @@ retry:
}
ret = syncop_setxattr_with_xdata (subvol, &loc, xattr, flags, dict);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -2911,6 +2940,7 @@ glfs_fsetxattr_with_xdata (struct glfs_fd *glfd, const char *name, const void *v
}
ret = syncop_fsetxattr_with_xdata (subvol, fd, xattr, flags, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
if (xattr)
dict_unref (xattr);
@@ -2960,6 +2990,7 @@ retry:
goto out;
ret = syncop_removexattr_with_xdata (subvol, &loc, name, dict);
+ DECODE_SYNCOP_ERR (ret);
ESTALE_RETRY (ret, errno, reval, &loc, retry);
@@ -3016,6 +3047,7 @@ glfs_fremovexattr_with_xdata (struct glfs_fd *glfd, const char *name, dict_t *di
}
ret = syncop_fremovexattr_with_xdata (subvol, fd, name, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref (fd);
@@ -3055,6 +3087,7 @@ glfs_fallocate (struct glfs_fd *glfd, int keep_size, off_t offset, size_t len)
}
ret = syncop_fallocate (subvol, fd, keep_size, offset, len);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref(fd);
@@ -3089,6 +3122,7 @@ glfs_discard (struct glfs_fd *glfd, off_t offset, size_t len)
}
ret = syncop_discard (subvol, fd, offset, len);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref(fd);
@@ -3120,6 +3154,7 @@ glfs_zerofill (struct glfs_fd *glfd, off_t offset, off_t len)
}
ret = syncop_zerofill (subvol, fd, offset, len);
+ DECODE_SYNCOP_ERR (ret);
out:
if (fd)
fd_unref(fd);
@@ -3367,6 +3402,7 @@ glfs_posix_lock (struct glfs_fd *glfd, int cmd, struct flock *flock)
gf_flock_from_flock (&gf_flock, flock);
gf_flock_from_flock (&saved_flock, flock);
ret = syncop_lk (subvol, fd, cmd, &gf_flock);
+ DECODE_SYNCOP_ERR (ret);
gf_flock_to_flock (&gf_flock, flock);
if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW))
diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c
index 6a60557ff..14d6c1b2c 100644
--- a/api/src/glfs-handleops.c
+++ b/api/src/glfs-handleops.c
@@ -152,6 +152,7 @@ glfs_h_stat (struct glfs *fs, struct glfs_object *object, struct stat *stat)
/* fop/op */
ret = syncop_stat (subvol, &loc, &iatt);
+ DECODE_SYNCOP_ERR (ret);
/* populate out args */
if (!ret && stat) {
@@ -258,6 +259,7 @@ glfs_h_setattrs (struct glfs *fs, struct glfs_object *object, struct stat *stat,
/* fop/op */
ret = syncop_setattr (subvol, &loc, &iatt, glvalid, 0, 0);
+ DECODE_SYNCOP_ERR (ret);
out:
loc_wipe (&loc);
@@ -331,6 +333,7 @@ glfs_h_open_with_xdata (struct glfs *fs, struct glfs_object *object, int flags,
/* fop/op */
ret = syncop_open_with_xdata (subvol, &loc, flags, glfd->fd, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
loc_wipe (&loc);
@@ -417,6 +420,7 @@ glfs_h_creat_with_xdata (struct glfs *fs, struct glfs_object *parent, const char
/* fop/op */
ret = syncop_create (subvol, &loc, flags, mode, glfd->fd,
xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
/* populate out args */
if (ret == 0) {
@@ -521,6 +525,7 @@ glfs_h_mkdir_with_xdata (struct glfs *fs, struct glfs_object *parent, const char
/* fop/op */
ret = syncop_mkdir (subvol, &loc, mode, xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
/* populate out args */
if ( ret == 0 ) {
@@ -617,6 +622,7 @@ glfs_h_mknod_with_xdata (struct glfs *fs, struct glfs_object *parent, const char
/* fop/op */
ret = syncop_mknod (subvol, &loc, mode, dev, xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
/* populate out args */
if (ret == 0) {
@@ -705,11 +711,13 @@ glfs_h_unlink_with_xdata (struct glfs *fs, struct glfs_object *parent, const cha
if (!IA_ISDIR(loc.inode->ia_type)) {
ret = syncop_unlink_with_xdata (subvol, &loc, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret != 0) {
goto out;
}
} else {
ret = syncop_rmdir_with_xdata (subvol, &loc, 0, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret != 0) {
goto out;
}
@@ -790,6 +798,7 @@ glfs_h_opendir_with_xdata (struct glfs *fs, struct glfs_object *object, dict_t *
/* fop/op */
ret = syncop_opendir_with_xdata (subvol, &loc, glfd->fd, dict);
+ DECODE_SYNCOP_ERR (ret);
out:
loc_wipe (&loc);
@@ -887,6 +896,7 @@ glfs_h_create_from_handle (struct glfs *fs, unsigned char *handle, int len,
}
ret = syncop_lookup (subvol, &loc, 0, &iatt, 0, 0);
+ DECODE_SYNCOP_ERR (ret);
if (ret) {
gf_log (subvol->name, GF_LOG_WARNING,
"inode refresh of %s failed: %s",
@@ -975,6 +985,7 @@ glfs_h_truncate (struct glfs *fs, struct glfs_object *object, off_t offset)
/* fop/op */
ret = syncop_truncate (subvol, &loc, (off_t)offset);
+ DECODE_SYNCOP_ERR (ret);
/* populate out args */
if (ret == 0)
@@ -1037,6 +1048,7 @@ glfs_h_symlink_with_xdata (struct glfs *fs, struct glfs_object *parent, const ch
/* fop/op */
ret = syncop_symlink (subvol, &loc, data, xattr_req, &iatt);
+ DECODE_SYNCOP_ERR (ret);
/* populate out args */
if (ret == 0) {
@@ -1129,6 +1141,7 @@ glfs_h_readlink (struct glfs *fs, struct glfs_object *object, char *buf,
/* fop/op */
ret = syncop_readlink (subvol, &loc, &linkval, bufsiz);
+ DECODE_SYNCOP_ERR (ret);
/* populate out args */
if (ret > 0)
@@ -1214,6 +1227,7 @@ glfs_h_link_with_xdata (struct glfs *fs, struct glfs_object *linksrc,
/* fop/op */
ret = syncop_link_with_xdata (subvol, &oldloc, &newloc, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret == 0)
/* TODO: No iatt to pass as there has been no lookup */
@@ -1310,6 +1324,7 @@ glfs_h_rename_with_xdata (struct glfs *fs, struct glfs_object *olddir, const cha
/* TODO: check if new or old is a prefix of the other, and fail EINVAL */
ret = syncop_rename_with_xdata (subvol, &oldloc, &newloc, dict);
+ DECODE_SYNCOP_ERR (ret);
if (ret == 0)
inode_rename (oldloc.parent->table, oldloc.parent, oldloc.name,
diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h
index ec1d5579d..f04557323 100644
--- a/api/src/glfs-internal.h
+++ b/api/src/glfs-internal.h
@@ -18,6 +18,26 @@
#define DEFAULT_REVAL_COUNT 1
+/*
+ * syncop_xxx() calls are executed in two ways, one is inside a synctask where
+ * the executing function will do 'swapcontext' and the other is without
+ * synctask where the executing thread is made to wait using pthread_cond_wait.
+ * Executing thread may change when syncop_xxx() is executed inside a synctask.
+ * This leads to errno_location change i.e. errno may give errno of
+ * non-executing thread. So errno is not touched inside a synctask execution.
+ * All gfapi calls are executed using the second way of executing syncop_xxx()
+ * where the executing thread waits using pthread_cond_wait so it is ok to set
+ * errno in these cases. The following macro makes syncop_xxx() behave just
+ * like a system call, where -1 is returned and errno is set when a failure
+ * occurs.
+ */
+#define DECODE_SYNCOP_ERR(ret) do { \
+ if (ret < 0) { \
+ errno = -ret; \
+ ret = -1; \
+ } \
+ } while (0)
+
#define ESTALE_RETRY(ret,errno,reval,loc,label) do { \
if (ret == -1 && errno == ESTALE) { \
if (reval < DEFAULT_REVAL_COUNT) { \
diff --git a/api/src/glfs-resolve.c b/api/src/glfs-resolve.c
index 4ca2eb6fc..c88330aa4 100644
--- a/api/src/glfs-resolve.c
+++ b/api/src/glfs-resolve.c
@@ -48,6 +48,7 @@ glfs_first_lookup_safe (xlator_t *subvol)
loc.name = "";
ret = syncop_lookup (subvol, &loc, 0, 0, 0, 0);
+ DECODE_SYNCOP_ERR (ret);
gf_log (subvol->name, GF_LOG_DEBUG, "first lookup complete %d", ret);
@@ -98,6 +99,7 @@ glfs_refresh_inode_safe (xlator_t *subvol, inode_t *oldinode)
return NULL;
ret = syncop_lookup (subvol, &loc, 0, &iatt, 0, 0);
+ DECODE_SYNCOP_ERR (ret);
if (ret) {
gf_log (subvol->name, GF_LOG_WARNING,
@@ -181,6 +183,7 @@ glfs_resolve_symlink (struct glfs *fs, xlator_t *subvol, inode_t *inode,
loc.path = rpath;
ret = syncop_readlink (subvol, &loc, &path, 4096);
+ DECODE_SYNCOP_ERR (ret);
if (ret < 0)
goto out;
@@ -210,6 +213,7 @@ glfs_resolve_base (struct glfs *fs, xlator_t *subvol, inode_t *inode,
goto out;
ret = syncop_lookup (subvol, &loc, NULL, iatt, NULL, NULL);
+ DECODE_SYNCOP_ERR (ret);
out:
loc_wipe (&loc);
@@ -268,6 +272,7 @@ glfs_resolve_component (struct glfs *fs, xlator_t *subvol, inode_t *parent,
}
ret = syncop_lookup (subvol, &loc, NULL, &ciatt, NULL, NULL);
+ DECODE_SYNCOP_ERR (ret);
if (ret && reval) {
inode_unref (loc.inode);
loc.inode = inode_new (parent->table);
@@ -292,6 +297,7 @@ glfs_resolve_component (struct glfs *fs, xlator_t *subvol, inode_t *parent,
ret = syncop_lookup (subvol, &loc, xattr_req, &ciatt,
NULL, NULL);
+ DECODE_SYNCOP_ERR (ret);
}
if (ret)
goto out;
@@ -515,6 +521,7 @@ glfs_migrate_fd_locks_safe (struct glfs *fs, xlator_t *oldsubvol, fd_t *oldfd,
ret = syncop_fgetxattr (oldsubvol, oldfd, &lockinfo,
GF_XATTR_LOCKINFO_KEY);
+ DECODE_SYNCOP_ERR (ret);
if (ret < 0) {
gf_log (fs->volname, GF_LOG_WARNING,
"fgetxattr (%s) failed (%s) on graph %s (%d)",
@@ -533,6 +540,7 @@ glfs_migrate_fd_locks_safe (struct glfs *fs, xlator_t *oldsubvol, fd_t *oldfd,
}
ret = syncop_fsetxattr (newsubvol, newfd, lockinfo, 0);
+ DECODE_SYNCOP_ERR (ret);
if (ret < 0) {
gf_log (fs->volname, GF_LOG_WARNING,
"fsetxattr (%s) failed (%s) on graph %s (%d)",
@@ -568,6 +576,7 @@ glfs_migrate_fd_safe (struct glfs *fs, xlator_t *newsubvol, fd_t *oldfd)
if (!oldsubvol->switched) {
ret = syncop_fsync (oldsubvol, oldfd, 0);
+ DECODE_SYNCOP_ERR (ret);
if (ret) {
gf_log (fs->volname, GF_LOG_WARNING,
"fsync() failed (%s) on %s graph %s (%d)",
@@ -614,6 +623,7 @@ glfs_migrate_fd_safe (struct glfs *fs, xlator_t *newsubvol, fd_t *oldfd)
ret = syncop_open (newsubvol, &loc,
oldfd->flags & ~(O_TRUNC|O_EXCL|O_CREAT),
newfd);
+ DECODE_SYNCOP_ERR (ret);
loc_wipe (&loc);
if (ret) {