]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
filestore: create snap_0 on mkfs
authorSage Weil <sage@newdream.net>
Tue, 6 Mar 2012 17:19:32 +0000 (09:19 -0800)
committerSage Weil <sage@newdream.net>
Tue, 6 Mar 2012 17:19:32 +0000 (09:19 -0800)
If we create a new filestore, apply one transaction, and then crash, we
want to make sure roll back to a consistent reference point--empty.  The
simplest solution is to create that snap_0 during mkfs.  This avoids
strangeness like

2012-02-27 00:42:00.336703 7fb1381ef780 filestore(/ceph/osd.0) mkfs in /ceph/osd.0
2012-02-27 00:42:00.341399 7fb1381ef780 journal _open /ceph/osd.0.journal fd 10: 1048576000 bytes, block size 4096 bytes, directio = 1, aio = 0
2012-02-27 00:42:00.349705 7fb1381ef780 filestore(/ceph/osd.0) mkjournal created journal on /ceph/osd.0.journal
2012-02-27 00:42:00.349728 7fb1381ef780 filestore(/ceph/osd.0) mkfs done in /ceph/osd.0
2012-02-27 00:42:00.349787 7fb1381ef780 filestore(/ceph/osd.0) mount FIEMAP ioctl is NOT supported
2012-02-27 00:42:00.349800 7fb1381ef780 filestore(/ceph/osd.0) mount detected btrfs
2012-02-27 00:42:00.349813 7fb1381ef780 filestore(/ceph/osd.0) mount btrfs CLONE_RANGE ioctl is supported
2012-02-27 00:42:00.357023 7fb1381ef780 filestore(/ceph/osd.0) mount btrfs SNAP_CREATE is supported
2012-02-27 00:42:00.405174 7fb1381ef780 filestore(/ceph/osd.0) mount btrfs SNAP_DESTROY is supported
2012-02-27 00:42:00.405214 7fb1381ef780 filestore(/ceph/osd.0) mount btrfs START_SYNC got (25) Inappropriate ioctl for device
2012-02-27 00:42:00.405228 7fb1381ef780 filestore(/ceph/osd.0) mount btrfs START_SYNC is NOT supported: (25) Inappropriate ioctl for device
2012-02-27 00:42:00.405235 7fb1381ef780 filestore(/ceph/osd.0) mount WARNING: btrfs snaps enabled, but no SNAP_CREATE_V2 ioctl (from kernel 2.6.37+)
2012-02-27 00:42:00.405561 7fb1381ef780 filestore(/ceph/osd.0) mount found snaps <>
2012-02-27 00:42:00.405576 7fb1381ef780 filestore(/ceph/osd.0) mount WARNING: no consistent snaps found, store may be in inconsistent state

and subsequent badness if we fail before a proper commit is made.

Fixes: #2105
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/os/FileStore.cc

index 95593fc4a2d1ae8f01f978ce62ae7c5207520d95..c9f3ec6481cf7d29b63c8b3ddf7b45842040dbe5 100644 (file)
@@ -1025,9 +1025,29 @@ int FileStore::mkfs()
           << cpp_strerror(ret) << dendl;
       goto close_basedir_fd;
     }
+    btrfs_stable_commits = true;
   }
 #endif
 
+  // write initial op_seq
+  {
+    uint64_t initial_seq;
+    int fd = read_op_seq(&initial_seq);
+    if (fd < 0) {
+      derr << "FileStore::mkfs: failed to create " << current_op_seq_fn << ": "
+          << cpp_strerror(fd) << dendl;
+      goto close_basedir_fd;
+    }
+    int err = write_op_seq(fd, 1);
+    if (err < 0) {
+      TEMP_FAILURE_RETRY(::close(fd));  
+      derr << "FileStore::mkfs: failed to write to " << current_op_seq_fn << ": "
+          << cpp_strerror(err) << dendl;
+      goto close_basedir_fd;
+    }
+    TEMP_FAILURE_RETRY(::close(fd));  
+  }
+
   {
     leveldb::Options options;
     options.create_if_missing = true;
@@ -1043,6 +1063,28 @@ int FileStore::mkfs()
     }
   }
 
+  if (btrfs_stable_commits) {
+    // create snap_0 too
+    snprintf(volargs.name, sizeof(volargs.name), COMMIT_SNAP_ITEM, 1ull);
+    volargs.fd = ::open(current_fn.c_str(), O_RDONLY);
+    assert(volargs.fd >= 0);
+    if (::ioctl(basedir_fd, BTRFS_IOC_SNAP_CREATE, (unsigned long int)&volargs)) {
+      ret = -errno;
+      derr << "FileStore::mkfs: failed to create " << volargs.name << ": "
+          << cpp_strerror(ret) << dendl;
+      goto close_basedir_fd;
+    }
+
+    if (::fchmod(volargs.fd, 0755)) {
+      TEMP_FAILURE_RETRY(::close(volargs.fd));
+      ret = -errno;
+      derr << "FileStore::mkfs: failed to chmod " << basedir << "/" << volargs.name << " to 0755: "
+          << cpp_strerror(ret) << dendl;
+      goto close_basedir_fd;
+    }
+    TEMP_FAILURE_RETRY(::close(volargs.fd));
+  }
+
   // journal?
   ret = mkjournal();
   if (ret)