From: Jan Fajerski Date: Thu, 20 Apr 2017 16:38:43 +0000 (+0200) Subject: fs: normalize file open flags internally used by cephfs X-Git-Tag: v10.2.8~11^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bb79663490468b4ac2832aa9e3cbac019c1f712d;p=ceph.git fs: normalize file open flags internally used by cephfs The file open flags (O_foo) are platform specific. Normalize these flags before they are send to the MDS. For processing of client messages the MDS should only compare to these normalized flags. Otherwise this can lead to bogus flags getting transmitted on ppc64. Signed-off-by: Jan Fajerski (cherry picked from commit 88d2da5e93198e69435e288ce00d216d5fe27f80) Conflicts: src/client/Client.cc Conflicts can be resolved by choosing changes from HEAD and adding a call to ceph_flags_sys2wire where flags are logged. src/mds/Server.cc Conflicts can be resolved by choosing changes from HEAD and while making sure that the MDS compares request O_ flags the the CEPH_O_ flags, since all wire O_ flags are normalized. --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 616a8b2273cc..c22be75debb7 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7543,11 +7543,11 @@ int Client::getdir(const char *relpath, list& contents) int Client::open(const char *relpath, int flags, 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; + ldout(cct, 3) << "open enter(" << relpath << ", " << ceph_flags_sys2wire(flags) << "," << mode << ") = " << dendl; Mutex::Locker lock(client_lock); tout(cct) << "open" << std::endl; tout(cct) << relpath << std::endl; - tout(cct) << flags << std::endl; + tout(cct) << ceph_flags_sys2wire(flags) << std::endl; uid_t uid = get_uid(); gid_t gid = get_gid(); @@ -7619,7 +7619,7 @@ int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit, out: tout(cct) << r << std::endl; - ldout(cct, 3) << "open exit(" << path << ", " << flags << ") = " << r << dendl; + ldout(cct, 3) << "open exit(" << path << ", " << ceph_flags_sys2wire(flags) << ") = " << r << dendl; return r; } @@ -7820,7 +7820,8 @@ void Client::_put_fh(Fh *f) int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid, int gid) { - int cmode = ceph_flags_to_mode(flags); + // use normalized flags to generate cmode + int cmode = ceph_flags_to_mode(ceph_flags_sys2wire(flags)); if (cmode < 0) return -EINVAL; int want = ceph_caps_for_mode(cmode); @@ -7841,8 +7842,8 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid, int gid) MetaRequest *req = new MetaRequest(CEPH_MDS_OP_OPEN); filepath path; in->make_nosnap_relative_path(path); - req->set_filepath(path); - req->head.args.open.flags = flags & ~O_CREAT; + req->set_filepath(path); + req->head.args.open.flags = ceph_flags_sys2wire(flags & ~O_CREAT); req->head.args.open.mode = mode; req->head.args.open.pool = -1; if (cct->_conf->client_debug_getattr_caps) @@ -10540,7 +10541,8 @@ int Client::_create(Inode *dir, const char *name, int flags, mode_t mode, return -EDQUOT; } - int cmode = ceph_flags_to_mode(flags); + // use normalized flags to generate cmode + int cmode = ceph_flags_to_mode(ceph_flags_sys2wire(flags)); if (cmode < 0) return -EINVAL; @@ -10561,7 +10563,7 @@ int Client::_create(Inode *dir, const char *name, int flags, mode_t mode, path.push_dentry(name); req->set_filepath(path); req->set_inode(dir); - req->head.args.open.flags = flags | O_CREAT; + req->head.args.open.flags = ceph_flags_sys2wire(flags | O_CREAT); req->head.args.open.stripe_unit = stripe_unit; req->head.args.open.stripe_count = stripe_count; @@ -11265,10 +11267,10 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid) vinodeno_t vino = _get_vino(in); - ldout(cct, 3) << "ll_open " << vino << " " << flags << dendl; + ldout(cct, 3) << "ll_open " << vino << " " << ceph_flags_sys2wire(flags) << dendl; tout(cct) << "ll_open" << std::endl; tout(cct) << vino.ino.val << std::endl; - tout(cct) << flags << std::endl; + tout(cct) << ceph_flags_sys2wire(flags) << std::endl; int r; if (uid < 0) { @@ -11289,8 +11291,8 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, int uid, int gid) ll_unclosed_fh_set.insert(fhptr); } tout(cct) << (unsigned long)fhptr << std::endl; - ldout(cct, 3) << "ll_open " << vino << " " << flags << " = " << r << " (" << - fhptr << ")" << dendl; + ldout(cct, 3) << "ll_open " << vino << " " << ceph_flags_sys2wire(flags) << + " = " << r << " (" << fhptr << ")" << dendl; return r; } @@ -11303,12 +11305,12 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode, 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 << " " << ceph_flags_sys2wire(flags)<< ", uid " << uid << ", gid " << gid << dendl; tout(cct) << "ll_create" << std::endl; tout(cct) << vparent.ino.val << std::endl; tout(cct) << name << std::endl; tout(cct) << mode << std::endl; - tout(cct) << flags << std::endl; + tout(cct) << ceph_flags_sys2wire(flags) << std::endl; bool created = false; InodeRef in; @@ -11365,7 +11367,7 @@ out: tout(cct) << (unsigned long)fhptr << std::endl; tout(cct) << attr->st_ino << std::endl; ldout(cct, 3) << "ll_create " << parent << " " << name << " 0" << oct << - mode << dec << " " << flags << " = " << r << " (" << fhptr << " " << + mode << dec << " " << ceph_flags_sys2wire(flags) << " = " << r << " (" << fhptr << " " << hex << attr->st_ino << dec << ")" << dendl; // passing an Inode in outp requires an additional ref diff --git a/src/common/ceph_fs.cc b/src/common/ceph_fs.cc index 6b69e267b70f..9338eb6791eb 100644 --- a/src/common/ceph_fs.cc +++ b/src/common/ceph_fs.cc @@ -41,18 +41,18 @@ int ceph_flags_to_mode(int flags) int mode = -1; #ifdef O_DIRECTORY /* fixme */ - if ((flags & O_DIRECTORY) == O_DIRECTORY) + if ((flags & CEPH_O_DIRECTORY) == CEPH_O_DIRECTORY) return CEPH_FILE_MODE_PIN; #endif switch (flags & O_ACCMODE) { - case O_WRONLY: + case CEPH_O_WRONLY: mode = CEPH_FILE_MODE_WR; break; - case O_RDONLY: + case CEPH_O_RDONLY: mode = CEPH_FILE_MODE_RD; break; - case O_RDWR: + case CEPH_O_RDWR: case O_ACCMODE: /* this is what the VFS does */ mode = CEPH_FILE_MODE_RDWR; break; @@ -78,3 +78,33 @@ int ceph_caps_for_mode(int mode) return caps; } + +int ceph_flags_sys2wire(int flags) +{ + int wire_flags = 0; + + switch (flags & O_ACCMODE) { + case O_RDONLY: + wire_flags |= CEPH_O_RDONLY; + break; + case O_WRONLY: + wire_flags |= CEPH_O_WRONLY; + break; + case O_RDWR: + wire_flags |= CEPH_O_RDWR; + break; + } + flags &= ~O_ACCMODE; + +#define ceph_sys2wire(a) if (flags & a) { wire_flags |= CEPH_##a; flags &= ~a; } + + ceph_sys2wire(O_CREAT); + ceph_sys2wire(O_EXCL); + ceph_sys2wire(O_TRUNC); + ceph_sys2wire(O_DIRECTORY); + ceph_sys2wire(O_NOFOLLOW); + +#undef ceph_sys2wire + + return wire_flags; +} diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 3f1128677f13..36229dfe5762 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -379,6 +379,20 @@ extern const char *ceph_mds_op_name(int op); #define CEPH_SETATTR_MTIME_NOW (1 << 7) #define CEPH_SETATTR_ATIME_NOW (1 << 8) +/* + * open request flags + */ +#define CEPH_O_RDONLY 00000000 +#define CEPH_O_WRONLY 00000001 +#define CEPH_O_RDWR 00000002 +#define CEPH_O_CREAT 00000100 +#define CEPH_O_EXCL 00000200 +#define CEPH_O_TRUNC 00001000 +#define CEPH_O_DIRECTORY 00200000 +#define CEPH_O_NOFOLLOW 00400000 + +int ceph_flags_sys2wire(int flags); + /* * Ceph setxattr request flags. */ diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 56e93107214b..f8c6060a0972 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -58,7 +58,6 @@ #include "osd/OSDMap.h" #include -#include #include #include @@ -2886,7 +2885,7 @@ void Server::handle_client_open(MDRequestRef& mdr) int flags = req->head.args.open.flags; int cmode = ceph_flags_to_mode(flags); - bool need_auth = !file_mode_is_readonly(cmode) || (flags & O_TRUNC); + bool need_auth = !file_mode_is_readonly(cmode) || (flags & CEPH_O_TRUNC); dout(7) << "open on " << req->get_filepath() << dendl; @@ -2922,8 +2921,8 @@ void Server::handle_client_open(MDRequestRef& mdr) // can only open non-regular inode with mode FILE_MODE_PIN, at least for now. cmode = CEPH_FILE_MODE_PIN; // the inode is symlink and client wants to follow it, ignore the O_TRUNC flag. - if (cur->inode.is_symlink() && !(flags & O_NOFOLLOW)) - flags &= ~O_TRUNC; + if (cur->inode.is_symlink() && !(flags & CEPH_O_NOFOLLOW)) + flags &= ~CEPH_O_TRUNC; } dout(10) << "open flags = " << flags @@ -2937,13 +2936,13 @@ void Server::handle_client_open(MDRequestRef& mdr) respond_to_request(mdr, -ENXIO); // FIXME what error do we want? return; }*/ - if ((flags & O_DIRECTORY) && !cur->inode.is_dir() && !cur->inode.is_symlink()) { + if ((flags & CEPH_O_DIRECTORY) && !cur->inode.is_dir() && !cur->inode.is_symlink()) { dout(7) << "specified O_DIRECTORY on non-directory " << *cur << dendl; respond_to_request(mdr, -EINVAL); return; } - if ((flags & O_TRUNC) && !cur->inode.is_file()) { + if ((flags & CEPH_O_TRUNC) && !cur->inode.is_file()) { dout(7) << "specified O_TRUNC on !(file|symlink) " << *cur << dendl; // we should return -EISDIR for directory, return -EINVAL for other non-regular respond_to_request(mdr, cur->inode.is_dir() ? -EISDIR : -EINVAL); @@ -2981,7 +2980,7 @@ void Server::handle_client_open(MDRequestRef& mdr) } // O_TRUNC - if ((flags & O_TRUNC) && !mdr->has_completed) { + if ((flags & CEPH_O_TRUNC) && !mdr->has_completed) { assert(cur->is_auth()); xlocks.insert(&cur->filelock); @@ -3121,7 +3120,7 @@ void Server::handle_client_openc(MDRequestRef& mdr) return; } - if (!(req->head.args.open.flags & O_EXCL)) { + if (!(req->head.args.open.flags & CEPH_O_EXCL)) { int r = mdcache->path_traverse(mdr, NULL, NULL, req->get_filepath(), &mdr->dn[0], NULL, MDS_TRAVERSE_FORWARD); if (r > 0) return; @@ -3144,7 +3143,7 @@ void Server::handle_client_openc(MDRequestRef& mdr) // r == -ENOENT } - bool excl = (req->head.args.open.flags & O_EXCL); + bool excl = (req->head.args.open.flags & CEPH_O_EXCL); set rdlocks, wrlocks, xlocks; file_layout_t *dir_layout = NULL; CDentry *dn = rdlock_path_xlock_dentry(mdr, 0, rdlocks, wrlocks, xlocks, @@ -3219,7 +3218,7 @@ void Server::handle_client_openc(MDRequestRef& mdr) if (!dnl->is_null()) { // it existed. - assert(req->head.args.open.flags & O_EXCL); + assert(req->head.args.open.flags & CEPH_O_EXCL); dout(10) << "O_EXCL, target exists, failing with -EEXIST" << dendl; mdr->tracei = dnl->get_inode(); mdr->tracedn = dn;