linux内核源码阅读之facebook硬盘加速flashcache之四
1581/*
1582 * Decide the mapping and perform necessary cache operations for a bio request.
1583 */
1584int
1585flashcache_map(struct dm_target *ti, struct bio *bio,
1586 union map_info *map_context)
1587{
1588 struct cache_c *dmc = (struct cache_c *) ti->private;
1589 int sectors = to_sector(bio->bi_size);
1590 int queued;
1591
1592 if (sectors <= 32)
1593 size_hist[sectors]++;
1594
1595 if (bio_barrier(bio))
1596 return -EOPNOTSUPP;
1597
1598 VERIFY(to_sector(bio->bi_size) <= dmc->block_size);
1599
1600 if (bio_data_dir(bio) == READ)
1601 dmc->reads++;
1602 else
1603 dmc->writes++;
1604
1605 spin_lock_irq(&dmc->cache_spin_lock);
1606 if (unlikely(sysctl_pid_do_expiry &&
1607 (dmc->whitelist_head || dmc->blacklist_head)))
1608 flashcache_pid_expiry_all_locked(dmc);
1609 if ((to_sector(bio->bi_size) != dmc->block_size) ||
1610 (bio_data_dir(bio) == WRITE && flashcache_uncacheable(dmc))) {
1611 queued = flashcache_inval_blocks(dmc, bio);
1612 spin_unlock_irq(&dmc->cache_spin_lock);
1613 if (queued) {
1614 if (unlikely(queued < 0))
1615 flashcache_bio_endio(bio, -EIO);
1616 } else {
1617 /* Start uncached IO */
1618 flashcache_start_uncached_io(dmc, bio);
1619 }
1620 } else {
1621 spin_unlock_irq(&dmc->cache_spin_lock);
1622 if (bio_data_dir(bio) == READ)
1623 flashcache_read(dmc, bio);
1624 else
1625 flashcache_write(dmc, bio);
1626 }
1627 return DM_MAPIO_SUBMITTED;
1628}
1350 ti->split_io = dmc->block_size;
1351 ti->private = dmc;
571int
572flashcache_dm_io_sync_vm(struct cache_c *dmc, struct dm_io_region *where, int rw, void *data)
573{
574 unsigned long error_bits = 0;
575 int error;
576 struct dm_io_request io_req = {
577 .bi_rw = rw,
578 .mem.type = DM_IO_VMA,
579 .mem.ptr.vma = data,
580 .mem.offset = 0,
581 .notify.fn = NULL,
582 .client = dmc->io_client,
583 };
584
585 error = dm_io(&io_req, 1, where, &error_bits);
586 if (error)
587 return error;
588 if (error_bits)
589 return error_bits;
590 return 0;
591}
720 header = (struct flash_superblock *)vmalloc(512);
721 if (!header) {
722 DMERR("flashcache_md_create: Unable to allocate sector");
723 return 1;
724 }
725 where.bdev = dmc->cache_dev->bdev;
726 where.sector = 0;
727 where.count = 1;
728#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
729 error = flashcache_dm_io_sync_vm(&where, READ, header);
730#else
731 error = flashcache_dm_io_sync_vm(dmc, &where, READ, header);
732#endif
unsigned num_dests, struct dm_io_region *dests,
unsigned flags, dm_kcopyd_notify_fn fn, void *context);
1208 r = dm_kcopyd_client_create(FLASHCACHE_COPY_PAGES, &dmc->kcp_client);
1209 if (r) {
1210 ti->error = "Failed to initialize kcopyd client\n";
1211 dm_io_client_destroy(dmc->io_client);
1212 goto bad3;
1213 }
struct block_device *bdev;
sector_t sector;
sector_t count; /* If this is zero the region is ignored. */
};
linux内核源码阅读之facebook硬盘加速flashcache之四的更多相关文章
- linux内核源码阅读之facebook硬盘加速flashcache之八
		
前面我们的分析中重点关注正常的数据流程,这一小节关注如果有异常,那么流程是怎么走完的呢? 1)创建新任务时kcached_job申请不到 2)读写命中时cache块为忙 3)系统关机时处理,系统开机时 ...
 - linux内核源码阅读之facebook硬盘加速flashcache之三
		
上一节讲到在刷缓存的时候会调用new_kcahed_job创建kcached_job,由此我们也可以看到cache数据块与磁盘数据的对应关系.上一篇:http://blog.csdn.net/lium ...
 - linux内核源码阅读之facebook硬盘加速flashcache之二
		
flashcache数据结构都在flashcache.h文件中,但在看数据结构之前,需要先过一遍flashcache是什么,要完成哪些功能?如果是自己设计这样一个系统的话,大概要怎么设计. 前面讲过, ...
 - linux内核源码阅读之facebook硬盘加速flashcache之六
		
其实到目前为止,如果对读流程已经能轻松地看懂了,那么写流程不需要太多脑细胞.我觉得再写下去没有太大的必要了,后面想想为了保持flashcache完整性,还是写出来吧.接着到写流程: 1530stati ...
 - linux内核源码阅读之facebook硬盘加速flashcache之五
		
正常流程到flashcache_map的1623行或1625行,按顺序先看读流程: 1221static void 1222flashcache_read(struct cache_c *dmc, s ...
 - linux内核源码阅读之facebook硬盘加速利器flashcache
		
从来没有写过源码阅读,这种感觉越来越强烈,虽然劣于文笔,但还是下定决心认真写一回. 源代码下载请参见上一篇flashcache之我见 http://blog.csdn.net/liumangxiong ...
 - ubuntu下linux内核源码阅读工具和调试方法总结
		
http://blog.chinaunix.net/uid-20940095-id-66148.html 一 linux内核源码阅读工具 windows下当然首选source insight, 但是l ...
 - Linux内核源码阅读记录一之分析存储在不同段中的函数调用过程
		
在写驱动的过程中,对于入口函数与出口函数我们会用一句话来修饰他们:module_init与module_exit,那会什么经过修饰后,内核就能狗调用我们编写的入口函数与出口函数呢?下面就来分析内核调用 ...
 - Linux内核源码分析
		
Linux源码下载: https://www.kernel.org/ https://git.kernel.org/ Linux内核源码阅读以及工具(转): https://blog.csdn.net ...
 
随机推荐
- 关于yii2的gridview关联搜索步骤
			
在使用yii2构建搜索视图,经常都会使用到gridview这个组件,这个组件十分强大,通过一定的配置就能进行关联搜索,下面就是简单的步骤 需求场景:一个车系表,里面存放在品牌表的id,现在要用品牌名字 ...
 - Makefile写法
			
概述 -- 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员,makef ...
 - TCPL 行计数
			
C programming language: P13 行计数 e.g. #include <stdio.h>int main(void){ int c, nb, nt, nl; ...
 - vim note
			
2016-1-22 vim plugin collections: (参考 https://www.youtube.com/watch?v=0QFR-_wUoA0) vim-pathogen 插件管 ...
 - Linux 分区初始化为物理卷,把物理卷加入卷组
			
用到的命令有 1.pvcreate (physical volume create) 2.vgcreate (volume group create) 例子1:创建物理卷 pvcreate /dev/ ...
 - LBYL与EAFP两种防御性编程风格
			
检查数据可以让程序更健壮,用术语来说就是防御性编程. 检查数据的时候,有这样的两种不同的风格. LBYL:Look Before You Leap EAFP:It's Easier to Ask ...
 - word-wrap,white-space和text-overflow属性
			
(1) //在断点处换行 word-wrap: normal; //允许在长单词进行换行 word-wrap: break-word; (2) white-space:怎么处理元素间的空白 white ...
 - Android 教你打造炫酷的ViewPagerIndicator 不仅仅是高仿MIUI
			
1.概述 哈,今天给大家带来一个ViewPagerIndicator的制作,相信大家在做tabIndicator的时候,大多数人都用过 TabPageIndicator,并且很多知名APP都使用过这个 ...
 - 关于html5之canvas的那些事
			
何为canvas <canvas> 标签只是图形容器,您必须使用脚本来绘制图形.默认情况下该矩形区域宽为300像素,高为150像素,设置宽高必须在canvas标签内部,不能加单位px. 大 ...
 - cocos2d-x学习日志(12) --弹出对话框的设计与实现
			
我们时常需要这么些功能,弹出一个层,给与用户一些提示,这也是一种模态窗口,在没有对当前对话框进行确认的时候,不能继续往下操作. 功能分析 我们设计一个对话框,对话框上有几个按钮(个数可定制),当然有个 ...