Lines Matching refs:mg
477 struct dm_cache_migration *mg;
479 mg = mempool_alloc(&cache->migration_pool, GFP_NOIO);
481 memset(mg, 0, sizeof(*mg));
483 mg->cache = cache;
486 return mg;
489 static void free_migration(struct dm_cache_migration *mg)
491 struct cache *cache = mg->cache;
496 mempool_free(mg, &cache->migration_pool);
1071 static void quiesce(struct dm_cache_migration *mg,
1074 init_continuation(&mg->k, continuation);
1075 dm_cell_quiesce_v2(mg->cache->prison, mg->cell, &mg->k.ws);
1087 struct dm_cache_migration *mg = container_of(context, struct dm_cache_migration, k);
1090 mg->k.input = BLK_STS_IOERR;
1092 queue_continuation(mg->cache->wq, &mg->k);
1095 static void copy(struct dm_cache_migration *mg, bool promote)
1098 struct cache *cache = mg->cache;
1101 o_region.sector = from_oblock(mg->op->oblock) * cache->sectors_per_block;
1105 c_region.sector = from_cblock(mg->op->cblock) * cache->sectors_per_block;
1109 dm_kcopyd_copy(cache->copier, &o_region, 1, &c_region, 0, copy_complete, &mg->k);
1111 dm_kcopyd_copy(cache->copier, &c_region, 1, &o_region, 0, copy_complete, &mg->k);
1125 struct dm_cache_migration *mg = bio->bi_private;
1126 struct cache *cache = mg->cache;
1132 mg->k.input = bio->bi_status;
1134 queue_continuation(cache->wq, &mg->k);
1137 static void overwrite(struct dm_cache_migration *mg,
1140 struct bio *bio = mg->overwrite_bio;
1143 dm_hook_bio(&pb->hook_info, bio, overwrite_endio, mg);
1149 if (mg->op->op == POLICY_PROMOTE)
1150 remap_to_cache(mg->cache, bio, mg->op->cblock);
1152 remap_to_origin(mg->cache, bio);
1154 init_continuation(&mg->k, continuation);
1155 accounted_request(mg->cache, bio);
1169 static void mg_complete(struct dm_cache_migration *mg, bool success)
1172 struct cache *cache = mg->cache;
1173 struct policy_work *op = mg->op;
1184 if (mg->overwrite_bio) {
1187 else if (mg->k.input)
1188 mg->overwrite_bio->bi_status = mg->k.input;
1190 mg->overwrite_bio->bi_status = BLK_STS_IOERR;
1191 bio_endio(mg->overwrite_bio);
1218 if (mg->cell) {
1219 if (dm_cell_unlock_v2(cache->prison, mg->cell, &bios))
1220 free_prison_cell(cache, mg->cell);
1223 free_migration(mg);
1232 struct dm_cache_migration *mg = ws_to_mg(ws);
1234 mg_complete(mg, mg->k.input == 0);
1240 struct dm_cache_migration *mg = ws_to_mg(ws);
1241 struct cache *cache = mg->cache;
1242 struct policy_work *op = mg->op;
1252 mg_complete(mg, false);
1255 mg_complete(mg, true);
1265 mg_complete(mg, false);
1288 init_continuation(&mg->k, mg_success);
1289 continue_after_commit(&cache->committer, &mg->k);
1294 mg_complete(mg, true);
1301 struct dm_cache_migration *mg = ws_to_mg(ws);
1306 if (mg->k.input)
1307 mg_complete(mg, false);
1315 struct dm_cache_migration *mg = ws_to_mg(ws);
1320 if (mg->k.input)
1321 mg_complete(mg, false);
1327 r = dm_cell_lock_promote_v2(mg->cache->prison, mg->cell,
1330 mg_complete(mg, false);
1333 quiesce(mg, mg_update_metadata);
1342 struct dm_cache_migration *mg = ws_to_mg(ws);
1343 struct cache *cache = mg->cache;
1344 struct policy_work *op = mg->op;
1353 init_continuation(&mg->k, mg_upgrade_lock);
1354 copy(mg, is_policy_promote);
1359 struct dm_cache_migration *mg = ws_to_mg(ws);
1361 if (mg->overwrite_bio) {
1367 if (!optimisable_bio(mg->cache, mg->overwrite_bio, mg->op->oblock)) {
1371 bool rb = bio_detain_shared(mg->cache, mg->op->oblock, mg->overwrite_bio);
1374 mg->overwrite_bio = NULL;
1375 inc_io_migrations(mg->cache);
1387 overwrite(mg, mg_update_metadata_after_copy);
1393 static int mg_lock_writes(struct dm_cache_migration *mg)
1397 struct cache *cache = mg->cache;
1407 build_key(mg->op->oblock, oblock_succ(mg->op->oblock), &key);
1409 mg->overwrite_bio ? READ_WRITE_LOCK_LEVEL : WRITE_LOCK_LEVEL,
1410 prealloc, &mg->cell);
1413 mg_complete(mg, false);
1417 if (mg->cell != prealloc)
1421 mg_copy(&mg->k.ws);
1423 quiesce(mg, mg_copy);
1430 struct dm_cache_migration *mg;
1437 mg = alloc_migration(cache);
1439 mg->op = op;
1440 mg->overwrite_bio = bio;
1445 return mg_lock_writes(mg);
1454 static void invalidate_complete(struct dm_cache_migration *mg, bool success)
1457 struct cache *cache = mg->cache;
1460 if (dm_cell_unlock_v2(cache->prison, mg->cell, &bios))
1461 free_prison_cell(cache, mg->cell);
1463 if (!success && mg->overwrite_bio)
1464 bio_io_error(mg->overwrite_bio);
1466 free_migration(mg);
1474 struct dm_cache_migration *mg = ws_to_mg(ws);
1476 invalidate_complete(mg, !mg->k.input);
1507 struct dm_cache_migration *mg = ws_to_mg(ws);
1508 struct cache *cache = mg->cache;
1510 r = invalidate_cblock(cache, mg->invalidate_cblock);
1512 invalidate_complete(mg, false);
1516 init_continuation(&mg->k, invalidate_completed);
1517 continue_after_commit(&cache->committer, &mg->k);
1518 remap_to_origin_clear_discard(cache, mg->overwrite_bio, mg->invalidate_oblock);
1519 mg->overwrite_bio = NULL;
1523 static int invalidate_lock(struct dm_cache_migration *mg)
1527 struct cache *cache = mg->cache;
1532 build_key(mg->invalidate_oblock, oblock_succ(mg->invalidate_oblock), &key);
1534 READ_WRITE_LOCK_LEVEL, prealloc, &mg->cell);
1537 invalidate_complete(mg, false);
1541 if (mg->cell != prealloc)
1545 quiesce(mg, invalidate_remove);
1552 init_continuation(&mg->k, invalidate_remove);
1553 queue_work(cache->wq, &mg->k.ws);
1562 struct dm_cache_migration *mg;
1567 mg = alloc_migration(cache);
1569 mg->overwrite_bio = bio;
1570 mg->invalidate_cblock = cblock;
1571 mg->invalidate_oblock = oblock;
1573 return invalidate_lock(mg);