From: Jeff Layton Date: Tue, 25 Oct 2016 13:14:20 +0000 (-0400) Subject: client: add a ceph_fsetattrx X-Git-Tag: v11.1.0~383^2~29 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c18a4be5fb882c4d2c50b7c3bbb79c75d2621480;p=ceph.git client: add a ceph_fsetattrx ...and convert ceph_fsetattr callers to use it instead. Signed-off-by: Jeff Layton --- diff --git a/src/client/Client.cc b/src/client/Client.cc index a3194f23a885..ee18d1caf687 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6682,6 +6682,23 @@ int Client::fsetattr(int fd, struct stat *attr, int mask, const UserPerm& perms) return _setattr(f->inode, attr, mask, perms); } +int Client::fsetattrx(int fd, struct ceph_statx *stx, int mask, const UserPerm& perms) +{ + Mutex::Locker lock(client_lock); + tout(cct) << "fsetattr" << std::endl; + tout(cct) << fd << std::endl; + tout(cct) << mask << std::endl; + + Fh *f = get_filehandle(fd); + if (!f) + return -EBADF; +#if defined(__linux__) && defined(O_PATH) + if (f->flags & O_PATH) + return -EBADF; +#endif + return _setattrx(f->inode, stx, mask, perms); +} + int Client::stat(const char *relpath, struct stat *stbuf, const UserPerm& perms, frag_info_t *dirstat, int mask) { diff --git a/src/client/Client.h b/src/client/Client.h index d544e927558f..2e2591710361 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1007,6 +1007,7 @@ public: int setattrx(const char *relpath, struct ceph_statx *stx, int mask, const UserPerm& perms, int flags=0); int fsetattr(int fd, struct stat *attr, int mask, const UserPerm& perms); + int fsetattrx(int fd, struct ceph_statx *stx, int mask, const UserPerm& perms); int chmod(const char *path, mode_t mode, const UserPerm& perms); int fchmod(int fd, mode_t mode, const UserPerm& perms); int lchmod(const char *path, mode_t mode, const UserPerm& perms); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 09e9801ea35b..ca8de2066beb 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -655,6 +655,18 @@ int ceph_lstat(struct ceph_mount_info *cmount, const char *path, struct stat *st */ int ceph_setattr(struct ceph_mount_info *cmount, const char *relpath, struct stat *attr, int mask); +/** + * Set a file's attributes (extended version). + * + * @param cmount the ceph mount handle to use for performing the setattr. + * @param relpath the path to the file/directory to set the attributes of. + * @param stx the statx struct that must include attribute values to set on the file. + * @param mask a mask of all the CEPH_SETATTR_* values that have been set in the statx struct. + * @param flags mask of AT_* flags (only AT_ATTR_NOFOLLOW is respected for now) + * @returns 0 on success or negative error code on failure. + */ +int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath, struct ceph_statx *stx, int mask, int flags); + /** * Set a file's attributes. * @@ -668,15 +680,14 @@ int ceph_fsetattr(struct ceph_mount_info *cmount, int fd, struct stat *attr, int /** * Set a file's attributes (extended version). - * + * * @param cmount the ceph mount handle to use for performing the setattr. - * @param relpath the path to the file/directory to set the attributes of. + * @param fd the fd of the open file/directory to set the attributes of. * @param stx the statx struct that must include attribute values to set on the file. - * @param mask a mask of all the CEPH_SETATTR_* values that have been set in the statx struct. - * @param flags mask of AT_* flags (only AT_ATTR_NOFOLLOW is respected for now) + * @param mask a mask of all the stat values that have been set on the stat struct. * @returns 0 on success or negative error code on failure. */ -int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath, struct ceph_statx *stx, int mask, int flags); +int ceph_fsetattrx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, int mask); /** * Change the mode bits (permissions) of a file/directory. diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 40a7b50bda1d..bf3d414063b9 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -649,6 +649,14 @@ extern "C" int ceph_fsetattr(struct ceph_mount_info *cmount, int fd, return cmount->get_client()->fsetattr(fd, attr, mask, cmount->default_perms); } +extern "C" int ceph_fsetattrx(struct ceph_mount_info *cmount, int fd, + struct ceph_statx *stx, int mask) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->fsetattrx(fd, stx, mask, cmount->default_perms); +} + extern "C" int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath, struct ceph_statx *stx, int mask, int flags) { diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 3fe62a790353..919683f5724e 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -1158,6 +1158,7 @@ TEST(LibCephFS, UseUnmounted) { EXPECT_EQ(-ENOTCONN, ceph_setxattr(cmount, "/path", "name", NULL, 0, 0)); EXPECT_EQ(-ENOTCONN, ceph_lsetxattr(cmount, "/path", "name", NULL, 0, 0)); EXPECT_EQ(-ENOTCONN, ceph_fsetattr(cmount, 0, &st, 0)); + EXPECT_EQ(-ENOTCONN, ceph_fsetattrx(cmount, 0, &stx, 0)); EXPECT_EQ(-ENOTCONN, ceph_chmod(cmount, "/path", 0)); EXPECT_EQ(-ENOTCONN, ceph_fchmod(cmount, 0, 0)); EXPECT_EQ(-ENOTCONN, ceph_chown(cmount, "/path", 0, 0)); @@ -1685,14 +1686,12 @@ TEST(LibCephFS, SetSize) { int fd = ceph_open(cmount, filename, O_RDWR|O_CREAT|O_EXCL, 0666); ASSERT_LT(0, fd); - struct stat st; + struct ceph_statx stx; uint64_t size = 8388608; - st.st_size = (off_t)size; - ASSERT_EQ(ceph_fsetattr(cmount, fd, &st, CEPH_SETATTR_SIZE), 0); - - struct stat stbuf; - ASSERT_EQ(ceph_fstat(cmount, fd, &stbuf), 0); - ASSERT_EQ(stbuf.st_size, (off_t)size); + stx.stx_size = (off_t)size; + ASSERT_EQ(ceph_fsetattrx(cmount, fd, &stx, CEPH_SETATTR_SIZE), 0); + ASSERT_EQ(ceph_fstatx(cmount, fd, &stx, CEPH_STATX_SIZE, 0), 0); + ASSERT_EQ(stx.stx_size, (off_t)size); ceph_close(cmount, fd); ceph_shutdown(cmount);