From: Greg Farnum Date: Wed, 3 Aug 2016 05:32:56 +0000 (-0700) Subject: client: pass UserPerm to all open() variants X-Git-Tag: v11.0.1~36^2~41 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5c6748d6cfa03e4373bb39ddb8c047fd21ed2c87;p=ceph.git client: pass UserPerm to all open() variants Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 7d0466c57043..597d2ae24a14 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7505,8 +7505,9 @@ int Client::getdir(const char *relpath, list& contents, /****** file i/o **********/ -int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit, - int stripe_count, int object_size, const char *data_pool) +int Client::open(const char *relpath, int flags, const UserPerm& perms, + mode_t mode, int stripe_unit, int stripe_count, + int object_size, const char *data_pool) { ldout(cct, 3) << "open enter(" << relpath << ", " << flags << "," << mode << ") = " << dendl; Mutex::Locker lock(client_lock); @@ -7514,9 +7515,6 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit, tout(cct) << relpath << std::endl; tout(cct) << flags << std::endl; - uid_t uid = get_uid(); - gid_t gid = get_gid(); - Fh *fh = NULL; #if defined(__linux__) && defined(O_PATH) @@ -7532,7 +7530,7 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit, bool created = false; /* O_CREATE with O_EXCL enforces O_NOFOLLOW. */ bool followsym = !((flags & O_NOFOLLOW) || ((flags & O_CREAT) && (flags & O_EXCL))); - int r = path_walk(path, &in, followsym, uid, gid); + int r = path_walk(path, &in, perms, followsym); if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL)) return -EEXIST; @@ -7549,16 +7547,16 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit, string dname = dirpath.last_dentry(); dirpath.pop_dentry(); InodeRef dir; - r = path_walk(dirpath, &dir, true, uid, gid); + r = path_walk(dirpath, &dir, perms, true); if (r < 0) goto out; if (cct->_conf->client_permissions) { - r = may_create(dir.get(), uid, gid); + r = may_create(dir.get(), perms); if (r < 0) goto out; } r = _create(dir.get(), dname.c_str(), flags, mode, &in, &fh, stripe_unit, - stripe_count, object_size, data_pool, &created, uid, gid); + stripe_count, object_size, data_pool, &created, perms); } if (r < 0) goto out; @@ -7566,14 +7564,14 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit, if (!created) { // posix says we can only check permissions of existing files if (cct->_conf->client_permissions) { - r = may_open(in.get(), flags, uid, gid); + r = may_open(in.get(), flags, perms); if (r < 0) goto out; } } if (!fh) - r = _open(in.get(), flags, mode, &fh, uid, gid); + r = _open(in.get(), flags, mode, &fh, perms); if (r >= 0) { // allocate a integer file descriptor assert(fh); @@ -7588,10 +7586,10 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit, return r; } -int Client::open(const char *relpath, int flags, mode_t mode) +int Client::open(const char *relpath, int flags, const UserPerm& perms, mode_t mode) { /* Use default file striping parameters */ - return open(relpath, flags, mode, 0, 0, 0, NULL); + return open(relpath, flags, perms, mode, 0, 0, 0, NULL); } int Client::lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name, diff --git a/src/client/Client.h b/src/client/Client.h index 1f47b620c460..9638fc4cfaa0 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -829,10 +829,6 @@ private: int _removexattr(InodeRef &in, const char *nm, const UserPerm& perms); int _open(Inode *in, int flags, mode_t mode, Fh **fhp, const UserPerm& perms); - int _open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid, int gid) { - UserPerm perms(uid, gid); - return _open(in, flags, mode, fhp, perms); - } int _renew_caps(Inode *in); int _create(Inode *in, const char *name, int flags, mode_t mode, InodeRef *inp, Fh **fhp, int stripe_unit, int stripe_count, int object_size, @@ -1120,8 +1116,10 @@ public: // file ops int mknod(const char *path, mode_t mode, dev_t rdev=0); - int open(const char *path, int flags, mode_t mode=0); - int open(const char *path, int flags, mode_t mode, int stripe_unit, int stripe_count, int object_size, const char *data_pool); + 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, + const char *data_pool); int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name, const UserPerm& perms); int lookup_ino(inodeno_t ino, const UserPerm& perms, Inode **inode=NULL); diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index 837d06737100..2a12fe3bdee5 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -819,7 +819,9 @@ int SyntheticClient::run() int count = iargs.front(); iargs.pop_front(); if (run_me()) { for (int i=0; iopen("test", (rand()%2) ? (O_WRONLY|O_CREAT) : O_RDONLY); + int fd = client->open("test", (rand()%2) ? + (O_WRONLY|O_CREAT) : O_RDONLY, + perms); if (fd > 0) client->close(fd); } } @@ -1153,13 +1155,13 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) int64_t b = t.get_int(); int64_t c = t.get_int(); int64_t d = t.get_int(); - int64_t fd = client->open(a, b, c); + int64_t fd = client->open(a, b, perms, c); if (fd > 0) open_files[d] = fd; } else if (strcmp(op, "oldopen") == 0) { const char *a = t.get_string(buf, p); int64_t b = t.get_int(); int64_t d = t.get_int(); - int64_t fd = client->open(a, b, 0755); + int64_t fd = client->open(a, b, perms, 0755); if (fd > 0) open_files[d] = fd; } else if (strcmp(op, "close") == 0) { int64_t id = t.get_int(); @@ -1701,7 +1703,7 @@ int SyntheticClient::dump_placement(string& fn) { UserPerm perms = client->pick_my_perms(); // open file - int fd = client->open(fn.c_str(), O_RDONLY); + int fd = client->open(fn.c_str(), O_RDONLY, perms); dout(5) << "reading from " << fn << " fd " << fd << dendl; if (fd < 0) return fd; @@ -1879,7 +1881,7 @@ int SyntheticClient::make_files(int num, int count, int priv, bool more) if (more) { client->lstat(d, &st, perms); - int fd = client->open(d, O_RDONLY); + int fd = client->open(d, O_RDONLY, perms); client->unlink(d, perms); client->close(fd); } @@ -1956,7 +1958,7 @@ int SyntheticClient::open_shared(int num, int count) list fds; for (int n=0; nopen(d,O_RDONLY); + int fd = client->open(d, O_RDONLY, perms); if (fd > 0) fds.push_back(fd); } @@ -1979,7 +1981,7 @@ int SyntheticClient::open_shared(int num, int count) // Hits OSD 0 with writes to various files with OSD 0 as the primary. int SyntheticClient::overload_osd_0(int n, int size, int wrsize) { - + UserPerm perms = client->pick_my_perms(); // collect a bunch of files starting on OSD 0 int left = n; int tried = 0; @@ -1990,7 +1992,7 @@ int SyntheticClient::overload_osd_0(int n, int size, int wrsize) { dout(0) << "in OSD overload" << dendl; string filename = get_sarg(tried); dout(1) << "OSD Overload workload: trying file " << filename << dendl; - int fd = client->open(filename.c_str(), O_RDWR|O_CREAT); + int fd = client->open(filename.c_str(), O_RDWR|O_CREAT, perms); ++tried; // only use the file if its first primary is OSD 0 @@ -2036,8 +2038,9 @@ int SyntheticClient::write_file(string& fn, int size, loff_t wrsize) // size i char *buf = new char[wrsize+100]; // 1 MB memset(buf, 7, wrsize); int64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)wrsize; + UserPerm perms = client->pick_my_perms(); - int fd = client->open(fn.c_str(), O_RDWR|O_CREAT); + int fd = client->open(fn.c_str(), O_RDWR|O_CREAT, perms); dout(5) << "writing to " << fn << " fd " << fd << dendl; if (fd < 0) { delete[] buf; @@ -2152,8 +2155,9 @@ int SyntheticClient::read_file(const std::string& fn, int size, char *buf = new char[rdsize]; memset(buf, 1, rdsize); uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize; + UserPerm perms = client->pick_my_perms(); - int fd = client->open(fn.c_str(), O_RDONLY); + int fd = client->open(fn.c_str(), O_RDONLY, perms); dout(5) << "reading from " << fn << " fd " << fd << dendl; if (fd < 0) { delete[] buf; @@ -2423,8 +2427,9 @@ int SyntheticClient::object_rw(int nobj, int osize, int wrpc, int SyntheticClient::read_random(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes { + UserPerm perms = client->pick_my_perms(); uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize; - int fd = client->open(fn.c_str(), O_RDWR); + int fd = client->open(fn.c_str(), O_RDWR, perms); dout(5) << "reading from " << fn << " fd " << fd << dendl; if (fd < 0) return fd; @@ -2552,7 +2557,8 @@ int normdist(int min, int max, int stdev) /* specifies input values */ int SyntheticClient::read_random_ex(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes { uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize; - int fd = client->open(fn.c_str(), O_RDWR); + UserPerm perms = client->pick_my_perms(); + int fd = client->open(fn.c_str(), O_RDWR, perms); dout(5) << "reading from " << fn << " fd " << fd << dendl; if (fd < 0) return fd; @@ -2756,7 +2762,7 @@ int SyntheticClient::random_walk(int num_req) if (contents.empty()) op = CEPH_MDS_OP_READDIR; else { - r = client->open( get_random_sub(), O_RDONLY ); + r = client->open(get_random_sub(), O_RDONLY, perms); if (r > 0) { assert(open_files.count(r) == 0); open_files.insert(r); @@ -2910,14 +2916,14 @@ void SyntheticClient::foo() const char *fn = "blah"; char buffer[8192]; client->unlink(fn, perms); - int handle = client->open(fn,O_CREAT|O_RDWR,S_IRWXU); + int handle = client->open(fn, O_CREAT|O_RDWR, perms, S_IRWXU); assert(handle>=0); int r=client->write(handle,buffer,8192); assert(r>=0); r=client->close(handle); assert(r>=0); - handle = client->open(fn,O_RDWR); // open the same file, it must have some data already + handle = client->open(fn, O_RDWR, perms); // open the same file, it must have some data already assert(handle>=0); r=client->read(handle,buffer,8192); assert(r==8192); // THIS ASSERTION FAILS with disabled cache @@ -2928,13 +2934,13 @@ void SyntheticClient::foo() } if (1) { dout(0) << "first" << dendl; - int fd = client->open("tester", O_WRONLY|O_CREAT); + int fd = client->open("tester", O_WRONLY|O_CREAT, perms); client->write(fd, "hi there", 0, 8); client->close(fd); dout(0) << "sleep" << dendl; sleep(10); dout(0) << "again" << dendl; - fd = client->open("tester", O_WRONLY|O_CREAT); + fd = client->open("tester", O_WRONLY|O_CREAT, perms); client->write(fd, "hi there", 0, 8); client->close(fd); return; @@ -2950,7 +2956,7 @@ void SyntheticClient::foo() char src[80]; snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c); //int fd = - client->open(src, O_RDONLY); + client->open(src, O_RDONLY, perms); } return; @@ -3312,7 +3318,7 @@ void SyntheticClient::import_find(const char *base, const char *find, bool data) if (S_ISDIR(mode)) { client->mkdir(f.c_str(), mode, perms); } else { - int fd = client->open(f.c_str(), O_WRONLY|O_CREAT, mode & 0777); + int fd = client->open(f.c_str(), O_WRONLY|O_CREAT, perms, mode & 0777); assert(fd > 0); if (data) { client->write(fd, "", 0, size); @@ -3353,12 +3359,12 @@ int SyntheticClient::lookup_ino(inodeno_t ino, const UserPerm& perms) int SyntheticClient::chunk_file(string &filename) { - int fd = client->open(filename.c_str(), O_RDONLY); + UserPerm perms = client->pick_my_perms(); + int fd = client->open(filename.c_str(), O_RDONLY, perms); if (fd < 0) return fd; struct stat st; - UserPerm perms = client->pick_my_perms(); int ret = client->fstat(fd, &st, perms); if (ret < 0) { client->close(fd); @@ -3433,7 +3439,7 @@ void SyntheticClient::mksnapfile(const char *dir) string f = dir; f += "/foo"; - int fd = client->open(f.c_str(), O_WRONLY|O_CREAT|O_TRUNC); + int fd = client->open(f.c_str(), O_WRONLY|O_CREAT|O_TRUNC, perms); char buf[1048576*4]; client->write(fd, buf, sizeof(buf), 0); @@ -3444,7 +3450,7 @@ void SyntheticClient::mksnapfile(const char *dir) s += "/.snap/1"; client->mkdir(s.c_str(), 0755, perms); - fd = client->open(f.c_str(), O_WRONLY); + fd = client->open(f.c_str(), O_WRONLY, perms); client->write(fd, buf, 1048576*2, 1048576); client->fsync(fd, true); client->close(fd); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 6d3c0c1f9f1a..c85544ade262 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -819,7 +819,8 @@ extern "C" int ceph_open(struct ceph_mount_info *cmount, const char *path, { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->open(path, flags, mode); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->open(path, flags, perms, mode); } extern "C" int ceph_open_layout(struct ceph_mount_info *cmount, const char *path, int flags, @@ -827,7 +828,8 @@ extern "C" int ceph_open_layout(struct ceph_mount_info *cmount, const char *path { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->open(path, flags, mode, stripe_unit, + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->open(path, flags, perms, mode, stripe_unit, stripe_count, object_size, data_pool); }