From: Yan, Zheng Date: Sun, 1 Mar 2015 06:17:35 +0000 (+0800) Subject: libcephfs: add ceph_f{get,set,list,remove)_xattr X-Git-Tag: v9.0.0~142^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=87e82ee3b80f00a092b800dbf69fc87fdb32c8e9;p=ceph.git libcephfs: add ceph_f{get,set,list,remove)_xattr Add xattr functions that operate on file descriptor Signed-off-by: Yan, Zheng --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 5c4654da2f8c..92a1957a50e1 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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) { diff --git a/src/client/Client.h b/src/client/Client.h index d1dbebb3a603..5961e9dceca5 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -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(); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index b2645ea5bff5..769d4bdf5937 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -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. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc index e3281de27348..c0d3e15b5905 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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)