diff options
Diffstat (limited to 'api/examples/gfapi.py')
| -rwxr-xr-x | api/examples/gfapi.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/api/examples/gfapi.py b/api/examples/gfapi.py index 7d7a5bab1..3ac67f4d5 100755 --- a/api/examples/gfapi.py +++ b/api/examples/gfapi.py @@ -1,6 +1,7 @@ #!/usr/bin/python from ctypes import * +from ctypes.util import find_library import os import sys import time @@ -8,9 +9,9 @@ import types # Looks like ctypes is having trouble with dependencies, so just force them to # load with RTLD_GLOBAL until I figure that out. -glfs = CDLL("libglusterfs.so",RTLD_GLOBAL) -xdr = CDLL("libgfxdr.so",RTLD_GLOBAL) -api = CDLL("libgfapi.so",RTLD_GLOBAL) +glfs = CDLL(find_library("glusterfs"),RTLD_GLOBAL) +xdr = CDLL(find_library("gfxdr"),RTLD_GLOBAL) +api = CDLL(find_library("gfapi"),RTLD_GLOBAL) # Wow, the Linux kernel folks really play nasty games with this structure. If # you look at the man page for stat(2) and then at this definition you'll note @@ -98,6 +99,13 @@ class File(object): def write (self, data, flags=0): return api.glfs_write(self.fd,data,len(data),flags) + def fallocate (self, mode, offset, len): + return api.glfs_fallocate(self.fd, mode, offset, len) + + def discard (self, offset, len): + return api.glfs_discard(self.fd, offset, len) + + class Dir(object): def __init__ (self, fd): @@ -349,6 +357,19 @@ if __name__ == "__main__": return False, "wrong listxattr value %s" % repr(xattrs) return True, "listxattr worked" + def test_fallocate (vol, path, data): + mypath = path + ".io" + fd = vol.creat(mypath,os.O_WRONLY|os.O_EXCL,0644) + if not fd: + return False, "creat error" + rc = fd.fallocate(0, 0, 1024*1024) + if rc != 0: + return False, "fallocate error" + rc = fd.discard(4096, 4096) + if rc != 0: + return False, "discard error" + return True, "fallocate/discard worked" + test_list = ( test_create_write, test_open_read, @@ -363,6 +384,7 @@ if __name__ == "__main__": test_setxattr, test_getxattr, test_listxattr, + test_fallocate, ) ok_to_fail = ( |
