From: Jeff Layton Date: Mon, 24 Oct 2016 14:02:59 +0000 (-0400) Subject: client: add ll_createx X-Git-Tag: v11.1.0~383^2~15 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=af3a8a6a1d5192950f8cb11e784e6a95f5bddce0;p=ceph.git client: add ll_createx Signed-off-by: Jeff Layton --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 6f4c2b1dd738..fe73d033f9f4 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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); diff --git a/src/client/Client.h b/src/client/Client.h index a48f30b29078..c2f4e8cbf863 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -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); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 8bb8baf6f3d8..f1b01812b900 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -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, diff --git a/src/libcephfs.cc b/src/libcephfs.cc index ca5415aae213..4f4e99e7fd9e 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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, diff --git a/src/test/libcephfs/recordlock.cc b/src/test/libcephfs/recordlock.cc index e588ba2bb169..8ba1cb5bf011 100644 --- a/src/test/libcephfs/recordlock.cc +++ b/src/test/libcephfs/recordlock.cc @@ -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 diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 0f37fe7c2e82..edbccf207341 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -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);