From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH 4/7] btrfs-progs: mkfs/rootdir: Introduce function to get end position of last device extent
Date: Fri, 20 Oct 2017 09:59:04 +0800 [thread overview]
Message-ID: <20171020015907.25430-5-wqu@suse.com> (raw)
In-Reply-To: <20171020015907.25430-1-wqu@suse.com>
Useful for later 'mkfs.btrfs --rootdir' shrink support.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
mkfs/rootdir.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c
index 99022afaa030..1ca37996a3b3 100644
--- a/mkfs/rootdir.c
+++ b/mkfs/rootdir.c
@@ -26,6 +26,7 @@
#include <fcntl.h>
#include <ftw.h>
#include "ctree.h"
+#include "volumes.h"
#include "internal.h"
#include "disk-io.h"
#include "messages.h"
@@ -778,3 +779,45 @@ u64 btrfs_mkfs_size_dir(const char *dir_name, u32 sectorsize, u64 min_dev_size,
total_size = data_chunk_size + meta_chunk_size + min_dev_size;
return total_size;
}
+
+/*
+ * Get the end position of the last device extent for given @devid;
+ * @size_ret is exclsuive (means it should be aligned to sectorsize)
+ */
+static int get_device_extent_end(struct btrfs_fs_info *fs_info,
+ u64 devid, u64 *size_ret)
+{
+ struct btrfs_root *dev_root = fs_info->dev_root;
+ struct btrfs_key key;
+ struct btrfs_path path;
+ struct btrfs_dev_extent *de;
+ int ret;
+
+ key.objectid = devid;
+ key.type = BTRFS_DEV_EXTENT_KEY;
+ key.offset = (u64)-1;
+
+ btrfs_init_path(&path);
+ ret = btrfs_search_slot(NULL, dev_root, &key, &path, 0, 0);
+ /* Not really possible */
+ BUG_ON(ret == 0);
+
+ ret = btrfs_previous_item(dev_root, &path, devid, BTRFS_DEV_EXTENT_KEY);
+ if (ret < 0)
+ goto out;
+
+ /* No dev_extent at all, not really possible for rootdir case*/
+ if (ret > 0) {
+ *size_ret = 0;
+ ret = -EUCLEAN;
+ goto out;
+ }
+
+ btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
+ de = btrfs_item_ptr(path.nodes[0], path.slots[0],
+ struct btrfs_dev_extent);
+ *size_ret = key.offset + btrfs_dev_extent_length(path.nodes[0], de);
+out:
+ btrfs_release_path(&path);
+ return ret;
+}
--
2.14.2
next prev parent reply other threads:[~2017-10-20 1:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-20 1:59 [PATCH 0/7] btrfs-progs: mkfs: Reword --rootdir Qu Wenruo
2017-10-20 1:59 ` [PATCH 1/7] btrfs-progs: mkfs: Don't use custom chunk allocator for rootdir Qu Wenruo
2017-10-20 1:59 ` [PATCH 2/7] btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier Qu Wenruo
2017-10-20 1:59 ` [PATCH 3/7] btrfs-progs: mkfs: Only zero out the first 1M for rootdir Qu Wenruo
2017-11-28 15:32 ` David Sterba
2017-10-20 1:59 ` Qu Wenruo [this message]
2017-11-28 15:36 ` [PATCH 4/7] btrfs-progs: mkfs/rootdir: Introduce function to get end position of last device extent David Sterba
2017-10-20 1:59 ` [PATCH 5/7] btrfs-progs: mkfs/rootdir: Shrink fs for rootdir option Qu Wenruo
2017-10-20 1:59 ` [PATCH 6/7] btrfs-progs: mkfs: Update allocation info before verbose output Qu Wenruo
2017-11-28 15:41 ` David Sterba
2017-10-20 1:59 ` [PATCH 7/7] btrfs-progs: mkfs: Separate shrink from rootdir Qu Wenruo
2017-11-20 20:15 ` [PATCH 0/7] btrfs-progs: mkfs: Reword --rootdir David Sterba
2017-11-28 15:44 ` David Sterba
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=20171020015907.25430-5-wqu@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.cz \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).