From: Greg Farnum Date: Wed, 3 Aug 2016 20:44:00 +0000 (-0700) Subject: client: pass UserPerm to mkdirs, rmdir, symlink, mknod X-Git-Tag: v11.0.1~36^2~26 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=06d177bccfc41a96253b3f65f7974bf3bd5a2779;p=ceph.git client: pass UserPerm to mkdirs, rmdir, symlink, mknod Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 48a1cbd59179..7cb5794f799e 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6202,7 +6202,7 @@ int Client::mkdir(const char *relpath, mode_t mode, const UserPerm& perm) return _mkdir(dir.get(), name.c_str(), mode, perm); } -int Client::mkdirs(const char *relpath, mode_t mode) +int Client::mkdirs(const char *relpath, mode_t mode, const UserPerm& perms) { Mutex::Locker lock(client_lock); ldout(cct, 10) << "Client::mkdirs " << relpath << dendl; @@ -6210,8 +6210,6 @@ int Client::mkdirs(const char *relpath, mode_t mode) tout(cct) << relpath << std::endl; tout(cct) << mode << std::endl; - UserPerm perms(get_uid(), get_gid()); - //get through existing parts of path filepath path(relpath); unsigned int i; @@ -6253,7 +6251,7 @@ int Client::mkdirs(const char *relpath, mode_t mode) return 0; } -int Client::rmdir(const char *relpath) +int Client::rmdir(const char *relpath, const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "rmdir" << std::endl; @@ -6262,7 +6260,6 @@ int Client::rmdir(const char *relpath) string name = path.last_dentry(); path.pop_dentry(); InodeRef dir; - UserPerm perms(get_uid(), get_gid()); int r = path_walk(path, &dir, perms); if (r < 0) return r; @@ -6274,7 +6271,7 @@ int Client::rmdir(const char *relpath) return _rmdir(dir.get(), name.c_str(), perms); } -int Client::mknod(const char *relpath, mode_t mode, dev_t rdev) +int Client::mknod(const char *relpath, mode_t mode, const UserPerm& perms, dev_t rdev) { Mutex::Locker lock(client_lock); tout(cct) << "mknod" << std::endl; @@ -6285,7 +6282,6 @@ int Client::mknod(const char *relpath, mode_t mode, dev_t rdev) string name = path.last_dentry(); path.pop_dentry(); InodeRef dir; - UserPerm perms(get_uid(), get_gid()); int r = path_walk(path, &dir, perms); if (r < 0) return r; @@ -6299,7 +6295,7 @@ int Client::mknod(const char *relpath, mode_t mode, dev_t rdev) // symlinks -int Client::symlink(const char *target, const char *relpath) +int Client::symlink(const char *target, const char *relpath, const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "symlink" << std::endl; @@ -6310,7 +6306,6 @@ int Client::symlink(const char *target, const char *relpath) string name = path.last_dentry(); path.pop_dentry(); InodeRef dir; - UserPerm perms(get_uid(), get_gid()); int r = path_walk(path, &dir, perms); if (r < 0) return r; diff --git a/src/client/Client.h b/src/client/Client.h index bc60b16c2445..d93ec4a6a9eb 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1047,13 +1047,13 @@ public: // dirs int mkdir(const char *path, mode_t mode, const UserPerm& perm); - int mkdirs(const char *path, mode_t mode); - int rmdir(const char *path); + int mkdirs(const char *path, mode_t mode, const UserPerm& perms); + int rmdir(const char *path, const UserPerm& perms); // symlinks int readlink(const char *path, char *buf, loff_t size, const UserPerm& perms); - int symlink(const char *existing, const char *newname); + int symlink(const char *existing, const char *newname, const UserPerm& perms); // inode stuff int stat(const char *path, struct stat *stbuf, const UserPerm& perms, @@ -1077,7 +1077,7 @@ public: int truncate(const char *path, loff_t size, const UserPerm& perms); // file ops - int mknod(const char *path, mode_t mode, dev_t rdev=0); + int mknod(const char *path, mode_t mode, const UserPerm& perms, dev_t rdev=0); int open(const char *path, int flags, const UserPerm& perms, mode_t mode=0); int open(const char *path, int flags, const UserPerm& perms, mode_t mode, int stripe_unit, int stripe_count, int object_size, diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index 2a12fe3bdee5..77de39596471 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -833,7 +833,7 @@ int SyntheticClient::run() { int count = iargs.front(); iargs.pop_front(); if (run_me()) { - client->mknod("test", 0777); + client->mknod("test", 0777, perms); struct stat st; for (int i=0; ilstat("test", &st, perms); @@ -1090,11 +1090,11 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) client->mkdir(a, b, perms); } else if (strcmp(op, "rmdir") == 0) { const char *a = t.get_string(buf, p); - client->rmdir(a); + client->rmdir(a, perms); } else if (strcmp(op, "symlink") == 0) { const char *a = t.get_string(buf, p); const char *b = t.get_string(buf2, p); - client->symlink(a,b); + client->symlink(a, b, perms); } else if (strcmp(op, "readlink") == 0) { const char *a = t.get_string(buf, p); char buf[100]; @@ -1128,11 +1128,11 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) const char *a = t.get_string(buf, p); int64_t b = t.get_int(); int64_t c = t.get_int(); - client->mknod(a, b, c); + client->mknod(a, b, perms, c); } else if (strcmp(op, "oldmknod") == 0) { const char *a = t.get_string(buf, p); int64_t b = t.get_int(); - client->mknod(a, b, 0); + client->mknod(a, b, perms, 0); } else if (strcmp(op, "getdir") == 0) { const char *a = t.get_string(buf, p); list contents; @@ -1586,7 +1586,7 @@ int SyntheticClient::clean_dir(string& basedir) if ((st.st_mode & S_IFMT) == S_IFDIR) { clean_dir(file); - client->rmdir(file.c_str()); + client->rmdir(file.c_str(), perms); } else { client->unlink(file.c_str(), perms); } @@ -1761,7 +1761,7 @@ int SyntheticClient::make_dirs(const char *basedir, int dirs, int files, int dep dout(3) << "make_dirs " << basedir << " dirs " << dirs << " files " << files << " depth " << depth << dendl; for (int i=0; imknod(d, 0644); + client->mknod(d, 0644, perms); } if (depth == 0) return 0; @@ -1877,7 +1877,7 @@ int SyntheticClient::make_files(int num, int count, int priv, bool more) for (int n=0; nmknod(d, 0644); + client->mknod(d, 0644, perms); if (more) { client->lstat(d, &st, perms); @@ -1912,7 +1912,7 @@ int SyntheticClient::link_test() utime_t start = ceph_clock_now(client->cct); for (int i=0; imknod(d, 0755); + client->mknod(d, 0755, perms); } utime_t end = ceph_clock_now(client->cct); end -= start; @@ -1942,7 +1942,7 @@ int SyntheticClient::create_shared(int num) client->mkdir("test", 0755, perms); for (int n=0; nmknod(d, 0644); + client->mknod(d, 0644, perms); } return 0; @@ -2721,9 +2721,9 @@ int SyntheticClient::random_walk(int num_req) if (op == CEPH_MDS_OP_RMDIR) { if (!subdirs.empty()) - r = client->rmdir( get_random_subdir() ); + r = client->rmdir(get_random_subdir(), perms); else - r = client->rmdir( cwd.c_str() ); // will pbly fail + r = client->rmdir(cwd.c_str(), perms); // will pbly fail } if (op == CEPH_MDS_OP_SYMLINK) { @@ -2755,7 +2755,7 @@ int SyntheticClient::random_walk(int num_req) } if (op == CEPH_MDS_OP_MKNOD) { - r = client->mknod( make_sub("mknod"), 0644); + r = client->mknod(make_sub("mknod"), 0644, perms); } if (op == CEPH_MDS_OP_OPEN) { @@ -2896,7 +2896,7 @@ void SyntheticClient::foo() client->mkdir("/b", 0755, perms); for (int i=0; i<10; i++) { snprintf(a, sizeof(a), "/a/%d", i); - client->mknod(a, 0644); + client->mknod(a, 0644, perms); } while (1) { for (int i=0; i<10; i++) { @@ -3019,28 +3019,28 @@ void SyntheticClient::foo() } // link fun - client->mknod("one", 0755); - client->mknod("two", 0755); + client->mknod("one", 0755, perms); + client->mknod("two", 0755, perms); client->link("one", "three", perms); client->mkdir("dir", 0755, perms); client->link("two", "/dir/twolink", perms); client->link("dir/twolink", "four", perms); // unlink fun - client->mknod("a", 0644); + client->mknod("a", 0644, perms); client->unlink("a", perms); - client->mknod("b", 0644); + client->mknod("b", 0644, perms); client->link("b", "c", perms); client->unlink("c", perms); client->mkdir("d", 0755, perms); client->unlink("d", perms); - client->rmdir("d"); + client->rmdir("d", perms); // rename fun - client->mknod("p1", 0644); - client->mknod("p2", 0644); + client->mknod("p1", 0644, perms); + client->mknod("p2", 0644, perms); client->rename("p1","p2", perms); - client->mknod("p3", 0644); + client->mknod("p3", 0644, perms); client->rename("p3","p4", perms); // check dest dir ambiguity thing @@ -3057,7 +3057,7 @@ void SyntheticClient::foo() client->rename("p4", "p4.l", perms); // check anchor updates - client->mknod("dir1/a", 0644); + client->mknod("dir1/a", 0644, perms); client->link("dir1/a", "da1", perms); client->link("dir1/a", "da2", perms); client->link("da2","da3", perms); @@ -3068,10 +3068,10 @@ void SyntheticClient::foo() // check directory renames client->mkdir("dir3", 0755, perms); - client->mknod("dir3/asdf", 0644); + client->mknod("dir3/asdf", 0644, perms); client->mkdir("dir4", 0755, perms); client->mkdir("dir5", 0755, perms); - client->mknod("dir5/asdf", 0644); + client->mknod("dir5/asdf", 0644, perms); client->rename("dir3", "dir4", perms); // ok client->rename("dir4", "dir5", perms); // fail } @@ -3149,18 +3149,18 @@ int SyntheticClient::thrash_links(const char *basedir, int dirs, int files, int int o = rand() % 4; switch (o) { case 0: - client->mknod(src.c_str(), 0755); + client->mknod(src.c_str(), 0755, perms); if (renames) client->rename(src.c_str(), dst.c_str(), perms); break; case 1: - client->mknod(src.c_str(), 0755); + client->mknod(src.c_str(), 0755, perms); client->unlink(dst.c_str(), perms); client->link(src.c_str(), dst.c_str(), perms); 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; + //case 4: client->mknod(src.c_str(), 0755, perms); break; + //case 5: client->mknod(dst.c_str(), 0755, perms); break; } } return 0; @@ -3307,7 +3307,7 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data) target = filename.substr(pos + 4); } dout(10) << "symlink from '" << link << "' -> '" << target << "'" << dendl; - client->symlink(target.c_str(), link.c_str()); + client->symlink(target.c_str(), link.c_str(), perms); } else { string f; if (base[0] != '-') { diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 89e7dd8ef113..1960f0a93cf0 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -583,14 +583,16 @@ extern "C" int ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mod { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->mkdirs(path, mode); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->mkdirs(path, mode, perms); } extern "C" int ceph_rmdir(struct ceph_mount_info *cmount, const char *path) { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->rmdir(path); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->rmdir(path, perms); } // symlinks @@ -608,7 +610,8 @@ extern "C" int ceph_symlink(struct ceph_mount_info *cmount, const char *existing { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->symlink(existing, newname); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->symlink(existing, newname, perms); } // inode stuff @@ -811,7 +814,8 @@ extern "C" int ceph_mknod(struct ceph_mount_info *cmount, const char *path, { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->mknod(path, mode, rdev); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->mknod(path, mode, perms, rdev); } extern "C" int ceph_open(struct ceph_mount_info *cmount, const char *path,