Write super with bio functions

Write our super block from an allocated page with our bio functions
instead of relying on the old block cache layer which is going away.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2017-02-10 08:44:14 -08:00
parent 75b018a0e7
commit 92b10e8270
3 changed files with 26 additions and 10 deletions

View File

@@ -197,6 +197,17 @@ int scoutfs_bio_read(struct super_block *sb, struct page **pages,
return scoutfs_bio_wait_comp(sb, &comp);
}
int scoutfs_bio_write(struct super_block *sb, struct page **pages,
u64 blkno, unsigned int nr_blocks)
{
struct scoutfs_bio_completion comp;
scoutfs_bio_init_comp(&comp);
scoutfs_bio_submit_comp(sb, WRITE, pages, blkno, nr_blocks, &comp);
return scoutfs_bio_wait_comp(sb, &comp);
}
/* return pointer to the blk 4k block offset amongst the pages */
void *scoutfs_page_block_address(struct page **pages, unsigned int blk)
{

View File

@@ -35,6 +35,8 @@ int scoutfs_bio_wait_comp(struct super_block *sb,
int scoutfs_bio_read(struct super_block *sb, struct page **pages,
u64 blkno, unsigned int nr_blocks);
int scoutfs_bio_write(struct super_block *sb, struct page **pages,
u64 blkno, unsigned int nr_blocks);
void *scoutfs_page_block_address(struct page **pages, unsigned int blk);

View File

@@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/pagemap.h>
#include <linux/magic.h>
#include <linux/random.h>
#include <linux/statfs.h>
@@ -110,26 +111,28 @@ void scoutfs_advance_dirty_super(struct super_block *sb)
/*
* The caller is responsible for setting the super header's blkno
* and seq to something reasonable.
*
* XXX it'd be pretty easy to preallocate to avoid failure here.
*/
int scoutfs_write_dirty_super(struct super_block *sb)
{
struct scoutfs_sb_info *sbi = SCOUTFS_SB(sb);
struct scoutfs_super_block *super;
struct scoutfs_block *bl;
struct page *page;
int ret;
/* XXX prealloc? */
bl = scoutfs_block_dirty(sb, le64_to_cpu(sbi->super.hdr.blkno));
if (WARN_ON_ONCE(IS_ERR(bl)))
return PTR_ERR(bl);
super = scoutfs_block_data(bl);
page = alloc_page(GFP_KERNEL | __GFP_ZERO);
if (!page)
return -ENOMEM;
super = page_address(page);
memcpy(super, &sbi->super, sizeof(*super));
scoutfs_block_zero(bl, sizeof(*super));
scoutfs_block_set_crc(bl);
ret = scoutfs_block_write_sync(bl);
scoutfs_block_put(bl);
ret = scoutfs_bio_write(sb, &page, le64_to_cpu(super->hdr.blkno), 1);
WARN_ON_ONCE(ret);
__free_page(page);
return ret;
}