From: Jeff Layton Date: Mon, 24 Oct 2016 14:02:59 +0000 (-0400) Subject: client: switch arguments on ceph_ll_lookup to use ceph_statx and UserPerm X-Git-Tag: v11.1.0~383^2~23 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=63cf828f6ff70434eec735fb4f505c23473c221d;p=ceph.git client: switch arguments on ceph_ll_lookup to use ceph_statx and UserPerm For now, we leave the old ->ll_lookup method in place, as FUSE needs it. We could do a ceph_statx -> stat conversion, but that's extra copies and I don't think we want the perf hit in FUSE. Signed-off-by: Jeff Layton --- diff --git a/src/client/Client.cc b/src/client/Client.cc index ee18d1caf687..45262c89a9df 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9786,6 +9786,43 @@ int Client::ll_lookup(Inode *parent, const char *name, struct stat *attr, return r; } +int Client::ll_lookupx(Inode *parent, const char *name, Inode **out, + struct ceph_statx *stx, unsigned want, unsigned flags, + const UserPerm& perms) +{ + Mutex::Locker lock(client_lock); + ldout(cct, 3) << "ll_lookupx " << parent << " " << name << dendl; + tout(cct) << "ll_lookupx" << std::endl; + tout(cct) << name << std::endl; + + int r = 0; + if (!cct->_conf->fuse_default_permissions) { + r = may_lookup(parent, perms); + if (r < 0) + return r; + } + + string dname(name); + InodeRef in; + + unsigned mask = statx_to_mask(flags, want); + r = _lookup(parent, dname, mask, &in, perms); + if (r < 0) { + stx->stx_ino = 0; + stx->stx_mask = 0; + } else { + assert(in); + fill_statx(in, mask, stx); + _ll_get(in.get()); + } + + ldout(cct, 3) << "ll_lookupx " << parent << " " << name + << " -> " << r << " (" << hex << stx->stx_ino << dec << ")" << dendl; + tout(cct) << stx->stx_ino << std::endl; + *out = in.get(); + return r; +} + int Client::ll_walk(const char* name, Inode **out, struct stat *attr, const UserPerm& perms) { diff --git a/src/client/Client.h b/src/client/Client.h index 2e2591710361..d4769cc76441 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1114,6 +1114,9 @@ public: Inode *ll_get_inode(vinodeno_t vino); int ll_lookup(Inode *parent, const char *name, struct stat *attr, Inode **out, const UserPerm& perms); + int ll_lookupx(Inode *parent, const char *name, Inode **out, + struct ceph_statx *stx, unsigned want, unsigned flags, + const UserPerm& perms); bool ll_forget(Inode *in, int count); bool ll_put(Inode *in); int ll_getattr(Inode *in, struct stat *st, const UserPerm& perms); diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index 0a48d2680cff..9c44d7a334b0 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -37,6 +37,7 @@ using namespace std; #include "common/errno.h" #include "include/assert.h" +#include "include/cephfs/ceph_statx.h" #define dout_subsys ceph_subsys_client #undef dout_prefix @@ -1023,11 +1024,11 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) const char *p = prefix.c_str(); if (prefix.length()) { client->mkdir(prefix.c_str(), 0755, perms); - struct stat attr; + struct ceph_statx stx; i1 = client->ll_get_inode(vinodeno_t(1, CEPH_NOSNAP)); - if (client->ll_lookup(i1, prefix.c_str(), &attr, &i2, perms) == 0) { - ll_inos[1] = attr.st_ino; - dout(5) << "'root' ino is " << inodeno_t(attr.st_ino) << dendl; + if (client->ll_lookupx(i1, prefix.c_str(), &i2, &stx, CEPH_STATX_INO, 0, perms) == 0) { + ll_inos[1] = stx.stx_ino; + dout(5) << "'root' ino is " << inodeno_t(stx.stx_ino) << dendl; client->ll_put(i1); } else { dout(0) << "warning: play_trace couldn't lookup up my per-client directory" << dendl; @@ -1227,11 +1228,11 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) int64_t i = t.get_int(); const char *name = t.get_string(buf, p); int64_t r = t.get_int(); - struct stat attr; + struct ceph_statx stx; if (ll_inos.count(i)) { i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP)); - if (client->ll_lookup(i1, name, &attr, &i2, perms) == 0) - ll_inos[r] = attr.st_ino; + if (client->ll_lookupx(i1, name, &i2, &stx, CEPH_STATX_INO, 0, perms) == 0) + ll_inos[r] = stx.stx_ino; client->ll_put(i1); } } else if (strcmp(op, "ll_forget") == 0) { diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 14d400337ece..c1b24c8a98d2 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -1425,9 +1425,9 @@ int ceph_ll_lookup_inode( */ int ceph_ll_lookup_root(struct ceph_mount_info *cmount, Inode **parent); -int ceph_ll_lookup(struct ceph_mount_info *cmount, struct Inode *parent, - const char *name, struct stat *attr, - Inode **out, int uid, int gid); +int ceph_ll_lookup(struct ceph_mount_info *cmount, Inode *parent, + const char *name, Inode **out, struct ceph_statx *stx, + unsigned want, unsigned flags, const UserPerm *perms); int ceph_ll_put(struct ceph_mount_info *cmount, struct Inode *in); int ceph_ll_forget(struct ceph_mount_info *cmount, struct Inode *in, int count); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 1f9c92030bbd..ffcdb7ba856b 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -1402,13 +1402,13 @@ extern "C" int ceph_ll_lookup_inode( return 0; } -extern "C" int ceph_ll_lookup(class ceph_mount_info *cmount, - struct Inode *parent, const char *name, - struct stat *attr, Inode **out, - int uid, int gid) +extern "C" int ceph_ll_lookup(struct ceph_mount_info *cmount, + Inode *parent, const char *name, Inode **out, + struct ceph_statx *stx, unsigned want, + unsigned flags, const UserPerm *perms) { - UserPerm perms(uid, gid); - return (cmount->get_client())->ll_lookup(parent, name, attr, out, perms); + return (cmount->get_client())->ll_lookupx(parent, name, out, stx, want, + flags, *perms); } extern "C" int ceph_ll_put(class ceph_mount_info *cmount, Inode *in) diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 96a5607977ff..c2621f08f468 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -568,11 +568,15 @@ TEST(LibCephFS, Xattrs_ll) { Inode *root = NULL; Inode *existent_file_handle = NULL; - struct stat attr; int res = ceph_ll_lookup_root(cmount, &root); ASSERT_EQ(res, 0); - res = ceph_ll_lookup(cmount, root, test_xattr_file, &attr, &existent_file_handle, 0, 0); + + UserPerm *perms = ceph_mount_perms(cmount); + struct ceph_statx stx; + + res = ceph_ll_lookup(cmount, root, test_xattr_file, &existent_file_handle, + &stx, 0, 0, perms); ASSERT_EQ(res, 0); const char *valid_name = "user.attrname"; @@ -1393,7 +1397,9 @@ TEST(LibCephFS, Nlink) { sprintf(linkname, "nlinklink%x", getpid()); struct stat st; + struct ceph_statx stx; Fh *fh; + UserPerm *perms = ceph_mount_perms(cmount); 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, @@ -1404,7 +1410,8 @@ TEST(LibCephFS, Nlink) { ASSERT_EQ(st.st_nlink, (nlink_t)2); ASSERT_EQ(ceph_ll_unlink(cmount, dir, linkname, getuid(), getgid()), 0); - ASSERT_EQ(ceph_ll_lookup(cmount, dir, filename, &st, &file, 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); ceph_shutdown(cmount); @@ -1559,6 +1566,7 @@ TEST(LibCephFS, LazyStatx) { Inode *root1, *file1, *root2, *file2; struct stat st; + struct ceph_statx stx; Fh *fh; ASSERT_EQ(ceph_ll_lookup_root(cmount1, &root1), 0); @@ -1568,9 +1576,11 @@ TEST(LibCephFS, LazyStatx) { ASSERT_EQ(ceph_ll_lookup_root(cmount2, &root2), 0); - ASSERT_EQ(ceph_ll_lookup(cmount2, root2, filename, &st, &file2, getuid(), getgid()), 0); - struct timespec old_ctime = st.st_ctim; + UserPerm *perms = ceph_mount_perms(cmount2); + ASSERT_EQ(ceph_ll_lookup(cmount2, root2, filename, &file2, &stx, CEPH_STATX_CTIME, 0, perms), 0); + + struct timespec old_ctime = stx.stx_ctime; /* * Now sleep, do a chmod on the first client and the see whether we get a @@ -1580,8 +1590,7 @@ TEST(LibCephFS, LazyStatx) { st.st_mode = 0644; ASSERT_EQ(ceph_ll_setattr(cmount1, file1, &st, CEPH_SETATTR_MODE, getuid(), getgid()), 0); - struct ceph_statx stx; - ASSERT_EQ(ceph_ll_getattr(cmount2, file2, &stx, CEPH_STATX_CTIME, AT_NO_ATTR_SYNC, ceph_mount_perms(cmount2)), 0); + ASSERT_EQ(ceph_ll_getattr(cmount2, file2, &stx, CEPH_STATX_CTIME, AT_NO_ATTR_SYNC, perms), 0); ASSERT_TRUE(stx.stx_mask & CEPH_STATX_CTIME); ASSERT_TRUE(stx.stx_ctime.tv_sec == old_ctime.tv_sec && stx.stx_ctime.tv_nsec == old_ctime.tv_nsec);