]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_fuse: refactor init to make mount_point accessible
authorJohn Spray <john.spray@redhat.com>
Mon, 8 Sep 2014 22:43:20 +0000 (23:43 +0100)
committerJohn Spray <john.spray@redhat.com>
Wed, 17 Sep 2014 12:21:48 +0000 (13:21 +0100)
...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 <john.spray@redhat.com>
src/ceph_fuse.cc
src/client/fuse_ll.cc
src/client/fuse_ll.h

index 54616f60f99d38ca246e7262b303f85ce6bde090..a222bfdca97a524c640114d5c92d3c77b03b1307 100644 (file)
@@ -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;
index 7f419c3232c4a4ecb6fcb54128c03efdaa2e8da6..c97c6df5d4fb80f0387d552e7dd4612127f1a848 100644 (file)
@@ -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<uint64_t,int> snap_stag_map;
   ceph::unordered_map<int,uint64_t> 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 "";
+  }
+}
index cf0fb6a0c57c00040f58e132e1ffc75ca8372edc..85e587baf46b55acac1de0cf5c06995ebc4e8f50 100644 (file)
@@ -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;
 };