From: Sidong Yang <realwakka@gmail.com>
To: linux-btrfs@vger.kernel.org, Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Sidong Yang <realwakka@gmail.com>
Subject: [PATCH v2] btrfs-progs: property: introduce drop_subtree_threshold property
Date: Sun, 11 Aug 2024 12:24:15 +0000 [thread overview]
Message-ID: <20240811122415.6575-1-realwakka@gmail.com> (raw)
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
---
cmds/property.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/cmds/property.c b/cmds/property.c
index a36b5ab2..88344001 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,50 @@ 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) {
+ if (sysfs_fd == -ENOENT) {
+ error("failed to access qgroups/drop_subtree_threshold for %s,"
+ " quota should be enabled for this property: %m",
+ object);
+ }
+ close(fd);
+ return -errno;
+ }
+
+ 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);
+ }
+ }
+ if (ret < 0) {
+ ret = -errno;
+ } else {
+ ret = 0;
+ }
+
+ close(sysfs_fd);
+ close(fd);
+ return ret;
+}
const struct prop_handler prop_handlers[] = {
{
@@ -259,6 +304,14 @@ 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
next reply other threads:[~2024-08-11 12:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-11 12:24 Sidong Yang [this message]
2024-08-11 22:46 ` [PATCH v2] btrfs-progs: property: introduce drop_subtree_threshold property Qu Wenruo
2024-08-12 0:52 ` Sidong Yang
2024-08-11 23:17 ` Roman Mamedov
2024-08-12 0:54 ` Sidong Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240811122415.6575-1-realwakka@gmail.com \
--to=realwakka@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.