summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorVikas Gorur <vikas@gluster.com>2009-03-16 04:03:55 -0700
committerAnand V. Avati <avati@amp.gluster.com>2009-03-17 17:15:07 +0530
commit3099d29e8e65554af31927c8f767b9b6103ca58e (patch)
tree0f9aef0dd519a591f3129871281ef248082f19d4 /libglusterfs/src
parent7d61f9d69309ccb0f9aa787caacfef77bc4e32d2 (diff)
Add system call abstraction layer
- syscall.c provides platform-independent system calls - previous code for this from compat.c removed - posix xlator uses new functions from syscall.c - solaris_flistxattr added to compat.c Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/Makefile.am4
-rw-r--r--libglusterfs/src/compat.c55
-rw-r--r--libglusterfs/src/compat.h21
-rw-r--r--libglusterfs/src/syscall.c432
-rw-r--r--libglusterfs/src/syscall.h148
5 files changed, 637 insertions, 23 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index 16e6717de9e..982c4d69de9 100644
--- a/libglusterfs/src/Makefile.am
+++ b/libglusterfs/src/Makefile.am
@@ -6,9 +6,9 @@ libglusterfs_la_LIBADD = @LEXLIB@
lib_LTLIBRARIES = libglusterfs.la
-libglusterfs_la_SOURCES = dict.c spec.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c scheduler.c common-utils.c transport.c timer.c inode.c call-stub.c compat.c authenticate.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c
+libglusterfs_la_SOURCES = dict.c spec.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c scheduler.c common-utils.c transport.c timer.c inode.c call-stub.c compat.c authenticate.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c
-noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h protocol.h scheduler.h xlator.h transport.h stack.h timer.h list.h inode.h call-stub.h compat.h authenticate.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h
+noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h protocol.h scheduler.h xlator.h transport.h stack.h timer.h list.h inode.h call-stub.h compat.h authenticate.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h syscall.h
EXTRA_DIST = spec.l spec.y
diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c
index f0bd9119c7c..bad62b563d5 100644
--- a/libglusterfs/src/compat.c
+++ b/libglusterfs/src/compat.c
@@ -264,6 +264,61 @@ solaris_listxattr(const char *path,
return len;
}
+
+int
+solaris_flistxattr(int fd,
+ char *list,
+ size_t size)
+{
+ int attrdirfd = -1;
+ ssize_t len = 0;
+ DIR *dirptr = NULL;
+ struct dirent *dent = NULL;
+ int newfd = -1;
+
+ attrdirfd = openat (fd, ".", O_RDONLY, 0);
+ if (attrdirfd >= 0) {
+ newfd = dup(attrdirfd);
+ dirptr = fdopendir(newfd);
+ if (dirptr) {
+ while ((dent = readdir(dirptr))) {
+ size_t listlen = strlen(dent->d_name);
+ if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) {
+ /* we don't want "." and ".." here */
+ continue;
+ }
+ if (size == 0) {
+ /* return the current size of the list of extended attribute names*/
+ len += listlen + 1;
+ } else {
+ /* check size and copy entrie + nul into list. */
+ if ((len + listlen + 1) > size) {
+ errno = ERANGE;
+ len = -1;
+ break;
+ } else {
+ strncpy(list + len, dent->d_name, listlen);
+ len += listlen;
+ list[len] = '\0';
+ ++len;
+ }
+ }
+ }
+
+ if (closedir(dirptr) == -1) {
+ close (attrdirfd);
+ return -1;
+ }
+ } else {
+ close (attrdirfd);
+ return -1;
+ }
+ close (attrdirfd);
+ }
+ return len;
+}
+
+
int
solaris_removexattr(const char *path,
const char* key)
diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index 67f8138b1df..42d2fa1419e 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -107,14 +107,6 @@ enum {
# endif
# endif
-#define lremovexattr(path,key) extattr_delete_link(path, EXTATTR_NAMESPACE_USER, key)
-#define llistxattr(path,key,size) extattr_list_link(path, EXTATTR_NAMESPACE_USER, key, size)
-#define lgetxattr(path, key, value, size) extattr_get_link(path, EXTATTR_NAMESPACE_USER, key, value, size)
-#define lsetxattr(path,key,value,size,flags) extattr_set_link(path, EXTATTR_NAMESPACE_USER, key, value, size)
-#define fgetxattr(fd,key,value,size) extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, key, value, size)
-#define fsetxattr(fd,key,value,size,flag) extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, key, value, size)
-
-
#define F_GETLK64 F_GETLK
#define F_SETLK64 F_SETLK
#define F_SETLKW64 F_SETLKW
@@ -168,13 +160,6 @@ enum {
# endif
# endif
-#define llistxattr(path,key,size) listxattr(path,key,size,XATTR_NOFOLLOW)
-#define lgetxattr(path,key,value,size) getxattr(path,key,value,size,0,XATTR_NOFOLLOW)
-#define lsetxattr(path,key,value,size,flags) setxattr(path,key,value,size,0,flags|XATTR_NOFOLLOW)
-#define lremovexattr(path,key) removexattr(path,key,XATTR_NOFOLLOW)
-#define fgetxattr(path,key,value,size) fgetxattr(path,key,value,size,0,0)
-#define fsetxattr(path,key,value,size,flag) fsetxattr(path,key,value,size,0,flag)
-
#define F_GETLK64 F_GETLK
#define F_SETLK64 F_SETLK
#define F_SETLKW64 F_SETLKW
@@ -231,12 +216,6 @@ enum {
#define s6_addr32 _S6_un._S6_u32
#endif
-#define lremovexattr(path,key) solaris_removexattr(path,key)
-#define llistxattr(path,key,size) solaris_listxattr(path,key,size)
-#define lgetxattr(path,key,value,size) solaris_getxattr(path,key,value,size)
-#define lsetxattr(path,key,value,size,flags) solaris_setxattr(path,key,value,size,flags)
-#define fgetxattr(fd,key,value,size) solaris_fgetxattr(fd,key,value,size)
-#define fsetxattr(fd,key,value,size,flags) solaris_fsetxattr(fd,key,value,size,flags)
#define lutimes(filename,times) utimes(filename,times)
int asprintf(char **string_ptr, const char *format, ...);
diff --git a/libglusterfs/src/syscall.c b/libglusterfs/src/syscall.c
new file mode 100644
index 00000000000..f8e8c939a77
--- /dev/null
+++ b/libglusterfs/src/syscall.c
@@ -0,0 +1,432 @@
+/*
+ Copyright (c) 2009 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "compat.h"
+#include "syscall.h"
+
+#include <sys/types.h>
+#include <utime.h>
+#include <sys/time.h>
+
+int
+sys_lstat (const char *path, struct stat *buf)
+{
+ return lstat (path, buf);
+}
+
+
+int
+sys_stat (const char *path, struct stat *buf)
+{
+ return stat (path, buf);
+}
+
+
+int
+sys_fstat (int fd, struct stat *buf)
+{
+ return fstat (fd, buf);
+}
+
+
+DIR *
+sys_opendir (const char *name)
+{
+ return opendir (name);
+}
+
+
+struct dirent *
+sys_readdir (DIR *dir)
+{
+ return readdir (dir);
+}
+
+
+ssize_t
+sys_readlink (const char *path, char *buf, size_t bufsiz)
+{
+ return readlink (path, buf, bufsiz);
+}
+
+
+int
+sys_closedir (DIR *dir)
+{
+ return closedir (dir);
+}
+
+
+int
+sys_mknod (const char *pathname, mode_t mode, dev_t dev)
+{
+ return mknod (pathname, mode, dev);
+}
+
+
+int
+sys_mkdir (const char *pathname, mode_t mode)
+{
+ return mkdir (pathname, mode);
+}
+
+
+int
+sys_unlink (const char *pathname)
+{
+ return unlink (pathname);
+}
+
+
+int
+sys_rmdir (const char *pathname)
+{
+ return rmdir (pathname);
+}
+
+
+int
+sys_symlink (const char *oldpath, const char *newpath)
+{
+ return symlink (oldpath, newpath);
+}
+
+
+int
+sys_rename (const char *oldpath, const char *newpath)
+{
+ return rename (oldpath, newpath);
+}
+
+
+int
+sys_link (const char *oldpath, const char *newpath)
+{
+ return link (oldpath, newpath);
+}
+
+
+int
+sys_chmod (const char *path, mode_t mode)
+{
+ return chmod (path, mode);
+}
+
+
+int
+sys_fchmod (int fd, mode_t mode)
+{
+ return fchmod (fd, mode);
+}
+
+
+int
+sys_chown (const char *path, uid_t owner, gid_t group)
+{
+ return chown (path, owner, group);
+}
+
+
+int
+sys_fchown (int fd, uid_t owner, gid_t group)
+{
+ return fchown (fd, owner, group);
+}
+
+
+int
+sys_lchown (const char *path, uid_t owner, gid_t group)
+{
+ return lchown (path, owner, group);
+}
+
+
+int
+sys_truncate (const char *path, off_t length)
+{
+ return truncate (path, length);
+}
+
+
+int
+sys_ftruncate (int fd, off_t length)
+{
+ return ftruncate (fd, length);
+}
+
+
+int
+sys_utimes (const char *filename, const struct timeval times[2])
+{
+ return utimes (filename, times);
+}
+
+
+int
+sys_creat (const char *pathname, mode_t mode)
+{
+ return creat (pathname, mode);
+}
+
+
+ssize_t
+sys_readv (int fd, const struct iovec *iov, int iovcnt)
+{
+ return readv (fd, iov, iovcnt);
+}
+
+
+ssize_t
+sys_writev (int fd, const struct iovec *iov, int iovcnt)
+{
+ return writev (fd, iov, iovcnt);
+}
+
+
+ssize_t
+sys_read (int fd, void *buf, size_t count)
+{
+ return read (fd, buf, count);
+}
+
+
+ssize_t
+sys_write (int fd, const void *buf, size_t count)
+{
+ return write (fd, buf, count);
+}
+
+
+off_t
+sys_lseek (int fd, off_t offset, int whence)
+{
+ return lseek (fd, offset, whence);
+}
+
+
+int
+sys_statvfs (const char *path, struct statvfs *buf)
+{
+ return statvfs (path, buf);
+}
+
+
+int
+sys_close (int fd)
+{
+ return close (fd);
+}
+
+
+int
+sys_fsync (int fd)
+{
+ return fsync (fd);
+}
+
+
+int
+sys_fdatasync (int fd)
+{
+#ifdef HAVE_FDATASYNC
+ return fdatasync (fd);
+#else
+ return 0;
+#endif
+}
+
+
+int
+sys_lsetxattr (const char *path, const char *name, const void *value,
+ size_t size, int flags)
+{
+
+#ifdef GF_LINUX_HOST_OS
+ return lsetxattr (path, name, value, size, flags);
+#endif
+
+#ifdef GF_BSD_HOST_OS
+ return extattr_set_link (path, EXTATTR_NAMESPACE_USER,
+ name, value, size);
+#endif
+
+#ifdef GF_SOLARIS_HOST_OS
+ return solaris_setxattr (path, name, value, size, flags);
+#endif
+
+#ifdef GF_DARWIN_HOST_OS
+ return setxattr (path, name, value, size, 0,
+ flags|XATTR_NOFOLLOW);
+#endif
+
+}
+
+
+ssize_t
+sys_llistxattr (const char *path, char *list, size_t size)
+{
+
+#ifdef GF_LINUX_HOST_OS
+ return llistxattr (path, list, size);
+#endif
+
+#ifdef GF_BSD_HOST_OS
+ return extattr_list_link (path, EXTATTR_NAMESPACE_USER, list, size);
+#endif
+
+#ifdef GF_SOLARIS_HOST_OS
+ return solaris_listxattr (path, list, size);
+#endif
+
+#ifdef GF_DARWIN_HOST_OS
+ return listxattr (path, list, size, XATTR_NOFOLLOW);
+#endif
+
+}
+
+
+ssize_t
+sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
+{
+
+#ifdef GF_LINUX_HOST_OS
+ return lgetxattr (path, name, value, size);
+#endif
+
+#ifdef GF_BSD_HOST_OS
+ return extattr_get_link (path, EXTATTR_NAMESPACE_USER, name, value,
+ size);
+#endif
+
+#ifdef GF_SOLARIS_HOST_OS
+ return solaris_getxattr (path, name, value, size);
+#endif
+
+#ifdef GF_DARWIN_HOST_OS
+ return getxattr (path, name, value, size, 0, XATTR_NOFOLLOW);
+#endif
+
+}
+
+
+ssize_t
+sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
+{
+
+#ifdef GF_LINUX_HOST_OS
+ return fgetxattr (filedes, name, value, size);
+#endif
+
+#ifdef GF_BSD_HOST_OS
+ return extattr_get_fd (filedes, EXTATTR_NAMESPACE_USER, name,
+ value, size);
+#endif
+
+#ifdef GF_SOLARIS_HOST_OS
+ return solaris_fgetxattr (filedes, name, value, size);
+#endif
+
+#ifdef GF_DARWIN_HOST_OS
+ return fgetxattr (filedes, name, value, size, 0, 0);
+#endif
+
+}
+
+
+int
+sys_fsetxattr (int filedes, const char *name, const void *value,
+ size_t size, int flags)
+{
+
+#ifdef GF_LINUX_HOST_OS
+ return fsetxattr (filedes, name, value, size, flags);
+#endif
+
+#ifdef GF_BSD_HOST_OS
+ return extattr_set_fd (filedes, EXTATTR_NAMESPACE_USER, name,
+ value, size);
+#endif
+
+#ifdef GF_SOLARIS_HOST_OS
+ solaris_fsetxattr (filedes, name, value, size, flags);
+#endif
+
+#ifdef GF_DARWIN_HOST_OS
+ return fsetxattr (filedes, name, value, size, 0, flags);
+#endif
+
+}
+
+
+ssize_t
+sys_flistxattr (int filedes, char *list, size_t size)
+{
+
+#ifdef GF_LINUX_HOST_OS
+ return flistxattr (filedes, list, size);
+#endif
+
+#ifdef GF_BSD_HOST_OS
+ return extattr_list_fd (filedes, EXTATTR_NAMESPACE_USER, list, size);
+#endif
+
+#ifdef GF_SOLARIS_HOST_OS
+ return solaris_flistxattr (filedes, list, size);
+#endif
+
+#ifdef GF_DARWIN_HOST_OS
+ return flistxattr (filedes, list, size, XATTR_NOFOLLOW);
+#endif
+
+}
+
+
+int
+sys_lremovexattr (const char *path, const char *name)
+{
+
+#ifdef GF_LINUX_HOST_OS
+ return lremovexattr (path, name);
+#endif
+
+#ifdef GF_BSD_HOST_OS
+ return extattr_delete_link (path, EXTATTR_NAMESPACE_USER, name);
+#endif
+
+#ifdef GF_SOLARIS_HOST_OS
+ return solaris_removexattr (path, name);
+#endif
+
+#ifdef GF_DARWIN_HOST_OS
+ return removexattr (path, name, XATTR_NOFOLLOW);
+#endif
+
+}
+
+
+int
+sys_access (const char *pathname, int mode)
+{
+ return access (pathname, mode);
+}
diff --git a/libglusterfs/src/syscall.h b/libglusterfs/src/syscall.h
new file mode 100644
index 00000000000..d9cbb8fd41a
--- /dev/null
+++ b/libglusterfs/src/syscall.h
@@ -0,0 +1,148 @@
+/*
+ Copyright (c) 2009 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __SYSCALL_H__
+#define __SYSCALL_H__
+
+int
+sys_lstat (const char *path, struct stat *buf);
+
+int
+sys_stat (const char *path, struct stat *buf);
+
+int
+sys_fstat (int fd, struct stat *buf);
+
+DIR *
+sys_opendir (const char *name);
+
+struct dirent *
+sys_readdir (DIR *dir);
+
+ssize_t
+sys_readlink (const char *path, char *buf, size_t bufsiz);
+
+int
+sys_closedir (DIR *dir);
+
+int
+sys_mknod (const char *pathname, mode_t mode, dev_t dev);
+
+int
+sys_mkdir (const char *pathname, mode_t mode);
+
+int
+sys_unlink (const char *pathname);
+
+int
+sys_rmdir (const char *pathname);
+
+int
+sys_symlink (const char *oldpath, const char *newpath);
+
+int
+sys_rename (const char *oldpath, const char *newpath);
+
+int
+sys_link (const char *oldpath, const char *newpath);
+
+int
+sys_chmod (const char *path, mode_t mode);
+
+int
+sys_fchmod (int fd, mode_t mode);
+
+int
+sys_chown (const char *path, uid_t owner, gid_t group);
+
+int
+sys_fchown (int fd, uid_t owner, gid_t group);
+
+int
+sys_lchown (const char *path, uid_t owner, gid_t group);
+
+int
+sys_truncate (const char *path, off_t length);
+
+int
+sys_ftruncate (int fd, off_t length);
+
+int
+sys_utimes (const char *filename, const struct timeval times[2]);
+
+int
+sys_creat (const char *pathname, mode_t mode);
+
+ssize_t
+sys_readv (int fd, const struct iovec *iov, int iovcnt);
+
+ssize_t
+sys_writev (int fd, const struct iovec *iov, int iovcnt);
+
+ssize_t
+sys_read (int fd, void *buf, size_t count);
+
+ssize_t
+sys_write (int fd, const void *buf, size_t count);
+
+off_t
+sys_lseek (int fd, off_t offset, int whence);
+
+int
+sys_statvfs (const char *path, struct statvfs *buf);
+
+int
+sys_close (int fd);
+
+int
+sys_fsync (int fd);
+
+int
+sys_fdatasync (int fd);
+
+int
+sys_lsetxattr (const char *path, const char *name, const void *value,
+ size_t size, int flags);
+
+ssize_t
+sys_llistxattr (const char *path, char *list, size_t size);
+
+ssize_t
+sys_lgetxattr (const char *path, const char *name, void *value, size_t size);
+
+ssize_t
+sys_fgetxattr (int filedes, const char *name, void *value, size_t size);
+
+int
+sys_fsetxattr (int filedes, const char *name, const void *value,
+ size_t size, int flags);
+
+ssize_t
+sys_flistxattr (int filedes, char *list, size_t size);
+
+int
+sys_lremovexattr (const char *path, const char *name);
+
+int
+sys_access (const char *pathname, int mode);
+
+int
+sys_ftruncate (int fd, off_t length);
+
+#endif /* __SYSCALL_H__ */