]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/os/FuseStore.cc
import 15.2.2 octopus source
[ceph.git] / ceph / src / os / FuseStore.cc
index 2fcfb6cac1cbc5478e6a28b00c367c9cc2ad4efe..80b5f9aaa01b04af14086f1dc02f12a03fe30f83 100644 (file)
@@ -9,6 +9,8 @@
 
 #define FUSE_USE_VERSION 30
 #include <fuse.h>
+#include <fuse_lowlevel.h>
+#include "include/ceph_fuse.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -31,7 +33,9 @@
 struct fs_info {
   struct fuse_args args;
   struct fuse *f;
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 0)
   struct fuse_chan *ch;
+#endif
   char *mountpoint;
 };
 
@@ -229,7 +233,11 @@ static int parse_fn(CephContext* cct, const char *path, coll_t *cid,
 }
 
 
-static int os_getattr(const char *path, struct stat *stbuf)
+static int os_getattr(const char *path, struct stat *stbuf
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+                      , struct fuse_file_info *fi
+#endif
+                      )
 {
   fuse_context *fc = fuse_get_context();
   FuseStore *fs = static_cast<FuseStore*>(fc->private_data);
@@ -386,7 +394,11 @@ static int os_readdir(const char *path,
                      void *buf,
                      fuse_fill_dir_t filler,
                      off_t offset,
-                     struct fuse_file_info *fi)
+                     struct fuse_file_info *fi
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+                      , enum fuse_readdir_flags
+#endif
+                      )
 {
   fuse_context *fc = fuse_get_context();
   FuseStore *fs = static_cast<FuseStore*>(fc->private_data);
@@ -411,11 +423,11 @@ static int os_readdir(const char *path,
   switch (t) {
   case FN_ROOT:
     {
-      filler(buf, "type", NULL, 0);
+      filler_compat(filler, buf, "type", NULL, 0);
       vector<coll_t> cls;
       fs->store->list_collections(cls);
       for (auto c : cls) {
-       int r = filler(buf, stringify(c).c_str(), NULL, 0);
+       int r = filler_compat(filler, buf, stringify(c).c_str(), NULL, 0);
        if (r > 0)
          break;
       }
@@ -427,28 +439,28 @@ static int os_readdir(const char *path,
       if (!ch) {
        return -ENOENT;
       }
-      filler(buf, "bitwise_hash_start", NULL, 0);
+      filler_compat(filler, buf, "bitwise_hash_start", NULL, 0);
       if (fs->store->collection_bits(ch) >= 0) {
-       filler(buf, "bitwise_hash_end", NULL, 0);
-       filler(buf, "bitwise_hash_bits", NULL, 0);
+       filler_compat(filler, buf, "bitwise_hash_end", NULL, 0);
+       filler_compat(filler, buf, "bitwise_hash_bits", NULL, 0);
       }
-      filler(buf, "all", NULL, 0);
-      filler(buf, "by_bitwise_hash", NULL, 0);
+      filler_compat(filler, buf, "all", NULL, 0);
+      filler_compat(filler, buf, "by_bitwise_hash", NULL, 0);
       spg_t pgid;
       if (cid.is_pg(&pgid) &&
          fs->store->exists(ch, pgid.make_pgmeta_oid())) {
-       filler(buf, "pgmeta", NULL, 0);
+       filler_compat(filler, buf, "pgmeta", NULL, 0);
       }
     }
     break;
 
   case FN_OBJECT:
     {
-      filler(buf, "bitwise_hash", NULL, 0);
-      filler(buf, "data", NULL, 0);
-      filler(buf, "omap", NULL, 0);
-      filler(buf, "attr", NULL, 0);
-      filler(buf, "omap_header", NULL, 0);
+      filler_compat(filler, buf, "bitwise_hash", NULL, 0);
+      filler_compat(filler, buf, "data", NULL, 0);
+      filler_compat(filler, buf, "omap", NULL, 0);
+      filler_compat(filler, buf, "attr", NULL, 0);
+      filler_compat(filler, buf, "omap_header", NULL, 0);
     }
     break;
 
@@ -503,7 +515,7 @@ static int os_readdir(const char *path,
          uint64_t cur_off = ((uint64_t)bitwise_hash << hash_shift) |
            (uint64_t)hashoff;
          string s = stringify(p);
-         r = filler(buf, s.c_str(), NULL, cur_off);
+         r = filler_compat(filler, buf, s.c_str(), NULL, cur_off);
          if (r)
            break;
        }
@@ -526,7 +538,7 @@ static int os_readdir(const char *path,
          continue;
        }
        ++offset;
-       int r = filler(buf, k.c_str(), NULL, offset);
+       int r = filler_compat(filler, buf, k.c_str(), NULL, offset);
        if (r)
          break;
       }
@@ -544,7 +556,7 @@ static int os_readdir(const char *path,
          continue;
        }
        ++offset;
-       int r = filler(buf, a.first.c_str(), NULL, offset);
+       int r = filler_compat(filler, buf, a.first.c_str(), NULL, offset);
        if (r)
          break;
       }
@@ -781,7 +793,11 @@ static int os_mkdir(const char *path, mode_t mode)
   return 0;
 }
 
-static int os_chmod(const char *path, mode_t mode)
+static int os_chmod(const char *path, mode_t mode
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+                    , struct fuse_file_info *fi
+#endif
+                    )
 {
   fuse_context *fc = fuse_get_context();
   FuseStore *fs = static_cast<FuseStore*>(fc->private_data);
@@ -1052,7 +1068,11 @@ static int os_unlink(const char *path)
   return 0;
 }
 
-static int os_truncate(const char *path, off_t size)
+static int os_truncate(const char *path, off_t size
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+                       , struct fuse_file_info *fi
+#endif
+                       )
 {
   fuse_context *fc = fuse_get_context();
   FuseStore *fs = static_cast<FuseStore*>(fc->private_data);
@@ -1118,7 +1138,9 @@ static int os_statfs(const char *path, struct statvfs *stbuf)
 static struct fuse_operations fs_oper = {
   getattr: os_getattr,
   readlink: 0,
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 0)
   getdir: 0,
+#endif
   mknod: 0,
   mkdir: os_mkdir,
   unlink: os_unlink,
@@ -1129,7 +1151,9 @@ static struct fuse_operations fs_oper = {
   chmod: os_chmod,
   chown: 0,
   truncate: os_truncate,
+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 0)
   utime: 0,
+#endif
   open: os_open,
   read: os_read,
   write: os_write,
@@ -1178,16 +1202,38 @@ int FuseStore::start()
     "-d", // debug
   };
   int c = 3;
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+  int rc;
+  struct fuse_cmdline_opts opts = {};
+#endif
   auto fuse_debug = store->cct->_conf.get_val<bool>("fuse_debug");
   if (fuse_debug)
     ++c;
   fuse_args a = FUSE_ARGS_INIT(c, (char**)v);
   info->args = a;
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+  if (fuse_parse_cmdline(&info->args, &opts) == -1) {
+#else
   if (fuse_parse_cmdline(&info->args, &info->mountpoint, NULL, NULL) == -1) {
+#endif
     derr << __func__ << " failed to parse args" << dendl;
     return -EINVAL;
   }
 
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+  info->mountpoint = opts.mountpoint;
+  info->f = fuse_new(&info->args, &fs_oper, sizeof(fs_oper), (void*)this);
+  if (!info->f) {
+    derr << __func__ << " fuse_new failed" << dendl;
+    return -EIO;
+  }
+
+  rc = fuse_mount(info->f, info->mountpoint);
+  if (rc != 0) {
+    derr << __func__ << " fuse_mount failed" << dendl;
+    return -EIO;
+  }
+#else
   info->ch = fuse_mount(info->mountpoint, &info->args);
   if (!info->ch) {
     derr << __func__ << " fuse_mount failed" << dendl;
@@ -1201,6 +1247,7 @@ int FuseStore::start()
     derr << __func__ << " fuse_new failed" << dendl;
     return -EIO;
   }
+#endif
 
   fuse_thread.create("fusestore");
   dout(10) << __func__ << " done" << dendl;
@@ -1220,7 +1267,11 @@ int FuseStore::loop()
 int FuseStore::stop()
 {
   dout(10) << __func__ << " enter" << dendl;
+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
+  fuse_unmount(info->f);
+#else
   fuse_unmount(info->mountpoint, info->ch);
+#endif
   fuse_thread.join();
   fuse_destroy(info->f);
   dout(10) << __func__ << " exit" << dendl;