All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Subject: [RFC PATCH 03/22] btrfs-progs: Add new init/free function and member for mkfs_config
Date: Wed, 18 Nov 2015 15:22:03 +0800	[thread overview]
Message-ID: <1447831342-15056-4-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1447831342-15056-1-git-send-email-quwenruo@cn.fujitsu.com>

Add new members for mkfs_config:
1. super_bytenr
   For convert case to restore where super block is allocated.
   Has no use for normal mkfs case.

2. convert_used
   A cache tree to record which ranges are used in original filesystem.
   This will gives the guide for later convert implement to provide better
   system/meta chunk allocation, other than just allocating them into
   range covered by DATA chunk.

3. chunk_uuid
   Chunk tree uuid, used for later per tree root initialization.

Since convert_used is a cache_tree, it needs to be initialized and freed
properly, add new init/free function for it too.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 btrfs-convert.c |  5 +++++
 mkfs.c          |  2 ++
 utils.h         | 29 +++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/btrfs-convert.c b/btrfs-convert.c
index 02e5cdb..f66affd 100644
--- a/btrfs-convert.c
+++ b/btrfs-convert.c
@@ -2322,6 +2322,9 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxatt
 	}
 	if (btrfs_check_nodesize(nodesize, blocksize, features))
 		goto fail;
+
+	init_mkfs_config(&mkfs_cfg);
+
 	blocks_per_node = nodesize / blocksize;
 	ret = -blocks_per_node;
 	for (i = 0; i < 7; i++) {
@@ -2479,6 +2482,8 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxatt
 	printf("conversion complete.\n");
 	return 0;
 fail:
+	free_mkfs_config(&mkfs_cfg);
+
 	if (fd != -1)
 		close(fd);
 	if (is_btrfs)
diff --git a/mkfs.c b/mkfs.c
index 5f1411f..306be51 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1669,6 +1669,7 @@ int main(int ac, char **av)
 			"WARNING: metatdata has lower redundancy than data!\n\n");
 	}
 
+	init_mkfs_config(&mkfs_cfg);
 	mkfs_cfg.label = label;
 	mkfs_cfg.fs_uuid = fs_uuid;
 	memcpy(mkfs_cfg.blocks, blocks, sizeof(blocks));
@@ -1839,6 +1840,7 @@ raid_groups:
 	}
 
 out:
+	free_mkfs_config(&mkfs_cfg);
 	ret = close_ctree(root);
 	BUG_ON(ret);
 	btrfs_close_all_devices();
diff --git a/utils.h b/utils.h
index b625330..dff2633 100644
--- a/utils.h
+++ b/utils.h
@@ -109,14 +109,43 @@ void btrfs_parse_features_to_string(char *buf, u64 flags);
 struct btrfs_mkfs_config {
 	char *label;
 	char *fs_uuid;
+	char *chunk_uuid;
+
 	u64 blocks[8];
 	u64 num_bytes;
 	u32 nodesize;
 	u32 sectorsize;
 	u32 stripesize;
 	u64 features;
+
+	/*
+	 * Already used space in original filesystem before convert.
+	 * For normal mkfs case, it should be empty.
+	 */
+	struct cache_tree convert_used;
+
+	/*
+	 * Super block bytenr.
+	 * For normal mkfs case, it shouldn't be used as mkfs doesn't support
+	 * change super block bytenr anymore.
+	 *
+	 * For convert use, it restore the superblock bytenr from the temporary
+	 * btrfs fs.
+	 */
+	u64 super_bytenr;
 };
 
+static inline void init_mkfs_config(struct btrfs_mkfs_config *cfg)
+{
+	memset(cfg, 0, sizeof(*cfg));
+	cache_tree_init(&cfg->convert_used);
+}
+
+static inline void free_mkfs_config(struct btrfs_mkfs_config *cfg)
+{
+	free_extent_cache_tree(&cfg->convert_used);
+}
+
 int make_btrfs(int fd, struct btrfs_mkfs_config *cfg);
 int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
 			struct btrfs_root *root, u64 objectid);
-- 
2.6.2


  parent reply	other threads:[~2015-11-18  7:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18  7:22 [RFC PATCH 00/22] Btrfs-convert rework part 1 Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 01/22] btrfs-progs: extent-cache: Add comments for search/lookup functions Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 02/22] btrfs-progs: extent-tree: Add add_merge_cache_extent function Qu Wenruo
2015-11-18  7:22 ` Qu Wenruo [this message]
2015-11-18  7:22 ` [RFC PATCH 04/22] btrfs-progs: convert: Read and build up used space tree Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 05/22] btrfs-progs: utils: Introduce new function to remove reserved ranges Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 06/22] btrfs-progs: utils: Introduce function to calculate the available space Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 07/22] btrfs-progs: Reserve space for system/meta chunks and superblock Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 08/22] btrfs-progs: Introduce function to setup temporary superblock Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 09/22] btrfs-progs: Introduce function to setup temporary tree root Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 10/22] btrfs-progs: Introduce function to setup temporary chunk root Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 11/22] btrfs-progs: Introduce function to initialize device tree Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 12/22] btrfs-progs: Introduce function to initialize fs tree Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 13/22] btrfs-progs: Introduce function to initialize csum tree Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 14/22] btrfs-progs: Introduce function to setup temporary extent tree Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 15/22] btrfs-progs: Introduce function to create convert data chunks Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 16/22] btrfs-progs: extent-tree: Introduce function to find the first overlap extent Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 17/22] btrfs-progs: extent-tree: Enhance btrfs_record_file_extent Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 18/22] btrfs-progs: convert: Introduce new function to create ext2 image Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 19/22] btrfs-progs: convert: Introduce function to migrate reserved ranges Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 20/22] btrfs-progs: Enhance record_file_blocks to handle " Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 21/22] btrfs-progs: convert: Introduce init_btrfs_v2 function Qu Wenruo
2015-11-18  7:22 ` [RFC PATCH 22/22] btrfs-progs: Introduce do_convert_v2 function Qu Wenruo

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=1447831342-15056-4-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.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.