All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 7/8] btrfs-progs: check/lowmem: Implement received info clearing for RW volumes
Date: Mon, 13 Sep 2021 16:17:28 +0300	[thread overview]
Message-ID: <20210913131729.37897-8-nborisov@suse.com> (raw)
In-Reply-To: <20210913131729.37897-1-nborisov@suse.com>

This is the counterpart to the original mode's implementation but for
lowmem. I've put the code under the  if (!check_all) branch because
otherwise the check is run multiple times - from check_chunks_and_extents_lowmem
and from actual fs_root check. By having it under the !check_all
condition in check_btrfs_root it ensures that the check is performed
only when checking the fs roots themselves.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 check/mode-lowmem.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 323e66bc4cb1..70cf164752ff 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -5197,6 +5197,44 @@ static int check_btrfs_root(struct btrfs_root *root, int check_all)
 		ret = check_fs_first_inode(root);
 		if (ret < 0)
 			return FATAL_ERROR;
+
+		if (!((btrfs_root_flags(root_item) & BTRFS_ROOT_SUBVOL_RDONLY) ||
+					btrfs_is_empty_uuid(root_item->received_uuid))) {
+			printf("Subvolume id: %llu is RW and has a received uuid\n",
+					root->root_key.objectid);
+			if (repair) {
+				struct btrfs_trans_handle *trans = btrfs_start_transaction(root, 2);
+				if (IS_ERR(trans))
+					return PTR_ERR(trans);
+
+				ret = btrfs_uuid_tree_remove(trans, root_item->received_uuid,
+						BTRFS_UUID_KEY_RECEIVED_SUBVOL, root->root_key.objectid);
+
+				if (ret && ret != -ENOENT) {
+					btrfs_abort_transaction(trans, ret);
+					return ret;
+				}
+
+				memset(root_item->received_uuid, 0, BTRFS_UUID_SIZE);
+				btrfs_set_root_stransid(root_item, 0);
+				btrfs_set_root_rtransid(root_item, 0);
+				btrfs_set_stack_timespec_sec(&root_item->stime, 0);
+				btrfs_set_stack_timespec_nsec(&root_item->stime, 0);
+				btrfs_set_stack_timespec_sec(&root_item->rtime, 0);
+				btrfs_set_stack_timespec_nsec(&root_item->rtime, 0);
+
+				ret = btrfs_update_root(trans, gfs_info->tree_root, &root->root_key,
+						root_item);
+				if (ret < 0) {
+					btrfs_abort_transaction(trans, ret);
+					return ret;
+				}
+
+				btrfs_commit_transaction(trans, gfs_info->tree_root);
+				printf("Cleared received information for subvol: %llu\n",
+						root->root_key.objectid);
+			}
+		}
 	}
 
 
-- 
2.17.1


  parent reply	other threads:[~2021-09-13 13:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 13:17 [PATCH 0/8] Implement progs support for removing received uuid on RW vols Nikolay Borisov
2021-09-13 13:17 ` [PATCH 1/8] btrfs-progs: Add btrfs_is_empty_uuid Nikolay Borisov
2021-09-14  0:58   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 2/8] btrfs-progs: Remove root argument from btrfs_fixup_low_keys Nikolay Borisov
2021-09-14  1:01   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 3/8] btrfs-progs: Remove fs_info argument from leaf_data_end Nikolay Borisov
2021-09-14  1:02   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 4/8] btrfs-progs: Remove root argument from btrfs_truncate_item Nikolay Borisov
2021-09-14  1:02   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 5/8] btrfs-progs: Add btrfs_uuid_tree_remove Nikolay Borisov
2021-09-14  1:07   ` Qu Wenruo
2021-09-14  4:49     ` Nikolay Borisov
2021-09-14  4:57       ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 6/8] btrfs-progs: check/original: Implement removing received data for RW subvols Nikolay Borisov
2021-09-13 13:17 ` Nikolay Borisov [this message]
2021-09-13 13:17 ` [PATCH 8/8] btrfs-progs: tests: Add test for received information removal Nikolay Borisov

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=20210913131729.37897-8-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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.