* [PATCH v3] btrfs-progs: property: introduce drop_subtree_threshold property
@ 2024-08-12 12:31 Sidong Yang
0 siblings, 0 replies; only message in thread
From: Sidong Yang @ 2024-08-12 12:31 UTC (permalink / raw)
To: linux-btrfs; +Cc: Sidong Yang, Qu Wenruo, Roman Mamedov
This patch introduces new property drop_subtree_threshold. This property
could be set/get easily by root dir without find sysfs path.
Fixes: https://github.com/kdave/btrfs-progs/issues/795
Issue: #795
Signed-off-by: Sidong Yang <realwakka@gmail.com>
---
v2: error msg for -ENOENT, fix desc for prop
v3: warn msg and return 0 for -ENOENT, fix style
---
cmds/property.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/cmds/property.c b/cmds/property.c
index a36b5ab2..42c372dd 100644
--- a/cmds/property.c
+++ b/cmds/property.c
@@ -35,6 +35,7 @@
#include "common/utils.h"
#include "common/help.h"
#include "common/filesystem-utils.h"
+#include "common/sysfs-utils.h"
#include "cmds/commands.h"
#include "cmds/props.h"
@@ -236,6 +237,49 @@ out:
return ret;
}
+static int prop_drop_subtree_threshold(enum prop_object_type type,
+ const char *object,
+ const char *name,
+ const char *value,
+ bool force)
+{
+ int ret;
+ int fd;
+ int sysfs_fd;
+ char buf[255];
+
+ fd = btrfs_open_path(object, value, false);
+ if (fd < 0)
+ return -errno;
+
+ sysfs_fd = sysfs_open_fsid_file(fd, "qgroups/drop_subtree_threshold");
+ if (sysfs_fd < 0) {
+ ret = sysfs_fd;
+ if (ret == -ENOENT) {
+ warning("failed to access qgroups/drop_subtree_threshold for %s, quota should be enabled for this property: %m",
+ object);
+ ret = 0;
+ }
+ close(fd);
+ return ret;
+ }
+
+ if (value) {
+ ret = write(sysfs_fd, value, strlen(value));
+ } else {
+ ret = read(sysfs_fd, buf, 255);
+ if (ret > 0) {
+ buf[ret] = 0;
+ pr_verbose(LOG_DEFAULT, "drop_subtree_threshold=%s", buf);
+ }
+ }
+
+ ret = ret < 0 ? -errno : 0;
+
+ close(sysfs_fd);
+ close(fd);
+ return ret;
+}
const struct prop_handler prop_handlers[] = {
{
@@ -259,6 +303,13 @@ const struct prop_handler prop_handlers[] = {
.types = prop_object_inode,
.handler = prop_compression
},
+ {
+ .name = "drop_subtree_threshold",
+ .desc = "subtree level threshold to mark qgroup inconsistent during snapshot deletion, can reduce qgroup workload of snapshot deletion",
+ .read_only = 0,
+ .types = prop_object_root,
+ .handler = prop_drop_subtree_threshold
+ },
{NULL, NULL, 0, 0, NULL}
};
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2024-08-12 12:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-12 12:31 [PATCH v3] btrfs-progs: property: introduce drop_subtree_threshold property Sidong Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox