]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add a ceph_fsetattrx
authorJeff Layton <jlayton@redhat.com>
Tue, 25 Oct 2016 13:14:20 +0000 (09:14 -0400)
committerJeff Layton <jlayton@redhat.com>
Tue, 25 Oct 2016 17:05:03 +0000 (13:05 -0400)
...and convert ceph_fsetattr callers to use it instead.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h
src/libcephfs.cc
src/test/libcephfs/test.cc

index a3194f23a8850800ab464cc3ae1855e4ad269eaf..ee18d1caf687c192a203d02678447904903623f4 100644 (file)
@@ -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)
 {
index d544e927558f25218dd75742d412473aecba7199..2e2591710361fcce9120636b6b6c78a37306c390 100644 (file)
@@ -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);
index 09e9801ea35bd61abf8f31354587be012353be98..ca8de2066bebd3b49f0dc47634058abb661d9674 100644 (file)
@@ -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.
index 40a7b50bda1dc4dfead48647898e83fbda7ebefa..bf3d414063b9860c3c83f7c400726cf2700f1f29 100644 (file)
@@ -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)
 {
index 3fe62a790353c3051427a0d10331c3f8ee02c7b9..919683f5724e00a76bd9cececd8779fd9bb69321 100644 (file)
@@ -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);