From: Greg Farnum Date: Mon, 11 Jul 2016 23:06:08 +0000 (-0700) Subject: client: always pass UserPerm to unlink functions X-Git-Tag: v11.0.1~36^2~92 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f904c1a972d956b3aa2de08e8862814ee447ed18;p=ceph.git client: always pass UserPerm to unlink functions Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 51888e50530..f29d8a04bc6 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6153,7 +6153,7 @@ int Client::link(const char *relexisting, const char *relpath, const UserPerm& p return r; } -int Client::unlink(const char *relpath) +int Client::unlink(const char *relpath, const UserPerm& perm) { Mutex::Locker lock(client_lock); tout(cct) << "unlink" << std::endl; @@ -6163,15 +6163,15 @@ int Client::unlink(const char *relpath) string name = path.last_dentry(); path.pop_dentry(); InodeRef dir; - int r = path_walk(path, &dir); + int r = path_walk(path, &dir, perm); if (r < 0) return r; if (cct->_conf->client_permissions) { - r = may_delete(dir.get(), name.c_str()); + r = may_delete(dir.get(), name.c_str(), perm); if (r < 0) return r; } - return _unlink(dir.get(), name.c_str()); + return _unlink(dir.get(), name.c_str(), perm); } int Client::rename(const char *relfrom, const char *relto) @@ -10822,9 +10822,11 @@ int Client::ll_symlink(Inode *parent, const char *name, const char *value, return r; } -int Client::_unlink(Inode *dir, const char *name, int uid, int gid) +int Client::_unlink(Inode *dir, const char *name, const UserPerm& perm) { - ldout(cct, 3) << "_unlink(" << dir->ino << " " << name << " uid " << uid << " gid " << gid << ")" << dendl; + ldout(cct, 3) << "_unlink(" << dir->ino << " " << name + << " uid " << perm.uid() << " gid " << perm.gid() + << ")" << dendl; if (dir->snapid != CEPH_NOSNAP) { return -EROFS; @@ -10847,7 +10849,7 @@ int Client::_unlink(Inode *dir, const char *name, int uid, int gid) req->dentry_drop = CEPH_CAP_FILE_SHARED; req->dentry_unless = CEPH_CAP_FILE_EXCL; - res = _lookup(dir, name, 0, &otherin, uid, gid); + res = _lookup(dir, name, 0, &otherin, perm); if (res < 0) goto fail; req->set_other_inode(otherin.get()); @@ -10855,7 +10857,7 @@ int Client::_unlink(Inode *dir, const char *name, int uid, int gid) req->set_inode(dir); - res = make_request(req, uid, gid); + res = make_request(req, perm); trim_cache(); ldout(cct, 3) << "unlink(" << path << ") = " << res << dendl; @@ -10866,7 +10868,7 @@ int Client::_unlink(Inode *dir, const char *name, int uid, int gid) return res; } -int Client::ll_unlink(Inode *in, const char *name, int uid, int gid) +int Client::ll_unlink(Inode *in, const char *name, const UserPerm& perm) { Mutex::Locker lock(client_lock); @@ -10878,11 +10880,11 @@ int Client::ll_unlink(Inode *in, const char *name, int uid, int gid) tout(cct) << name << std::endl; if (!cct->_conf->fuse_default_permissions) { - int r = may_delete(in, name, uid, gid); + int r = may_delete(in, name, perm); if (r < 0) return r; } - return _unlink(in, name, uid, gid); + return _unlink(in, name, perm); } int Client::_rmdir(Inode *dir, const char *name, int uid, int gid) diff --git a/src/client/Client.h b/src/client/Client.h index 127c5748bb8..0c243610b65 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -787,7 +787,7 @@ private: 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 _unlink(Inode *dir, const char *name, const UserPerm& perm); 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); int _rmdir(Inode *dir, const char *name, int uid=-1, int gid=-1); @@ -1026,7 +1026,7 @@ public: void seekdir(dir_result_t *dirp, loff_t offset); int link(const char *existing, const char *newname, const UserPerm& perm); - int unlink(const char *path); + int unlink(const char *path, const UserPerm& perm); int rename(const char *from, const char *to); // dirs @@ -1159,7 +1159,7 @@ public: Inode **out, int uid = -1, int gid = -1); int ll_symlink(Inode *in, const char *name, const char *value, struct stat *attr, Inode **out, int uid = -1, int gid = -1); - int ll_unlink(Inode *in, const char *name, int uid = -1, int gid = -1); + int ll_unlink(Inode *in, const char *name, const UserPerm& perm); int ll_rmdir(Inode *in, const char *name, int uid = -1, int gid = -1); int ll_rename(Inode *parent, const char *name, Inode *newparent, const char *newname, int uid = -1, int gid = -1); diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index d6e396f950f..255870f3025 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1075,7 +1075,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) client->link(a, b, perms); } else if (strcmp(op, "unlink") == 0) { const char *a = t.get_string(buf, p); - client->unlink(a); + client->unlink(a, perms); } else if (strcmp(op, "rename") == 0) { const char *a = t.get_string(buf, p); const char *b = t.get_string(buf2, p); @@ -1311,7 +1311,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) const char *n = t.get_string(buf, p); if (ll_inos.count(i)) { i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP)); - client->ll_unlink(i1, n); + client->ll_unlink(i1, n, perms); client->ll_put(i1); } } else if (strcmp(op, "ll_rmdir") == 0) { @@ -1584,7 +1584,7 @@ int SyntheticClient::clean_dir(string& basedir) clean_dir(file); client->rmdir(file.c_str()); } else { - client->unlink(file.c_str()); + client->unlink(file.c_str(), perms); } } @@ -1842,6 +1842,7 @@ int SyntheticClient::make_files(int num, int count, int priv, bool more) { int whoami = client->get_nodeid().v; char d[255]; + UserPerm perms = client->pick_my_perms(); if (priv) { for (int c=0; clstat(d, &st); int fd = client->open(d, O_RDONLY); - client->unlink(d); + client->unlink(d, perms); client->close(fd); } @@ -1941,6 +1942,7 @@ int SyntheticClient::open_shared(int num, int count) { // files char d[255]; + UserPerm perms = client->pick_my_perms(); for (int c=0; c fds; @@ -1953,7 +1955,7 @@ int SyntheticClient::open_shared(int num, int count) if (false && client->get_nodeid() == 0) for (int n=0; nunlink(d); + client->unlink(d, perms); } while (!fds.empty()) { @@ -2016,7 +2018,8 @@ int SyntheticClient::check_first_primary(int fh) int SyntheticClient::rm_file(string& fn) { - return client->unlink(fn.c_str()); + UserPerm perms = client->pick_my_perms(); + return client->unlink(fn.c_str(), perms); } int SyntheticClient::write_file(string& fn, int size, loff_t wrsize) // size is in MB, wrsize in bytes @@ -2687,7 +2690,7 @@ int SyntheticClient::random_walk(int num_req) if (contents.empty()) op = CEPH_MDS_OP_READDIR; else - r = client->unlink( get_random_sub() ); // will fail on dirs + r = client->unlink(get_random_sub(), perms); // will fail on dirs } if (op == CEPH_MDS_OP_RENAME) { @@ -2888,7 +2891,7 @@ void SyntheticClient::foo() } for (int i=0; i<10; i++) { snprintf(b, sizeof(b), "/b/%d", i); - client->unlink(b); + client->unlink(b, perms); } } return; @@ -2897,7 +2900,7 @@ void SyntheticClient::foo() // bug1.cpp const char *fn = "blah"; char buffer[8192]; - client->unlink(fn); + client->unlink(fn, perms); int handle = client->open(fn,O_CREAT|O_RDWR,S_IRWXU); assert(handle>=0); int r=client->write(handle,buffer,8192); @@ -2993,7 +2996,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->unlink(dst); + client->unlink(dst, perms); } @@ -3010,12 +3013,12 @@ void SyntheticClient::foo() // unlink fun client->mknod("a", 0644); - client->unlink("a"); + client->unlink("a", perms); client->mknod("b", 0644); client->link("b", "c", perms); - client->unlink("c"); + client->unlink("c", perms); client->mkdir("d", 0755); - client->unlink("d"); + client->unlink("d", perms); client->rmdir("d"); // rename fun @@ -3136,11 +3139,11 @@ int SyntheticClient::thrash_links(const char *basedir, int dirs, int files, int break; case 1: client->mknod(src.c_str(), 0755); - client->unlink(dst.c_str()); + client->unlink(dst.c_str(), perms); 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; + case 2: client->unlink(src.c_str(), perms); break; + case 3: client->unlink(dst.c_str(), perms); break; //case 4: client->mknod(src.c_str(), 0755); break; //case 5: client->mknod(dst.c_str(), 0755); break; } diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index 3390f3b4e08..9f1139cb389 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -377,8 +377,9 @@ static void fuse_ll_unlink(fuse_req_t req, fuse_ino_t parent, const char *name) CephFuse::Handle *cfuse = fuse_ll_req_prepare(req); const struct fuse_ctx *ctx = fuse_req_ctx(req); Inode *in = cfuse->iget(parent); + UserPerm perm(ctx->uid, ctx->gid); - int r = cfuse->client->ll_unlink(in, name, ctx->uid, ctx->gid); + int r = cfuse->client->ll_unlink(in, name, perm); fuse_reply_err(req, -r); cfuse->iput(in); // iput required diff --git a/src/libcephfs.cc b/src/libcephfs.cc index abcf303e33b..12a51e8f09f 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -553,7 +553,8 @@ extern "C" int ceph_unlink(struct ceph_mount_info *cmount, const char *path) { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->unlink(path); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->unlink(path, perms); } extern "C" int ceph_rename(struct ceph_mount_info *cmount, const char *from, @@ -1585,7 +1586,8 @@ extern "C" int ceph_ll_unlink(class ceph_mount_info *cmount, Inode *in, const char *name, int uid, int gid) { - return (cmount->get_client()->ll_unlink(in, name, uid, gid)); + UserPerm perms(uid, gid); + return (cmount->get_client()->ll_unlink(in, name, perms)); } extern "C" int ceph_ll_statfs(class ceph_mount_info *cmount,