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>
<< 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;
}
}
+ 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)