Skip to contentSkip to conversation

btrfs-progs: move inode cache removal functionality to "btrfs rescue" group

PATCH In review Qu Wenruo 2 participants 6 messages Oct 9, 2023

Subsystems (3)
lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

cover btrfs-progs: move inode cache removal functionality to "btrfs rescue" group

This is the first step to move those cache clearing functionality to "btrfs rescue", as "btrfs check" doesn't looks that proper just to clear various cache.

This patchset is handling issue #669 by moving the rarely used inode cache clearing to "btrfs rescue" as the safe and first step.

Qu Wenruo (2):
btrfs-progs: move clear-cache.[ch] from check to common directory
btrfs-progs: move inode cache removal to rescue group

 Documentation/btrfs-check.rst   |  5 +++-
 Documentation/btrfs-rescue.rst  |  6 ++++
 Makefile                        |  6 ++--
 check/main.c                    |  3 +-
 cmds/rescue.c                   | 52 +++++++++++++++++++++++++++++++++
 {check => common}/clear-cache.c |  2 +-
 {check => common}/clear-cache.h |  0
 convert/main.c                  |  2 +-
 tune/main.c                     |  2 +-
 9 files changed, 70 insertions(+), 8 deletions(-)
 rename {check => common}/clear-cache.c (99%)
 rename {check => common}/clear-cache.h (100%)

--
2.42.0

author
#2 lore raw

PATCH 2/2 btrfs-progs: move inode cache removal to rescue group

The option "--clear-ino-cache" is not really that suitable for "btrfs check" group.

Let's move it to "btrfs rescue" group to fix those small hiccups, just like the existing "btrfs rescue fix-device-size" command.

For now, "btrfs check --clear-ino-cache" would still work, with one extra warning referring to "btrfs rescue clear-ino-cache". This is mostly to reduce the surprise, and keep script users (I doubt if there is any though) happy for now.

In the next or two releases, we would fully remove the support in "btrfs check" group.

Another small change is, in the documents, we refer to the feature as "inode map", which doesn't match with the mount option documents. Since we're here, unify them to "inode cache" feature.

Issue: #669

---
 Documentation/btrfs-check.rst  |  5 +++-
 Documentation/btrfs-rescue.rst |  6 ++++
 check/main.c                   |  1 +
 cmds/rescue.c                  | 52 ++++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 1 deletion(-)
Documentation/btrfs-check.rst +4 -1
index cf8de9fcc888..3c5f96f1951f 100644
@@ -84,8 +84,11 @@ SAFE OR ADVISORY OPTIONS
         See also the *clear_cache* mount option.
 
 --clear-ino-cache
-        remove leftover items pertaining to the deprecated inode map feature
+        remove leftover items pertaining to the deprecated `inode cache` feature
 
+	.. warning::
+		This option is deprecated, please use `btrfs rescue clear-ino-cache`
+		instead, this option would be removed in the future eventually.
 
 DANGEROUS OPTIONS
 -----------------
Documentation/btrfs-rescue.rst +6 -0
index 39d250cefa48..e99aa4ad8a7e 100644
@@ -50,6 +50,12 @@ fix-device-size <device>
 
                 WARNING: CPU: 3 PID: 439 at fs/btrfs/ctree.h:1559 btrfs_update_device+0x1c5/0x1d0 [btrfs]
 
+clear-ino-cache <device>
+        Remove leftover items pertaining to the deprecated `inode cache` feature.
+
+	The `inode cache` feature (enabled by mount option "inode_cache") is
+	fully removed in v5.11 kernel.
+
 clear-uuid-tree <device>
         Clear UUID tree, so that kernel can re-generate it at next read-write
         mount.
check/main.c +1 -0
index 1174939fd6eb..7760511b85d9 100644
@@ -10242,6 +10242,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
 	}
 
 	if (clear_ino_cache) {
+		warning("--clear-ino-cache option is deprecated, please use \"btrfs rescue clear-ino-cache\" instead.")
 		ret = clear_ino_cache_items(gfs_info);
 		err = ret;
 		goto close_out;
cmds/rescue.c +52 -0

70 lines not on this page · raw message

Signature · 1 line
2.42.0
author
#1 lore raw

PATCH 1/2 btrfs-progs: move clear-cache.[ch] from check to common directory

In reply to Qu Wenruo

The clear-cache functionality is not shared by several commands:

- btrfs check
For --clear-cache and --clear-ino-cache.

- btrfstune
Mostly for block-group-tree feature conversion.

- btrfs-convert
To enable the now default v2 space cache.

Thus it's no longer proper to keep clea-cache.[ch] under check/ directory, move them to common/ directory.

---
 Makefile                        | 6 +++---
 check/main.c                    | 2 +-
 {check => common}/clear-cache.c | 2 +-
 {check => common}/clear-cache.h | 0
 convert/main.c                  | 2 +-
 tune/main.c                     | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)
 rename {check => common}/clear-cache.c (99%)
 rename {check => common}/clear-cache.h (100%)
Makefile +3 -3
index e5817f1456a2..345c8efc8249 100644
@@ -242,7 +242,7 @@ cmds_objects = cmds/subvolume.o cmds/subvolume-list.o \
 	       cmds/inspect-dump-super.o cmds/inspect-tree-stats.o cmds/filesystem-du.o \
 	       cmds/reflink.o \
 	       mkfs/common.o check/mode-common.o check/mode-lowmem.o \
-	       check/clear-cache.o
+	       common/clear-cache.o
 
 libbtrfs_objects = \
 		kernel-lib/rbtree.o	\
@@ -262,12 +262,12 @@ libbtrfsutil_objects = libbtrfsutil/errors.o libbtrfsutil/filesystem.o \
 		       libbtrfsutil/stubs.o
 convert_objects = convert/main.o convert/common.o convert/source-fs.o \
 		  convert/source-ext2.o convert/source-reiserfs.o \
-		  mkfs/common.o check/clear-cache.o
+		  mkfs/common.o common/clear-cache.o
 mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
 image_objects = image/main.o image/sanitize.o image/image-create.o image/common.o \
 		image/image-restore.o
 tune_objects = tune/main.o tune/seeding.o tune/change-uuid.o tune/change-metadata-uuid.o \
-	       tune/convert-bgt.o tune/change-csum.o check/clear-cache.o tune/quota.o
+	       tune/convert-bgt.o tune/change-csum.o common/clear-cache.o tune/quota.o
 all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \
 	      $(mkfs_objects) $(image_objects) $(tune_objects) $(libbtrfsutil_objects)
 
check/main.c +1 -1
index be27ee5f2415..1174939fd6eb 100644
@@ -58,6 +58,7 @@
 #include "common/help.h"
 #include "common/open-utils.h"
 #include "common/string-utils.h"
+#include "common/clear-cache.h"
 #include "cmds/commands.h"
 #include "mkfs/common.h"
 #include "check/common.h"
@@ -66,7 +67,6 @@
 #include "check/mode-original.h"
 #include "check/mode-lowmem.h"
 #include "check/qgroup-verify.h"
-#include "check/clear-cache.h"
 
 /* Global context variables */
 struct btrfs_fs_info *gfs_info;
common/clear-cache.c renamed from check/clear-cache.c +1 -1
similarity index 99%
rename from check/clear-cache.c
rename to common/clear-cache.c
index d83d9b2fcda8..d57313b783c0 100644
@@ -33,7 +33,7 @@
 #include "common/messages.h"
 #include "check/repair.h"
 #include "check/mode-common.h"
-#include "check/clear-cache.h"
+#include "common/clear-cache.h"
 
 /*
  * Number of free space cache inodes to delete in one transaction.
common/clear-cache.h renamed from check/clear-cache.h +0 -0
similarity index 100%
rename from check/clear-cache.h
rename to common/clear-cache.h
convert/main.c +1 -1
index 5d7c1e1d99d6..c9e50c036f92 100644
@@ -119,9 +119,9 @@
 #include "common/box.h"
 #include "common/open-utils.h"
 #include "common/extent-tree-utils.h"
+#include "common/clear-cache.h"
 #include "cmds/commands.h"
 #include "check/repair.h"
-#include "check/clear-cache.h"
 #include "mkfs/common.h"
 #include "convert/common.h"
 #include "convert/source-fs.h"
tune/main.c +1 -1
index 08dedce26cb5..4aef76748343 100644
@@ -37,9 +37,9 @@
 #include "common/string-utils.h"
 #include "common/help.h"
 #include "common/box.h"
+#include "common/clear-cache.h"
 #include "cmds/commands.h"
 #include "tune/tune.h"
-#include "check/clear-cache.h"
 
 static char *device;
 static int force = 0;
Signature · 1 line
2.42.0
#3 lore raw

Re: [PATCH 2/2] btrfs-progs: move inode cache removal to rescue group

In reply to Qu Wenruo
Quoted 14 lines · Qu Wenruo

The option "--clear-ino-cache" is not really that suitable for "btrfs check" group.

Let's move it to "btrfs rescue" group to fix those small hiccups, just like the existing "btrfs rescue fix-device-size" command.

For now, "btrfs check --clear-ino-cache" would still work, with one extra warning referring to "btrfs rescue clear-ino-cache". This is mostly to reduce the surprise, and keep script users (I doubt if there is any though) happy for now.

In the next or two releases, we would fully remove the support in "btrfs check" group.

Quoted 6 lines

Another small change is, in the documents, we refer to the feature as "inode map", which doesn't match with the mount option documents. Since we're here, unify them to "inode cache" feature.

Issue: #669

Please don't forget to add the new command to btrfs-completion. I've noticed 2 more were missing so it's done in a separate commit.

Quoted 46 lines
---
 Documentation/btrfs-check.rst  |  5 +++-
 Documentation/btrfs-rescue.rst |  6 ++++
 check/main.c                   |  1 +
 cmds/rescue.c                  | 52 ++++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 1 deletion(-)
Documentation/btrfs-check.rst +4 -1
index cf8de9fcc888..3c5f96f1951f 100644
@@ -84,8 +84,11 @@ SAFE OR ADVISORY OPTIONS
         See also the *clear_cache* mount option.
 
 --clear-ino-cache
-        remove leftover items pertaining to the deprecated inode map feature
+        remove leftover items pertaining to the deprecated `inode cache` feature
 
+	.. warning::
+		This option is deprecated, please use `btrfs rescue clear-ino-cache`
+		instead, this option would be removed in the future eventually.
 
 DANGEROUS OPTIONS
 -----------------
Documentation/btrfs-rescue.rst +6 -0
index 39d250cefa48..e99aa4ad8a7e 100644
@@ -50,6 +50,12 @@ fix-device-size <device>
 
                 WARNING: CPU: 3 PID: 439 at fs/btrfs/ctree.h:1559 btrfs_update_device+0x1c5/0x1d0 [btrfs]
 
+clear-ino-cache <device>
+        Remove leftover items pertaining to the deprecated `inode cache` feature.
+
+	The `inode cache` feature (enabled by mount option "inode_cache") is
+	fully removed in v5.11 kernel.
+
 clear-uuid-tree <device>
         Clear UUID tree, so that kernel can re-generate it at next read-write
         mount.
check/main.c +0 -0
index 1174939fd6eb..7760511b85d9 100644

check/main.c static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) · line 10245

Quoted 4 lines
check/main.c +1 -0
@@ -10242,6 +10242,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
 	}
 
 	if (clear_ino_cache) {
+		warning("--clear-ino-cache option is deprecated, please use \"btrfs rescue clear-ino-cache\" instead.")

No "." at the end of the text and the ";" is missing, does not compile.

Quoted 82 lines
check/main.c +0 -0
 		ret = clear_ino_cache_items(gfs_info);
 		err = ret;
 		goto close_out;
cmds/rescue.c +52 -0
index be6f5016d5a9..38f4e1423434 100644
@@ -34,6 +34,7 @@
 #include "common/utils.h"
 #include "common/help.h"
 #include "common/open-utils.h"
+#include "common/clear-cache.h"
 #include "cmds/commands.h"
 #include "cmds/rescue.h"
 
@@ -405,6 +406,56 @@ out:
 }
 static DEFINE_SIMPLE_COMMAND(rescue_clear_uuid_tree, "clear-uuid-tree");
 
+static const char * const cmd_rescue_clear_ino_cache_usage[] = {
+	"btrfs rescue clear-ino-cache <device>",
+	"remove leftover items pertaining to the deprecated inode cache feature",
+	NULL
+};
+
+static int cmd_rescue_clear_ino_cache(const struct cmd_struct *cmd,
+				      int argc, char **argv)
+{
+	struct open_ctree_args oca = { 0 };
+	struct btrfs_fs_info *fs_info;
+	char *devname;
+	int ret;
+
+	clean_args_no_options(cmd, argc, argv);
+
+	if (check_argc_exact(argc, 2))
+		return 1;
+
+	devname = argv[optind];
+	ret = check_mounted(devname);
+	if (ret < 0) {
+		errno = -ret;
+		error("could not check mount status: %m");
+		goto out;
+	} else if (ret) {
+		error("%s is currently mounted", devname);
+		ret = -EBUSY;
+		goto out;
+	}
+	oca.filename = devname;
+	oca.flags = OPEN_CTREE_WRITES;
+	fs_info = open_ctree_fs_info(&oca);
+	if (!fs_info) {
+		error("could not open btrfs");
+		ret = -EIO;
+		goto out;
+	}
+	ret = clear_ino_cache_items(fs_info);
+	if (ret < 0) {
+		errno = -ret;
+		error("failed to clear ino cache: %m");
+	} else {
+		pr_verbose(LOG_DEFAULT, "Successfully cleared ino cache");
+	}
+out:
+	return !!ret;
+}
+static DEFINE_SIMPLE_COMMAND(rescue_clear_ino_cache, "clear-ino-cache");
+
 static const char rescue_cmd_group_info[] =
 "toolbox for specific rescue operations";
 
@@ -416,6 +467,7 @@ static const struct cmd_group rescue_cmd_group = {
 		&cmd_struct_rescue_fix_device_size,
 		&cmd_struct_rescue_create_control_device,
 		&cmd_struct_rescue_clear_uuid_tree,
+		&cmd_struct_rescue_clear_ino_cache,
 		NULL
 	}
 };
Signature · 1 line
2.42.0
author
#4 lore raw

Re: [PATCH 2/2] btrfs-progs: move inode cache removal to rescue group

Quoted 73 lines · David Sterba
Quoted 14 lines · Qu Wenruo

The option "--clear-ino-cache" is not really that suitable for "btrfs check" group.

Let's move it to "btrfs rescue" group to fix those small hiccups, just like the existing "btrfs rescue fix-device-size" command.

For now, "btrfs check --clear-ino-cache" would still work, with one extra warning referring to "btrfs rescue clear-ino-cache". This is mostly to reduce the surprise, and keep script users (I doubt if there is any though) happy for now.

In the next or two releases, we would fully remove the support in "btrfs check" group.

Quoted 6 lines

Another small change is, in the documents, we refer to the feature as "inode map", which doesn't match with the mount option documents. Since we're here, unify them to "inode cache" feature.

Issue: #669

Please don't forget to add the new command to btrfs-completion. I've noticed 2 more were missing so it's done in a separate commit.

Quoted 48 lines
---
  Documentation/btrfs-check.rst  |  5 +++-
  Documentation/btrfs-rescue.rst |  6 ++++
  check/main.c                   |  1 +
  cmds/rescue.c                  | 52 ++++++++++++++++++++++++++++++++++
  4 files changed, 63 insertions(+), 1 deletion(-)
Documentation/btrfs-check.rst +4 -1
index cf8de9fcc888..3c5f96f1951f 100644
@@ -84,8 +84,11 @@ SAFE OR ADVISORY OPTIONS
          See also the *clear_cache* mount option.
 
  --clear-ino-cache
-        remove leftover items pertaining to the deprecated inode map feature
+        remove leftover items pertaining to the deprecated `inode cache` feature
 
+	.. warning::
+		This option is deprecated, please use `btrfs rescue clear-ino-cache`
+		instead, this option would be removed in the future eventually.
 
  DANGEROUS OPTIONS
  -----------------
Documentation/btrfs-rescue.rst +6 -0
index 39d250cefa48..e99aa4ad8a7e 100644
@@ -50,6 +50,12 @@ fix-device-size <device>
 
                  WARNING: CPU: 3 PID: 439 at fs/btrfs/ctree.h:1559 btrfs_update_device+0x1c5/0x1d0 [btrfs]
 
+clear-ino-cache <device>
+        Remove leftover items pertaining to the deprecated `inode cache` feature.
+
+	The `inode cache` feature (enabled by mount option "inode_cache") is
+	fully removed in v5.11 kernel.
+
  clear-uuid-tree <device>
          Clear UUID tree, so that kernel can re-generate it at next read-write
          mount.
check/main.c +0 -0
index 1174939fd6eb..7760511b85d9 100644
@@ -10242,6 +10242,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
  	}
 
Quoted 5 lines

check/main.c static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) · line 10245

Quoted 2 lines
check/main.c +1 -0
  	if (clear_ino_cache) {
+		warning("--clear-ino-cache option is deprecated, please use \"btrfs rescue clear-ino-cache\" instead.")

No "." at the end of the text and the ";" is missing, does not compile.

My bad, I noticed the warning is missing thus added it in the last minute...

Do I need to resend or you have already fixed it during merge?

Thanks,
Qu

Quoted 83 lines
Quoted 83 lines
check/main.c +0 -0
  		ret = clear_ino_cache_items(gfs_info);
  		err = ret;
  		goto close_out;
cmds/rescue.c +52 -0
index be6f5016d5a9..38f4e1423434 100644
@@ -34,6 +34,7 @@
  #include "common/utils.h"
  #include "common/help.h"
  #include "common/open-utils.h"
+#include "common/clear-cache.h"
  #include "cmds/commands.h"
  #include "cmds/rescue.h"
 
@@ -405,6 +406,56 @@ out:
  }
  static DEFINE_SIMPLE_COMMAND(rescue_clear_uuid_tree, "clear-uuid-tree");
 
+static const char * const cmd_rescue_clear_ino_cache_usage[] = {
+	"btrfs rescue clear-ino-cache <device>",
+	"remove leftover items pertaining to the deprecated inode cache feature",
+	NULL
+};
+
+static int cmd_rescue_clear_ino_cache(const struct cmd_struct *cmd,
+				      int argc, char **argv)
+{
+	struct open_ctree_args oca = { 0 };
+	struct btrfs_fs_info *fs_info;
+	char *devname;
+	int ret;
+
+	clean_args_no_options(cmd, argc, argv);
+
+	if (check_argc_exact(argc, 2))
+		return 1;
+
+	devname = argv[optind];
+	ret = check_mounted(devname);
+	if (ret < 0) {
+		errno = -ret;
+		error("could not check mount status: %m");
+		goto out;
+	} else if (ret) {
+		error("%s is currently mounted", devname);
+		ret = -EBUSY;
+		goto out;
+	}
+	oca.filename = devname;
+	oca.flags = OPEN_CTREE_WRITES;
+	fs_info = open_ctree_fs_info(&oca);
+	if (!fs_info) {
+		error("could not open btrfs");
+		ret = -EIO;
+		goto out;
+	}
+	ret = clear_ino_cache_items(fs_info);
+	if (ret < 0) {
+		errno = -ret;
+		error("failed to clear ino cache: %m");
+	} else {
+		pr_verbose(LOG_DEFAULT, "Successfully cleared ino cache");
+	}
+out:
+	return !!ret;
+}
+static DEFINE_SIMPLE_COMMAND(rescue_clear_ino_cache, "clear-ino-cache");
+
  static const char rescue_cmd_group_info[] =
  "toolbox for specific rescue operations";
 
@@ -416,6 +467,7 @@ static const struct cmd_group rescue_cmd_group = {
  		&cmd_struct_rescue_fix_device_size,
  		&cmd_struct_rescue_create_control_device,
  		&cmd_struct_rescue_clear_uuid_tree,
+		&cmd_struct_rescue_clear_ino_cache,
  		NULL
  	}
  };
Signature · 1 line
2.42.0
#5 lore raw

Re: [PATCH 2/2] btrfs-progs: move inode cache removal to rescue group

Quoted 13 lines · Qu Wenruo
Quoted 11 lines · David Sterba

check/main.c static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) · line 10245

Quoted 7 lines · Qu Wenruo
check/main.c +1 -0
@@ -10242,6 +10242,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
  	}
 
  	if (clear_ino_cache) {
+		warning("--clear-ino-cache option is deprecated, please use \"btrfs rescue clear-ino-cache\" instead.")

No "." at the end of the text and the ";" is missing, does not compile.

Quoted 3 lines

My bad, I noticed the warning is missing thus added it in the last minute...

Do I need to resend or you have already fixed it during merge?

No need to resend.