From 914f6ddebd899667b1937dfe9d5f1a94537dc500 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 10 Dec 2010 16:26:06 -0800 Subject: [PATCH] filestore: detect final version of async ioctl SNAP_CREATE_V2 Li's revised interface for the async snap ioctl is more flexible. Update the ioctl call sites and detection code accordingly. Signed-off-by: Sage Weil --- src/os/FileStore.cc | 37 +++++++++++++++++-------------------- src/os/FileStore.h | 4 ++-- src/os/btrfs_ioctl.h | 14 +++++++++----- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index b078692e10a7b..8cf22e97233f8 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -847,8 +847,9 @@ int FileStore::_detect_fs() vol_args.fd = 0; strcpy(vol_args.name, "async_snap_test"); - struct btrfs_ioctl_async_vol_args async_args; + struct btrfs_ioctl_vol_args_v2 async_args; async_args.fd = fd; + async_args.flags = BTRFS_SUBVOL_CREATE_ASYNC; strcpy(async_args.name, "async_snap_test"); // remove old one, first @@ -860,15 +861,11 @@ int FileStore::_detect_fs() dout(0) << "mount failed to remove old async_snap_test: " << strerror_r(-r, buf, sizeof(buf)) << dendl; } - /* - - do not autodetect this yet until the btrfs ioctl interface is finalized! - - r = ::ioctl(fd, BTRFS_IOC_SNAP_CREATE_ASYNC, &async_args); - dout(0) << "mount btrfs SNAP_CREATE_ASYNC got " << r << " " << strerror_r(-r, buf, sizeof(buf)) << dendl; + r = ::ioctl(fd, BTRFS_IOC_SNAP_CREATE_V2, &async_args); + dout(0) << "mount btrfs SNAP_CREATE_V2 got " << r << " " << strerror_r(-r, buf, sizeof(buf)) << dendl; if (r == 0 || errno == EEXIST) { - dout(0) << "mount btrfs SNAP_CREATE_ASYNC is supported" << dendl; - btrfs_snap_create_async = true; + dout(0) << "mount btrfs SNAP_CREATE_V2 is supported" << dendl; + btrfs_snap_create_v2 = true; // clean up r = ::ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &vol_args); @@ -876,17 +873,16 @@ int FileStore::_detect_fs() dout(0) << "mount btrfs SNAP_DESTROY failed: " << strerror_r(-r, buf, sizeof(buf)) << dendl; } } else { - dout(0) << "mount btrfs SNAP_CREATE_ASYNC is NOT supported: " + dout(0) << "mount btrfs SNAP_CREATE_V2 is NOT supported: " << strerror_r(-r, buf, sizeof(buf)) << dendl; } - */ } - if (g_conf.filestore_btrfs_snap && !btrfs_snap_create_async) { - dout(0) << "mount WARNING: btrfs snaps enabled, but no SNAP_CREATE_ASYNC ioctl (from kernel 2.6.37+)" << dendl; + if (g_conf.filestore_btrfs_snap && !btrfs_snap_create_v2) { + dout(0) << "mount WARNING: btrfs snaps enabled, but no SNAP_CREATE_V2 ioctl (from kernel 2.6.37+)" << dendl; cerr << TEXT_YELLOW << " ** WARNING: 'filestore btrfs snap' is enabled (for safe transactions,\n" - << " rollback), but btrfs does not support the SNAP_CREATE_ASYNC ioctl\n" + << " rollback), but btrfs does not support the SNAP_CREATE_V2 ioctl\n" << " (added in Linux 2.6.37). Expect slow btrfs sync/commit\n" << " performance.\n" << TEXT_NORMAL; @@ -1147,12 +1143,12 @@ int FileStore::mount() } else if (!g_conf.filestore_btrfs_snap) { g_conf.filestore_journal_writeahead = true; dout(0) << "mount: enabling WRITEAHEAD journal mode: 'filestore btrfs snap' mode is not enabled" << dendl; - } else if (!btrfs_snap_create_async) { + } else if (!btrfs_snap_create_v2) { g_conf.filestore_journal_writeahead = true; - dout(0) << "mount: enabling WRITEAHEAD journal mode: btrfs SNAP_CREATE_ASYNC ioctl not detected (v2.6.37+)" << dendl; + dout(0) << "mount: enabling WRITEAHEAD journal mode: btrfs SNAP_CREATE_V2 ioctl not detected (v2.6.37+)" << dendl; } else { g_conf.filestore_journal_parallel = true; - dout(0) << "mount: enabling PARALLEL journal mode: btrfs, SNAP_CREATE_ASYNC detected and 'filestore btrfs snap' mode is enabled" << dendl; + dout(0) << "mount: enabling PARALLEL journal mode: btrfs, SNAP_CREATE_V2 detected and 'filestore btrfs snap' mode is enabled" << dendl; } } else { if (g_conf.filestore_journal_writeahead) @@ -2299,15 +2295,16 @@ void FileStore::sync_entry() if (do_snap) { - if (btrfs_snap_create_async) { + if (btrfs_snap_create_v2) { // be smart! - struct btrfs_ioctl_async_vol_args async_args; + struct btrfs_ioctl_vol_args_v2 async_args; async_args.fd = current_fd; + async_args.flags = BTRFS_SUBVOL_CREATE_ASYNC; snprintf(async_args.name, sizeof(async_args.name), COMMIT_SNAP_ITEM, (long long unsigned)cp); dout(10) << "taking async snap '" << async_args.name << "'" << dendl; - int r = ::ioctl(basedir_fd, BTRFS_IOC_SNAP_CREATE_ASYNC, &async_args); + int r = ::ioctl(basedir_fd, BTRFS_IOC_SNAP_CREATE_V2, &async_args); char buf[100]; dout(20) << "async snap create '" << async_args.name << "' transid " << async_args.transid diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 3c4e2a26d67b7..79d43e908c0e3 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -46,7 +46,7 @@ class FileStore : public JournalingObjectStore { bool btrfs_clone_range; bool btrfs_snap_create; bool btrfs_snap_destroy; - bool btrfs_snap_create_async; + bool btrfs_snap_create_v2; bool btrfs_wait_sync; bool ioctl_fiemap; int fsid_fd, op_fd; @@ -176,7 +176,7 @@ class FileStore : public JournalingObjectStore { btrfs(false), btrfs_trans_start_end(false), btrfs_clone_range(false), btrfs_snap_create(false), btrfs_snap_destroy(false), - btrfs_snap_create_async(false), + btrfs_snap_create_v2(false), btrfs_wait_sync(false), ioctl_fiemap(false), fsid_fd(-1), op_fd(-1), diff --git a/src/os/btrfs_ioctl.h b/src/os/btrfs_ioctl.h index 17c99ebdf9604..c344d12c646bf 100644 --- a/src/os/btrfs_ioctl.h +++ b/src/os/btrfs_ioctl.h @@ -30,11 +30,15 @@ struct btrfs_ioctl_vol_args { char name[BTRFS_PATH_NAME_MAX + 1]; }; -#define BTRFS_SNAPSHOT_NAME_MAX 4079 -struct btrfs_ioctl_async_vol_args { +#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) + +#define BTRFS_SUBVOL_NAME_MAX 4039 +struct btrfs_ioctl_vol_args_v2 { __s64 fd; __u64 transid; - char name[BTRFS_SNAPSHOT_NAME_MAX + 1]; + __u64 flags; + __u64 unused[4]; + char name[BTRFS_SUBVOL_NAME_MAX + 1]; }; #define BTRFS_INO_LOOKUP_PATH_MAX 4080 @@ -187,6 +191,6 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_space_args) #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64) #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) -#define BTRFS_IOC_SNAP_CREATE_ASYNC _IOW(BTRFS_IOCTL_MAGIC, 23, \ - struct btrfs_ioctl_async_vol_args) +#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ + struct btrfs_ioctl_vol_args_v2) #endif -- 2.39.5