From: Greg Farnum Date: Wed, 29 Jun 2016 00:36:35 +0000 (-0700) Subject: client: always pass UserPerm to [_]link() X-Git-Tag: v11.0.1~36^2~94 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bc9cac14f9b12d4bdd21c8f0c035ad8f31164ffe;p=ceph.git client: always pass UserPerm to [_]link() Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index e8fdf7f47315..51888e50530c 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6117,7 +6117,7 @@ int Client::path_walk(const filepath& origpath, InodeRef *end, bool followsym, // namespace ops -int Client::link(const char *relexisting, const char *relpath) +int Client::link(const char *relexisting, const char *relpath, const UserPerm& perm) { Mutex::Locker lock(client_lock); tout(cct) << "link" << std::endl; @@ -6130,10 +6130,10 @@ int Client::link(const char *relexisting, const char *relpath) path.pop_dentry(); InodeRef in, dir; - int r = path_walk(existing, &in); + int r = path_walk(existing, &in, perm, true); if (r < 0) goto out; - r = path_walk(path, &dir); + r = path_walk(path, &dir, perm, true); if (r < 0) goto out; if (cct->_conf->client_permissions) { @@ -6141,14 +6141,14 @@ int Client::link(const char *relexisting, const char *relpath) r = -EPERM; goto out; } - r = may_hardlink(in.get()); + r = may_hardlink(in.get(), perm); if (r < 0) goto out; - r = may_create(dir.get()); + r = may_create(dir.get(), perm); if (r < 0) goto out; } - r = _link(in.get(), dir.get(), name.c_str()); + r = _link(in.get(), dir.get(), name.c_str(), perm); out: return r; } @@ -11071,10 +11071,10 @@ int Client::ll_rename(Inode *parent, const char *name, Inode *newparent, return _rename(parent, name, newparent, newname, uid, gid); } -int Client::_link(Inode *in, Inode *dir, const char *newname, int uid, int gid, InodeRef *inp) +int Client::_link(Inode *in, Inode *dir, const char *newname, const UserPerm& perm, InodeRef *inp) { ldout(cct, 3) << "_link(" << in->ino << " to " << dir->ino << " " << newname - << " uid " << uid << " gid " << gid << ")" << dendl; + << " uid " << perm.uid() << " gid " << perm.gid() << ")" << dendl; if (strlen(newname) > NAME_MAX) return -ENAMETOOLONG; @@ -11103,7 +11103,7 @@ int Client::_link(Inode *in, Inode *dir, const char *newname, int uid, int gid, goto fail; req->set_dentry(de); - res = make_request(req, uid, gid, inp); + res = make_request(req, perm.uid(), perm.gid(), inp); ldout(cct, 10) << "link result is " << res << dendl; trim_cache(); @@ -11116,7 +11116,7 @@ int Client::_link(Inode *in, Inode *dir, const char *newname, int uid, int gid, } int Client::ll_link(Inode *in, Inode *newparent, const char *newname, - struct stat *attr, int uid, int gid) + struct stat *attr, const UserPerm& perm) { Mutex::Locker lock(client_lock); @@ -11138,15 +11138,15 @@ int Client::ll_link(Inode *in, Inode *newparent, const char *newname, r = -EPERM; goto out; } - r = may_hardlink(in, uid, gid); + r = may_hardlink(in, perm); if (r < 0) goto out; - r = may_create(newparent, uid, gid); + r = may_create(newparent, perm); if (r < 0) goto out; } - r = _link(in, newparent, newname, uid, gid, &target); + r = _link(in, newparent, newname, perm, &target); if (r == 0) { assert(target); fill_stat(target, attr); diff --git a/src/client/Client.h b/src/client/Client.h index 085e087ba98c..ed407d692a37 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -774,7 +774,8 @@ private: int _do_lookup(Inode *dir, const string& name, int mask, InodeRef *target, int uid, int gid); int _lookup(Inode *dir, const string& dname, int mask, InodeRef *target, int uid, int gid); - int _link(Inode *in, Inode *dir, const char *name, int uid=-1, int gid=-1, InodeRef *inp = 0); + int _link(Inode *in, Inode *dir, const char *name, const UserPerm& perm, + InodeRef *inp = 0); int _unlink(Inode *dir, const char *name, int uid=-1, int gid=-1); int _rename(Inode *olddir, const char *oname, Inode *ndir, const char *nname, int uid=-1, int gid=-1); int _mkdir(Inode *dir, const char *name, mode_t mode, int uid=-1, int gid=-1, InodeRef *inp = 0); @@ -1013,7 +1014,7 @@ public: loff_t telldir(dir_result_t *dirp); void seekdir(dir_result_t *dirp, loff_t offset); - int link(const char *existing, const char *newname); + int link(const char *existing, const char *newname, const UserPerm& perm); int unlink(const char *path); int rename(const char *from, const char *to); @@ -1152,7 +1153,7 @@ public: int ll_rename(Inode *parent, const char *name, Inode *newparent, const char *newname, int uid = -1, int gid = -1); int ll_link(Inode *in, Inode *newparent, const char *newname, - struct stat *attr, int uid = -1, int gid = -1); + struct stat *attr, const UserPerm& perm); int ll_open(Inode *in, int flags, Fh **fh, int uid = -1, int gid = -1); int ll_create(Inode *parent, const char *name, mode_t mode, int flags, struct stat *attr, Inode **out, Fh **fhp, int uid = -1, diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index a17f49e2ccfd..d6e396f950fc 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1072,7 +1072,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) if (strcmp(op, "link") == 0) { const char *a = t.get_string(buf, p); const char *b = t.get_string(buf2, p); - client->link(a,b); + client->link(a, b, perms); } else if (strcmp(op, "unlink") == 0) { const char *a = t.get_string(buf, p); client->unlink(a); @@ -1344,7 +1344,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) ll_inos.count(ni)) { i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP)); i2 = client->ll_get_inode(vinodeno_t(ll_inos[ni],CEPH_NOSNAP)); - client->ll_link(i1, i2, nn, &attr); + client->ll_link(i1, i2, nn, &attr, perms); client->ll_put(i1); client->ll_put(i2); } @@ -1891,6 +1891,8 @@ int SyntheticClient::link_test() char d[255]; char e[255]; + UserPerm perms = client->pick_my_perms(); + // create files int num = 200; @@ -1912,7 +1914,7 @@ int SyntheticClient::link_test() for (int i=0; ilink(d, e); + client->link(d, e, perms); } end = ceph_clock_now(client->cct); end -= start; @@ -2867,6 +2869,8 @@ void SyntheticClient::make_dir_mess(const char *basedir, int n) void SyntheticClient::foo() { + UserPerm perms = client->pick_my_perms(); + if (1) { // make 2 parallel dirs, link/unlink between them. char a[100], b[100]; @@ -2880,7 +2884,7 @@ void SyntheticClient::foo() for (int i=0; i<10; i++) { snprintf(a, sizeof(a), "/a/%d", i); snprintf(b, sizeof(b), "/b/%d", i); - client->link(a, b); + client->link(a, b, perms); } for (int i=0; i<10; i++) { snprintf(b, sizeof(b), "/b/%d", i); @@ -2974,7 +2978,7 @@ void SyntheticClient::foo() char dst[80]; snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c); snprintf(dst, sizeof(dst), "syn.0.0/dir.%d/dir.%d/newlink.%d", d, e, f); - client->link(src, dst); + client->link(src, dst, perms); } srand(0); for (int i=0; i<100; i++) { @@ -2999,16 +3003,16 @@ void SyntheticClient::foo() // link fun client->mknod("one", 0755); client->mknod("two", 0755); - client->link("one", "three"); + client->link("one", "three", perms); client->mkdir("dir", 0755); - client->link("two", "/dir/twolink"); - client->link("dir/twolink", "four"); + client->link("two", "/dir/twolink", perms); + client->link("dir/twolink", "four", perms); // unlink fun client->mknod("a", 0644); client->unlink("a"); client->mknod("b", 0644); - client->link("b", "c"); + client->link("b", "c", perms); client->unlink("c"); client->mkdir("d", 0755); client->unlink("d"); @@ -3029,16 +3033,16 @@ void SyntheticClient::foo() client->rename("dir2/p2","/p2"); // check primary+remote link merging - client->link("p2","p2.l"); - client->link("p4","p4.l"); + client->link("p2","p2.l", perms); + client->link("p4","p4.l", perms); client->rename("p2.l","p2"); client->rename("p4","p4.l"); // check anchor updates client->mknod("dir1/a", 0644); - client->link("dir1/a", "da1"); - client->link("dir1/a", "da2"); - client->link("da2","da3"); + client->link("dir1/a", "da1", perms); + client->link("dir1/a", "da2", perms); + client->link("da2","da3", perms); client->rename("dir1/a","dir2/a"); client->rename("dir2/a","da2"); client->rename("da1","da2"); @@ -3062,6 +3066,8 @@ int SyntheticClient::thrash_links(const char *basedir, int dirs, int files, int if (time_to_stop()) return 0; + UserPerm perms = client->pick_my_perms(); + srand(0); if (1) { bool renames = true; // thrash renames too? @@ -3131,7 +3137,7 @@ int SyntheticClient::thrash_links(const char *basedir, int dirs, int files, int case 1: client->mknod(src.c_str(), 0755); client->unlink(dst.c_str()); - client->link(src.c_str(), dst.c_str()); + client->link(src.c_str(), dst.c_str(), perms); break; case 2: client->unlink(src.c_str()); break; case 3: client->unlink(dst.c_str()); break; @@ -3174,7 +3180,7 @@ int SyntheticClient::thrash_links(const char *basedir, int dirs, int files, int snprintf(f, sizeof(f), "/ln.%d", i); ln += f; - client->link(file.c_str(), ln.c_str()); + client->link(file.c_str(), ln.c_str(), perms); } } return 0; diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index 873ff59877e0..3390f3b4e080 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -446,9 +446,9 @@ static void fuse_ll_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, struct fuse_entry_param fe; memset(&fe, 0, sizeof(fe)); + UserPerm perm(ctx->uid, ctx->gid); - int r = cfuse->client->ll_link(in, nin, newname, &fe.attr, ctx->uid, - ctx->gid); + int r = cfuse->client->ll_link(in, nin, newname, &fe.attr, perm); if (r == 0) { fe.ino = cfuse->make_fake_ino(fe.attr.st_ino, fe.attr.st_dev); fe.attr.st_rdev = new_encode_dev(fe.attr.st_rdev); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index daf9f0381dc2..abcf303e33b9 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -545,7 +545,8 @@ extern "C" int ceph_link (struct ceph_mount_info *cmount, const char *existing, { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->link(existing, newname); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->link(existing, newname, perms); } extern "C" int ceph_unlink(struct ceph_mount_info *cmount, const char *path) @@ -1539,8 +1540,8 @@ extern "C" int ceph_ll_link(class ceph_mount_info *cmount, const char *name, struct stat *attr, int uid, int gid) { - return (cmount->get_client()->ll_link(in, newparent, name, attr, uid, - gid)); + UserPerm perms(uid, gid); + return (cmount->get_client()->ll_link(in, newparent, name, attr, perms)); } extern "C" int ceph_ll_truncate(class ceph_mount_info *cmount,