scoutfs: add scoutfs_block_zero_from()

We already have a function that zeros the end of a block starting at a
given offset.  Some callers have a pointer to the byte to zero from so
let's add a convenience function that calculates the offset from the
pointer.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2016-09-28 13:42:27 -07:00
parent cf0199da00
commit f7f7a2e53f
2 changed files with 12 additions and 0 deletions

View File

@@ -476,6 +476,9 @@ void scoutfs_block_set_crc(struct buffer_head *bh)
hdr->crc = cpu_to_le32(scoutfs_crc_block(hdr));
}
/*
* Zero the block from the given byte to the end of the block.
*/
void scoutfs_block_zero(struct buffer_head *bh, size_t off)
{
if (WARN_ON_ONCE(off > SCOUTFS_BLOCK_SIZE))
@@ -485,6 +488,14 @@ void scoutfs_block_zero(struct buffer_head *bh, size_t off)
memset((char *)bh->b_data + off, 0, SCOUTFS_BLOCK_SIZE - off);
}
/*
* Zero the block from the given byte to the end of the block.
*/
void scoutfs_block_zero_from(struct buffer_head *bh, void *ptr)
{
return scoutfs_block_zero(bh, (char *)ptr - (char *)bh->b_data);
}
void scoutfs_block_set_lock_class(struct buffer_head *bh,
struct lock_class_key *class)
{

View File

@@ -18,6 +18,7 @@ int scoutfs_block_write_dirty(struct super_block *sb);
void scoutfs_block_set_crc(struct buffer_head *bh);
void scoutfs_block_zero(struct buffer_head *bh, size_t off);
void scoutfs_block_zero_from(struct buffer_head *bh, void *ptr);
void scoutfs_block_set_lock_class(struct buffer_head *bh,
struct lock_class_key *class);