Merge pull request #3840 from ceph/wip-libcephfs-fsetxattr

libcephfs: add ceph_f{get,set,list,remove)_xattr

Reviewed-by: John Spray <john.spray@redhat.com>
This commit is contained in:
John Spray 2015-03-19 22:03:04 +00:00
commit 3ee11b567c
4 changed files with 126 additions and 0 deletions

View File

@ -8429,6 +8429,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);
@ -8449,6 +8458,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);
@ -8469,6 +8487,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);
@ -8489,6 +8516,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)
{

View File

@ -841,12 +841,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();

View File

@ -33,6 +33,13 @@ typedef off_t off64_t;
extern "C" {
#endif
#define LIBCEPHFS_VER_MAJOR 0
#define LIBCEPHFS_VER_MINOR 94
#define LIBCEPHFS_VER_EXTRA 0
#define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
#define LIBCEPHFS_VERSION_CODE LIBCEPHFS_VERSION(LIBCEPHFS_VER_MAJOR, LIBCEPHFS_VER_MINOR, LIBCEPHFS_VER_EXTRA)
/*
* On FreeBSD and Apple the offset is 64 bit, but libc doesn't announce it in
* the way glibc does.
@ -876,6 +883,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,
@ -903,6 +923,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.
*
@ -924,6 +955,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.
*
@ -950,6 +991,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.
*

View 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)