public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: xfs@oss.sgi.com
Subject: [PATCH v6 12/18] xfs: helper to convert holemask to inode alloc. bitmap
Date: Mon,  2 Mar 2015 08:28:02 -0500	[thread overview]
Message-ID: <1425302888-4962-13-git-send-email-bfoster@redhat.com> (raw)
In-Reply-To: <1425302888-4962-1-git-send-email-bfoster@redhat.com>

The inobt record holemask field is a condensed data type designed to fit
into the existing on-disk record and is zero based (allocated regions
are set to 0, sparse regions are set to 1) to provide backwards
compatibility. This makes the type somewhat complex for use in higher
level inode manipulations such as individual inode allocation, etc.

Rather than foist the complexity of dealing with this field to every bit
of logic that requires inode granular information, create a helper to
convert the holemask to an inode allocation bitmap. The inode allocation
bitmap is inode granularity similar to the inobt record free mask and
indicates which inodes of the chunk are physically allocated on disk,
irrespective of whether the inode is considered allocated or free by the
filesystem.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/libxfs/xfs_ialloc_btree.c | 51 ++++++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_ialloc_btree.h |  3 +++
 2 files changed, 54 insertions(+)

diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c
index b95aac5..aa13b46 100644
--- a/fs/xfs/libxfs/xfs_ialloc_btree.c
+++ b/fs/xfs/libxfs/xfs_ialloc_btree.c
@@ -427,3 +427,54 @@ xfs_inobt_maxrecs(
 		return blocklen / sizeof(xfs_inobt_rec_t);
 	return blocklen / (sizeof(xfs_inobt_key_t) + sizeof(xfs_inobt_ptr_t));
 }
+
+/*
+ * Convert the inode record holemask to an inode allocation bitmap. The inode
+ * allocation bitmap is inode granularity and specifies whether an inode is
+ * physically allocated on disk (not whether the inode is considered allocated
+ * or free by the fs).
+ *
+ * A bit value of 1 means the inode is allocated, a value of 0 means it is free.
+ */
+uint64_t
+xfs_inobt_irec_to_allocmask(
+	struct xfs_inobt_rec_incore	*rec)
+{
+	uint64_t			bitmap = 0;
+	uint64_t			inodespbit;
+	int				nextbit;
+	uint				allocbitmap;
+
+	/*
+	 * The holemask has 16-bits for a 64 inode record. Therefore each
+	 * holemask bit represents multiple inodes. Create a mask of bits to set
+	 * in the allocmask for each holemask bit.
+	 */
+	inodespbit = (1 << XFS_INODES_PER_HOLEMASK_BIT) - 1;
+
+	/*
+	 * Allocated inodes are represented by 0 bits in holemask. Invert the 0
+	 * bits to 1 and convert to a uint so we can use xfs_next_bit(). Mask
+	 * anything beyond the 16 holemask bits since this casts to a larger
+	 * type.
+	 */
+	allocbitmap = ~rec->ir_holemask & ((1 << XFS_INOBT_HOLEMASK_BITS) - 1);
+
+	/*
+	 * allocbitmap is the inverted holemask so every set bit represents
+	 * allocated inodes. To expand from 16-bit holemask granularity to
+	 * 64-bit (e.g., bit-per-inode), set inodespbit bits in the target
+	 * bitmap for every holemask bit.
+	 */
+	nextbit = xfs_next_bit(&allocbitmap, 1, 0);
+	while (nextbit != -1) {
+		ASSERT(nextbit < (sizeof(rec->ir_holemask) * NBBY));
+
+		bitmap |= (inodespbit <<
+			   (nextbit * XFS_INODES_PER_HOLEMASK_BIT));
+
+		nextbit = xfs_next_bit(&allocbitmap, 1, nextbit + 1);
+	}
+
+	return bitmap;
+}
diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.h b/fs/xfs/libxfs/xfs_ialloc_btree.h
index d7ebea7..2c581ba 100644
--- a/fs/xfs/libxfs/xfs_ialloc_btree.h
+++ b/fs/xfs/libxfs/xfs_ialloc_btree.h
@@ -62,4 +62,7 @@ extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *,
 		xfs_btnum_t);
 extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int);
 
+/* ir_holemask to inode allocation bitmap conversion */
+uint64_t xfs_inobt_irec_to_allocmask(struct xfs_inobt_rec_incore *);
+
 #endif	/* __XFS_IALLOC_BTREE_H__ */
-- 
1.9.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2015-03-02 13:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 13:27 [PATCH v6 00/18] xfs: sparse inode chunks Brian Foster
2015-03-02 13:27 ` [PATCH v6 01/18] xfs: create individual inode alloc. helper Brian Foster
2015-03-02 13:27 ` [PATCH v6 02/18] xfs: update free inode record logic to support sparse inode records Brian Foster
2015-03-02 13:27 ` [PATCH v6 03/18] xfs: support min/max agbno args in block allocator Brian Foster
2015-03-02 13:27 ` [PATCH v6 04/18] xfs: add sparse inode chunk alignment superblock field Brian Foster
2015-03-02 13:27 ` [PATCH v6 05/18] xfs: use sparse chunk alignment for min. inode allocation requirement Brian Foster
2015-03-02 13:27 ` [PATCH v6 06/18] xfs: sparse inode chunks feature helpers and mount requirements Brian Foster
2015-03-02 13:27 ` [PATCH v6 07/18] xfs: add fs geometry bit for sparse inode chunks Brian Foster
2015-03-02 13:27 ` [PATCH v6 08/18] xfs: introduce inode record hole mask " Brian Foster
2015-03-02 13:27 ` [PATCH v6 09/18] xfs: use actual inode count for sparse records in bulkstat/inumbers Brian Foster
2015-03-02 13:28 ` [PATCH v6 10/18] xfs: pass inode count through ordered icreate log item Brian Foster
2015-03-02 13:28 ` [PATCH v6 11/18] xfs: handle sparse inode chunks in icreate log recovery Brian Foster
2015-03-02 13:28 ` Brian Foster [this message]
2015-03-02 13:28 ` [PATCH v6 13/18] xfs: allocate sparse inode chunks on full chunk allocation failure Brian Foster
2015-03-02 13:28 ` [PATCH v6 14/18] xfs: randomly do sparse inode allocations in DEBUG mode Brian Foster
2015-03-02 13:28 ` [PATCH v6 15/18] xfs: filter out sparse regions from individual inode allocation Brian Foster
2015-03-02 13:28 ` [PATCH v6 16/18] xfs: only free allocated regions of inode chunks Brian Foster
2015-03-02 13:28 ` [PATCH v6 17/18] xfs: skip unallocated regions of inode chunks in xfs_ifree_cluster() Brian Foster
2015-03-02 13:28 ` [PATCH v6 18/18] xfs: enable sparse inode chunks for v5 superblocks Brian Foster
2015-05-06 14:19 ` [PATCH v6 00/18] xfs: sparse inode chunks Brian Foster
2015-05-06 22:09   ` Dave Chinner

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=1425302888-4962-13-git-send-email-bfoster@redhat.com \
    --to=bfoster@redhat.com \
    --cc=xfs@oss.sgi.com \
    /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