Add seq field to block map item

The file block mapping code needs to know if an existing block mapping
is dirty in the current transaction or not.  It was doing that by
calling in to the allocator.

Instead of calling in to the allocator we can instead store the seq of
the block in the mapping item.  We also probably want to know the seq of
data blocks to make it possible to discover regions of files that have
changed since a previous seq.

This does increase the size of the block mapping item but they're not
long for this world.  We're going to replace them with proper extent
items in the near future.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2016-10-14 18:06:58 -07:00
parent c8d1703196
commit 17ec4a1480
2 changed files with 8 additions and 14 deletions

View File

@@ -251,6 +251,7 @@ int scoutfs_truncate_block_items(struct super_block *sb, u64 ino, u64 size)
break;
bmap.blkno[i] = 0;
bmap.seq[i] = 0;
modified = true;
}
i = 0;
@@ -393,19 +394,11 @@ static int map_writable_block(struct inode *inode, u64 iblock, u64 *blkno_ret)
i = iblock & SCOUTFS_BLOCK_MAP_MASK;
old_blkno = le64_to_cpu(bmap.blkno[i]);
/*
* If the existing block was free in stable then its dirty in
* this trans and we can use it.
*/
if (old_blkno) {
ret = scoutfs_buddy_was_free(sb, old_blkno, 0);
if (ret < 0)
goto out;
if (ret > 0) {
*blkno_ret = old_blkno;
ret = 0;
goto out;
}
/* If the existing block is dirty then we can use it */
if (old_blkno && (bmap.seq[i] == super->hdr.seq)) {
*blkno_ret = old_blkno;
ret = 0;
goto out;
}
ret = alloc_file_block(sb, &new_blkno);
@@ -419,6 +412,7 @@ static int map_writable_block(struct inode *inode, u64 iblock, u64 *blkno_ret)
}
bmap.blkno[i] = cpu_to_le64(new_blkno);
bmap.seq[i] = super->hdr.seq;
/* dirtying guarantees success */
err = scoutfs_btree_update(sb, meta, &key, &val);

View File

@@ -302,8 +302,8 @@ struct scoutfs_xattr {
#define SCOUTFS_BLOCK_MAP_MASK (SCOUTFS_BLOCK_MAP_COUNT - 1)
struct scoutfs_block_map {
__le32 crc[SCOUTFS_BLOCK_MAP_COUNT];
__le64 blkno[SCOUTFS_BLOCK_MAP_COUNT];
__le64 seq[SCOUTFS_BLOCK_MAP_COUNT];
};
/*