From 0bb821056b5945e651ff90adc9e51d3ee97f16f6 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 16 Jul 2015 16:00:55 -0400 Subject: [PATCH] client: pass uid, gid to lookup The MDS cares about who is performing lookup, too! Signed-off-by: Sage Weil --- src/client/Client.cc | 40 ++++++++++++++++++++++------------------ src/client/Client.h | 9 +++++---- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 546066a1a619d..e55b4d6a36691 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -1471,7 +1471,7 @@ int Client::verify_reply_trace(int r, << " got_ino " << got_created_ino << " ino " << created_ino << dendl; - r = _do_lookup(d->dir->parent_inode, d->name, &target); + r = _do_lookup(d->dir->parent_inode, d->name, &target, uid, gid); } else { // if the dentry is not linked, just do our best. see #5021. assert(0 == "how did this happen? i want logs!"); @@ -5299,7 +5299,8 @@ void Client::renew_caps(MetaSession *session) // =============================================================== // high level (POSIXy) interface -int Client::_do_lookup(Inode *dir, const string& name, InodeRef *target) +int Client::_do_lookup(Inode *dir, const string& name, InodeRef *target, + int uid, int gid) { int op = dir->snapid == CEPH_SNAPDIR ? CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP; MetaRequest *req = new MetaRequest(op); @@ -5311,12 +5312,13 @@ int Client::_do_lookup(Inode *dir, const string& name, InodeRef *target) req->head.args.getattr.mask = 0; ldout(cct, 10) << "_do_lookup on " << path << dendl; - int r = make_request(req, 0, 0, target); + int r = make_request(req, uid, gid, target); ldout(cct, 10) << "_do_lookup res is " << r << dendl; return r; } -int Client::_lookup(Inode *dir, const string& dname, InodeRef *target) +int Client::_lookup(Inode *dir, const string& dname, InodeRef *target, + int uid, int gid) { int r = 0; Dentry *dn = NULL; @@ -5397,7 +5399,7 @@ int Client::_lookup(Inode *dir, const string& dname, InodeRef *target) } } - r = _do_lookup(dir, dname, target); + r = _do_lookup(dir, dname, target, uid, gid); goto done; hit_dn: @@ -5448,7 +5450,8 @@ int Client::get_or_create(Inode *dir, const char* name, return 0; } -int Client::path_walk(const filepath& origpath, InodeRef *end, bool followsym) +int Client::path_walk(const filepath& origpath, InodeRef *end, bool followsym, + int uid, int gid) { filepath path = origpath; InodeRef cur; @@ -5468,7 +5471,7 @@ int Client::path_walk(const filepath& origpath, InodeRef *end, bool followsym) ldout(cct, 10) << " " << i << " " << *cur << " " << dname << dendl; ldout(cct, 20) << " (path is " << path << ")" << dendl; InodeRef next; - int r = _lookup(cur.get(), dname, &next); + int r = _lookup(cur.get(), dname, &next, uid, gid); if (r < 0) return r; // only follow trailing symlink if followsym. always follow @@ -5611,7 +5614,7 @@ int Client::mkdir(const char *relpath, mode_t mode) return _mkdir(dir.get(), name.c_str(), mode); } -int Client::mkdirs(const char *relpath, mode_t mode) +int Client::mkdirs(const char *relpath, mode_t mode, int uid, int gid) { Mutex::Locker lock(client_lock); ldout(cct, 10) << "Client::mkdirs " << relpath << dendl; @@ -5626,8 +5629,9 @@ int Client::mkdirs(const char *relpath, mode_t mode) InodeRef cur, next; cur = cwd; for (i=0; ist_ino = 0; goto out; @@ -9866,7 +9870,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, &otherin); + res = _lookup(dir, name, &otherin, uid, gid); if (res < 0) goto fail; req->set_other_inode(otherin.get()); @@ -9924,7 +9928,7 @@ int Client::_rmdir(Inode *dir, const char *name, int uid, int gid) int res = get_or_create(dir, name, &de); if (res < 0) goto fail; - res = _lookup(dir, name, &in); + res = _lookup(dir, name, &in, uid, gid); if (res < 0) goto fail; if (req->get_op() == CEPH_MDS_OP_RMDIR) { @@ -10014,13 +10018,13 @@ int Client::_rename(Inode *fromdir, const char *fromname, Inode *todir, const ch req->dentry_unless = CEPH_CAP_FILE_EXCL; InodeRef oldin, otherin; - res = _lookup(fromdir, fromname, &oldin); + res = _lookup(fromdir, fromname, &oldin, uid, gid); if (res < 0) goto fail; req->set_old_inode(oldin.get()); req->old_inode_drop = CEPH_CAP_LINK_SHARED; - res = _lookup(todir, toname, &otherin); + res = _lookup(todir, toname, &otherin, uid, gid); if (res != 0 && res != -ENOENT) { goto fail; } else if (res == 0) { @@ -10331,7 +10335,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, bool created = false; InodeRef in; - int r = _lookup(parent, name, &in); + int r = _lookup(parent, name, &in, uid, gid); if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL)) return -EEXIST; diff --git a/src/client/Client.h b/src/client/Client.h index d92609ff9f5b9..8b418570e207f 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -455,7 +455,8 @@ protected: // path traversal for high-level interface InodeRef cwd; - int path_walk(const filepath& fp, InodeRef *end, bool followsym=true); + int path_walk(const filepath& fp, InodeRef *end, bool followsym=true, + int uid=-1, int gid=-1); int fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0); int fill_stat(InodeRef& in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0) { return fill_stat(in.get(), st, dirstat, rstat); @@ -683,8 +684,8 @@ private: // internal interface // call these with client_lock held! - int _do_lookup(Inode *dir, const string& name, InodeRef *target); - int _lookup(Inode *dir, const string& dname, InodeRef *target); + int _do_lookup(Inode *dir, const string& name, InodeRef *target, int uid, int gid); + int _lookup(Inode *dir, const string& dname, 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 _unlink(Inode *dir, const char *name, int uid=-1, int gid=-1); @@ -849,7 +850,7 @@ public: // dirs int mkdir(const char *path, mode_t mode); - int mkdirs(const char *path, mode_t mode); + int mkdirs(const char *path, mode_t mode, int uid=-1, int gid=-1); int rmdir(const char *path); // symlinks -- 2.39.5