From c78dafac7f82de8a7b72f42fcd58c01dbc4a88df Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Sat, 16 Apr 2011 10:32:53 +0000 Subject: syncdaemon: load xattrs from libc on-demand This reduces startup time for invocations other than master / slave role (kind of which now proliferates glusterd) Signed-off-by: Csaba Henk Signed-off-by: Anand Avati BUG: 2780 (geo-replication operations take too much time to complete) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2780 --- .../features/marker/utils/syncdaemon/libcxattr.py | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 xlators/features/marker/utils/syncdaemon/libcxattr.py (limited to 'xlators/features/marker/utils/syncdaemon/libcxattr.py') diff --git a/xlators/features/marker/utils/syncdaemon/libcxattr.py b/xlators/features/marker/utils/syncdaemon/libcxattr.py new file mode 100644 index 00000000000..907a16c7802 --- /dev/null +++ b/xlators/features/marker/utils/syncdaemon/libcxattr.py @@ -0,0 +1,63 @@ +import os +from ctypes import * +from ctypes.util import find_library + +class Xattr(object): + + libc = CDLL(find_library("libc")) + + @classmethod + def geterrno(cls): + return c_int.in_dll(cls.libc, 'errno').value + + @classmethod + def raise_oserr(cls): + errn = cls.geterrno() + raise OSError(errn, os.strerror(errn)) + + @classmethod + def _query_xattr(cls, path, siz, syscall, *a): + if siz: + buf = create_string_buffer('\0' * siz) + else: + buf = None + ret = getattr(cls.libc, syscall)(*((path,) + a + (buf, siz))) + if ret == -1: + cls.raise_oserr() + if siz: + return buf.raw[:ret] + else: + return ret + + @classmethod + def lgetxattr(cls, path, attr, siz=0): + return cls._query_xattr( path, siz, 'lgetxattr', attr) + + @classmethod + def llistxattr(cls, path, siz=0): + ret = cls._query_xattr(path, siz, 'llistxattr') + if isinstance(ret, str): + ret = ret.split('\0') + return ret + + @classmethod + def lsetxattr(cls, path, attr, val): + ret = cls.libc.lsetxattr(path, attr, val, len(val), 0) + if ret == -1: + cls.raise_oserr() + + @classmethod + def lremovexattr(cls, path, attr): + ret = cls.libc.lremovexattr(path, attr) + if ret == -1: + cls.raise_oserr() + + @classmethod + def llistxattr_buf(cls, path): + size = cls.llistxattr(path) + if size == -1: + raise_oserr() + return cls.llistxattr(path, size) + + + -- cgit