]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: add ceph_f{get,set,list,remove)_xattr
authorYan, Zheng <zyan@redhat.com>
Sun, 1 Mar 2015 06:17:35 +0000 (14:17 +0800)
committerYan, Zheng <zyan@redhat.com>
Thu, 5 Mar 2015 04:51:34 +0000 (12:51 +0800)
Add xattr functions that operate on file descriptor

Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index 5c4654da2f8c68fbc80b9e2ba6ef9eaa21d48988..92a1957a50e1e03e86d8bc91f00eebed6f2fa051 100644 (file)
@@ -8417,6 +8417,15 @@ int Client::lgetxattr(const char *path, const char *name, void *value, size_t si
   return Client::_getxattr(ceph_inode, name, value, size, getuid(), getgid());
 }
 
+int Client::fgetxattr(int fd, const char *name, void *value, size_t size)
+{
+  Mutex::Locker lock(client_lock);
+  Fh *f = get_filehandle(fd);
+  if (!f)
+    return -EBADF;
+  return Client::_getxattr(f->inode, name, value, size, getuid(), getgid());
+}
+
 int Client::listxattr(const char *path, char *list, size_t size)
 {
   Mutex::Locker lock(client_lock);
@@ -8437,6 +8446,15 @@ int Client::llistxattr(const char *path, char *list, size_t size)
   return Client::_listxattr(ceph_inode, list, size, getuid(), getgid());
 }
 
+int Client::flistxattr(int fd, char *list, size_t size)
+{
+  Mutex::Locker lock(client_lock);
+  Fh *f = get_filehandle(fd);
+  if (!f)
+    return -EBADF;
+  return Client::_listxattr(f->inode, list, size, getuid(), getgid());
+}
+
 int Client::removexattr(const char *path, const char *name)
 {
   Mutex::Locker lock(client_lock);
@@ -8457,6 +8475,15 @@ int Client::lremovexattr(const char *path, const char *name)
   return Client::_removexattr(ceph_inode, name, getuid(), getgid());
 }
 
+int Client::fremovexattr(int fd, const char *name)
+{
+  Mutex::Locker lock(client_lock);
+  Fh *f = get_filehandle(fd);
+  if (!f)
+    return -EBADF;
+  return Client::_removexattr(f->inode, name, getuid(), getgid());
+}
+
 int Client::setxattr(const char *path, const char *name, const void *value, size_t size, int flags)
 {
   Mutex::Locker lock(client_lock);
@@ -8477,6 +8504,15 @@ int Client::lsetxattr(const char *path, const char *name, const void *value, siz
   return Client::_setxattr(ceph_inode, name, value, size, flags, getuid(), getgid());
 }
 
+int Client::fsetxattr(int fd, const char *name, const void *value, size_t size, int flags)
+{
+  Mutex::Locker lock(client_lock);
+  Fh *f = get_filehandle(fd);
+  if (!f)
+    return -EBADF;
+  return Client::_setxattr(f->inode, name, value, size, flags, getuid(), getgid());
+}
+
 int Client::_getxattr(Inode *in, const char *name, void *value, size_t size,
                      int uid, int gid)
 {
index d1dbebb3a603ea99d2eba4b42c5337d63a0b6196..5961e9dceca582e46bf430c0ca6c19987f8aea82 100644 (file)
@@ -840,12 +840,16 @@ public:
   // full path xattr ops
   int getxattr(const char *path, const char *name, void *value, size_t size);
   int lgetxattr(const char *path, const char *name, void *value, size_t size);
+  int fgetxattr(int fd, const char *name, void *value, size_t size);
   int listxattr(const char *path, char *list, size_t size);
   int llistxattr(const char *path, char *list, size_t size);
+  int flistxattr(int fd, char *list, size_t size);
   int removexattr(const char *path, const char *name);
   int lremovexattr(const char *path, const char *name);
+  int fremovexattr(int fd, const char *name);
   int setxattr(const char *path, const char *name, const void *value, size_t size, int flags);
   int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
+  int fsetxattr(int fd, const char *name, const void *value, size_t size, int flags);
 
   int sync_fs();
   int64_t drop_caches();
index b2645ea5bff531960fa468d1d4e30ab560f1322c..769d4bdf59371ccaca091276bdad09e370ceb42f 100644 (file)
@@ -861,6 +861,19 @@ int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf);
 int ceph_getxattr(struct ceph_mount_info *cmount, const char *path, const char *name, 
        void *value, size_t size);
 
+/**
+ * Get an extended attribute.
+ *
+ * @param cmount the ceph mount handle to use for performing the getxattr.
+ * @param fd the open file descriptor referring to the file to get extended attribute from.
+ * @param name the name of the extended attribute to get
+ * @param value a pre-allocated buffer to hold the xattr's value
+ * @param size the size of the pre-allocated buffer
+ * @returns the size of the value or a negative error code on failure.
+ */
+int ceph_fgetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
+       void *value, size_t size);
+
 /**
  * Get an extended attribute wihtout following symbolic links.  This function is
  * identical to ceph_getxattr, but if the path refers to a symbolic link,
@@ -888,6 +901,17 @@ int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path, const char
  */
 int ceph_listxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size);
 
+/**
+ * List the extended attribute keys on a file.
+ *
+ * @param cmount the ceph mount handle to use for performing the listxattr.
+ * @param fd the open file descriptor referring to the file to list extended attributes on.
+ * @param list a buffer to be filled in with the list of extended attributes keys.
+ * @param size the size of the list buffer.
+ * @returns the size of the resulting list filled in.
+ */
+int ceph_flistxattr(struct ceph_mount_info *cmount, int fd, char *list, size_t size);
+
 /**
  * Get the list of extended attribute keys on a file, but do not follow symbolic links.
  *
@@ -909,6 +933,16 @@ int ceph_llistxattr(struct ceph_mount_info *cmount, const char *path, char *list
  */
 int ceph_removexattr(struct ceph_mount_info *cmount, const char *path, const char *name);
 
+/**
+ * Remove an extended attribute from a file.
+ *
+ * @param cmount the ceph mount handle to use for performing the removexattr.
+ * @param fd the open file descriptor referring to the file to remove extended attribute from.
+ * @param name the name of the extended attribute to remove.
+ * @returns 0 on success or a negative error code on failure.
+ */
+int ceph_fremovexattr(struct ceph_mount_info *cmount, int fd, const char *name);
+
 /**
  * Remove the extended attribute from a file, do not follow symbolic links.
  *
@@ -935,6 +969,22 @@ int ceph_lremovexattr(struct ceph_mount_info *cmount, const char *path, const ch
 int ceph_setxattr(struct ceph_mount_info *cmount, const char *path, const char *name, 
        const void *value, size_t size, int flags);
 
+/**
+ * Set an extended attribute on a file.
+ *
+ * @param cmount the ceph mount handle to use for performing the setxattr.
+ * @param fd the open file descriptor referring to the file to set extended attribute on.
+ * @param name the name of the extended attribute to set.
+ * @param value the bytes of the extended attribute value
+ * @param size the size of the extended attribute value
+ * @param flags the flags can be:
+ *     CEPH_XATTR_CREATE: create the extended attribute.  Must not exist.
+ *      CEPH_XATTR_REPLACE: replace the extended attribute, Must already exist.
+ * @returns 0 on success or a negative error code on failure.
+ */
+int ceph_fsetxattr(struct ceph_mount_info *cmount, int fd, const char *name,
+       const void *value, size_t size, int flags);
+
 /**
  * Set an extended attribute on a file, do not follow symbolic links.
  *
index e3281de27348422948caa28350c69d3c30b2c5b6..c0d3e15b5905bd6129aacb52306d004c22e21bb7 100644 (file)
@@ -632,6 +632,14 @@ extern "C" int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path,
   return cmount->get_client()->lgetxattr(path, name, value, size);
 }
 
+extern "C" int ceph_fgetxattr(struct ceph_mount_info *cmount, int fd, const char *name, void *value, size_t size)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->fgetxattr(fd, name, value, size);
+}
+
+
 extern "C" int ceph_listxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size)
 {
   if (!cmount->is_mounted())
@@ -646,6 +654,13 @@ extern "C" int ceph_llistxattr(struct ceph_mount_info *cmount, const char *path,
   return cmount->get_client()->llistxattr(path, list, size);
 }
 
+extern "C" int ceph_flistxattr(struct ceph_mount_info *cmount, int fd, char *list, size_t size)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->flistxattr(fd, list, size);
+}
+
 extern "C" int ceph_removexattr(struct ceph_mount_info *cmount, const char *path, const char *name)
 {
   if (!cmount->is_mounted())
@@ -660,6 +675,13 @@ extern "C" int ceph_lremovexattr(struct ceph_mount_info *cmount, const char *pat
   return cmount->get_client()->lremovexattr(path, name);
 }
 
+extern "C" int ceph_fremovexattr(struct ceph_mount_info *cmount, int fd, const char *name)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->fremovexattr(fd, name);
+}
+
 extern "C" int ceph_setxattr(struct ceph_mount_info *cmount, const char *path, const char *name, const void *value, size_t size, int flags)
 {
   if (!cmount->is_mounted())
@@ -673,6 +695,13 @@ extern "C" int ceph_lsetxattr(struct ceph_mount_info *cmount, const char *path,
     return -ENOTCONN;
   return cmount->get_client()->lsetxattr(path, name, value, size, flags);
 }
+
+extern "C" int ceph_fsetxattr(struct ceph_mount_info *cmount, int fd, const char *name, const void *value, size_t size, int flags)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->fsetxattr(fd, name, value, size, flags);
+}
 /* end xattr support */
 
 extern "C" int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode)