From f7a815a2d0e7e9d7ed1ec2da587790bd3ddda9e5 Mon Sep 17 00:00:00 2001 From: Justin Clift Date: Fri, 21 Mar 2014 20:13:16 +0000 Subject: features/glupy: Rename Glupy python module to avoid namespace conflict * Rename gluster.py to glupy.py to avoid namespace conflict (#1018619) * Move the main Glupy files into glusterfs-extra-xlators rpm * Move the Glupy Translator examples into glusterfs-devel rpm * Add Glupy entry to the MAINTAINERS file BUG: 1018619 Change-Id: I48de598ba5ae8eec0e7e276bbcca1abb0e549cef Signed-off-by: Justin Clift Reviewed-on: http://review.gluster.org/6979 Reviewed-by: Kaleb KEITHLEY Reviewed-by: Jeff Darcy --- .gitignore | 4 +- MAINTAINERS | 5 + api/examples/Makefile.am | 6 +- api/examples/__init__.py.in | 1 + api/examples/setup.py.in | 5 - configure.ac | 3 + glusterfs.spec.in | 61 +- xlators/features/glupy/Makefile.am | 2 +- xlators/features/glupy/examples/Makefile.am | 5 + xlators/features/glupy/examples/debug-trace.py | 775 +++++++++++++++++++++++ xlators/features/glupy/examples/helloworld.py | 19 + xlators/features/glupy/examples/negative.py | 91 +++ xlators/features/glupy/src/Makefile.am | 13 +- xlators/features/glupy/src/debug-trace.py | 774 ----------------------- xlators/features/glupy/src/glupy.c | 5 +- xlators/features/glupy/src/glupy.py | 841 +++++++++++++++++++++++++ xlators/features/glupy/src/gluster.py | 841 ------------------------- xlators/features/glupy/src/helloworld.py | 19 - xlators/features/glupy/src/negative.py | 92 --- xlators/features/glupy/src/setup.py.in | 24 + 20 files changed, 1843 insertions(+), 1743 deletions(-) create mode 100644 api/examples/__init__.py.in create mode 100644 xlators/features/glupy/examples/Makefile.am create mode 100644 xlators/features/glupy/examples/debug-trace.py create mode 100644 xlators/features/glupy/examples/helloworld.py create mode 100644 xlators/features/glupy/examples/negative.py delete mode 100644 xlators/features/glupy/src/debug-trace.py create mode 100644 xlators/features/glupy/src/glupy.py delete mode 100644 xlators/features/glupy/src/gluster.py delete mode 100644 xlators/features/glupy/src/helloworld.py delete mode 100644 xlators/features/glupy/src/negative.py create mode 100644 xlators/features/glupy/src/setup.py.in diff --git a/.gitignore b/.gitignore index e8d0012aa06..08bd0dae27b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,8 @@ Makefile stamp-h1 # Generated files -api/examples/__init__.py* +api/examples/__init__.py +api/examples/__init__.py? api/examples/setup.py argp-standalone/libargp.a contrib/uuid/uuid_types.h @@ -48,5 +49,6 @@ libtool run-tests.sh xlators/mount/fuse/utils/mount.glusterfs xlators/mount/fuse/utils/mount_glusterfs +xlators/features/glupy/src/setup.py geo-replication/src/peer_add_secret_pub geo-replication/src/peer_gsec_create diff --git a/MAINTAINERS b/MAINTAINERS index 57f7deb59d1..49c7c343164 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -119,6 +119,11 @@ M: Venky Shankar S: Maintained F: geo-replication/ +Glupy +M: Justin Clift +S: Maintained +F: xlators/features/glupy/ + libgfapi M: Anand Avati S: Maintained diff --git a/api/examples/Makefile.am b/api/examples/Makefile.am index 05f40ff53ed..f1a8d12b29e 100644 --- a/api/examples/Makefile.am +++ b/api/examples/Makefile.am @@ -1,6 +1,10 @@ +# The bits needed for glfsxmp EXTRA_PROGRAMS = glfsxmp glfsxmp_SOURCES = glfsxmp.c glfsxmp_CFLAGS = $(GLFS_CFLAGS) -Wall glfsxmp_LDADD = $(GLFS_LIBS) -lrt -EXTRA_DIST = gfapi.py +# Install __init__.py (a generated file), and gfapi.py into +# the Python site-packages area +pygfapidir = $(pythondir)/gluster +pygfapi_PYTHON = __init__.py gfapi.py diff --git a/api/examples/__init__.py.in b/api/examples/__init__.py.in new file mode 100644 index 00000000000..280beb2dcec --- /dev/null +++ b/api/examples/__init__.py.in @@ -0,0 +1 @@ +__version__ = "@PACKAGE_VERSION@" diff --git a/api/examples/setup.py.in b/api/examples/setup.py.in index 44b73809486..f22fa1f3099 100644 --- a/api/examples/setup.py.in +++ b/api/examples/setup.py.in @@ -1,10 +1,5 @@ from distutils.core import setup -# generate a __init__.py for the package namespace -fo = open('__init__.py', 'w') -fo.write('__version__ = "@PACKAGE_VERSION@"\n') -fo.close() - DESC = """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. diff --git a/configure.ac b/configure.ac index d3f5c1b1883..3a3d8712bc8 100644 --- a/configure.ac +++ b/configure.ac @@ -104,7 +104,9 @@ AC_CONFIG_FILES([Makefile xlators/features/changelog/lib/Makefile xlators/features/changelog/lib/src/Makefile xlators/features/glupy/Makefile + xlators/features/glupy/examples/Makefile xlators/features/glupy/src/Makefile + xlators/features/glupy/src/setup.py xlators/features/locks/Makefile xlators/features/locks/src/Makefile xlators/features/quota/Makefile @@ -178,6 +180,7 @@ AC_CONFIG_FILES([Makefile api/Makefile api/src/Makefile api/examples/Makefile + api/examples/__init__.py api/examples/setup.py geo-replication/Makefile geo-replication/src/Makefile diff --git a/glusterfs.spec.in b/glusterfs.spec.in index f3038eaa40d..5c4f74af44c 100644 --- a/glusterfs.spec.in +++ b/glusterfs.spec.in @@ -347,6 +347,25 @@ is in user space and easily manageable. This package provides the glusterfs libgfapi library. +%package extra-xlators +Summary: Extra Gluster filesystem Translators +Group: Applications/File +# We need -api rpm for its __init__.py in Python site-packages area +Requires: %{name}-api = %{version}-%{release} +Requires: python python-ctypes + +%description extra-xlators +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 extra filesystem Translators, such as Glupy, +for GlusterFS. + %if ( 0%{!?_without_ocf:1} ) %package resource-agents Summary: OCF Resource Agents for GlusterFS @@ -384,6 +403,8 @@ like Pacemaker. Summary: Development Libraries Group: Development/Libraries Requires: %{name} = %{version}-%{release} +# Needed for the Glupy examples to work +Requires: %{name}-extra-xlators = %{version}-%{release} %description devel GlusterFS is a clustered file-system capable of scaling to several @@ -451,6 +472,12 @@ sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|' libtool make %{?_smp_mflags} +# Build Glupy +pushd xlators/features/glupy/src +FLAGS="$RPM_OPT_FLAGS" python setup.py build +popd + +# Build the Python libgfapi examples pushd api/examples FLAGS="$RPM_OPT_FLAGS" python setup.py build popd @@ -458,6 +485,10 @@ popd %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} +# install the Glupy Python library in /usr/lib/python*/site-packages +pushd xlators/features/glupy/src +python setup.py install --skip-build --verbose --root %{buildroot} +popd # install the gfapi Python library in /usr/lib/python*/site-packages pushd api/examples python setup.py install --skip-build --verbose --root %{buildroot} @@ -669,6 +700,8 @@ rm -rf %{buildroot} %exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/protocol/server* %exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/mgmt* %exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/nfs* +# Glupy files are in the -extra-xlators package +%exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/glupy* # sample xlators not generally used or usable %exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/encryption/rot-13* %exclude %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/mac-compat* @@ -806,9 +839,26 @@ fi %files api %exclude %{_libdir}/*.so +# Shared Python-GlusterFS files +%{python_sitelib}/gluster/__init__.* +# Libgfapi files %{_libdir}/libgfapi.* %{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/mount/api* -%{python_sitelib}/* +%{python_sitelib}/gluster/gfapi.* +# Don't expect a .egg-info file on EL5 +%if ( 0%{?rhel} && 0%{?rhel} > 5 ) || ( 0%{?fedora} ) +%{python_sitelib}/glusterfs_api*.egg-info +%endif + +%files extra-xlators +# Glupy C shared library +%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/glupy.so +# Glupy Python files +%{python_sitelib}/gluster/glupy.* +# Don't expect a .egg-info file on EL5 +%if ( 0%{?rhel} && 0%{?rhel} > 5 ) || ( 0%{?fedora} ) +%{python_sitelib}/glusterfs_glupy*.egg-info +%endif %if ( 0%{!?_without_ocf:1} ) %files resource-agents @@ -822,6 +872,10 @@ fi %exclude %{_includedir}/glusterfs/api %exclude %{_libdir}/libgfapi.so %{_libdir}/*.so +# Glupy Translator examples +%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/glupy/debug-trace.* +%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/glupy/helloworld.* +%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/features/glupy/negative.* %files api-devel %{_libdir}/pkgconfig/glusterfs-api.pc @@ -899,6 +953,11 @@ fi * Wed Feb 26 2014 Niels de Vos - Drop glusterfs-devel dependency from glusterfs-api (#1065750) +* Wed Feb 19 2014 Justin Clift +- Rename gluster.py to glupy.py to avoid namespace conflict (#1018619) +- Move the main Glupy files into glusterfs-extra-xlators rpm +- Move the Glupy Translator examples into glusterfs-devel rpm + * Thu Feb 06 2014 Aravinda VK - Include geo-replication upgrade scripts and hook scripts. diff --git a/xlators/features/glupy/Makefile.am b/xlators/features/glupy/Makefile.am index a985f42a877..060429ecf0f 100644 --- a/xlators/features/glupy/Makefile.am +++ b/xlators/features/glupy/Makefile.am @@ -1,3 +1,3 @@ -SUBDIRS = src +SUBDIRS = src examples CLEANFILES = diff --git a/xlators/features/glupy/examples/Makefile.am b/xlators/features/glupy/examples/Makefile.am new file mode 100644 index 00000000000..c26abeaafb6 --- /dev/null +++ b/xlators/features/glupy/examples/Makefile.am @@ -0,0 +1,5 @@ +xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/features + +glupyexamplesdir = $(xlatordir)/glupy + +glupyexamples_PYTHON = negative.py helloworld.py debug-trace.py diff --git a/xlators/features/glupy/examples/debug-trace.py b/xlators/features/glupy/examples/debug-trace.py new file mode 100644 index 00000000000..6eef1b58b8f --- /dev/null +++ b/xlators/features/glupy/examples/debug-trace.py @@ -0,0 +1,775 @@ +import sys +import stat +from uuid import UUID +from time import strftime, localtime +from gluster.glupy import * + +# This translator was written primarily to test the fop entry point definitions +# and structure definitions in 'glupy.py'. + +# It is similar to the C language debug-trace translator, which logs the +# arguments passed to the fops and their corresponding cbk functions. + +dl.get_id.restype = c_long +dl.get_id.argtypes = [ POINTER(call_frame_t) ] + +dl.get_rootunique.restype = c_uint64 +dl.get_rootunique.argtypes = [ POINTER(call_frame_t) ] + +def uuid2str (gfid): + return str(UUID(''.join(map("{0:02x}".format, gfid)))) + + +def st_mode_from_ia (prot, filetype): + st_mode = 0 + type_bit = 0 + prot_bit = 0 + + if filetype == IA_IFREG: + type_bit = stat.S_IFREG + elif filetype == IA_IFDIR: + type_bit = stat.S_IFDIR + elif filetype == IA_IFLNK: + type_bit = stat.S_IFLNK + elif filetype == IA_IFBLK: + type_bit = stat.S_IFBLK + elif filetype == IA_IFCHR: + type_bit = stat.S_IFCHR + elif filetype == IA_IFIFO: + type_bit = stat.S_IFIFO + elif filetype == IA_IFSOCK: + type_bit = stat.S_IFSOCK + elif filetype == IA_INVAL: + pass + + + if prot.suid: + prot_bit |= stat.S_ISUID + if prot.sgid: + prot_bit |= stat.S_ISGID + if prot.sticky: + prot_bit |= stat.S_ISVTX + + if prot.owner.read: + prot_bit |= stat.S_IRUSR + if prot.owner.write: + prot_bit |= stat.S_IWUSR + if prot.owner.execn: + prot_bit |= stat.S_IXUSR + + if prot.group.read: + prot_bit |= stat.S_IRGRP + if prot.group.write: + prot_bit |= stat.S_IWGRP + if prot.group.execn: + prot_bit |= stat.S_IXGRP + + if prot.other.read: + prot_bit |= stat.S_IROTH + if prot.other.write: + prot_bit |= stat.S_IWOTH + if prot.other.execn: + prot_bit |= stat.S_IXOTH + + st_mode = (type_bit | prot_bit) + + return st_mode + + +def trace_stat2str (buf): + gfid = uuid2str(buf.contents.ia_gfid) + mode = st_mode_from_ia(buf.contents.ia_prot, buf.contents.ia_type) + atime_buf = strftime("[%b %d %H:%M:%S]", + localtime(buf.contents.ia_atime)) + mtime_buf = strftime("[%b %d %H:%M:%S]", + localtime(buf.contents.ia_mtime)) + ctime_buf = strftime("[%b %d %H:%M:%S]", + localtime(buf.contents.ia_ctime)) + return ("(gfid={0:s}, ino={1:d}, mode={2:o}, nlink={3:d}, uid ={4:d}, "+ + "gid ={5:d}, size={6:d}, blocks={7:d}, atime={8:s}, mtime={9:s}, "+ + "ctime={10:s})").format(gfid, buf.contents.ia_no, mode, + buf.contents.ia_nlink, + buf.contents.ia_uid, + buf.contents.ia_gid, + buf.contents.ia_size, + buf.contents.ia_blocks, + atime_buf, mtime_buf, + ctime_buf) + +class xlator(Translator): + + def __init__(self, c_this): + Translator.__init__(self, c_this) + self.gfids = {} + + def lookup_fop(self, frame, this, loc, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.gfid) + print("GLUPY TRACE LOOKUP FOP- {0:d}: gfid={1:s}; " + + "path={2:s}").format(unique, gfid, loc.contents.path) + self.gfids[key] = gfid + dl.wind_lookup(frame, POINTER(xlator_t)(), loc, xdata) + return 0 + + def lookup_cbk(self, frame, cookie, this, op_ret, op_errno, + inode, buf, xdata, postparent): + unique =dl.get_rootunique(frame) + key =dl.get_id(frame) + if op_ret == 0: + gfid = uuid2str(buf.contents.ia_gfid) + statstr = trace_stat2str(buf) + postparentstr = trace_stat2str(postparent) + print("GLUPY TRACE LOOKUP CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; *buf={3:s}; " + + "*postparent={4:s}").format(unique, gfid, + op_ret, statstr, + postparentstr) + else: + gfid = self.gfids[key] + print("GLUPY TRACE LOOKUP CBK - {0:d}: gfid={1:s};" + + " op_ret={2:d}; op_errno={3:d}").format(unique, + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_lookup(frame, cookie, this, op_ret, op_errno, + inode, buf, xdata, postparent) + return 0 + + def create_fop(self, frame, this, loc, flags, mode, umask, fd, + xdata): + unique = dl.get_rootunique(frame) + gfid = uuid2str(loc.contents.gfid) + print("GLUPY TRACE CREATE FOP- {0:d}: gfid={1:s}; path={2:s}; " + + "fd={3:s}; flags=0{4:o}; mode=0{5:o}; " + + "umask=0{6:o}").format(unique, gfid, loc.contents.path, + fd, flags, mode, umask) + dl.wind_create(frame, POINTER(xlator_t)(), loc, flags,mode, + umask, fd, xdata) + return 0 + + def create_cbk(self, frame, cookie, this, op_ret, op_errno, fd, + inode, buf, preparent, postparent, xdata): + unique = dl.get_rootunique(frame) + if op_ret >= 0: + gfid = uuid2str(inode.contents.gfid) + statstr = trace_stat2str(buf) + preparentstr = trace_stat2str(preparent) + postparentstr = trace_stat2str(postparent) + print("GLUPY TRACE CREATE CBK- {0:d}: gfid={1:s};" + + " op_ret={2:d}; fd={3:s}; *stbuf={4:s}; " + + "*preparent={5:s};" + + " *postparent={6:s}").format(unique, gfid, op_ret, + fd, statstr, + preparentstr, + postparentstr) + else: + print ("GLUPY TRACE CREATE CBK- {0:d}: op_ret={1:d}; " + + "op_errno={2:d}").format(unique, op_ret, op_errno) + dl.unwind_create(frame, cookie, this, op_ret, op_errno, fd, + inode, buf, preparent, postparent, xdata) + return 0 + + def open_fop(self, frame, this, loc, flags, fd, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE OPEN FOP- {0:d}: gfid={1:s}; path={2:s}; "+ + "flags={3:d}; fd={4:s}").format(unique, gfid, + loc.contents.path, flags, + fd) + self.gfids[key] = gfid + dl.wind_open(frame, POINTER(xlator_t)(), loc, flags, fd, xdata) + return 0 + + def open_cbk(self, frame, cookie, this, op_ret, op_errno, fd, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE OPEN CBK- {0:d}: gfid={1:s}; op_ret={2:d}; " + "op_errno={3:d}; *fd={4:s}").format(unique, gfid, + op_ret, op_errno, fd) + del self.gfids[key] + dl.unwind_open(frame, cookie, this, op_ret, op_errno, fd, + xdata) + return 0 + + def readv_fop(self, frame, this, fd, size, offset, flags, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(fd.contents.inode.contents.gfid) + print("GLUPY TRACE READV FOP- {0:d}: gfid={1:s}; "+ + "fd={2:s}; size ={3:d}; offset={4:d}; " + + "flags=0{5:x}").format(unique, gfid, fd, size, offset, + flags) + self.gfids[key] = gfid + dl.wind_readv (frame, POINTER(xlator_t)(), fd, size, offset, + flags, xdata) + return 0 + + def readv_cbk(self, frame, cookie, this, op_ret, op_errno, vector, + count, buf, iobref, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret >= 0: + statstr = trace_stat2str(buf) + print("GLUPY TRACE READV CBK- {0:d}: gfid={1:s}, "+ + "op_ret={2:d}; *buf={3:s};").format(unique, gfid, + op_ret, + statstr) + + else: + print("GLUPY TRACE READV CBK- {0:d}: gfid={1:s}, "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_readv (frame, cookie, this, op_ret, op_errno, + vector, count, buf, iobref, xdata) + return 0 + + def writev_fop(self, frame, this, fd, vector, count, offset, flags, + iobref, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(fd.contents.inode.contents.gfid) + print("GLUPY TRACE WRITEV FOP- {0:d}: gfid={1:s}; " + + "fd={2:s}; count={3:d}; offset={4:d}; " + + "flags=0{5:x}").format(unique, gfid, fd, count, offset, + flags) + self.gfids[key] = gfid + dl.wind_writev(frame, POINTER(xlator_t)(), fd, vector, count, + offset, flags, iobref, xdata) + return 0 + + def writev_cbk(self, frame, cookie, this, op_ret, op_errno, prebuf, + postbuf, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + if op_ret >= 0: + preopstr = trace_stat2str(prebuf) + postopstr = trace_stat2str(postbuf) + print("GLUPY TRACE WRITEV CBK- {0:d}: op_ret={1:d}; " + + "*prebuf={2:s}; " + + "*postbuf={3:s}").format(unique, op_ret, preopstr, + postopstr) + else: + gfid = self.gfids[key] + print("GLUPY TRACE WRITEV CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_writev (frame, cookie, this, op_ret, op_errno, + prebuf, postbuf, xdata) + return 0 + + def opendir_fop(self, frame, this, loc, fd, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE OPENDIR FOP- {0:d}: gfid={1:s}; path={2:s}; "+ + "fd={3:s}").format(unique, gfid, loc.contents.path, fd) + self.gfids[key] = gfid + dl.wind_opendir(frame, POINTER(xlator_t)(), loc, fd, xdata) + return 0 + + def opendir_cbk(self, frame, cookie, this, op_ret, op_errno, fd, + xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE OPENDIR CBK- {0:d}: gfid={1:s}; op_ret={2:d};"+ + " op_errno={3:d}; fd={4:s}").format(unique, gfid, op_ret, + op_errno, fd) + del self.gfids[key] + dl.unwind_opendir(frame, cookie, this, op_ret, op_errno, + fd, xdata) + return 0 + + def readdir_fop(self, frame, this, fd, size, offset, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(fd.contents.inode.contents.gfid) + print("GLUPY TRACE READDIR FOP- {0:d}: gfid={1:s}; fd={2:s}; " + + "size={3:d}; offset={4:d}").format(unique, gfid, fd, size, + offset) + self.gfids[key] = gfid + dl.wind_readdir(frame, POINTER(xlator_t)(), fd, size, offset, + xdata) + return 0 + + def readdir_cbk(self, frame, cookie, this, op_ret, op_errno, buf, + xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE READDIR CBK- {0:d}: gfid={1:s}; op_ret={2:d};"+ + " op_errno={3:d}").format(unique, gfid, op_ret, op_errno) + del self.gfids[key] + dl.unwind_readdir(frame, cookie, this, op_ret, op_errno, buf, + xdata) + return 0 + + def readdirp_fop(self, frame, this, fd, size, offset, dictionary): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(fd.contents.inode.contents.gfid) + print("GLUPY TRACE READDIRP FOP- {0:d}: gfid={1:s}; fd={2:s}; "+ + " size={3:d}; offset={4:d}").format(unique, gfid, fd, size, + offset) + self.gfids[key] = gfid + dl.wind_readdirp(frame, POINTER(xlator_t)(), fd, size, offset, + dictionary) + return 0 + + def readdirp_cbk(self, frame, cookie, this, op_ret, op_errno, buf, + xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE READDIRP CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, gfid, + op_ret, op_errno) + del self.gfids[key] + dl.unwind_readdirp(frame, cookie, this, op_ret, op_errno, buf, + xdata) + return 0 + + def mkdir_fop(self, frame, this, loc, mode, umask, xdata): + unique = dl.get_rootunique(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE MKDIR FOP- {0:d}: gfid={1:s}; path={2:s}; " + + "mode={3:d}; umask=0{4:o}").format(unique, gfid, + loc.contents.path, mode, + umask) + dl.wind_mkdir(frame, POINTER(xlator_t)(), loc, mode, umask, + xdata) + return 0 + + def mkdir_cbk(self, frame, cookie, this, op_ret, op_errno, inode, buf, + preparent, postparent, xdata): + unique = dl.get_rootunique(frame) + if op_ret == 0: + gfid = uuid2str(inode.contents.gfid) + statstr = trace_stat2str(buf) + preparentstr = trace_stat2str(preparent) + postparentstr = trace_stat2str(postparent) + print("GLUPY TRACE MKDIR CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; *stbuf={3:s}; *prebuf={4:s}; "+ + "*postbuf={5:s} ").format(unique, gfid, op_ret, + statstr, + preparentstr, + postparentstr) + else: + print("GLUPY TRACE MKDIR CBK- {0:d}: op_ret={1:d}; "+ + "op_errno={2:d}").format(unique, op_ret, op_errno) + dl.unwind_mkdir(frame, cookie, this, op_ret, op_errno, inode, + buf, preparent, postparent, xdata) + return 0 + + def rmdir_fop(self, frame, this, loc, flags, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE RMDIR FOP- {0:d}: gfid={1:s}; path={2:s}; "+ + "flags={3:d}").format(unique, gfid, loc.contents.path, + flags) + self.gfids[key] = gfid + dl.wind_rmdir(frame, POINTER(xlator_t)(), loc, flags, xdata) + return 0 + + def rmdir_cbk(self, frame, cookie, this, op_ret, op_errno, preparent, + postparent, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret == 0: + preparentstr = trace_stat2str(preparent) + postparentstr = trace_stat2str(postparent) + print("GLUPY TRACE RMDIR CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; *prebuf={3:s}; "+ + "*postbuf={4:s}").format(unique, gfid, op_ret, + preparentstr, + postparentstr) + else: + print("GLUPY TRACE RMDIR CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_rmdir(frame, cookie, this, op_ret, op_errno, + preparent, postparent, xdata) + return 0 + + def stat_fop(self, frame, this, loc, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE STAT FOP- {0:d}: gfid={1:s}; " + + " path={2:s}").format(unique, gfid, loc.contents.path) + self.gfids[key] = gfid + dl.wind_stat(frame, POINTER(xlator_t)(), loc, xdata) + return 0 + + def stat_cbk(self, frame, cookie, this, op_ret, op_errno, buf, + xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret == 0: + statstr = trace_stat2str(buf) + print("GLUPY TRACE STAT CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; *buf={3:s};").format(unique, + gfid, + op_ret, + statstr) + else: + print("GLUPY TRACE STAT CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_stat(frame, cookie, this, op_ret, op_errno, + buf, xdata) + return 0 + + def fstat_fop(self, frame, this, fd, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(fd.contents.inode.contents.gfid) + print("GLUPY TRACE FSTAT FOP- {0:d}: gfid={1:s}; " + + "fd={2:s}").format(unique, gfid, fd) + self.gfids[key] = gfid + dl.wind_fstat(frame, POINTER(xlator_t)(), fd, xdata) + return 0 + + def fstat_cbk(self, frame, cookie, this, op_ret, op_errno, buf, + xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret == 0: + statstr = trace_stat2str(buf) + print("GLUPY TRACE FSTAT CBK- {0:d}: gfid={1:s} "+ + " op_ret={2:d}; *buf={3:s}").format(unique, + gfid, + op_ret, + statstr) + else: + print("GLUPY TRACE FSTAT CBK- {0:d}: gfid={1:s} "+ + "op_ret={2:d}; op_errno={3:d}").format(unique. + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_fstat(frame, cookie, this, op_ret, op_errno, + buf, xdata) + return 0 + + def statfs_fop(self, frame, this, loc, xdata): + unique = dl.get_rootunique(frame) + if loc.contents.inode: + gfid = uuid2str(loc.contents.inode.contents.gfid) + else: + gfid = "0" + print("GLUPY TRACE STATFS FOP- {0:d}: gfid={1:s}; "+ + "path={2:s}").format(unique, gfid, loc.contents.path) + dl.wind_statfs(frame, POINTER(xlator_t)(), loc, xdata) + return 0 + + def statfs_cbk(self, frame, cookie, this, op_ret, op_errno, buf, + xdata): + unique = dl.get_rootunique(frame) + if op_ret == 0: + #TBD: print buf (pointer to an iovec type object) + print("GLUPY TRACE STATFS CBK {0:d}: "+ + "op_ret={1:d}").format(unique, op_ret) + else: + print("GLUPY TRACE STATFS CBK- {0:d}"+ + "op_ret={1:d}; op_errno={2:d}").format(unique, + op_ret, + op_errno) + dl.unwind_statfs(frame, cookie, this, op_ret, op_errno, + buf, xdata) + return 0 + + def getxattr_fop(self, frame, this, loc, name, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE GETXATTR FOP- {0:d}: gfid={1:s}; path={2:s};"+ + " name={3:s}").format(unique, gfid, loc.contents.path, + name) + self.gfids[key]=gfid + dl.wind_getxattr(frame, POINTER(xlator_t)(), loc, name, xdata) + return 0 + + def getxattr_cbk(self, frame, cookie, this, op_ret, op_errno, + dictionary, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE GETXATTR CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}; "+ + " dictionary={4:s}").format(unique, gfid, op_ret, op_errno, + dictionary) + del self.gfids[key] + dl.unwind_getxattr(frame, cookie, this, op_ret, op_errno, + dictionary, xdata) + return 0 + + def fgetxattr_fop(self, frame, this, fd, name, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(fd.contents.inode.contents.gfid) + print("GLUPY TRACE FGETXATTR FOP- {0:d}: gfid={1:s}; fd={2:s}; "+ + "name={3:s}").format(unique, gfid, fd, name) + self.gfids[key] = gfid + dl.wind_fgetxattr(frame, POINTER(xlator_t)(), fd, name, xdata) + return 0 + + def fgetxattr_cbk(self, frame, cookie, this, op_ret, op_errno, + dictionary, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE FGETXATTR CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d};"+ + " dictionary={4:s}").format(unique, gfid, op_ret, + op_errno, dictionary) + del self.gfids[key] + dl.unwind_fgetxattr(frame, cookie, this, op_ret, op_errno, + dictionary, xdata) + return 0 + + def setxattr_fop(self, frame, this, loc, dictionary, flags, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE SETXATTR FOP- {0:d}: gfid={1:s}; path={2:s};"+ + " flags={3:d}").format(unique, gfid, loc.contents.path, + flags) + self.gfids[key] = gfid + dl.wind_setxattr(frame, POINTER(xlator_t)(), loc, dictionary, + flags, xdata) + return 0 + + def setxattr_cbk(self, frame, cookie, this, op_ret, op_errno, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE SETXATTR CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, gfid, + op_ret, op_errno) + del self.gfids[key] + dl.unwind_setxattr(frame, cookie, this, op_ret, op_errno, + xdata) + return 0 + + def fsetxattr_fop(self, frame, this, fd, dictionary, flags, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(fd.contents.inode.contents.gfid) + print("GLUPY TRACE FSETXATTR FOP- {0:d}: gfid={1:s}; fd={2:p}; "+ + "flags={3:d}").format(unique, gfid, fd, flags) + self.gfids[key] = gfid + dl.wind_fsetxattr(frame, POINTER(xlator_t)(), fd, dictionary, + flags, xdata) + return 0 + + def fsetxattr_cbk(self, frame, cookie, this, op_ret, op_errno, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE FSETXATTR CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, gfid, + op_ret, op_errno) + del self.gfids[key] + dl.unwind_fsetxattr(frame, cookie, this, op_ret, op_errno, + xdata) + return 0 + + def removexattr_fop(self, frame, this, loc, name, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE REMOVEXATTR FOP- {0:d}: gfid={1:s}; "+ + "path={2:s}; name={3:s}").format(unique, gfid, + loc.contents.path, + name) + self.gfids[key] = gfid + dl.wind_removexattr(frame, POINTER(xlator_t)(), loc, name, + xdata) + return 0 + + def removexattr_cbk(self, frame, cookie, this, op_ret, op_errno, + xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + print("GLUPY TRACE REMOVEXATTR CBK- {0:d}: gfid={1:s} "+ + " op_ret={2:d}; op_errno={3:d}").format(unique, gfid, + op_ret, op_errno) + del self.gfids[key] + dl.unwind_removexattr(frame, cookie, this, op_ret, op_errno, + xdata) + return 0 + + def link_fop(self, frame, this, oldloc, newloc, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + if (newloc.contents.inode): + newgfid = uuid2str(newloc.contents.inode.contents.gfid) + else: + newgfid = "0" + oldgfid = uuid2str(oldloc.contents.inode.contents.gfid) + print("GLUPY TRACE LINK FOP-{0:d}: oldgfid={1:s}; oldpath={2:s};"+ + "newgfid={3:s};"+ + "newpath={4:s}").format(unique, oldgfid, + oldloc.contents.path, + newgfid, + newloc.contents.path) + self.gfids[key] = oldgfid + dl.wind_link(frame, POINTER(xlator_t)(), oldloc, newloc, + xdata) + return 0 + + def link_cbk(self, frame, cookie, this, op_ret, op_errno, inode, buf, + preparent, postparent, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret == 0: + statstr = trace_stat2str(buf) + preparentstr = trace_stat2str(preparent) + postparentstr = trace_stat2str(postparent) + print("GLUPY TRACE LINK CBK- {0:d}: op_ret={1:d} "+ + "*stbuf={2:s}; *prebuf={3:s}; "+ + "*postbuf={4:s} ").format(unique, op_ret, statstr, + preparentstr, + postparentstr) + else: + print("GLUPY TRACE LINK CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; "+ + "op_errno={3:d}").format(unique, gfid, + op_ret, op_errno) + del self.gfids[key] + dl.unwind_link(frame, cookie, this, op_ret, op_errno, inode, + buf, preparent, postparent, xdata) + return 0 + + def unlink_fop(self, frame, this, loc, xflag, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE UNLINK FOP- {0:d}; gfid={1:s}; path={2:s}; "+ + "flag={3:d}").format(unique, gfid, loc.contents.path, + xflag) + self.gfids[key] = gfid + dl.wind_unlink(frame, POINTER(xlator_t)(), loc, xflag, + xdata) + return 0 + + def unlink_cbk(self, frame, cookie, this, op_ret, op_errno, + preparent, postparent, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret == 0: + preparentstr = trace_stat2str(preparent) + postparentstr = trace_stat2str(postparent) + print("GLUPY TRACE UNLINK CBK- {0:d}: gfid ={1:s}; "+ + "op_ret={2:d}; *prebuf={3:s}; "+ + "*postbuf={4:s} ").format(unique, gfid, op_ret, + preparentstr, + postparentstr) + else: + print("GLUPY TRACE UNLINK CBK: {0:d}: gfid ={1:s}; "+ + "op_ret={2:d}; "+ + "op_errno={3:d}").format(unique, gfid, op_ret, + op_errno) + del self.gfids[key] + dl.unwind_unlink(frame, cookie, this, op_ret, op_errno, + preparent, postparent, xdata) + return 0 + + def readlink_fop(self, frame, this, loc, size, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE READLINK FOP- {0:d}: gfid={1:s}; path={2:s};"+ + " size={3:d}").format(unique, gfid, loc.contents.path, + size) + self.gfids[key] = gfid + dl.wind_readlink(frame, POINTER(xlator_t)(), loc, size, + xdata) + return 0 + + def readlink_cbk(self, frame, cookie, this, op_ret, op_errno, + buf, stbuf, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret == 0: + statstr = trace_stat2str(stbuf) + print("GLUPY TRACE READLINK CBK- {0:d}: gfid={1:s} "+ + " op_ret={2:d}; op_errno={3:d}; *prebuf={4:s}; "+ + "*postbuf={5:s} ").format(unique, gfid, + op_ret, op_errno, + buf, statstr) + else: + print("GLUPY TRACE READLINK CBK- {0:d}: gfid={1:s} "+ + " op_ret={2:d}; op_errno={3:d}").format(unique, + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_readlink(frame, cookie, this, op_ret, op_errno, buf, + stbuf, xdata) + return 0 + + def symlink_fop(self, frame, this, linkpath, loc, umask, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = uuid2str(loc.contents.inode.contents.gfid) + print("GLUPY TRACE SYMLINK FOP- {0:d}: gfid={1:s}; "+ + "linkpath={2:s}; path={3:s};"+ + "umask=0{4:o}").format(unique, gfid, linkpath, + loc.contents.path, umask) + self.gfids[key] = gfid + dl.wind_symlink(frame, POINTER(xlator_t)(), linkpath, loc, + umask, xdata) + return 0 + + def symlink_cbk(self, frame, cookie, this, op_ret, op_errno, + inode, buf, preparent, postparent, xdata): + unique = dl.get_rootunique(frame) + key = dl.get_id(frame) + gfid = self.gfids[key] + if op_ret == 0: + statstr = trace_stat2str(buf) + preparentstr = trace_stat2str(preparent) + postparentstr = trace_stat2str(postparent) + print("GLUPY TRACE SYMLINK CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; *stbuf={3:s}; *preparent={4:s}; "+ + "*postparent={5:s}").format(unique, gfid, + op_ret, statstr, + preparentstr, + postparentstr) + else: + print("GLUPY TRACE SYMLINK CBK- {0:d}: gfid={1:s}; "+ + "op_ret={2:d}; op_errno={3:d}").format(unique, + gfid, + op_ret, + op_errno) + del self.gfids[key] + dl.unwind_symlink(frame, cookie, this, op_ret, op_errno, + inode, buf, preparent, postparent, xdata) + return 0 diff --git a/xlators/features/glupy/examples/helloworld.py b/xlators/features/glupy/examples/helloworld.py new file mode 100644 index 00000000000..b565a4e5bc3 --- /dev/null +++ b/xlators/features/glupy/examples/helloworld.py @@ -0,0 +1,19 @@ +import sys +from gluster.glupy import * + +class xlator (Translator): + + def __init__(self, c_this): + Translator.__init__(self, c_this) + + def lookup_fop(self, frame, this, loc, xdata): + print "Python xlator: Hello!" + dl.wind_lookup(frame, POINTER(xlator_t)(), loc, xdata) + return 0 + + def lookup_cbk(self, frame, cookie, this, op_ret, op_errno, inode, buf, + xdata, postparent): + print "Python xlator: Hello again!" + dl.unwind_lookup(frame, cookie, this, op_ret, op_errno, inode, buf, + xdata, postparent) + return 0 diff --git a/xlators/features/glupy/examples/negative.py b/xlators/features/glupy/examples/negative.py new file mode 100644 index 00000000000..e7a4fc07ced --- /dev/null +++ b/xlators/features/glupy/examples/negative.py @@ -0,0 +1,91 @@ +import sys +from uuid import UUID +from gluster.glupy import * + +# Negative-lookup-caching example. If a file wasn't there the last time we +# looked, it's probably still not there. This translator keeps track of +# those failed lookups for us, and returns ENOENT without needing to pass the +# call any further for repeated requests. + +# If we were doing this for real, we'd need separate caches for each xlator +# instance. The easiest way to do this would be to have xlator.__init__ +# "register" each instance in a module-global dict, with the key as the C +# translator address and the value as the xlator object itself. For testing +# and teaching, it's sufficient just to have one cache. The keys are parent +# GFIDs, and the entries are lists of names within that parent that we know +# don't exist. +cache = {} + +# TBD: we need a better way of handling per-request data (frame->local in C). +dl.get_id.restype = c_long +dl.get_id.argtypes = [ POINTER(call_frame_t) ] + +def uuid2str (gfid): + return str(UUID(''.join(map("{0:02x}".format, gfid)))) + +class xlator (Translator): + + def __init__ (self, c_this): + self.requests = {} + Translator.__init__(self,c_this) + + def lookup_fop (self, frame, this, loc, xdata): + pargfid = uuid2str(loc.contents.pargfid) + print "lookup FOP: %s:%s" % (pargfid, loc.contents.name) + # Check the cache. + if cache.has_key(pargfid): + if loc.contents.name in cache[pargfid]: + print "short-circuiting for %s:%s" % (pargfid, + loc.contents.name) + dl.unwind_lookup(frame,0,this,-1,2,None,None,None,None) + return 0 + key = dl.get_id(frame) + self.requests[key] = (pargfid, loc.contents.name[:]) + # TBD: get real child xl from init, pass it here + dl.wind_lookup(frame,POINTER(xlator_t)(),loc,xdata) + return 0 + + def lookup_cbk (self, frame, cookie, this, op_ret, op_errno, inode, buf, + xdata, postparent): + print "lookup CBK: %d (%d)" % (op_ret, op_errno) + key = dl.get_id(frame) + pargfid, name = self.requests[key] + # Update the cache. + if op_ret == 0: + print "found %s, removing from cache" % name + if cache.has_key(pargfid): + cache[pargfid].discard(name) + elif op_errno == 2: # ENOENT + print "failed to find %s, adding to cache" % name + if cache.has_key(pargfid): + cache[pargfid].add(name) + else: + cache[pargfid] = set([name]) + del self.requests[key] + dl.unwind_lookup(frame,cookie,this,op_ret,op_errno, + inode,buf,xdata,postparent) + return 0 + + def create_fop (self, frame, this, loc, flags, mode, umask, fd, xdata): + pargfid = uuid2str(loc.contents.pargfid) + print "create FOP: %s:%s" % (pargfid, loc.contents.name) + key = dl.get_id(frame) + self.requests[key] = (pargfid, loc.contents.name[:]) + # TBD: get real child xl from init, pass it here + dl.wind_create(frame,POINTER(xlator_t)(),loc,flags,mode,umask,fd,xdata) + return 0 + + def create_cbk (self, frame, cookie, this, op_ret, op_errno, fd, inode, + buf, preparent, postparent, xdata): + print "create CBK: %d (%d)" % (op_ret, op_errno) + key = dl.get_id(frame) + pargfid, name = self.requests[key] + # Update the cache. + if op_ret == 0: + print "created %s, removing from cache" % name + if cache.has_key(pargfid): + cache[pargfid].discard(name) + del self.requests[key] + dl.unwind_create(frame,cookie,this,op_ret,op_errno,fd,inode,buf, + preparent,postparent,xdata) + return 0 diff --git a/xlators/features/glupy/src/Makefile.am b/xlators/features/glupy/src/Makefile.am index 21b91a16455..ae7b6d14d45 100644 --- a/xlators/features/glupy/src/Makefile.am +++ b/xlators/features/glupy/src/Makefile.am @@ -1,11 +1,12 @@ xlator_LTLIBRARIES = glupy.la +# Ensure GLUSTER_PYTHON_PATH is passed to glupy.so xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/features - glupydir = $(xlatordir)/glupy +AM_CPPFLAGS = $(PYTHONDEV_CPPFLAGS) $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src -isystem $(BUILD_PYTHON_INC) +AM_CFLAGS = $(PYTHONDEV_CFLAGS) -Wall -fno-strict-aliasing -DGLUSTER_PYTHON_PATH=\"$(glupydir)\" $(GF_CFLAGS) -glupy_PYTHON = gluster.py negative.py helloworld.py debug-trace.py - +# Flags to build glupy.so with glupy_la_LDFLAGS = $(PYTHONDEV_LDFLAGS) -module -avoid-version -shared -nostartfiles glupy_la_SOURCES = glupy.c glupy_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ @@ -13,8 +14,8 @@ glupy_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ noinst_HEADERS = glupy.h -AM_CPPFLAGS = $(PYTHONDEV_CPPFLAGS) $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src -isystem $(BUILD_PYTHON_INC) - -AM_CFLAGS = $(PYTHONDEV_CFLAGS) -Wall -fno-strict-aliasing -DGLUSTER_PYTHON_PATH=\"$(glupydir)\" $(GF_CFLAGS) +# Install glupy.py into the Python site-packages area +pyglupydir = $(pythondir)/gluster +pyglupy_PYTHON = glupy.py CLEANFILES = diff --git a/xlators/features/glupy/src/debug-trace.py b/xlators/features/glupy/src/debug-trace.py deleted file mode 100644 index 53e76546b15..00000000000 --- a/xlators/features/glupy/src/debug-trace.py +++ /dev/null @@ -1,774 +0,0 @@ -import sys -import stat -from uuid import UUID -from time import strftime, localtime -from gluster import * -# This translator was written primarily to test the fop entry point definitions -# and structure definitions in 'gluster.py'. -# It is similar to the debug-trace translator, one of the already available -# translator types written in C, that logs the arguments passed to the fops and -# their corresponding cbk functions. - -dl.get_id.restype = c_long -dl.get_id.argtypes = [ POINTER(call_frame_t) ] - -dl.get_rootunique.restype = c_uint64 -dl.get_rootunique.argtypes = [ POINTER(call_frame_t) ] - -def uuid2str (gfid): - return str(UUID(''.join(map("{0:02x}".format, gfid)))) - - -def st_mode_from_ia (prot, filetype): - st_mode = 0 - type_bit = 0 - prot_bit = 0 - - if filetype == IA_IFREG: - type_bit = stat.S_IFREG - elif filetype == IA_IFDIR: - type_bit = stat.S_IFDIR - elif filetype == IA_IFLNK: - type_bit = stat.S_IFLNK - elif filetype == IA_IFBLK: - type_bit = stat.S_IFBLK - elif filetype == IA_IFCHR: - type_bit = stat.S_IFCHR - elif filetype == IA_IFIFO: - type_bit = stat.S_IFIFO - elif filetype == IA_IFSOCK: - type_bit = stat.S_IFSOCK - elif filetype == IA_INVAL: - pass - - - if prot.suid: - prot_bit |= stat.S_ISUID - if prot.sgid: - prot_bit |= stat.S_ISGID - if prot.sticky: - prot_bit |= stat.S_ISVTX - - if prot.owner.read: - prot_bit |= stat.S_IRUSR - if prot.owner.write: - prot_bit |= stat.S_IWUSR - if prot.owner.execn: - prot_bit |= stat.S_IXUSR - - if prot.group.read: - prot_bit |= stat.S_IRGRP - if prot.group.write: - prot_bit |= stat.S_IWGRP - if prot.group.execn: - prot_bit |= stat.S_IXGRP - - if prot.other.read: - prot_bit |= stat.S_IROTH - if prot.other.write: - prot_bit |= stat.S_IWOTH - if prot.other.execn: - prot_bit |= stat.S_IXOTH - - st_mode = (type_bit | prot_bit) - - return st_mode - - -def trace_stat2str (buf): - gfid = uuid2str(buf.contents.ia_gfid) - mode = st_mode_from_ia(buf.contents.ia_prot, buf.contents.ia_type) - atime_buf = strftime("[%b %d %H:%M:%S]", - localtime(buf.contents.ia_atime)) - mtime_buf = strftime("[%b %d %H:%M:%S]", - localtime(buf.contents.ia_mtime)) - ctime_buf = strftime("[%b %d %H:%M:%S]", - localtime(buf.contents.ia_ctime)) - return ("(gfid={0:s}, ino={1:d}, mode={2:o}, nlink={3:d}, uid ={4:d}, "+ - "gid ={5:d}, size={6:d}, blocks={7:d}, atime={8:s}, mtime={9:s}, "+ - "ctime={10:s})").format(gfid, buf.contents.ia_no, mode, - buf.contents.ia_nlink, - buf.contents.ia_uid, - buf.contents.ia_gid, - buf.contents.ia_size, - buf.contents.ia_blocks, - atime_buf, mtime_buf, - ctime_buf) - -class xlator(Translator): - - def __init__(self, c_this): - Translator.__init__(self, c_this) - self.gfids = {} - - def lookup_fop(self, frame, this, loc, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.gfid) - print("GLUPY TRACE LOOKUP FOP- {0:d}: gfid={1:s}; " + - "path={2:s}").format(unique, gfid, loc.contents.path) - self.gfids[key] = gfid - dl.wind_lookup(frame, POINTER(xlator_t)(), loc, xdata) - return 0 - - def lookup_cbk(self, frame, cookie, this, op_ret, op_errno, - inode, buf, xdata, postparent): - unique =dl.get_rootunique(frame) - key =dl.get_id(frame) - if op_ret == 0: - gfid = uuid2str(buf.contents.ia_gfid) - statstr = trace_stat2str(buf) - postparentstr = trace_stat2str(postparent) - print("GLUPY TRACE LOOKUP CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; *buf={3:s}; " + - "*postparent={4:s}").format(unique, gfid, - op_ret, statstr, - postparentstr) - else: - gfid = self.gfids[key] - print("GLUPY TRACE LOOKUP CBK - {0:d}: gfid={1:s};" + - " op_ret={2:d}; op_errno={3:d}").format(unique, - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_lookup(frame, cookie, this, op_ret, op_errno, - inode, buf, xdata, postparent) - return 0 - - def create_fop(self, frame, this, loc, flags, mode, umask, fd, - xdata): - unique = dl.get_rootunique(frame) - gfid = uuid2str(loc.contents.gfid) - print("GLUPY TRACE CREATE FOP- {0:d}: gfid={1:s}; path={2:s}; " + - "fd={3:s}; flags=0{4:o}; mode=0{5:o}; " + - "umask=0{6:o}").format(unique, gfid, loc.contents.path, - fd, flags, mode, umask) - dl.wind_create(frame, POINTER(xlator_t)(), loc, flags,mode, - umask, fd, xdata) - return 0 - - def create_cbk(self, frame, cookie, this, op_ret, op_errno, fd, - inode, buf, preparent, postparent, xdata): - unique = dl.get_rootunique(frame) - if op_ret >= 0: - gfid = uuid2str(inode.contents.gfid) - statstr = trace_stat2str(buf) - preparentstr = trace_stat2str(preparent) - postparentstr = trace_stat2str(postparent) - print("GLUPY TRACE CREATE CBK- {0:d}: gfid={1:s};" + - " op_ret={2:d}; fd={3:s}; *stbuf={4:s}; " + - "*preparent={5:s};" + - " *postparent={6:s}").format(unique, gfid, op_ret, - fd, statstr, - preparentstr, - postparentstr) - else: - print ("GLUPY TRACE CREATE CBK- {0:d}: op_ret={1:d}; " + - "op_errno={2:d}").format(unique, op_ret, op_errno) - dl.unwind_create(frame, cookie, this, op_ret, op_errno, fd, - inode, buf, preparent, postparent, xdata) - return 0 - - def open_fop(self, frame, this, loc, flags, fd, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE OPEN FOP- {0:d}: gfid={1:s}; path={2:s}; "+ - "flags={3:d}; fd={4:s}").format(unique, gfid, - loc.contents.path, flags, - fd) - self.gfids[key] = gfid - dl.wind_open(frame, POINTER(xlator_t)(), loc, flags, fd, xdata) - return 0 - - def open_cbk(self, frame, cookie, this, op_ret, op_errno, fd, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE OPEN CBK- {0:d}: gfid={1:s}; op_ret={2:d}; " - "op_errno={3:d}; *fd={4:s}").format(unique, gfid, - op_ret, op_errno, fd) - del self.gfids[key] - dl.unwind_open(frame, cookie, this, op_ret, op_errno, fd, - xdata) - return 0 - - def readv_fop(self, frame, this, fd, size, offset, flags, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(fd.contents.inode.contents.gfid) - print("GLUPY TRACE READV FOP- {0:d}: gfid={1:s}; "+ - "fd={2:s}; size ={3:d}; offset={4:d}; " + - "flags=0{5:x}").format(unique, gfid, fd, size, offset, - flags) - self.gfids[key] = gfid - dl.wind_readv (frame, POINTER(xlator_t)(), fd, size, offset, - flags, xdata) - return 0 - - def readv_cbk(self, frame, cookie, this, op_ret, op_errno, vector, - count, buf, iobref, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret >= 0: - statstr = trace_stat2str(buf) - print("GLUPY TRACE READV CBK- {0:d}: gfid={1:s}, "+ - "op_ret={2:d}; *buf={3:s};").format(unique, gfid, - op_ret, - statstr) - - else: - print("GLUPY TRACE READV CBK- {0:d}: gfid={1:s}, "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_readv (frame, cookie, this, op_ret, op_errno, - vector, count, buf, iobref, xdata) - return 0 - - def writev_fop(self, frame, this, fd, vector, count, offset, flags, - iobref, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(fd.contents.inode.contents.gfid) - print("GLUPY TRACE WRITEV FOP- {0:d}: gfid={1:s}; " + - "fd={2:s}; count={3:d}; offset={4:d}; " + - "flags=0{5:x}").format(unique, gfid, fd, count, offset, - flags) - self.gfids[key] = gfid - dl.wind_writev(frame, POINTER(xlator_t)(), fd, vector, count, - offset, flags, iobref, xdata) - return 0 - - def writev_cbk(self, frame, cookie, this, op_ret, op_errno, prebuf, - postbuf, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - if op_ret >= 0: - preopstr = trace_stat2str(prebuf) - postopstr = trace_stat2str(postbuf) - print("GLUPY TRACE WRITEV CBK- {0:d}: op_ret={1:d}; " + - "*prebuf={2:s}; " + - "*postbuf={3:s}").format(unique, op_ret, preopstr, - postopstr) - else: - gfid = self.gfids[key] - print("GLUPY TRACE WRITEV CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_writev (frame, cookie, this, op_ret, op_errno, - prebuf, postbuf, xdata) - return 0 - - def opendir_fop(self, frame, this, loc, fd, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE OPENDIR FOP- {0:d}: gfid={1:s}; path={2:s}; "+ - "fd={3:s}").format(unique, gfid, loc.contents.path, fd) - self.gfids[key] = gfid - dl.wind_opendir(frame, POINTER(xlator_t)(), loc, fd, xdata) - return 0 - - def opendir_cbk(self, frame, cookie, this, op_ret, op_errno, fd, - xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE OPENDIR CBK- {0:d}: gfid={1:s}; op_ret={2:d};"+ - " op_errno={3:d}; fd={4:s}").format(unique, gfid, op_ret, - op_errno, fd) - del self.gfids[key] - dl.unwind_opendir(frame, cookie, this, op_ret, op_errno, - fd, xdata) - return 0 - - def readdir_fop(self, frame, this, fd, size, offset, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(fd.contents.inode.contents.gfid) - print("GLUPY TRACE READDIR FOP- {0:d}: gfid={1:s}; fd={2:s}; " + - "size={3:d}; offset={4:d}").format(unique, gfid, fd, size, - offset) - self.gfids[key] = gfid - dl.wind_readdir(frame, POINTER(xlator_t)(), fd, size, offset, - xdata) - return 0 - - def readdir_cbk(self, frame, cookie, this, op_ret, op_errno, buf, - xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE READDIR CBK- {0:d}: gfid={1:s}; op_ret={2:d};"+ - " op_errno={3:d}").format(unique, gfid, op_ret, op_errno) - del self.gfids[key] - dl.unwind_readdir(frame, cookie, this, op_ret, op_errno, buf, - xdata) - return 0 - - def readdirp_fop(self, frame, this, fd, size, offset, dictionary): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(fd.contents.inode.contents.gfid) - print("GLUPY TRACE READDIRP FOP- {0:d}: gfid={1:s}; fd={2:s}; "+ - " size={3:d}; offset={4:d}").format(unique, gfid, fd, size, - offset) - self.gfids[key] = gfid - dl.wind_readdirp(frame, POINTER(xlator_t)(), fd, size, offset, - dictionary) - return 0 - - def readdirp_cbk(self, frame, cookie, this, op_ret, op_errno, buf, - xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE READDIRP CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, gfid, - op_ret, op_errno) - del self.gfids[key] - dl.unwind_readdirp(frame, cookie, this, op_ret, op_errno, buf, - xdata) - return 0 - - def mkdir_fop(self, frame, this, loc, mode, umask, xdata): - unique = dl.get_rootunique(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE MKDIR FOP- {0:d}: gfid={1:s}; path={2:s}; " + - "mode={3:d}; umask=0{4:o}").format(unique, gfid, - loc.contents.path, mode, - umask) - dl.wind_mkdir(frame, POINTER(xlator_t)(), loc, mode, umask, - xdata) - return 0 - - def mkdir_cbk(self, frame, cookie, this, op_ret, op_errno, inode, buf, - preparent, postparent, xdata): - unique = dl.get_rootunique(frame) - if op_ret == 0: - gfid = uuid2str(inode.contents.gfid) - statstr = trace_stat2str(buf) - preparentstr = trace_stat2str(preparent) - postparentstr = trace_stat2str(postparent) - print("GLUPY TRACE MKDIR CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; *stbuf={3:s}; *prebuf={4:s}; "+ - "*postbuf={5:s} ").format(unique, gfid, op_ret, - statstr, - preparentstr, - postparentstr) - else: - print("GLUPY TRACE MKDIR CBK- {0:d}: op_ret={1:d}; "+ - "op_errno={2:d}").format(unique, op_ret, op_errno) - dl.unwind_mkdir(frame, cookie, this, op_ret, op_errno, inode, - buf, preparent, postparent, xdata) - return 0 - - def rmdir_fop(self, frame, this, loc, flags, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE RMDIR FOP- {0:d}: gfid={1:s}; path={2:s}; "+ - "flags={3:d}").format(unique, gfid, loc.contents.path, - flags) - self.gfids[key] = gfid - dl.wind_rmdir(frame, POINTER(xlator_t)(), loc, flags, xdata) - return 0 - - def rmdir_cbk(self, frame, cookie, this, op_ret, op_errno, preparent, - postparent, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret == 0: - preparentstr = trace_stat2str(preparent) - postparentstr = trace_stat2str(postparent) - print("GLUPY TRACE RMDIR CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; *prebuf={3:s}; "+ - "*postbuf={4:s}").format(unique, gfid, op_ret, - preparentstr, - postparentstr) - else: - print("GLUPY TRACE RMDIR CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_rmdir(frame, cookie, this, op_ret, op_errno, - preparent, postparent, xdata) - return 0 - - def stat_fop(self, frame, this, loc, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE STAT FOP- {0:d}: gfid={1:s}; " + - " path={2:s}").format(unique, gfid, loc.contents.path) - self.gfids[key] = gfid - dl.wind_stat(frame, POINTER(xlator_t)(), loc, xdata) - return 0 - - def stat_cbk(self, frame, cookie, this, op_ret, op_errno, buf, - xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret == 0: - statstr = trace_stat2str(buf) - print("GLUPY TRACE STAT CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; *buf={3:s};").format(unique, - gfid, - op_ret, - statstr) - else: - print("GLUPY TRACE STAT CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_stat(frame, cookie, this, op_ret, op_errno, - buf, xdata) - return 0 - - def fstat_fop(self, frame, this, fd, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(fd.contents.inode.contents.gfid) - print("GLUPY TRACE FSTAT FOP- {0:d}: gfid={1:s}; " + - "fd={2:s}").format(unique, gfid, fd) - self.gfids[key] = gfid - dl.wind_fstat(frame, POINTER(xlator_t)(), fd, xdata) - return 0 - - def fstat_cbk(self, frame, cookie, this, op_ret, op_errno, buf, - xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret == 0: - statstr = trace_stat2str(buf) - print("GLUPY TRACE FSTAT CBK- {0:d}: gfid={1:s} "+ - " op_ret={2:d}; *buf={3:s}").format(unique, - gfid, - op_ret, - statstr) - else: - print("GLUPY TRACE FSTAT CBK- {0:d}: gfid={1:s} "+ - "op_ret={2:d}; op_errno={3:d}").format(unique. - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_fstat(frame, cookie, this, op_ret, op_errno, - buf, xdata) - return 0 - - def statfs_fop(self, frame, this, loc, xdata): - unique = dl.get_rootunique(frame) - if loc.contents.inode: - gfid = uuid2str(loc.contents.inode.contents.gfid) - else: - gfid = "0" - print("GLUPY TRACE STATFS FOP- {0:d}: gfid={1:s}; "+ - "path={2:s}").format(unique, gfid, loc.contents.path) - dl.wind_statfs(frame, POINTER(xlator_t)(), loc, xdata) - return 0 - - def statfs_cbk(self, frame, cookie, this, op_ret, op_errno, buf, - xdata): - unique = dl.get_rootunique(frame) - if op_ret == 0: - #TBD: print buf (pointer to an iovec type object) - print("GLUPY TRACE STATFS CBK {0:d}: "+ - "op_ret={1:d}").format(unique, op_ret) - else: - print("GLUPY TRACE STATFS CBK- {0:d}"+ - "op_ret={1:d}; op_errno={2:d}").format(unique, - op_ret, - op_errno) - dl.unwind_statfs(frame, cookie, this, op_ret, op_errno, - buf, xdata) - return 0 - - def getxattr_fop(self, frame, this, loc, name, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE GETXATTR FOP- {0:d}: gfid={1:s}; path={2:s};"+ - " name={3:s}").format(unique, gfid, loc.contents.path, - name) - self.gfids[key]=gfid - dl.wind_getxattr(frame, POINTER(xlator_t)(), loc, name, xdata) - return 0 - - def getxattr_cbk(self, frame, cookie, this, op_ret, op_errno, - dictionary, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE GETXATTR CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}; "+ - " dictionary={4:s}").format(unique, gfid, op_ret, op_errno, - dictionary) - del self.gfids[key] - dl.unwind_getxattr(frame, cookie, this, op_ret, op_errno, - dictionary, xdata) - return 0 - - def fgetxattr_fop(self, frame, this, fd, name, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(fd.contents.inode.contents.gfid) - print("GLUPY TRACE FGETXATTR FOP- {0:d}: gfid={1:s}; fd={2:s}; "+ - "name={3:s}").format(unique, gfid, fd, name) - self.gfids[key] = gfid - dl.wind_fgetxattr(frame, POINTER(xlator_t)(), fd, name, xdata) - return 0 - - def fgetxattr_cbk(self, frame, cookie, this, op_ret, op_errno, - dictionary, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE FGETXATTR CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d};"+ - " dictionary={4:s}").format(unique, gfid, op_ret, - op_errno, dictionary) - del self.gfids[key] - dl.unwind_fgetxattr(frame, cookie, this, op_ret, op_errno, - dictionary, xdata) - return 0 - - def setxattr_fop(self, frame, this, loc, dictionary, flags, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE SETXATTR FOP- {0:d}: gfid={1:s}; path={2:s};"+ - " flags={3:d}").format(unique, gfid, loc.contents.path, - flags) - self.gfids[key] = gfid - dl.wind_setxattr(frame, POINTER(xlator_t)(), loc, dictionary, - flags, xdata) - return 0 - - def setxattr_cbk(self, frame, cookie, this, op_ret, op_errno, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE SETXATTR CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, gfid, - op_ret, op_errno) - del self.gfids[key] - dl.unwind_setxattr(frame, cookie, this, op_ret, op_errno, - xdata) - return 0 - - def fsetxattr_fop(self, frame, this, fd, dictionary, flags, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(fd.contents.inode.contents.gfid) - print("GLUPY TRACE FSETXATTR FOP- {0:d}: gfid={1:s}; fd={2:p}; "+ - "flags={3:d}").format(unique, gfid, fd, flags) - self.gfids[key] = gfid - dl.wind_fsetxattr(frame, POINTER(xlator_t)(), fd, dictionary, - flags, xdata) - return 0 - - def fsetxattr_cbk(self, frame, cookie, this, op_ret, op_errno, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE FSETXATTR CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, gfid, - op_ret, op_errno) - del self.gfids[key] - dl.unwind_fsetxattr(frame, cookie, this, op_ret, op_errno, - xdata) - return 0 - - def removexattr_fop(self, frame, this, loc, name, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE REMOVEXATTR FOP- {0:d}: gfid={1:s}; "+ - "path={2:s}; name={3:s}").format(unique, gfid, - loc.contents.path, - name) - self.gfids[key] = gfid - dl.wind_removexattr(frame, POINTER(xlator_t)(), loc, name, - xdata) - return 0 - - def removexattr_cbk(self, frame, cookie, this, op_ret, op_errno, - xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - print("GLUPY TRACE REMOVEXATTR CBK- {0:d}: gfid={1:s} "+ - " op_ret={2:d}; op_errno={3:d}").format(unique, gfid, - op_ret, op_errno) - del self.gfids[key] - dl.unwind_removexattr(frame, cookie, this, op_ret, op_errno, - xdata) - return 0 - - def link_fop(self, frame, this, oldloc, newloc, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - if (newloc.contents.inode): - newgfid = uuid2str(newloc.contents.inode.contents.gfid) - else: - newgfid = "0" - oldgfid = uuid2str(oldloc.contents.inode.contents.gfid) - print("GLUPY TRACE LINK FOP-{0:d}: oldgfid={1:s}; oldpath={2:s};"+ - "newgfid={3:s};"+ - "newpath={4:s}").format(unique, oldgfid, - oldloc.contents.path, - newgfid, - newloc.contents.path) - self.gfids[key] = oldgfid - dl.wind_link(frame, POINTER(xlator_t)(), oldloc, newloc, - xdata) - return 0 - - def link_cbk(self, frame, cookie, this, op_ret, op_errno, inode, buf, - preparent, postparent, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret == 0: - statstr = trace_stat2str(buf) - preparentstr = trace_stat2str(preparent) - postparentstr = trace_stat2str(postparent) - print("GLUPY TRACE LINK CBK- {0:d}: op_ret={1:d} "+ - "*stbuf={2:s}; *prebuf={3:s}; "+ - "*postbuf={4:s} ").format(unique, op_ret, statstr, - preparentstr, - postparentstr) - else: - print("GLUPY TRACE LINK CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; "+ - "op_errno={3:d}").format(unique, gfid, - op_ret, op_errno) - del self.gfids[key] - dl.unwind_link(frame, cookie, this, op_ret, op_errno, inode, - buf, preparent, postparent, xdata) - return 0 - - def unlink_fop(self, frame, this, loc, xflag, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE UNLINK FOP- {0:d}; gfid={1:s}; path={2:s}; "+ - "flag={3:d}").format(unique, gfid, loc.contents.path, - xflag) - self.gfids[key] = gfid - dl.wind_unlink(frame, POINTER(xlator_t)(), loc, xflag, - xdata) - return 0 - - def unlink_cbk(self, frame, cookie, this, op_ret, op_errno, - preparent, postparent, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret == 0: - preparentstr = trace_stat2str(preparent) - postparentstr = trace_stat2str(postparent) - print("GLUPY TRACE UNLINK CBK- {0:d}: gfid ={1:s}; "+ - "op_ret={2:d}; *prebuf={3:s}; "+ - "*postbuf={4:s} ").format(unique, gfid, op_ret, - preparentstr, - postparentstr) - else: - print("GLUPY TRACE UNLINK CBK: {0:d}: gfid ={1:s}; "+ - "op_ret={2:d}; "+ - "op_errno={3:d}").format(unique, gfid, op_ret, - op_errno) - del self.gfids[key] - dl.unwind_unlink(frame, cookie, this, op_ret, op_errno, - preparent, postparent, xdata) - return 0 - - def readlink_fop(self, frame, this, loc, size, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE READLINK FOP- {0:d}: gfid={1:s}; path={2:s};"+ - " size={3:d}").format(unique, gfid, loc.contents.path, - size) - self.gfids[key] = gfid - dl.wind_readlink(frame, POINTER(xlator_t)(), loc, size, - xdata) - return 0 - - def readlink_cbk(self, frame, cookie, this, op_ret, op_errno, - buf, stbuf, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret == 0: - statstr = trace_stat2str(stbuf) - print("GLUPY TRACE READLINK CBK- {0:d}: gfid={1:s} "+ - " op_ret={2:d}; op_errno={3:d}; *prebuf={4:s}; "+ - "*postbuf={5:s} ").format(unique, gfid, - op_ret, op_errno, - buf, statstr) - else: - print("GLUPY TRACE READLINK CBK- {0:d}: gfid={1:s} "+ - " op_ret={2:d}; op_errno={3:d}").format(unique, - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_readlink(frame, cookie, this, op_ret, op_errno, buf, - stbuf, xdata) - return 0 - - def symlink_fop(self, frame, this, linkpath, loc, umask, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = uuid2str(loc.contents.inode.contents.gfid) - print("GLUPY TRACE SYMLINK FOP- {0:d}: gfid={1:s}; "+ - "linkpath={2:s}; path={3:s};"+ - "umask=0{4:o}").format(unique, gfid, linkpath, - loc.contents.path, umask) - self.gfids[key] = gfid - dl.wind_symlink(frame, POINTER(xlator_t)(), linkpath, loc, - umask, xdata) - return 0 - - def symlink_cbk(self, frame, cookie, this, op_ret, op_errno, - inode, buf, preparent, postparent, xdata): - unique = dl.get_rootunique(frame) - key = dl.get_id(frame) - gfid = self.gfids[key] - if op_ret == 0: - statstr = trace_stat2str(buf) - preparentstr = trace_stat2str(preparent) - postparentstr = trace_stat2str(postparent) - print("GLUPY TRACE SYMLINK CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; *stbuf={3:s}; *preparent={4:s}; "+ - "*postparent={5:s}").format(unique, gfid, - op_ret, statstr, - preparentstr, - postparentstr) - else: - print("GLUPY TRACE SYMLINK CBK- {0:d}: gfid={1:s}; "+ - "op_ret={2:d}; op_errno={3:d}").format(unique, - gfid, - op_ret, - op_errno) - del self.gfids[key] - dl.unwind_symlink(frame, cookie, this, op_ret, op_errno, - inode, buf, preparent, postparent, xdata) - return 0 diff --git a/xlators/features/glupy/src/glupy.c b/xlators/features/glupy/src/glupy.c index dc86c0071e1..948b66f8d11 100644 --- a/xlators/features/glupy/src/glupy.c +++ b/xlators/features/glupy/src/glupy.c @@ -2365,7 +2365,7 @@ init (xlator_t *this) goto *err_cleanup; } - gf_log (this->name, GF_LOG_ERROR, "py_mod_name = %s", module_name); + gf_log (this->name, GF_LOG_DEBUG, "py_mod_name = %s", module_name); priv->py_module = PyImport_Import(py_mod_name); Py_DECREF(py_mod_name); if (!priv->py_module) { @@ -2375,6 +2375,7 @@ init (xlator_t *this) } goto *err_cleanup; } + gf_log (this->name, GF_LOG_INFO, "Import of %s succeeded", module_name); err_cleanup = &&err_deref_module; py_init_func = PyObject_GetAttrString(priv->py_module, "xlator"); @@ -2407,7 +2408,7 @@ init (xlator_t *this) } goto *err_cleanup; } - gf_log (this->name, GF_LOG_INFO, "init returned %p", priv->py_xlator); + gf_log (this->name, GF_LOG_DEBUG, "init returned %p", priv->py_xlator); return 0; diff --git a/xlators/features/glupy/src/glupy.py b/xlators/features/glupy/src/glupy.py new file mode 100644 index 00000000000..a5daa77d32a --- /dev/null +++ b/xlators/features/glupy/src/glupy.py @@ -0,0 +1,841 @@ +import sys +from ctypes import * + +dl = CDLL("",RTLD_GLOBAL) + + +class call_frame_t (Structure): + pass + +class dev_t (Structure): + pass + + +class dict_t (Structure): + pass + + +class gf_dirent_t (Structure): + pass + + +class iobref_t (Structure): + pass + + +class iovec_t (Structure): + pass + + +class list_head (Structure): + pass + +list_head._fields_ = [ + ("next", POINTER(list_head)), + ("prev", POINTER(list_head)) + ] + + +class rwxperm_t (Structure): + _fields_ = [ + ("read", c_uint8, 1), + ("write", c_uint8, 1), + ("execn", c_uint8, 1) + ] + + +class statvfs_t (Structure): + pass + + +class xlator_t (Structure): + pass + + +class ia_prot_t (Structure): + _fields_ = [ + ("suid", c_uint8, 1), + ("sgid", c_uint8, 1), + ("sticky", c_uint8, 1), + ("owner", rwxperm_t), + ("group", rwxperm_t), + ("other", rwxperm_t) + ] + +# For checking file type. +(IA_INVAL, IA_IFREG, IA_IFDIR, IA_IFLNK, IA_IFBLK, IA_IFCHR, IA_IFIFO, + IA_IFSOCK) = xrange(8) + + +class iatt_t (Structure): + _fields_ = [ + ("ia_no", c_uint64), + ("ia_gfid", c_ubyte * 16), + ("ia_dev", c_uint64), + ("ia_type", c_uint), + ("ia_prot", ia_prot_t), + ("ia_nlink", c_uint32), + ("ia_uid", c_uint32), + ("ia_gid", c_uint32), + ("ia_rdev", c_uint64), + ("ia_size", c_uint64), + ("ia_blksize", c_uint32), + ("ia_blocks", c_uint64), + ("ia_atime", c_uint32 ), + ("ia_atime_nsec", c_uint32), + ("ia_mtime", c_uint32), + ("ia_mtime_nsec", c_uint32), + ("ia_ctime", c_uint32), + ("ia_ctime_nsec", c_uint32) + ] + + +class mem_pool (Structure): + _fields_ = [ + ("list", list_head), + ("hot_count", c_int), + ("cold_count", c_int), + ("lock", c_void_p), + ("padded_sizeof_type", c_ulong), + ("pool", c_void_p), + ("pool_end", c_void_p), + ("real_sizeof_type", c_int), + ("alloc_count", c_uint64), + ("pool_misses", c_uint64), + ("max_alloc", c_int), + ("curr_stdalloc", c_int), + ("max_stdalloc", c_int), + ("name", c_char_p), + ("global_list", list_head) + ] + + +class U_ctx_key_inode (Union): + _fields_ = [ + ("key", c_uint64), + ("xl_key", POINTER(xlator_t)) + ] + + +class U_ctx_value1 (Union): + _fields_ = [ + ("value1", c_uint64), + ("ptr1", c_void_p) + ] + + +class U_ctx_value2 (Union): + _fields_ = [ + ("value2", c_uint64), + ("ptr2", c_void_p) + ] + +class inode_ctx (Structure): + _anonymous_ = ("u_key","u_value1","u_value2",) + _fields_ = [ + ("u_key", U_ctx_key_inode), + ("u_value1", U_ctx_value1), + ("u_value2", U_ctx_value2) + ] + +class inode_t (Structure): + pass + +class inode_table_t (Structure): + _fields_ = [ + ("lock", c_void_p), + ("hashsize", c_size_t), + ("name", c_char_p), + ("root", POINTER(inode_t)), + ("xl", POINTER(xlator_t)), + ("lru_limit", c_uint32), + ("inode_hash", POINTER(list_head)), + ("name_hash", POINTER(list_head)), + ("active", list_head), + ("active_size", c_uint32), + ("lru", list_head), + ("lru_size", c_uint32), + ("purge", list_head), + ("purge_size", c_uint32), + ("inode_pool", POINTER(mem_pool)), + ("dentry_pool", POINTER(mem_pool)), + ("fd_mem_pool", POINTER(mem_pool)) + ] + +inode_t._fields_ = [ + ("table", POINTER(inode_table_t)), + ("gfid", c_ubyte * 16), + ("lock", c_void_p), + ("nlookup", c_uint64), + ("fd_count", c_uint32), + ("ref", c_uint32), + ("ia_type", c_uint), + ("fd_list", list_head), + ("dentry_list", list_head), + ("hashv", list_head), + ("listv", list_head), + ("ctx", POINTER(inode_ctx)) + ] + + + +class U_ctx_key_fd (Union): + _fields_ = [ + ("key", c_uint64), + ("xl_key", c_void_p) + ] + +class fd_lk_ctx (Structure): + _fields_ = [ + ("lk_list", list_head), + ("ref", c_int), + ("lock", c_void_p) + ] + +class fd_ctx (Structure): + _anonymous_ = ("u_key","u_value1") + _fields_ = [ + ("u_key", U_ctx_key_fd), + ("u_value1", U_ctx_value1) + ] + +class fd_t (Structure): + _fields_ = [ + ("pid", c_uint64), + ("flags", c_int32), + ("refcount", c_int32), + ("inode_list", list_head), + ("inode", POINTER(inode_t)), + ("lock", c_void_p), + ("ctx", POINTER(fd_ctx)), + ("xl_count", c_int), + ("lk_ctx", POINTER(fd_lk_ctx)), + ("anonymous", c_uint) + ] + +class loc_t (Structure): + _fields_ = [ + ("path", c_char_p), + ("name", c_char_p), + ("inode", POINTER(inode_t)), + ("parent", POINTER(inode_t)), + ("gfid", c_ubyte * 16), + ("pargfid", c_ubyte * 16), + ] + + + +def _init_op (a_class, fop, cbk, wind, unwind): + # Decorators, used by translators. We could pass the signatures as + # parameters, but it's actually kind of nice to keep them around for + # inspection. + a_class.fop_type = apply(CFUNCTYPE,a_class.fop_sig) + a_class.cbk_type = apply(CFUNCTYPE,a_class.cbk_sig) + # Dispatch-function registration. + fop.restype = None + fop.argtypes = [ c_long, a_class.fop_type ] + # Callback-function registration. + cbk.restype = None + cbk.argtypes = [ c_long, a_class.cbk_type ] + # STACK_WIND function. + wind.restype = None + wind.argtypes = list(a_class.fop_sig[1:]) + # STACK_UNWIND function. + unwind.restype = None + unwind.argtypes = list(a_class.cbk_sig[1:]) + +class OpLookup: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(inode_t), POINTER(iatt_t), + POINTER(dict_t), POINTER(iatt_t)) +_init_op (OpLookup, dl.set_lookup_fop, dl.set_lookup_cbk, + dl.wind_lookup, dl.unwind_lookup) + +class OpCreate: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_int, c_uint, c_uint, POINTER(fd_t), + POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(fd_t), POINTER(inode_t), + POINTER(iatt_t), POINTER(iatt_t), POINTER(iatt_t), + POINTER(dict_t)) +_init_op (OpCreate, dl.set_create_fop, dl.set_create_cbk, + dl.wind_create, dl.unwind_create) + +class OpOpen: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_int, POINTER(fd_t), POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(fd_t), POINTER(dict_t)) +_init_op (OpOpen, dl.set_open_fop, dl.set_open_cbk, + dl.wind_open, dl.unwind_open) + +class OpReadv: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), c_size_t, c_long, c_uint32, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(iovec_t), c_int, POINTER(iatt_t), + POINTER(iobref_t), POINTER(dict_t)) +_init_op (OpReadv, dl.set_readv_fop, dl.set_readv_cbk, + dl.wind_readv, dl.unwind_readv) +class OpWritev: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), POINTER(iovec_t), c_int, c_long, c_uint32, + POINTER(iobref_t), POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(iatt_t), POINTER(iatt_t), + POINTER(dict_t)) +_init_op (OpWritev, dl.set_writev_fop, dl.set_writev_cbk, + dl.wind_writev, dl.unwind_writev) + +class OpOpendir: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), POINTER(fd_t) ,POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(fd_t), POINTER(dict_t)) +_init_op (OpOpendir, dl.set_opendir_fop, dl.set_opendir_cbk, + dl.wind_opendir, dl.unwind_opendir) + +class OpReaddir: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), c_size_t, c_long, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(gf_dirent_t), POINTER(dict_t)) +_init_op (OpReaddir, dl.set_readdir_fop, dl.set_readdir_cbk, + dl.wind_readdir, dl.unwind_readdir) + +class OpReaddirp: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), c_size_t, c_long, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(gf_dirent_t), POINTER(dict_t)) +_init_op (OpReaddirp, dl.set_readdirp_fop, dl.set_readdirp_cbk, + dl.wind_readdirp, dl.unwind_readdirp) + +class OpStat: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(iatt_t), POINTER(dict_t)) +_init_op (OpStat, dl.set_stat_fop, dl.set_stat_cbk, + dl.wind_stat, dl.unwind_stat) + +class OpFstat: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(iatt_t), POINTER(dict_t)) +_init_op (OpFstat, dl.set_fstat_fop, dl.set_fstat_cbk, + dl.wind_fstat, dl.unwind_fstat) + +class OpStatfs: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(statvfs_t), POINTER(dict_t)) +_init_op (OpStatfs, dl.set_statfs_fop, dl.set_statfs_cbk, + dl.wind_statfs, dl.unwind_statfs) + + +class OpSetxattr: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), POINTER(dict_t), c_int32, + POINTER (dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(dict_t)) +_init_op (OpSetxattr, dl.set_setxattr_fop, dl.set_setxattr_cbk, + dl.wind_setxattr, dl.unwind_setxattr) + +class OpGetxattr: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_char_p, POINTER (dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(dict_t), POINTER(dict_t)) +_init_op (OpGetxattr, dl.set_getxattr_fop, dl.set_getxattr_cbk, + dl.wind_getxattr, dl.unwind_getxattr) + +class OpFsetxattr: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), POINTER(dict_t), c_int32, + POINTER (dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(dict_t)) +_init_op (OpFsetxattr, dl.set_fsetxattr_fop, dl.set_fsetxattr_cbk, + dl.wind_fsetxattr, dl.unwind_fsetxattr) + +class OpFgetxattr: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), c_char_p, POINTER (dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(dict_t), POINTER(dict_t)) +_init_op (OpFgetxattr, dl.set_fgetxattr_fop, dl.set_fgetxattr_cbk, + dl.wind_fgetxattr, dl.unwind_fgetxattr) + +class OpRemovexattr: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_char_p, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(dict_t)) +_init_op (OpRemovexattr, dl.set_removexattr_fop, dl.set_removexattr_cbk, + dl.wind_removexattr, dl.unwind_removexattr) + + +class OpFremovexattr: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(fd_t), c_char_p, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(dict_t)) +_init_op (OpFremovexattr, dl.set_fremovexattr_fop, dl.set_fremovexattr_cbk, + dl.wind_fremovexattr, dl.unwind_fremovexattr) + +class OpLink: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), POINTER(loc_t), POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(inode_t), POINTER(iatt_t), + POINTER(iatt_t), POINTER(iatt_t), POINTER(dict_t)) +_init_op (OpLink, dl.set_link_fop, dl.set_link_cbk, + dl.wind_link, dl.unwind_link) + +class OpSymlink: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + c_char_p, POINTER(loc_t), c_uint, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(inode_t), POINTER(iatt_t), + POINTER(iatt_t), POINTER(iatt_t), POINTER(dict_t)) +_init_op (OpSymlink, dl.set_symlink_fop, dl.set_symlink_cbk, + dl.wind_symlink, dl.unwind_symlink) + +class OpUnlink: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_int, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(iatt_t), POINTER(iatt_t), + POINTER(dict_t)) +_init_op (OpUnlink, dl.set_unlink_fop, dl.set_unlink_cbk, + dl.wind_unlink, dl.unwind_unlink) + +class OpReadlink: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_size_t, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, c_char_p, POINTER(iatt_t), POINTER(dict_t)) +_init_op (OpReadlink, dl.set_readlink_fop, dl.set_readlink_cbk, + dl.wind_readlink, dl.unwind_readlink) + +class OpMkdir: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_uint, c_uint, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(inode_t), POINTER(iatt_t), + POINTER(iatt_t), POINTER(iatt_t), POINTER(dict_t)) +_init_op (OpMkdir, dl.set_mkdir_fop, dl.set_mkdir_cbk, + dl.wind_mkdir, dl.unwind_mkdir) + +class OpRmdir: + fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), + POINTER(loc_t), c_int, POINTER(dict_t)) + cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), + c_int, c_int, POINTER(iatt_t), POINTER(iatt_t), + POINTER(dict_t)) +_init_op (OpRmdir, dl.set_rmdir_fop, dl.set_rmdir_cbk, + dl.wind_rmdir, dl.unwind_rmdir) + + +class Translator: + def __init__ (self, c_this): + # This is only here to keep references to the stubs we create, + # because ctypes doesn't and glupy.so can't because it doesn't + # get a pointer to the actual Python object. It's a dictionary + # instead of a list in case we ever allow changing fops/cbks + # after initialization and need to look them up. + self.stub_refs = {} + funcs = dir(self.__class__) + if "lookup_fop" in funcs: + @OpLookup.fop_type + def stub (frame, this, loc, xdata, s=self): + return s.lookup_fop (frame, this, loc, xdata) + self.stub_refs["lookup_fop"] = stub + dl.set_lookup_fop(c_this,stub) + if "lookup_cbk" in funcs: + @OpLookup.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, inode, + buf, xdata, postparent, s=self): + return s.lookup_cbk(frame, cookie, this, op_ret, + op_errno, inode, buf, xdata, + postparent) + self.stub_refs["lookup_cbk"] = stub + dl.set_lookup_cbk(c_this,stub) + if "create_fop" in funcs: + @OpCreate.fop_type + def stub (frame, this, loc, flags, mode, umask, fd, + xdata, s=self): + return s.create_fop (frame, this, loc, flags, + mode, umask, fd, xdata) + self.stub_refs["create_fop"] = stub + dl.set_create_fop(c_this,stub) + if "create_cbk" in funcs: + @OpCreate.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, fd, + inode, buf, preparent, postparent, xdata, + s=self): + return s.create_cbk (frame, cookie, this, + op_ret, op_errno, fd, + inode, buf, preparent, + postparent, xdata) + self.stub_refs["create_cbk"] = stub + dl.set_create_cbk(c_this,stub) + if "open_fop" in funcs: + @OpOpen.fop_type + def stub (frame, this, loc, flags, fd, + xdata, s=self): + return s.open_fop (frame, this, loc, flags, + fd, xdata) + self.stub_refs["open_fop"] = stub + dl.set_open_fop(c_this,stub) + if "open_cbk" in funcs: + @OpOpen.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, fd, + xdata, s=self): + return s.open_cbk (frame, cookie, this, + op_ret, op_errno, fd, + xdata) + self.stub_refs["open_cbk"] = stub + dl.set_open_cbk(c_this,stub) + if "readv_fop" in funcs: + @OpReadv.fop_type + def stub (frame, this, fd, size, offset, flags, + xdata, s=self): + return s.readv_fop (frame, this, fd, size, + offset, flags, xdata) + self.stub_refs["readv_fop"] = stub + dl.set_readv_fop(c_this,stub) + if "readv_cbk" in funcs: + @OpReadv.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + vector, count, stbuf, iobref, xdata, + s=self): + return s.readv_cbk (frame, cookie, this, + op_ret, op_errno, vector, + count, stbuf, iobref, + xdata) + self.stub_refs["readv_cbk"] = stub + dl.set_readv_cbk(c_this,stub) + if "writev_fop" in funcs: + @OpWritev.fop_type + def stub (frame, this, fd, vector, count, + offset, flags, iobref, xdata, s=self): + return s.writev_fop (frame, this, fd, vector, + count, offset, flags, + iobref, xdata) + self.stub_refs["writev_fop"] = stub + dl.set_writev_fop(c_this,stub) + if "writev_cbk" in funcs: + @OpWritev.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + prebuf, postbuf, xdata, s=self): + return s.writev_cbk (frame, cookie, this, + op_ret, op_errno, prebuf, + postbuf, xdata) + self.stub_refs["writev_cbk"] = stub + dl.set_writev_cbk(c_this,stub) + if "opendir_fop" in funcs: + @OpOpendir.fop_type + def stub (frame, this, loc, fd, xdata, s=self): + return s.opendir_fop (frame, this, loc, fd, + xdata) + self.stub_refs["opendir_fop"] = stub + dl.set_opendir_fop(c_this,stub) + if "opendir_cbk" in funcs: + @OpOpendir.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, fd, + xdata, s=self): + return s.opendir_cbk(frame, cookie, this, + op_ret, op_errno, fd, + xdata) + self.stub_refs["opendir_cbk"] = stub + dl.set_opendir_cbk(c_this,stub) + if "readdir_fop" in funcs: + @OpReaddir.fop_type + def stub (frame, this, fd, size, offset, xdata, s=self): + return s.readdir_fop (frame, this, fd, size, + offset, xdata) + self.stub_refs["readdir_fop"] = stub + dl.set_readdir_fop(c_this,stub) + if "readdir_cbk" in funcs: + @OpReaddir.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + entries, xdata, s=self): + return s.readdir_cbk(frame, cookie, this, + op_ret, op_errno, entries, + xdata) + self.stub_refs["readdir_cbk"] = stub + dl.set_readdir_cbk(c_this,stub) + if "readdirp_fop" in funcs: + @OpReaddirp.fop_type + def stub (frame, this, fd, size, offset, xdata, s=self): + return s.readdirp_fop (frame, this, fd, size, + offset, xdata) + self.stub_refs["readdirp_fop"] = stub + dl.set_readdirp_fop(c_this,stub) + if "readdirp_cbk" in funcs: + @OpReaddirp.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + entries, xdata, s=self): + return s.readdirp_cbk (frame, cookie, this, + op_ret, op_errno, + entries, xdata) + self.stub_refs["readdirp_cbk"] = stub + dl.set_readdirp_cbk(c_this,stub) + if "stat_fop" in funcs: + @OpStat.fop_type + def stub (frame, this, loc, xdata, s=self): + return s.stat_fop (frame, this, loc, xdata) + self.stub_refs["stat_fop"] = stub + dl.set_stat_fop(c_this,stub) + if "stat_cbk" in funcs: + @OpStat.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, buf, + xdata, s=self): + return s.stat_cbk(frame, cookie, this, op_ret, + op_errno, buf, xdata) + self.stub_refs["stat_cbk"] = stub + dl.set_stat_cbk(c_this,stub) + if "fstat_fop" in funcs: + @OpFstat.fop_type + def stub (frame, this, fd, xdata, s=self): + return s.fstat_fop (frame, this, fd, xdata) + self.stub_refs["fstat_fop"] = stub + dl.set_fstat_fop(c_this,stub) + if "fstat_cbk" in funcs: + @OpFstat.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, buf, + xdata, s=self): + return s.fstat_cbk(frame, cookie, this, op_ret, + op_errno, buf, xdata) + self.stub_refs["fstat_cbk"] = stub + dl.set_fstat_cbk(c_this,stub) + if "statfs_fop" in funcs: + @OpStatfs.fop_type + def stub (frame, this, loc, xdata, s=self): + return s.statfs_fop (frame, this, loc, xdata) + self.stub_refs["statfs_fop"] = stub + dl.set_statfs_fop(c_this,stub) + if "statfs_cbk" in funcs: + @OpStatfs.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, buf, + xdata, s=self): + return s.statfs_cbk (frame, cookie, this, + op_ret, op_errno, buf, + xdata) + self.stub_refs["statfs_cbk"] = stub + dl.set_statfs_cbk(c_this,stub) + if "setxattr_fop" in funcs: + @OpSetxattr.fop_type + def stub (frame, this, loc, dictionary, flags, xdata, + s=self): + return s.setxattr_fop (frame, this, loc, + dictionary, flags, + xdata) + self.stub_refs["setxattr_fop"] = stub + dl.set_setxattr_fop(c_this,stub) + if "setxattr_cbk" in funcs: + @OpSetxattr.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, xdata, + s=self): + return s.setxattr_cbk(frame, cookie, this, + op_ret, op_errno, xdata) + self.stub_refs["setxattr_cbk"] = stub + dl.set_setxattr_cbk(c_this,stub) + if "getxattr_fop" in funcs: + @OpGetxattr.fop_type + def stub (frame, this, loc, name, xdata, s=self): + return s.getxattr_fop (frame, this, loc, name, + xdata) + self.stub_refs["getxattr_fop"] = stub + dl.set_getxattr_fop(c_this,stub) + if "getxattr_cbk" in funcs: + @OpGetxattr.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + dictionary, xdata, s=self): + return s.getxattr_cbk(frame, cookie, this, + op_ret, op_errno, + dictionary, xdata) + self.stub_refs["getxattr_cbk"] = stub + dl.set_getxattr_cbk(c_this,stub) + if "fsetxattr_fop" in funcs: + @OpFsetxattr.fop_type + def stub (frame, this, fd, dictionary, flags, xdata, + s=self): + return s.fsetxattr_fop (frame, this, fd, + dictionary, flags, + xdata) + self.stub_refs["fsetxattr_fop"] = stub + dl.set_fsetxattr_fop(c_this,stub) + if "fsetxattr_cbk" in funcs: + @OpFsetxattr.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, xdata, + s=self): + return s.fsetxattr_cbk(frame, cookie, this, + op_ret, op_errno, xdata) + self.stub_refs["fsetxattr_cbk"] = stub + dl.set_fsetxattr_cbk(c_this,stub) + if "fgetxattr_fop" in funcs: + @OpFgetxattr.fop_type + def stub (frame, this, fd, name, xdata, s=self): + return s.fgetxattr_fop (frame, this, fd, name, + xdata) + self.stub_refs["fgetxattr_fop"] = stub + dl.set_fgetxattr_fop(c_this,stub) + if "fgetxattr_cbk" in funcs: + @OpFgetxattr.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + dictionary, xdata, s=self): + return s.fgetxattr_cbk(frame, cookie, this, + op_ret, op_errno, + dictionary, xdata) + self.stub_refs["fgetxattr_cbk"] = stub + dl.set_fgetxattr_cbk(c_this,stub) + if "removexattr_fop" in funcs: + @OpRemovexattr.fop_type + def stub (frame, this, loc, name, xdata, s=self): + return s.removexattr_fop (frame, this, loc, + name, xdata) + self.stub_refs["removexattr_fop"] = stub + dl.set_removexattr_fop(c_this,stub) + if "removexattr_cbk" in funcs: + @OpRemovexattr.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + xdata, s=self): + return s.removexattr_cbk(frame, cookie, this, + op_ret, op_errno, + xdata) + self.stub_refs["removexattr_cbk"] = stub + dl.set_removexattr_cbk(c_this,stub) + if "fremovexattr_fop" in funcs: + @OpFremovexattr.fop_type + def stub (frame, this, fd, name, xdata, s=self): + return s.fremovexattr_fop (frame, this, fd, + name, xdata) + self.stub_refs["fremovexattr_fop"] = stub + dl.set_fremovexattr_fop(c_this,stub) + if "fremovexattr_cbk" in funcs: + @OpFremovexattr.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + xdata, s=self): + return s.fremovexattr_cbk(frame, cookie, this, + op_ret, op_errno, + xdata) + self.stub_refs["fremovexattr_cbk"] = stub + dl.set_fremovexattr_cbk(c_this,stub) + if "link_fop" in funcs: + @OpLink.fop_type + def stub (frame, this, oldloc, newloc, + xdata, s=self): + return s.link_fop (frame, this, oldloc, + newloc, xdata) + self.stub_refs["link_fop"] = stub + dl.set_link_fop(c_this,stub) + if "link_cbk" in funcs: + @OpLink.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + inode, buf, preparent, postparent, xdata, + s=self): + return s.link_cbk (frame, cookie, this, + op_ret, op_errno, inode, + buf, preparent, + postparent, xdata) + self.stub_refs["link_cbk"] = stub + dl.set_link_cbk(c_this,stub) + if "symlink_fop" in funcs: + @OpSymlink.fop_type + def stub (frame, this, linkname, loc, + umask, xdata, s=self): + return s.symlink_fop (frame, this, linkname, + loc, umask, xdata) + self.stub_refs["symlink_fop"] = stub + dl.set_symlink_fop(c_this,stub) + if "symlink_cbk" in funcs: + @OpSymlink.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + inode, buf, preparent, postparent, xdata, + s=self): + return s.symlink_cbk (frame, cookie, this, + op_ret, op_errno, inode, + buf, preparent, + postparent, xdata) + self.stub_refs["symlink_cbk"] = stub + dl.set_symlink_cbk(c_this,stub) + if "unlink_fop" in funcs: + @OpUnlink.fop_type + def stub (frame, this, loc, xflags, + xdata, s=self): + return s.unlink_fop (frame, this, loc, + xflags, xdata) + self.stub_refs["unlink_fop"] = stub + dl.set_unlink_fop(c_this,stub) + if "unlink_cbk" in funcs: + @OpUnlink.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + preparent, postparent, xdata, s=self): + return s.unlink_cbk (frame, cookie, this, + op_ret, op_errno, + preparent, postparent, + xdata) + self.stub_refs["unlink_cbk"] = stub + dl.set_unlink_cbk(c_this,stub) + if "readlink_fop" in funcs: + @OpReadlink.fop_type + def stub (frame, this, loc, size, + xdata, s=self): + return s.readlink_fop (frame, this, loc, + size, xdata) + self.stub_refs["readlink_fop"] = stub + dl.set_readlink_fop(c_this,stub) + if "readlink_cbk" in funcs: + @OpReadlink.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + path, buf, xdata, s=self): + return s.readlink_cbk (frame, cookie, this, + op_ret, op_errno, + path, buf, xdata) + self.stub_refs["readlink_cbk"] = stub + dl.set_readlink_cbk(c_this,stub) + if "mkdir_fop" in funcs: + @OpMkdir.fop_type + def stub (frame, this, loc, mode, umask, xdata, + s=self): + return s.mkdir_fop (frame, this, loc, mode, + umask, xdata) + self.stub_refs["mkdir_fop"] = stub + dl.set_mkdir_fop(c_this,stub) + if "mkdir_cbk" in funcs: + @OpMkdir.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, inode, + buf, preparent, postparent, xdata, s=self): + return s.mkdir_cbk (frame, cookie, this, + op_ret, op_errno, inode, + buf, preparent, + postparent, xdata) + self.stub_refs["mkdir_cbk"] = stub + dl.set_mkdir_cbk(c_this,stub) + if "rmdir_fop" in funcs: + @OpRmdir.fop_type + def stub (frame, this, loc, xflags, + xdata, s=self): + return s.rmdir_fop (frame, this, loc, + xflags, xdata) + self.stub_refs["rmdir_fop"] = stub + dl.set_rmdir_fop(c_this,stub) + if "rmdir_cbk" in funcs: + @OpRmdir.cbk_type + def stub (frame, cookie, this, op_ret, op_errno, + preparent, postparent, xdata, s=self): + return s.rmdir_cbk (frame, cookie, this, + op_ret, op_errno, + preparent, postparent, + xdata) + self.stub_refs["rmdir_cbk"] = stub + dl.set_rmdir_cbk(c_this,stub) diff --git a/xlators/features/glupy/src/gluster.py b/xlators/features/glupy/src/gluster.py deleted file mode 100644 index a5daa77d32a..00000000000 --- a/xlators/features/glupy/src/gluster.py +++ /dev/null @@ -1,841 +0,0 @@ -import sys -from ctypes import * - -dl = CDLL("",RTLD_GLOBAL) - - -class call_frame_t (Structure): - pass - -class dev_t (Structure): - pass - - -class dict_t (Structure): - pass - - -class gf_dirent_t (Structure): - pass - - -class iobref_t (Structure): - pass - - -class iovec_t (Structure): - pass - - -class list_head (Structure): - pass - -list_head._fields_ = [ - ("next", POINTER(list_head)), - ("prev", POINTER(list_head)) - ] - - -class rwxperm_t (Structure): - _fields_ = [ - ("read", c_uint8, 1), - ("write", c_uint8, 1), - ("execn", c_uint8, 1) - ] - - -class statvfs_t (Structure): - pass - - -class xlator_t (Structure): - pass - - -class ia_prot_t (Structure): - _fields_ = [ - ("suid", c_uint8, 1), - ("sgid", c_uint8, 1), - ("sticky", c_uint8, 1), - ("owner", rwxperm_t), - ("group", rwxperm_t), - ("other", rwxperm_t) - ] - -# For checking file type. -(IA_INVAL, IA_IFREG, IA_IFDIR, IA_IFLNK, IA_IFBLK, IA_IFCHR, IA_IFIFO, - IA_IFSOCK) = xrange(8) - - -class iatt_t (Structure): - _fields_ = [ - ("ia_no", c_uint64), - ("ia_gfid", c_ubyte * 16), - ("ia_dev", c_uint64), - ("ia_type", c_uint), - ("ia_prot", ia_prot_t), - ("ia_nlink", c_uint32), - ("ia_uid", c_uint32), - ("ia_gid", c_uint32), - ("ia_rdev", c_uint64), - ("ia_size", c_uint64), - ("ia_blksize", c_uint32), - ("ia_blocks", c_uint64), - ("ia_atime", c_uint32 ), - ("ia_atime_nsec", c_uint32), - ("ia_mtime", c_uint32), - ("ia_mtime_nsec", c_uint32), - ("ia_ctime", c_uint32), - ("ia_ctime_nsec", c_uint32) - ] - - -class mem_pool (Structure): - _fields_ = [ - ("list", list_head), - ("hot_count", c_int), - ("cold_count", c_int), - ("lock", c_void_p), - ("padded_sizeof_type", c_ulong), - ("pool", c_void_p), - ("pool_end", c_void_p), - ("real_sizeof_type", c_int), - ("alloc_count", c_uint64), - ("pool_misses", c_uint64), - ("max_alloc", c_int), - ("curr_stdalloc", c_int), - ("max_stdalloc", c_int), - ("name", c_char_p), - ("global_list", list_head) - ] - - -class U_ctx_key_inode (Union): - _fields_ = [ - ("key", c_uint64), - ("xl_key", POINTER(xlator_t)) - ] - - -class U_ctx_value1 (Union): - _fields_ = [ - ("value1", c_uint64), - ("ptr1", c_void_p) - ] - - -class U_ctx_value2 (Union): - _fields_ = [ - ("value2", c_uint64), - ("ptr2", c_void_p) - ] - -class inode_ctx (Structure): - _anonymous_ = ("u_key","u_value1","u_value2",) - _fields_ = [ - ("u_key", U_ctx_key_inode), - ("u_value1", U_ctx_value1), - ("u_value2", U_ctx_value2) - ] - -class inode_t (Structure): - pass - -class inode_table_t (Structure): - _fields_ = [ - ("lock", c_void_p), - ("hashsize", c_size_t), - ("name", c_char_p), - ("root", POINTER(inode_t)), - ("xl", POINTER(xlator_t)), - ("lru_limit", c_uint32), - ("inode_hash", POINTER(list_head)), - ("name_hash", POINTER(list_head)), - ("active", list_head), - ("active_size", c_uint32), - ("lru", list_head), - ("lru_size", c_uint32), - ("purge", list_head), - ("purge_size", c_uint32), - ("inode_pool", POINTER(mem_pool)), - ("dentry_pool", POINTER(mem_pool)), - ("fd_mem_pool", POINTER(mem_pool)) - ] - -inode_t._fields_ = [ - ("table", POINTER(inode_table_t)), - ("gfid", c_ubyte * 16), - ("lock", c_void_p), - ("nlookup", c_uint64), - ("fd_count", c_uint32), - ("ref", c_uint32), - ("ia_type", c_uint), - ("fd_list", list_head), - ("dentry_list", list_head), - ("hashv", list_head), - ("listv", list_head), - ("ctx", POINTER(inode_ctx)) - ] - - - -class U_ctx_key_fd (Union): - _fields_ = [ - ("key", c_uint64), - ("xl_key", c_void_p) - ] - -class fd_lk_ctx (Structure): - _fields_ = [ - ("lk_list", list_head), - ("ref", c_int), - ("lock", c_void_p) - ] - -class fd_ctx (Structure): - _anonymous_ = ("u_key","u_value1") - _fields_ = [ - ("u_key", U_ctx_key_fd), - ("u_value1", U_ctx_value1) - ] - -class fd_t (Structure): - _fields_ = [ - ("pid", c_uint64), - ("flags", c_int32), - ("refcount", c_int32), - ("inode_list", list_head), - ("inode", POINTER(inode_t)), - ("lock", c_void_p), - ("ctx", POINTER(fd_ctx)), - ("xl_count", c_int), - ("lk_ctx", POINTER(fd_lk_ctx)), - ("anonymous", c_uint) - ] - -class loc_t (Structure): - _fields_ = [ - ("path", c_char_p), - ("name", c_char_p), - ("inode", POINTER(inode_t)), - ("parent", POINTER(inode_t)), - ("gfid", c_ubyte * 16), - ("pargfid", c_ubyte * 16), - ] - - - -def _init_op (a_class, fop, cbk, wind, unwind): - # Decorators, used by translators. We could pass the signatures as - # parameters, but it's actually kind of nice to keep them around for - # inspection. - a_class.fop_type = apply(CFUNCTYPE,a_class.fop_sig) - a_class.cbk_type = apply(CFUNCTYPE,a_class.cbk_sig) - # Dispatch-function registration. - fop.restype = None - fop.argtypes = [ c_long, a_class.fop_type ] - # Callback-function registration. - cbk.restype = None - cbk.argtypes = [ c_long, a_class.cbk_type ] - # STACK_WIND function. - wind.restype = None - wind.argtypes = list(a_class.fop_sig[1:]) - # STACK_UNWIND function. - unwind.restype = None - unwind.argtypes = list(a_class.cbk_sig[1:]) - -class OpLookup: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(inode_t), POINTER(iatt_t), - POINTER(dict_t), POINTER(iatt_t)) -_init_op (OpLookup, dl.set_lookup_fop, dl.set_lookup_cbk, - dl.wind_lookup, dl.unwind_lookup) - -class OpCreate: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_int, c_uint, c_uint, POINTER(fd_t), - POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(fd_t), POINTER(inode_t), - POINTER(iatt_t), POINTER(iatt_t), POINTER(iatt_t), - POINTER(dict_t)) -_init_op (OpCreate, dl.set_create_fop, dl.set_create_cbk, - dl.wind_create, dl.unwind_create) - -class OpOpen: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_int, POINTER(fd_t), POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(fd_t), POINTER(dict_t)) -_init_op (OpOpen, dl.set_open_fop, dl.set_open_cbk, - dl.wind_open, dl.unwind_open) - -class OpReadv: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), c_size_t, c_long, c_uint32, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(iovec_t), c_int, POINTER(iatt_t), - POINTER(iobref_t), POINTER(dict_t)) -_init_op (OpReadv, dl.set_readv_fop, dl.set_readv_cbk, - dl.wind_readv, dl.unwind_readv) -class OpWritev: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), POINTER(iovec_t), c_int, c_long, c_uint32, - POINTER(iobref_t), POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(iatt_t), POINTER(iatt_t), - POINTER(dict_t)) -_init_op (OpWritev, dl.set_writev_fop, dl.set_writev_cbk, - dl.wind_writev, dl.unwind_writev) - -class OpOpendir: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), POINTER(fd_t) ,POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(fd_t), POINTER(dict_t)) -_init_op (OpOpendir, dl.set_opendir_fop, dl.set_opendir_cbk, - dl.wind_opendir, dl.unwind_opendir) - -class OpReaddir: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), c_size_t, c_long, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(gf_dirent_t), POINTER(dict_t)) -_init_op (OpReaddir, dl.set_readdir_fop, dl.set_readdir_cbk, - dl.wind_readdir, dl.unwind_readdir) - -class OpReaddirp: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), c_size_t, c_long, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(gf_dirent_t), POINTER(dict_t)) -_init_op (OpReaddirp, dl.set_readdirp_fop, dl.set_readdirp_cbk, - dl.wind_readdirp, dl.unwind_readdirp) - -class OpStat: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(iatt_t), POINTER(dict_t)) -_init_op (OpStat, dl.set_stat_fop, dl.set_stat_cbk, - dl.wind_stat, dl.unwind_stat) - -class OpFstat: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(iatt_t), POINTER(dict_t)) -_init_op (OpFstat, dl.set_fstat_fop, dl.set_fstat_cbk, - dl.wind_fstat, dl.unwind_fstat) - -class OpStatfs: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(statvfs_t), POINTER(dict_t)) -_init_op (OpStatfs, dl.set_statfs_fop, dl.set_statfs_cbk, - dl.wind_statfs, dl.unwind_statfs) - - -class OpSetxattr: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), POINTER(dict_t), c_int32, - POINTER (dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(dict_t)) -_init_op (OpSetxattr, dl.set_setxattr_fop, dl.set_setxattr_cbk, - dl.wind_setxattr, dl.unwind_setxattr) - -class OpGetxattr: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_char_p, POINTER (dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(dict_t), POINTER(dict_t)) -_init_op (OpGetxattr, dl.set_getxattr_fop, dl.set_getxattr_cbk, - dl.wind_getxattr, dl.unwind_getxattr) - -class OpFsetxattr: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), POINTER(dict_t), c_int32, - POINTER (dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(dict_t)) -_init_op (OpFsetxattr, dl.set_fsetxattr_fop, dl.set_fsetxattr_cbk, - dl.wind_fsetxattr, dl.unwind_fsetxattr) - -class OpFgetxattr: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), c_char_p, POINTER (dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(dict_t), POINTER(dict_t)) -_init_op (OpFgetxattr, dl.set_fgetxattr_fop, dl.set_fgetxattr_cbk, - dl.wind_fgetxattr, dl.unwind_fgetxattr) - -class OpRemovexattr: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_char_p, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(dict_t)) -_init_op (OpRemovexattr, dl.set_removexattr_fop, dl.set_removexattr_cbk, - dl.wind_removexattr, dl.unwind_removexattr) - - -class OpFremovexattr: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(fd_t), c_char_p, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(dict_t)) -_init_op (OpFremovexattr, dl.set_fremovexattr_fop, dl.set_fremovexattr_cbk, - dl.wind_fremovexattr, dl.unwind_fremovexattr) - -class OpLink: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), POINTER(loc_t), POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(inode_t), POINTER(iatt_t), - POINTER(iatt_t), POINTER(iatt_t), POINTER(dict_t)) -_init_op (OpLink, dl.set_link_fop, dl.set_link_cbk, - dl.wind_link, dl.unwind_link) - -class OpSymlink: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - c_char_p, POINTER(loc_t), c_uint, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(inode_t), POINTER(iatt_t), - POINTER(iatt_t), POINTER(iatt_t), POINTER(dict_t)) -_init_op (OpSymlink, dl.set_symlink_fop, dl.set_symlink_cbk, - dl.wind_symlink, dl.unwind_symlink) - -class OpUnlink: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_int, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(iatt_t), POINTER(iatt_t), - POINTER(dict_t)) -_init_op (OpUnlink, dl.set_unlink_fop, dl.set_unlink_cbk, - dl.wind_unlink, dl.unwind_unlink) - -class OpReadlink: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_size_t, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, c_char_p, POINTER(iatt_t), POINTER(dict_t)) -_init_op (OpReadlink, dl.set_readlink_fop, dl.set_readlink_cbk, - dl.wind_readlink, dl.unwind_readlink) - -class OpMkdir: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_uint, c_uint, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(inode_t), POINTER(iatt_t), - POINTER(iatt_t), POINTER(iatt_t), POINTER(dict_t)) -_init_op (OpMkdir, dl.set_mkdir_fop, dl.set_mkdir_cbk, - dl.wind_mkdir, dl.unwind_mkdir) - -class OpRmdir: - fop_sig = (c_int, POINTER(call_frame_t), POINTER(xlator_t), - POINTER(loc_t), c_int, POINTER(dict_t)) - cbk_sig = (c_int, POINTER(call_frame_t), c_long, POINTER(xlator_t), - c_int, c_int, POINTER(iatt_t), POINTER(iatt_t), - POINTER(dict_t)) -_init_op (OpRmdir, dl.set_rmdir_fop, dl.set_rmdir_cbk, - dl.wind_rmdir, dl.unwind_rmdir) - - -class Translator: - def __init__ (self, c_this): - # This is only here to keep references to the stubs we create, - # because ctypes doesn't and glupy.so can't because it doesn't - # get a pointer to the actual Python object. It's a dictionary - # instead of a list in case we ever allow changing fops/cbks - # after initialization and need to look them up. - self.stub_refs = {} - funcs = dir(self.__class__) - if "lookup_fop" in funcs: - @OpLookup.fop_type - def stub (frame, this, loc, xdata, s=self): - return s.lookup_fop (frame, this, loc, xdata) - self.stub_refs["lookup_fop"] = stub - dl.set_lookup_fop(c_this,stub) - if "lookup_cbk" in funcs: - @OpLookup.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, inode, - buf, xdata, postparent, s=self): - return s.lookup_cbk(frame, cookie, this, op_ret, - op_errno, inode, buf, xdata, - postparent) - self.stub_refs["lookup_cbk"] = stub - dl.set_lookup_cbk(c_this,stub) - if "create_fop" in funcs: - @OpCreate.fop_type - def stub (frame, this, loc, flags, mode, umask, fd, - xdata, s=self): - return s.create_fop (frame, this, loc, flags, - mode, umask, fd, xdata) - self.stub_refs["create_fop"] = stub - dl.set_create_fop(c_this,stub) - if "create_cbk" in funcs: - @OpCreate.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, fd, - inode, buf, preparent, postparent, xdata, - s=self): - return s.create_cbk (frame, cookie, this, - op_ret, op_errno, fd, - inode, buf, preparent, - postparent, xdata) - self.stub_refs["create_cbk"] = stub - dl.set_create_cbk(c_this,stub) - if "open_fop" in funcs: - @OpOpen.fop_type - def stub (frame, this, loc, flags, fd, - xdata, s=self): - return s.open_fop (frame, this, loc, flags, - fd, xdata) - self.stub_refs["open_fop"] = stub - dl.set_open_fop(c_this,stub) - if "open_cbk" in funcs: - @OpOpen.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, fd, - xdata, s=self): - return s.open_cbk (frame, cookie, this, - op_ret, op_errno, fd, - xdata) - self.stub_refs["open_cbk"] = stub - dl.set_open_cbk(c_this,stub) - if "readv_fop" in funcs: - @OpReadv.fop_type - def stub (frame, this, fd, size, offset, flags, - xdata, s=self): - return s.readv_fop (frame, this, fd, size, - offset, flags, xdata) - self.stub_refs["readv_fop"] = stub - dl.set_readv_fop(c_this,stub) - if "readv_cbk" in funcs: - @OpReadv.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - vector, count, stbuf, iobref, xdata, - s=self): - return s.readv_cbk (frame, cookie, this, - op_ret, op_errno, vector, - count, stbuf, iobref, - xdata) - self.stub_refs["readv_cbk"] = stub - dl.set_readv_cbk(c_this,stub) - if "writev_fop" in funcs: - @OpWritev.fop_type - def stub (frame, this, fd, vector, count, - offset, flags, iobref, xdata, s=self): - return s.writev_fop (frame, this, fd, vector, - count, offset, flags, - iobref, xdata) - self.stub_refs["writev_fop"] = stub - dl.set_writev_fop(c_this,stub) - if "writev_cbk" in funcs: - @OpWritev.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - prebuf, postbuf, xdata, s=self): - return s.writev_cbk (frame, cookie, this, - op_ret, op_errno, prebuf, - postbuf, xdata) - self.stub_refs["writev_cbk"] = stub - dl.set_writev_cbk(c_this,stub) - if "opendir_fop" in funcs: - @OpOpendir.fop_type - def stub (frame, this, loc, fd, xdata, s=self): - return s.opendir_fop (frame, this, loc, fd, - xdata) - self.stub_refs["opendir_fop"] = stub - dl.set_opendir_fop(c_this,stub) - if "opendir_cbk" in funcs: - @OpOpendir.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, fd, - xdata, s=self): - return s.opendir_cbk(frame, cookie, this, - op_ret, op_errno, fd, - xdata) - self.stub_refs["opendir_cbk"] = stub - dl.set_opendir_cbk(c_this,stub) - if "readdir_fop" in funcs: - @OpReaddir.fop_type - def stub (frame, this, fd, size, offset, xdata, s=self): - return s.readdir_fop (frame, this, fd, size, - offset, xdata) - self.stub_refs["readdir_fop"] = stub - dl.set_readdir_fop(c_this,stub) - if "readdir_cbk" in funcs: - @OpReaddir.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - entries, xdata, s=self): - return s.readdir_cbk(frame, cookie, this, - op_ret, op_errno, entries, - xdata) - self.stub_refs["readdir_cbk"] = stub - dl.set_readdir_cbk(c_this,stub) - if "readdirp_fop" in funcs: - @OpReaddirp.fop_type - def stub (frame, this, fd, size, offset, xdata, s=self): - return s.readdirp_fop (frame, this, fd, size, - offset, xdata) - self.stub_refs["readdirp_fop"] = stub - dl.set_readdirp_fop(c_this,stub) - if "readdirp_cbk" in funcs: - @OpReaddirp.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - entries, xdata, s=self): - return s.readdirp_cbk (frame, cookie, this, - op_ret, op_errno, - entries, xdata) - self.stub_refs["readdirp_cbk"] = stub - dl.set_readdirp_cbk(c_this,stub) - if "stat_fop" in funcs: - @OpStat.fop_type - def stub (frame, this, loc, xdata, s=self): - return s.stat_fop (frame, this, loc, xdata) - self.stub_refs["stat_fop"] = stub - dl.set_stat_fop(c_this,stub) - if "stat_cbk" in funcs: - @OpStat.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, buf, - xdata, s=self): - return s.stat_cbk(frame, cookie, this, op_ret, - op_errno, buf, xdata) - self.stub_refs["stat_cbk"] = stub - dl.set_stat_cbk(c_this,stub) - if "fstat_fop" in funcs: - @OpFstat.fop_type - def stub (frame, this, fd, xdata, s=self): - return s.fstat_fop (frame, this, fd, xdata) - self.stub_refs["fstat_fop"] = stub - dl.set_fstat_fop(c_this,stub) - if "fstat_cbk" in funcs: - @OpFstat.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, buf, - xdata, s=self): - return s.fstat_cbk(frame, cookie, this, op_ret, - op_errno, buf, xdata) - self.stub_refs["fstat_cbk"] = stub - dl.set_fstat_cbk(c_this,stub) - if "statfs_fop" in funcs: - @OpStatfs.fop_type - def stub (frame, this, loc, xdata, s=self): - return s.statfs_fop (frame, this, loc, xdata) - self.stub_refs["statfs_fop"] = stub - dl.set_statfs_fop(c_this,stub) - if "statfs_cbk" in funcs: - @OpStatfs.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, buf, - xdata, s=self): - return s.statfs_cbk (frame, cookie, this, - op_ret, op_errno, buf, - xdata) - self.stub_refs["statfs_cbk"] = stub - dl.set_statfs_cbk(c_this,stub) - if "setxattr_fop" in funcs: - @OpSetxattr.fop_type - def stub (frame, this, loc, dictionary, flags, xdata, - s=self): - return s.setxattr_fop (frame, this, loc, - dictionary, flags, - xdata) - self.stub_refs["setxattr_fop"] = stub - dl.set_setxattr_fop(c_this,stub) - if "setxattr_cbk" in funcs: - @OpSetxattr.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, xdata, - s=self): - return s.setxattr_cbk(frame, cookie, this, - op_ret, op_errno, xdata) - self.stub_refs["setxattr_cbk"] = stub - dl.set_setxattr_cbk(c_this,stub) - if "getxattr_fop" in funcs: - @OpGetxattr.fop_type - def stub (frame, this, loc, name, xdata, s=self): - return s.getxattr_fop (frame, this, loc, name, - xdata) - self.stub_refs["getxattr_fop"] = stub - dl.set_getxattr_fop(c_this,stub) - if "getxattr_cbk" in funcs: - @OpGetxattr.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - dictionary, xdata, s=self): - return s.getxattr_cbk(frame, cookie, this, - op_ret, op_errno, - dictionary, xdata) - self.stub_refs["getxattr_cbk"] = stub - dl.set_getxattr_cbk(c_this,stub) - if "fsetxattr_fop" in funcs: - @OpFsetxattr.fop_type - def stub (frame, this, fd, dictionary, flags, xdata, - s=self): - return s.fsetxattr_fop (frame, this, fd, - dictionary, flags, - xdata) - self.stub_refs["fsetxattr_fop"] = stub - dl.set_fsetxattr_fop(c_this,stub) - if "fsetxattr_cbk" in funcs: - @OpFsetxattr.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, xdata, - s=self): - return s.fsetxattr_cbk(frame, cookie, this, - op_ret, op_errno, xdata) - self.stub_refs["fsetxattr_cbk"] = stub - dl.set_fsetxattr_cbk(c_this,stub) - if "fgetxattr_fop" in funcs: - @OpFgetxattr.fop_type - def stub (frame, this, fd, name, xdata, s=self): - return s.fgetxattr_fop (frame, this, fd, name, - xdata) - self.stub_refs["fgetxattr_fop"] = stub - dl.set_fgetxattr_fop(c_this,stub) - if "fgetxattr_cbk" in funcs: - @OpFgetxattr.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - dictionary, xdata, s=self): - return s.fgetxattr_cbk(frame, cookie, this, - op_ret, op_errno, - dictionary, xdata) - self.stub_refs["fgetxattr_cbk"] = stub - dl.set_fgetxattr_cbk(c_this,stub) - if "removexattr_fop" in funcs: - @OpRemovexattr.fop_type - def stub (frame, this, loc, name, xdata, s=self): - return s.removexattr_fop (frame, this, loc, - name, xdata) - self.stub_refs["removexattr_fop"] = stub - dl.set_removexattr_fop(c_this,stub) - if "removexattr_cbk" in funcs: - @OpRemovexattr.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - xdata, s=self): - return s.removexattr_cbk(frame, cookie, this, - op_ret, op_errno, - xdata) - self.stub_refs["removexattr_cbk"] = stub - dl.set_removexattr_cbk(c_this,stub) - if "fremovexattr_fop" in funcs: - @OpFremovexattr.fop_type - def stub (frame, this, fd, name, xdata, s=self): - return s.fremovexattr_fop (frame, this, fd, - name, xdata) - self.stub_refs["fremovexattr_fop"] = stub - dl.set_fremovexattr_fop(c_this,stub) - if "fremovexattr_cbk" in funcs: - @OpFremovexattr.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - xdata, s=self): - return s.fremovexattr_cbk(frame, cookie, this, - op_ret, op_errno, - xdata) - self.stub_refs["fremovexattr_cbk"] = stub - dl.set_fremovexattr_cbk(c_this,stub) - if "link_fop" in funcs: - @OpLink.fop_type - def stub (frame, this, oldloc, newloc, - xdata, s=self): - return s.link_fop (frame, this, oldloc, - newloc, xdata) - self.stub_refs["link_fop"] = stub - dl.set_link_fop(c_this,stub) - if "link_cbk" in funcs: - @OpLink.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - inode, buf, preparent, postparent, xdata, - s=self): - return s.link_cbk (frame, cookie, this, - op_ret, op_errno, inode, - buf, preparent, - postparent, xdata) - self.stub_refs["link_cbk"] = stub - dl.set_link_cbk(c_this,stub) - if "symlink_fop" in funcs: - @OpSymlink.fop_type - def stub (frame, this, linkname, loc, - umask, xdata, s=self): - return s.symlink_fop (frame, this, linkname, - loc, umask, xdata) - self.stub_refs["symlink_fop"] = stub - dl.set_symlink_fop(c_this,stub) - if "symlink_cbk" in funcs: - @OpSymlink.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - inode, buf, preparent, postparent, xdata, - s=self): - return s.symlink_cbk (frame, cookie, this, - op_ret, op_errno, inode, - buf, preparent, - postparent, xdata) - self.stub_refs["symlink_cbk"] = stub - dl.set_symlink_cbk(c_this,stub) - if "unlink_fop" in funcs: - @OpUnlink.fop_type - def stub (frame, this, loc, xflags, - xdata, s=self): - return s.unlink_fop (frame, this, loc, - xflags, xdata) - self.stub_refs["unlink_fop"] = stub - dl.set_unlink_fop(c_this,stub) - if "unlink_cbk" in funcs: - @OpUnlink.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - preparent, postparent, xdata, s=self): - return s.unlink_cbk (frame, cookie, this, - op_ret, op_errno, - preparent, postparent, - xdata) - self.stub_refs["unlink_cbk"] = stub - dl.set_unlink_cbk(c_this,stub) - if "readlink_fop" in funcs: - @OpReadlink.fop_type - def stub (frame, this, loc, size, - xdata, s=self): - return s.readlink_fop (frame, this, loc, - size, xdata) - self.stub_refs["readlink_fop"] = stub - dl.set_readlink_fop(c_this,stub) - if "readlink_cbk" in funcs: - @OpReadlink.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - path, buf, xdata, s=self): - return s.readlink_cbk (frame, cookie, this, - op_ret, op_errno, - path, buf, xdata) - self.stub_refs["readlink_cbk"] = stub - dl.set_readlink_cbk(c_this,stub) - if "mkdir_fop" in funcs: - @OpMkdir.fop_type - def stub (frame, this, loc, mode, umask, xdata, - s=self): - return s.mkdir_fop (frame, this, loc, mode, - umask, xdata) - self.stub_refs["mkdir_fop"] = stub - dl.set_mkdir_fop(c_this,stub) - if "mkdir_cbk" in funcs: - @OpMkdir.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, inode, - buf, preparent, postparent, xdata, s=self): - return s.mkdir_cbk (frame, cookie, this, - op_ret, op_errno, inode, - buf, preparent, - postparent, xdata) - self.stub_refs["mkdir_cbk"] = stub - dl.set_mkdir_cbk(c_this,stub) - if "rmdir_fop" in funcs: - @OpRmdir.fop_type - def stub (frame, this, loc, xflags, - xdata, s=self): - return s.rmdir_fop (frame, this, loc, - xflags, xdata) - self.stub_refs["rmdir_fop"] = stub - dl.set_rmdir_fop(c_this,stub) - if "rmdir_cbk" in funcs: - @OpRmdir.cbk_type - def stub (frame, cookie, this, op_ret, op_errno, - preparent, postparent, xdata, s=self): - return s.rmdir_cbk (frame, cookie, this, - op_ret, op_errno, - preparent, postparent, - xdata) - self.stub_refs["rmdir_cbk"] = stub - dl.set_rmdir_cbk(c_this,stub) diff --git a/xlators/features/glupy/src/helloworld.py b/xlators/features/glupy/src/helloworld.py deleted file mode 100644 index 8fe4037118e..00000000000 --- a/xlators/features/glupy/src/helloworld.py +++ /dev/null @@ -1,19 +0,0 @@ -import sys -from gluster import * - -class xlator (Translator): - - def __init__(self, c_this): - Translator.__init__(self, c_this) - - def lookup_fop(self, frame, this, loc, xdata): - print "Python xlator: Hello!" - dl.wind_lookup(frame, POINTER(xlator_t)(), loc, xdata) - return 0 - - def lookup_cbk(self, frame, cookie, this, op_ret, op_errno, inode, buf, - xdata, postparent): - print "Python xlator: Hello again!" - dl.unwind_lookup(frame, cookie, this, op_ret, op_errno, inode, buf, - xdata, postparent) - return 0 diff --git a/xlators/features/glupy/src/negative.py b/xlators/features/glupy/src/negative.py deleted file mode 100644 index 1023602b9f3..00000000000 --- a/xlators/features/glupy/src/negative.py +++ /dev/null @@ -1,92 +0,0 @@ -import sys -from uuid import UUID -from gluster import * - -# Negative-lookup-caching example. If a file wasn't there the last time we -# looked, it's probably still not there. This translator keeps track of -# those failed lookups for us, and returns ENOENT without needing to pass the -# call any further for repeated requests. - -# If we were doing this for real, we'd need separate caches for each xlator -# instance. The easiest way to do this would be to have xlator.__init__ -# "register" each instance in a module-global dict, with the key as the C -# translator address and the value as the xlator object itself. For testing -# and teaching, it's sufficient just to have one cache. The keys are parent -# GFIDs, and the entries are lists of names within that parent that we know -# don't exist. -cache = {} - -# TBD: we need a better way of handling per-request data (frame->local in C). -dl.get_id.restype = c_long -dl.get_id.argtypes = [ POINTER(call_frame_t) ] - -def uuid2str (gfid): - return str(UUID(''.join(map("{0:02x}".format, gfid)))) - -class xlator (Translator): - - def __init__ (self, c_this): - self.requests = {} - Translator.__init__(self,c_this) - - def lookup_fop (self, frame, this, loc, xdata): - pargfid = uuid2str(loc.contents.pargfid) - print "lookup FOP: %s:%s" % (pargfid, loc.contents.name) - # Check the cache. - if cache.has_key(pargfid): - if loc.contents.name in cache[pargfid]: - print "short-circuiting for %s:%s" % (pargfid, - loc.contents.name) - dl.unwind_lookup(frame,0,this,-1,2,None,None,None,None) - return 0 - key = dl.get_id(frame) - self.requests[key] = (pargfid, loc.contents.name[:]) - # TBD: get real child xl from init, pass it here - dl.wind_lookup(frame,POINTER(xlator_t)(),loc,xdata) - return 0 - - def lookup_cbk (self, frame, cookie, this, op_ret, op_errno, inode, buf, - xdata, postparent): - print "lookup CBK: %d (%d)" % (op_ret, op_errno) - key = dl.get_id(frame) - pargfid, name = self.requests[key] - # Update the cache. - if op_ret == 0: - print "found %s, removing from cache" % name - if cache.has_key(pargfid): - cache[pargfid].discard(name) - elif op_errno == 2: # ENOENT - print "failed to find %s, adding to cache" % name - if cache.has_key(pargfid): - cache[pargfid].add(name) - else: - cache[pargfid] = set([name]) - del self.requests[key] - dl.unwind_lookup(frame,cookie,this,op_ret,op_errno, - inode,buf,xdata,postparent) - return 0 - - def create_fop (self, frame, this, loc, flags, mode, umask, fd, xdata): - pargfid = uuid2str(loc.contents.pargfid) - print "create FOP: %s:%s" % (pargfid, loc.contents.name) - key = dl.get_id(frame) - self.requests[key] = (pargfid, loc.contents.name[:]) - # TBD: get real child xl from init, pass it here - dl.wind_create(frame,POINTER(xlator_t)(),loc,flags,mode,umask,fd,xdata) - return 0 - - def create_cbk (self, frame, cookie, this, op_ret, op_errno, fd, inode, - buf, preparent, postparent, xdata): - print "create CBK: %d (%d)" % (op_ret, op_errno) - key = dl.get_id(frame) - pargfid, name = self.requests[key] - # Update the cache. - if op_ret == 0: - print "created %s, removing from cache" % name - if cache.has_key(pargfid): - cache[pargfid].discard(name) - del self.requests[key] - dl.unwind_create(frame,cookie,this,op_ret,op_errno,fd,inode,buf, - preparent,postparent,xdata) - return 0 - diff --git a/xlators/features/glupy/src/setup.py.in b/xlators/features/glupy/src/setup.py.in new file mode 100644 index 00000000000..1aea9875f0a --- /dev/null +++ b/xlators/features/glupy/src/setup.py.in @@ -0,0 +1,24 @@ +from distutils.core import setup + +DESC = """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 contains Glupy, the Python translator interface for GlusterFS.""" + +setup( + name='glusterfs-glupy', + version='@PACKAGE_VERSION@', + description='Glupy is the Python translator interface for GlusterFS', + long_description=DESC, + author='Gluster Community', + author_email='gluster-devel@nongnu.org', + license='LGPLv3', + url='http://gluster.org/', + package_dir={'gluster':''}, + packages=['gluster'] +) -- cgit