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 --- 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 + 13 files changed, 1766 insertions(+), 1735 deletions(-) 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 (limited to 'xlators/features') diff --git a/xlators/features/glupy/Makefile.am b/xlators/features/glupy/Makefile.am index a985f42a8..060429ecf 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 000000000..c26abeaaf --- /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 000000000..6eef1b58b --- /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 000000000..b565a4e5b --- /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 000000000..e7a4fc07c --- /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 21b91a164..ae7b6d14d 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 53e76546b..000000000 --- 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 dc86c0071..948b66f8d 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 000000000..a5daa77d3 --- /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 a5daa77d3..000000000 --- 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 8fe403711..000000000 --- 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 1023602b9..000000000 --- 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 000000000..1aea9875f --- /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 From 00802b3a484499267af2e4474d75d3f75887ad07 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Sun, 23 Mar 2014 08:01:15 +0530 Subject: features/compress: Add mem accounting support for compress Change-Id: I89a7a4cd64ef65ad3bab180d66797a62b4e1e195 BUG: 923540 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.org/7320 Tested-by: Gluster Build System Reviewed-by: Prashanth Pai Reviewed-by: Vijay Bellur --- xlators/features/compress/src/cdc-mem-types.h | 1 + xlators/features/compress/src/cdc.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'xlators/features') diff --git a/xlators/features/compress/src/cdc-mem-types.h b/xlators/features/compress/src/cdc-mem-types.h index efa008059..ead2c70ba 100644 --- a/xlators/features/compress/src/cdc-mem-types.h +++ b/xlators/features/compress/src/cdc-mem-types.h @@ -17,6 +17,7 @@ enum gf_cdc_mem_types { gf_cdc_mt_priv_t = gf_common_mt_end + 1, gf_cdc_mt_vec_t = gf_common_mt_end + 2, gf_cdc_mt_gzip_trailer_t = gf_common_mt_end + 3, + gf_cdc_mt_end = gf_common_mt_end + 4, }; #endif diff --git a/xlators/features/compress/src/cdc.c b/xlators/features/compress/src/cdc.c index a334c7e06..67fc52505 100644 --- a/xlators/features/compress/src/cdc.c +++ b/xlators/features/compress/src/cdc.c @@ -189,6 +189,25 @@ cdc_writev (call_frame_t *frame, return 0; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_cdc_mt_end); + + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} + int32_t init (xlator_t *this) { -- cgit From 997c89b6172116557f981510a94232486ec526b0 Mon Sep 17 00:00:00 2001 From: Kotresh H R Date: Tue, 25 Mar 2014 11:11:41 +0530 Subject: features/gfid-access: Fix possible inode memory corruption. During lookup, the inode is not ref'd. Added code to ref the inode in call path and unref in cbk path. Also fixed a case where we should always be putting linked inode into context as it is not guaranteed that we get same inode that we passed in a call to inode_link. Change-Id: Iaec083a9258658bef3047e83956729d3dbcd9a59 BUG: 1080295 Signed-off-by: Kotresh H R Reviewed-on: http://review.gluster.org/7329 Tested-by: Gluster Build System Reviewed-by: Raghavendra G Reviewed-by: Venky Shankar --- xlators/features/gfid-access/src/gfid-access.c | 32 ++++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/gfid-access/src/gfid-access.c b/xlators/features/gfid-access/src/gfid-access.c index 8e614397c..5cb6ecfbd 100644 --- a/xlators/features/gfid-access/src/gfid-access.c +++ b/xlators/features/gfid-access/src/gfid-access.c @@ -593,18 +593,19 @@ ga_virtual_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, dict_t *xdata, struct iatt *postparent) { - int j = 0; - int i = 0; - int ret = 0; - uint64_t temp_ino = 0; - inode_t *cbk_inode = NULL; - inode_t *true_inode = NULL; - uuid_t random_gfid = {0,}; + int j = 0; + int i = 0; + int ret = 0; + uint64_t temp_ino = 0; + inode_t *cbk_inode = NULL; + inode_t *true_inode = NULL; + uuid_t random_gfid = {0,}; + inode_t *linked_inode = NULL; if (frame->local) cbk_inode = frame->local; else - cbk_inode = inode; + cbk_inode = inode_ref (inode); frame->local = NULL; if (op_ret) @@ -619,6 +620,10 @@ ga_virtual_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if its just previously discover()'d inode */ true_inode = inode_find (inode->table, buf->ia_gfid); if (!true_inode) { + /* This unref is for 'inode_ref()' done in beginning. + This is needed as cbk_inode is allocated new inode + whose unref is taken at the end*/ + inode_unref (cbk_inode); cbk_inode = inode_new (inode->table); if (!cbk_inode) { @@ -630,7 +635,8 @@ ga_virtual_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, path is not yet looked up. Use the current inode itself for now */ - inode_link (inode, NULL, NULL, buf); + linked_inode = inode_link (inode, NULL, NULL, buf); + inode = linked_inode; } else { /* 'inode_ref()' has been done in inode_find() */ inode = true_inode; @@ -674,6 +680,10 @@ unwind: STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, cbk_inode, buf, xdata, postparent); + /* Also handles inode_unref of frame->local if done in ga_lookup */ + if (cbk_inode) + inode_unref (cbk_inode); + return 0; } @@ -819,6 +829,8 @@ ga_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) /* time do another lookup and update the context with proper inode */ op_errno = ESTALE; + /* 'inode_ref()' done in inode_find */ + inode_unref (true_inode); goto err; } @@ -833,7 +845,7 @@ discover: /* if revalidate, then we need to have the proper reference */ if (inode) { tmp_loc.inode = inode_ref (inode); - frame->local = loc->inode; + frame->local = inode_ref (loc->inode); } else { tmp_loc.inode = inode_ref (loc->inode); } -- cgit From ca6af761fb63068b170b9e8b1143598af244e06c Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Tue, 25 Mar 2014 16:15:15 +0530 Subject: features/glupy: Add mem accounting support When glusterfs is built from source using -DDEBUG flag and glupy xlator is added to vol file, the brick process used to crash when mounting the volume. This fix is largely derived from the fix submitted for BZ #1035751. Thanks to Justin Clift for helping in tracking this down. BUG: 1035751 Change-Id: Id64f92eecc9335e34dd08812fe176774e7723c2c Signed-off-by: Prashanth Pai Reviewed-on: http://review.gluster.org/7332 Reviewed-by: Jeff Darcy Tested-by: Gluster Build System --- xlators/features/glupy/src/glupy.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'xlators/features') diff --git a/xlators/features/glupy/src/glupy.c b/xlators/features/glupy/src/glupy.c index 948b66f8d..7492124dd 100644 --- a/xlators/features/glupy/src/glupy.c +++ b/xlators/features/glupy/src/glupy.c @@ -2313,6 +2313,25 @@ get_rootunique (call_frame_t *frame) return frame->root->unique; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_glupy_mt_end); + + if (ret != 0) { + gf_log(this->name, GF_LOG_ERROR, "Memory accounting init" + " failed"); + return ret; + } + + return ret; +} + int32_t init (xlator_t *this) { -- cgit From b69c4c843ce0c6a361c46fd53cbbbb9ce0e27cd8 Mon Sep 17 00:00:00 2001 From: Varun Shastry Date: Wed, 5 Feb 2014 13:02:34 +0530 Subject: features/barrier: add barrier translator gluster feature page: http://www.gluster.org/community/documentation/index.php/Features/Server-side_Barrier_feature Change-Id: Ia9f8802a54d1ffbd1cf789b80f5d30819bf65f64 BUG: 1060002 Signed-off-by: Varun Shastry Reviewed-on: http://review.gluster.org/6928 Tested-by: Gluster Build System Reviewed-by: Krishnan Parthasarathi Reviewed-by: Atin Mukherjee Reviewed-by: Vijay Bellur --- xlators/features/Makefile.am | 2 +- xlators/features/barrier/Makefile.am | 3 + xlators/features/barrier/src/Makefile.am | 16 + xlators/features/barrier/src/barrier-mem-types.h | 20 + xlators/features/barrier/src/barrier.c | 520 +++++++++++++++++++++++ xlators/features/barrier/src/barrier.h | 91 ++++ 6 files changed, 651 insertions(+), 1 deletion(-) create mode 100644 xlators/features/barrier/Makefile.am create mode 100644 xlators/features/barrier/src/Makefile.am create mode 100644 xlators/features/barrier/src/barrier-mem-types.h create mode 100644 xlators/features/barrier/src/barrier.c create mode 100644 xlators/features/barrier/src/barrier.h (limited to 'xlators/features') diff --git a/xlators/features/Makefile.am b/xlators/features/Makefile.am index d2f5ef192..1fdd474c2 100644 --- a/xlators/features/Makefile.am +++ b/xlators/features/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = locks quota read-only mac-compat quiesce marker index \ +SUBDIRS = locks quota read-only mac-compat quiesce marker index barrier \ protect compress changelog gfid-access $(GLUPY_SUBDIR) qemu-block # trash path-converter # filter CLEANFILES = diff --git a/xlators/features/barrier/Makefile.am b/xlators/features/barrier/Makefile.am new file mode 100644 index 000000000..a985f42a8 --- /dev/null +++ b/xlators/features/barrier/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = src + +CLEANFILES = diff --git a/xlators/features/barrier/src/Makefile.am b/xlators/features/barrier/src/Makefile.am new file mode 100644 index 000000000..8859be328 --- /dev/null +++ b/xlators/features/barrier/src/Makefile.am @@ -0,0 +1,16 @@ +xlator_LTLIBRARIES = barrier.la +xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/features + +barrier_la_LDFLAGS = -module -avoid-version + +barrier_la_SOURCES = barrier.c + +barrier_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la + +noinst_HEADERS = barrier.h barrier-mem-types.h + +AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src + +AM_CFLAGS = -Wall $(GF_CFLAGS) + +CLEANFILES = diff --git a/xlators/features/barrier/src/barrier-mem-types.h b/xlators/features/barrier/src/barrier-mem-types.h new file mode 100644 index 000000000..36647a669 --- /dev/null +++ b/xlators/features/barrier/src/barrier-mem-types.h @@ -0,0 +1,20 @@ +/* + Copyright (c) 2014 Red Hat, Inc. + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef __BARRIER_MEM_TYPES_H__ +#define __BARRIER_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_barrier_mem_types_ { + gf_barrier_mt_priv_t = gf_common_mt_end + 1, + gf_barrier_mt_end +}; +#endif diff --git a/xlators/features/barrier/src/barrier.c b/xlators/features/barrier/src/barrier.c new file mode 100644 index 000000000..566c67f30 --- /dev/null +++ b/xlators/features/barrier/src/barrier.c @@ -0,0 +1,520 @@ +/* + Copyright (c) 2014 Red Hat, Inc. + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "barrier.h" +#include "defaults.h" +#include "call-stub.h" + +int32_t +barrier_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, + dict_t *xdata) +{ + BARRIER_FOP_CBK (writev, out, frame, this, op_ret, op_errno, + prebuf, postbuf, xdata); +out: + return 0; +} + +int32_t +barrier_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + BARRIER_FOP_CBK (fremovexattr, out, frame, this, op_ret, op_errno, + xdata); +out: + return 0; +} + +int32_t +barrier_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + BARRIER_FOP_CBK (removexattr, out, frame, this, op_ret, op_errno, + xdata); +out: + return 0; +} + +int32_t +barrier_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + BARRIER_FOP_CBK (truncate, out, frame, this, op_ret, op_errno, prebuf, + postbuf, xdata); +out: + return 0; +} + +int32_t +barrier_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + BARRIER_FOP_CBK (ftruncate, out, frame, this, op_ret, op_errno, prebuf, + postbuf, xdata); +out: + return 0; +} + +int32_t +barrier_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) +{ + BARRIER_FOP_CBK (rename, out, frame, this, op_ret, op_errno, buf, + preoldparent, postoldparent, prenewparent, + postnewparent, xdata); +out: + return 0; +} + +int32_t +barrier_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + BARRIER_FOP_CBK (rmdir, out, frame, this, op_ret, op_errno, preparent, + postparent, xdata); +out: + return 0; +} + +int32_t +barrier_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + BARRIER_FOP_CBK (unlink, out, frame, this, op_ret, op_errno, preparent, + postparent, xdata); +out: + return 0; +} + +int32_t +barrier_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + BARRIER_FOP_CBK (fsync, out, frame, this, op_ret, op_errno, + prebuf, postbuf, xdata); +out: + return 0; +} + +int32_t +barrier_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iovec *vector, int32_t count, off_t off, uint32_t flags, + struct iobref *iobref, dict_t *xdata) +{ + if (!(flags & O_SYNC)) { + STACK_WIND_TAIL (frame, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->writev, + fd, vector, count, off, flags, iobref, xdata); + + return 0; + } + + STACK_WIND (frame, barrier_writev_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->writev, fd, vector, count, + off, flags, iobref, xdata); + return 0; +} + +int32_t +barrier_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + STACK_WIND (frame, barrier_fremovexattr_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->fremovexattr, + fd, name, xdata); + return 0; +} + +int32_t +barrier_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) +{ + STACK_WIND (frame, barrier_removexattr_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->removexattr, + loc, name, xdata); + return 0; +} + +int32_t +barrier_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, + off_t offset, dict_t *xdata) +{ + STACK_WIND (frame, barrier_truncate_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->truncate, + loc, offset, xdata); + return 0; +} + +int32_t +barrier_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) +{ + STACK_WIND (frame, barrier_rename_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->rename, + oldloc, newloc, xdata); + return 0; +} + +int +barrier_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + dict_t *xdata) +{ + STACK_WIND (frame, barrier_rmdir_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->rmdir, + loc, flags, xdata); + return 0; +} + +int32_t +barrier_unlink (call_frame_t *frame, xlator_t *this, + loc_t *loc, int xflag, dict_t *xdata) +{ + STACK_WIND (frame, barrier_unlink_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->unlink, + loc, xflag, xdata); + return 0; +} + +int32_t +barrier_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, + off_t offset, dict_t *xdata) +{ + STACK_WIND (frame, barrier_ftruncate_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->ftruncate, + fd, offset, xdata); + return 0; +} + +int32_t +barrier_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, + int32_t flags, dict_t *xdata) +{ + STACK_WIND (frame, barrier_fsync_cbk, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->fsync, + fd, flags, xdata); + return 0; +} + +call_stub_t * +__barrier_dequeue (xlator_t *this, struct list_head *queue) +{ + call_stub_t *stub = NULL; + barrier_priv_t *priv = NULL; + + priv = this->private; + GF_ASSERT (priv); + + if (list_empty (queue)) + goto out; + + stub = list_entry (queue->next, call_stub_t, list); + list_del_init (&stub->list); + +out: + return stub; +} + +void +barrier_dequeue_all (xlator_t *this, struct list_head *queue) +{ + call_stub_t *stub = NULL; + + gf_log (this->name, GF_LOG_INFO, "Dequeuing all the barriered fops"); + + /* TODO: Start the below task in a new thread */ + while ((stub = __barrier_dequeue (this, queue))) + call_resume (stub); + + gf_log (this->name, GF_LOG_INFO, "Dequeuing the barriered fops is " + "finished"); + return; +} + +void +barrier_timeout (void *data) +{ + xlator_t *this = NULL; + barrier_priv_t *priv = NULL; + struct list_head queue = {0,}; + + this = data; + THIS = this; + priv = this->private; + + INIT_LIST_HEAD (&queue); + + gf_log (this->name, GF_LOG_CRITICAL, "Disabling barrier because of " + "the barrier timeout."); + + LOCK (&priv->lock); + { + __barrier_disable (this, &queue); + } + UNLOCK (&priv->lock); + + barrier_dequeue_all (this, &queue); + + return; +} + +void +__barrier_enqueue (xlator_t *this, call_stub_t *stub) +{ + barrier_priv_t *priv = NULL; + + priv = this->private; + GF_ASSERT (priv); + + list_add_tail (&stub->list, &priv->queue); + priv->queue_size++; + + return; +} + +void +__barrier_disable (xlator_t *this, struct list_head *queue) +{ + GF_UNUSED int ret = 0; + barrier_priv_t *priv = NULL; + + priv = this->private; + GF_ASSERT (priv); + + if (priv->timer) { + ret = gf_timer_call_cancel (this->ctx, priv->timer); + priv->timer = NULL; + } + + list_splice_init (&priv->queue, queue); + priv->queue_size = 0; + priv->barrier_enabled = _gf_false; +} + +int +__barrier_enable (xlator_t *this, barrier_priv_t *priv) +{ + int ret = -1; + + priv->timer = gf_timer_call_after (this->ctx, priv->timeout, + barrier_timeout, (void *) this); + if (!priv->timer) { + gf_log (this->name, GF_LOG_CRITICAL, "Couldn't add barrier " + "timeout event."); + goto out; + } + + priv->barrier_enabled = _gf_true; + ret = 0; +out: + return ret; +} + +int +reconfigure (xlator_t *this, dict_t *options) +{ + barrier_priv_t *priv = NULL; + gf_boolean_t past = _gf_false; + int ret = -1; + gf_boolean_t barrier_enabled = _gf_false; + uint32_t timeout = {0,}; + struct list_head queue = {0,}; + + priv = this->private; + GF_ASSERT (priv); + + GF_OPTION_RECONF ("barrier", barrier_enabled, options, bool, out); + GF_OPTION_RECONF ("timeout", timeout, options, time, out); + + INIT_LIST_HEAD (&queue); + + LOCK (&priv->lock); + { + past = priv->barrier_enabled; + + switch (past) { + case _gf_false: + if (barrier_enabled) { + ret = __barrier_enable (this, priv); + if (ret) + goto unlock; + + } else { + gf_log (this->name, GF_LOG_ERROR, + "Already disabled"); + goto unlock; + } + break; + + case _gf_true: + if (!barrier_enabled) { + __barrier_disable (this, &queue); + + } else { + gf_log (this->name, GF_LOG_ERROR, + "Already enabled"); + goto unlock; + } + break; + } + + priv->timeout.tv_sec = timeout; + + ret = 0; + } +unlock: + UNLOCK (&priv->lock); + + if (!list_empty (&queue)) + barrier_dequeue_all (this, &queue); + +out: + return ret; +} + +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + ret = xlator_mem_acct_init (this, gf_barrier_mt_end + 1); + if (ret) + gf_log (this->name, GF_LOG_ERROR, "Memory accounting " + "initialization failed."); + + return ret; +} + +int +init (xlator_t *this) +{ + int ret = -1; + barrier_priv_t *priv = NULL; + uint32_t timeout = {0,}; + + if (!this->children || this->children->next) { + gf_log (this->name, GF_LOG_ERROR, + "'barrier' not configured with exactly one child"); + goto out; + } + + if (!this->parents) + gf_log (this->name, GF_LOG_WARNING, + "dangling volume. check volfile "); + + priv = GF_CALLOC (1, sizeof (*priv), gf_barrier_mt_priv_t); + if (!priv) + goto out; + + LOCK_INIT (&priv->lock); + + GF_OPTION_INIT ("barrier", priv->barrier_enabled, bool, out); + GF_OPTION_INIT ("timeout", timeout, time, out); + priv->timeout.tv_sec = timeout; + + INIT_LIST_HEAD (&priv->queue); + + if (priv->barrier_enabled) { + ret = __barrier_enable (this, priv); + if (ret == -1) + goto out; + } + + this->private = priv; + ret = 0; +out: + return ret; +} + +void +fini (xlator_t *this) +{ + barrier_priv_t *priv = NULL; + struct list_head queue = {0,}; + + priv = this->private; + if (!priv) + goto out; + + INIT_LIST_HEAD (&queue); + + gf_log (this->name, GF_LOG_INFO, "Disabling barriering and dequeuing " + "all the queued fops"); + LOCK (&priv->lock); + { + __barrier_disable (this, &queue); + } + UNLOCK (&priv->lock); + + if (!list_empty (&queue)) + barrier_dequeue_all (this, &queue); + + this->private = NULL; + + LOCK_DESTROY (&priv->lock); + GF_FREE (priv); +out: + return; +} + +struct xlator_fops fops = { + + /* Barrier Class fops */ + .rmdir = barrier_rmdir, + .unlink = barrier_unlink, + .rename = barrier_rename, + .removexattr = barrier_removexattr, + .fremovexattr = barrier_fremovexattr, + .truncate = barrier_truncate, + .ftruncate = barrier_ftruncate, + .fsync = barrier_fsync, + + /* Writes with only O_SYNC flag */ + .writev = barrier_writev, +}; + +struct xlator_dumpops dumpops; + +struct xlator_cbks cbks; + +struct volume_options options[] = { + { .key = {"barrier"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "When \"on\", blocks acknowledgements to application " + "for file operations such as rmdir, rename, unlink, " + "removexattr, fremovexattr, truncate, ftruncate, " + "write (with O_SYNC), fsync. It is turned \"off\" by " + "default." + }, + { .key = {"timeout"}, + .type = GF_OPTION_TYPE_TIME, + .default_value = "120", + .description = "After 'timeout' seconds since the time 'barrier' " + "option was set to \"on\", acknowledgements to file " + "operations are no longer blocked and previously " + "blocked acknowledgements are sent to the application" + }, + { .key = {NULL} }, +}; diff --git a/xlators/features/barrier/src/barrier.h b/xlators/features/barrier/src/barrier.h new file mode 100644 index 000000000..8face9f65 --- /dev/null +++ b/xlators/features/barrier/src/barrier.h @@ -0,0 +1,91 @@ +/* + Copyright (c) 2014 Red Hat, Inc. + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef __BARRIER_H__ +#define __BARRIER_H__ + +#include "barrier-mem-types.h" +#include "xlator.h" +#include "timer.h" +#include "call-stub.h" + +#define BARRIER_SAFE_ASSIGN(lock, to, value) \ + do { \ + LOCK (&(lock)); \ + { \ + to = value; \ + } \ + UNLOCK (&(lock)); \ + } while (0) + +#define BARRIER_FOP_CBK(fop_name, label, frame, this, params ...) \ + do { \ + barrier_priv_t *_priv = NULL; \ + call_stub_t *_stub = NULL; \ + gf_boolean_t _barrier_enabled= _gf_false; \ + struct list_head queue = {0, }; \ + \ + INIT_LIST_HEAD (&queue); \ + \ + _priv = this->private; \ + GF_ASSERT (_priv); \ + \ + LOCK (&_priv->lock); \ + { \ + if (_priv->barrier_enabled) { \ + _barrier_enabled = _priv->barrier_enabled;\ + \ + _stub = fop_##fop_name##_cbk_stub \ + (frame, \ + default_##fop_name##_cbk_resume,\ + params); \ + if (!_stub) { \ + __barrier_disable (this, &queue);\ + goto unlock; \ + } \ + \ + __barrier_enqueue (this, _stub); \ + } \ + } \ +unlock: \ + UNLOCK (&_priv->lock); \ + \ + if (_stub) \ + goto label; \ + \ + if (_barrier_enabled && !_stub) { \ + gf_log (this->name, GF_LOG_CRITICAL, \ + "Failed to barrier FOPs, disabling " \ + "barrier. FOP: %s, ERROR: %s", \ + #fop_name, strerror (ENOMEM)); \ + barrier_dequeue_all (this, &queue); \ + } \ + \ + STACK_UNWIND_STRICT (fop_name, frame, params); \ + goto label; \ + } while (0) + +typedef struct { + gf_timer_t *timer; + gf_boolean_t barrier_enabled; + gf_lock_t lock; + struct list_head queue; + struct timespec timeout; + uint32_t queue_size; +} barrier_priv_t; + +int __barrier_enable (xlator_t *this, barrier_priv_t *priv); +void __barrier_enqueue (xlator_t *this, call_stub_t *stub); +void __barrier_disable (xlator_t *this, struct list_head *queue); +void barrier_timeout (void *data); +void barrier_dequeue_all (xlator_t *this, struct list_head *queue); +call_stub_t *__barrier_dequeue (xlator_t *this, struct list_head *queue); + +#endif -- cgit From ef08cf0fb6ce63094468d85f5b3bab7637e88b00 Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Tue, 4 Mar 2014 12:04:37 +0530 Subject: feature/barrier: Add statedump support This patch adds statedump support for barrier. This currently dumps barrier xlators private information and the queue of barriered fops. Change-Id: I273eb6e676db02c40c363feeff58a79737dc041e BUG: 1060002 Reviewed-on: http://review.gluster.org/7136 Tested-by: Gluster Build System Reviewed-by: Krishnan Parthasarathi Reviewed-by: Vijay Bellur --- xlators/features/barrier/src/barrier.c | 82 +++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) (limited to 'xlators/features') diff --git a/xlators/features/barrier/src/barrier.c b/xlators/features/barrier/src/barrier.c index 566c67f30..e5465d1b4 100644 --- a/xlators/features/barrier/src/barrier.c +++ b/xlators/features/barrier/src/barrier.c @@ -17,6 +17,8 @@ #include "defaults.h" #include "call-stub.h" +#include "statedump.h" + int32_t barrier_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *prebuf, @@ -478,6 +480,82 @@ out: return; } +static void +barrier_dump_stub (call_stub_t *stub, char *prefix) +{ + char key[GF_DUMP_MAX_BUF_LEN] = {0,}; + + gf_proc_dump_build_key (key, prefix, "fop"); + gf_proc_dump_write (key, "%s", gf_fop_list[stub->fop]); + + gf_proc_dump_build_key (key, prefix, "gfid"); + gf_proc_dump_write (key, "%s", uuid_utoa (stub->args.loc.gfid)); + + if (stub->args.loc.path) { + gf_proc_dump_build_key (key, prefix, "path"); + gf_proc_dump_write (key, "%s", stub->args.loc.path); + } + if (stub->args.loc.name) { + gf_proc_dump_build_key (key, prefix, "name"); + gf_proc_dump_write (key, "%s", stub->args.loc.name); + } + + return; +} + +static void +__barrier_dump_queue (barrier_priv_t *priv) +{ + call_stub_t *stub = NULL; + char key[GF_DUMP_MAX_BUF_LEN] = {0,}; + int i = 0; + + GF_VALIDATE_OR_GOTO ("barrier", priv, out); + + list_for_each_entry (stub, &priv->queue, list) { + snprintf (key, sizeof (key), "stub.%d", i++); + gf_proc_dump_add_section (key); + barrier_dump_stub(stub, key); + } + +out: + return; +} + +int +barrier_dump_priv (xlator_t *this) +{ + int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = {0,}; + barrier_priv_t *priv = NULL; + + GF_VALIDATE_OR_GOTO ("barrier", this, out); + + priv = this->private; + if (!priv) + return 0; + + gf_proc_dump_build_key (key, "xlator.features.barrier", "priv"); + gf_proc_dump_add_section (key); + + LOCK (&priv->lock); + { + gf_proc_dump_build_key (key, "barrier", "enabled"); + gf_proc_dump_write (key, "%d", priv->barrier_enabled); + gf_proc_dump_build_key (key, "barrier", "timeout"); + gf_proc_dump_write (key, "%"PRId64, priv->timeout.tv_sec); + if (priv->barrier_enabled) { + gf_proc_dump_build_key (key, "barrier", "queue_size"); + gf_proc_dump_write (key, "%d", priv->queue_size); + __barrier_dump_queue (priv); + } + } + UNLOCK (&priv->lock); + +out: + return ret; +} + struct xlator_fops fops = { /* Barrier Class fops */ @@ -494,7 +572,9 @@ struct xlator_fops fops = { .writev = barrier_writev, }; -struct xlator_dumpops dumpops; +struct xlator_dumpops dumpops = { + .priv = barrier_dump_priv, +}; struct xlator_cbks cbks; -- cgit From cbe454b7189255a74df4464e12dff0fcf0064240 Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Tue, 8 Apr 2014 12:28:04 +0530 Subject: features/locks: Fix a missing assignment in new_entrylk_lock() Change-Id: If5c03456d61ec930d588b57781fb545eed18e4a2 BUG: 1085220 Signed-off-by: Vijay Bellur Reviewed-on: http://review.gluster.org/7413 Reviewed-by: Pranith Kumar Karampuri Tested-by: Gluster Build System Reviewed-by: Santosh Pradhan --- xlators/features/locks/src/entrylk.c | 1 + 1 file changed, 1 insertion(+) (limited to 'xlators/features') diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c index ea6995627..dc86512be 100644 --- a/xlators/features/locks/src/entrylk.c +++ b/xlators/features/locks/src/entrylk.c @@ -62,6 +62,7 @@ new_entrylk_lock (pl_inode_t *pinode, const char *basename, entrylk_type type, newlock->volume = domain; newlock->owner = frame->root->lk_owner; newlock->frame = frame; + newlock->this = frame->this; if (conn_id) { newlock->connection_id = gf_strdup (conn_id); -- cgit