cregit-Linux how code gets into the kernel

Release 4.7 fs/logfs/dev_bdev.c

Directory: fs/logfs
/*
 * fs/logfs/dev_bdev.c  - Device access methods for block devices
 *
 * As should be obvious for Linux kernel code, license is GPLv2
 *
 * Copyright (c) 2005-2008 Joern Engel <joern@logfs.org>
 */
#include "logfs.h"
#include <linux/bio.h>
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/gfp.h>
#include <linux/prefetch.h>


#define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1))


static int sync_request(struct page *page, struct block_device *bdev, int rw) { struct bio bio; struct bio_vec bio_vec; bio_init(&bio); bio.bi_max_vecs = 1; bio.bi_io_vec = &bio_vec; bio_vec.bv_page = page; bio_vec.bv_len = PAGE_SIZE; bio_vec.bv_offset = 0; bio.bi_vcnt = 1; bio.bi_bdev = bdev; bio.bi_iter.bi_sector = page->index * (PAGE_SIZE >> 9); bio.bi_iter.bi_size = PAGE_SIZE; return submit_bio_wait(rw, &bio); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel9183.49%125.00%
kent overstreetkent overstreet1211.01%250.00%
prasad joshiprasad joshi65.50%125.00%
Total109100.00%4100.00%


static int bdev_readpage(void *_sb, struct page *page) { struct super_block *sb = _sb; struct block_device *bdev = logfs_super(sb)->s_bdev; int err; err = sync_request(page, bdev, READ); if (err) { ClearPageUptodate(page); SetPageError(page); } else { SetPageUptodate(page); ClearPageError(page); } unlock_page(page); return err; }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel85100.00%1100.00%
Total85100.00%1100.00%

static DECLARE_WAIT_QUEUE_HEAD(wq);
static void writeseg_end_io(struct bio *bio) { struct bio_vec *bvec; int i; struct super_block *sb = bio->bi_private; struct logfs_super *super = logfs_super(sb); BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */ bio_for_each_segment_all(bvec, bio, i) { end_page_writeback(bvec->bv_page); put_page(bvec->bv_page); } bio_put(bio); if (atomic_dec_and_test(&super->s_pending_writes)) wake_up(&wq); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel7481.32%240.00%
kent overstreetkent overstreet1314.29%120.00%
christoph hellwigchristoph hellwig33.30%120.00%
kirill a. shutemovkirill a. shutemov11.10%120.00%
Total91100.00%5100.00%


static int __bdev_writeseg(struct super_block *sb, u64 ofs, pgoff_t index, size_t nr_pages) { struct logfs_super *super = logfs_super(sb); struct address_space *mapping = super->s_mapping_inode->i_mapping; struct bio *bio; struct page *page; unsigned int max_pages; int i; max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES); bio = bio_alloc(GFP_NOFS, max_pages); BUG_ON(!bio); for (i = 0; i < nr_pages; i++) { if (i >= max_pages) { /* Block layer cannot split bios :( */ bio->bi_vcnt = i; bio->bi_iter.bi_size = i * PAGE_SIZE; bio->bi_bdev = super->s_bdev; bio->bi_iter.bi_sector = ofs >> 9; bio->bi_private = sb; bio->bi_end_io = writeseg_end_io; atomic_inc(&super->s_pending_writes); submit_bio(WRITE, bio); ofs += i * PAGE_SIZE; index += i; nr_pages -= i; i = 0; bio = bio_alloc(GFP_NOFS, max_pages); BUG_ON(!bio); } page = find_lock_page(mapping, index + i); BUG_ON(!page); bio->bi_io_vec[i].bv_page = page; bio->bi_io_vec[i].bv_len = PAGE_SIZE; bio->bi_io_vec[i].bv_offset = 0; BUG_ON(PageWriteback(page)); set_page_writeback(page); unlock_page(page); } bio->bi_vcnt = nr_pages; bio->bi_iter.bi_size = nr_pages * PAGE_SIZE; bio->bi_bdev = super->s_bdev; bio->bi_iter.bi_sector = ofs >> 9; bio->bi_private = sb; bio->bi_end_io = writeseg_end_io; atomic_inc(&super->s_pending_writes); submit_bio(WRITE, bio); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel31895.21%233.33%
kent overstreetkent overstreet92.69%233.33%
prasad joshiprasad joshi41.20%116.67%
sudip mukherjeesudip mukherjee30.90%116.67%
Total334100.00%6100.00%


static void bdev_writeseg(struct super_block *sb, u64 ofs, size_t len) { struct logfs_super *super = logfs_super(sb); int head; BUG_ON(super->s_flags & LOGFS_SB_FLAG_RO); if (len == 0) { /* This can happen when the object fit perfectly into a * segment, the segment gets written per sync and subsequently * closed. */ return; } head = ofs & (PAGE_SIZE - 1); if (head) { ofs -= head; len += head; } len = PAGE_ALIGN(len); __bdev_writeseg(sb, ofs, ofs >> PAGE_SHIFT, len >> PAGE_SHIFT); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel95100.00%1100.00%
Total95100.00%1100.00%


static void erase_end_io(struct bio *bio) { struct super_block *sb = bio->bi_private; struct logfs_super *super = logfs_super(sb); BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */ BUG_ON(bio->bi_vcnt == 0); bio_put(bio); if (atomic_dec_and_test(&super->s_pending_writes)) wake_up(&wq); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel6595.59%266.67%
christoph hellwigchristoph hellwig34.41%133.33%
Total68100.00%3100.00%


static int do_erase(struct super_block *sb, u64 ofs, pgoff_t index, size_t nr_pages) { struct logfs_super *super = logfs_super(sb); struct bio *bio; unsigned int max_pages; int i; max_pages = min_t(size_t, nr_pages, BIO_MAX_PAGES); bio = bio_alloc(GFP_NOFS, max_pages); BUG_ON(!bio); for (i = 0; i < nr_pages; i++) { if (i >= max_pages) { /* Block layer cannot split bios :( */ bio->bi_vcnt = i; bio->bi_iter.bi_size = i * PAGE_SIZE; bio->bi_bdev = super->s_bdev; bio->bi_iter.bi_sector = ofs >> 9; bio->bi_private = sb; bio->bi_end_io = erase_end_io; atomic_inc(&super->s_pending_writes); submit_bio(WRITE, bio); ofs += i * PAGE_SIZE; index += i; nr_pages -= i; i = 0; bio = bio_alloc(GFP_NOFS, max_pages); BUG_ON(!bio); } bio->bi_io_vec[i].bv_page = super->s_erase_page; bio->bi_io_vec[i].bv_len = PAGE_SIZE; bio->bi_io_vec[i].bv_offset = 0; } bio->bi_vcnt = nr_pages; bio->bi_iter.bi_size = nr_pages * PAGE_SIZE; bio->bi_bdev = super->s_bdev; bio->bi_iter.bi_sector = ofs >> 9; bio->bi_private = sb; bio->bi_end_io = erase_end_io; atomic_inc(&super->s_pending_writes); submit_bio(WRITE, bio); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel26994.39%342.86%
kent overstreetkent overstreet93.16%228.57%
prasad joshiprasad joshi41.40%114.29%
sudip mukherjeesudip mukherjee31.05%114.29%
Total285100.00%7100.00%


static int bdev_erase(struct super_block *sb, loff_t to, size_t len, int ensure_write) { struct logfs_super *super = logfs_super(sb); BUG_ON(to & (PAGE_SIZE - 1)); BUG_ON(len & (PAGE_SIZE - 1)); if (super->s_flags & LOGFS_SB_FLAG_RO) return -EROFS; if (ensure_write) { /* * Object store doesn't care whether erases happen or not. * But for the journal they are required. Otherwise a scan * can find an old commit entry and assume it is the current * one, travelling back in time. */ do_erase(sb, to, to >> PAGE_SHIFT, len >> PAGE_SHIFT); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel89100.00%2100.00%
Total89100.00%2100.00%


static void bdev_sync(struct super_block *sb) { struct logfs_super *super = logfs_super(sb); wait_event(wq, atomic_read(&super->s_pending_writes) == 0); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel36100.00%1100.00%
Total36100.00%1100.00%


static struct page *bdev_find_first_sb(struct super_block *sb, u64 *ofs) { struct logfs_super *super = logfs_super(sb); struct address_space *mapping = super->s_mapping_inode->i_mapping; filler_t *filler = bdev_readpage; *ofs = 0; return read_cache_page(mapping, 0, filler, sb); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel61100.00%1100.00%
Total61100.00%1100.00%


static struct page *bdev_find_last_sb(struct super_block *sb, u64 *ofs) { struct logfs_super *super = logfs_super(sb); struct address_space *mapping = super->s_mapping_inode->i_mapping; filler_t *filler = bdev_readpage; u64 pos = (super->s_bdev->bd_inode->i_size & ~0xfffULL) - 0x1000; pgoff_t index = pos >> PAGE_SHIFT; *ofs = pos; return read_cache_page(mapping, index, filler, sb); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel86100.00%1100.00%
Total86100.00%1100.00%


static int bdev_write_sb(struct super_block *sb, struct page *page) { struct block_device *bdev = logfs_super(sb)->s_bdev; /* Nothing special to do for block devices. */ return sync_request(page, bdev, WRITE); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel39100.00%1100.00%
Total39100.00%1100.00%


static void bdev_put_device(struct logfs_super *s) { blkdev_put(s->s_bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel1875.00%133.33%
al viroal viro312.50%133.33%
tejun heotejun heo312.50%133.33%
Total24100.00%3100.00%


static int bdev_can_write_buf(struct super_block *sb, u64 ofs) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel17100.00%1100.00%
Total17100.00%1100.00%

static const struct logfs_device_ops bd_devops = { .find_first_sb = bdev_find_first_sb, .find_last_sb = bdev_find_last_sb, .write_sb = bdev_write_sb, .readpage = bdev_readpage, .writeseg = bdev_writeseg, .erase = bdev_erase, .can_write_buf = bdev_can_write_buf, .sync = bdev_sync, .put_device = bdev_put_device, };
int logfs_get_sb_bdev(struct logfs_super *p, struct file_system_type *type, const char *devname) { struct block_device *bdev; bdev = blkdev_get_by_path(devname, FMODE_READ|FMODE_WRITE|FMODE_EXCL, type); if (IS_ERR(bdev)) return PTR_ERR(bdev); if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { int mtdnr = MINOR(bdev->bd_dev); blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); return logfs_get_sb_mtd(p, mtdnr); } p->s_bdev = bdev; p->s_mtd = NULL; p->s_devops = &bd_devops; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel8471.79%116.67%
al viroal viro2723.08%350.00%
tejun heotejun heo65.13%233.33%
Total117100.00%6100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
joern engeljoern engel150692.91%522.73%
kent overstreetkent overstreet432.65%418.18%
al viroal viro301.85%418.18%
prasad joshiprasad joshi140.86%29.09%
tejun heotejun heo120.74%313.64%
sudip mukherjeesudip mukherjee60.37%14.55%
christoph hellwigchristoph hellwig60.37%14.55%
linus torvaldslinus torvalds30.19%14.55%
kirill a. shutemovkirill a. shutemov10.06%14.55%
Total1621100.00%22100.00%
Directory: fs/logfs
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}