* [PATCH] btrfs: Add qgroup_auto_cleanup mount flag to automatically cleanup qgroups
@ 2017-06-28 21:51 Sargun Dhillon
2017-07-01 2:45 ` kbuild test robot
0 siblings, 1 reply; 2+ messages in thread
From: Sargun Dhillon @ 2017-06-28 21:51 UTC (permalink / raw)
To: linux-btrfs
This patch introduces a new mount option - qgroup_auto_cleanup.
The purpose of this mount option is to cause btrfs to automatically
delete qgroups on subvolume deletion. This only cleans up the
associated level-0 qgroup, and not qgroups that are above it.
Since this behaviour is API-changing it is opt-in. Existing software,
and scripts may be doing qgroup cleanup on subvolume deletion explicitly,
and the absence of a qgroup may cause failure.
Signed-off-by: Sargun Dhillon <sargun@sargun.me>
---
fs/btrfs/ctree.h | 1 +
fs/btrfs/ioctl.c | 15 +++++++++++++++
fs/btrfs/super.c | 15 ++++++++++++++-
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 5bdd3666..b3d54e4 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1336,6 +1336,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
#define BTRFS_MOUNT_FRAGMENT_METADATA (1 << 25)
#define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)
#define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)
+#define BTRFS_MOUNT_QGROUP_AUTO_CLEANUP (1 << 28)
#define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
#define BTRFS_DEFAULT_MAX_INLINE (2048)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index fa1b78c..e9901c4 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2546,6 +2546,21 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
goto out_end_trans;
}
}
+ /*
+ * Attempt to automatically remove the automatically attached qgroup
+ * setup in btrfs_qgroup_inherit. As a matter of convention, the id
+ * is the same as the subvolume id.
+ *
+ * This can fail non-fatally for level 0 qgroups, therefore we do
+ * not abort the transaction if this fails, nor return an error.
+ */
+ if (btrfs_test_opt(fs_info, QGROUP_AUTO_CLEANUP)) {
+ ret = btrfs_remove_qgroup(trans, fs_info,
+ dest->root_key.objectid, 0);
+ if (ret && ret != -ENOENT)
+ btrfs_warn(fs_info,
+ "Failed to cleanup qgroup. err: %d", ret);
+ }
out_end_trans:
trans->block_rsv = NULL;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 74e4779..d83c841 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -321,7 +321,8 @@ enum {
Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
Opt_datasum, Opt_treelog, Opt_noinode_cache, Opt_usebackuproot,
- Opt_nologreplay, Opt_norecovery,
+ Opt_nologreplay, Opt_norecovery, Opt_qgroup_auto_cleanup,
+ Opt_no_qgroup_auto_cleanup,
#ifdef CONFIG_BTRFS_DEBUG
Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all,
#endif
@@ -381,6 +382,8 @@ static const match_table_t tokens = {
{Opt_rescan_uuid_tree, "rescan_uuid_tree"},
{Opt_fatal_errors, "fatal_errors=%s"},
{Opt_commit_interval, "commit=%d"},
+ {Opt_qgroup_auto_cleanup, "qgroup_auto_cleanup"},
+ {Opt_no_qgroup_auto_cleanup, "no_qgroup_auto_cleanup"},
#ifdef CONFIG_BTRFS_DEBUG
{Opt_fragment_data, "fragment=data"},
{Opt_fragment_metadata, "fragment=metadata"},
@@ -798,6 +801,14 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
}
break;
+ case Opt_qgroup_auto_cleanup:
+ btrfs_set_and_info(info, QGROUP_AUTO_CLEANUP,
+ "enabling qgroup auto cleanup");
+ break;
+ case Opt_no_qgroup_auto_cleanup:
+ btrfs_clear_and_info(info, QGROUP_AUTO_CLEANUP,
+ "disabling qgroup auto cleanup");
+ break;
#ifdef CONFIG_BTRFS_DEBUG
case Opt_fragment_all:
btrfs_info(info, "fragmenting all space");
@@ -1287,6 +1298,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
seq_puts(seq, ",fatal_errors=panic");
if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL)
seq_printf(seq, ",commit=%d", info->commit_interval);
+ if (btrfs_test_opt(info, QGROUP_AUTO_CLEANUP))
+ seq_puts(seq, ",qgroup_auto_cleanup");
#ifdef CONFIG_BTRFS_DEBUG
if (btrfs_test_opt(info, FRAGMENT_DATA))
seq_puts(seq, ",fragment=data");
--
2.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: Add qgroup_auto_cleanup mount flag to automatically cleanup qgroups
2017-06-28 21:51 [PATCH] btrfs: Add qgroup_auto_cleanup mount flag to automatically cleanup qgroups Sargun Dhillon
@ 2017-07-01 2:45 ` kbuild test robot
0 siblings, 0 replies; 2+ messages in thread
From: kbuild test robot @ 2017-07-01 2:45 UTC (permalink / raw)
To: Sargun Dhillon; +Cc: kbuild-all, linux-btrfs
[-- Attachment #1: Type: text/plain, Size: 1680 bytes --]
Hi Sargun,
[auto build test ERROR on v4.12-rc7]
[also build test ERROR on next-20170630]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Sargun-Dhillon/btrfs-Add-qgroup_auto_cleanup-mount-flag-to-automatically-cleanup-qgroups/20170701-102114
config: x86_64-randconfig-x015-201726 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64
All errors (new ones prefixed by >>):
fs//btrfs/ioctl.c: In function 'btrfs_ioctl_snap_destroy':
>> fs//btrfs/ioctl.c:2555:9: error: too many arguments to function 'btrfs_remove_qgroup'
ret = btrfs_remove_qgroup(trans, fs_info,
^~~~~~~~~~~~~~~~~~~
In file included from fs//btrfs/ioctl.c:60:0:
fs//btrfs/qgroup.h:129:5: note: declared here
int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
^~~~~~~~~~~~~~~~~~~
vim +/btrfs_remove_qgroup +2555 fs//btrfs/ioctl.c
2549 * is the same as the subvolume id.
2550 *
2551 * This can fail non-fatally for level 0 qgroups, therefore we do
2552 * not abort the transaction if this fails, nor return an error.
2553 */
2554 if (btrfs_test_opt(fs_info, QGROUP_AUTO_CLEANUP)) {
> 2555 ret = btrfs_remove_qgroup(trans, fs_info,
2556 dest->root_key.objectid, 0);
2557 if (ret && ret != -ENOENT)
2558 btrfs_warn(fs_info,
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 27370 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-01 2:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-28 21:51 [PATCH] btrfs: Add qgroup_auto_cleanup mount flag to automatically cleanup qgroups Sargun Dhillon
2017-07-01 2:45 ` kbuild test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).