diff options
author | Ram Raja <rraja@redhat.com> | 2013-04-30 00:47:56 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2013-05-13 13:23:21 -0700 |
commit | 68712c33b4c792449e7d49ae348f96f97175bbd9 (patch) | |
tree | aefb5547fa7ac4a2c51bfafdd50ca681f331f4f6 /xlators/features/glupy | |
parent | b9fdbc079025ffd743305cee868e02f653326419 (diff) |
glupy patch by Ram, Justin: Add/Modify fops, structure types, utility fns
Extend the following fops with Python:
* open
* readv
* writev
* opendir
* readdir
* readdirp
* stat
* fstat
* statfs
* setxattr
* getxattr
* fsetxattr
* fgetxattr
* removexattr
* fremovexattr
* link
* unlink
* readlink
* symlink
* mkdir
* rmdir
Add fd_t, inode_t and iatt_t structure types.
Modify loc_t structure type; Alter the data types of the following
attributes - inode, parent, gfid, pargfid.
Modify uuid2str function, which returns a string equivalent for a ctype
object representing a gfid, to make use of python's 'uuid' module for
accurate representation of uuids.
by Justin Clift:
Adjust debug-trace.py to work with Python 2.6
Work around 'zero length field name in format' bug in
negative.py's uuid2str function
Fix indentation errors in negative.py, glupy.h,
glupy.c, gluster.py
Change-Id: If0fcfb2866e21c0380a973f8ffab9ea7b6a4cd5d
BUG: 961856
Signed-off-by: Ram Raja <rraja@redhat.com>
Reviewed-on: http://review.gluster.org/4907
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-by: Justin Clift <jclift@redhat.com>
Tested-by: Justin Clift <jclift@redhat.com>
Diffstat (limited to 'xlators/features/glupy')
-rw-r--r-- | xlators/features/glupy/doc/TESTING | 9 | ||||
-rw-r--r-- | xlators/features/glupy/doc/test.vol | 10 | ||||
-rw-r--r-- | xlators/features/glupy/src/Makefile.am | 2 | ||||
-rw-r--r-- | xlators/features/glupy/src/debug-trace.py | 774 | ||||
-rw-r--r-- | xlators/features/glupy/src/glupy.c | 2086 | ||||
-rw-r--r-- | xlators/features/glupy/src/glupy.h | 22 | ||||
-rw-r--r-- | xlators/features/glupy/src/gluster.py | 905 | ||||
-rw-r--r-- | xlators/features/glupy/src/negative.py | 127 |
8 files changed, 3773 insertions, 162 deletions
diff --git a/xlators/features/glupy/doc/TESTING b/xlators/features/glupy/doc/TESTING new file mode 100644 index 00000000000..e05f17f498f --- /dev/null +++ b/xlators/features/glupy/doc/TESTING @@ -0,0 +1,9 @@ +Loading a translator written in Python using the glupy meta translator +------------------------------------------------------------------------------- +'test.vol' is a simple volfile with the debug-trace Python translator on top +of a brick. The volfile can be mounted using the following command. + +$ glusterfs --debug -f test.vol /path/to/mntpt + +If then file operations are performed on the newly mounted file system, log +output would be printed by the Python translator on the standard output. diff --git a/xlators/features/glupy/doc/test.vol b/xlators/features/glupy/doc/test.vol new file mode 100644 index 00000000000..0751a488c1f --- /dev/null +++ b/xlators/features/glupy/doc/test.vol @@ -0,0 +1,10 @@ +volume vol-posix + type storage/posix + option directory /path/to/brick +end-volume + +volume vol-glupy + type features/glupy + option module-name debug-trace + subvolumes vol-posix +end-volume diff --git a/xlators/features/glupy/src/Makefile.am b/xlators/features/glupy/src/Makefile.am index ccecc7a4ff1..931e5b741cb 100644 --- a/xlators/features/glupy/src/Makefile.am +++ b/xlators/features/glupy/src/Makefile.am @@ -4,7 +4,7 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/features glupydir = $(xlatordir)/glupy -glupy_PYTHON = gluster.py negative.py helloworld.py +glupy_PYTHON = gluster.py negative.py helloworld.py debug-trace.py glupy_la_LDFLAGS = -module -avoid-version -shared -nostartfiles glupy_la_SOURCES = glupy.c diff --git a/xlators/features/glupy/src/debug-trace.py b/xlators/features/glupy/src/debug-trace.py new file mode 100644 index 00000000000..53e76546b15 --- /dev/null +++ b/xlators/features/glupy/src/debug-trace.py @@ -0,0 +1,774 @@ +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 9c06085b938..fafea817cdb 100644 --- a/xlators/features/glupy/src/glupy.c +++ b/xlators/features/glupy/src/glupy.c @@ -78,7 +78,7 @@ glupy_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, glupy_leave(gstate); return ret; - + unwind: frame->local = NULL; STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, @@ -116,7 +116,6 @@ wind: void wind_lookup (call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata) { - xlator_t *this = THIS; if (!xl || (xl == this)) { @@ -175,7 +174,7 @@ glupy_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, glupy_leave(gstate); return ret; - + unwind: frame->local = NULL; STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf, @@ -215,7 +214,6 @@ void wind_create (call_frame_t *frame, xlator_t *xl, loc_t *loc, int32_t flags, mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) { - xlator_t *this = THIS; if (!xl || (xl == this)) { @@ -253,14 +251,2068 @@ set_create_cbk (long py_this, fop_create_cbk_t cbk) priv->cbks[GLUPY_CREATE] = (long)cbk; } +/* FOP: OPEN */ + +int32_t +glupy_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_OPEN]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_open_cbk_t)(priv->cbks[GLUPY_OPEN]))( + frame, cookie, this, op_ret, op_errno, + fd, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata); + return 0; +} + +int32_t +glupy_open (call_frame_t *frame, xlator_t *this, loc_t *loc, + int32_t flags, fd_t *fd, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_OPEN]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_open_t)(priv->fops[GLUPY_OPEN]))( + frame, this, loc, flags, fd, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_open_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata); + return 0; +} + +void +wind_open (call_frame_t *frame, xlator_t *xl, loc_t *loc, int32_t flags, + fd_t *fd, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_open_cbk, xl, xl->fops->open, loc, flags, + fd, xdata); +} + +void +unwind_open (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata); +} + +void +set_open_fop (long py_this, fop_open_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + priv->fops[GLUPY_OPEN] = (long)fop; +} + +void +set_open_cbk (long py_this, fop_open_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + priv->cbks[GLUPY_OPEN] = (long)cbk; +} + +/* FOP: READV */ + +int32_t +glupy_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iovec *vector, + int32_t count, struct iatt *stbuf, struct iobref *iobref, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_READV]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_readv_cbk_t)(priv->cbks[GLUPY_READV]))( + frame, cookie, this, op_ret, op_errno, + vector, count, stbuf, iobref, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, + count, stbuf, iobref, xdata); + return 0; +} + +int32_t +glupy_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, + size_t size, off_t offset, uint32_t flags, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_READV]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_readv_t)(priv->fops[GLUPY_READV]))( + frame, this, fd, size, offset, flags, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_readv_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->readv, fd, size, offset, + flags, xdata); + return 0; +} + +void +wind_readv (call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size, + off_t offset, uint32_t flags, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_readv_cbk, xl, xl->fops->readv, fd, size, + offset, flags, xdata); +} + +void +unwind_readv (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iovec *vector, + int32_t count, struct iatt *stbuf, struct iobref *iobref, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, + count, stbuf, iobref, xdata); +} + +void +set_readv_fop (long py_this, fop_readv_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + priv->fops[GLUPY_READV] = (long)fop; +} + +void +set_readv_cbk (long py_this, fop_readv_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + priv->cbks[GLUPY_READV] = (long)cbk; +} + +/* FOP: WRITEV */ + +int32_t +glupy_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) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_WRITEV]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_writev_cbk_t)(priv->cbks[GLUPY_WRITEV]))( + frame, cookie, this, op_ret, op_errno, + prebuf, postbuf, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, + postbuf, xdata); + return 0; +} + +int32_t +glupy_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iovec *vector, int32_t count, off_t offset, + uint32_t flags, struct iobref *iobref, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_WRITEV]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_writev_t)(priv->fops[GLUPY_WRITEV]))( + frame, this, fd, vector, count, offset, flags, + iobref, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_writev_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->writev, fd, vector, count, + offset, flags, iobref, xdata); + return 0; +} + +void +wind_writev (call_frame_t *frame, xlator_t *xl, fd_t *fd, struct iovec *vector, + int32_t count, off_t offset, uint32_t flags, struct iobref *iobref, + dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_writev_cbk, xl, xl->fops->writev, fd, vector, + count, offset, flags, iobref, xdata); +} + +void +unwind_writev (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, + postbuf, xdata); +} + +void +set_writev_fop (long py_this, fop_writev_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + priv->fops[GLUPY_WRITEV] = (long)fop; +} + +void +set_writev_cbk (long py_this, fop_writev_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + priv->cbks[GLUPY_WRITEV] = (long)cbk; +} + + +/* FOP: OPENDIR */ + +int32_t +glupy_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_OPENDIR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_opendir_cbk_t)(priv->cbks[GLUPY_OPENDIR]))( + frame, cookie, this, op_ret, op_errno, + fd, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd, xdata); + return 0; +} + +int32_t +glupy_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, + fd_t *fd, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_OPENDIR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_opendir_t)(priv->fops[GLUPY_OPENDIR]))( + frame, this, loc, fd, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_opendir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->opendir, loc, fd, xdata); + return 0; +} + +void +wind_opendir (call_frame_t *frame, xlator_t *xl, loc_t *loc, fd_t *fd, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND(frame,glupy_opendir_cbk,xl,xl->fops->opendir,loc,fd,xdata); +} + +void +unwind_opendir (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT(opendir,frame,op_ret,op_errno, + fd,xdata); +} + +void +set_opendir_fop (long py_this, fop_opendir_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_OPENDIR] = (long)fop; +} + +void +set_opendir_cbk (long py_this, fop_opendir_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_OPENDIR] = (long)cbk; +} + +/* FOP: READDIR */ + +int32_t +glupy_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_READDIR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_readdir_cbk_t)(priv->cbks[GLUPY_READDIR]))( + frame, cookie, this, op_ret, op_errno, + entries, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, entries, + xdata); + return 0; +} + +int32_t +glupy_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, + size_t size, off_t offset, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_READDIR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_readdir_t)(priv->fops[GLUPY_READDIR]))( + frame, this, fd, size, offset, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_readdir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->readdir,fd, size, offset, xdata); + return 0; +} + +void +wind_readdir(call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size, + off_t offset, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND(frame,glupy_readdir_cbk,xl,xl->fops->readdir,fd,size,offset,xdata); +} + +void +unwind_readdir (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT(readdir,frame,op_ret,op_errno, + entries, xdata); +} + +void +set_readdir_fop (long py_this, fop_readdir_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_READDIR] = (long)fop; +} + +void +set_readdir_cbk (long py_this, fop_readdir_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_READDIR] = (long)cbk; +} + + +/* FOP: READDIRP */ + +int32_t +glupy_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_READDIRP]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_readdirp_cbk_t)(priv->cbks[GLUPY_READDIRP]))( + frame, cookie, this, op_ret, op_errno, + entries, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, entries, + xdata); + return 0; +} + +int32_t +glupy_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, + size_t size, off_t offset, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_READDIRP]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_readdirp_t)(priv->fops[GLUPY_READDIRP]))( + frame, this, fd, size, offset, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_readdirp_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->readdirp,fd, size, offset, xdata); + return 0; +} + +void +wind_readdirp (call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size, + off_t offset, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND(frame,glupy_readdirp_cbk,xl,xl->fops->readdirp,fd,size,offset,xdata); +} + +void +unwind_readdirp (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT(readdirp,frame,op_ret,op_errno, + entries, xdata); +} + +void +set_readdirp_fop (long py_this, fop_readdirp_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_READDIRP] = (long)fop; +} + +void +set_readdirp_cbk (long py_this, fop_readdirp_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_READDIRP] = (long)cbk; +} + + +/* FOP:STAT */ + +int32_t +glupy_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_STAT]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_stat_cbk_t)(priv->cbks[GLUPY_STAT]))( + frame, cookie, this, op_ret, op_errno, + buf, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, buf, xdata); + return 0; +} + +int32_t +glupy_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_STAT]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_stat_t)(priv->fops[GLUPY_STAT]))( + frame, this, loc, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_stat_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->stat, loc, xdata); + return 0; +} + +void +wind_stat (call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND(frame,glupy_stat_cbk,xl,xl->fops->stat,loc,xdata); +} + +void +unwind_stat (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT(stat,frame,op_ret,op_errno, + buf,xdata); +} + +void +set_stat_fop (long py_this, fop_stat_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_STAT] = (long)fop; +} + +void +set_stat_cbk (long py_this, fop_stat_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_STAT] = (long)cbk; +} + + +/* FOP: FSTAT */ + +int32_t +glupy_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_FSTAT]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_fstat_cbk_t)(priv->cbks[GLUPY_FSTAT]))( + frame, cookie, this, op_ret, op_errno, + buf, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf, xdata); + return 0; +} + +int32_t +glupy_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_FSTAT]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_fstat_t)(priv->fops[GLUPY_FSTAT]))( + frame, this, fd, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_fstat_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fstat, fd, xdata); + return 0; +} + +void +wind_fstat (call_frame_t *frame, xlator_t *xl, fd_t *fd, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND(frame,glupy_fstat_cbk,xl,xl->fops->fstat,fd,xdata); +} + +void +unwind_fstat (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT(fstat,frame,op_ret,op_errno, + buf,xdata); +} + +void +set_fstat_fop (long py_this, fop_fstat_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_FSTAT] = (long)fop; +} + +void +set_fstat_cbk (long py_this, fop_fstat_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_FSTAT] = (long)cbk; +} + +/* FOP:STATFS */ + +int32_t +glupy_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct statvfs *buf, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_STATFS]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_statfs_cbk_t)(priv->cbks[GLUPY_STATFS]))( + frame, cookie, this, op_ret, op_errno, + buf, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf, xdata); + return 0; +} + +int32_t +glupy_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_STATFS]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_statfs_t)(priv->fops[GLUPY_STATFS]))( + frame, this, loc, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_statfs_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->statfs, loc, xdata); + return 0; +} + +void +wind_statfs (call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND(frame,glupy_statfs_cbk,xl,xl->fops->statfs,loc,xdata); +} + +void +unwind_statfs (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct statvfs *buf, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT(statfs,frame,op_ret,op_errno, + buf,xdata); +} + +void +set_statfs_fop (long py_this, fop_statfs_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_STATFS] = (long)fop; +} + +void +set_statfs_cbk (long py_this, fop_statfs_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_STATFS] = (long)cbk; +} + + +/* FOP: SETXATTR */ + +int32_t +glupy_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_SETXATTR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_setxattr_cbk_t)(priv->cbks[GLUPY_SETXATTR]))( + frame, cookie, this, op_ret, op_errno, + xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata); + return 0; +} + +int32_t +glupy_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + dict_t *dict, int32_t flags, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_SETXATTR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_setxattr_t)(priv->fops[GLUPY_SETXATTR]))( + frame, this, loc, dict, flags, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_setxattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setxattr, loc, dict, + flags, xdata); + return 0; +} + +void +wind_setxattr (call_frame_t *frame, xlator_t *xl, loc_t *loc, + dict_t *dict, int32_t flags, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_setxattr_cbk, xl, xl->fops->setxattr, + loc, dict, flags, xdata); +} + + +void +unwind_setxattr (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata); + +} + +void +set_setxattr_fop (long py_this, fop_setxattr_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_SETXATTR] = (long)fop; +} + +void +set_setxattr_cbk (long py_this, fop_setxattr_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_SETXATTR] = (long)cbk; +} + +/* FOP: GETXATTR */ + +int32_t +glupy_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_GETXATTR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_getxattr_cbk_t)(priv->cbks[GLUPY_GETXATTR]))( + frame, cookie, this, op_ret, op_errno, dict, + xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, + xdata); + return 0; +} + +int32_t +glupy_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_GETXATTR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_getxattr_t)(priv->fops[GLUPY_GETXATTR]))( + frame, this, loc, name, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_getxattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->getxattr, loc, name, + xdata); + return 0; +} + +void +wind_getxattr (call_frame_t *frame, xlator_t *xl, loc_t *loc, + const char *name, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_getxattr_cbk, xl, xl->fops->getxattr, + loc, name, xdata); +} + + +void +unwind_getxattr (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, + xdata); + +} + + +void +set_getxattr_fop (long py_this, fop_getxattr_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_GETXATTR] = (long)fop; +} + + +void +set_getxattr_cbk (long py_this, fop_getxattr_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_GETXATTR] = (long)cbk; +} + +/* FOP: FSETXATTR */ + +int32_t +glupy_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_FSETXATTR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_fsetxattr_cbk_t)(priv->cbks[GLUPY_FSETXATTR]))( + frame, cookie, this, op_ret, op_errno, + xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata); + return 0; +} + +int32_t +glupy_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + dict_t *dict, int32_t flags, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_FSETXATTR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_fsetxattr_t)(priv->fops[GLUPY_FSETXATTR]))( + frame, this, fd, dict, flags, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_fsetxattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fsetxattr, fd, dict, + flags, xdata); + return 0; +} + +void +wind_fsetxattr (call_frame_t *frame, xlator_t *xl, fd_t *fd, + dict_t *dict, int32_t flags, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_fsetxattr_cbk, xl, xl->fops->fsetxattr, + fd, dict, flags, xdata); +} + + +void +unwind_fsetxattr (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata); + +} + +void +set_fsetxattr_fop (long py_this, fop_fsetxattr_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_FSETXATTR] = (long)fop; +} + +void +set_fsetxattr_cbk (long py_this, fop_fsetxattr_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_FSETXATTR] = (long)cbk; +} + +/* FOP: FGETXATTR */ + +int32_t +glupy_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_FGETXATTR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_fgetxattr_cbk_t)(priv->cbks[GLUPY_FGETXATTR]))( + frame, cookie, this, op_ret, op_errno, dict, + xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict, + xdata); + return 0; +} + +int32_t +glupy_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_FGETXATTR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_fgetxattr_t)(priv->fops[GLUPY_FGETXATTR]))( + frame, this, fd, name, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_fgetxattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fgetxattr, fd, name, + xdata); + return 0; +} + +void +wind_fgetxattr (call_frame_t *frame, xlator_t *xl, fd_t *fd, + const char *name, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_fgetxattr_cbk, xl, xl->fops->fgetxattr, + fd, name, xdata); +} + + +void +unwind_fgetxattr (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict, + xdata); + +} + + +void +set_fgetxattr_fop (long py_this, fop_fgetxattr_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_FGETXATTR] = (long)fop; +} + + +void +set_fgetxattr_cbk (long py_this, fop_fgetxattr_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_FGETXATTR] = (long)cbk; +} + +/* FOP:REMOVEXATTR */ + +int32_t +glupy_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_REMOVEXATTR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_removexattr_cbk_t)(priv->cbks[GLUPY_REMOVEXATTR]))( + frame, cookie, this, op_ret, op_errno, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata); + return 0; +} + +int32_t +glupy_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_REMOVEXATTR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_removexattr_t)(priv->fops[GLUPY_REMOVEXATTR]))( + frame, this, loc, name, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_removexattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->removexattr, loc, name, + xdata); + return 0; +} + +void +wind_removexattr (call_frame_t *frame, xlator_t *xl, loc_t *loc, + const char *name, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_removexattr_cbk, xl, xl->fops->removexattr, + loc, name, xdata); +} + + +void +unwind_removexattr (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata); + +} + +void +set_removexattr_fop (long py_this, fop_removexattr_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_REMOVEXATTR] = (long)fop; +} + +void +set_removexattr_cbk (long py_this, fop_removexattr_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_REMOVEXATTR] = (long)cbk; +} + + +/* FOP:FREMOVEXATTR */ + +int32_t +glupy_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_FREMOVEXATTR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_fremovexattr_cbk_t)(priv->cbks[GLUPY_FREMOVEXATTR]))( + frame, cookie, this, op_ret, op_errno, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata); + return 0; +} + +int32_t +glupy_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_FREMOVEXATTR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_fremovexattr_t)(priv->fops[GLUPY_FREMOVEXATTR]))( + frame, this, fd, name, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_fremovexattr_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->fremovexattr, fd, name, + xdata); + return 0; +} + +void +wind_fremovexattr (call_frame_t *frame, xlator_t *xl, fd_t *fd, + const char *name, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_fremovexattr_cbk, xl, xl->fops->fremovexattr, + fd, name, xdata); +} + + +void +unwind_fremovexattr (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata); + +} + +void +set_fremovexattr_fop (long py_this, fop_fremovexattr_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_FREMOVEXATTR] = (long)fop; +} + +void +set_fremovexattr_cbk (long py_this, fop_fremovexattr_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_FREMOVEXATTR] = (long)cbk; +} + + +/* FOP: LINK*/ +int32_t +glupy_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_LINK]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_link_cbk_t)(priv->cbks[GLUPY_LINK]))( + frame, cookie, this, op_ret, op_errno, + inode, buf, preparent, postparent, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); + return 0; +} + +int32_t +glupy_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_LINK]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_link_t)(priv->fops[GLUPY_LINK]))( + frame, this, oldloc, newloc, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_link_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->link, oldloc, newloc, + xdata); + return 0; +} + +void +wind_link (call_frame_t *frame, xlator_t *xl, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_link_cbk, xl, xl->fops->link, + oldloc, newloc, xdata); +} + +void +unwind_link (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); +} + +void +set_link_fop (long py_this, fop_link_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_LINK] = (long)fop; +} + +void +set_link_cbk (long py_this, fop_link_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_LINK] = (long)cbk; +} + +/* FOP: SYMLINK*/ +int32_t +glupy_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_SYMLINK]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_symlink_cbk_t)(priv->cbks[GLUPY_SYMLINK]))( + frame, cookie, this, op_ret, op_errno, + inode, buf, preparent, postparent, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); + return 0; +} + +int32_t +glupy_symlink(call_frame_t *frame, xlator_t *this, const char *linkname, + loc_t *loc, mode_t umask, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_SYMLINK]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_symlink_t)(priv->fops[GLUPY_SYMLINK]))( + frame, this, linkname, loc, umask, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_symlink_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->symlink, linkname, loc, + umask, xdata); + return 0; +} + +void +wind_symlink (call_frame_t *frame, xlator_t *xl, const char *linkname, + loc_t *loc, mode_t umask, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_symlink_cbk, xl, xl->fops->symlink, + linkname, loc, umask, xdata); +} + +void +unwind_symlink (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); +} + +void +set_symlink_fop (long py_this, fop_symlink_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_SYMLINK] = (long)fop; +} + +void +set_symlink_cbk (long py_this, fop_symlink_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_SYMLINK] = (long)cbk; +} + + +/* FOP: READLINK */ +int32_t +glupy_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, const char *path, + struct iatt *buf, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_READLINK]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_readlink_cbk_t)(priv->cbks[GLUPY_READLINK]))( + frame, cookie, this, op_ret, op_errno, + path, buf, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, path, + buf, xdata); + return 0; +} + +int32_t +glupy_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, + size_t size, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_READLINK]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_readlink_t)(priv->fops[GLUPY_READLINK]))( + frame, this, loc, size, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_readlink_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->readlink, loc, + size, xdata); + return 0; +} + +void +wind_readlink (call_frame_t *frame, xlator_t *xl, loc_t *loc, + size_t size, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_readlink_cbk, xl, xl->fops->readlink, + loc, size, xdata); +} + +void +unwind_readlink (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, const char *path, + struct iatt *buf, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, path, buf, + xdata); +} + +void +set_readlink_fop (long py_this, fop_readlink_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_READLINK] = (long)fop; +} + +void +set_readlink_cbk (long py_this, fop_readlink_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_READLINK] = (long)cbk; +} + + +/* FOP: UNLINK */ + +int32_t +glupy_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) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_UNLINK]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_unlink_cbk_t)(priv->cbks[GLUPY_UNLINK]))( + frame, cookie, this, op_ret, op_errno, + preparent, postparent, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, preparent, + postparent, xdata); + return 0; +} + +int32_t +glupy_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, + int xflags, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_UNLINK]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_unlink_t)(priv->fops[GLUPY_UNLINK]))( + frame, this, loc, xflags, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_unlink_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->unlink, loc, + xflags, xdata); + return 0; +} + +void +wind_unlink (call_frame_t *frame, xlator_t *xl, loc_t *loc, + int xflags, dict_t *xdata) +{ + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_unlink_cbk, xl, xl->fops->unlink, + loc, xflags, xdata); +} + +void +unwind_unlink (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, + preparent, postparent, xdata); +} + +void +set_unlink_fop (long py_this, fop_unlink_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_UNLINK] = (long)fop; +} + +void +set_unlink_cbk (long py_this, fop_unlink_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_UNLINK] = (long)cbk; +} + + +/* FOP: MKDIR */ + +int32_t +glupy_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_MKDIR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_mkdir_cbk_t)(priv->cbks[GLUPY_MKDIR]))( + frame, cookie, this, op_ret, op_errno, + inode, buf, preparent, postparent, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); + return 0; +} + +int32_t +glupy_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + mode_t umask, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_MKDIR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_mkdir_t)(priv->fops[GLUPY_MKDIR]))( + frame, this, loc, mode, umask, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_mkdir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->mkdir, loc, mode, umask, + xdata); + return 0; +} + +void +wind_mkdir (call_frame_t *frame, xlator_t *xl, loc_t *loc, mode_t mode, + mode_t umask, dict_t *xdata) +{ + + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_mkdir_cbk, xl, xl->fops->mkdir, + loc, mode, umask, xdata); +} + +void +unwind_mkdir (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); +} + +void +set_mkdir_fop (long py_this, fop_mkdir_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_MKDIR] = (long)fop; +} + +void +set_mkdir_cbk (long py_this, fop_mkdir_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_MKDIR] = (long)cbk; +} + + +/* FOP: RMDIR */ + +int32_t +glupy_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) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + + if (!priv->cbks[GLUPY_RMDIR]) { + goto unwind; + } + + gstate = glupy_enter(); + ret = ((fop_rmdir_cbk_t)(priv->cbks[GLUPY_RMDIR]))( + frame, cookie, this, op_ret, op_errno, + preparent, postparent, xdata); + glupy_leave(gstate); + + return ret; + +unwind: + frame->local = NULL; + STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno, preparent, + postparent, xdata); + return 0; +} + +int32_t +glupy_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, + int xflags, dict_t *xdata) +{ + glupy_private_t *priv = this->private; + PyGILState_STATE gstate; + int32_t ret; + static long next_id = 0; + + if (!priv->fops[GLUPY_RMDIR]) { + goto wind; + } + + gstate = glupy_enter(); + frame->local = (void *)++next_id; + ret = ((fop_rmdir_t)(priv->fops[GLUPY_RMDIR]))( + frame, this, loc, xflags, xdata); + glupy_leave(gstate); + + return ret; + +wind: + STACK_WIND (frame, glupy_rmdir_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->rmdir, loc, + xflags, xdata); + return 0; +} + +void +wind_rmdir (call_frame_t *frame, xlator_t *xl, loc_t *loc, + int xflags, dict_t *xdata) +{ + + xlator_t *this = THIS; + + if (!xl || (xl == this)) { + xl = FIRST_CHILD(this); + } + + STACK_WIND (frame, glupy_rmdir_cbk, xl, xl->fops->rmdir, + loc, xflags, xdata); +} + +void +unwind_rmdir (call_frame_t *frame, long cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) +{ + frame->local = NULL; + STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno, + preparent, postparent, xdata); +} + +void +set_rmdir_fop (long py_this, fop_rmdir_t fop) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->fops[GLUPY_RMDIR] = (long)fop; +} + +void +set_rmdir_cbk (long py_this, fop_rmdir_cbk_t cbk) +{ + glupy_private_t *priv = ((xlator_t *)py_this)->private; + + priv->cbks[GLUPY_RMDIR] = (long)cbk; +} + + /* NON-FOP-SPECIFIC CODE */ + long get_id (call_frame_t *frame) { return (long)(frame->local); } +uint64_t +get_rootunique (call_frame_t *frame) +{ + return frame->root->unique; +} + int32_t init (xlator_t *this) { @@ -313,6 +2365,7 @@ init (xlator_t *this) goto *err_cleanup; } + gf_log (this->name, GF_LOG_ERROR, "py_mod_name = %s", module_name); priv->py_module = PyImport_Import(py_mod_name); Py_DECREF(py_mod_name); if (!priv->py_module) { @@ -393,8 +2446,29 @@ fini (xlator_t *this) } struct xlator_fops fops = { - .lookup = glupy_lookup, - .create = glupy_create, + .lookup = glupy_lookup, + .create = glupy_create, + .open = glupy_open, + .readv = glupy_readv, + .writev = glupy_writev, + .opendir = glupy_opendir, + .readdir = glupy_readdir, + .stat = glupy_stat, + .fstat = glupy_fstat, + .setxattr = glupy_setxattr, + .getxattr = glupy_getxattr, + .fsetxattr = glupy_fsetxattr, + .fgetxattr = glupy_fgetxattr, + .removexattr = glupy_removexattr, + .fremovexattr = glupy_fremovexattr, + .link = glupy_link, + .unlink = glupy_unlink, + .readlink = glupy_readlink, + .symlink = glupy_symlink, + .mkdir = glupy_mkdir, + .rmdir = glupy_rmdir, + .statfs = glupy_statfs, + .readdirp = glupy_readdirp }; struct xlator_cbks cbks = { diff --git a/xlators/features/glupy/src/glupy.h b/xlators/features/glupy/src/glupy.h index e6d2ff4f32c..8661fce88c5 100644 --- a/xlators/features/glupy/src/glupy.h +++ b/xlators/features/glupy/src/glupy.h @@ -29,6 +29,28 @@ enum { GLUPY_LOOKUP = 0, GLUPY_CREATE, + GLUPY_OPEN, + GLUPY_READV, + GLUPY_WRITEV, + GLUPY_OPENDIR, + GLUPY_READDIR, + GLUPY_READDIRP, + GLUPY_STAT, + GLUPY_FSTAT, + GLUPY_STATFS, + GLUPY_SETXATTR, + GLUPY_GETXATTR, + GLUPY_FSETXATTR, + GLUPY_FGETXATTR, + GLUPY_REMOVEXATTR, + GLUPY_FREMOVEXATTR, + GLUPY_LINK, + GLUPY_UNLINK, + GLUPY_READLINK, + GLUPY_SYMLINK, + GLUPY_MKNOD, + GLUPY_MKDIR, + GLUPY_RMDIR, GLUPY_N_FUNCS }; diff --git a/xlators/features/glupy/src/gluster.py b/xlators/features/glupy/src/gluster.py index ac732fb1733..a5daa77d32a 100644 --- a/xlators/features/glupy/src/gluster.py +++ b/xlators/features/glupy/src/gluster.py @@ -3,116 +3,839 @@ from ctypes import * dl = CDLL("",RTLD_GLOBAL) + class call_frame_t (Structure): - pass + pass + +class dev_t (Structure): + pass + class dict_t (Structure): - pass + pass -class fd_t (Structure): + +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): - pass + _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 + 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", c_void_p ), - ( "parent", c_void_p ), - # Not quite correct, but easier to manipulate. - ( "gfid", c_uint * 4 ), - ( "pargfid", c_uint * 4 ), - ] + _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), + ] + -class xlator_t (Structure): - pass 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:]) + # 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)) + 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) + 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)) + 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) + dl.wind_create, dl.unwind_create) -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) - return 0 - self.stub_refs["create_cbk"] = stub - dl.set_create_cbk(c_this,stub) +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/negative.py b/xlators/features/glupy/src/negative.py index 6ca855f72f0..1023602b9f3 100644 --- a/xlators/features/glupy/src/negative.py +++ b/xlators/features/glupy/src/negative.py @@ -1,4 +1,5 @@ import sys +from uuid import UUID from gluster import * # Negative-lookup-caching example. If a file wasn't there the last time we @@ -19,75 +20,73 @@ cache = {} dl.get_id.restype = c_long dl.get_id.argtypes = [ POINTER(call_frame_t) ] -def uuid2str (orig): - return "%08x%08x%08x%08x" % (orig[0], orig[1], orig[2], orig[3]) +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 __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_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 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_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 + 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 |