From: John Spray Date: Mon, 8 Sep 2014 22:43:20 +0000 (+0100) Subject: ceph_fuse: refactor init to make mount_point accessible X-Git-Tag: v0.86~63^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bdda237751c531a902220082a9c6ffd3a042cd88;p=ceph.git ceph_fuse: refactor init to make mount_point accessible ...so that we can read out the mount point between init and start() in order to feed it to Client before it connects to the MDS. Signed-off-by: John Spray --- diff --git a/src/ceph_fuse.cc b/src/ceph_fuse.cc index 54616f60f99d..a222bfdca97a 100644 --- a/src/ceph_fuse.cc +++ b/src/ceph_fuse.cc @@ -134,6 +134,12 @@ int main(int argc, const char **argv, const char *envp[]) { cfuse = new CephFuse(client, fd[1]); + r = cfuse->init(newargc, newargv); + if (r != 0) { + cerr << "ceph-fuse[" << getpid() << "]: fuse failed to initialize" << std::endl; + goto out_messenger_start_failed; + } + cout << "ceph-fuse[" << getpid() << "]: starting ceph client" << std::endl; r = messenger->start(); if (r < 0) { @@ -156,9 +162,9 @@ int main(int argc, const char **argv, const char *envp[]) { goto out_shutdown; } - r = cfuse->init(newargc, newargv); + r = cfuse->start(); if (r != 0) { - cerr << "ceph-fuse[" << getpid() << "]: fuse failed to initialize" << std::endl; + cerr << "ceph-fuse[" << getpid() << "]: fuse failed to start" << std::endl; goto out_client_unmount; } cerr << "ceph-fuse[" << getpid() << "]: starting fuse" << std::endl; diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index 7f419c3232c4..c97c6df5d4fb 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -64,8 +64,10 @@ static dev_t new_decode_dev(uint32_t dev) class CephFuse::Handle { public: Handle(Client *c, int fd); + ~Handle(); int init(int argc, const char *argv[]); + int start(); int loop(); void finalize(); @@ -88,6 +90,7 @@ public: ceph::unordered_map snap_stag_map; ceph::unordered_map stag_snap_map; + struct fuse_args args; }; static void fuse_ll_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) @@ -774,6 +777,12 @@ CephFuse::Handle::Handle(Client *c, int fd) : { snap_stag_map[CEPH_NOSNAP] = 0; stag_snap_map[0] = CEPH_NOSNAP; + memset(&args, 0, sizeof(args)); +} + +CephFuse::Handle::~Handle() +{ + fuse_opt_free_args(&args); } void CephFuse::Handle::finalize() @@ -825,36 +834,41 @@ int CephFuse::Handle::init(int argc, const char *argv[]) for (int argctr = 1; argctr < argc; argctr++) newargv[newargc++] = argv[argctr]; - struct fuse_args args = FUSE_ARGS_INIT(newargc, (char**)newargv); - int ret = 0; + derr << "init, newargv = " << newargv << " newargc=" << newargc << dendl; + struct fuse_args a = FUSE_ARGS_INIT(newargc, (char**)newargv); + args = a; // Roundabout construction b/c FUSE_ARGS_INIT is for initialization not assignment - char *mountpoint; if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) == -1) { derr << "fuse_parse_cmdline failed." << dendl; - ret = EINVAL; - goto done; + fuse_opt_free_args(&args); + free(newargv); + return EINVAL; } + assert(args.allocated); // Checking fuse has realloc'd args so we can free newargv + free(newargv); + return 0; +} + +int CephFuse::Handle::start() +{ ch = fuse_mount(mountpoint, &args); if (!ch) { derr << "fuse_mount(mountpoint=" << mountpoint << ") failed." << dendl; - ret = EIO; - goto done; + return EIO; } se = fuse_lowlevel_new(&args, &fuse_ll_oper, sizeof(fuse_ll_oper), this); if (!se) { derr << "fuse_lowlevel_new failed" << dendl; - ret = EDOM; - goto done; + return EDOM; } signal(SIGTERM, SIG_DFL); signal(SIGINT, SIG_DFL); if (fuse_set_signal_handlers(se) == -1) { derr << "fuse_set_signal_handlers failed" << dendl; - ret = ENOSYS; - goto done; + return ENOSYS; } fuse_session_add_chan(se, ch); @@ -877,10 +891,7 @@ int CephFuse::Handle::init(int argc, const char *argv[]) if (client->cct->_conf->fuse_use_invalidate_cb) client->ll_register_ino_invalidate_cb(ino_invalidate_cb, this); -done: - fuse_opt_free_args(&args); - free(newargv); - return ret; + return 0; } int CephFuse::Handle::loop() @@ -951,6 +962,11 @@ int CephFuse::init(int argc, const char *argv[]) return _handle->init(argc, argv); } +int CephFuse::start() +{ + return _handle->start(); +} + int CephFuse::loop() { return _handle->loop(); @@ -960,3 +976,12 @@ void CephFuse::finalize() { return _handle->finalize(); } + +std::string CephFuse::get_mount_point() const +{ + if (_handle->mountpoint) { + return _handle->mountpoint; + } else { + return ""; + } +} diff --git a/src/client/fuse_ll.h b/src/client/fuse_ll.h index cf0fb6a0c57c..85e587baf46b 100644 --- a/src/client/fuse_ll.h +++ b/src/client/fuse_ll.h @@ -17,9 +17,12 @@ public: CephFuse(Client *c, int fd); ~CephFuse(); int init(int argc, const char *argv[]); + int start(); + int mount(); int loop(); void finalize(); class Handle; + std::string get_mount_point() const; private: CephFuse::Handle *_handle; };