]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add ll_createx
authorJeff Layton <jlayton@redhat.com>
Mon, 24 Oct 2016 14:02:59 +0000 (10:02 -0400)
committerJeff Layton <jlayton@redhat.com>
Tue, 25 Oct 2016 17:06:28 +0000 (13:06 -0400)
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/recordlock.cc
src/test/libcephfs/test.cc

index 6f4c2b1dd738a8068fe8609146e9a1fcffebcbb8..fe73d033f9f40181fca30405676c7522f177f35c 100644 (file)
@@ -11777,6 +11777,33 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode,
   return r;
 }
 
+int Client::ll_createx(Inode *parent, const char *name, mode_t mode,
+                       int oflags, Inode **outp, Fh **fhp,
+                       struct ceph_statx *stx, unsigned want, unsigned lflags,
+                       const UserPerm& perms)
+{
+  unsigned caps = statx_to_mask(lflags, want);
+  InodeRef in;
+  Mutex::Locker lock(client_lock);
+
+  int r = _ll_create(parent, name, mode, oflags, &in, caps, fhp, perms);
+  if (r >= 0) {
+    assert(in);
+
+    // passing an Inode in outp requires an additional ref
+    if (outp) {
+      _ll_get(in.get());
+      *outp = in.get();
+    }
+    fill_statx(in, caps, stx);
+  } else {
+    stx->stx_ino = 0;
+    stx->stx_mask = 0;
+  }
+
+  return r;
+}
+
 loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence)
 {
   Mutex::Locker lock(client_lock);
index a48f30b290789c5d5cf9bba0f8a1567b40a507b0..c2f4e8cbf863dc80ca2ff851834a1c239dc8db43 100644 (file)
@@ -1156,6 +1156,10 @@ public:
   int ll_create(Inode *parent, const char *name, mode_t mode, int flags,
                struct stat *attr, Inode **out, Fh **fhp,
                const UserPerm& perms);
+  int ll_createx(Inode *parent, const char *name, mode_t mode,
+               int oflags, Inode **outp, Fh **fhp,
+               struct ceph_statx *stx, unsigned want, unsigned lflags,
+               const UserPerm& perms);
   int ll_read_block(Inode *in, uint64_t blockid, char *buf,  uint64_t offset,
                    uint64_t length, file_layout_t* layout);
 
index 8bb8baf6f3d8b67803d41699b3c81e5def646e85..f1b01812b9009812eaafed576b41234b3963ef3d 100644 (file)
@@ -1477,10 +1477,10 @@ int ceph_ll_listxattr(struct ceph_mount_info *cmount, struct Inode *in,
                      const UserPerm *perms);
 int ceph_ll_removexattr(struct ceph_mount_info *cmount, struct Inode *in,
                        const char *name, const UserPerm *perms);
-int ceph_ll_create(struct ceph_mount_info *cmount, struct Inode *parent,
-                  const char *name, mode_t mode, int flags,
-                  struct stat *attr, struct Inode **out, Fh **fhp,
-                  int uid, int gid);
+int ceph_ll_create(struct ceph_mount_info *cmount, Inode *parent,
+                  const char *name, mode_t mode, int oflags, Inode **outp,
+                  Fh **fhp, struct ceph_statx *stx, unsigned want,
+                  unsigned lflags, const UserPerm *perms);
 int ceph_ll_mknod(struct ceph_mount_info *cmount, struct Inode *parent,
                  const char *name, mode_t mode, dev_t rdev,
                  struct stat *attr, struct Inode **out,
index ca5415aae213aecba5fa6c356dce15c23710c04e..4f4e99e7fd9e73a0adbeed972c472e7a68f806d4 100644 (file)
@@ -1538,13 +1538,13 @@ extern "C" int ceph_ll_close(class ceph_mount_info *cmount, Fh* fh)
 }
 
 extern "C" int ceph_ll_create(class ceph_mount_info *cmount,
-                             struct Inode *parent, const char *name,
-                             mode_t mode, int flags, struct stat *attr,
-                             struct Inode **out, Fh **fhp, int uid, int gid)
+                             Inode *parent, const char *name, mode_t mode,
+                             int oflags, Inode **outp, Fh **fhp,
+                             struct ceph_statx *stx, unsigned want,
+                             unsigned lflags, const UserPerm *perms)
 {
-  UserPerm perms(uid, gid);
-  return (cmount->get_client())->ll_create(parent, name, mode, flags,
-                                          attr, out, fhp, perms);
+  return (cmount->get_client())->ll_createx(parent, name, mode, oflags, outp,
+                                           fhp, stx, want, lflags, *perms);
 }
 
 extern "C" int ceph_ll_mknod(class ceph_mount_info *cmount,
index e588ba2bb169f80fada7adfec281361e168b07e3..8ba1cb5bf011d2ccf5dddedaee0f533a9827e584 100644 (file)
@@ -80,7 +80,7 @@ TEST(LibCephFS, BasicRecordLocking) {
   sprintf(c_file, "recordlock_test_%d", getpid());
   Fh *fh = NULL;
   Inode *root = NULL, *inode = NULL;
-  struct stat attr;
+  struct ceph_statx stx;
   int rc;
   struct flock lock1, lock2;
 
@@ -89,8 +89,8 @@ TEST(LibCephFS, BasicRecordLocking) {
   ASSERT_EQ(rc, 0); 
 
   // Get the inode and Fh corresponding to c_file
-  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT, &attr,
-                     &inode, &fh, 0, 0);
+  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT,
+                     &inode, &fh, &stx, 0, 0, ceph_mount_perms(cmount));
   ASSERT_EQ(rc, 0); 
 
   // write lock twice
@@ -282,7 +282,7 @@ static void thread_ConcurrentRecordLocking(str_ConcurrentRecordLocking& s) {
   struct ceph_mount_info *const cmount = s.cmount;
   Fh *fh = NULL;
   Inode *root = NULL, *inode = NULL;
-  struct stat attr;
+  struct ceph_statx stx;
   struct flock lock1;
   int rc;
   struct timespec ts;
@@ -292,8 +292,8 @@ static void thread_ConcurrentRecordLocking(str_ConcurrentRecordLocking& s) {
   ASSERT_EQ(rc, 0); 
 
   // Get the inode and Fh corresponding to c_file
-  rc = ceph_ll_create(cmount, root, s.file, fileMode, O_RDWR | O_CREAT, &attr,
-                     &inode, &fh, 0, 0);
+  rc = ceph_ll_create(cmount, root, s.file, fileMode, O_RDWR | O_CREAT,
+                     &inode, &fh, &stx, 0, 0, ceph_mount_perms(cmount));
   ASSERT_EQ(rc, 0); 
 
   lock1.l_type = F_WRLCK;
@@ -373,7 +373,7 @@ TEST(LibCephFS, ConcurrentRecordLocking) {
   sprintf(c_file, "recordlock_test_%d", mypid);
   Fh *fh = NULL;
   Inode *root = NULL, *inode = NULL;
-  struct stat attr;
+  struct ceph_statx stx;
   struct flock lock1;
   int rc;
 
@@ -382,8 +382,8 @@ TEST(LibCephFS, ConcurrentRecordLocking) {
   ASSERT_EQ(rc, 0); 
 
   // Get the inode and Fh corresponding to c_file
-  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT, &attr,
-                     &inode, &fh, 0, 0);
+  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT,
+                     &inode, &fh, &stx, 0, 0, ceph_mount_perms(cmount));
   ASSERT_EQ(rc, 0); 
 
   // Lock
@@ -515,7 +515,7 @@ TEST(LibCephFS, ThreesomeRecordLocking) {
   sprintf(c_file, "recordlock_test_%d", mypid);
   Fh *fh = NULL;
   Inode *root = NULL, *inode = NULL;
-  struct stat attr;
+  struct ceph_statx stx;
   struct flock lock1;
   int rc;
 
@@ -524,8 +524,8 @@ TEST(LibCephFS, ThreesomeRecordLocking) {
   ASSERT_EQ(rc, 0); 
 
   // Get the inode and Fh corresponding to c_file
-  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT, &attr,
-                     &inode, &fh, 0, 0);
+  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT,
+                     &inode, &fh, &stx, 0, 0, ceph_mount_perms(cmount));
   ASSERT_EQ(rc, 0); 
 
   // Lock
@@ -667,7 +667,7 @@ static void process_ConcurrentRecordLocking(str_ConcurrentRecordLocking& s) {
   struct timespec ts;
   Fh *fh = NULL;
   Inode *root = NULL, *inode = NULL;
-  struct stat attr;
+  struct ceph_statx stx;
   int rc;
   struct flock lock1;
 
@@ -679,8 +679,8 @@ static void process_ConcurrentRecordLocking(str_ConcurrentRecordLocking& s) {
   ASSERT_EQ(rc, 0); 
 
   // Get the inode and Fh corresponding to c_file
-  rc = ceph_ll_create(cmount, root, s.file, fileMode, O_RDWR | O_CREAT, &attr,
-                     &inode, &fh, 0, 0);
+  rc = ceph_ll_create(cmount, root, s.file, fileMode, O_RDWR | O_CREAT,
+                     &inode, &fh, &stx, 0, 0, ceph_mount_perms(cmount));
   ASSERT_EQ(rc, 0); 
 
   WAIT_MAIN(1); // (R1)
@@ -758,7 +758,7 @@ TEST(LibCephFS, DISABLED_InterProcessRecordLocking) {
   sprintf(c_file, "recordlock_test_%d", mypid);
   Fh *fh = NULL;
   Inode *root = NULL, *inode = NULL;
-  struct stat attr;
+  struct ceph_statx stx;
   struct flock lock1;
   int rc;
 
@@ -788,8 +788,8 @@ TEST(LibCephFS, DISABLED_InterProcessRecordLocking) {
   ASSERT_EQ(rc, 0); 
 
   // Get the inode and Fh corresponding to c_file
-  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT, &attr,
-                     &inode, &fh, 0, 0);
+  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT,
+                     &inode, &fh, &stx, 0, 0, ceph_mount_perms(cmount));
   ASSERT_EQ(rc, 0); 
 
   // Lock
@@ -919,7 +919,7 @@ TEST(LibCephFS, DISABLED_ThreesomeInterProcessRecordLocking) {
   sprintf(c_file, "recordlock_test_%d", mypid);
   Fh *fh = NULL;
   Inode *root = NULL, *inode = NULL;
-  struct stat attr;
+  struct ceph_statx stx;
   struct flock lock1;
   int rc;
 
@@ -956,8 +956,8 @@ TEST(LibCephFS, DISABLED_ThreesomeInterProcessRecordLocking) {
   ASSERT_EQ(rc, 0); 
 
   // Get the inode and Fh corresponding to c_file
-  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT, &attr,
-                     &inode, &fh, 0, 0);
+  rc = ceph_ll_create(cmount, root, c_file, fileMode, O_RDWR | O_CREAT,
+                     &inode, &fh, &stx, 0, 0, ceph_mount_perms(cmount));
   ASSERT_EQ(rc, 0); 
 
   // Lock
index 0f37fe7c2e82bb752671024620b7d5f7340da71e..edbccf2073419362bbb958a38478ab4ed4071d0f 100644 (file)
@@ -1403,8 +1403,8 @@ TEST(LibCephFS, Nlink) {
 
   ASSERT_EQ(ceph_ll_mkdir(cmount, root, dirname, 0755, &st, &dir, getuid(), getgid()), 0);
   ASSERT_EQ(ceph_ll_create(cmount, dir, filename, 0666, O_RDWR|O_CREAT|O_EXCL,
-                          &st, &file, &fh, getuid(), getgid()), 0);
-  ASSERT_EQ(st.st_nlink, (nlink_t)1);
+                          &file, &fh, &stx, CEPH_STATX_NLINK, 0, perms), 0);
+  ASSERT_EQ(stx.stx_nlink, (nlink_t)1);
 
   ASSERT_EQ(ceph_ll_link(cmount, file, dir, linkname, &st, getuid(), getgid()), 0);
   ASSERT_EQ(st.st_nlink, (nlink_t)2);
@@ -1412,7 +1412,7 @@ TEST(LibCephFS, Nlink) {
   ASSERT_EQ(ceph_ll_unlink(cmount, dir, linkname, getuid(), getgid()), 0);
   ASSERT_EQ(ceph_ll_lookup(cmount, dir, filename, &file, &stx,
                           CEPH_STATX_NLINK, 0, perms), 0);
-  ASSERT_EQ(st.st_nlink, (nlink_t)1);
+  ASSERT_EQ(stx.stx_nlink, (nlink_t)1);
 
   ceph_shutdown(cmount);
 }
@@ -1565,7 +1565,6 @@ TEST(LibCephFS, LazyStatx) {
   sprintf(filename, "lazystatx%x", getpid());
 
   Inode *root1, *file1, *root2, *file2;
-  struct stat st;
   struct ceph_statx stx;
   Fh *fh;
   UserPerm *perms1 = ceph_mount_perms(cmount1);
@@ -1574,8 +1573,7 @@ TEST(LibCephFS, LazyStatx) {
   ASSERT_EQ(ceph_ll_lookup_root(cmount1, &root1), 0);
   ceph_ll_unlink(cmount1, root1, filename, getuid(), getgid());
   ASSERT_EQ(ceph_ll_create(cmount1, root1, filename, 0666, O_RDWR|O_CREAT|O_EXCL,
-                           &st, &file1, &fh, getuid(), getgid()), 0);
-
+                          &file1, &fh, &stx, 0, 0, perms1), 0);
 
   ASSERT_EQ(ceph_ll_lookup_root(cmount2, &root2), 0);