]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
filestore: autodetect presense of FIEMAP ioctl
authorSage Weil <sage@newdream.net>
Tue, 9 Nov 2010 22:36:02 +0000 (14:36 -0800)
committerSage Weil <sage@newdream.net>
Tue, 9 Nov 2010 22:36:02 +0000 (14:36 -0800)
If it's not there, assume the whole object is allocated.

Signed-off-by: Sage Weil <sage@newdream.net>
src/os/FileStore.cc
src/os/FileStore.h

index a450b9e255e6ba40b6381f02ed5c6f8a2dd96a2f..b988555356a534bb25fc7bd7860891fb635b4f07 100644 (file)
@@ -39,9 +39,7 @@
 #include <sys/ioctl.h>
 #include <linux/fs.h>
 
-#ifdef HAVE_FIEMAP_H
-#include <linux/fiemap.h>
-#endif
+#include "include/fiemap.h"
 
 #ifndef __CYGWIN__
 # include <sys/xattr.h>
@@ -379,7 +377,6 @@ bool parse_attrname(char **name)
   return false;
 }
 
-#ifdef HAVE_FIEMAP_H
 static int do_fiemap(int fd, off_t start, size_t len, struct fiemap **pfiemap)
 {
   struct fiemap *fiemap = NULL;
@@ -425,12 +422,6 @@ done_err:
   free(fiemap);
   return ret;
 }
-#else
-static int do_fiemap(int fd, off_t start, size_t len, struct fiemap **pfiemap)
-{
-  return -ENOTSUP;
-}
-#endif
 
 int FileStore::statfs(struct statfs *buf)
 {
@@ -767,8 +758,19 @@ int FileStore::_detect_fs()
   if (fd < 0)
     return -errno;
 
+  // fiemap?
+  struct fiemap *fiemap;
+  int r = do_fiemap(fd, 0, 1, &fiemap);
+  if (r == -EOPNOTSUPP) {
+    dout(0) << "mount FIEMAP ioctl is NOT supported" << dendl;
+    ioctl_fiemap = false;
+  } else {
+    dout(0) << "mount FIEMAP ioctl is supported" << dendl;
+    ioctl_fiemap = true;
+  }
+
   struct statfs st;
-  int r = ::fstatfs(fd, &st);
+  r = ::fstatfs(fd, &st);
   if (r < 0)
     return -errno;
 
@@ -1867,11 +1869,19 @@ int FileStore::read(coll_t cid, const sobject_t& oid,
   return r;
 }
 
-#ifdef HAVE_FIEMAP_H
 int FileStore::fiemap(coll_t cid, const sobject_t& oid,
                     uint64_t offset, size_t len,
                     bufferlist& bl)
 {
+
+  if (!ioctl_fiemap) {
+    map<off_t, size_t> m;
+    m[offset] = len;
+    ::encode(m, bl);
+    return 0;
+  }
+
+
   char fn[PATH_MAX];
   struct fiemap *fiemap = NULL;
   map<off_t, size_t> extmap;
@@ -1934,17 +1944,6 @@ done:
   free(fiemap);
   return r;
 }
-#else
-int FileStore::fiemap(coll_t cid, const sobject_t& oid,
-                    uint64_t offset, size_t len,
-                    bufferlist& bl)
-{
-  map<off_t, size_t> m;
-  m[offset] = len;
-  ::encode(m, bl);
-  return 0;
-}
-#endif
 
 
 int FileStore::_remove(coll_t cid, const sobject_t& oid) 
index c7398c444644305ecf763e013e0432476a2c1f19..dbedefe326373b698a839a81065de882db294987 100644 (file)
@@ -50,6 +50,7 @@ class FileStore : public JournalingObjectStore {
   bool btrfs_snap_destroy;
   bool btrfs_snap_create_async;
   bool btrfs_wait_sync;
+  bool ioctl_fiemap;
   int fsid_fd, op_fd;
 
   int basedir_fd, current_fd;
@@ -179,6 +180,7 @@ class FileStore : public JournalingObjectStore {
     btrfs_snap_destroy(false),
     btrfs_snap_create_async(false),
     btrfs_wait_sync(false),
+    ioctl_fiemap(false),
     fsid_fd(-1), op_fd(-1),
     attrs(this), fake_attrs(false), 
     collections(this), fake_collections(false),