All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Subject: [PATCH v3 06/15] ext2fs: add new APIs needed for fast commits
Date: Wed, 20 Jan 2021 13:26:32 -0800	[thread overview]
Message-ID: <20210120212641.526556-7-user@harshads-520.kir.corp.google.com> (raw)
In-Reply-To: <20210120212641.526556-1-user@harshads-520.kir.corp.google.com>

From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

This patch adds the following new APIs:

Count the total number of blocks occupied by inode including
intermediate extent tree nodes.
extern blk64_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
                                       struct ext2_inode *inode);

Convert ext3_extent to ext2fs_extent.
extern void ext2fs_convert_extent(struct ext2fs_extent *to,
                                       struct ext3_extent *from);

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
---
 lib/ext2fs/ext2fs.h |  4 +++
 lib/ext2fs/extent.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index ec841006..fdcb28f6 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1332,6 +1332,10 @@ extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle);
 extern size_t ext2fs_max_extent_depth(ext2_extent_handle_t handle);
 extern errcode_t ext2fs_fix_extents_checksums(ext2_filsys fs, ext2_ino_t ino,
 					      struct ext2_inode *inode);
+extern blk64_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
+					struct ext2_inode *inode);
+extern errcode_t ext2fs_decode_extent(struct ext2fs_extent *to, void *from,
+				      int len);
 
 /* fallocate.c */
 #define EXT2_FALLOCATE_ZERO_BLOCKS	(0x1)
diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c
index ac3dbfec..8d5fc1ab 100644
--- a/lib/ext2fs/extent.c
+++ b/lib/ext2fs/extent.c
@@ -1785,6 +1785,69 @@ out:
 	return errcode;
 }
 
+errcode_t ext2fs_decode_extent(struct ext2fs_extent *to, void *addr, int len)
+{
+	struct ext3_extent *from = (struct ext3_extent *)addr;
+
+	if (len != sizeof(struct ext3_extent))
+		return EXT2_ET_INVALID_ARGUMENT;
+
+	to->e_pblk = ext2fs_le32_to_cpu(from->ee_start) +
+		((__u64) ext2fs_le16_to_cpu(from->ee_start_hi)
+			<< 32);
+	to->e_lblk = ext2fs_le32_to_cpu(from->ee_block);
+	to->e_len = ext2fs_le16_to_cpu(from->ee_len);
+	to->e_flags |= EXT2_EXTENT_FLAGS_LEAF;
+	if (to->e_len > EXT_INIT_MAX_LEN) {
+		to->e_len -= EXT_INIT_MAX_LEN;
+		to->e_flags |= EXT2_EXTENT_FLAGS_UNINIT;
+	}
+
+	return 0;
+}
+
+blk64_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
+			struct ext2_inode *inode)
+{
+	ext2_extent_handle_t	handle;
+	struct ext2fs_extent	extent;
+	errcode_t		errcode;
+	int			i;
+	blk64_t			blkcount = 0;
+	blk64_t			*intermediate_nodes;
+
+	errcode = ext2fs_extent_open2(fs, ino, inode, &handle);
+	if (errcode)
+		goto out;
+
+	errcode = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent);
+	if (errcode)
+		goto out;
+
+	ext2fs_get_array(handle->max_depth, sizeof(blk64_t),
+				&intermediate_nodes);
+	blkcount = handle->level;
+	while (!errcode) {
+		if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF) {
+			blkcount += extent.e_len;
+			for (i = 0; i < handle->level; i++) {
+				if (intermediate_nodes[i] !=
+					handle->path[i].end_blk) {
+					blkcount++;
+					intermediate_nodes[i] =
+						handle->path[i].end_blk;
+				}
+			}
+		}
+		errcode = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT, &extent);
+	}
+	ext2fs_free_mem(&intermediate_nodes);
+out:
+	ext2fs_extent_free(handle);
+
+	return blkcount;
+}
+
 #ifdef DEBUG
 /*
  * Override debugfs's prompt
-- 
2.30.0.284.gd98b1dd5eaa7-goog


  parent reply	other threads:[~2021-01-21  0:31 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 21:26 [PATCH v3 00/15] Fast commit changes for e2fsprogs Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 01/15] ext2fs: move calculate_summary_stats to ext2fs lib Harshad Shirwadkar
2021-01-21 15:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 02/15] e2fsck: add kernel endian-ness conversion macros Harshad Shirwadkar
2021-01-21 15:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 03/15] e2fsck: port fc changes from kernel's recovery.c to e2fsck Harshad Shirwadkar
2021-01-21 15:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 04/15] libext2fs: provide APIs to configure fast commit blocks Harshad Shirwadkar
2021-01-21 15:56   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 05/15] e2fsprogs: make userspace tools number of fast commits blocks aware Harshad Shirwadkar
2021-01-21 15:58   ` Theodore Ts'o
2021-01-20 21:26 ` Harshad Shirwadkar [this message]
2021-01-21  5:58   ` [PATCH v3 06/15] ext2fs: add new APIs needed for fast commits Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 07/15] e2fsck: add function to rewrite extent tree Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 08/15] e2fsck: add fast commit setup code Harshad Shirwadkar
2021-01-21 16:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 09/15] e2fsck: add fast commit scan pass Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 10/15] e2fsck: add fast commit replay skeleton Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 11/15] e2fsck: add fc replay for link, unlink, creat tags Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 12/15] e2fsck: add replay for add_range, del_range, and inode tags Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 13/15] debugfs: add fast commit support to logdump Harshad Shirwadkar
2021-01-21 16:49   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 14/15] tests: add fast commit recovery tests Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 15/15] ext4: fix tests to account for new dumpe2fs output Harshad Shirwadkar
2021-01-21 16:01   ` Theodore Ts'o
2021-01-21  5:22 ` [PATCH v3 00/15] Fast commit changes for e2fsprogs Theodore Ts'o

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=20210120212641.526556-7-user@harshads-520.kir.corp.google.com \
    --to=harshadshirwadkar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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.