]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
filestore: check for SNAP_DESTROY ioctl, and file if not present
authorSage Weil <sage@newdream.net>
Thu, 8 Apr 2010 17:36:03 +0000 (10:36 -0700)
committerSage Weil <sage@newdream.net>
Thu, 8 Apr 2010 17:39:47 +0000 (10:39 -0700)
src/os/FileStore.cc
src/os/FileStore.h

index 8e453aa42e63d69a54703e375dc385251c91f569..5323c3846c9fc66b45546ecca82b726e2e26ad9b 100644 (file)
@@ -433,6 +433,36 @@ int FileStore::_detect_fs()
       btrfs_clone_range = false;
       dout(0) << "mount btrfs CLONE_RANGE ioctl is NOT supported: " << strerror_r(-r, buf, sizeof(buf)) << dendl;
     }
+
+    // snap_create and snap_destroy?
+    struct btrfs_ioctl_vol_args volargs;
+    volargs.fd = fd;
+    strcpy(volargs.name, "sync_snap_test");
+    r = ::ioctl(fd, BTRFS_IOC_SNAP_CREATE, &volargs);
+    if (r == 0 || errno == EEXIST) {
+      dout(0) << "mount btrfs SNAP_CREATE is supported" << dendl;
+      btrfs_snap_create = true;
+
+      r = ::ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &volargs);
+      if (r == 0) {
+       dout(0) << "mount btrfs SNAP_DESTROY is supported" << dendl;
+       btrfs_snap_destroy = true;
+      } else {
+       dout(0) << "mount btrfs SNAP_DESTROY failed: " << strerror_r(-r, buf, sizeof(buf)) << dendl;
+      }
+    } else {
+      dout(0) << "mount btrfs SNAP_CREATE failed: " << strerror_r(-r, buf, sizeof(buf)) << dendl;
+    }
+
+    if (g_conf.filestore_btrfs_snap && !btrfs_snap_destroy) {
+      dout(0) << "mount btrfs snaps enabled, but no SNAP_DESTROY ioctl (from kernel 2.6.32+)" << dendl;
+      cerr << TEXT_RED
+          << " ** ERROR: 'filestore btrfs snap' is enabled (for safe transactions, rollback),\n"
+          << "           but btrfs does not support the SNAP_DESTROY ioctl (added in\n"
+          << "           Linux 2.6.32).\n"
+          << TEXT_NORMAL;
+      return -ENOTTY;
+    }
   } else {
     dout(0) << "mount did NOT detect btrfs" << dendl;
     btrfs = false;
@@ -1625,10 +1655,11 @@ void FileStore::sync_entry()
          snaps.pop_front();
          dout(10) << "removing snap '" << snapargs.name << "'" << dendl;
          int r = ::ioctl(basedir_fd, BTRFS_IOC_SNAP_DESTROY, &snapargs);
-         char buf[100];
-         dout(20) << "snap destroyed '" << snapargs.name << "' got " << r
-                 << " " << strerror_r(r < 0 ? errno : 0, buf, sizeof(buf)) << dendl;
-         assert(r == 0);
+         if (r) {
+           char buf[100];
+           dout(20) << "unable to destroy snap '" << snapargs.name << "' got " << r
+                    << " " << strerror_r(r < 0 ? errno : 0, buf, sizeof(buf)) << dendl;
+         }
        }
       }
 
index a615a0d1d712ca9dd4ccf1aa434762b6d844c312..952aee60bce40158a4f107ccfb91bfb968a90bf1 100644 (file)
@@ -46,6 +46,8 @@ class FileStore : public JournalingObjectStore {
   bool btrfs;
   bool btrfs_trans_start_end;
   bool btrfs_clone_range;
+  bool btrfs_snap_create;
+  bool btrfs_snap_destroy;
   int fsid_fd, op_fd;
 
   int basedir_fd, current_fd;
@@ -172,6 +174,8 @@ class FileStore : public JournalingObjectStore {
   FileStore(const char *base, const char *jdev = 0) : 
     basedir(base), journalpath(jdev ? jdev:""),
     btrfs(false), btrfs_trans_start_end(false), btrfs_clone_range(false),
+    btrfs_snap_create(false),
+    btrfs_snap_destroy(false),
     fsid_fd(-1), op_fd(-1),
     attrs(this), fake_attrs(false), 
     collections(this), fake_collections(false),