linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Divya Indi <divya.indi@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: ashish.samant@oracle.com, bo.li.liu@oracle.com
Subject: [PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their bg info
Date: Mon, 17 Oct 2016 17:35:13 -0700	[thread overview]
Message-ID: <1476750915-3105-2-git-send-email-divya.indi@oracle.com> (raw)
In-Reply-To: <1476750915-3105-1-git-send-email-divya.indi@oracle.com>

An efficient alternative to retrieving block groups:
get_chunks(): Walk the chunk tree to retrieve the chunks.
get_bg_info(): For each retrieved chunk, lookup an exact match of block
group in the extent tree.

Signed-off-by: Divya Indi <divya.indi@oracle.com>
Reviewed-by: Ashish Samant <ashish.samant@oracle.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
---
 cmds-inspect.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/cmds-inspect.c b/cmds-inspect.c
index 4b7cea0..f435ea9 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -81,6 +81,72 @@ out:
 	return !!ret;
 }
 
+static void bg_flags_to_str(u64 flags, char *ret)
+{
+	int empty = 1;
+
+	if (flags & BTRFS_BLOCK_GROUP_DATA) {
+		empty = 0;
+		strcpy(ret, "DATA");
+	}
+	if (flags & BTRFS_BLOCK_GROUP_METADATA) {
+		if (!empty)
+			strcat(ret, "|");
+		strcat(ret, "METADATA");
+	}
+	if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
+		if (!empty)
+			strcat(ret, "|");
+		strcat(ret, "SYSTEM");
+	}
+}
+
+/* Walking through the chunk tree to retrieve chunks. */
+
+static int get_chunks(int fd, struct btrfs_ioctl_search_args *chunk_args)
+{
+	struct btrfs_ioctl_search_key *sk;
+	int ret;
+	int e;
+
+	sk = &chunk_args->key;
+
+	sk->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
+	sk->min_objectid = sk->max_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
+	sk->max_type = sk->min_type = BTRFS_CHUNK_ITEM_KEY;
+	sk->nr_items = 4096;
+
+	ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, chunk_args);
+	e = errno;
+	if (ret < 0) {
+		fprintf(stderr, "ret %d error '%s'\n", ret,
+				strerror(e));
+	}
+	return ret;
+}
+
+/* Given the objectid, find the block group item in the extent tree */
+static int get_bg_info(int fd, struct btrfs_ioctl_search_args *bg_args,
+		       u64 objectid, unsigned long length)
+{
+	struct btrfs_ioctl_search_key *bg_sk;
+	int ret;
+	int e;
+
+	bg_sk = &bg_args->key;
+
+	bg_sk->min_objectid = bg_sk->max_objectid = objectid;
+	bg_sk->nr_items = 1;
+	bg_sk->min_offset = bg_sk->max_offset = length;
+
+	ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, bg_args);
+	e = errno;
+	if (ret < 0) {
+		fprintf(stderr, "ret %d error '%s'\n", ret,
+				strerror(e));
+	}
+	return ret;
+}
 static const char * const cmd_inspect_inode_resolve_usage[] = {
 	"btrfs inspect-internal inode-resolve [-v] <inode> <path>",
 	"Get file system paths for the given inode",
-- 
1.7.1


  reply	other threads:[~2016-10-18  0:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18  0:35 btrfs-progs: Add 2 new subcommands to inspect-internal Divya Indi
2016-10-18  0:35 ` Divya Indi [this message]
2016-10-18  0:35   ` [PATCH 2/3] btrfs-progs: Add a command to show bg info Divya Indi
2016-10-18  0:35     ` [PATCH 3/3] btrfs-progs: Add command to check if balance op is req Divya Indi
2016-10-18  1:42       ` Qu Wenruo
2016-10-19 17:08         ` Divya Indi
2016-10-28 15:20           ` David Sterba
2016-10-28 16:29             ` Graham Cobb
2016-10-31 16:33               ` David Sterba
2016-11-02  0:39                 ` divya.indi
2016-10-30 14:10             ` Qu Wenruo
2016-10-18  1:39     ` [PATCH 2/3] btrfs-progs: Add a command to show bg info Qu Wenruo
2016-10-18  5:24       ` Roman Mamedov
2016-10-19 17:33         ` Divya Indi
2016-10-28 16:00     ` David Sterba
2016-11-02  0:40       ` divya.indi
2016-10-18  1:34   ` [PATCH 1/3] btrfs-progs: Generic functions to retrieve chunks and their " Qu Wenruo
2016-10-28 15:44   ` David Sterba
2016-11-02  0:39     ` divya.indi
2017-06-07 17:03     ` Goffredo Baroncelli
2017-06-09 21:57       ` divya.indi

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=1476750915-3105-2-git-send-email-divya.indi@oracle.com \
    --to=divya.indi@oracle.com \
    --cc=ashish.samant@oracle.com \
    --cc=bo.li.liu@oracle.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 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).