summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/src/glfs-fops.c368
-rw-r--r--api/src/glfs-handleops.c195
-rw-r--r--api/src/glfs-internal.h38
-rw-r--r--api/src/glfs-mgmt.c16
-rw-r--r--api/src/glfs.c119
-rw-r--r--heal/src/glfs-heal.c1
6 files changed, 591 insertions, 146 deletions
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
index 08f0884c7ee..37fa688a702 100644
--- a/api/src/glfs-fops.c
+++ b/api/src/glfs-fops.c
@@ -124,7 +124,8 @@ pub_glfs_open (struct glfs *fs, const char *path, int flags)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -190,6 +191,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return glfd;
}
@@ -204,7 +208,8 @@ pub_glfs_close (struct glfs_fd *glfd)
fd_t *fd = NULL;
struct glfs *fs = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -231,6 +236,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -246,7 +254,8 @@ pub_glfs_lstat (struct glfs *fs, const char *path, struct stat *stat)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -266,6 +275,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -281,7 +293,8 @@ pub_glfs_stat (struct glfs *fs, const char *path, struct stat *stat)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -301,6 +314,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -315,7 +331,8 @@ pub_glfs_fstat (struct glfs_fd *glfd, struct stat *stat)
struct iatt iatt = {0, };
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -342,6 +359,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -360,7 +380,8 @@ pub_glfs_creat (struct glfs *fs, const char *path, int flags, mode_t mode)
dict_t *xattr_req = NULL;
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -482,6 +503,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return glfd;
}
@@ -494,7 +518,8 @@ pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence)
struct stat sb = {0, };
int ret = -1;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
switch (whence) {
case SEEK_SET:
@@ -513,7 +538,12 @@ pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence)
break;
}
+ __GLFS_EXIT_FS;
+
return glfd->offset;
+
+invalid_fs:
+ return -1;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lseek, 3.4.0);
@@ -531,7 +561,8 @@ pub_glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt,
struct iobref *iobref = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -571,6 +602,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -750,7 +784,8 @@ pub_glfs_preadv_async (struct glfs_fd *glfd, const struct iovec *iovec,
glfs_t *fs = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -818,7 +853,12 @@ out:
if (fd)
fd_unref (fd);
+ __GLFS_EXIT_FS;
+
return ret;
+
+invalid_fs:
+ return -1;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv_async, 3.4.0);
@@ -886,7 +926,8 @@ pub_glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt,
struct iovec iov = {0, };
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -951,6 +992,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1014,19 +1058,22 @@ pub_glfs_pwritev_async (struct glfs_fd *glfd, const struct iovec *iovec,
void *data)
{
struct glfs_io *gio = NULL;
- int ret = 0;
+ int ret = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t);
if (!gio) {
errno = ENOMEM;
- return -1;
+ goto out;
}
gio->iov = iov_dup (iovec, count);
if (!gio->iov) {
GF_FREE (gio);
errno = ENOMEM;
- return -1;
+ goto out;
}
gio->op = GF_FOP_WRITE;
@@ -1046,6 +1093,10 @@ pub_glfs_pwritev_async (struct glfs_fd *glfd, const struct iovec *iovec,
GF_FREE (gio);
}
+out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1109,7 +1160,8 @@ pub_glfs_fsync (struct glfs_fd *glfd)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -1133,6 +1185,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1175,7 +1230,17 @@ glfs_fsync_async_common (struct glfs_fd *glfd, glfs_io_cbk fn, void *data,
int
pub_glfs_fsync_async (struct glfs_fd *glfd, glfs_io_cbk fn, void *data)
{
- return glfs_fsync_async_common (glfd, fn, data, 0);
+ int ret = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
+
+ ret = glfs_fsync_async_common (glfd, fn, data, 0);
+
+ __GLFS_EXIT_FS;
+
+invalid_fs:
+ return ret;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync_async, 3.4.0);
@@ -1188,7 +1253,8 @@ pub_glfs_fdatasync (struct glfs_fd *glfd)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -1212,6 +1278,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1221,7 +1290,17 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync, 3.4.0);
int
pub_glfs_fdatasync_async (struct glfs_fd *glfd, glfs_io_cbk fn, void *data)
{
- return glfs_fsync_async_common (glfd, fn, data, 1);
+ int ret = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
+
+ ret = glfs_fsync_async_common (glfd, fn, data, 1);
+
+ __GLFS_EXIT_FS;
+
+invalid_fs:
+ return ret;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync_async, 3.4.0);
@@ -1234,7 +1313,8 @@ pub_glfs_ftruncate (struct glfs_fd *glfd, off_t offset)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -1258,6 +1338,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1269,12 +1352,15 @@ pub_glfs_ftruncate_async (struct glfs_fd *glfd, off_t offset, glfs_io_cbk fn,
void *data)
{
struct glfs_io *gio = NULL;
- int ret = 0;
+ int ret = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t);
if (!gio) {
errno = ENOMEM;
- return -1;
+ goto out;
}
gio->op = GF_FOP_FTRUNCATE;
@@ -1292,6 +1378,10 @@ pub_glfs_ftruncate_async (struct glfs_fd *glfd, off_t offset, glfs_io_cbk fn,
GF_FREE (gio);
}
+out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1307,7 +1397,8 @@ pub_glfs_access (struct glfs *fs, const char *path, int mode)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1332,6 +1423,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1349,7 +1443,8 @@ pub_glfs_symlink (struct glfs *fs, const char *data, const char *path)
dict_t *xattr_req = NULL;
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1416,6 +1511,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1432,7 +1530,8 @@ pub_glfs_readlink (struct glfs *fs, const char *path, char *buf, size_t bufsiz)
int reval = 0;
char *linkval = NULL;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1467,6 +1566,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1484,7 +1586,8 @@ pub_glfs_mknod (struct glfs *fs, const char *path, mode_t mode, dev_t dev)
dict_t *xattr_req = NULL;
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1551,6 +1654,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1568,7 +1674,8 @@ pub_glfs_mkdir (struct glfs *fs, const char *path, mode_t mode)
dict_t *xattr_req = NULL;
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1635,6 +1742,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1650,7 +1760,8 @@ pub_glfs_unlink (struct glfs *fs, const char *path)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1684,6 +1795,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1699,7 +1813,8 @@ pub_glfs_rmdir (struct glfs *fs, const char *path)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1733,6 +1848,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1750,7 +1868,8 @@ pub_glfs_rename (struct glfs *fs, const char *oldpath, const char *newpath)
struct iatt newiatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1809,6 +1928,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1826,7 +1948,8 @@ pub_glfs_link (struct glfs *fs, const char *oldpath, const char *newpath)
struct iatt newiatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1885,6 +2008,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1901,7 +2027,8 @@ pub_glfs_opendir (struct glfs *fs, const char *path)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1961,6 +2088,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return glfd;
}
@@ -1970,13 +2100,21 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_opendir, 3.4.0);
int
pub_glfs_closedir (struct glfs_fd *glfd)
{
- __glfs_entry_fd (glfd);
+ int ret = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
gf_dirent_free (list_entry (&glfd->entries, gf_dirent_t, list));
glfs_fd_destroy (glfd);
- return 0;
+ __GLFS_EXIT_FS;
+
+ ret = 0;
+
+invalid_fs:
+ return ret;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_closedir, 3.4.0);
@@ -2026,12 +2164,15 @@ pub_glfs_discard_async (struct glfs_fd *glfd, off_t offset, size_t len,
glfs_io_cbk fn, void *data)
{
struct glfs_io *gio = NULL;
- int ret = 0;
+ int ret = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t);
if (!gio) {
errno = ENOMEM;
- return -1;
+ goto out;
}
gio->op = GF_FOP_DISCARD;
@@ -2050,6 +2191,10 @@ pub_glfs_discard_async (struct glfs_fd *glfd, off_t offset, size_t len,
GF_FREE (gio);
}
+out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2061,12 +2206,15 @@ pub_glfs_zerofill_async (struct glfs_fd *glfd, off_t offset, off_t len,
glfs_io_cbk fn, void *data)
{
struct glfs_io *gio = NULL;
- int ret = 0;
+ int ret = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t);
if (!gio) {
errno = ENOMEM;
- return -1;
+ goto out;
}
gio->op = GF_FOP_ZEROFILL;
@@ -2085,6 +2233,10 @@ pub_glfs_zerofill_async (struct glfs_fd *glfd, off_t offset, off_t len,
GF_FREE (gio);
}
+out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2240,7 +2392,8 @@ pub_glfs_readdirplus_r (struct glfs_fd *glfd, struct stat *stat,
gf_dirent_t *entry = NULL;
struct dirent *buf = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
errno = 0;
@@ -2251,7 +2404,8 @@ pub_glfs_readdirplus_r (struct glfs_fd *glfd, struct stat *stat,
if (!buf) {
errno = ENOMEM;
- return -1;
+ ret = -1;
+ goto out;
}
entry = glfd_entry_next (glfd, !!stat);
@@ -2271,7 +2425,13 @@ pub_glfs_readdirplus_r (struct glfs_fd *glfd, struct stat *stat,
glfs_iatt_to_stat (glfd->fs, &entry->d_stat, stat);
}
+out:
+ __GLFS_EXIT_FS;
+
return ret;
+
+invalid_fs:
+ return -1;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdirplus_r, 3.4.0);
@@ -2321,7 +2481,8 @@ pub_glfs_statvfs (struct glfs *fs, const char *path, struct statvfs *buf)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -2346,6 +2507,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2362,7 +2526,8 @@ glfs_setattr (struct glfs *fs, const char *path, struct iatt *iatt,
struct iatt riatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -2390,6 +2555,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2401,7 +2569,8 @@ glfs_fsetattr (struct glfs_fd *glfd, struct iatt *iatt, int valid)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -2425,6 +2594,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2652,7 +2824,8 @@ glfs_getxattr_common (struct glfs *fs, const char *path, const char *name,
dict_t *xattr = NULL;
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -2685,6 +2858,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2718,7 +2894,8 @@ pub_glfs_fgetxattr (struct glfs_fd *glfd, const char *name, void *value,
dict_t *xattr = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -2746,6 +2923,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2791,7 +2971,8 @@ glfs_listxattr_common (struct glfs *fs, const char *path, void *value,
dict_t *xattr = NULL;
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -2825,6 +3006,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2855,7 +3039,8 @@ pub_glfs_flistxattr (struct glfs_fd *glfd, void *value, size_t size)
dict_t *xattr = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -2883,6 +3068,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2899,7 +3087,8 @@ glfs_setxattr_common (struct glfs *fs, const char *path, const char *name,
dict_t *xattr = NULL;
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -2937,6 +3126,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -2970,7 +3162,8 @@ pub_glfs_fsetxattr (struct glfs_fd *glfd, const char *name, const void *value,
dict_t *xattr = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -3004,6 +3197,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3020,7 +3216,8 @@ glfs_removexattr_common (struct glfs *fs, const char *path, const char *name,
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -3049,6 +3246,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3078,7 +3278,8 @@ pub_glfs_fremovexattr (struct glfs_fd *glfd, const char *name)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -3102,6 +3303,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3115,7 +3319,8 @@ pub_glfs_fallocate (struct glfs_fd *glfd, int keep_size, off_t offset, size_t le
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -3139,6 +3344,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3152,7 +3360,8 @@ pub_glfs_discard (struct glfs_fd *glfd, off_t offset, size_t len)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -3176,6 +3385,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3189,7 +3401,8 @@ pub_glfs_zerofill (struct glfs_fd *glfd, off_t offset, off_t len)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -3211,6 +3424,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3226,7 +3442,8 @@ pub_glfs_chdir (struct glfs *fs, const char *path)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -3255,6 +3472,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3269,7 +3489,8 @@ pub_glfs_fchdir (struct glfs_fd *glfd)
xlator_t *subvol = NULL;
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -3301,6 +3522,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3318,7 +3542,8 @@ pub_glfs_realpath (struct glfs *fs, const char *path, char *resolved_path)
struct iatt iatt = {0, };
int reval = 0;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
if (resolved_path)
retpath = resolved_path;
@@ -3361,6 +3586,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return retpath;
}
@@ -3374,7 +3602,8 @@ pub_glfs_getcwd (struct glfs *fs, char *buf, size_t n)
inode_t *inode = NULL;
char *path = NULL;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
if (!buf || n < 2) {
ret = -1;
@@ -3405,6 +3634,9 @@ out:
if (inode)
inode_unref (inode);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
if (ret < 0)
return NULL;
@@ -3445,7 +3677,8 @@ pub_glfs_posix_lock (struct glfs_fd *glfd, int cmd, struct flock *flock)
struct gf_flock saved_flock = {0, };
fd_t *fd = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
subvol = glfs_active_subvol (glfd->fs);
if (!subvol) {
@@ -3475,6 +3708,9 @@ out:
glfs_subvol_done (glfd->fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3489,7 +3725,8 @@ pub_glfs_dup (struct glfs_fd *glfd)
glfs_fd_t *dupfd = NULL;
struct glfs *fs = NULL;
- __glfs_entry_fd (glfd);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs);
fs = glfd->fs;
subvol = glfs_active_subvol (fs);
@@ -3519,6 +3756,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return dupfd;
}
@@ -3640,7 +3880,8 @@ glfs_anonymous_pwritev (struct glfs *fs, struct glfs_object *object,
int ret = -1;
size_t size = -1;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -3714,6 +3955,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -3731,7 +3975,8 @@ glfs_anonymous_preadv (struct glfs *fs, struct glfs_object *object,
ssize_t ret = -1;
ssize_t size = -1;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -3778,5 +4023,8 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c
index 2793e1cb118..8ff23ecff03 100644
--- a/api/src/glfs-handleops.c
+++ b/api/src/glfs-handleops.c
@@ -72,13 +72,15 @@ pub_glfs_h_lookupat (struct glfs *fs, struct glfs_object *parent,
struct glfs_object *object = NULL;
loc_t loc = {0, };
+ DECLARE_OLD_THIS;
+
/* validate in args */
- if ((fs == NULL) || (path == NULL)) {
+ if (path == NULL) {
errno = EINVAL;
return NULL;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -116,6 +118,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return object;
}
@@ -130,13 +135,15 @@ pub_glfs_h_statfs (struct glfs *fs, struct glfs_object *object,
inode_t *inode = NULL;
loc_t loc = {0, };
+ DECLARE_OLD_THIS;
+
/* validate in args */
if ((fs == NULL) || (object == NULL || statvfs == NULL)) {
errno = EINVAL;
return -1;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -168,6 +175,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -182,13 +192,15 @@ pub_glfs_h_stat (struct glfs *fs, struct glfs_object *object, struct stat *stat)
loc_t loc = {0, };
struct iatt iatt = {0, };
+ DECLARE_OLD_THIS;
+
/* validate in args */
if ((fs == NULL) || (object == NULL)) {
errno = EINVAL;
return -1;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -224,6 +236,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -234,7 +249,7 @@ int
pub_glfs_h_getattrs (struct glfs *fs, struct glfs_object *object,
struct stat *stat)
{
- int ret = 0;
+ int ret = -1;
xlator_t *subvol = NULL;
inode_t *inode = NULL;
struct iatt iatt = {0, };
@@ -245,7 +260,8 @@ pub_glfs_h_getattrs (struct glfs *fs, struct glfs_object *object,
return -1;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -258,6 +274,7 @@ pub_glfs_h_getattrs (struct glfs *fs, struct glfs_object *object,
/* get/refresh the in arg objects inode in correlation to the xlator */
inode = glfs_resolve_inode (fs, subvol, object);
if (!inode) {
+ ret = 0;
errno = ESTALE;
goto out;
}
@@ -276,6 +293,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -297,8 +317,6 @@ glfs_h_getxattrs_common (struct glfs *fs, struct glfs_object *object,
return -1;
}
- __glfs_entry_fs (fs);
-
/* get the active volume */
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -336,7 +354,7 @@ int
pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
const char *name, void *value, size_t size)
{
- int ret = 0;
+ int ret = -1;
dict_t *xattr = NULL;
/* validate in args */
@@ -345,6 +363,9 @@ pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
return -1;
}
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
ret = glfs_h_getxattrs_common (fs, object, &xattr, name);
if (ret)
goto out;
@@ -358,6 +379,10 @@ pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object,
out:
if (xattr)
dict_unref (xattr);
+
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -380,7 +405,8 @@ pub_glfs_h_setattrs (struct glfs *fs, struct glfs_object *object,
return -1;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -414,6 +440,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -438,7 +467,8 @@ pub_glfs_h_setxattrs (struct glfs *fs, struct glfs_object *object,
return -1;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -480,6 +510,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -501,7 +534,8 @@ pub_glfs_h_removexattrs (struct glfs *fs, struct glfs_object *object,
return -1;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -533,6 +567,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -554,7 +591,8 @@ pub_glfs_h_open (struct glfs *fs, struct glfs_object *object, int flags)
return NULL;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -622,6 +660,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return glfd;
}
@@ -648,7 +689,8 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path,
return NULL;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -726,6 +768,7 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path,
out:
if (ret && object != NULL) {
+ /* Release the held reference */
glfs_h_close (object);
object = NULL;
}
@@ -745,6 +788,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return object;
}
@@ -770,7 +816,8 @@ pub_glfs_h_mkdir (struct glfs *fs, struct glfs_object *parent, const char *path,
return NULL;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -837,6 +884,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return object;
}
@@ -862,7 +912,8 @@ pub_glfs_h_mknod (struct glfs *fs, struct glfs_object *parent, const char *path,
return NULL;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -928,6 +979,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return object;
}
@@ -948,7 +1002,8 @@ pub_glfs_h_unlink (struct glfs *fs, struct glfs_object *parent, const char *path
return -1;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -995,6 +1050,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1016,7 +1074,8 @@ pub_glfs_h_opendir (struct glfs *fs, struct glfs_object *object)
return NULL;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1074,6 +1133,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return glfd;
}
@@ -1094,7 +1156,8 @@ pub_glfs_h_access (struct glfs *fs, struct glfs_object *object, int mask)
goto out;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1128,6 +1191,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1185,7 +1251,8 @@ pub_glfs_h_create_from_handle (struct glfs *fs, unsigned char *handle, int len,
return NULL;
}
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1255,6 +1322,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return object;
}
@@ -1264,7 +1334,6 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_create_from_handle, 3.4.2);
int
pub_glfs_h_close (struct glfs_object *object)
{
- /* Release the held reference */
inode_unref (object->inode);
GF_FREE (object);
@@ -1282,13 +1351,15 @@ pub_glfs_h_truncate (struct glfs *fs, struct glfs_object *object, off_t offset)
xlator_t *subvol = NULL;
inode_t *inode = NULL;
+ DECLARE_OLD_THIS;
+
/* validate in args */
- if ((fs == NULL) || (object == NULL)) {
+ if (object == NULL) {
errno = EINVAL;
return -1;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1323,6 +1394,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1342,14 +1416,16 @@ pub_glfs_h_symlink (struct glfs *fs, struct glfs_object *parent,
dict_t *xattr_req = NULL;
struct glfs_object *object = NULL;
+ DECLARE_OLD_THIS;
+
/* validate in args */
- if ((fs == NULL) || (parent == NULL) || (name == NULL) ||
+ if ((parent == NULL) || (name == NULL) ||
(data == NULL)) {
errno = EINVAL;
return NULL;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1421,6 +1497,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return object;
}
@@ -1437,13 +1516,15 @@ pub_glfs_h_readlink (struct glfs *fs, struct glfs_object *object, char *buf,
inode_t *inode = NULL;
char *linkval = NULL;
+ DECLARE_OLD_THIS;
+
/* validate in args */
- if ((fs == NULL) || (object == NULL) || (buf == NULL)) {
+ if ((object == NULL) || (buf == NULL)) {
errno = EINVAL;
return -1;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1481,6 +1562,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1498,14 +1582,16 @@ pub_glfs_h_link (struct glfs *fs, struct glfs_object *linksrc,
loc_t oldloc = {0, };
loc_t newloc = {0, };
+ DECLARE_OLD_THIS;
+
/* validate in args */
- if ((fs == NULL) || (linksrc == NULL) || (parent == NULL) ||
+ if ((linksrc == NULL) || (parent == NULL) ||
(name == NULL)) {
errno = EINVAL;
return -1;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1570,6 +1656,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1590,14 +1679,16 @@ pub_glfs_h_rename (struct glfs *fs, struct glfs_object *olddir,
struct iatt oldiatt = {0, };
struct iatt newiatt = {0, };
+ DECLARE_OLD_THIS;
+
/* validate in args */
- if ((fs == NULL) || (olddir == NULL) || (oldname == NULL) ||
+ if ((olddir == NULL) || (oldname == NULL) ||
(newdir == NULL) || (newname == NULL)) {
errno = EINVAL;
return -1;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
/* get the active volume */
subvol = glfs_active_subvol (fs);
@@ -1667,6 +1758,9 @@ out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1777,19 +1871,21 @@ pub_glfs_h_poll_upcall (struct glfs *fs, struct callback_arg *up_arg)
int ret = -1;
struct gf_upcall *upcall_data = NULL;
- if (!fs || !up_arg) {
+ DECLARE_OLD_THIS;
+
+ if (!up_arg) {
errno = EINVAL;
goto err;
}
- __glfs_entry_fs (fs);
+ __GLFS_ENTRY_VALIDATE_FS (fs, err);
/* get the active volume */
subvol = glfs_active_subvol (fs);
if (!subvol) {
errno = EIO;
- goto err;
+ goto restore;
}
/* Ideally applications should stop polling before calling
@@ -1871,6 +1967,8 @@ out:
glfs_subvol_done (fs, subvol);
+restore:
+ __GLFS_EXIT_FS;
err:
return ret;
}
@@ -1890,23 +1988,32 @@ pub_glfs_h_acl_set (struct glfs *fs, struct glfs_object *object,
const char *acl_key = NULL;
ssize_t acl_len = 0;
- if (!fs || !object || !acl) {
+ DECLARE_OLD_THIS;
+
+ if (!object || !acl) {
errno = EINVAL;
return ret;
}
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
acl_key = gf_posix_acl_get_key (type);
if (!acl_key)
- return ret;
+ goto out;
acl_s = acl_to_any_text (acl, NULL, ',',
TEXT_ABBREVIATE | TEXT_NUMERIC_IDS);
if (!acl_s)
- return ret;
+ goto out;
ret = pub_glfs_h_setxattrs (fs, object, acl_key, acl_s, acl_len, 0);
acl_free (acl_s);
+
+out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1920,18 +2027,22 @@ pub_glfs_h_acl_get (struct glfs *fs, struct glfs_object *object,
dict_t *xattr = NULL;
const char *acl_key = NULL;
- if (!fs || !object) {
+ DECLARE_OLD_THIS;
+
+ if (!object) {
errno = EINVAL;
return NULL;
}
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
acl_key = gf_posix_acl_get_key (type);
if (!acl_key)
- return NULL;
+ goto out;
ret = glfs_h_getxattrs_common (fs, object, &xattr, acl_key);
if (ret)
- return NULL;
+ goto out;
ret = dict_get_str (xattr, (char *)acl_key, &acl_s);
if (ret == -1)
@@ -1941,6 +2052,10 @@ pub_glfs_h_acl_get (struct glfs *fs, struct glfs_object *object,
out:
GF_FREE (acl_s);
+
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return acl;
}
#else /* !HAVE_ACL_LIBACL_H */
diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h
index 275f8d1534b..384050be8ad 100644
--- a/api/src/glfs-internal.h
+++ b/api/src/glfs-internal.h
@@ -199,18 +199,32 @@ int glfs_first_lookup (xlator_t *subvol);
void glfs_process_upcall_event (struct glfs *fs, void *data);
GFAPI_PRIVATE(glfs_process_upcall_event, 3.7.0);
-static inline void
-__glfs_entry_fs (struct glfs *fs)
-{
- THIS = fs->ctx->master;
-}
-
-
-static inline void
-__glfs_entry_fd (struct glfs_fd *fd)
-{
- THIS = fd->fd->inode->table->xl->ctx->master;
-}
+#define DECLARE_OLD_THIS xlator_t *old_THIS = NULL
+
+#define __GLFS_ENTRY_VALIDATE_FS(fs, label) \
+do { \
+ if (!fs) { \
+ errno = EINVAL; \
+ goto label; \
+ } \
+ old_THIS = THIS; \
+ THIS = fs->ctx->master; \
+} while (0)
+
+#define __GLFS_EXIT_FS \
+do { \
+ THIS = old_THIS; \
+} while (0)
+
+#define __GLFS_ENTRY_VALIDATE_FD(glfd, label) \
+do { \
+ if (!glfd) { \
+ errno = EINVAL; \
+ goto label; \
+ } \
+ old_THIS = THIS; \
+ THIS = glfd->fd->inode->table->xl->ctx->master; \
+} while (0)
/*
diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c
index 81e9fd63fa0..2159d6795ad 100644
--- a/api/src/glfs-mgmt.c
+++ b/api/src/glfs-mgmt.c
@@ -339,6 +339,9 @@ pub_glfs_get_volumeid (struct glfs *fs, char *volid, size_t size)
/* TODO: Define a global macro to store UUID size */
size_t uuid_size = 16;
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
pthread_mutex_lock (&fs->mutex);
{
/* check if the volume uuid is initialized */
@@ -356,12 +359,13 @@ pub_glfs_get_volumeid (struct glfs *fs, char *volid, size_t size)
gf_msg (THIS->name, GF_LOG_ERROR, EINVAL,
API_MSG_FETCH_VOLUUID_FAILED, "Unable to fetch "
"volume UUID");
- return -1;
+ goto out;
}
done:
if (!volid || !size) {
gf_msg_debug (THIS->name, 0, "volumeid/size is null");
+ __GLFS_EXIT_FS;
return uuid_size;
}
@@ -369,12 +373,20 @@ done:
gf_msg (THIS->name, GF_LOG_ERROR, ERANGE, API_MSG_INSUFF_SIZE,
"Insufficient size passed");
errno = ERANGE;
- return -1;
+ goto out;
}
memcpy (volid, fs->vol_uuid, uuid_size);
+ __GLFS_EXIT_FS;
+
return uuid_size;
+
+out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
+ return -1;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_get_volumeid, 3.5.0);
diff --git a/api/src/glfs.c b/api/src/glfs.c
index 23377f651d1..d6a6fe9c850 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -303,6 +303,9 @@ pub_glfs_set_xlator_option (struct glfs *fs, const char *xlator,
{
xlator_cmdline_option_t *option = NULL;
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
option = GF_CALLOC (1, sizeof (*option),
glfs_mt_xlator_cmdline_option_t);
if (!option)
@@ -322,18 +325,25 @@ pub_glfs_set_xlator_option (struct glfs *fs, const char *xlator,
list_add (&option->cmd_args, &fs->ctx->cmd_args.xlator_options);
+ __GLFS_EXIT_FS;
+
return 0;
enomem:
errno = ENOMEM;
- if (!option)
+ if (!option) {
+ __GLFS_EXIT_FS;
return -1;
+ }
GF_FREE (option->volume);
GF_FREE (option->key);
GF_FREE (option->value);
GF_FREE (option);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return -1;
}
@@ -353,6 +363,9 @@ pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport,
return ret;
}
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
cmd_args = &fs->ctx->cmd_args;
list_for_each_entry(server, &cmd_args->curr_server->list, list) {
if ((!strcmp(server->volfile_server, host) &&
@@ -365,6 +378,9 @@ pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport,
}
out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -385,6 +401,9 @@ pub_glfs_set_volfile_server (struct glfs *fs, const char *transport,
return ret;
}
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
cmd_args = &fs->ctx->cmd_args;
cmd_args->max_connect_attempts = 1;
@@ -444,6 +463,9 @@ out:
}
}
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -453,6 +475,9 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_volfile_server, 3.4.0);
int
pub_glfs_setfsuid (uid_t fsuid)
{
+ /* TODO:
+ * - Set the THIS and restore it appropriately
+ */
return syncopctx_setfsuid (&fsuid);
}
@@ -462,6 +487,9 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsuid, 3.4.2);
int
pub_glfs_setfsgid (gid_t fsgid)
{
+ /* TODO:
+ * - Set the THIS and restore it appropriately
+ */
return syncopctx_setfsgid (&fsgid);
}
@@ -471,6 +499,9 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsgid, 3.4.2);
int
pub_glfs_setfsgroups (size_t size, const gid_t *list)
{
+ /* TODO:
+ * - Set the THIS and restore it appropriately
+ */
return syncopctx_setfsgroups(size, list);
}
@@ -563,7 +594,7 @@ pub_glfs_new (const char *volname)
struct glfs *fs = NULL;
int ret = -1;
glusterfs_ctx_t *ctx = NULL;
- gf_boolean_t cleanup_fini = _gf_false;
+ xlator_t *old_THIS = NULL;
if (!volname) {
errno = EINVAL;
@@ -590,47 +621,49 @@ pub_glfs_new (const char *volname)
if (ret != 0)
goto cond_child_destroy;
- cleanup_fini = _gf_true;
-
ctx = glusterfs_ctx_new ();
if (!ctx)
- goto freefs;
+ goto fini;
/* first globals init, for gf_mem_acct_enable_set () */
ret = glusterfs_globals_init (ctx);
if (ret)
- goto freefs;
+ goto fini;
- if (!THIS->ctx)
- THIS->ctx = ctx;
+ old_THIS = THIS;
+ /* THIS is set to NULL so that we do not modify the caller xlators'
+ * ctx, instead we set the global_xlator->ctx
+ */
+ THIS = NULL;
+ THIS->ctx = ctx;
/* then ctx_defaults_init, for xlator_mem_acct_init(THIS) */
ret = glusterfs_ctx_defaults_init (ctx);
if (ret)
- goto freefs;
+ goto fini;
fs->ctx = ctx;
ret = glfs_set_logging (fs, "/dev/null", 0);
if (ret)
- goto freefs;
+ goto fini;
fs->ctx->cmd_args.volfile_id = gf_strdup (volname);
if (!(fs->ctx->cmd_args.volfile_id))
- goto freefs;
+ goto fini;
fs->volname = strdup (volname);
if (!fs->volname)
- goto freefs;
+ goto fini;
INIT_LIST_HEAD (&fs->openfds);
INIT_LIST_HEAD (&fs->upcall_list);
fs->pin_refcnt = 0;
- return fs;
+ goto out;
cond_child_destroy:
pthread_cond_destroy (&fs->child_down_cond);
@@ -642,7 +675,10 @@ mutex_destroy:
pthread_mutex_destroy (&fs->mutex);
freefs:
-
+ FREE (fs);
+ fs = NULL;
+ goto out;
+fini:
/*
* When pthread_*init() fails there is no way for other cleanup
* funtions (glfs_fini/glfs_free_from_ctx) to know which of them succeded
@@ -651,14 +687,13 @@ freefs:
* directly call glfs_fini() to cleanup the resources.
*/
- if (!cleanup_fini)
- FREE(fs);
- else
- glfs_fini (fs);
- fs = NULL;
+ glfs_fini (fs);
+ fs = NULL;
+out:
+ if (old_THIS)
+ THIS = old_THIS;
return fs;
-
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_new, 3.4.0);
@@ -750,9 +785,12 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_volfile, 3.4.0);
int
pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel)
{
- int ret = 0;
+ int ret = -1;
char *tmplog = NULL;
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
if (!logfile) {
ret = gf_set_log_file_path (&fs->ctx->cmd_args);
if (ret)
@@ -775,6 +813,9 @@ pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel)
goto out;
out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -882,6 +923,8 @@ pub_glfs_init (struct glfs *fs)
{
int ret = -1;
+ DECLARE_OLD_THIS;
+
if (!fs || !fs->ctx) {
gf_msg ("glfs", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY,
"fs is not properly initialized.");
@@ -889,17 +932,22 @@ pub_glfs_init (struct glfs *fs)
return ret;
}
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
ret = glfs_init_common (fs);
if (ret)
- return ret;
+ goto out;
ret = glfs_init_wait (fs);
+out:
+ __GLFS_EXIT_FS;
/* Set the initial current working directory to "/" */
if (ret >= 0) {
ret = glfs_chdir (fs, "/");
}
+invalid_fs:
return ret;
}
@@ -985,19 +1033,15 @@ pub_glfs_fini (struct glfs *fs)
int fs_init = 0;
int err = -1;
+ DECLARE_OLD_THIS;
- if (!fs) {
- errno = EINVAL;
- return 0;
- }
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
ctx = fs->ctx;
if (!ctx) {
goto free_fs;
}
- __glfs_entry_fs (fs);
-
if (ctx->mgmt) {
rpc_clnt_disable (ctx->mgmt);
ctx->mgmt = NULL;
@@ -1141,6 +1185,9 @@ fail:
if (!ret)
ret = err;
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1150,7 +1197,10 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fini, 3.4.0);
ssize_t
pub_glfs_get_volfile (struct glfs *fs, void *buf, size_t len)
{
- ssize_t res;
+ ssize_t res = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
glfs_lock(fs);
if (len >= fs->oldvollen) {
@@ -1164,6 +1214,9 @@ pub_glfs_get_volfile (struct glfs *fs, void *buf, size_t len)
}
glfs_unlock(fs);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return res;
}
@@ -1173,9 +1226,10 @@ int
pub_glfs_ipc (struct glfs *fs, int opcode)
{
xlator_t *subvol = NULL;
- int ret;
+ int ret = -1;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1189,6 +1243,9 @@ pub_glfs_ipc (struct glfs *fs, int opcode)
out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
diff --git a/heal/src/glfs-heal.c b/heal/src/glfs-heal.c
index 770a3c6883c..cbdb5930cc2 100644
--- a/heal/src/glfs-heal.c
+++ b/heal/src/glfs-heal.c
@@ -773,7 +773,6 @@ main (int argc, char **argv)
}
sleep (2);
- __glfs_entry_fs (fs);
top_subvol = glfs_active_subvol (fs);
if (!top_subvol) {
ret = -1;