diff mbox series

[v2,6/8] btrfs-progs: Implement helper to remove received information of RW subvol

Message ID 20210914090558.79411-7-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series Implement progs support for removing received uuid on RW vols | expand

Commit Message

Nikolay Borisov Sept. 14, 2021, 9:05 a.m. UTC
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 check/mode-common.c | 40 ++++++++++++++++++++++++++++++++++++++++
 check/mode-common.h |  1 +
 2 files changed, 41 insertions(+)

Comments

Qu Wenruo Sept. 14, 2021, 9:23 a.m. UTC | #1
On 2021/9/14 下午5:05, Nikolay Borisov wrote:
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   check/mode-common.c | 40 ++++++++++++++++++++++++++++++++++++++++
>   check/mode-common.h |  1 +
>   2 files changed, 41 insertions(+)
>
> diff --git a/check/mode-common.c b/check/mode-common.c
> index 0059672c6402..7a5313280f3f 100644
> --- a/check/mode-common.c
> +++ b/check/mode-common.c
> @@ -1301,3 +1301,43 @@ int repair_dev_item_bytes_used(struct btrfs_fs_info *fs_info,
>   	btrfs_abort_transaction(trans, ret);
>   	return ret;
>   }
> +
> +int repair_received_subvol(struct btrfs_root *root)
> +{
> +	struct btrfs_root_item *root_item = &root->root_item;
> +	struct btrfs_trans_handle *trans;
> +	int ret;
> +
> +	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;
> +	}
> +
> +	ret = btrfs_commit_transaction(trans, gfs_info->tree_root);
> +	if (!ret)
> +		printf("Cleared received information for subvol: %llu\n",
> +				root->root_key.objectid);
> +	return ret;
> +}
> diff --git a/check/mode-common.h b/check/mode-common.h
> index cdfb10d58cde..f1ec5dca0199 100644
> --- a/check/mode-common.h
> +++ b/check/mode-common.h
> @@ -130,6 +130,7 @@ int reset_imode(struct btrfs_trans_handle *trans, struct btrfs_root *root,
>   		struct btrfs_path *path, u64 ino, u32 mode);
>   int repair_imode_common(struct btrfs_root *root, struct btrfs_path *path);
>   int check_repair_free_space_inode(struct btrfs_path *path);
> +int repair_received_subvol(struct btrfs_root *root);
>
>   /*
>    * Check if the inode mode @imode is valid
>
diff mbox series

Patch

diff --git a/check/mode-common.c b/check/mode-common.c
index 0059672c6402..7a5313280f3f 100644
--- a/check/mode-common.c
+++ b/check/mode-common.c
@@ -1301,3 +1301,43 @@  int repair_dev_item_bytes_used(struct btrfs_fs_info *fs_info,
 	btrfs_abort_transaction(trans, ret);
 	return ret;
 }
+
+int repair_received_subvol(struct btrfs_root *root)
+{
+	struct btrfs_root_item *root_item = &root->root_item;
+	struct btrfs_trans_handle *trans;
+	int ret;
+
+	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;
+	}
+
+	ret = btrfs_commit_transaction(trans, gfs_info->tree_root);
+	if (!ret)
+		printf("Cleared received information for subvol: %llu\n",
+				root->root_key.objectid);
+	return ret;
+}
diff --git a/check/mode-common.h b/check/mode-common.h
index cdfb10d58cde..f1ec5dca0199 100644
--- a/check/mode-common.h
+++ b/check/mode-common.h
@@ -130,6 +130,7 @@  int reset_imode(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		struct btrfs_path *path, u64 ino, u32 mode);
 int repair_imode_common(struct btrfs_root *root, struct btrfs_path *path);
 int check_repair_free_space_inode(struct btrfs_path *path);
+int repair_received_subvol(struct btrfs_root *root);
 
 /*
  * Check if the inode mode @imode is valid