From: Greg Farnum Date: Thu, 28 Jul 2016 18:51:05 +0000 (-0700) Subject: client: switch ll_open and ll_create to be UserPerm-based X-Git-Tag: v11.0.1~36^2~71 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7a5cdaa1e369c23651ed16b81115b74dd4bd5eb5;p=ceph.git client: switch ll_open and ll_create to be UserPerm-based Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 0d457b4ef3a5..faed0da72421 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -11321,7 +11321,7 @@ int Client::ll_fsyncdir(dir_result_t *dirp) return _fsync(dirp->inode.get(), false); } -int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid) +int Client::ll_open(Inode *in, int flags, Fh **fhp, const UserPerm& perms) { assert(!(flags & O_CREAT)); @@ -11335,17 +11335,13 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid) tout(cct) << flags << std::endl; int r; - if (uid < 0) { - uid = get_uid(); - gid = get_gid(); - } if (!cct->_conf->fuse_default_permissions) { - r = may_open(in, flags, uid, gid); + r = may_open(in, flags, perms); if (r < 0) goto out; } - r = _open(in, flags, 0, fhp /* may be NULL */, uid, gid); + r = _open(in, flags, 0, fhp /* may be NULL */, perms); out: Fh *fhptr = fhp ? *fhp : NULL; @@ -11360,14 +11356,15 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid) int Client::ll_create(Inode *parent, const char *name, mode_t mode, int flags, struct stat *attr, Inode **outp, Fh **fhp, - int uid, int gid) + const UserPerm& perms) { Mutex::Locker lock(client_lock); vinodeno_t vparent = _get_vino(parent); ldout(cct, 3) << "ll_create " << vparent << " " << name << " 0" << oct << - mode << dec << " " << flags << ", uid " << uid << ", gid " << gid << dendl; + mode << dec << " " << flags << ", uid " << perms.uid() + << ", gid " << perms.gid() << dendl; tout(cct) << "ll_create" << std::endl; tout(cct) << vparent.ino.val << std::endl; tout(cct) << name << std::endl; @@ -11376,19 +11373,19 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, bool created = false; InodeRef in; - int r = _lookup(parent, name, CEPH_STAT_CAP_INODE_ALL, &in, uid, gid); + int r = _lookup(parent, name, CEPH_STAT_CAP_INODE_ALL, &in, perms); if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL)) return -EEXIST; if (r == -ENOENT && (flags & O_CREAT)) { if (!cct->_conf->fuse_default_permissions) { - r = may_create(parent, uid, gid); + r = may_create(parent, perms); if (r < 0) goto out; } r = _create(parent, name, flags, mode, &in, fhp /* may be NULL */, - 0, 0, 0, NULL, &created, uid, gid); + 0, 0, 0, NULL, &created, perms); if (r < 0) goto out; } @@ -11402,7 +11399,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, ldout(cct, 20) << "ll_create created = " << created << dendl; if (!created) { if (!cct->_conf->fuse_default_permissions) { - r = may_open(in.get(), flags, uid, gid); + r = may_open(in.get(), flags, perms); if (r < 0) { if (fhp && *fhp) { int release_r = _release_fh(*fhp); @@ -11412,7 +11409,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, } } if (fhp && (*fhp == NULL)) { - r = _open(in.get(), flags, mode, fhp, uid, gid); + r = _open(in.get(), flags, mode, fhp, perms); if (r < 0) goto out; } diff --git a/src/client/Client.h b/src/client/Client.h index d10233d18f07..ac45b1bf0c95 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1202,10 +1202,10 @@ public: const char *newname, const UserPerm& perm); int ll_link(Inode *in, Inode *newparent, const char *newname, struct stat *attr, const UserPerm& perm); - int ll_open(Inode *in, int flags, Fh **fh, int uid = -1, int gid = -1); + int ll_open(Inode *in, int flags, Fh **fh, const UserPerm& perms); int ll_create(Inode *parent, const char *name, mode_t mode, int flags, - struct stat *attr, Inode **out, Fh **fhp, int uid = -1, - int gid = -1); + struct stat *attr, Inode **out, Fh **fhp, + const UserPerm& perms); int ll_read_block(Inode *in, uint64_t blockid, char *buf, uint64_t offset, uint64_t length, file_layout_t* layout); diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index e45b4ad20899..d2fa9fc6df31 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1374,7 +1374,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) Fh *fhp; if (ll_inos.count(i)) { i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP)); - if (client->ll_open(i1, f, &fhp) == 0) + if (client->ll_open(i1, f, &fhp, perms) == 0) ll_files[r] = fhp; client->ll_put(i1); } @@ -1389,7 +1389,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only) if (ll_inos.count(i)) { Fh *fhp; i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP)); - if (client->ll_create(i1, n, m, f, &attr, NULL, &fhp) == 0) { + if (client->ll_create(i1, n, m, f, &attr, NULL, &fhp, perms) == 0) { ll_inos[ri] = attr.st_ino; ll_files[r] = fhp; } diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index 42bd14431ce8..89ec8ee77d18 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -477,8 +477,9 @@ static void fuse_ll_open(fuse_req_t req, fuse_ino_t ino, const struct fuse_ctx *ctx = fuse_req_ctx(req); Inode *in = cfuse->iget(ino); Fh *fh = NULL; + UserPerm perms(ctx->uid, ctx->gid); - int r = cfuse->client->ll_open(in, fi->flags, &fh, ctx->uid, ctx->gid); + int r = cfuse->client->ll_open(in, fi->flags, &fh, perms); if (r == 0) { fi->fh = (uint64_t)fh; #if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8) @@ -677,12 +678,13 @@ static void fuse_ll_create(fuse_req_t req, fuse_ino_t parent, const char *name, Inode *i1 = cfuse->iget(parent), *i2; struct fuse_entry_param fe; Fh *fh = NULL; + UserPerm perms(ctx->uid, ctx->gid); memset(&fe, 0, sizeof(fe)); // pass &i2 for the created inode so that ll_create takes an initial ll_ref int r = cfuse->client->ll_create(i1, name, mode, fi->flags, &fe.attr, &i2, - &fh, ctx->uid, ctx->gid); + &fh, perms); if (r == 0) { fi->fh = (uint64_t)fh; fe.ino = cfuse->make_fake_ino(fe.attr.st_ino, fe.attr.st_dev); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 0d1036366897..0ef9337980e7 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -1450,7 +1450,8 @@ extern "C" int ceph_ll_setattr(class ceph_mount_info *cmount, extern "C" int ceph_ll_open(class ceph_mount_info *cmount, Inode *in, int flags, Fh **fh, int uid, int gid) { - return (cmount->get_client()->ll_open(in, flags, fh, uid, gid)); + UserPerm perms(uid, gid); + return (cmount->get_client()->ll_open(in, flags, fh, perms)); } extern "C" int ceph_ll_read(class ceph_mount_info *cmount, Fh* filehandle, @@ -1546,8 +1547,9 @@ extern "C" int ceph_ll_create(class ceph_mount_info *cmount, mode_t mode, int flags, struct stat *attr, struct Inode **out, Fh **fhp, int uid, int gid) { + UserPerm perms(uid, gid); return (cmount->get_client())->ll_create(parent, name, mode, flags, - attr, out, fhp, uid, gid); + attr, out, fhp, perms); } extern "C" int ceph_ll_mknod(class ceph_mount_info *cmount,