summaryrefslogtreecommitdiffstats
path: root/glusterfs.spec.in
diff options
context:
space:
mode:
authorKaleb S. KEITHLEY <kkeithle@redhat.com>2013-06-07 09:46:12 -0400
committerAnand Avati <avati@redhat.com>2013-06-21 10:32:39 -0700
commit159938575b43ce9af503c74560e044ee69d1395c (patch)
tree922c72dd749326a44698a141f247a375e10db2ad /glusterfs.spec.in
parentcc477c7da1b543d51939aba919155a651099d4ba (diff)
build: sync glusterfs.spec.in with Fedora glusterfs.spec
(This is the release-3.4 branch.) * remove G4S/UFO from community packaging. The Fedora/EPEL packaging will follow suit once the glusterfs-openstack-swift packaging materializes from the G4S team. Note that for the time being 'make dist' still creates a UFO tarball from the .../ufo directory for use by fedora packaging. * add glusterfs-api and glusterfs-api-devel sub-packages * add extras/systemd/glusterd.service. Use it (or extras/init.d/glusterd) instead of the Fedora versions. * restores ability to build glusterfs RPMs from the dist tarball with 'rpmbuild {-ts,-tb,-ta} glusterfs-XXX.tar.gz' * reverse {--with,--without}_fusermount in sync with fedora .spec and master branch * other minor cleanups mostly to sync with fedora .spec and to build from the dist tarball. Any differences will be resolved in the fedora .spec in the next release (i.e. beta4 or GA). * this is nominally for "the impending merge of .../api from master" but should be independent of that change. (still deciding whether to add the fedora glusterfsd.{init,service) files here or remove them from fedora.) BUG: 819130 Change-Id: I90c7355ca02239995b1df7646e3cd10ec227bcc5 Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com> Reviewed-on: http://review.gluster.org/5179 Reviewed-by: Niels de Vos <ndevos@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'glusterfs.spec.in')
-rw-r--r--glusterfs.spec.in933
1 files changed, 136 insertions, 797 deletions
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
index c54dcb50da2..4277a601230 100644
--- a/glusterfs.spec.in
+++ b/glusterfs.spec.in
@@ -1,6 +1,11 @@
+%global _hardened_build 1
+
%global _for_fedora_koji_builds 0
+# uncomment and add '%' to use the prereltag for pre-releases
+# global prereltag beta2
+
# if you wish to compile an rpm without rdma support, compile like this...
# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without rdma
%{?_without_rdma:%global _without_rdma --disable-ibverbs}
@@ -14,9 +19,9 @@
# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without epoll
%{?_without_epoll:%global _without_epoll --disable-epoll}
-# if you wish to compile an rpm with fusermount...
-# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --with fusermount
-%{?_with_fusermount:%global _with_fusermount --enable-fusermount}
+# if you wish to compile an rpm without fusermount...
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without fusermount
+%{?_without_fusermount:%global _without_fusermount --disable-fusermount}
# if you wish to compile an rpm without geo-replication support, compile like this...
# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without georeplication
@@ -26,66 +31,45 @@
# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without ocf
%{?_without_ocf:%global _without_ocf --without-ocf}
-# if you wish to build rpms without UFO, compile like this
-# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@tar.gz --without ufo
-%{?_without_ufo:%global _without_ufo true}
-
-%if ( 0%{?fedora} ) || ( 0%{?rhel} && 0%{?rhel} >= 6 )
-%global SWIFTVER 1.8.0
-%if 0%{_for_fedora_koji_builds}
-%global UFOVER 1.1
-%else
-%global UFOVER @PACKAGE_VERSION@
-%endif
-%if ! 0%{?_without_ufo:1}
-%global _with_ufo true
-%endif
-%endif
-
%if ( 0%{?fedora} && 0%{?fedora} > 16 ) || ( 0%{?rhel} && 0%{?rhel} > 6 )
%global _with_systemd true
%endif
Summary: Cluster File System
-%if 0%{_for_fedora_koji_builds}
+%if ( 0%{_for_fedora_koji_builds} )
Name: glusterfs
-Version: 3.3.1
-Release: 10%{?dist}
+Version: 3.4.0
+Release: 0.5%{?prereltag:.%{prereltag}}%{?dist}
+Vendor: Fedora Project
%else
Name: @PACKAGE_NAME@
Version: @PACKAGE_VERSION@
Release: 1%{?dist}
+Vendor: glusterfs.org
%endif
-License: GPLv3+ and (GPLv2 or LGPLv3+)
+License: GPLv2 or LGPLv3+
Group: System Environment/Base
-%if 0%{_for_fedora_koji_builds}
-Vendor: Red Hat
-%endif
-URL: http://www.gluster.org//docs/index.php/GlusterFS
-%if 0%{_for_fedora_koji_builds}
-Source0: http://bits.gluster.com/pub/gluster/glusterfs/src/glusterfs-%{version}.tar.gz
-%else
-Source0: @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz
-%endif
+URL: http://www.gluster.org/docs/index.php/GlusterFS
+%if ( 0%{_for_fedora_koji_builds} )
+Source0: http://download.gluster.org/pub/gluster/glusterfs/qa-releases/%{PACKAGE_VERSION}%{?prereltag}/glusterfs-%{version}%{?prereltag}.tar.gz
Source1: glusterd.sysconfig
Source2: glusterfsd.sysconfig
Source3: umount.glusterfs
Source4: glusterfs-fuse.logrotate
Source5: glusterd.logrotate
Source6: glusterfsd.logrotate
+Source7: rhel5-load-fuse-modules
+Source11: glusterfsd.service
+Source13: glusterfsd.init
Patch0: %{name}-3.2.5.configure.ac.patch
Patch1: %{name}-3.3.0.libglusterfs.Makefile.patch
+%else
+Source0: @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz
+%endif
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
-Source10: glusterd.service
-Source11: glusterfsd.service
-Source12: glusterd.init
-Source13: glusterfsd.init
-
-%if 0%{?_with_systemd:1}
-%global glusterd_service %{S:%{SOURCE10}}
-%global glusterfsd_service %{S:%{SOURCE11}}
+%if ( 0%{?_with_systemd:1} )
BuildRequires: systemd-units
Requires(post): systemd-units
Requires(preun): systemd-units
@@ -94,19 +78,10 @@ Requires(postun): systemd-units
%define _init_disable() /bin/systemctl disable %1.service ;
%define _init_restart() /bin/systemctl try-restart %1.service ;
%define _init_stop() /bin/systemctl stop %1.service ;
-%define _init_install() %{__install} -D -p -m 0644 %1 %{buildroot}%{_unitdir}/%2.service ;
# can't seem to make a generic macro that works
%define _init_glusterd %{_unitdir}/glusterd.service
%define _init_glusterfsd %{_unitdir}/glusterfsd.service
-%define _init_gluster_swift_account %{_unitdir}/gluster-swift-account.service
-%define _init_gluster_swift_container %{_unitdir}/gluster-swift-container.service
-%define _init_gluster_swift_object %{_unitdir}/gluster-swift-object.service
-%define _init_gluster_swift_proxy %{_unitdir}/gluster-swift-proxy.service
%else
-%if 0%{_for_fedora_koji_builds}
-%global glusterd_service %{S:%{SOURCE12}}
-%global glusterfsd_service %{S:%{SOURCE13}}
-%endif
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/service
Requires(preun): /sbin/chkconfig
@@ -115,14 +90,9 @@ Requires(postun): /sbin/service
%define _init_disable() /sbin/chkconfig --del %1 ;
%define _init_restart() /sbin/service %1 condrestart &>/dev/null ;
%define _init_stop() /sbin/service %1 stop &>/dev/null ;
-%define _init_install() %{__install} -D -p -m 0755 %1 %{buildroot}%{_sysconfdir}/init.d/%2 ;
# can't seem to make a generic macro that works
%define _init_glusterd %{_sysconfdir}/init.d/glusterd
%define _init_glusterfsd %{_sysconfdir}/init.d/glusterfsd
-%define _init_gluster_swift_account %{_sysconfdir}/init.d/gluster-swift-account
-%define _init_gluster_swift_container %{_sysconfdir}/init.d/gluster-swift-container
-%define _init_gluster_swift_object %{_sysconfdir}/init.d/gluster-swift-object
-%define _init_gluster_swift_proxy %{_sysconfdir}/init.d/gluster-swift-proxy
%endif
BuildRequires: bison flex
@@ -130,11 +100,11 @@ BuildRequires: gcc make automake libtool
BuildRequires: ncurses-devel readline-devel
BuildRequires: libxml2-devel openssl-devel
BuildRequires: libaio-devel
-#BuildRequires: systemtap-sdt-devel lvm2-devel # glusterfs-3.4.x
-%if 0%{?suse_version}
+BuildRequires: systemtap-sdt-devel
BuildRequires: python-devel
-%else
BuildRequires: python-ctypes
+%if ( 0%{?fedora} ) || ( 0%{?rhel} && 0%{?rhel} >= 6 )
+BuildRequires: lvm2-devel
%endif
Obsoletes: hekafs <= 0.7
@@ -145,6 +115,20 @@ Provides: %{name}-libs = %{version}-%{release}
Provides: %{name}-common = %{version}-%{release}
Provides: %{name}-core = %{version}-%{release}
+# We do not want to generate useless provides and requires for xlator .so files
+# Filter all generated:
+#
+# TODO: RHEL5 does not have a convenient solution
+%if ( 0%{?rhel} == 6 )
+ # filter_setup exists in RHEL6 only
+ %filter_provides_in %{_libdir}/glusterfs/%{version}/
+ %global __filter_from_req %{?__filter_from_req} | %{__grep} -v -P '^(?!lib).*\.so.*$'
+ %filter_setup
+%else
+ # modern rpm and current Fedora do not generate requires when the
+ # provides are filtered
+ %global __provides_exclude_from ^%{_libdir}/glusterfs/%{version}/.*$
+%endif
%description
GlusterFS is a clustered file-system capable of scaling to several
@@ -159,7 +143,7 @@ This package includes the glusterfs binary, the glusterfsd daemon and the
gluster command line, libglusterfs and glusterfs translator modules common to
both GlusterFS server and client framework.
-%if 0%{!?_without_rdma:1}
+%if ( 0%{!?_without_rdma:1} )
%package rdma
Summary: GlusterFS rdma support for ib-verbs
Group: Applications/File
@@ -179,7 +163,7 @@ is in user space and easily manageable.
This package provides support to ib-verbs library.
%endif
-%if 0%{!?_without_georeplication:1}
+%if ( 0%{!?_without_georeplication:1} )
%package geo-replication
Summary: GlusterFS Geo-replication
Group: Applications/File
@@ -225,7 +209,11 @@ License: GPLv3+
Group: System Environment/Daemons
Requires: %{name} = %{version}-%{release}
Requires: %{name}-fuse = %{version}-%{release}
+%if ( 0%{?fedora} ) || ( 0%{?rhel} && 0%{?rhel} >= 6 )
Requires: rpcbind
+%else
+Requires: portmap
+%endif
%description server
GlusterFS is a clustered file-system capable of scaling to several
@@ -238,15 +226,33 @@ is in user space and easily manageable.
This package provides the glusterfs server daemon.
-%if 0%{!?_without_ocf:1}
+%package api
+Summary: Clustered file-system api library
+License: GPLv2 or LGPLv3+
+Group: System Environment/Daemons
+Requires: %{name} = %{version}-%{release}
+
+%description api
+GlusterFS is a clustered file-system capable of scaling to several
+petabytes. It aggregates various storage bricks over Infiniband RDMA
+or TCP/IP interconnect into one large parallel network file
+system. GlusterFS is one of the most sophisticated file systems in
+terms of features and extensibility. It borrows a powerful concept
+called Translators from GNU Hurd kernel. Much of the code in GlusterFS
+is in user space and easily manageable.
+
+This package provides the glusterfs libgfapi library
+
+%if ( 0%{!?_without_ocf:1} )
%package resource-agents
Summary: OCF Resource Agents for GlusterFS
License: GPLv3+
-%if ( 0%{?fedora} ) || ( 0%{?rhel} && 0%{?rhel} >= 6 )
+%if ( ! ( 0%{?rhel} && 0%{?rhel} < 6 ) )
+# EL5 does not support noarch sub-packages
BuildArch: noarch
%endif
# this Group handling comes from the Fedora resource-agents package
-%if 0%{?fedora} || 0%{?centos_version} || 0%{?rhel}
+%if ( 0%{?fedora} || 0%{?centos_version} || 0%{?rhel} )
Group: System Environment/Base
%else
Group: Productivity/Clustering/HA
@@ -287,272 +293,34 @@ is in user space and easily manageable.
This package provides the development libraries.
-%if 0%{?_with_ufo:1}
-%if ( 0%{?fedora} && 0%{?fedora} < 19 ) || ( 0%{?rhel} && 0%{?rhel} < 7 )
-%package swift
-Summary: GlusterFS OpenStack Object Storage
-Group: Applications/System
-License: ASL 2.0
-BuildArch: noarch
-
-%if 0%{_for_fedora_koji_builds}
-Source20: http://launchpad.net/swift/folsom/%{SWIFTVER}/+download/swift-%{SWIFTVER}.tar.gz
-%else
-Source20: swift-%{SWIFTVER}.tar.gz
-%endif
-
-Source30: gluster-swift-account.service
-Source31: gluster-swift-container.service
-Source32: gluster-swift-object.service
-Source33: gluster-swift-proxy.service
-Source34: gluster-swift-account@.service
-Source35: gluster-swift-container@.service
-Source36: gluster-swift-object@.service
-Source37: gluster-swift.tmpfs
-Source40: gluster-swift-account.init
-Source41: gluster-swift-container.init
-Source42: gluster-swift-object.init
-Source43: gluster-swift-proxy.init
-Source44: gluster-swift-functions
-# these first appeared in openstack-swift-1.7.4-2.fc19
-Source50: gluster-swift-account-replicator.service
-Source51: gluster-swift-account-replicator@.service
-Source52: gluster-swift-account-auditor.service
-Source53: gluster-swift-account-auditor@.service
-Source54: gluster-swift-account-reaper.service
-Source55: gluster-swift-account-reaper@.service
-Source56: gluster-swift-container-replicator.service
-Source57: gluster-swift-container-replicator@.service
-Source58: gluster-swift-container-auditor.service
-Source59: gluster-swift-container-auditor@.service
-Source60: gluster-swift-container-updater.service
-Source61: gluster-swift-container-updater@.service
-Source62: gluster-swift-object-replicator.service
-Source63: gluster-swift-object-replicator@.service
-Source64: gluster-swift-object-auditor.service
-Source65: gluster-swift-object-auditor@.service
-Source66: gluster-swift-object-updater.service
-Source67: gluster-swift-object-updater@.service
-Source68: gluster-swift-object-expirer.service
-Source69: gluster-swift-object-expirer@.service
-# these first appeared in openstack-swift-1.7.4-1.fc18 and -1.7.4-2.el6
-Source70: account-server.conf
-Source71: container-server.conf
-Source72: object-server.conf
-Source73: proxy-server.conf
-Source74: swift.conf
-Source75: object-expirer.conf
-
-Patch20: 0001-Use-updated-parallel-install-versions-of-epel-packag.patch
-Patch21: 0002-Add-fixes-for-building-the-doc-package.patch
-Patch22: glusterfs-3.3.1.swift.constraints.backport-1.7.4.patch
-Patch23: glusterfs-3.4.0.swift.egginfo-grizzly.patch
-Patch24: 0002-Add-fixes-for-building-the-doc-package.patch.180
-#BuildRoot: %(mktemp -ud %{_tmppath}/swift-%{SWIFTVER}-%{release}-XXXXXX)
-
-%if 0%{?_with_systemd:1}
-%global glusterswiftaccount_service %{S:%{SOURCE30}}
-%global glusterswiftcontainer_service %{S:%{SOURCE31}}
-%global glusterswiftobject_service %{S:%{SOURCE32}}
-%global glusterswiftproxy_service %{S:%{SOURCE33}}
-%else
-%global glusterswiftaccount_service %{S:%{SOURCE40}}
-%global glusterswiftcontainer_service %{S:%{SOURCE41}}
-%global glusterswiftobject_service %{S:%{SOURCE42}}
-%global glusterswiftproxy_service %{S:%{SOURCE43}}
-%endif
-
-BuildRequires: python-devel
-BuildRequires: python-setuptools
-BuildRequires: python-netifaces
-%if ( 0%{?rhel} && 0%{?rhel} < 7 )
-BuildRequires: python-webob1.0
-BuildRequires: python-paste-deploy1.5
-Requires: python-webob1.0
-Requires: python-paste-deploy1.5
-%else
-BuildRequires: python-webob
-BuildRequires: python-paste-deploy
-Requires: python-webob
-Requires: python-paste-deploy
-%endif
+%package api-devel
+Summary: Development Libraries
+License: GPLv2 or LGPLv3+
+Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
-Requires: python-configobj
-Requires: python-eventlet >= 0.9.8
-Requires: python-greenlet >= 0.3.1
-Requires: python-simplejson
-Requires: pyxattr
-Requires: python-setuptools
-Requires: python-netifaces
-%if "%{SWIFTVER}" != "1.7.4"
-Requires: python-swiftclient
-%endif
-
-%if ( 0%{?fedora} && 0%{?fedora} < 19 ) || ( 0%{?rhel} && 0%{?rhel} < 7 )
-Conflicts: openstack-swift
-%endif
-
-%description swift
-
-OpenStack Object Storage (swift) aggregates commodity servers to work together
-in clusters for reliable, redundant, and large-scale storage of static objects.
-Objects are written to multiple hardware devices in the data center, with the
-OpenStack software responsible for ensuring data replication and integrity
-across the cluster. Storage clusters can scale horizontally by adding new nodes,
-which are automatically configured. Should a node fail, OpenStack works to
-replicate its content from other active nodes. Because OpenStack uses software
-logic to ensure data replication and distribution across different devices,
-inexpensive commodity hard drives and servers can be used in lieu of more
-expensive equipment.
-
-
-%package swift-account
-Summary: A swift account server
-Group: Applications/System
-License: ASL 2.0
-BuildArch: noarch
-Requires: %{name}-swift = %{version}-%{release}
-
-%description swift-account
-OpenStack Object Storage (swift) aggregates commodity servers to work together
-in clusters for reliable, redundant, and large-scale storage of static objects.
-
-This package contains the %{name}-swift account server.
-
-
-%package swift-container
-Summary: A swift container server
-Group: Applications/System
-License: ASL 2.0
-BuildArch: noarch
-Requires: %{name}-swift = %{version}-%{release}
-
-%description swift-container
-OpenStack Object Storage (swift) aggregates commodity servers to work together
-in clusters for reliable, redundant, and large-scale storage of static objects.
-
-This package contains the %{name}-swift container server.
-
-%package swift-object
-Summary: A swift object server
-Group: Applications/System
-License: ASL 2.0
-BuildArch: noarch
-Requires: %{name}-swift = %{version}-%{release}
-Requires: rsync >= 3.0
-
-%description swift-object
-OpenStack Object Storage (swift) aggregates commodity servers to work together
-in clusters for reliable, redundant, and large-scale storage of static objects.
-
-This package contains the %{name}-swift object server.
-
-%package swift-proxy
-Summary: A swift proxy server
-Group: Applications/System
-License: ASL 2.0
-BuildArch: noarch
-Requires: %{name}-swift = %{version}-%{release}
-
-%description swift-proxy
-OpenStack Object Storage (swift) aggregates commodity servers to work together
-in clusters for reliable, redundant, and large-scale storage of static objects.
-This package contains the %{name}-swift proxy server.
-
-
-%package swift-doc
-Summary: Documentation for %{name}
-Group: Documentation
-BuildArch: noarch
-# Required for generating docs
-BuildRequires: python-eventlet
-BuildRequires: python-simplejson
-%if ( 0%{?rhel} && 0%{?rhel} < 7 )
-BuildRequires: python-webob1.0
-BuildRequires: python-sphinx10
-%else
-BuildRequires: python-webob
-BuildRequires: python-sphinx
-%endif
-BuildRequires: pyxattr
-
-%description swift-doc
-OpenStack Object Storage (swift) aggregates commodity servers to work together
-in clusters for reliable, redundant, and large-scale storage of static objects.
-
-This package contains documentation files for %{name}-swift.
-
-%endif
-
-%package ufo
-Summary: GlusterFS Unified File and Object Storage.
-Group: Applications/System
-License: ASL 2.0
-BuildArch: noarch
-%if ( 0%{?fedora} && 0%{?fedora} < 19 ) || ( 0%{?rhel} && 0%{?rhel} < 7 )
-Requires: %{name}-swift = %{version}-%{release}
-%else
-Requires: openstack-swift = %{SWIFTVER}
-%endif
-Requires: memcached
-Requires: openssl
-Requires: python
-Obsoletes: glusterfs-swift-plugin < 3.3.1-4
-Obsoletes: glusterfs-swift-ufo <= 3.3.1-4
-
-%if 0%{_for_fedora_koji_builds}
-Source15: http://download.gluster.org/pub/gluster/glusterfs/3.3/3.3.1/UFO/gluster-swift-ufo-%{UFOVER}.tar.gz
-%else
-Source15: gluster-swift-ufo-@PACKAGE_VERSION@.tar.gz
-%endif
-Patch15: %{name}-3.3.1.ufo.gluster.swift.common.DiskFile-1.7.4.patch
-
-%description ufo
-Gluster Unified File and Object Storage unifies NAS and object storage
-technology. This provides a system for data storage that enables users to access
-the same data as an object and as a file, simplifying management and controlling
-storage costs.
+%description api-devel
+GlusterFS is a clustered file-system capable of scaling to several
+petabytes. It aggregates various storage bricks over Infiniband RDMA
+or TCP/IP interconnect into one large parallel network file
+system. GlusterFS is one of the most sophisticated file systems in
+terms of features and extensibility. It borrows a powerful concept
+called Translators from GNU Hurd kernel. Much of the code in GlusterFS
+is in user space and easily manageable.
-%endif
+This package provides the api include files.
%prep
-%setup -q -n %{name}-%{version}
-%if 0%{?_with_ufo:1}
-# unpack swift-1.x.y
-%setup -q -T -D -n %{name}-%{version} -a 20
-# unpack gluster ufo
-%setup -q -T -D -n %{name}-%{version} -a 15
-%if 0%{_for_fedora_koji_builds}
+%setup -q -n %{name}-%{version}%{?prereltag}
+%if ( 0%{_for_fedora_koji_builds} )
#%patch0 -p0
-%patch1 -p0
-%endif
-cd swift-%{SWIFTVER}
-%if ( 0%{?rhel} && 0%{?rhel} < 7 )
-%patch20 -p1
-%if "%{SWIFTVER}" == "1.7.4"
-%patch21 -p1
-%else
-%patch24 -p1
-%endif
-%endif
-%if "%{SWIFTVER}" == "1.7.4"
-%patch22 -p1
-%else
-%patch23 -p1
-%endif
-%if 0%{_for_fedora_koji_builds}
-%if "%{UFOVER}" == "1.1"
-cd ../ufo
-%patch15 -p1
-%endif
-%endif
+%patch1 -p0 -F4
%endif
%build
./autogen.sh
-%configure %{?_without_rdma} %{?_without_epoll} %{?_with_fusermount} %{?_without_georeplication} %{?_without_ocf}
+%configure %{?_without_rdma} %{?_without_epoll} %{?_without_fusermount} %{?_without_georeplication} %{?_without_ocf}
# Remove rpath
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
@@ -560,19 +328,6 @@ sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
%{__make} %{?_smp_mflags}
-%if 0%{?_with_ufo:1}
-cd swift-%{SWIFTVER}
-%{__python} setup.py build
-%{__mkdir_p} doc/build
-%if ( 0%{?fedora} )
-%{__python} setup.py build_sphinx
-%endif
-cd ..
-cd ufo
-%{__python} setup.py build
-cd ..
-%endif
-
%install
%{__rm} -rf %{buildroot}
%{__make} install DESTDIR=%{buildroot}
@@ -591,7 +346,7 @@ cd ..
%{__mkdir_p} %{buildroot}%{_includedir}/glusterfs/server
%{__install} -p -m 0644 xlators/protocol/server/src/*.h \
%{buildroot}%{_includedir}/glusterfs/server/
-%if 0%{_for_fedora_koji_builds}
+%if ( 0%{_for_fedora_koji_builds} )
%{__install} -D -p -m 0644 %{SOURCE1} \
%{buildroot}%{_sysconfdir}/sysconfig/glusterd
%{__install} -D -p -m 0644 %{SOURCE2} \
@@ -600,15 +355,13 @@ cd ..
%{__install} -D -p -m 0644 extras/glusterd-sysconfig \
%{buildroot}%{_sysconfdir}/sysconfig/glusterd
%endif
-# We'll use our init.d
-%if 0%{?_with_systemd:1}
-%{__rm} -f %{buildroot}%{_sysconfdir}/init.d/glusterd
-%endif
-%if 0%{?rhel} && 0%{?rhel} <= 5
-%{__install} -D -p -m 0755 extras/init.d/rhel5-load-fuse.modules \
+%if ( 0%{_for_fedora_koji_builds} )
+%if ( 0%{?rhel} && 0%{?rhel} <= 5 )
+%{__install} -D -p -m 0755 %{SOURCE7} \
%{buildroot}%{_sysconfdir}/sysconfig/modules/glusterfs-fuse.modules
%endif
+%endif
%{__mkdir_p} %{buildroot}%{_localstatedir}/log/glusterd
%{__mkdir_p} %{buildroot}%{_localstatedir}/log/glusterfs
@@ -619,8 +372,9 @@ cd ..
find %{buildroot}%{_libdir} -name '*.a' -delete
find %{buildroot}%{_libdir} -name '*.la' -delete
-# Remove installed docs, we include them ourselves as %%doc
+# Remove installed docs, they're included by %%doc
%{__rm} -rf %{buildroot}%{_datadir}/doc/glusterfs/
+%{__bzip2} ChangeLog
# Remove benchmarking and other unpackaged files
%{__rm} -rf %{buildroot}/benchmarking
@@ -634,13 +388,7 @@ find %{buildroot}%{_libdir} -name '*.la' -delete
sed -i 's|option working-directory /etc/glusterd|option working-directory %{_sharedstatedir}/glusterd|g' \
%{buildroot}%{_sysconfdir}/glusterfs/glusterd.vol
-# Install systemd .service files. `make install` will install the init files
-%if ( 0%{?_with_systemd:1} ) || ( 0%{_for_fedora_koji_builds} )
-%_init_install %{glusterd_service} glusterd
-%_init_install %{glusterfsd_service} glusterfsd
-%endif
-
-%if 0%{_for_fedora_koji_builds}
+%if ( 0%{_for_fedora_koji_builds} )
# Install wrapper umount script
%{__install} -D -p -m 0755 %{SOURCE3} \
%{buildroot}/sbin/umount.glusterfs
@@ -659,7 +407,7 @@ sed -i 's|option working-directory /etc/glusterd|option working-directory %{_sha
%{buildroot}%{_sysconfdir}/logrotate.d/glusterfs
%endif
-%if 0%{!?_without_georeplication:1}
+%if ( 0%{!?_without_georeplication:1} )
# geo-rep ghosts
%{__mkdir_p} %{buildroot}%{_sharedstatedir}/glusterd/geo-replication
touch %{buildroot}%{_sharedstatedir}/glusterd/geo-replication/gsyncd.conf
@@ -699,100 +447,6 @@ touch %{buildroot}%{_sharedstatedir}/glusterd/options
touch %{buildroot}%{_sharedstatedir}/glusterd/nfs/nfs-server.vol
touch %{buildroot}%{_sharedstatedir}/glusterd/nfs/run/nfs.pid
-%if 0%{?_with_ufo:1}
-cd swift-%{SWIFTVER}
-%{__python} setup.py install -O1 --skip-build --root %{buildroot}
-# common swift .service or .init files
-%_init_install %{glusterswiftaccount_service} gluster-swift-account
-%_init_install %{glusterswiftcontainer_service} gluster-swift-container
-%_init_install %{glusterswiftobject_service} gluster-swift-object
-%_init_install %{glusterswiftproxy_service} gluster-swift-proxy
-%if 0%{?_with_systemd:1}
-# extra systemd .service files
-%_init_install %{SOURCE34} gluster-swift-account@
-%_init_install %{SOURCE35} gluster-swift-container@
-%_init_install %{SOURCE36} gluster-swift-object@
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-# more extra systemd .service files in f19
-%_init_install %{SOURCE50} gluster-swift-account-replicator
-%_init_install %{SOURCE51} gluster-swift-account-replicator@
-%_init_install %{SOURCE52} gluster-swift-account-auditor
-%_init_install %{SOURCE53} gluster-swift-account-auditor@
-%_init_install %{SOURCE54} gluster-swift-account-reaper
-%_init_install %{SOURCE55} gluster-swift-account-reaper@
-%_init_install %{SOURCE56} gluster-swift-container-replicator
-%_init_install %{SOURCE57} gluster-swift-container-replicator@
-%_init_install %{SOURCE58} gluster-swift-container-auditor
-%_init_install %{SOURCE59} gluster-swift-container-auditor@
-%_init_install %{SOURCE60} gluster-swift-container-updater
-%_init_install %{SOURCE61} gluster-swift-container-updater@
-%_init_install %{SOURCE62} gluster-swift-object-replicator
-%_init_install %{SOURCE63} gluster-swift-object-replicator@
-%_init_install %{SOURCE64} gluster-swift-object-auditor
-%_init_install %{SOURCE65} gluster-swift-object-auditor@
-%_init_install %{SOURCE66} gluster-swift-object-updater
-%_init_install %{SOURCE67} gluster-swift-object-updater@
-%_init_install %{SOURCE68} gluster-swift-object-expirer
-%_init_install %{SOURCE69} gluster-swift-object-expirer@
-%endif
-%else
-# Init helper functions
-%{__install} -p -D -m 644 %{SOURCE44} %{buildroot}%{_datarootdir}/gluster-swift/functions
-# Init scripts
-%_init_install %{glusterswiftaccount_service} gluster-swift-account
-%_init_install %{glusterswiftcontainer_service} gluster-swift-container
-%_init_install %{glusterswiftobject_service} gluster-swift-object
-%_init_install %{glusterswiftproxy_service} gluster-swift-proxy
-%endif
-# Misc other
-%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/swift
-%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/swift/account-server
-%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/swift/container-server
-%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/swift/object-server
-%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/swift/proxy-server
-# Config files
-#%if ( 0%{?fedora} && 0%{?fedora} > 17 )
-# these first appeared in openstack-swift-1.7.4-1.fc18
-#install -p -D -m 660 %{SOURCE70} %{buildroot}%{_sysconfdir}/swift/account-server.conf
-#install -p -D -m 660 %{SOURCE71} %{buildroot}%{_sysconfdir}/swift/container-server.conf
-#install -p -D -m 660 %{SOURCE72} %{buildroot}%{_sysconfdir}/swift/object-server.conf
-#install -p -D -m 660 %{SOURCE73} %{buildroot}%{_sysconfdir}/swift/proxy-server.conf
-#install -p -D -m 660 %{SOURCE74} %{buildroot}%{_sysconfdir}/swift/swift.conf
-#install -p -D -m 660 %{SOURCE75} %{buildroot}%{_sysconfdir}/swift/object-expirer.conf
-#%endif
-# Install pid directory
-%{__install} -d -m 755 %{buildroot}%{_localstatedir}/run/swift
-%{__install} -d -m 755 %{buildroot}%{_localstatedir}/run/swift/account-server
-%{__install} -d -m 755 %{buildroot}%{_localstatedir}/run/swift/container-server
-%{__install} -d -m 755 %{buildroot}%{_localstatedir}/run/swift/object-server
-%{__install} -d -m 755 %{buildroot}%{_localstatedir}/run/swift/proxy-server
-%if 0%{?_with_systemd:1}
-# Swift run directories
-%{__mkdir_p} %{buildroot}%{_sysconfdir}/tmpfiles.d
-install -p -m 0644 %{SOURCE37} %{buildroot}%{_sysconfdir}/tmpfiles.d/gluster-swift.conf
-%endif
-# Install recon directory
-install -d -m 755 %{buildroot}%{_localstatedir}/cache/swift
-# man pages
-install -d -m 755 %{buildroot}%{_mandir}/man5
-for m in doc/manpages/*.5; do
- install -p -m 0644 $m %{buildroot}%{_mandir}/man5
-done
-install -d -m 755 %{buildroot}%{_mandir}/man1
-for m in doc/manpages/*.1; do
- install -p -m 0644 $m %{buildroot}%{_mandir}/man1
-done
-cd ..
-cd ufo
-%{__python} setup.py install -O1 --skip-build --root %{buildroot}
-cd ..
-%{__mkdir_p} %{buildroot}%{_sysconfdir}/swift
-cp -r ufo/etc/* %{buildroot}%{_sysconfdir}/swift/
-%{__mkdir_p} %{buildroot}%{_bindir}
-cp ufo/bin/gluster-swift-gen-builders %{buildroot}%{_bindir}/
-%endif
-# Remove tests
-%{__rm} -rf %{buildroot}/%{python_sitelib}/test
%clean
%{__rm} -rf %{buildroot}
@@ -804,9 +458,10 @@ cp ufo/bin/gluster-swift-gen-builders %{buildroot}%{_bindir}/
%files
%defattr(-,root,root,-)
-%doc ChangeLog COPYING-GPLV2 COPYING-LGPLV3 INSTALL README THANKS
+%doc ChangeLog.bz2 COPYING-GPLV2 COPYING-LGPLV3 INSTALL README THANKS
%config(noreplace) %{_sysconfdir}/logrotate.d/*
%config(noreplace) %{_sysconfdir}/sysconfig/*
+%exclude %{_libdir}/libgfapi.*
%{_libdir}/glusterfs
%{_libdir}/*.so.*
%{_sbindir}/glusterfs*
@@ -815,24 +470,24 @@ cp ufo/bin/gluster-swift-gen-builders %{buildroot}%{_bindir}/
%dir %{_localstatedir}/log/glusterfs
%dir %{_localstatedir}/run/gluster
%dir %{_sharedstatedir}/glusterd
-%if 0%{!?_without_rdma:1}
-%exclude %{_libdir}/glusterfs/%{version}/rpc-transport/rdma*
+%if ( 0%{!?_without_rdma:1} )
+%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/rpc-transport/rdma*
%endif
-%exclude %{_libdir}/glusterfs/%{version}/xlator/mount/fuse*
-%exclude %{_libdir}/glusterfs/%{version}/xlator/storage*
-%exclude %{_libdir}/glusterfs/%{version}/xlator/features/posix*
-%exclude %{_libdir}/glusterfs/%{version}/xlator/protocol/server*
-%exclude %{_libdir}/glusterfs/%{version}/xlator/mgmt*
-%exclude %{_libdir}/glusterfs/%{version}/xlator/nfs*
+%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/mount/fuse*
+%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/storage*
+%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/posix*
+%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/protocol/server*
+%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/mgmt*
+%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/nfs*
-%if 0%{!?_without_rdma:1}
+%if ( 0%{!?_without_rdma:1} )
%files rdma
%defattr(-,root,root,-)
-%{_libdir}/glusterfs/%{version}/rpc-transport/rdma*
+%{_libdir}/glusterfs/%{version}%{?prereltag}/rpc-transport/rdma*
%endif
-%if 0%{!?_without_georeplication:1}
+%if ( 0%{!?_without_georeplication:1} )
%post geo-replication
#restart glusterd.
if [ $1 -ge 1 ]; then
@@ -849,47 +504,49 @@ fi
%files fuse
%defattr(-,root,root,-)
-%if 0%{_for_fedora_koji_builds}
+%if ( 0%{_for_fedora_koji_builds} )
%config(noreplace) %{_sysconfdir}/logrotate.d/glusterfs-fuse
%endif
-%{_libdir}/glusterfs/%{version}/xlator/mount/fuse*
+%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/mount/fuse*
/sbin/mount.glusterfs
-%if 0%{_for_fedora_koji_builds}
+%if ( 0%{_for_fedora_koji_builds} )
/sbin/umount.glusterfs
%endif
-%if 0%{?_with_fusermount:1}
+%if ( 0%{!?_without_fusermount:1} )
%{_bindir}/fusermount-glusterfs
%endif
-%if 0%{?rhel} && 0%{?rhel} <= 5
+%if ( 0%{_for_fedora_koji_builds} )
+%if ( 0%{?rhel} && 0%{?rhel} <= 5 )
%{_sysconfdir}/sysconfig/modules/glusterfs-fuse.modules
%endif
+%endif
%files server
%defattr(-,root,root,-)
%doc extras/clear_xattrs.sh
-%if 0%{_for_fedora_koji_builds}
+%if ( 0%{_for_fedora_koji_builds} )
%config(noreplace) %{_sysconfdir}/logrotate.d/glusterd
%endif
%config(noreplace) %{_sysconfdir}/sysconfig/glusterd
%config(noreplace) %{_sysconfdir}/glusterfs
# Legacy configs
-%if 0%{_for_fedora_koji_builds}
+%if ( 0%{_for_fedora_koji_builds} )
%config(noreplace) %{_sysconfdir}/logrotate.d/glusterfsd
%config(noreplace) %{_sysconfdir}/sysconfig/glusterfsd
%endif
# init files
%_init_glusterd
-%if ( 0%{?_with_systemd:1} ) || ( 0%{_for_fedora_koji_builds} )
+%if ( 0%{_for_fedora_koji_builds} && 0%{?_with_systemd:1} )
%_init_glusterfsd
%endif
# binaries
%{_sbindir}/gluster
%{_sbindir}/glusterd
-%{_libdir}/glusterfs/%{version}/xlator/storage*
-%{_libdir}/glusterfs/%{version}/xlator/features/posix*
-%{_libdir}/glusterfs/%{version}/xlator/protocol/server*
-%{_libdir}/glusterfs/%{version}/xlator/mgmt*
-%{_libdir}/glusterfs/%{version}/xlator/nfs*
+%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/storage*
+%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/posix*
+%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/protocol/server*
+%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/mgmt*
+%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/nfs*
%ghost %attr(0644,-,-) %{_sharedstatedir}/glusterd/glusterd.info
%ghost %attr(0600,-,-) %{_sharedstatedir}/glusterd/options
# This is really ugly, but I have no idea how to mark these directories in an
@@ -927,7 +584,11 @@ fi
%ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/nfs/run
%ghost %attr(0600,-,-) %{_sharedstatedir}/glusterd/nfs/run/nfs.pid
-%if 0%{!?_without_ocf:1}
+%files api
+%exclude %{_libdir}/*.so
+%{_libdir}/libgfapi.*
+
+%if ( 0%{!?_without_ocf:1} )
%files resource-agents
%defattr(-,root,root)
# /usr/lib is the standard for OCF, also on x86_64
@@ -937,161 +598,15 @@ fi
%files devel
%defattr(-,root,root,-)
%{_includedir}/glusterfs
-%{_libdir}/pkgconfig/glusterfs-api.pc
%exclude %{_includedir}/glusterfs/y.tab.h
+%exclude %{_includedir}/glusterfs/api
+%exclude %{_libdir}/libgfapi.so
%{_libdir}/*.so
-%if 0%{?_with_ufo:1}
-%files swift
-%defattr(-,root,root,-)
-%doc swift-%{SWIFTVER}/AUTHORS
-%doc swift-%{SWIFTVER}/LICENSE
-%doc swift-%{SWIFTVER}/README*
-%doc swift-%{SWIFTVER}/etc/dispersion.conf-sample
-%doc swift-%{SWIFTVER}/etc/drive-audit.conf-sample
-%doc swift-%{SWIFTVER}/etc/object-expirer.conf-sample
-%doc swift-%{SWIFTVER}/etc/swift.conf-sample
-%{_mandir}/man5/dispersion.conf.5*
-%{_mandir}/man1/swift*.1*
-%if 0%{?_with_systemd:1}
-%config(noreplace) %{_sysconfdir}/tmpfiles.d/gluster-swift.conf
-%else
-%dir %{_datarootdir}/gluster-swift/functions
-%endif
-%dir %{_sysconfdir}/swift
-#%if ( 0%{?fedora} && 0%{?fedora} > 17 )
-#%config(noreplace) %attr(660, root, swift) %{_sysconfdir}/swift/swift.conf
-#%endif
-%dir %attr(0755, swift, swift) %{_localstatedir}/run/swift
-%dir %{python_sitelib}/swift
-%{_bindir}/swift-account-audit
-%{_bindir}/swift-bench
-%{_bindir}/swift-bench-client
-%{_bindir}/swift-drive-audit
-%{_bindir}/swift-get-nodes
-%{_bindir}/swift-init
-%{_bindir}/swift-ring-builder
-%{_bindir}/swift-dispersion-populate
-%{_bindir}/swift-dispersion-report
-%{_bindir}/swift-recon*
-%{_bindir}/swift-object-expirer
-%{_bindir}/swift-oldies
-%{_bindir}/swift-orphans
-%{_bindir}/swift-form-signature
-%{_bindir}/swift-temp-url
-%{python_sitelib}/swift/*.py*
-%{python_sitelib}/swift/common
-%{python_sitelib}/swift-%{SWIFTVER}-*.egg-info
-
-%files swift-account
-%defattr(-,root,root,-)
-%doc swift-%{SWIFTVER}/etc/account-server.conf-sample
-%{_mandir}/man5/account-server.conf.5*
-%{_mandir}/man1/swift-account-auditor.1*
-%{_mandir}/man1/swift-account-reaper.1*
-%{_mandir}/man1/swift-account-replicator.1*
-%{_mandir}/man1/swift-account-server.1*
-%_init_gluster_swift_account
-%if 0%{?_with_systemd:1}
-%{_unitdir}/gluster-swift-account@.service
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%{_unitdir}/gluster-swift-account-*.service
-%endif
-%endif
-%dir %attr(0755, swift, swift) %{_localstatedir}/run/swift/account-server
-%dir %{_sysconfdir}/swift/account-server
-%{_bindir}/swift-account-auditor
-%{_bindir}/swift-account-reaper
-%{_bindir}/swift-account-replicator
-%{_bindir}/swift-account-server
-%{python_sitelib}/swift/account
-
-%files swift-container
-%defattr(-,root,root,-)
-%doc swift-%{SWIFTVER}/etc/container-server.conf-sample
-%{_mandir}/man5/container-server.conf.5*
-%{_mandir}/man1/swift-container-auditor.1*
-%{_mandir}/man1/swift-container-replicator.1*
-%{_mandir}/man1/swift-container-server.1*
-%{_mandir}/man1/swift-container-sync.1*
-%{_mandir}/man1/swift-container-updater.1*
-%_init_gluster_swift_container
-%if 0%{?_with_systemd:1}
-%{_unitdir}/gluster-swift-container@.service
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%{_unitdir}/gluster-swift-container-*.service
-%endif
-%endif
-%dir %attr(0755, swift, swift) %{_localstatedir}/run/swift/container-server
-%dir %attr(0755, swift, swift) %{_localstatedir}/cache/swift
-%dir %{_sysconfdir}/swift/container-server
-%{_bindir}/swift-container-auditor
-%{_bindir}/swift-container-server
-%{_bindir}/swift-container-replicator
-%{_bindir}/swift-container-updater
-%{_bindir}/swift-container-sync
-%{python_sitelib}/swift/container
-
-%files swift-object
-%defattr(-,root,root,-)
-%doc swift-%{SWIFTVER}/etc/object-server.conf-sample
-%doc swift-%{SWIFTVER}/etc/rsyncd.conf-sample
-%{_mandir}/man5/object-server.conf.5*
-%{_mandir}/man1/swift-object-auditor.1*
-%{_mandir}/man1/swift-object-info.1*
-%{_mandir}/man1/swift-object-replicator.1*
-%{_mandir}/man1/swift-object-server.1*
-%{_mandir}/man1/swift-object-updater.1*
-%_init_gluster_swift_object
-%if 0%{?_with_systemd:1}
-%{_unitdir}/gluster-swift-object@.service
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%{_unitdir}/gluster-swift-object-*.service
-%exclude %{_unitdir}/gluster-swift-object-expirer*.service
-%endif
-%endif
-%dir %attr(0755, swift, swift) %{_localstatedir}/run/swift/object-server
-%dir %attr(0755, swift, swift) %{_localstatedir}/cache/swift
-%dir %{_sysconfdir}/swift/object-server
-%{_bindir}/swift-object-auditor
-%{_bindir}/swift-object-info
-%{_bindir}/swift-object-replicator
-%{_bindir}/swift-object-server
-%{_bindir}/swift-object-updater
-%{python_sitelib}/swift/obj
-
-%files swift-proxy
-%defattr(-,root,root,-)
-%doc swift-%{SWIFTVER}/etc/proxy-server.conf-sample
-%doc swift-%{SWIFTVER}/etc/object-expirer.conf-sample
-%{_mandir}/man5/object-expirer.conf.5*
-%{_mandir}/man5/proxy-server.conf.5*
-%{_mandir}/man1/swift-object-expirer.1*
-%{_mandir}/man1/swift-proxy-server.1*
-%_init_gluster_swift_proxy
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%{_unitdir}/gluster-swift-object-expirer*.service
-%endif
-%dir %attr(0755, swift, swift) %{_localstatedir}/run/swift/proxy-server
-%dir %attr(0755, swift, swift) %{_localstatedir}/cache/swift
-%dir %{_sysconfdir}/swift/proxy-server
-%{_bindir}/swift-object-expirer
-%{_bindir}/swift-proxy-server
-%{python_sitelib}/swift/proxy
-
-%files swift-doc
-%defattr(-,root,root,-)
-%doc swift-%{SWIFTVER}/LICENSE
-
-%files ufo
-%defattr(-,root,root,-)
-%{python_sitelib}/gluster
-%{python_sitelib}/gluster_swift_ufo-*-*.egg-info
-%{_bindir}/gluster-swift-gen-builders
-%{_sysconfdir}/swift/*-gluster
-%{_sysconfdir}/swift/*/1.conf-gluster
-%endif
-
+%files api-devel
+%{_libdir}/pkgconfig/glusterfs-api.pc
+%{_libdir}/libgfapi.so
+%{_includedir}/glusterfs/api/*
%post server
# Legacy server
@@ -1156,186 +671,10 @@ if [ $1 -ge 1 ]; then
%_init_restart glusterd
fi
-
-%if 0%{?_with_ufo:1}
-%pre swift
-getent group swift >/dev/null || groupadd -r swift -g 160
-getent passwd swift >/dev/null || \
-useradd -r -g swift -u 160 -d %{_sharedstatedir}/swift -s /sbin/nologin \
--c "OpenStack Swift Daemons" swift
-exit 0
-
-%pre swift-account
-
-if [ -f /etc/swift/account-server/1.conf ]; then
- echo "warning: /etc/swift/account-server/1.conf saved as /etc/swift/account-server/1.conf.rpmsave"
- cp /etc/swift/account-server/1.conf /etc/swift/account-server/1.conf.rpmsave
-fi
-
-
-%post swift-account
-%_init_enable gluster-swift-account
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%_init_enable gluster-swift-account-replicator
-%_init_enable gluster-swift-account-auditor
-%_init_enable gluster-swift-account-reaper
-%endif
-
-
-%preun swift-account
-if [ $1 = 0 ] ; then
- %_init_stop gluster-swift-account
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_disable gluster-swift-account
- %_init_stop gluster-swift-account-replicator
- %_init_disable gluster-swift-account-replicator
- %_init_stop gluster-swift-account-auditor
- %_init_disable gluster-swift-account-auditor
- %_init_stop gluster-swift-account-reaper
- %_init_disable gluster-swift-account-reaper
-%endif
-fi
-
-
-%postun swift-account
-if [ $1 -ge 1 ] ; then
- %_init_restart gluster-swift-account
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_restart gluster-swift-account-replicator
- %_init_restart gluster-swift-account-auditor
- %_init_restart gluster-swift-account-reaper
-%endif
-fi
-
-
-%pre swift-container
-
-if [ -f /etc/swift/container-server/1.conf ]; then
- echo "warning: /etc/swift/container-server/1.conf saved as /etc/swift/container-server/1.conf.rpmsave"
- cp /etc/swift/container-server/1.conf /etc/swift/container-server/1.conf.rpmsave
-fi
-
-
-%post swift-container
-%_init_enable gluster-swift-container
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%_init_enable gluster-swift-container-replicator
-%_init_enable gluster-swift-container-auditor
-%_init_enable gluster-swift-container-updater
-%endif
-
-
-%preun swift-container
-if [ $1 = 0 ] ; then
- %_init_stop gluster-swift-container
- %_init_disable gluster-swift-container
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_stop gluster-swift-container-replicator
- %_init_disable gluster-swift-container-replicator
- %_init_stop gluster-swift-container-auditor
- %_init_disable gluster-swift-container-auditor
- %_init_stop gluster-swift-container-updater
- %_init_disable gluster-swift-container-updater
-%endif
-fi
-
-
-%postun swift-container
-if [ $1 -ge 1 ] ; then
- %_init_restart gluster-swift-container
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_restart gluster-swift-container-replicator
- %_init_restart gluster-swift-container-auditor
- %_init_restart gluster-swift-container-updator
-%endif
-fi
-
-
-%pre swift-object
-
-if [ -f /etc/swift/object-server/1.conf ]; then
- echo "warning: /etc/swift/object-server/1.conf saved as /etc/swift/object-server/1.conf.rpmsave"
- cp /etc/swift/object-server/1.conf /etc/swift/object-server/1.conf.rpmsave
-fi
-
-
-%post swift-object
-%_init_enable gluster-swift-object
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%_init_enable gluster-swift-object-replicator
-%_init_enable gluster-swift-object-auditor
-%_init_enable gluster-swift-object-updater
-%endif
-
-
-%preun swift-object
-if [ $1 = 0 ] ; then
- %_init_stop gluster-swift-object
- %_init_disable gluster-swift-object
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_stop gluster-swift-object-replicator
- %_init_disable gluster-swift-object-replicator
- %_init_stop gluster-swift-object-auditor
- %_init_disable gluster-swift-object-auditor
- %_init_stop gluster-swift-object-updater
- %_init_disable gluster-swift-object-updater
-%endif
-fi
-
-
-%postun swift-object
-if [ $1 -ge 1 ] ; then
- %_init_restart gluster-swift-object
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_restart gluster-swift-object-replicator
- %_init_restart gluster-swift-object-auditor
- %_init_restart gluster-swift-object-updater
-%endif
-fi
-
-
-%pre swift-proxy
-
-if [ -f /etc/swift/proxy-server.conf ]; then
- echo "warning: /etc/swift/proxy-server.conf saved as /etc/swift/proxy-server.conf.rpmsave"
- cp /etc/swift/proxy-server.conf /etc/swift/proxy-server.conf.rpmsave
-fi
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-if [ -f /etc/swift/object-expirer.conf ]; then
- echo "warning: /etc/swift/object-expirer.conf saved as /etc/swift/object-expirer.conf.rpmsave"
- cp /etc/swift/object-expirer.conf /etc/swift/object-expirer.conf.rpmsave
-fi
-%endif
-
-
-%post swift-proxy
-%_init_enable gluster-swift-proxy
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
-%_init_enable gluster-swift-object-expirer
-%endif
-
-
-%preun swift-proxy
-if [ $1 = 0 ] ; then
- %_init_stop gluster-swift-proxy
- %_init_disable gluster-swift-proxy
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_stop gluster-swift-object-expirer
- %_init_disable gluster-swift-object-expirer
-%endif
-fi
-
-
-%postun swift-proxy
-if [ $1 -ge 1 ] ; then
- %_init_restart gluster-swift-proxy
-%if ( 0%{?fedora} && 0%{?fedora} > 18 )
- %_init_restart gluster-swift-object-expirer
-%endif
-fi
-%endif
-
%changelog
+* Fri Jun 7 2013 Kaleb S. KEITHLEY <kkeithle@redhat.com>
+- Sync with Fedora glusterfs.spec, remove G4S/UFO and Swift
+
* Mon Mar 4 2013 Niels de Vos <ndevos@redhat.com>
- Package /var/run/gluster so that statedumps can be created
66' href='#n2166'>2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478

/*
  Copyright (c) 2012-2018 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

/* for SEEK_HOLE and SEEK_DATA */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <unistd.h>

#include "glfs-internal.h"
#include "glfs-mem-types.h"
#include <glusterfs/syncop.h>
#include "glfs.h"
#include "gfapi-messages.h"
#include <glusterfs/compat-errno.h>
#include <limits.h>
#include "glusterfs3.h"
#include <glusterfs/iatt.h>

#ifdef NAME_MAX
#define GF_NAME_MAX NAME_MAX
#else
#define GF_NAME_MAX 255
#endif

struct upcall_syncop_args {
    struct glfs *fs;
    struct gf_upcall upcall_data;
};

#define READDIRBUF_SIZE (sizeof(struct dirent) + GF_NAME_MAX + 1)

typedef void (*glfs_io_cbk34)(glfs_fd_t *fd, ssize_t ret, void *data);

/*
 * This function will mark glfd for deletion and decrement its refcount.
 */
int
glfs_mark_glfd_for_deletion(struct glfs_fd *glfd)
{
    LOCK(&glfd->lock);
    {
        glfd->state = GLFD_CLOSE;
    }
    UNLOCK(&glfd->lock);

    GF_REF_PUT(glfd);

    return 0;
}

/* This function is useful for all async fops. There is chance that glfd is
 * closed before async fop is completed. When glfd is closed we change the
 * state to GLFD_CLOSE.
 *
 * This function will return _gf_true if the glfd is still valid else return
 * _gf_false.
 */
gf_boolean_t
glfs_is_glfd_still_valid(struct glfs_fd *glfd)
{
    gf_boolean_t ret = _gf_false;

    LOCK(&glfd->lock);
    {
        if (glfd->state != GLFD_CLOSE)
            ret = _gf_true;
    }
    UNLOCK(&glfd->lock);

    return ret;
}

void
glfd_set_state_bind(struct glfs_fd *glfd)
{
    LOCK(&glfd->lock);
    {
        glfd->state = GLFD_OPEN;
    }
    UNLOCK(&glfd->lock);

    fd_bind(glfd->fd);
    glfs_fd_bind(glfd);

    return;
}

/*
 * This routine is called when an upcall event of type
 * 'GF_UPCALL_CACHE_INVALIDATION' is received.
 * It makes a copy of the contents of the upcall cache-invalidation
 * data received into an entry which is stored in the upcall list
 * maintained by gfapi.
 */
int
glfs_get_upcall_cache_invalidation(struct gf_upcall *to_up_data,
                                   struct gf_upcall *from_up_data)
{
    struct gf_upcall_cache_invalidation *ca_data = NULL;
    struct gf_upcall_cache_invalidation *f_ca_data = NULL;
    int ret = -1;

    GF_VALIDATE_OR_GOTO(THIS->name, to_up_data, out);
    GF_VALIDATE_OR_GOTO(THIS->name, from_up_data, out);

    f_ca_data = from_up_data->data;
    GF_VALIDATE_OR_GOTO(THIS->name, f_ca_data, out);

    ca_data = GF_CALLOC(1, sizeof(*ca_data), glfs_mt_upcall_entry_t);

    if (!ca_data) {
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_ALLOC_FAILED, "entry",
                NULL);
        goto out;
    }

    to_up_data->data = ca_data;

    ca_data->flags = f_ca_data->flags;
    ca_data->expire_time_attr = f_ca_data->expire_time_attr;
    ca_data->stat = f_ca_data->stat;
    ca_data->p_stat = f_ca_data->p_stat;
    ca_data->oldp_stat = f_ca_data->oldp_stat;

    ret = 0;
out:
    return ret;
}

int
glfs_get_upcall_lease(struct gf_upcall *to_up_data,
                      struct gf_upcall *from_up_data)
{
    struct gf_upcall_recall_lease *ca_data = NULL;
    struct gf_upcall_recall_lease *f_ca_data = NULL;
    int ret = -1;

    GF_VALIDATE_OR_GOTO(THIS->name, to_up_data, out);
    GF_VALIDATE_OR_GOTO(THIS->name, from_up_data, out);

    f_ca_data = from_up_data->data;
    GF_VALIDATE_OR_GOTO(THIS->name, f_ca_data, out);

    ca_data = GF_CALLOC(1, sizeof(*ca_data), glfs_mt_upcall_entry_t);

    if (!ca_data) {
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_ALLOC_FAILED, "entry",
                NULL);
        goto out;
    }

    to_up_data->data = ca_data;

    ca_data->lease_type = f_ca_data->lease_type;
    gf_uuid_copy(ca_data->tid, f_ca_data->tid);
    ca_data->dict = f_ca_data->dict;

    ret = 0;
out:
    return ret;
}
int
glfs_loc_link(loc_t *loc, struct iatt *iatt)
{
    int ret = -1;
    inode_t *old_inode = NULL;
    uint64_t ctx_value = LOOKUP_NOT_NEEDED;

    if (!loc->inode) {
        errno = EINVAL;
        return -1;
    }

    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_ctx_set(loc->inode, THIS, &ctx_value);
        inode_lookup(loc->inode);
        inode_unref(old_inode);
        ret = 0;
    } else {
        ret = -1;
    }

    return ret;
}

void
glfs_iatt_to_stat(struct glfs *fs, struct iatt *iatt, struct stat *stat)
{
    iatt_to_stat(iatt, stat);
    stat->st_dev = fs->dev_id;
}

void
glfs_iatt_to_statx(struct glfs *fs, const struct iatt *iatt,
                   struct glfs_stat *statx)
{
    statx->glfs_st_mask = 0;

    statx->glfs_st_mode = 0;
    if (IATT_TYPE_VALID(iatt->ia_flags)) {
        statx->glfs_st_mode |= st_mode_type_from_ia(iatt->ia_type);
        statx->glfs_st_mask |= GLFS_STAT_TYPE;
    }

    if (IATT_MODE_VALID(iatt->ia_flags)) {
        statx->glfs_st_mode |= st_mode_prot_from_ia(iatt->ia_prot);
        statx->glfs_st_mask |= GLFS_STAT_MODE;
    }

    if (IATT_NLINK_VALID(iatt->ia_flags)) {
        statx->glfs_st_nlink = iatt->ia_nlink;
        statx->glfs_st_mask |= GLFS_STAT_NLINK;
    }

    if (IATT_UID_VALID(iatt->ia_flags)) {
        statx->glfs_st_uid = iatt->ia_uid;
        statx->glfs_st_mask |= GLFS_STAT_UID;
    }

    if (IATT_GID_VALID(iatt->ia_flags)) {
        statx->glfs_st_gid = iatt->ia_gid;
        statx->glfs_st_mask |= GLFS_STAT_GID;
    }

    if (IATT_ATIME_VALID(iatt->ia_flags)) {
        statx->glfs_st_atime.tv_sec = iatt->ia_atime;
        statx->glfs_st_atime.tv_nsec = iatt->ia_atime_nsec;
        statx->glfs_st_mask |= GLFS_STAT_ATIME;
    }

    if (IATT_MTIME_VALID(iatt->ia_flags)) {
        statx->glfs_st_mtime.tv_sec = iatt->ia_mtime;
        statx->glfs_st_mtime.tv_nsec = iatt->ia_mtime_nsec;
        statx->glfs_st_mask |= GLFS_STAT_MTIME;
    }

    if (IATT_CTIME_VALID(iatt->ia_flags)) {
        statx->glfs_st_ctime.tv_sec = iatt->ia_ctime;
        statx->glfs_st_ctime.tv_nsec = iatt->ia_ctime_nsec;
        statx->glfs_st_mask |= GLFS_STAT_CTIME;
    }

    if (IATT_BTIME_VALID(iatt->ia_flags)) {
        statx->glfs_st_btime.tv_sec = iatt->ia_btime;
        statx->glfs_st_btime.tv_nsec = iatt->ia_btime_nsec;
        statx->glfs_st_mask |= GLFS_STAT_BTIME;
    }

    if (IATT_INO_VALID(iatt->ia_flags)) {
        statx->glfs_st_ino = iatt->ia_ino;
        statx->glfs_st_mask |= GLFS_STAT_INO;
    }

    if (IATT_SIZE_VALID(iatt->ia_flags)) {
        statx->glfs_st_size = iatt->ia_size;
        statx->glfs_st_mask |= GLFS_STAT_SIZE;
    }

    if (IATT_BLOCKS_VALID(iatt->ia_flags)) {
        statx->glfs_st_blocks = iatt->ia_blocks;
        statx->glfs_st_mask |= GLFS_STAT_BLOCKS;
    }

    /* unconditionally present, encode as is */
    statx->glfs_st_blksize = iatt->ia_blksize;
    statx->glfs_st_rdev_major = ia_major(iatt->ia_rdev);
    statx->glfs_st_rdev_minor = ia_minor(iatt->ia_rdev);
    statx->glfs_st_dev_major = ia_major(fs->dev_id);
    statx->glfs_st_dev_minor = ia_minor(fs->dev_id);

    /* At present we do not read any localFS attributes and pass them along,
     * so setting this to 0. As we start supporting file attributes we can
     * populate the same here as well */
    statx->glfs_st_attributes = 0;
    statx->glfs_st_attributes_mask = 0;
}

void
priv_glfs_iatt_from_statx(struct iatt *iatt, const struct glfs_stat *statx)
{
    /* Most code in xlators are not checking validity flags before accessing
    the items. Hence zero everything before setting valid items */
    memset(iatt, 0, sizeof(struct iatt));

    if (GLFS_STAT_TYPE_VALID(statx->glfs_st_mask)) {
        iatt->ia_type = ia_type_from_st_mode(statx->glfs_st_mode);
        iatt->ia_flags |= IATT_TYPE;
    }

    if (GLFS_STAT_MODE_VALID(statx->glfs_st_mask)) {
        iatt->ia_prot = ia_prot_from_st_mode(statx->glfs_st_mode);
        iatt->ia_flags |= IATT_MODE;
    }

    if (GLFS_STAT_NLINK_VALID(statx->glfs_st_mask)) {
        iatt->ia_nlink = statx->glfs_st_nlink;
        iatt->ia_flags |= IATT_NLINK;
    }

    if (GLFS_STAT_UID_VALID(statx->glfs_st_mask)) {
        iatt->ia_uid = statx->glfs_st_uid;
        iatt->ia_flags |= IATT_UID;
    }

    if (GLFS_STAT_GID_VALID(statx->glfs_st_mask)) {
        iatt->ia_gid = statx->glfs_st_gid;
        iatt->ia_flags |= IATT_GID;
    }

    if (GLFS_STAT_ATIME_VALID(statx->glfs_st_mask)) {
        iatt->ia_atime = statx->glfs_st_atime.tv_sec;
        iatt->ia_atime_nsec = statx->glfs_st_atime.tv_nsec;
        iatt->ia_flags |= IATT_ATIME;
    }

    if (GLFS_STAT_MTIME_VALID(statx->glfs_st_mask)) {
        iatt->ia_mtime = statx->glfs_st_mtime.tv_sec;
        iatt->ia_mtime_nsec = statx->glfs_st_mtime.tv_nsec;
        iatt->ia_flags |= IATT_MTIME;
    }

    if (GLFS_STAT_CTIME_VALID(statx->glfs_st_mask)) {
        iatt->ia_ctime = statx->glfs_st_ctime.tv_sec;
        iatt->ia_ctime_nsec = statx->glfs_st_ctime.tv_nsec;
        iatt->ia_flags |= IATT_CTIME;
    }

    if (GLFS_STAT_BTIME_VALID(statx->glfs_st_mask)) {
        iatt->ia_btime = statx->glfs_st_btime.tv_sec;
        iatt->ia_btime_nsec = statx->glfs_st_btime.tv_nsec;
        iatt->ia_flags |= IATT_BTIME;
    }

    if (GLFS_STAT_INO_VALID(statx->glfs_st_mask)) {
        iatt->ia_ino = statx->glfs_st_ino;
        iatt->ia_flags |= IATT_INO;
    }

    if (GLFS_STAT_SIZE_VALID(statx->glfs_st_mask)) {
        iatt->ia_size = statx->glfs_st_size;
        iatt->ia_flags |= IATT_SIZE;
    }

    if (GLFS_STAT_BLOCKS_VALID(statx->glfs_st_mask)) {
        iatt->ia_blocks = statx->glfs_st_blocks;
        iatt->ia_flags |= IATT_BLOCKS;
    }

    /* unconditionally present, encode as is */
    iatt->ia_blksize = statx->glfs_st_blksize;
    iatt->ia_rdev = makedev(statx->glfs_st_rdev_major,
                            statx->glfs_st_rdev_minor);
    iatt->ia_dev = makedev(statx->glfs_st_dev_major, statx->glfs_st_dev_minor);
    iatt->ia_attributes = statx->glfs_st_attributes;
    iatt->ia_attributes_mask = statx->glfs_st_attributes_mask;
}
GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_iatt_from_statx, 6.0);

void
glfsflags_from_gfapiflags(struct glfs_stat *stat, int *glvalid)
{
    *glvalid = 0;
    if (stat->glfs_st_mask & GLFS_STAT_MODE) {
        *glvalid |= GF_SET_ATTR_MODE;
    }

    if (stat->glfs_st_mask & GLFS_STAT_SIZE) {
        *glvalid |= GF_SET_ATTR_SIZE;
    }

    if (stat->glfs_st_mask & GLFS_STAT_UID) {
        *glvalid |= GF_SET_ATTR_UID;
    }

    if (stat->glfs_st_mask & GLFS_STAT_GID) {
        *glvalid |= GF_SET_ATTR_GID;
    }

    if (stat->glfs_st_mask & GLFS_STAT_ATIME) {
        *glvalid |= GF_SET_ATTR_ATIME;
    }

    if (stat->glfs_st_mask & GLFS_STAT_MTIME) {
        *glvalid |= GF_SET_ATTR_MTIME;
    }
}

int
glfs_loc_unlink(loc_t *loc)
{
    inode_unlink(loc->inode, loc->parent, loc->name);

    /* since glfs_h_* objects hold a reference to inode
     * it is safe to keep lookup count to '0' */
    if (!inode_has_dentry(loc->inode))
        inode_forget(loc->inode, 0);

    return 0;
}

struct glfs_fd *
pub_glfs_open(struct glfs *fs, const char *path, int flags)
{
    int ret = -1;
    struct glfs_fd *glfd = NULL;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    glfd = glfs_fd_new(fs);
    if (!glfd)
        goto out;

retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    if (IA_ISDIR(iatt.ia_type)) {
        ret = -1;
        errno = EISDIR;
        goto out;
    }

    if (!IA_ISREG(iatt.ia_type)) {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    if (glfd->fd) {
        /* Retry. Safe to touch glfd->fd as we
           still have not glfs_fd_bind() yet.
        */
        fd_unref(glfd->fd);
        glfd->fd = NULL;
    }

    glfd->fd = fd_create(loc.inode, getpid());
    if (!glfd->fd) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }
    glfd->fd->flags = flags;

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_open(subvol, &loc, flags, glfd->fd, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);
out:
    loc_wipe(&loc);

    if (fop_attr)
        dict_unref(fop_attr);

    if (ret && glfd) {
        GF_REF_PUT(glfd);
        glfd = NULL;
    } else if (glfd) {
        glfd_set_state_bind(glfd);
    }

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return glfd;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_open, 3.4.0);

int
pub_glfs_close(struct glfs_fd *glfd)
{
    xlator_t *subvol = NULL;
    int ret = -1;
    fd_t *fd = NULL;
    struct glfs *fs = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    if (glfd->lk_owner.len != 0) {
        ret = syncopctx_setfslkowner(&glfd->lk_owner);
        if (ret)
            goto out;
    }
    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_flush(subvol, fd, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);
out:
    fs = glfd->fs;

    if (fd)
        fd_unref(fd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_mark_glfd_for_deletion(glfd);
    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_close, 3.4.0);

int
pub_glfs_lstat(struct glfs *fs, const char *path, struct stat *stat)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0 && stat)
        glfs_iatt_to_stat(fs, &iatt, stat);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lstat, 3.4.0);

int
pub_glfs_stat(struct glfs *fs, const char *path, struct stat *stat)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0 && stat)
        glfs_iatt_to_stat(fs, &iatt, stat);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_stat, 3.4.0);

int
priv_glfs_statx(struct glfs *fs, const char *path, const unsigned int mask,
                struct glfs_stat *statxbuf)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    if (path == NULL) {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    if (mask & ~GLFS_STAT_ALL) {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);
    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0 && statxbuf)
        glfs_iatt_to_statx(fs, &iatt, statxbuf);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_statx, 6.0);

int
pub_glfs_fstat(struct glfs_fd *glfd, struct stat *stat)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    struct iatt iatt = {
        0,
    };
    fd_t *fd = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = syncop_fstat(subvol, fd, &iatt, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret == 0 && stat)
        glfs_iatt_to_stat(glfd->fs, &iatt, stat);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fstat, 3.4.0);

struct glfs_fd *
pub_glfs_creat(struct glfs *fs, const char *path, int flags, mode_t mode)
{
    int ret = -1;
    struct glfs_fd *glfd = NULL;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    uuid_t gfid;
    dict_t *xattr_req = NULL;
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    xattr_req = dict_new();
    if (!xattr_req) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gf_uuid_generate(gfid);
    ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true);
    if (ret) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    glfd = glfs_fd_new(fs);
    if (!glfd)
        goto out;

    /* This must be glfs_resolve() and NOT glfs_lresolve().
       That is because open("name", O_CREAT) where "name"
       is a danging symlink must create the dangling
       destination.
    */
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == -1 && errno != ENOENT)
        /* Any other type of error is fatal */
        goto out;

    if (ret == -1 && errno == ENOENT && !loc.parent)
        /* The parent directory or an ancestor even
           higher does not exist
        */
        goto out;

    if (loc.inode) {
        if (flags & O_EXCL) {
            ret = -1;
            errno = EEXIST;
            goto out;
        }

        if (IA_ISDIR(iatt.ia_type)) {
            ret = -1;
            errno = EISDIR;
            goto out;
        }

        if (!IA_ISREG(iatt.ia_type)) {
            ret = -1;
            errno = EINVAL;
            goto out;
        }
    }

    if (ret == -1 && errno == ENOENT) {
        loc.inode = inode_new(loc.parent->table);
        if (!loc.inode) {
            ret = -1;
            errno = ENOMEM;
            goto out;
        }
    }

    if (glfd->fd) {
        /* Retry. Safe to touch glfd->fd as we
           still have not glfs_fd_bind() yet.
        */
        fd_unref(glfd->fd);
        glfd->fd = NULL;
    }

    glfd->fd = fd_create(loc.inode, getpid());
    if (!glfd->fd) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }
    glfd->fd->flags = flags;

    if (get_fop_attr_thrd_key(&xattr_req))
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");
    if (ret == 0) {
        ret = syncop_open(subvol, &loc, flags, glfd->fd, xattr_req, NULL);
        DECODE_SYNCOP_ERR(ret);
    } else {
        ret = syncop_create(subvol, &loc, flags, mode, glfd->fd, &iatt,
                            xattr_req, NULL);
        DECODE_SYNCOP_ERR(ret);
    }

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0)
        ret = glfs_loc_link(&loc, &iatt);
out:
    loc_wipe(&loc);

    if (xattr_req)
        dict_unref(xattr_req);

    if (ret && glfd) {
        GF_REF_PUT(glfd);
        glfd = NULL;
    } else if (glfd) {
        glfd_set_state_bind(glfd);
    }

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return glfd;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_creat, 3.4.0);

#ifdef HAVE_SEEK_HOLE
static int
glfs_seek(struct glfs_fd *glfd, off_t offset, int whence)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    gf_seek_what_t what = 0;
    off_t off = -1;

    switch (whence) {
        case SEEK_DATA:
            what = GF_SEEK_DATA;
            break;
        case SEEK_HOLE:
            what = GF_SEEK_HOLE;
            break;
        default:
            /* other SEEK_* do not make sense, all operations get an offset
             * and the position in the fd is not tracked */
            errno = EINVAL;
            goto out;
    }

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        errno = EBADFD;
        goto done;
    }

    ret = syncop_seek(subvol, fd, offset, what, NULL, &off);
    DECODE_SYNCOP_ERR(ret);

    if (ret != -1)
        glfd->offset = off;

done:
    if (fd)
        fd_unref(fd);

    glfs_subvol_done(glfd->fs, subvol);

out:
    return ret;
}
#endif

off_t
pub_glfs_lseek(struct glfs_fd *glfd, off_t offset, int whence)
{
    struct stat sb = {
        0,
    };
    int ret = -1;
    off_t off = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    switch (whence) {
        case SEEK_SET:
            glfd->offset = offset;
            ret = 0;
            break;
        case SEEK_CUR:
            glfd->offset += offset;
            ret = 0;
            break;
        case SEEK_END:
            ret = pub_glfs_fstat(glfd, &sb);
            if (ret) {
                /* seek cannot fail :O */
                break;
            }
            glfd->offset = sb.st_size + offset;
            break;
#ifdef HAVE_SEEK_HOLE
        case SEEK_DATA:
        case SEEK_HOLE:
            ret = glfs_seek(glfd, offset, whence);
            break;
#endif
        default:
            errno = EINVAL;
    }

    if (glfd)
        GF_REF_PUT(glfd);

    __GLFS_EXIT_FS;

    if (ret != -1)
        off = glfd->offset;

    return off;

invalid_fs:
    return -1;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lseek, 3.4.0);

static ssize_t
glfs_preadv_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt,
                   off_t offset, int flags, struct glfs_stat *poststat)
{
    xlator_t *subvol = NULL;
    ssize_t ret = -1;
    ssize_t size = -1;
    struct iovec *iov = NULL;
    int cnt = 0;
    struct iobref *iobref = NULL;
    fd_t *fd = NULL;
    struct iatt iatt = {
        0,
    };
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    size = iov_length(iovec, iovcnt);

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_readv(subvol, fd, size, offset, 0, &iov, &cnt, &iobref, &iatt,
                       fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret >= 0 && poststat)
        glfs_iatt_to_statx(glfd->fs, &iatt, poststat);

    if (ret <= 0)
        goto out;

    size = iov_copy(iovec, iovcnt, iov, cnt); /* FIXME!!! */

    glfd->offset = (offset + size);

    ret = size;
out:
    if (iov)
        GF_FREE(iov);
    if (iobref)
        iobref_unref(iobref);

    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

ssize_t
pub_glfs_preadv(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt,
                off_t offset, int flags)
{
    return glfs_preadv_common(glfd, iovec, iovcnt, offset, flags, NULL);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv, 3.4.0);

ssize_t
pub_glfs_read(struct glfs_fd *glfd, void *buf, size_t count, int flags)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = buf;
    iov.iov_len = count;

    ret = pub_glfs_preadv(glfd, &iov, 1, glfd->offset, flags);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_read, 3.4.0);

ssize_t
pub_glfs_pread34(struct glfs_fd *glfd, void *buf, size_t count, off_t offset,
                 int flags)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = buf;
    iov.iov_len = count;

    ret = pub_glfs_preadv(glfd, &iov, 1, offset, flags);

    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_pread34, glfs_pread, 3.4.0);

ssize_t
pub_glfs_pread(struct glfs_fd *glfd, void *buf, size_t count, off_t offset,
               int flags, struct glfs_stat *poststat)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = buf;
    iov.iov_len = count;

    ret = glfs_preadv_common(glfd, &iov, 1, offset, flags, poststat);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread, 6.0);

ssize_t
pub_glfs_readv(struct glfs_fd *glfd, const struct iovec *iov, int count,
               int flags)
{
    ssize_t ret = 0;

    ret = pub_glfs_preadv(glfd, iov, count, glfd->offset, flags);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readv, 3.4.0);

struct glfs_io {
    struct glfs_fd *glfd;
    int op;
    off_t offset;
    struct iovec *iov;
    int count;
    int flags;
    gf_boolean_t oldcb;
    union {
        glfs_io_cbk34 fn34;
        glfs_io_cbk fn;
    };
    void *data;
};

static int
glfs_io_async_cbk(int op_ret, int op_errno, call_frame_t *frame, void *cookie,
                  struct iovec *iovec, int count, struct iatt *prebuf,
                  struct iatt *postbuf)
{
    struct glfs_io *gio = NULL;
    xlator_t *subvol = NULL;
    struct glfs *fs = NULL;
    struct glfs_fd *glfd = NULL;
    int ret = -1;
    struct glfs_stat prestat = {}, *prestatp = NULL;
    struct glfs_stat poststat = {}, *poststatp = NULL;

    GF_VALIDATE_OR_GOTO("gfapi", frame, inval);
    GF_VALIDATE_OR_GOTO("gfapi", cookie, inval);

    gio = frame->local;
    frame->local = NULL;
    subvol = cookie;
    glfd = gio->glfd;
    fs = glfd->fs;

    if (!glfs_is_glfd_still_valid(glfd))
        goto err;

    if (op_ret <= 0) {
        goto out;
    } else if (gio->op == GF_FOP_READ) {
        if (!iovec) {
            op_ret = -1;
            op_errno = EINVAL;
            goto out;
        }

        op_ret = iov_copy(gio->iov, gio->count, iovec, count);
        glfd->offset = gio->offset + op_ret;
    } else if (gio->op == GF_FOP_WRITE) {
        glfd->offset = gio->offset + gio->iov->iov_len;
    }

out:
    errno = op_errno;
    if (gio->oldcb) {
        gio->fn34(gio->glfd, op_ret, gio->data);
    } else {
        if (prebuf) {
            prestatp = &prestat;
            glfs_iatt_to_statx(fs, prebuf, prestatp);
        }

        if (postbuf) {
            poststatp = &poststat;
            glfs_iatt_to_statx(fs, postbuf, poststatp);
        }

        gio->fn(gio->glfd, op_ret, prestatp, poststatp, gio->data);
    }
err:
    fd_unref(glfd->fd);
    /* Since the async operation is complete
     * release the ref taken during the start
     * of async operation
     */
    GF_REF_PUT(glfd);

    GF_FREE(gio->iov);
    GF_FREE(gio);
    STACK_DESTROY(frame->root);
    glfs_subvol_done(fs, subvol);

    ret = 0;
inval:
    return ret;
}

static int
glfs_preadv_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
                      int op_ret, int op_errno, struct iovec *iovec, int count,
                      struct iatt *stbuf, struct iobref *iobref, dict_t *xdata)
{
    glfs_io_async_cbk(op_ret, op_errno, frame, cookie, iovec, count, NULL,
                      stbuf);

    return 0;
}

static int
glfs_preadv_async_common(struct glfs_fd *glfd, const struct iovec *iovec,
                         int count, off_t offset, int flags, gf_boolean_t oldcb,
                         glfs_io_cbk fn, void *data)
{
    struct glfs_io *gio = NULL;
    int ret = 0;
    call_frame_t *frame = NULL;
    xlator_t *subvol = NULL;
    struct glfs *fs = NULL;
    fd_t *fd = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    fs = glfd->fs;

    frame = syncop_create_frame(THIS);
    if (!frame) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t);
    if (!gio) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gio->iov = iov_dup(iovec, count);
    if (!gio->iov) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gio->op = GF_FOP_READ;
    gio->glfd = glfd;
    gio->count = count;
    gio->offset = offset;
    gio->flags = flags;
    gio->oldcb = oldcb;
    gio->fn = fn;
    gio->data = data;

    frame->local = gio;

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    STACK_WIND_COOKIE(frame, glfs_preadv_async_cbk, subvol, subvol,
                      subvol->fops->readv, fd, iov_length(iovec, count), offset,
                      flags, fop_attr);

out:
    if (ret) {
        if (fd)
            fd_unref(fd);
        if (glfd)
            GF_REF_PUT(glfd);
        if (gio) {
            GF_FREE(gio->iov);
            GF_FREE(gio);
        }
        if (frame) {
            STACK_DESTROY(frame->root);
        }
        glfs_subvol_done(fs, subvol);
    }
    if (fop_attr)
        dict_unref(fop_attr);

    __GLFS_EXIT_FS;

    return ret;

invalid_fs:
    return -1;
}

int
pub_glfs_preadv_async34(struct glfs_fd *glfd, const struct iovec *iovec,
                        int count, off_t offset, int flags, glfs_io_cbk34 fn,
                        void *data)
{
    return glfs_preadv_async_common(glfd, iovec, count, offset, flags, _gf_true,
                                    (void *)fn, data);
}

GFAPI_SYMVER_PUBLIC(glfs_preadv_async34, glfs_preadv_async, 3.4.0);

int
pub_glfs_preadv_async(struct glfs_fd *glfd, const struct iovec *iovec,
                      int count, off_t offset, int flags, glfs_io_cbk fn,
                      void *data)
{
    return glfs_preadv_async_common(glfd, iovec, count, offset, flags,
                                    _gf_false, fn, data);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv_async, 6.0);

int
pub_glfs_read_async34(struct glfs_fd *glfd, void *buf, size_t count, int flags,
                      glfs_io_cbk34 fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = buf;
    iov.iov_len = count;

    ret = glfs_preadv_async_common(glfd, &iov, 1, glfd->offset, flags, _gf_true,
                                   (void *)fn, data);

    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_read_async34, glfs_read_async, 3.4.0);

int
pub_glfs_read_async(struct glfs_fd *glfd, void *buf, size_t count, int flags,
                    glfs_io_cbk fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = buf;
    iov.iov_len = count;

    ret = glfs_preadv_async_common(glfd, &iov, 1, glfd->offset, flags,
                                   _gf_false, fn, data);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_read_async, 6.0);

int
pub_glfs_pread_async34(struct glfs_fd *glfd, void *buf, size_t count,
                       off_t offset, int flags, glfs_io_cbk34 fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = buf;
    iov.iov_len = count;

    ret = glfs_preadv_async_common(glfd, &iov, 1, offset, flags, _gf_true,
                                   (void *)fn, data);

    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_pread_async34, glfs_pread_async, 3.4.0);

int
pub_glfs_pread_async(struct glfs_fd *glfd, void *buf, size_t count,
                     off_t offset, int flags, glfs_io_cbk fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = buf;
    iov.iov_len = count;

    ret = glfs_preadv_async_common(glfd, &iov, 1, offset, flags, _gf_false, fn,
                                   data);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread_async, 6.0);

int
pub_glfs_readv_async34(struct glfs_fd *glfd, const struct iovec *iov, int count,
                       int flags, glfs_io_cbk34 fn, void *data)
{
    ssize_t ret = 0;

    ret = glfs_preadv_async_common(glfd, iov, count, glfd->offset, flags,
                                   _gf_true, (void *)fn, data);
    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_readv_async34, glfs_readv_async, 3.4.0);

int
pub_glfs_readv_async(struct glfs_fd *glfd, const struct iovec *iov, int count,
                     int flags, glfs_io_cbk fn, void *data)
{
    ssize_t ret = 0;

    ret = glfs_preadv_async_common(glfd, iov, count, glfd->offset, flags,
                                   _gf_false, fn, data);
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readv_async, 6.0);

static ssize_t
glfs_pwritev_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt,
                    off_t offset, int flags, struct glfs_stat *prestat,
                    struct glfs_stat *poststat)
{
    xlator_t *subvol = NULL;
    int ret = -1;
    struct iobref *iobref = NULL;
    struct iobuf *iobuf = NULL;
    struct iovec iov = {
        0,
    };
    fd_t *fd = NULL;
    struct iatt preiatt =
                    {
                        0,
                    },
                postiatt = {
                    0,
                };
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = iobuf_copy(subvol->ctx->iobuf_pool, iovec, iovcnt, &iobref, &iobuf,
                     &iov);
    if (ret)
        goto out;

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_writev(subvol, fd, &iov, 1, offset, iobref, flags, &preiatt,
                        &postiatt, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret >= 0) {
        if (prestat)
            glfs_iatt_to_statx(glfd->fs, &preiatt, prestat);
        if (poststat)
            glfs_iatt_to_statx(glfd->fs, &postiatt, poststat);
    }

    if (ret <= 0)
        goto out;

    glfd->offset = (offset + iov.iov_len);
out:
    if (iobuf)
        iobuf_unref(iobuf);
    if (iobref)
        iobref_unref(iobref);
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

ssize_t
pub_glfs_copy_file_range(struct glfs_fd *glfd_in, off64_t *off_in,
                         struct glfs_fd *glfd_out, off64_t *off_out, size_t len,
                         unsigned int flags, struct glfs_stat *statbuf,
                         struct glfs_stat *prestat, struct glfs_stat *poststat)
{
    xlator_t *subvol = NULL;
    int ret = -1;
    fd_t *fd_in = NULL;
    fd_t *fd_out = NULL;
    struct iatt preiatt =
                    {
                        0,
                    },
                iattbuf =
                    {
                        0,
                    },
                postiatt = {
                    0,
                };
    dict_t *fop_attr = NULL;
    off64_t pos_in;
    off64_t pos_out;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd_in, invalid_fs);
    __GLFS_ENTRY_VALIDATE_FD(glfd_out, invalid_fs);

    GF_REF_GET(glfd_in);
    GF_REF_GET(glfd_out);

    if (glfd_in->fs != glfd_out->fs) {
        ret = -1;
        errno = EXDEV;
        goto out;
    }

    subvol = glfs_active_subvol(glfd_in->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd_in = glfs_resolve_fd(glfd_in->fs, subvol, glfd_in);
    if (!fd_in) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    fd_out = glfs_resolve_fd(glfd_out->fs, subvol, glfd_out);
    if (!fd_out) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    /*
     * This is based on how the vfs layer in the kernel handles
     * copy_file_range call. Upon receiving it follows the
     * below method to consider the offset.
     * if (off_in != NULL)
     *    use the value off_in to perform the op
     * else if off_in == NULL
     *    use the current file offset position to perform the op
     *
     * For gfapi, glfd->offset is used. For a freshly opened
     * fd, the offset is set to 0.
     */
    if (off_in)
        pos_in = *off_in;
    else
        pos_in = glfd_in->offset;

    if (off_out)
        pos_out = *off_out;
    else
        pos_out = glfd_out->offset;

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_copy_file_range(subvol, fd_in, pos_in, fd_out, pos_out, len,
                                 flags, &iattbuf, &preiatt, &postiatt, fop_attr,
                                 NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret >= 0) {
        pos_in += ret;
        pos_out += ret;

        if (off_in)
            *off_in = pos_in;
        if (off_out)
            *off_out = pos_out;

        if (statbuf)
            glfs_iatt_to_statx(glfd_in->fs, &iattbuf, statbuf);
        if (prestat)
            glfs_iatt_to_statx(glfd_in->fs, &preiatt, prestat);
        if (poststat)
            glfs_iatt_to_statx(glfd_in->fs, &postiatt, poststat);
    }

    if (ret <= 0)
        goto out;

    /*
     * If *off_in is NULL, then there is no offset info that can
     * obtained from the input argument. Hence follow below method.
     *  If *off_in is NULL, then
     *     glfd->offset = offset + ret;
     * else
     *     do nothing.
     *
     * According to the man page of copy_file_range, if off_in is
     * NULL, then the offset of the source file is advanced by
     * the return value of the fop. The same applies to off_out as
     * well. Otherwise, if *off_in is not NULL, then the offset
     * is not advanced by the filesystem. The entity which sends
     * the copy_file_range call is supposed to advance the offset
     * value in its buffer (pointed to by *off_in or *off_out)
     * by the return value of copy_file_range.
     */
    if (!off_in)
        glfd_in->offset += ret;

    if (!off_out)
        glfd_out->offset += ret;

out:
    if (fd_in)
        fd_unref(fd_in);
    if (fd_out)
        fd_unref(fd_out);
    if (glfd_in)
        GF_REF_PUT(glfd_in);
    if (glfd_out)
        GF_REF_PUT(glfd_out);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd_in->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_copy_file_range, 6.0);

ssize_t
pub_glfs_pwritev(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt,
                 off_t offset, int flags)
{
    return glfs_pwritev_common(glfd, iovec, iovcnt, offset, flags, NULL, NULL);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwritev, 3.4.0);

ssize_t
pub_glfs_write(struct glfs_fd *glfd, const void *buf, size_t count, int flags)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = (void *)buf;
    iov.iov_len = count;

    ret = pub_glfs_pwritev(glfd, &iov, 1, glfd->offset, flags);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_write, 3.4.0);

ssize_t
pub_glfs_writev(struct glfs_fd *glfd, const struct iovec *iov, int count,
                int flags)
{
    ssize_t ret = 0;

    ret = pub_glfs_pwritev(glfd, iov, count, glfd->offset, flags);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev, 3.4.0);

ssize_t
pub_glfs_pwrite34(struct glfs_fd *glfd, const void *buf, size_t count,
                  off_t offset, int flags)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = (void *)buf;
    iov.iov_len = count;

    ret = pub_glfs_pwritev(glfd, &iov, 1, offset, flags);

    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_pwrite34, glfs_pwrite, 3.4.0);

ssize_t
pub_glfs_pwrite(struct glfs_fd *glfd, const void *buf, size_t count,
                off_t offset, int flags, struct glfs_stat *prestat,
                struct glfs_stat *poststat)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = (void *)buf;
    iov.iov_len = count;

    ret = glfs_pwritev_common(glfd, &iov, 1, offset, flags, prestat, poststat);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite, 6.0);

extern glfs_t *
pub_glfs_from_glfd(glfs_fd_t *);

static int
glfs_pwritev_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
                       int op_ret, int op_errno, struct iatt *prebuf,
                       struct iatt *postbuf, dict_t *xdata)
{
    glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf,
                      postbuf);

    return 0;
}

static int
glfs_pwritev_async_common(struct glfs_fd *glfd, const struct iovec *iovec,
                          int count, off_t offset, int flags,
                          gf_boolean_t oldcb, glfs_io_cbk fn, void *data)
{
    struct glfs_io *gio = NULL;
    int ret = -1;
    call_frame_t *frame = NULL;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    struct iobref *iobref = NULL;
    struct iobuf *iobuf = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    /* Need to take explicit ref so that the fd
     * is not destroyed before the fop is complete
     */
    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        errno = EBADFD;
        goto out;
    }

    gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t);
    if (!gio) {
        errno = ENOMEM;
        goto out;
    }

    gio->op = GF_FOP_WRITE;
    gio->glfd = glfd;
    gio->offset = offset;
    gio->flags = flags;
    gio->oldcb = oldcb;
    gio->fn = fn;
    gio->data = data;
    gio->count = 1;
    gio->iov = GF_CALLOC(gio->count, sizeof(*(gio->iov)), gf_common_mt_iovec);
    if (!gio->iov) {
        errno = ENOMEM;
        goto out;
    }

    ret = iobuf_copy(subvol->ctx->iobuf_pool, iovec, count, &iobref, &iobuf,
                     gio->iov);
    if (ret)
        goto out;

    frame = syncop_create_frame(THIS);
    if (!frame) {
        errno = ENOMEM;
        ret = -1;
        goto out;
    }

    frame->local = gio;

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    STACK_WIND_COOKIE(frame, glfs_pwritev_async_cbk, subvol, subvol,
                      subvol->fops->writev, fd, gio->iov, gio->count, offset,
                      flags, iobref, fop_attr);

    ret = 0;
out:
    if (ret) {
        if (fd)
            fd_unref(fd);
        if (glfd)
            GF_REF_PUT(glfd);
        GF_FREE(gio);
        /*
         * If there is any error condition check after the frame
         * creation, we have to destroy the frame root.
         */
        glfs_subvol_done(glfd->fs, subvol);
    }
    if (fop_attr)
        dict_unref(fop_attr);

    if (iobuf)
        iobuf_unref(iobuf);
    if (iobref)
        iobref_unref(iobref);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_pwritev_async34(struct glfs_fd *glfd, const struct iovec *iovec,
                         int count, off_t offset, int flags, glfs_io_cbk34 fn,
                         void *data)
{
    return glfs_pwritev_async_common(glfd, iovec, count, offset, flags,
                                     _gf_true, (void *)fn, data);
}

GFAPI_SYMVER_PUBLIC(glfs_pwritev_async34, glfs_pwritev_async, 3.4.0);

int
pub_glfs_pwritev_async(struct glfs_fd *glfd, const struct iovec *iovec,
                       int count, off_t offset, int flags, glfs_io_cbk fn,
                       void *data)
{
    return glfs_pwritev_async_common(glfd, iovec, count, offset, flags,
                                     _gf_false, fn, data);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwritev_async, 6.0);

int
pub_glfs_write_async34(struct glfs_fd *glfd, const void *buf, size_t count,
                       int flags, glfs_io_cbk34 fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = (void *)buf;
    iov.iov_len = count;

    ret = glfs_pwritev_async_common(glfd, &iov, 1, glfd->offset, flags,
                                    _gf_true, (void *)fn, data);

    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_write_async34, glfs_write_async, 3.4.0);

int
pub_glfs_write_async(struct glfs_fd *glfd, const void *buf, size_t count,
                     int flags, glfs_io_cbk fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = (void *)buf;
    iov.iov_len = count;

    ret = glfs_pwritev_async_common(glfd, &iov, 1, glfd->offset, flags,
                                    _gf_false, fn, data);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_write_async, 6.0);

int
pub_glfs_pwrite_async34(struct glfs_fd *glfd, const void *buf, int count,
                        off_t offset, int flags, glfs_io_cbk34 fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = (void *)buf;
    iov.iov_len = count;

    ret = glfs_pwritev_async_common(glfd, &iov, 1, offset, flags, _gf_true,
                                    (void *)fn, data);

    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_pwrite_async34, glfs_pwrite_async, 3.4.0);

int
pub_glfs_pwrite_async(struct glfs_fd *glfd, const void *buf, int count,
                      off_t offset, int flags, glfs_io_cbk fn, void *data)
{
    struct iovec iov = {
        0,
    };
    ssize_t ret = 0;

    iov.iov_base = (void *)buf;
    iov.iov_len = count;

    ret = glfs_pwritev_async_common(glfd, &iov, 1, offset, flags, _gf_false, fn,
                                    data);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite_async, 6.0);

int
pub_glfs_writev_async34(struct glfs_fd *glfd, const struct iovec *iov,
                        int count, int flags, glfs_io_cbk34 fn, void *data)
{
    ssize_t ret = 0;

    ret = glfs_pwritev_async_common(glfd, iov, count, glfd->offset, flags,
                                    _gf_true, (void *)fn, data);
    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_writev_async34, glfs_writev_async, 3.4.0);

int
pub_glfs_writev_async(struct glfs_fd *glfd, const struct iovec *iov, int count,
                      int flags, glfs_io_cbk fn, void *data)
{
    ssize_t ret = 0;

    ret = glfs_pwritev_async_common(glfd, iov, count, glfd->offset, flags,
                                    _gf_false, fn, data);
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev_async, 6.0);

static int
glfs_fsync_common(struct glfs_fd *glfd, struct glfs_stat *prestat,
                  struct glfs_stat *poststat)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    struct iatt preiatt =
                    {
                        0,
                    },
                postiatt = {
                    0,
                };
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_fsync(subvol, fd, 0, &preiatt, &postiatt, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret >= 0) {
        if (prestat)
            glfs_iatt_to_statx(glfd->fs, &preiatt, prestat);
        if (poststat)
            glfs_iatt_to_statx(glfd->fs, &postiatt, poststat);
    }
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_fsync34(struct glfs_fd *glfd)
{
    return glfs_fsync_common(glfd, NULL, NULL);
}

GFAPI_SYMVER_PUBLIC(glfs_fsync34, glfs_fsync, 3.4.0);

int
pub_glfs_fsync(struct glfs_fd *glfd, struct glfs_stat *prestat,
               struct glfs_stat *poststat)
{
    return glfs_fsync_common(glfd, prestat, poststat);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync, 6.0);

static int
glfs_fsync_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
                     int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
                     struct iatt *postbuf, dict_t *xdata)
{
    glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf,
                      postbuf);

    return 0;
}

static int
glfs_fsync_async_common(struct glfs_fd *glfd, gf_boolean_t oldcb,
                        glfs_io_cbk fn, void *data, int dataonly)
{
    struct glfs_io *gio = NULL;
    int ret = 0;
    call_frame_t *frame = NULL;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;

    /* Need to take explicit ref so that the fd
     * is not destroyed before the fop is complete
     */
    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    frame = syncop_create_frame(THIS);
    if (!frame) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t);
    if (!gio) {
        errno = ENOMEM;
        ret = -1;
        goto out;
    }

    gio->op = GF_FOP_FSYNC;
    gio->glfd = glfd;
    gio->flags = dataonly;
    gio->oldcb = oldcb;
    gio->fn = fn;
    gio->data = data;

    frame->local = gio;

    STACK_WIND_COOKIE(frame, glfs_fsync_async_cbk, subvol, subvol,
                      subvol->fops->fsync, fd, dataonly, NULL);

out:
    if (ret) {
        if (fd)
            fd_unref(fd);
        GF_REF_PUT(glfd);
        GF_FREE(gio);
        if (frame)
            STACK_DESTROY(frame->root);
        glfs_subvol_done(glfd->fs, subvol);
    }

    return ret;
}

int
pub_glfs_fsync_async34(struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data)
{
    int ret = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    ret = glfs_fsync_async_common(glfd, _gf_true, (void *)fn, data, 0);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_fsync_async34, glfs_fsync_async, 3.4.0);

int
pub_glfs_fsync_async(struct glfs_fd *glfd, glfs_io_cbk fn, void *data)
{
    int ret = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    ret = glfs_fsync_async_common(glfd, _gf_false, fn, data, 0);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync_async, 6.0);

static int
glfs_fdatasync_common(struct glfs_fd *glfd, struct glfs_stat *prestat,
                      struct glfs_stat *poststat)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    struct iatt preiatt =
                    {
                        0,
                    },
                postiatt = {
                    0,
                };
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_fsync(subvol, fd, 1, &preiatt, &postiatt, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret >= 0) {
        if (prestat)
            glfs_iatt_to_statx(glfd->fs, &preiatt, prestat);
        if (poststat)
            glfs_iatt_to_statx(glfd->fs, &postiatt, poststat);
    }
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_fdatasync34(struct glfs_fd *glfd)
{
    return glfs_fdatasync_common(glfd, NULL, NULL);
}

GFAPI_SYMVER_PUBLIC(glfs_fdatasync34, glfs_fdatasync, 3.4.0);

int
pub_glfs_fdatasync(struct glfs_fd *glfd, struct glfs_stat *prestat,
                   struct glfs_stat *poststat)
{
    return glfs_fdatasync_common(glfd, prestat, poststat);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync, 6.0);

int
pub_glfs_fdatasync_async34(struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data)
{
    int ret = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    ret = glfs_fsync_async_common(glfd, _gf_true, (void *)fn, data, 1);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC(glfs_fdatasync_async34, glfs_fdatasync_async, 3.4.0);

int
pub_glfs_fdatasync_async(struct glfs_fd *glfd, glfs_io_cbk fn, void *data)
{
    int ret = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    ret = glfs_fsync_async_common(glfd, _gf_false, fn, data, 1);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync_async, 6.0);

static int
glfs_ftruncate_common(struct glfs_fd *glfd, off_t offset,
                      struct glfs_stat *prestat, struct glfs_stat *poststat)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    struct iatt preiatt =
                    {
                        0,
                    },
                postiatt = {
                    0,
                };
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_ftruncate(subvol, fd, offset, &preiatt, &postiatt, fop_attr,
                           NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret >= 0) {
        if (prestat)
            glfs_iatt_to_statx(glfd->fs, &preiatt, prestat);
        if (poststat)
            glfs_iatt_to_statx(glfd->fs, &postiatt, poststat);
    }
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_ftruncate34(struct glfs_fd *glfd, off_t offset)
{
    return glfs_ftruncate_common(glfd, offset, NULL, NULL);
}

GFAPI_SYMVER_PUBLIC(glfs_ftruncate34, glfs_ftruncate, 3.4.0);

int
pub_glfs_ftruncate(struct glfs_fd *glfd, off_t offset,
                   struct glfs_stat *prestat, struct glfs_stat *poststat)
{
    return glfs_ftruncate_common(glfd, offset, prestat, poststat);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate, 6.0);

int
pub_glfs_truncate(struct glfs *fs, const char *path, off_t length)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = syncop_truncate(subvol, &loc, length, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_truncate, 3.7.15);

static int
glfs_ftruncate_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
                         int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
                         struct iatt *postbuf, dict_t *xdata)
{
    glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf,
                      postbuf);

    return 0;
}

static int
glfs_ftruncate_async_common(struct glfs_fd *glfd, off_t offset,
                            gf_boolean_t oldcb, glfs_io_cbk fn, void *data)
{
    struct glfs_io *gio = NULL;
    int ret = -1;
    call_frame_t *frame = NULL;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    /* Need to take explicit ref so that the fd
     * is not destroyed before the fop is complete
     */
    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        errno = EBADFD;
        goto out;
    }

    frame = syncop_create_frame(THIS);
    if (!frame) {
        errno = ENOMEM;
        goto out;
    }

    gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t);
    if (!gio) {
        errno = ENOMEM;
        goto out;
    }

    gio->op = GF_FOP_FTRUNCATE;
    gio->glfd = glfd;
    gio->offset = offset;
    gio->oldcb = oldcb;
    gio->fn = fn;
    gio->data = data;

    frame->local = gio;

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    STACK_WIND_COOKIE(frame, glfs_ftruncate_async_cbk, subvol, subvol,
                      subvol->fops->ftruncate, fd, offset, fop_attr);

    ret = 0;

out:
    if (ret) {
        if (fd)
            fd_unref(fd);
        if (glfd)
            GF_REF_PUT(glfd);
        GF_FREE(gio);
        if (frame)
            STACK_DESTROY(frame->root);
        glfs_subvol_done(glfd->fs, subvol);
    }
    if (fop_attr)
        dict_unref(fop_attr);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_ftruncate_async34(struct glfs_fd *glfd, off_t offset, glfs_io_cbk34 fn,
                           void *data)
{
    return glfs_ftruncate_async_common(glfd, offset, _gf_true, (void *)fn,
                                       data);
}

GFAPI_SYMVER_PUBLIC(glfs_ftruncate_async34, glfs_ftruncate_async, 3.4.0);

int
pub_glfs_ftruncate_async(struct glfs_fd *glfd, off_t offset, glfs_io_cbk fn,
                         void *data)
{
    return glfs_ftruncate_async_common(glfd, offset, _gf_false, fn, data);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate_async, 6.0);

int
pub_glfs_access(struct glfs *fs, const char *path, int mode)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = syncop_access(subvol, &loc, mode, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_access, 3.4.0);

int
pub_glfs_symlink(struct glfs *fs, const char *data, const char *path)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    uuid_t gfid;
    dict_t *xattr_req = NULL;
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    xattr_req = dict_new();
    if (!xattr_req) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gf_uuid_generate(gfid);
    ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true);
    if (ret) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (loc.inode) {
        errno = EEXIST;
        ret = -1;
        goto out;
    }

    if (ret == -1 && errno != ENOENT)
        /* Any other type of error is fatal */
        goto out;

    if (ret == -1 && errno == ENOENT && !loc.parent)
        /* The parent directory or an ancestor even
           higher does not exist
        */
        goto out;

    /* ret == -1 && errno == ENOENT */
    loc.inode = inode_new(loc.parent->table);
    if (!loc.inode) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    ret = syncop_symlink(subvol, &loc, data, &iatt, xattr_req, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0)
        ret = glfs_loc_link(&loc, &iatt);
out:
    loc_wipe(&loc);

    if (xattr_req)
        dict_unref(xattr_req);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_symlink, 3.4.0);

int
pub_glfs_readlink(struct glfs *fs, const char *path, char *buf, size_t bufsiz)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;
    char *linkval = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    if (iatt.ia_type != IA_IFLNK) {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    ret = syncop_readlink(subvol, &loc, &linkval, bufsiz, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);
    if (ret > 0) {
        memcpy(buf, linkval, ret);
        GF_FREE(linkval);
    }

    ESTALE_RETRY(ret, errno, reval, &loc, retry);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readlink, 3.4.0);

int
pub_glfs_mknod(struct glfs *fs, const char *path, mode_t mode, dev_t dev)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    uuid_t gfid;
    dict_t *xattr_req = NULL;
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    xattr_req = dict_new();
    if (!xattr_req) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gf_uuid_generate(gfid);
    ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true);
    if (ret) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (loc.inode) {
        errno = EEXIST;
        ret = -1;
        goto out;
    }

    if (ret == -1 && errno != ENOENT)
        /* Any other type of error is fatal */
        goto out;

    if (ret == -1 && errno == ENOENT && !loc.parent)
        /* The parent directory or an ancestor even
           higher does not exist
        */
        goto out;

    /* ret == -1 && errno == ENOENT */
    loc.inode = inode_new(loc.parent->table);
    if (!loc.inode) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    ret = syncop_mknod(subvol, &loc, mode, dev, &iatt, xattr_req, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0)
        ret = glfs_loc_link(&loc, &iatt);
out:
    loc_wipe(&loc);

    if (xattr_req)
        dict_unref(xattr_req);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_mknod, 3.4.0);

int
pub_glfs_mkdir(struct glfs *fs, const char *path, mode_t mode)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    uuid_t gfid;
    dict_t *xattr_req = NULL;
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    xattr_req = dict_new();
    if (!xattr_req) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    gf_uuid_generate(gfid);
    ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true);
    if (ret) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (loc.inode) {
        errno = EEXIST;
        ret = -1;
        goto out;
    }

    if (ret == -1 && errno != ENOENT)
        /* Any other type of error is fatal */
        goto out;

    if (ret == -1 && errno == ENOENT && !loc.parent)
        /* The parent directory or an ancestor even
           higher does not exist
        */
        goto out;

    /* ret == -1 && errno == ENOENT */
    loc.inode = inode_new(loc.parent->table);
    if (!loc.inode) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    ret = syncop_mkdir(subvol, &loc, mode, &iatt, xattr_req, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0)
        ret = glfs_loc_link(&loc, &iatt);
out:
    loc_wipe(&loc);

    if (xattr_req)
        dict_unref(xattr_req);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_mkdir, 3.4.0);

int
pub_glfs_unlink(struct glfs *fs, const char *path)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    if (iatt.ia_type == IA_IFDIR) {
        ret = -1;
        errno = EISDIR;
        goto out;
    }

    /* TODO: Add leaseid */
    ret = syncop_unlink(subvol, &loc, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0)
        ret = glfs_loc_unlink(&loc);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_unlink, 3.4.0);

int
pub_glfs_rmdir(struct glfs *fs, const char *path)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    if (iatt.ia_type != IA_IFDIR) {
        ret = -1;
        errno = ENOTDIR;
        goto out;
    }

    ret = syncop_rmdir(subvol, &loc, 0, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret == 0)
        ret = glfs_loc_unlink(&loc);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_rmdir, 3.4.0);

int
pub_glfs_rename(struct glfs *fs, const char *oldpath, const char *newpath)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t oldloc = {
        0,
    };
    loc_t newloc = {
        0,
    };
    struct iatt oldiatt = {
        0,
    };
    struct iatt newiatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, oldpath, &oldloc, &oldiatt, reval);

    ESTALE_RETRY(ret, errno, reval, &oldloc, retry);

    if (ret)
        goto out;
retrynew:
    ret = glfs_lresolve(fs, subvol, newpath, &newloc, &newiatt, reval);

    ESTALE_RETRY(ret, errno, reval, &newloc, retrynew);

    if (ret && errno != ENOENT && newloc.parent)
        goto out;

    if (newiatt.ia_type != IA_INVAL) {
        if ((oldiatt.ia_type == IA_IFDIR) != (newiatt.ia_type == IA_IFDIR)) {
            /* Either both old and new must be dirs,
             * or both must be non-dirs. Else, fail.
             */
            ret = -1;
            errno = EISDIR;
            goto out;
        }
    }

    /* TODO: - check if new or old is a prefix of the other, and fail EINVAL
     *       - Add leaseid */

    ret = syncop_rename(subvol, &oldloc, &newloc, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret == -1 && errno == ESTALE) {
        if (reval < DEFAULT_REVAL_COUNT) {
            reval++;
            loc_wipe(&oldloc);
            loc_wipe(&newloc);
            goto retry;
        }
    }

    if (ret == 0) {
        inode_rename(oldloc.parent->table, oldloc.parent, oldloc.name,
                     newloc.parent, newloc.name, oldloc.inode, &oldiatt);

        if (newloc.inode && !inode_has_dentry(newloc.inode))
            inode_forget(newloc.inode, 0);
    }
out:
    loc_wipe(&oldloc);
    loc_wipe(&newloc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_rename, 3.4.0);

int
pub_glfs_link(struct glfs *fs, const char *oldpath, const char *newpath)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t oldloc = {
        0,
    };
    loc_t newloc = {
        0,
    };
    struct iatt oldiatt = {
        0,
    };
    struct iatt newiatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_lresolve(fs, subvol, oldpath, &oldloc, &oldiatt, reval);

    ESTALE_RETRY(ret, errno, reval, &oldloc, retry);

    if (ret)
        goto out;
retrynew:
    ret = glfs_lresolve(fs, subvol, newpath, &newloc, &newiatt, reval);

    ESTALE_RETRY(ret, errno, reval, &newloc, retrynew);

    if (ret == 0) {
        ret = -1;
        errno = EEXIST;
        goto out;
    }

    if (oldiatt.ia_type == IA_IFDIR) {
        ret = -1;
        errno = EISDIR;
        goto out;
    }

    /* Filling the inode of the hard link to be same as that of the
       original file
    */
    if (newloc.inode) {
        inode_unref(newloc.inode);
        newloc.inode = NULL;
    }
    newloc.inode = inode_ref(oldloc.inode);

    ret = syncop_link(subvol, &oldloc, &newloc, &newiatt, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    if (ret == -1 && errno == ESTALE) {
        loc_wipe(&oldloc);
        loc_wipe(&newloc);
        if (reval--)
            goto retry;
    }

    if (ret == 0)
        ret = glfs_loc_link(&newloc, &newiatt);
out:
    loc_wipe(&oldloc);
    loc_wipe(&newloc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_link, 3.4.0);

struct glfs_fd *
pub_glfs_opendir(struct glfs *fs, const char *path)
{
    int ret = -1;
    struct glfs_fd *glfd = NULL;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    glfd = glfs_fd_new(fs);
    if (!glfd)
        goto out;

    INIT_LIST_HEAD(&glfd->entries);
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    if (!IA_ISDIR(iatt.ia_type)) {
        ret = -1;
        errno = ENOTDIR;
        goto out;
    }

    if (glfd->fd) {
        /* Retry. Safe to touch glfd->fd as we
           still have not glfs_fd_bind() yet.
        */
        fd_unref(glfd->fd);
        glfd->fd = NULL;
    }

    glfd->fd = fd_create(loc.inode, getpid());
    if (!glfd->fd) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    ret = syncop_opendir(subvol, &loc, glfd->fd, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);
out:
    loc_wipe(&loc);

    if (ret && glfd) {
        GF_REF_PUT(glfd);
        glfd = NULL;
    } else if (glfd) {
        glfd_set_state_bind(glfd);
    }

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return glfd;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_opendir, 3.4.0);

int
pub_glfs_closedir(struct glfs_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_mark_glfd_for_deletion(glfd);

    __GLFS_EXIT_FS;

    ret = 0;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_closedir, 3.4.0);

long
pub_glfs_telldir(struct glfs_fd *fd)
{
    return fd->offset;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_telldir, 3.4.0);

void
pub_glfs_seekdir(struct glfs_fd *fd, long offset)
{
    gf_dirent_t *entry = NULL;
    gf_dirent_t *tmp = NULL;

    if (fd->offset == offset)
        return;

    fd->offset = offset;
    fd->next = NULL;

    list_for_each_entry_safe(entry, tmp, &fd->entries, list)
    {
        if (entry->d_off != offset)
            continue;

        if (&tmp->list != &fd->entries) {
            /* found! */
            fd->next = tmp;
            return;
        }
    }
    /* could not find entry at requested offset in the cache.
       next readdir_r() will result in glfd_entry_refresh()
    */
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_seekdir, 3.4.0);

static int
glfs_discard_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
                       int32_t op_ret, int32_t op_errno,
                       struct iatt *preop_stbuf, struct iatt *postop_stbuf,
                       dict_t *xdata)
{
    glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, preop_stbuf,
                      postop_stbuf);

    return 0;
}

static int
glfs_discard_async_common(struct glfs_fd *glfd, off_t offset, size_t len,
                          gf_boolean_t oldcb, glfs_io_cbk fn, void *data)
{
    struct glfs_io *gio = NULL;
    int ret = -1;
    call_frame_t *frame = NULL;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    /* Need to take explicit ref so that the fd
     * is not destroyed before the fop is complete
     */
    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        errno = EBADFD;
        goto out;
    }

    frame = syncop_create_frame(THIS);
    if (!frame) {
        errno = ENOMEM;
        goto out;
    }

    gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t);
    if (!gio) {
        errno = ENOMEM;
        goto out;
    }

    gio->op = GF_FOP_DISCARD;
    gio->glfd = glfd;
    gio->offset = offset;
    gio->count = len;
    gio->oldcb = oldcb;
    gio->fn = fn;
    gio->data = data;

    frame->local = gio;
    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    STACK_WIND_COOKIE(frame, glfs_discard_async_cbk, subvol, subvol,
                      subvol->fops->discard, fd, offset, len, fop_attr);

    ret = 0;
out:
    if (ret) {
        if (fd)
            fd_unref(fd);
        if (glfd)
            GF_REF_PUT(glfd);
        GF_FREE(gio);
        if (frame)
            STACK_DESTROY(frame->root);
        glfs_subvol_done(glfd->fs, subvol);
    }

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_discard_async35(struct glfs_fd *glfd, off_t offset, size_t len,
                         glfs_io_cbk34 fn, void *data)
{
    return glfs_discard_async_common(glfd, offset, len, _gf_true, (void *)fn,
                                     data);
}

GFAPI_SYMVER_PUBLIC(glfs_discard_async35, glfs_discard_async, 3.5.0);

int
pub_glfs_discard_async(struct glfs_fd *glfd, off_t offset, size_t len,
                       glfs_io_cbk fn, void *data)
{
    return glfs_discard_async_common(glfd, offset, len, _gf_false, fn, data);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_discard_async, 6.0);

static int
glfs_zerofill_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
                        int32_t op_ret, int32_t op_errno,
                        struct iatt *preop_stbuf, struct iatt *postop_stbuf,
                        dict_t *xdata)
{
    glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, preop_stbuf,
                      postop_stbuf);

    return 0;
}

static int
glfs_zerofill_async_common(struct glfs_fd *glfd, off_t offset, off_t len,
                           gf_boolean_t oldcb, glfs_io_cbk fn, void *data)
{
    struct glfs_io *gio = NULL;
    int ret = -1;
    call_frame_t *frame = NULL;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    /* Need to take explicit ref so that the fd
     * is not destroyed before the fop is complete
     */
    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        errno = EBADFD;
        goto out;
    }

    frame = syncop_create_frame(THIS);
    if (!frame) {
        errno = ENOMEM;
        goto out;
    }

    gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t);
    if (!gio) {
        errno = ENOMEM;
        goto out;
    }

    gio->op = GF_FOP_ZEROFILL;
    gio->glfd = glfd;
    gio->offset = offset;
    gio->count = len;
    gio->oldcb = oldcb;
    gio->fn = fn;
    gio->data = data;

    frame->local = gio;

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    STACK_WIND_COOKIE(frame, glfs_zerofill_async_cbk, subvol, subvol,
                      subvol->fops->zerofill, fd, offset, len, fop_attr);
    ret = 0;
out:
    if (ret) {
        if (fd)
            fd_unref(fd);
        if (glfd)
            GF_REF_PUT(glfd);
        GF_FREE(gio);
        if (frame)
            STACK_DESTROY(frame->root);
        glfs_subvol_done(glfd->fs, subvol);
    }
    if (fop_attr)
        dict_unref(fop_attr);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_zerofill_async35(struct glfs_fd *glfd, off_t offset, off_t len,
                          glfs_io_cbk34 fn, void *data)
{
    return glfs_zerofill_async_common(glfd, offset, len, _gf_true, (void *)fn,
                                      data);
}

GFAPI_SYMVER_PUBLIC(glfs_zerofill_async35, glfs_zerofill_async, 3.5.0);

int
pub_glfs_zerofill_async(struct glfs_fd *glfd, off_t offset, off_t len,
                        glfs_io_cbk fn, void *data)
{
    return glfs_zerofill_async_common(glfd, offset, len, _gf_false, fn, data);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_zerofill_async, 6.0);

void
gf_dirent_to_dirent(gf_dirent_t *gf_dirent, struct dirent *dirent)
{
    dirent->d_ino = gf_dirent->d_ino;

#ifdef _DIRENT_HAVE_D_OFF
    dirent->d_off = gf_dirent->d_off;
#endif

#ifdef _DIRENT_HAVE_D_TYPE
    dirent->d_type = gf_dirent->d_type;
#endif

#ifdef _DIRENT_HAVE_D_NAMLEN
    dirent->d_namlen = strlen(gf_dirent->d_name);
#endif

    snprintf(dirent->d_name, NAME_MAX + 1, "%s", gf_dirent->d_name);
}

int
glfd_entry_refresh(struct glfs_fd *glfd, int plus)
{
    xlator_t *subvol = NULL;
    gf_dirent_t entries;
    gf_dirent_t old;
    gf_dirent_t *entry = NULL;
    int ret = -1;
    fd_t *fd = NULL;

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    if (fd->inode->ia_type != IA_IFDIR) {
        ret = -1;
        errno = EBADF;
        goto out;
    }

    INIT_LIST_HEAD(&entries.list);
    INIT_LIST_HEAD(&old.list);

    if (plus)
        ret = syncop_readdirp(subvol, fd, 131072, glfd->offset, &entries, NULL,
                              NULL);
    else
        ret = syncop_readdir(subvol, fd, 131072, glfd->offset, &entries, NULL,
                             NULL);
    DECODE_SYNCOP_ERR(ret);
    if (ret >= 0) {
        if (plus) {
            list_for_each_entry(entry, &entries.list, list)
            {
                if ((!entry->inode && (!IA_ISDIR(entry->d_stat.ia_type))) ||
                    ((entry->d_stat.ia_ctime == 0) &&
                     strcmp(entry->d_name, ".") &&
                     strcmp(entry->d_name, ".."))) {
                    /* entry->inode for directories will be
                     * always set to null to force a lookup
                     * on the dentry. Hence to not degrade
                     * readdir performance, we skip lookups
                     * for directory entries. Also we will have
                     * proper stat if directory present on
                     * hashed subvolume.
                     *
                     * In addition, if the stat is invalid, force
                     * lookup to fetch proper stat.
                     */
                    gf_fill_iatt_for_dirent(entry, fd->inode, subvol);
                }
            }

            gf_link_inodes_from_dirent(THIS, fd->inode, &entries);
        }

        list_splice_init(&glfd->entries, &old.list);
        list_splice_init(&entries.list, &glfd->entries);

        /* spurious errno is dangerous for glfd_entry_next() */
        errno = 0;
    }

    if (ret > 0)
        glfd->next = list_entry(glfd->entries.next, gf_dirent_t, list);

    gf_dirent_free(&old);
out:
    if (fd)
        fd_unref(fd);

    glfs_subvol_done(glfd->fs, subvol);

    return ret;
}

gf_dirent_t *
glfd_entry_next(struct glfs_fd *glfd, int plus)
{
    gf_dirent_t *entry = NULL;
    int ret = -1;

    if (!glfd->offset || !glfd->next) {
        ret = glfd_entry_refresh(glfd, plus);
        if (ret < 0)
            return NULL;
    }

    entry = glfd->next;
    if (!entry)
        return NULL;

    if (&entry->next->list == &glfd->entries)
        glfd->next = NULL;
    else
        glfd->next = entry->next;

    glfd->offset = entry->d_off;

    return entry;
}

struct dirent *
glfs_readdirbuf_get(struct glfs_fd *glfd)
{
    struct dirent *buf = NULL;

    LOCK(&glfd->fd->lock);
    {
        buf = glfd->readdirbuf;
        if (buf) {
            memset(buf, 0, READDIRBUF_SIZE);
            goto unlock;
        }

        buf = GF_CALLOC(1, READDIRBUF_SIZE, glfs_mt_readdirbuf_t);
        if (!buf) {
            errno = ENOMEM;
            goto unlock;
        }

        glfd->readdirbuf = buf;
    }
unlock:
    UNLOCK(&glfd->fd->lock);

    return buf;
}

int
pub_glfs_readdirplus_r(struct glfs_fd *glfd, struct stat *stat,
                       struct dirent *ext, struct dirent **res)
{
    int ret = 0;
    gf_dirent_t *entry = NULL;
    struct dirent *buf = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    errno = 0;

    if (ext)
        buf = ext;
    else
        buf = glfs_readdirbuf_get(glfd);

    if (!buf) {
        errno = ENOMEM;
        ret = -1;
        goto out;
    }

    entry = glfd_entry_next(glfd, !!stat);
    if (errno)
        ret = -1;

    if (res) {
        if (entry)
            *res = buf;
        else
            *res = NULL;
    }

    if (entry) {
        gf_dirent_to_dirent(entry, buf);
        if (stat)
            glfs_iatt_to_stat(glfd->fs, &entry->d_stat, stat);
    }

out:
    if (glfd)
        GF_REF_PUT(glfd);

    __GLFS_EXIT_FS;

    return ret;

invalid_fs:
    return -1;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdirplus_r, 3.4.0);

int
pub_glfs_readdir_r(struct glfs_fd *glfd, struct dirent *buf,
                   struct dirent **res)
{
    return pub_glfs_readdirplus_r(glfd, 0, buf, res);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdir_r, 3.4.0);

struct dirent *
pub_glfs_readdirplus(struct glfs_fd *glfd, struct stat *stat)
{
    struct dirent *res = NULL;
    int ret = -1;

    ret = pub_glfs_readdirplus_r(glfd, stat, NULL, &res);
    if (ret)
        return NULL;

    return res;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdirplus, 3.5.0);

struct dirent *
pub_glfs_readdir(struct glfs_fd *glfd)
{
    return pub_glfs_readdirplus(glfd, NULL);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdir, 3.5.0);

int
pub_glfs_statvfs(struct glfs *fs, const char *path, struct statvfs *buf)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = syncop_statfs(subvol, &loc, buf, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_statvfs, 3.4.0);

int
pub_glfs_setattr(struct glfs *fs, const char *path, struct glfs_stat *stat,
                 int follow)
{
    int ret = -1;
    int glvalid;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt riatt = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    GF_VALIDATE_OR_GOTO("glfs_setattr", stat, out);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    if (follow)
        ret = glfs_resolve(fs, subvol, path, &loc, &riatt, reval);
    else
        ret = glfs_lresolve(fs, subvol, path, &loc, &riatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    glfs_iatt_from_statx(&iatt, stat);
    glfsflags_from_gfapiflags(stat, &glvalid);

    /* TODO : Add leaseid */
    ret = syncop_setattr(subvol, &loc, &iatt, glvalid, 0, 0, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);
out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setattr, 6.0);

int
pub_glfs_fsetattr(struct glfs_fd *glfd, struct glfs_stat *stat)
{
    int ret = -1;
    int glvalid;
    struct iatt iatt = {
        0,
    };
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    GF_VALIDATE_OR_GOTO("glfs_fsetattr", stat, out);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    glfs_iatt_from_statx(&iatt, stat);
    glfsflags_from_gfapiflags(stat, &glvalid);

    /* TODO : Add leaseid */
    ret = syncop_fsetattr(subvol, fd, &iatt, glvalid, 0, 0, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsetattr, 6.0);

int
pub_glfs_chmod(struct glfs *fs, const char *path, mode_t mode)
{
    int ret = -1;
    struct glfs_stat stat = {
        0,
    };

    stat.glfs_st_mode = mode;
    stat.glfs_st_mask = GLFS_STAT_MODE;

    ret = glfs_setattr(fs, path, &stat, 1);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chmod, 3.4.0);

int
pub_glfs_fchmod(struct glfs_fd *glfd, mode_t mode)
{
    int ret = -1;
    struct glfs_stat stat = {
        0,
    };

    stat.glfs_st_mode = mode;
    stat.glfs_st_mask = GLFS_STAT_MODE;

    ret = glfs_fsetattr(glfd, &stat);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchmod, 3.4.0);

int
pub_glfs_chown(struct glfs *fs, const char *path, uid_t uid, gid_t gid)
{
    int ret = 0;
    struct glfs_stat stat = {
        0,
    };

    if (uid != (uid_t)-1) {
        stat.glfs_st_uid = uid;
        stat.glfs_st_mask = GLFS_STAT_UID;
    }

    if (gid != (uid_t)-1) {
        stat.glfs_st_gid = gid;
        stat.glfs_st_mask = stat.glfs_st_mask | GLFS_STAT_GID;
    }

    if (stat.glfs_st_mask)
        ret = glfs_setattr(fs, path, &stat, 1);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chown, 3.4.0);

int
pub_glfs_lchown(struct glfs *fs, const char *path, uid_t uid, gid_t gid)
{
    int ret = 0;
    struct glfs_stat stat = {
        0,
    };

    if (uid != (uid_t)-1) {
        stat.glfs_st_uid = uid;
        stat.glfs_st_mask = GLFS_STAT_UID;
    }

    if (gid != (uid_t)-1) {
        stat.glfs_st_gid = gid;
        stat.glfs_st_mask = stat.glfs_st_mask | GLFS_STAT_GID;
    }

    if (stat.glfs_st_mask)
        ret = glfs_setattr(fs, path, &stat, 0);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lchown, 3.4.0);

int
pub_glfs_fchown(struct glfs_fd *glfd, uid_t uid, gid_t gid)
{
    int ret = 0;
    struct glfs_stat stat = {
        0,
    };

    if (uid != (uid_t)-1) {
        stat.glfs_st_uid = uid;
        stat.glfs_st_mask = GLFS_STAT_UID;
    }

    if (gid != (uid_t)-1) {
        stat.glfs_st_gid = gid;
        stat.glfs_st_mask = stat.glfs_st_mask | GLFS_STAT_GID;
    }

    if (stat.glfs_st_mask)
        ret = glfs_fsetattr(glfd, &stat);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchown, 3.4.0);

int
pub_glfs_utimens(struct glfs *fs, const char *path,
                 const struct timespec times[2])
{
    int ret = -1;
    struct glfs_stat stat = {
        0,
    };

    stat.glfs_st_atime = times[0];
    stat.glfs_st_mtime = times[1];

    stat.glfs_st_mask = GLFS_STAT_ATIME | GLFS_STAT_MTIME;

    ret = glfs_setattr(fs, path, &stat, 1);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_utimens, 3.4.0);

int
pub_glfs_lutimens(struct glfs *fs, const char *path,
                  const struct timespec times[2])
{
    int ret = -1;
    struct glfs_stat stat = {
        0,
    };

    stat.glfs_st_atime = times[0];
    stat.glfs_st_mtime = times[1];

    stat.glfs_st_mask = GLFS_STAT_ATIME | GLFS_STAT_MTIME;

    ret = glfs_setattr(fs, path, &stat, 0);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lutimens, 3.4.0);

int
pub_glfs_futimens(struct glfs_fd *glfd, const struct timespec times[2])
{
    int ret = -1;
    struct glfs_stat stat = {
        0,
    };

    stat.glfs_st_atime = times[0];
    stat.glfs_st_mtime = times[1];

    stat.glfs_st_mask = GLFS_STAT_ATIME | GLFS_STAT_MTIME;

    ret = glfs_fsetattr(glfd, &stat);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_futimens, 3.4.0);

int
glfs_getxattr_process(void *value, size_t size, dict_t *xattr, const char *name)
{
    data_t *data = NULL;
    int ret = -1;

    data = dict_get(xattr, (char *)name);
    if (!data) {
        errno = ENODATA;
        ret = -1;
        goto out;
    }

    ret = data->len;
    if (!value || !size)
        goto out;

    if (size < ret) {
        ret = -1;
        errno = ERANGE;
        goto out;
    }

    memcpy(value, data->data, ret);
out:
    return ret;
}

ssize_t
glfs_getxattr_common(struct glfs *fs, const char *path, const char *name,
                     void *value, size_t size, int follow)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    dict_t *xattr = NULL;
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    if (!name || *name == '\0') {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    if (strlen(name) > GF_XATTR_NAME_MAX) {
        ret = -1;
        errno = ENAMETOOLONG;
        goto out;
    }

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

retry:
    if (follow)
        ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);
    else
        ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = syncop_getxattr(subvol, &loc, &xattr, name, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = glfs_getxattr_process(value, size, xattr, name);
out:
    loc_wipe(&loc);

    if (xattr)
        dict_unref(xattr);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

ssize_t
pub_glfs_getxattr(struct glfs *fs, const char *path, const char *name,
                  void *value, size_t size)
{
    return glfs_getxattr_common(fs, path, name, value, size, 1);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_getxattr, 3.4.0);

ssize_t
pub_glfs_lgetxattr(struct glfs *fs, const char *path, const char *name,
                   void *value, size_t size)
{
    return glfs_getxattr_common(fs, path, name, value, size, 0);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lgetxattr, 3.4.0);

ssize_t
pub_glfs_fgetxattr(struct glfs_fd *glfd, const char *name, void *value,
                   size_t size)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    dict_t *xattr = NULL;
    fd_t *fd = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    if (!name || *name == '\0') {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    if (strlen(name) > GF_XATTR_NAME_MAX) {
        ret = -1;
        errno = ENAMETOOLONG;
        goto out;
    }

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = syncop_fgetxattr(subvol, fd, &xattr, name, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);
    if (ret)
        goto out;

    ret = glfs_getxattr_process(value, size, xattr, name);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (xattr)
        dict_unref(xattr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fgetxattr, 3.4.0);

int
glfs_listxattr_process(void *value, size_t size, dict_t *xattr)
{
    int ret = -1;

    if (!xattr)
        goto out;

    ret = dict_keys_join(NULL, 0, xattr, NULL);

    if (!value || !size)
        goto out;

    if (size < ret) {
        ret = -1;
        errno = ERANGE;
    } else {
        dict_keys_join(value, size, xattr, NULL);
    }

out:
    return ret;
}

ssize_t
glfs_listxattr_common(struct glfs *fs, const char *path, void *value,
                      size_t size, int follow)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    dict_t *xattr = NULL;
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

retry:
    if (follow)
        ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);
    else
        ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = syncop_getxattr(subvol, &loc, &xattr, NULL, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = glfs_listxattr_process(value, size, xattr);
out:
    loc_wipe(&loc);

    if (xattr)
        dict_unref(xattr);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

ssize_t
pub_glfs_listxattr(struct glfs *fs, const char *path, void *value, size_t size)
{
    return glfs_listxattr_common(fs, path, value, size, 1);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_listxattr, 3.4.0);

ssize_t
pub_glfs_llistxattr(struct glfs *fs, const char *path, void *value, size_t size)
{
    return glfs_listxattr_common(fs, path, value, size, 0);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_llistxattr, 3.4.0);

ssize_t
pub_glfs_flistxattr(struct glfs_fd *glfd, void *value, size_t size)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    dict_t *xattr = NULL;
    fd_t *fd = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = syncop_fgetxattr(subvol, fd, &xattr, NULL, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);
    if (ret)
        goto out;

    ret = glfs_listxattr_process(value, size, xattr);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (xattr)
        dict_unref(xattr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_flistxattr, 3.4.0);

int
glfs_setxattr_common(struct glfs *fs, const char *path, const char *name,
                     const void *value, size_t size, int flags, int follow)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    dict_t *xattr = NULL;
    int reval = 0;
    void *value_cp = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    if (!name || *name == '\0') {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    if (strlen(name) > GF_XATTR_NAME_MAX) {
        ret = -1;
        errno = ENAMETOOLONG;
        goto out;
    }

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

retry:
    if (follow)
        ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);
    else
        ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    value_cp = gf_memdup(value, size);
    GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret,
                           "Failed to"
                           " duplicate setxattr value",
                           out);

    xattr = dict_for_key_value(name, value_cp, size, _gf_false);
    if (!xattr) {
        GF_FREE(value_cp);
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    ret = syncop_setxattr(subvol, &loc, xattr, flags, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

out:
    loc_wipe(&loc);
    if (xattr)
        dict_unref(xattr);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_setxattr(struct glfs *fs, const char *path, const char *name,
                  const void *value, size_t size, int flags)
{
    return glfs_setxattr_common(fs, path, name, value, size, flags, 1);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setxattr, 3.4.0);

int
pub_glfs_lsetxattr(struct glfs *fs, const char *path, const char *name,
                   const void *value, size_t size, int flags)
{
    return glfs_setxattr_common(fs, path, name, value, size, flags, 0);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lsetxattr, 3.4.0);

int
pub_glfs_fsetxattr(struct glfs_fd *glfd, const char *name, const void *value,
                   size_t size, int flags)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    dict_t *xattr = NULL;
    fd_t *fd = NULL;
    void *value_cp = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    if (!name || *name == '\0') {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    if (strlen(name) > GF_XATTR_NAME_MAX) {
        ret = -1;
        errno = ENAMETOOLONG;
        goto out;
    }

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    value_cp = gf_memdup(value, size);
    GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret,
                           "Failed to"
                           " duplicate setxattr value",
                           out);

    xattr = dict_for_key_value(name, value_cp, size, _gf_false);
    if (!xattr) {
        GF_FREE(value_cp);
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    ret = syncop_fsetxattr(subvol, fd, xattr, flags, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);
out:
    if (xattr)
        dict_unref(xattr);

    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsetxattr, 3.4.0);

int
glfs_removexattr_common(struct glfs *fs, const char *path, const char *name,
                        int follow)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    if (follow)
        ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);
    else
        ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    ret = syncop_removexattr(subvol, &loc, name, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_removexattr(struct glfs *fs, const char *path, const char *name)
{
    return glfs_removexattr_common(fs, path, name, 1);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_removexattr, 3.4.0);

int
pub_glfs_lremovexattr(struct glfs *fs, const char *path, const char *name)
{
    return glfs_removexattr_common(fs, path, name, 0);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lremovexattr, 3.4.0);

int
pub_glfs_fremovexattr(struct glfs_fd *glfd, const char *name)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = syncop_fremovexattr(subvol, fd, name, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fremovexattr, 3.4.0);

int
pub_glfs_fallocate(struct glfs_fd *glfd, int keep_size, off_t offset,
                   size_t len)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_fallocate(subvol, fd, keep_size, offset, len, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fallocate, 3.5.0);

int
pub_glfs_discard(struct glfs_fd *glfd, off_t offset, size_t len)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_discard(subvol, fd, offset, len, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_discard, 3.5.0);

int
pub_glfs_zerofill(struct glfs_fd *glfd, off_t offset, off_t len)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    dict_t *fop_attr = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        errno = EBADFD;
        goto out;
    }

    ret = get_fop_attr_thrd_key(&fop_attr);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_zerofill(subvol, fd, offset, len, fop_attr, NULL);
    DECODE_SYNCOP_ERR(ret);
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);
    if (fop_attr)
        dict_unref(fop_attr);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_zerofill, 3.5.0);

int
pub_glfs_chdir(struct glfs *fs, const char *path)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    if (!IA_ISDIR(iatt.ia_type)) {
        ret = -1;
        errno = ENOTDIR;
        goto out;
    }

    glfs_cwd_set(fs, loc.inode);

out:
    loc_wipe(&loc);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chdir, 3.4.0);

int
pub_glfs_fchdir(struct glfs_fd *glfd)
{
    int ret = -1;
    inode_t *inode = NULL;
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    inode = fd->inode;

    if (!IA_ISDIR(inode->ia_type)) {
        ret = -1;
        errno = ENOTDIR;
        goto out;
    }

    glfs_cwd_set(glfd->fs, inode);
    ret = 0;
out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchdir, 3.4.0);

static gf_boolean_t warn_realpath = _gf_true; /* log once */

static char *
glfs_realpath_common(struct glfs *fs, const char *path, char *resolved_path,
                     gf_boolean_t warn_deprecated)
{
    int ret = -1;
    char *retpath = NULL;
    char *allocpath = NULL;
    xlator_t *subvol = NULL;
    loc_t loc = {
        0,
    };
    struct iatt iatt = {
        0,
    };
    int reval = 0;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    if (resolved_path)
        retpath = resolved_path;
    else if (warn_deprecated) {
        retpath = allocpath = malloc(PATH_MAX + 1);
        if (warn_realpath) {
            warn_realpath = _gf_false;
            gf_log(THIS->name, GF_LOG_WARNING,
                   "this application "
                   "is compiled against an old version of "
                   "libgfapi, it should use glfs_free() to "
                   "release the path returned by "
                   "glfs_realpath()");
        }
    } else {
        retpath = allocpath = GLFS_CALLOC(1, PATH_MAX + 1, NULL,
                                          glfs_mt_realpath_t);
    }

    if (!retpath) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }
retry:
    ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval);

    ESTALE_RETRY(ret, errno, reval, &loc, retry);

    if (ret)
        goto out;

    if (loc.path) {
        snprintf(retpath, PATH_MAX + 1, "%s", loc.path);
    }

out:
    loc_wipe(&loc);

    if (ret == -1) {
        if (warn_deprecated && allocpath)
            free(allocpath);
        else if (allocpath)
            GLFS_FREE(allocpath);
        retpath = NULL;
    }

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return retpath;
}

char *
pub_glfs_realpath34(struct glfs *fs, const char *path, char *resolved_path)
{
    return glfs_realpath_common(fs, path, resolved_path, _gf_true);
}

GFAPI_SYMVER_PUBLIC(glfs_realpath34, glfs_realpath, 3.4.0);

char *
pub_glfs_realpath(struct glfs *fs, const char *path, char *resolved_path)
{
    return glfs_realpath_common(fs, path, resolved_path, _gf_false);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_realpath, 3.7.17);

char *
pub_glfs_getcwd(struct glfs *fs, char *buf, size_t n)
{
    int ret = -1;
    inode_t *inode = NULL;
    char *path = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    if (!buf || n < 2) {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    inode = glfs_cwd_get(fs);

    if (!inode) {
        strncpy(buf, "/", n);
        ret = 0;
        goto out;
    }

    ret = inode_path(inode, 0, &path);
    if (n <= ret) {
        ret = -1;
        errno = ERANGE;
        goto out;
    }

    strncpy(buf, path, n);
    ret = 0;
out:
    GF_FREE(path);

    if (inode)
        inode_unref(inode);

    __GLFS_EXIT_FS;

invalid_fs:
    if (ret < 0)
        return NULL;

    return buf;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_getcwd, 3.4.0);

static void
gf_flock_to_flock(struct gf_flock *gf_flock, struct flock *flock)
{
    flock->l_type = gf_flock->l_type;
    flock->l_whence = gf_flock->l_whence;
    flock->l_start = gf_flock->l_start;
    flock->l_len = gf_flock->l_len;
    flock->l_pid = gf_flock->l_pid;
}

static void
gf_flock_from_flock(struct gf_flock *gf_flock, struct flock *flock)
{
    gf_flock->l_type = flock->l_type;
    gf_flock->l_whence = flock->l_whence;
    gf_flock->l_start = flock->l_start;
    gf_flock->l_len = flock->l_len;
    gf_flock->l_pid = flock->l_pid;
}

static int
glfs_lock_common(struct glfs_fd *glfd, int cmd, struct flock *flock,
                 dict_t *xdata)
{
    int ret = -1;
    xlator_t *subvol = NULL;
    struct gf_flock gf_flock = {
        0,
    };
    struct gf_flock saved_flock = {
        0,
    };
    fd_t *fd = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    if (!flock) {
        errno = EINVAL;
        goto out;
    }

    GF_REF_GET(glfd);
    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    /* Generate glusterfs flock structure from client flock
     * structure to be processed by server */
    gf_flock_from_flock(&gf_flock, flock);

    /* Keep another copy of flock for split/merge of locks
     * at client side */
    gf_flock_from_flock(&saved_flock, flock);

    if (glfd->lk_owner.len != 0) {
        ret = syncopctx_setfslkowner(&glfd->lk_owner);

        if (ret)
            goto out;
    }

    ret = get_fop_attr_thrd_key(&xdata);
    if (ret)
        gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed");

    ret = syncop_lk(subvol, fd, cmd, &gf_flock, xdata, NULL);
    DECODE_SYNCOP_ERR(ret);

    /* Convert back from gf_flock to flock as expected by application */
    gf_flock_to_flock(&gf_flock, flock);

    if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) {
        ret = fd_lk_insert_and_merge(fd, cmd, &saved_flock);
        if (ret) {
            gf_smsg(THIS->name, GF_LOG_ERROR, 0,
                    API_MSG_LOCK_INSERT_MERGE_FAILED, "gfid=%s",
                    uuid_utoa(fd->inode->gfid), NULL);
            ret = 0;
        }
    }

out:
    if (fd)
        fd_unref(fd);
    if (glfd)
        GF_REF_PUT(glfd);

    glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

int
pub_glfs_file_lock(struct glfs_fd *glfd, int cmd, struct flock *flock,
                   glfs_lock_mode_t lk_mode)
{
    int ret = -1;
    dict_t *xdata_in = NULL;

    if (lk_mode == GLFS_LK_MANDATORY) {
        /* Create a new dictionary */
        xdata_in = dict_new();
        if (xdata_in == NULL) {
            ret = -1;
            errno = ENOMEM;
            goto out;
        }

        /* Set GF_LK_MANDATORY internally within dictionary to map
         * GLFS_LK_MANDATORY */
        ret = dict_set_uint32(xdata_in, GF_LOCK_MODE, GF_LK_MANDATORY);
        if (ret) {
            gf_smsg(THIS->name, GF_LOG_ERROR, 0,
                    API_MSG_SETTING_LOCK_TYPE_FAILED, NULL);
            ret = -1;
            errno = ENOMEM;
            goto out;
        }
    }

    ret = glfs_lock_common(glfd, cmd, flock, xdata_in);
out:
    if (xdata_in)
        dict_unref(xdata_in);

    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_file_lock, 4.0.0);

int
pub_glfs_posix_lock(struct glfs_fd *glfd, int cmd, struct flock *flock)
{
    return glfs_lock_common(glfd, cmd, flock, NULL);
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_posix_lock, 3.4.0);

int
pub_glfs_fd_set_lkowner(struct glfs_fd *glfd, void *data, int len)
{
    int ret = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    if (!GF_REF_GET(glfd)) {
        goto invalid_fs;
    }

    GF_VALIDATE_OR_GOTO(THIS->name, data, out);

    if ((len <= 0) || (len > GFAPI_MAX_LOCK_OWNER_LEN)) {
        errno = EINVAL;
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ARG,
                "lk_owner len=%d", len, NULL);
        goto out;
    }

    glfd->lk_owner.len = len;

    memcpy(glfd->lk_owner.data, data, len);

    ret = 0;
out:
    if (glfd)
        GF_REF_PUT(glfd);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fd_set_lkowner, 3.10.7);

struct glfs_fd *
pub_glfs_dup(struct glfs_fd *glfd)
{
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    struct glfs_fd *dupfd = NULL;
    struct glfs *fs = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    fs = glfd->fs;
    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(fs, subvol, glfd);
    if (!fd) {
        errno = EBADFD;
        goto out;
    }

    dupfd = glfs_fd_new(fs);
    if (!dupfd) {
        errno = ENOMEM;
        goto out;
    }

    dupfd->fd = fd_ref(fd);
    dupfd->state = glfd->state;
out:
    if (fd)
        fd_unref(fd);
    if (dupfd)
        glfs_fd_bind(dupfd);
    if (glfd)
        GF_REF_PUT(glfd);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return dupfd;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_dup, 3.4.0);

static void
glfs_enqueue_upcall_data(struct glfs *fs, struct gf_upcall *upcall_data)
{
    int ret = -1;
    upcall_entry *u_list = NULL;

    if (!fs || !upcall_data)
        goto out;

    u_list = GF_CALLOC(1, sizeof(*u_list), glfs_mt_upcall_entry_t);

    if (!u_list) {
        gf_smsg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, "entry",
                NULL);
        goto out;
    }

    INIT_LIST_HEAD(&u_list->upcall_list);

    gf_uuid_copy(u_list->upcall_data.gfid, upcall_data->gfid);
    u_list->upcall_data.event_type = upcall_data->event_type;

    switch (upcall_data->event_type) {
        case GF_UPCALL_CACHE_INVALIDATION:
            ret = glfs_get_upcall_cache_invalidation(&u_list->upcall_data,
                                                     upcall_data);
            break;
        case GF_UPCALL_RECALL_LEASE:
            ret = glfs_get_upcall_lease(&u_list->upcall_data, upcall_data);
            break;
        default:
            break;
    }

    if (ret) {
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ENTRY, NULL);
        goto out;
    }

    pthread_mutex_lock(&fs->upcall_list_mutex);
    {
        list_add_tail(&u_list->upcall_list, &fs->upcall_list);
    }
    pthread_mutex_unlock(&fs->upcall_list_mutex);

    ret = 0;

out:
    if (ret && u_list) {
        GF_FREE(u_list->upcall_data.data);
        GF_FREE(u_list);
    }
}

static void
glfs_free_upcall_lease(void *to_free)
{
    struct glfs_upcall_lease *arg = to_free;

    if (!arg)
        return;

    if (arg->object)
        glfs_h_close(arg->object);

    GF_FREE(arg);
}

int
glfs_recall_lease_fd(struct glfs *fs, struct gf_upcall *up_data)
{
    struct gf_upcall_recall_lease *recall_lease = NULL;
    xlator_t *subvol = NULL;
    int ret = 0;
    inode_t *inode = NULL;
    struct glfs_fd *glfd = NULL;
    struct glfs_fd *tmp = NULL;
    struct list_head glfd_list;
    fd_t *fd = NULL;
    uint64_t value = 0;
    struct glfs_lease lease = {
        0,
    };

    GF_VALIDATE_OR_GOTO("gfapi", up_data, out);
    GF_VALIDATE_OR_GOTO("gfapi", fs, out);

    recall_lease = up_data->data;
    GF_VALIDATE_OR_GOTO("gfapi", recall_lease, out);

    INIT_LIST_HEAD(&glfd_list);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    gf_msg_debug(THIS->name, 0, "Recall lease received for gfid:%s",
                 uuid_utoa(up_data->gfid));

    inode = inode_find(subvol->itable, up_data->gfid);
    if (!inode) {
        ret = -1;
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INODE_FIND_FAILED,
                "gfid=%s", uuid_utoa(up_data->gfid), "graph_id=%d",
                subvol->graph->id, NULL);
        goto out;
    }

    LOCK(&inode->lock);
    {
        list_for_each_entry(fd, &inode->fd_list, inode_list)
        {
            ret = fd_ctx_get(fd, subvol, &value);
            glfd = (struct glfs_fd *)(uintptr_t)value;
            if (glfd) {
                gf_msg_trace(THIS->name, 0, "glfd (%p) has held lease", glfd);
                GF_REF_GET(glfd);
                list_add_tail(&glfd->list, &glfd_list);
            }
        }
    }
    UNLOCK(&inode->lock);

    if (!list_empty(&glfd_list)) {
        list_for_each_entry_safe(glfd, tmp, &glfd_list, list)
        {
            LOCK(&glfd->lock);
            {
                if (glfd->state != GLFD_CLOSE) {
                    gf_msg_trace(THIS->name, 0,
                                 "glfd (%p) has held lease, "
                                 "calling recall cbk",
                                 glfd);
                    glfd->cbk(lease, glfd->cookie);
                }
            }
            UNLOCK(&glfd->lock);

            list_del_init(&glfd->list);
            GF_REF_PUT(glfd);
        }
    }

out:
    return ret;
}

static int
glfs_recall_lease_upcall(struct glfs *fs, struct glfs_upcall *up_arg,
                         struct gf_upcall *up_data)
{
    struct gf_upcall_recall_lease *recall_lease = NULL;
    struct glfs_object *object = NULL;
    xlator_t *subvol = NULL;
    int ret = -1;
    struct glfs_upcall_lease *up_lease_arg = NULL;

    GF_VALIDATE_OR_GOTO("gfapi", up_data, out);
    GF_VALIDATE_OR_GOTO("gfapi", fs, out);

    recall_lease = up_data->data;
    GF_VALIDATE_OR_GOTO("gfapi", recall_lease, out);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        errno = EIO;
        goto out;
    }

    gf_msg_debug(THIS->name, 0, "Recall lease received for gfid:%s",
                 uuid_utoa(up_data->gfid));

    object = glfs_h_find_handle(fs, up_data->gfid, GFAPI_HANDLE_LENGTH);
    if (!object) {
        /* The reason handle creation will fail is because we
         * couldn't find the inode in the gfapi inode table.
         *
         * But since application would have taken inode_ref, the
         * only case when this can happen is when it has closed
         * the handle and hence will no more be interested in
         * the upcall for this particular gfid.
         */
        gf_smsg(THIS->name, GF_LOG_DEBUG, errno, API_MSG_CREATE_HANDLE_FAILED,
                "gfid=%s", uuid_utoa(up_data->gfid), NULL);
        errno = ESTALE;
        goto out;
    }

    up_lease_arg = GF_CALLOC(1, sizeof(struct glfs_upcall_lease),
                             glfs_mt_upcall_inode_t);
    up_lease_arg->object = object;

    GF_VALIDATE_OR_GOTO("glfs_recall_lease", up_lease_arg, out);

    up_lease_arg->lease_type = recall_lease->lease_type;

    up_arg->reason = GLFS_UPCALL_RECALL_LEASE;
    up_arg->event = up_lease_arg;
    up_arg->free_event = glfs_free_upcall_lease;

    ret = 0;

out:
    if (ret) {
        /* Close p_object and oldp_object as well if being referenced.*/
        if (object)
            glfs_h_close(object);

        /* Set reason to prevent applications from using ->event */
        up_arg->reason = GF_UPCALL_EVENT_NULL;
    }
    return ret;
}

static int
upcall_syncop_args_free(struct upcall_syncop_args *args)
{
    dict_t *dict = NULL;
    struct gf_upcall *upcall_data = NULL;

    if (args) {
        upcall_data = &args->upcall_data;
        switch (upcall_data->event_type) {
            case GF_UPCALL_CACHE_INVALIDATION:
                dict = ((struct gf_upcall_cache_invalidation *)(upcall_data
                                                                    ->data))
                           ->dict;
                break;
            case GF_UPCALL_RECALL_LEASE:
                dict = ((struct gf_upcall_recall_lease *)(upcall_data->data))
                           ->dict;
                break;
        }
        if (dict)
            dict_unref(dict);

        GF_FREE(upcall_data->client_uid);
        GF_FREE(upcall_data->data);
    }
    GF_FREE(args);
    return 0;
}

static int
glfs_upcall_syncop_cbk(int ret, call_frame_t *frame, void *opaque)
{
    struct upcall_syncop_args *args = opaque;

    (void)upcall_syncop_args_free(args);

    return 0;
}

static int
glfs_cbk_upcall_syncop(void *opaque)
{
    struct upcall_syncop_args *args = opaque;
    struct gf_upcall *upcall_data = NULL;
    struct glfs_upcall *up_arg = NULL;
    struct glfs *fs;
    int ret = -1;

    fs = args->fs;
    upcall_data = &args->upcall_data;

    if (!upcall_data) {
        goto out;
    }

    up_arg = GLFS_CALLOC(1, sizeof(struct gf_upcall), glfs_release_upcall,
                         glfs_mt_upcall_entry_t);
    if (!up_arg) {
        gf_smsg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, "entry",
                NULL);
        goto out;
    }

    switch (upcall_data->event_type) {
        case GF_UPCALL_CACHE_INVALIDATION:
            ret = glfs_h_poll_cache_invalidation(fs, up_arg, upcall_data);
            break;
        case GF_UPCALL_RECALL_LEASE:
            ret = glfs_recall_lease_upcall(fs, up_arg, upcall_data);
            break;
        default:
            errno = EINVAL;
    }

    /* It could so happen that the file which got
     * upcall notification may have got deleted by
     * the same client. In such cases up_arg->reason
     * is set to GLFS_UPCALL_EVENT_NULL. No need to
     * send upcall then
     */
    if (up_arg->reason == GLFS_UPCALL_EVENT_NULL) {
        gf_smsg(THIS->name, GF_LOG_DEBUG, errno,
                API_MSG_UPCALL_EVENT_NULL_RECEIVED, NULL);
        ret = 0;
        GLFS_FREE(up_arg);
        goto out;
    } else if (ret) {
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ENTRY, NULL);
        goto out;
    }

    if (fs->up_cbk && up_arg)
        (fs->up_cbk)(up_arg, fs->up_data);

    /* application takes care of calling glfs_free on up_arg post
     * their processing */

out:
    return ret;
}

static struct gf_upcall_cache_invalidation *
gf_copy_cache_invalidation(struct gf_upcall_cache_invalidation *src)
{
    struct gf_upcall_cache_invalidation *dst = NULL;

    if (!src)
        goto out;

    dst = GF_CALLOC(1, sizeof(struct gf_upcall_cache_invalidation),
                    glfs_mt_upcall_entry_t);

    if (!dst) {
        gf_smsg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, "entry",
                NULL);
        goto out;
    }

    dst->flags = src->flags;
    dst->expire_time_attr = src->expire_time_attr;
    dst->stat = src->stat;
    dst->p_stat = src->p_stat;
    dst->oldp_stat = src->oldp_stat;

    if (src->dict)
        dst->dict = dict_copy_with_ref(src->dict, NULL);

    return dst;
out:
    return NULL;
}

static struct gf_upcall_recall_lease *
gf_copy_recall_lease(struct gf_upcall_recall_lease *src)
{
    struct gf_upcall_recall_lease *dst = NULL;

    if (!src)
        goto out;

    dst = GF_CALLOC(1, sizeof(struct gf_upcall_recall_lease),
                    glfs_mt_upcall_entry_t);

    if (!dst) {
        gf_smsg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, "entry",
                NULL);
        goto out;
    }

    dst->lease_type = src->lease_type;
    memcpy(dst->tid, src->tid, 16);

    if (src->dict)
        dst->dict = dict_copy_with_ref(src->dict, NULL);

    return dst;
out:
    return NULL;
}

static struct upcall_syncop_args *
upcall_syncop_args_init(struct glfs *fs, struct gf_upcall *upcall_data)
{
    struct upcall_syncop_args *args = NULL;
    int ret = -1;
    struct gf_upcall *t_data = NULL;

    if (!fs || !upcall_data)
        goto out;

    args = GF_CALLOC(1, sizeof(struct upcall_syncop_args),
                     glfs_mt_upcall_entry_t);
    if (!args) {
        gf_smsg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED,
                "syncop args", NULL);
        goto out;
    }

    /* Note: we are not taking any ref on fs here.
     * Ideally applications have to unregister for upcall events
     * or stop polling for upcall events before performing
     * glfs_fini. And as for outstanding synctasks created, we wait
     * for all syncenv threads to finish tasks before cleaning up the
     * fs->ctx. Hence it seems safe to process these callback
     * notification without taking any lock/ref.
     */
    args->fs = fs;
    t_data = &(args->upcall_data);
    t_data->client_uid = gf_strdup(upcall_data->client_uid);

    gf_uuid_copy(t_data->gfid, upcall_data->gfid);
    t_data->event_type = upcall_data->event_type;

    switch (t_data->event_type) {
        case GF_UPCALL_CACHE_INVALIDATION:
            t_data->data = gf_copy_cache_invalidation(
                (struct gf_upcall_cache_invalidation *)upcall_data->data);
            break;
        case GF_UPCALL_RECALL_LEASE:
            t_data->data = gf_copy_recall_lease(
                (struct gf_upcall_recall_lease *)upcall_data->data);
            break;
    }

    if (!t_data->data)
        goto out;

    return args;
out:
    if (ret) {
        if (args) {
            GF_FREE(args->upcall_data.client_uid);
            GF_FREE(args);
        }
    }

    return NULL;
}

static void
glfs_cbk_upcall_data(struct glfs *fs, struct gf_upcall *upcall_data)
{
    struct upcall_syncop_args *args = NULL;
    int ret = -1;

    if (!fs || !upcall_data)
        goto out;

    if (!(fs->upcall_events & upcall_data->event_type)) {
        /* ignore events which application hasn't registered*/
        goto out;
    }

    args = upcall_syncop_args_init(fs, upcall_data);

    if (!args)
        goto out;

    ret = synctask_new(THIS->ctx->env, glfs_cbk_upcall_syncop,
                       glfs_upcall_syncop_cbk, NULL, args);
    /* should we retry incase of failure? */
    if (ret) {
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_UPCALL_SYNCOP_FAILED,
                "event_type=%d", upcall_data->event_type, "gfid=%s",
                (char *)(upcall_data->gfid), NULL);
        upcall_syncop_args_free(args);
    }

out:
    return;
}

/*
 * This routine is called in case of any notification received
 * from the server. All the upcall events are queued up in a list
 * to be read by the applications.
 *
 * In case if the application registers a cbk function, that shall
 * be called by this routine in case of any event received.
 * The cbk fn is responsible for notifying the
 * applications the way it desires for each event queued (for eg.,
 * can raise a signal or broadcast a cond variable etc.)
 *
 * Otherwise all the upcall events are queued up in a list
 * to be read/polled by the applications.
 */
void
priv_glfs_process_upcall_event(struct glfs *fs, void *data)
{
    glusterfs_ctx_t *ctx = NULL;
    struct gf_upcall *upcall_data = NULL;

    DECLARE_OLD_THIS;

    gf_msg_debug(THIS->name, 0, "Upcall gfapi callback is called");

    __GLFS_ENTRY_VALIDATE_FS(fs, err);

    if (!data)
        goto out;

    /* Unlike in I/O path, "glfs_fini" would not have freed
     * 'fs' by the time we take lock as it waits for all epoll
     * threads to exit including this
     */
    pthread_mutex_lock(&fs->mutex);
    {
        ctx = fs->ctx;

        /* if we're not interested in upcalls (anymore), skip them */
        if (ctx->cleanup_started || !fs->cache_upcalls) {
            pthread_mutex_unlock(&fs->mutex);
            goto out;
        }

        fs->pin_refcnt++;
    }
    pthread_mutex_unlock(&fs->mutex);

    upcall_data = (struct gf_upcall *)data;

    gf_msg_trace(THIS->name, 0, "Upcall gfapi gfid = %s",
                 (char *)(upcall_data->gfid));

    /* *
     * TODO: RECALL LEASE for each glfd
     *
     * In case of RECALL_LEASE, we could associate separate
     * cbk function for each glfd either by
     * - extending pub_glfs_lease to accept new args (recall_cbk_fn, cookie)
     * - or by defining new API "glfs_register_recall_cbk_fn (glfd,
     * recall_cbk_fn, cookie) . In such cases, flag it and instead of calling
     * below upcall functions, define a new one to go through the glfd list and
     * invoke each of theirs recall_cbk_fn.
     * */

    if (fs->up_cbk) { /* upcall cbk registered */
        (void)glfs_cbk_upcall_data(fs, upcall_data);
    } else {
        (void)glfs_enqueue_upcall_data(fs, upcall_data);
    }

    pthread_mutex_lock(&fs->mutex);
    {
        fs->pin_refcnt--;
    }
    pthread_mutex_unlock(&fs->mutex);

out:
    __GLFS_EXIT_FS;
err:
    return;
}
GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_process_upcall_event, 3.7.0);

ssize_t
glfs_anonymous_pwritev(struct glfs *fs, struct glfs_object *object,
                       const struct iovec *iovec, int iovcnt, off_t offset,
                       int flags)
{
    xlator_t *subvol = NULL;
    struct iobref *iobref = NULL;
    struct iobuf *iobuf = NULL;
    struct iovec iov = {
        0,
    };
    inode_t *inode = NULL;
    fd_t *fd = NULL;
    int ret = -1;
    size_t size = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    /* get/refresh the in arg objects inode in correlation to the xlator */
    inode = glfs_resolve_inode(fs, subvol, object);
    if (!inode) {
        ret = -1;
        errno = ESTALE;
        goto out;
    }

    fd = fd_anonymous(inode);
    if (!fd) {
        ret = -1;
        gf_smsg("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, NULL);
        errno = ENOMEM;
        goto out;
    }

    size = iov_length(iovec, iovcnt);

    iobuf = iobuf_get2(subvol->ctx->iobuf_pool, size);
    if (!iobuf) {
        ret = -1;
        errno = ENOMEM;
        goto out;
    }

    iobref = iobref_new();
    if (!iobref) {
        iobuf_unref(iobuf);
        errno = ENOMEM;
        ret = -1;
        goto out;
    }

    ret = iobref_add(iobref, iobuf);
    if (ret) {
        iobuf_unref(iobuf);
        iobref_unref(iobref);
        errno = ENOMEM;
        ret = -1;
        goto out;
    }

    iov_unload(iobuf_ptr(iobuf), iovec, iovcnt);

    iov.iov_base = iobuf_ptr(iobuf);
    iov.iov_len = size;

    /* TODO : set leaseid */
    ret = syncop_writev(subvol, fd, &iov, 1, offset, iobref, flags, NULL, NULL,
                        NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    iobuf_unref(iobuf);
    iobref_unref(iobref);

    if (ret <= 0)
        goto out;

out:

    if (fd)
        fd_unref(fd);

    if (inode)
        inode_unref(inode);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

ssize_t
glfs_anonymous_preadv(struct glfs *fs, struct glfs_object *object,
                      const struct iovec *iovec, int iovcnt, off_t offset,
                      int flags)
{
    xlator_t *subvol = NULL;
    struct iovec *iov = NULL;
    struct iobref *iobref = NULL;
    inode_t *inode = NULL;
    fd_t *fd = NULL;
    int cnt = 0;
    ssize_t ret = -1;
    ssize_t size = -1;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);

    subvol = glfs_active_subvol(fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    /* get/refresh the in arg objects inode in correlation to the xlator */
    inode = glfs_resolve_inode(fs, subvol, object);
    if (!inode) {
        ret = -1;
        errno = ESTALE;
        goto out;
    }

    fd = fd_anonymous(inode);
    if (!fd) {
        ret = -1;
        gf_smsg("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, NULL);
        errno = ENOMEM;
        goto out;
    }

    size = iov_length(iovec, iovcnt);

    /* TODO : set leaseid */
    ret = syncop_readv(subvol, fd, size, offset, flags, &iov, &cnt, &iobref,
                       NULL, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);
    if (ret <= 0)
        goto out;

    size = iov_copy(iovec, iovcnt, iov, cnt);

    ret = size;
out:
    if (iov)
        GF_FREE(iov);
    if (iobref)
        iobref_unref(iobref);
    if (fd)
        fd_unref(fd);

    if (inode)
        inode_unref(inode);

    glfs_subvol_done(fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

static void
glfs_release_xreaddirp_stat(void *ptr)
{
    struct glfs_xreaddirp_stat *to_free = ptr;

    if (to_free->object)
        glfs_h_close(to_free->object);
}

/*
 * Given glfd of a directory, this function does readdirp and returns
 * xstat along with dirents.
 */
int
pub_glfs_xreaddirplus_r(struct glfs_fd *glfd, uint32_t flags,
                        struct glfs_xreaddirp_stat **xstat_p,
                        struct dirent *ext, struct dirent **res)
{
    int ret = -1;
    gf_dirent_t *entry = NULL;
    struct dirent *buf = NULL;
    struct glfs_xreaddirp_stat *xstat = NULL;

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    GF_VALIDATE_OR_GOTO(THIS->name, xstat_p, out);
    GF_VALIDATE_OR_GOTO(THIS->name, res, out);

    errno = 0;

    if (ext)
        buf = ext;
    else
        buf = glfs_readdirbuf_get(glfd);

    if (!buf)
        goto out;

    xstat = GLFS_CALLOC(1, sizeof(struct glfs_xreaddirp_stat),
                        glfs_release_xreaddirp_stat, glfs_mt_xreaddirp_stat_t);

    if (!xstat)
        goto out;

    /* this is readdirplus operation */
    entry = glfd_entry_next(glfd, 1);

    /* XXX: Ideally when we reach EOD, errno should have been
     * set to ENOENT. But that doesn't seem to be the case.
     *
     * The only way to confirm if its EOD at this point is that
     * errno == 0 and entry == NULL
     */
    if (errno)
        goto out;

    if (!entry) {
        /* reached EOD, ret = 0  */
        ret = 0;
        *res = NULL;
        *xstat_p = NULL;

        /* free xstat as applications shall not be using it */
        GLFS_FREE(xstat);

        goto out;
    }

    *res = buf;
    gf_dirent_to_dirent(entry, buf);

    if (flags & GFAPI_XREADDIRP_STAT) {
        glfs_iatt_to_stat(glfd->fs, &entry->d_stat, &xstat->st);
        xstat->flags_handled |= GFAPI_XREADDIRP_STAT;
    }

    if ((flags & GFAPI_XREADDIRP_HANDLE) &&
        /* skip . and .. */
        strcmp(buf->d_name, ".") && strcmp(buf->d_name, "..")) {
        /* Now create object.
         * We can use "glfs_h_find_handle" as well as inodes would have
         * already got linked as part of 'gf_link_inodes_from_dirent' */
        xstat->object = glfs_h_create_from_handle(
            glfd->fs, entry->d_stat.ia_gfid, GFAPI_HANDLE_LENGTH, NULL);

        if (xstat->object) { /* success */
            /* note: xstat->object->inode->ref is taken
             * This shall be unref'ed when application does
             * glfs_free(xstat) */
            xstat->flags_handled |= GFAPI_XREADDIRP_HANDLE;
        }
    }

    ret = xstat->flags_handled;
    *xstat_p = xstat;

    gf_msg_debug(THIS->name, 0,
                 "xreaddirp- requested_flags (%x) , processed_flags (%x)",
                 flags, xstat->flags_handled);

out:
    GF_REF_PUT(glfd);

    if (ret < 0) {
        gf_smsg(THIS->name, GF_LOG_WARNING, errno, API_MSG_XREADDIRP_R_FAILED,
                "reason=%s", strerror(errno), NULL);

        if (xstat)
            GLFS_FREE(xstat);
    }

    __GLFS_EXIT_FS;

    return ret;

invalid_fs:
    return -1;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_xreaddirplus_r, 3.11.0);

struct stat *
pub_glfs_xreaddirplus_get_stat(struct glfs_xreaddirp_stat *xstat)
{
    GF_VALIDATE_OR_GOTO("glfs_xreaddirplus_get_stat", xstat, out);

    if (!xstat->flags_handled & GFAPI_XREADDIRP_STAT)
        gf_smsg(THIS->name, GF_LOG_ERROR, errno, API_MSG_FLAGS_HANDLE,
                "GFAPI_XREADDIRP_STAT"
                "xstat=%p",
                xstat, "handles=%x", xstat->flags_handled, NULL);
    return &xstat->st;

out:
    return NULL;
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_xreaddirplus_get_stat, 3.11.0);

void
gf_lease_to_glfs_lease(struct gf_lease *gf_lease, struct glfs_lease *lease)
{
    u_int lease_type = gf_lease->lease_type;
    lease->cmd = gf_lease->cmd;
    lease->lease_type = lease_type;
    memcpy(lease->lease_id, gf_lease->lease_id, LEASE_ID_SIZE);
}

void
glfs_lease_to_gf_lease(struct glfs_lease *lease, struct gf_lease *gf_lease)
{
    u_int lease_type = lease->lease_type;
    gf_lease->cmd = lease->cmd;
    gf_lease->lease_type = lease_type;
    memcpy(gf_lease->lease_id, lease->lease_id, LEASE_ID_SIZE);
}

int
pub_glfs_lease(struct glfs_fd *glfd, struct glfs_lease *lease,
               glfs_recall_cbk fn, void *data)
{
    int ret = -1;
    loc_t loc = {
        0,
    };
    xlator_t *subvol = NULL;
    fd_t *fd = NULL;
    struct gf_lease gf_lease = {
        0,
    };

    DECLARE_OLD_THIS;
    __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs);

    GF_REF_GET(glfd);

    if (!is_valid_lease_id(lease->lease_id)) {
        ret = -1;
        errno = EINVAL;
        goto out;
    }

    subvol = glfs_active_subvol(glfd->fs);
    if (!subvol) {
        ret = -1;
        errno = EIO;
        goto out;
    }

    fd = glfs_resolve_fd(glfd->fs, subvol, glfd);
    if (!fd) {
        ret = -1;
        errno = EBADFD;
        goto out;
    }

    switch (lease->lease_type) {
        case GLFS_RD_LEASE:
            if ((fd->flags != O_RDONLY) && !(fd->flags & O_RDWR)) {
                ret = -1;
                errno = EINVAL;
                goto out;
            }
            break;
        case GLFS_RW_LEASE:
            if (!((fd->flags & O_WRONLY) || (fd->flags & O_RDWR))) {
                ret = -1;
                errno = EINVAL;
                goto out;
            }
            break;
        default:
            if (lease->cmd != GLFS_GET_LEASE) {
                ret = -1;
                errno = EINVAL;
                goto out;
            }
            break;
    }

    /* populate loc */
    GLFS_LOC_FILL_INODE(fd->inode, loc, out);

    glfs_lease_to_gf_lease(lease, &gf_lease);

    ret = syncop_lease(subvol, &loc, &gf_lease, NULL, NULL);
    DECODE_SYNCOP_ERR(ret);

    gf_lease_to_glfs_lease(&gf_lease, lease);

    /* TODO: Add leases for client replay
    if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW))
            fd_lk_insert_and_merge (fd, cmd, &saved_flock);
    */
    if (ret == 0) {
        ret = fd_ctx_set(glfd->fd, subvol, (uint64_t)(long)glfd);
        if (ret) {
            gf_smsg(subvol->name, GF_LOG_ERROR, ENOMEM,
                    API_MSG_FDCTX_SET_FAILED, "fd=%p", glfd->fd, NULL);
            goto out;
        }
        glfd->cbk = fn;
        glfd->cookie = data;
    }

out:

    if (glfd)
        GF_REF_PUT(glfd);

    if (subvol)
        glfs_subvol_done(glfd->fs, subvol);

    __GLFS_EXIT_FS;

invalid_fs:
    return ret;
}

GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lease, 4.0.0);