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
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 }