From bb451d202b8bdb7e220e8acb953a44fd4818803e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 Apr 2010 10:34:50 -0700 Subject: [PATCH] filestore: use SNAP_DESTROY_ASYNC ioctl if available --- src/os/FileStore.cc | 18 ++++++++++++++---- src/os/FileStore.h | 2 ++ src/os/btrfs_ioctl.h | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 8ece0697d56e8..901d2a298e631 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -558,9 +558,17 @@ int FileStore::_detect_fs() // clean up volargs.fd = 0; - r = ::ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &volargs); - if (r != 0) { - dout(0) << "mount btrfs SNAP_DESTROY failed: " << strerror_r(-r, buf, sizeof(buf)) << dendl; + r = ::ioctl(fd, BTRFS_IOC_SNAP_DESTROY_ASYNC, &volargs); + if (r == 0) { + dout(0) << "mount btrfs SNAP_DESTROY_ASYNC is supported" << dendl; + btrfs_snap_destroy_async = true; + } else { + dout(0) << "mount btrfs SNAP_DESTROY_ASYNC is NOT supported: " + << strerror_r(-r, buf, sizeof(buf)) << dendl; + r = ::ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &volargs); + if (r != 0) { + 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: " @@ -690,7 +698,9 @@ int FileStore::mount() // drop current snapargs.fd = 0; strcpy(snapargs.name, "current"); - int r = ::ioctl(basedir_fd, BTRFS_IOC_SNAP_DESTROY, &snapargs); + int r = ::ioctl(basedir_fd, + btrfs_snap_destroy_async ? BTRFS_IOC_SNAP_DESTROY_ASYNC:BTRFS_IOC_SNAP_DESTROY, + &snapargs); if (r) { char buf[80]; dout(0) << "error removing old current subvol: " << strerror_r(errno, buf, sizeof(buf)) << dendl; diff --git a/src/os/FileStore.h b/src/os/FileStore.h index dc26e15a34ba3..a8ddcbf78182c 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -49,6 +49,7 @@ class FileStore : public JournalingObjectStore { bool btrfs_snap_create; bool btrfs_snap_destroy; bool btrfs_snap_create_async; + bool btrfs_snap_destroy_async; bool btrfs_wait_sync; int fsid_fd, op_fd; @@ -178,6 +179,7 @@ class FileStore : public JournalingObjectStore { btrfs_snap_create(false), btrfs_snap_destroy(false), btrfs_snap_create_async(false), + btrfs_snap_destroy_async(false), btrfs_wait_sync(false), fsid_fd(-1), op_fd(-1), attrs(this), fake_attrs(false), diff --git a/src/os/btrfs_ioctl.h b/src/os/btrfs_ioctl.h index 21ff3c1d35377..0c33ab730d65b 100644 --- a/src/os/btrfs_ioctl.h +++ b/src/os/btrfs_ioctl.h @@ -184,4 +184,6 @@ struct btrfs_ioctl_space_args { #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_vol_args) +#define BTRFS_IOC_SNAP_DESTROY_ASYNC _IOW(BTRFS_IOCTL_MAGIC, 24, \ + struct btrfs_ioctl_vol_args) #endif -- 2.39.5