[PATCH 19/20] Add file data and debugfs read/write commands
Zach Brown
zab at zabbo.net
Wed Jun 18 15:43:38 PDT 2025
On Thu, Jun 12, 2025 at 10:11:11PM +0200, Valerie Aurora wrote:
> Implement ngnfs_data_read() and ngnfs_data_write() and corresponding
> debugfs commands. Also copy over const_ilog2() and related functions
> from the kernel.
> +/*
> + * Calculate the index of the block reference for this logical block
> + * within an indirect block at this level (1 = pointers to data blocks).
> + */
> +static u32 calc_ref_ind(u64 dblk, int level)
> +{
> + u32 ind;
> + int i;
> +
> + BUG_ON(level < 1);
> +
> + for (i = 1; i < level; i++)
> + dblk >>= NGNFS_DATA_REFS_PER_BLK_SHIFT;
> +
> + ind = dblk & (NGNFS_DATA_REFS_PER_BLK - 1ULL);
All this can be a lot smaller with "(>> (shift * level)) & mask). I
tend to still use the SHIFT/SIZE/MASK convention from PAGE_SIZE, ancient
though that is.
> +/*
> + * Calculate the height of the tree (level of the root pointer) needed
> + * to index the logical block dblk in this file.
> + */
> +static u8 height_from_dblk(u64 dblk)
> +{
> + u8 height = 2;
> +
> + if (dblk == 0)
> + return 1;
> +
> + while (dblk >>= NGNFS_DATA_REFS_PER_BLK_SHIFT)
> + height++;
Similarly, this can use (ffs() / shift) with a bit of finesse.
- z
More information about the ngnfs-devel
mailing list