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: v12.0.3~117^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=88d2da5e93198e69435e288ce00d216d5fe27f80;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 --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 0cd9d66d2843..458467b851ad 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7908,11 +7908,11 @@ 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; + 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; Fh *fh = NULL; @@ -7982,7 +7982,7 @@ int Client::open(const char *relpath, int flags, const UserPerm& perms, 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; } @@ -8198,7 +8198,8 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, return -EROFS; } - 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); @@ -8214,8 +8215,8 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, 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) @@ -11170,7 +11171,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; @@ -11191,7 +11193,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; @@ -11963,10 +11965,10 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, const UserPerm& perms) 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 (!cct->_conf->fuse_default_permissions) { @@ -11983,8 +11985,8 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, const UserPerm& perms) 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; } @@ -11997,13 +11999,13 @@ 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 " << perms.uid() + mode << dec << " " << ceph_flags_sys2wire(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; tout(cct) << mode << std::endl; - tout(cct) << flags << std::endl; + tout(cct) << ceph_flags_sys2wire(flags) << std::endl; bool created = false; int r = _lookup(parent, name, caps, in, perms); @@ -12064,8 +12066,8 @@ out: tout(cct) << (unsigned long)*fhp << std::endl; tout(cct) << ino << std::endl; ldout(cct, 3) << "_ll_create " << parent << " " << name << " 0" << oct << - mode << dec << " " << flags << " = " << r << " (" << *fhp << " " << - hex << ino << dec << ")" << dendl; + mode << dec << " " << ceph_flags_sys2wire(flags) << " = " << r << " (" << + *fhp << " " << hex << ino << dec << ")" << dendl; return r; } @@ -12104,6 +12106,7 @@ int Client::ll_createx(Inode *parent, const char *name, mode_t mode, Mutex::Locker lock(client_lock); InodeRef in; + int r = _ll_create(parent, name, mode, oflags, &in, caps, fhp, perms); if (r >= 0) { assert(in); diff --git a/src/common/ceph_fs.cc b/src/common/ceph_fs.cc index a4f71be943ac..923e38b59d00 100644 --- a/src/common/ceph_fs.cc +++ b/src/common/ceph_fs.cc @@ -17,18 +17,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; @@ -54,3 +54,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 9c2135e56b70..726ee69d62f2 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -384,6 +384,20 @@ extern const char *ceph_mds_op_name(int op); #define CEPH_SETATTR_ATIME_NOW (1 << 8) #define CEPH_SETATTR_KILL_SGUID (1 << 10) +/* + * 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 cd92b4edd605..01e92484bfd8 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -58,7 +58,6 @@ #include "osd/OSDMap.h" #include -#include #include #include @@ -2952,7 +2951,7 @@ void Server::handle_client_open(MDRequestRef& mdr) return; } - bool need_auth = !file_mode_is_readonly(cmode) || (flags & O_TRUNC); + bool need_auth = !file_mode_is_readonly(cmode) || (flags & CEPH_O_TRUNC); if ((cmode & CEPH_FILE_MODE_WR) && mdcache->is_readonly()) { dout(7) << "read-only FS" << dendl; @@ -2977,8 +2976,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 @@ -2992,13 +2991,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); @@ -3036,7 +3035,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); @@ -3174,7 +3173,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; @@ -3197,7 +3196,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, @@ -3271,7 +3270,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;