summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Watkins <noahwatkins@gmail.com>2013-07-20 18:41:40 -0700
committerNoah Watkins <noahwatkins@gmail.com>2013-09-17 10:16:20 -0700
commit09366738e37700c0f70faa00cc5e72b468d67a8f (patch)
tree56f2022ba54ae05f78c6a9e62e739d4392d8120c
parent4a0570b89c21dbc9e33491f1a863fb14e2ee9592 (diff)
downloadceph-09366738e37700c0f70faa00cc5e72b468d67a8f.tar.gz
xattr: test for xattr routine variants
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r--configure.ac7
-rw-r--r--src/common/xattr.c113
2 files changed, 82 insertions, 38 deletions
diff --git a/configure.ac b/configure.ac
index e84567ef8e4..90e2c7d5eb4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -551,9 +551,16 @@ AC_CHECK_MEMBER([struct stat.st_mtimespec.tv_nsec],
[AC_DEFINE(HAVE_STAT_ST_TIMESPEC, 1,
[Define if you have struct stat.st_mtimespec.tv_nsec])])
+AC_CHECK_FUNC([extattr_set_fd],
+ [AC_DEFINE(HAVE_EXTATTR, 1, [Define if you have extattr_set_fd])])
+
AC_CHECK_HEADERS([linux/fs.h])
AC_CHECK_HEADERS([sys/disk.h])
AC_CHECK_HEADERS([sys/prctl.h])
+AC_CHECK_HEADERS([sys/extattr.h])
+AC_CHECK_HEADERS([sys/xattr.h])
+AC_CHECK_HEADERS([sys/malloc.h])
+AC_CHECK_HEADERS([strings.h])
AC_CHECK_FUNCS([prctl])
AC_CHECK_FUNCS([posix_fadvise])
AC_CHECK_FUNCS([sem_timedwait])
diff --git a/src/common/xattr.c b/src/common/xattr.c
index 239ee02db42..e06076f3965 100644
--- a/src/common/xattr.c
+++ b/src/common/xattr.c
@@ -7,22 +7,39 @@
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
+ *
+ * OSX Support
+ * -----------
+ * The xattr access routines on OSX include a `position` argument in addition
+ * to the parameters of the standard Linux counterparts. A custom feature test
+ * can be written to detect the different versions. For now we test for
+ * __APPLE__, and default to the Linux version.
*/
-#if defined(__FreeBSD__)
-#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
+#include "acconfig.h"
+
+/*
+ * The original FreeBSD port below (now guarded by HAVE_EXTATTR) was using
+ * FreeBSD specific string manipulation routines.
+ */
+#ifdef HAVE_STRINGS_H
#include <strings.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_EXTATTR_H
#include <sys/extattr.h>
-#elif defined(__linux__)
-#include <sys/types.h>
-#include <sys/xattr.h>
-#elif defined(DARWIN)
+#endif
+
+#ifdef HAVE_SYS_XATTR_H
#include <sys/xattr.h>
-#else
-#error "Your system is not supported!"
+#endif
+
+#ifdef HAVE_SYS_MALLOC_H
+#include <sys/malloc.h>
#endif
#include "common/xattr.h"
@@ -37,14 +54,18 @@ ceph_os_setxattr(const char *path, const char *name,
{
int error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
error = extattr_set_file(path, EXTATTR_NAMESPACE_USER, name, value,
size);
if (error > 0)
error = 0;
-#elif defined(__linux__) || defined(DARWIN)
+#else
+#ifdef __APPLE__
+ error = setxattr(path, name, value, size, 0, 0);
+#else
error = setxattr(path, name, value, size, 0);
#endif
+#endif
return (error);
}
@@ -55,14 +76,18 @@ ceph_os_fsetxattr(int fd, const char *name, const void *value,
{
int error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
error = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, name, value,
size);
if (error > 0)
error = 0;
-#elif defined(__linux__) || defined(DARWIN)
+#else
+#ifdef __APPLE__
+ error = fsetxattr(fd, name, value, size, 0, 0);
+#else
error = fsetxattr(fd, name, value, size, 0);
#endif
+#endif
return (error);
}
@@ -73,7 +98,7 @@ void *value, size_t size)
{
ssize_t error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
if (value == NULL || size == 0) {
error = extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, value,
size);
@@ -90,10 +115,12 @@ void *value, size_t size)
}
}
}
-#elif defined(__linux__)
+#else
+#ifdef __APPLE__
+ error = getxattr(path, name, value, size, 0, 0);
+#else
error = getxattr(path, name, value, size);
-#elif defined(DARWIN)
- error = getxattr(path, name, value, size, 0);
+#endif
#endif
return (error);
@@ -105,7 +132,7 @@ ceph_os_fgetxattr(int fd, const char *name, void *value,
{
ssize_t error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
if (value == NULL || size == 0) {
error = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, value,
size);
@@ -122,10 +149,12 @@ ceph_os_fgetxattr(int fd, const char *name, void *value,
}
}
}
-#elif defined(__linux__)
+#else
+#ifdef __APPLE__
+ error = fgetxattr(fd, name, value, size, 0, 0);
+#else
error = fgetxattr(fd, name, value, size);
-#elif defined(DARWIN)
- error = fgetxattr(fd, name, value, size, 0);
+#endif
#endif
return (error);
@@ -136,7 +165,7 @@ ceph_os_listxattr(const char *path, char *list, size_t size)
{
ssize_t error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
/*
* XXX. The format of the list FreeBSD returns differs
* from the Linux ones. We have to perform the conversion. :-(
@@ -171,10 +200,12 @@ ceph_os_listxattr(const char *path, char *list, size_t size)
error = extattr_list_file(path, EXTATTR_NAMESPACE_USER,
list, size);
}
-#elif defined(__linux__)
- error = listxattr(path, list, size);
-#elif defined(DARWIN)
+#else
+#ifdef __APPLE__
error = listxattr(path, list, size, 0);
+#else
+ error = listxattr(path, list, size);
+#endif
#endif
return (error);
@@ -185,7 +216,7 @@ ceph_os_flistxattr(int fd, char *list, size_t size)
{
ssize_t error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
/*
* XXX. The format of the list FreeBSD returns differs
* from the Linux ones. We have to perform the conversion. :-(
@@ -220,10 +251,12 @@ ceph_os_flistxattr(int fd, char *list, size_t size)
error = extattr_list_fd(fd, EXTATTR_NAMESPACE_USER,
list, size);
}
-#elif defined(__linux__)
- error = flistxattr(fd, list, size);
-#elif defined(DARWIN)
+#else
+#ifdef __APPLE__
error = flistxattr(fd, list, size, 0);
+#else
+ error = flistxattr(fd, list, size);
+#endif
#endif
return (error);
@@ -234,12 +267,14 @@ ceph_os_removexattr(const char *path, const char *name)
{
int error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
error = extattr_delete_file(path, EXTATTR_NAMESPACE_USER, name);
-#elif defined(__linux__)
- error = removexattr(path, name);
-#elif defined(DARWIN)
+#else
+#ifdef __APPLE__
error = removexattr(path, name, 0);
+#else
+ error = removexattr(path, name);
+#endif
#endif
return (error);
@@ -250,12 +285,14 @@ ceph_os_fremovexattr(int fd, const char *name)
{
int error = -1;
-#if defined(__FreeBSD__)
+#ifdef HAVE_EXTATTR
error = extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, name);
-#elif defined(__linux__)
- error = fremovexattr(fd, name);
-#elif defined(DARWIN)
+#else
+#ifdef __APPLE__
error = fremovexattr(fd, name, 0);
+#else
+ error = fremovexattr(fd, name);
+#endif
#endif
return (error);