linux内核源码阅读之facebook硬盘加速flashcache之五
正常流程到flashcache_map的1623行或1625行,按顺序先看读流程:
113void 114flashcache_io_callback(unsigned long error, void *context)115{116 struct kcached_job *job = (struct kcached_job *) context;117 struct cache_c *dmc = job->dmc;118 struct bio *bio;119 unsigned long flags;120 int index = job->index;121 struct cacheblock *cacheblk = &dmc->cache[index];122123 VERIFY(index != -1); 124 bio = job->bio;125 VERIFY(bio != NULL);126 if (error)127 DMERR("flashcache_io_callback: io error %ld block %lu action %d", 128 error, job->disk.sector, job->action);129 job->error = error;130 switch (job->action) {131 case READDISK:132 DPRINTK("flashcache_io_callback: READDISK %d",133 index);134 spin_lock_irqsave(&dmc->cache_spin_lock, flags);135 if (unlikely(sysctl_flashcache_error_inject & READDISK_ERROR)) {136 job->error = error = -EIO;137 sysctl_flashcache_error_inject &= ~READDISK_ERROR;138 }139 VERIFY(cacheblk->cache_state & DISKREADINPROG);140 spin_unlock_irqrestore(&dmc->cache_spin_lock, flags);141 if (likely(error == 0)) {142 /* Kick off the write to the cache */143 job->action = READFILL;144 flashcache_enqueue_readfill(dmc, job);145 return;146 } else {147 dmc->disk_read_errors++; 148 flashcache_bio_endio(bio, error);149 }150 break; 174 case READFILL:175 DPRINTK("flashcache_io_callback: READFILL %d",176 index);177 spin_lock_irqsave(&dmc->cache_spin_lock, flags);178 if (unlikely(sysctl_flashcache_error_inject & READFILL_ERROR)) {179 job->error = error = -EIO;180 sysctl_flashcache_error_inject &= ~READFILL_ERROR;181 }182 if (unlikely(error))183 dmc->ssd_write_errors++;184 VERIFY(cacheblk->cache_state & DISKREADINPROG);185 spin_unlock_irqrestore(&dmc->cache_spin_lock, flags);186 flashcache_bio_endio(bio, error);187 break;