Skip to contentSkip to conversation

btrfs-progs: property: introduce drop_subtree_threshold property

PATCH Superseded Sidong Yang 3 participants 5 messages Aug 11, 2024 – Aug 12, 2024 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs-progs: property: introduce drop_subtree_threshold property

This patch introduces new property drop_subtree_threshold. This property could be set/get easily by root dir without find sysfs path.

Issue: #795

---
v2: error msg for -ENOENT, fix desc for prop

---
 cmds/property.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
cmds/property.c +53 -0
index a36b5ab2..88344001 100644
@@ -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}
 };
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 39 lines · Sidong Yang

This patch introduces new property drop_subtree_threshold. This property could be set/get easily by root dir without find sysfs path.

Issue: #795

---
v2: error msg for -ENOENT, fix desc for prop

---
  cmds/property.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 53 insertions(+)
cmds/property.c +11 -0
index a36b5ab2..88344001 100644
@@ -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];
+

cmds/property.c out: · line 259

Quoted 10 lines
cmds/property.c +10 -0
+        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);

I do not think this needs to be error(), warning() should be enough.

cmds/property.c out: · line 262

Quoted 3 lines
cmds/property.c +3 -0
+		}
+		close(fd);
+		return -errno;

Furthermore for ENOENT case I do not even think we should return error.

The point here is, if qgroup is not running (or running in simple quota) mode, there is no need to set threshold at all, thus no need to return any error.

Quoted 25 lines
cmds/property.c +21 -0
+	}
+
+	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[] = {
  	{

cmds/property.c const struct prop_handler prop_handlers[] = { · line 310

Quoted 7 lines
cmds/property.c +4 -0
@@ -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",

Please do not break the string, even it's very long.

Thanks,
Qu

Quoted 7 lines
cmds/property.c +4 -0
+		.read_only = 0,
+		.types = prop_object_root,
+		.handler = prop_drop_subtree_threshold
+	},
  	{NULL, NULL, 0, 0, NULL}
  };
 
#2 lore raw
Quoted 59 lines · Qu Wenruo
Quoted 37 lines · Sidong Yang

This patch introduces new property drop_subtree_threshold. This property could be set/get easily by root dir without find sysfs path.

Issue: #795

---
v2: error msg for -ENOENT, fix desc for prop

---
  cmds/property.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 53 insertions(+)
cmds/property.c +11 -0
index a36b5ab2..88344001 100644
@@ -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];
+

cmds/property.c out: · line 258

Quoted 10 lines
cmds/property.c +10 -0
+        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);

I do not think this needs to be error(), warning() should be enough.

cmds/property.c out: · line 262

Quoted 3 lines
cmds/property.c +3 -0
+		}
+		close(fd);
+		return -errno;

Furthermore for ENOENT case I do not even think we should return error.

Quoted 4 lines

The point here is, if qgroup is not running (or running in simple quota) mode, there is no need to set threshold at all, thus no need to return any error.

Okay, I understood. It's better to return 0 if qgroup is not running in next patch version.

Quoted 25 lines
Quoted 25 lines
cmds/property.c +21 -0
+	}
+
+	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,
Quoted 8 lines

cmds/property.c const struct prop_handler prop_handlers[] = { · line 310

Quoted 6 lines
cmds/property.c +4 -0
  		.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",

Please do not break the string, even it's very long.

Thanks, I was worried about this.

Thanks,
Sidong

Quoted 10 lines

Thanks,
Qu

Quoted 6 lines
cmds/property.c +4 -0
+		.read_only = 0,
+		.types = prop_object_root,
+		.handler = prop_drop_subtree_threshold
+	},
  	{NULL, NULL, 0, 0, NULL}
  };
#3 lore raw
In reply to Sidong Yang
Quoted 30 lines · On Sun, 11 Aug 2024 12:24:15 +0000 Sidong Yang <[email protected]> wrote:

This patch introduces new property drop_subtree_threshold. This property could be set/get easily by root dir without find sysfs path.

Issue: #795

---
v2: error msg for -ENOENT, fix desc for prop

---
 cmds/property.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
cmds/property.c +2 -0
index a36b5ab2..88344001 100644
@@ -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,

cmds/property.c out: · line 250

Quoted 10 lines
cmds/property.c +10 -0
+				       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);

This line is indented with spaces instead of TABs like the rest and as it should. I did not check if this is the only occurrence.

Checkpatch should catch this: https://docs.kernel.org/dev-tools/checkpatch.html

Quoted 51 lines
cmds/property.c +41 -0
+	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}
 };
 
Signature · 2 lines
With respect,
Roman
#4 lore raw

On Mon, Aug 12, 2024 at 04:17:20AM +0500, Roman Mamedov wrote:

Hi! Roman.
Thanks for review.

Quoted 47 lines
Quoted 30 lines · On Sun, 11 Aug 2024 12:24:15 +0000 Sidong Yang <[email protected]> wrote:

This patch introduces new property drop_subtree_threshold. This property could be set/get easily by root dir without find sysfs path.

Issue: #795

---
v2: error msg for -ENOENT, fix desc for prop

---
 cmds/property.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
cmds/property.c +2 -0
index a36b5ab2..88344001 100644
@@ -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,

cmds/property.c out: · line 250

Quoted 10 lines
cmds/property.c +10 -0
+				       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);

This line is indented with spaces instead of TABs like the rest and as it should. I did not check if this is the only occurrence.

Quoted 1 line

Checkpatch should catch this: https://docs.kernel.org/dev-tools/checkpatch.html

Oops, I didn't notice about this. thanks for tip!

Quoted 44 lines
Quoted 44 lines
cmds/property.c +36 -0
+	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"
Quoted 13 lines
Quoted 8 lines
cmds/property.c +5 -0
+		"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}
 };
 
Signature · 2 lines
With respect,
Roman

Thanks,
Sidong