From bcc068eaa81047fe4ab13e8cd63fa49c9102e2fd Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 26 Oct 2010 16:46:31 -0700 Subject: [PATCH] filestore: read commit_seq before mounting (btrfs ioctls) --- src/os/FileStore.cc | 50 ++++++++++++++++++++++++++++++--------------- src/os/FileStore.h | 1 + 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 6312b3856f1a7..10efa525dfc67 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -878,6 +878,27 @@ int FileStore::_sanity_check_fs() return 0; } + +int FileStore::read_op_seq(const char *fn, uint64_t *seq) +{ + int op_fd = ::open(current_op_seq_fn, O_CREAT|O_RDWR, 0644); + if (op_fd < 0) + return op_fd; + + char s[40]; + int l = ::read(op_fd, s, sizeof(s)); + if (l >= 0) { + s[l] = 0; + *seq = atoll(s); + } else { + char buf[80]; + dout(0) << "error reading " << current_op_seq_fn << ": " + << strerror_r(errno, buf, sizeof(buf)) << dendl; + } + + return op_fd; +} + int FileStore::mount() { char buf[80]; @@ -947,6 +968,14 @@ int FileStore::mount() uint64_t cp = snaps.back(); btrfs_ioctl_vol_args snapargs; + uint64_t curr_seq; + + int curr_fd = read_op_seq(current_op_seq_fn, &curr_seq); + if (curr_fd >= 0) + close(curr_fd); + dout(0) << "*** curr_seq=" << curr_seq << " cp=" << cp << dendl; + + // drop current snapargs.fd = 0; strcpy(snapargs.name, "current"); @@ -978,26 +1007,13 @@ int FileStore::mount() } } + uint64_t initial_op_seq = 0; + current_fd = ::open(current_fn, O_RDONLY); assert(current_fd >= 0); - // init op_seq - op_fd = ::open(current_op_seq_fn, O_CREAT|O_RDWR, 0644); - assert(op_fd >= 0); - - uint64_t initial_op_seq = 0; - { - char s[40]; - int l = ::read(op_fd, s, sizeof(s)); - if (l >= 0) { - s[l] = 0; - initial_op_seq = atoll(s); - } else { - char buf[80]; - dout(0) << "mount error reading " << current_op_seq_fn << ": " - << strerror_r(errno, buf, sizeof(buf)) << dendl; - } - } + op_fd = read_op_seq(current_op_seq_fn, &initial_op_seq); + assert (op_fd >= 0); dout(5) << "mount op_seq is " << initial_op_seq << dendl; // journal diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 040eb48498ac7..714ac5e91927a 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -196,6 +196,7 @@ class FileStore : public JournalingObjectStore { int _sanity_check_fs(); bool test_mount_in_use(); + int read_op_seq(const char *fn, uint64_t *seq); int mount(); int umount(); int wipe_subvol(const char *s); -- 2.39.5