dm cache: move hook_info into common portion of per_bio_data structure
PATCH 1/2 dm cache: move hook_info into common portion of per_bio_data structure
Commit c9d28d5d ("dm cache: promotion optimisation for writes") incorrectly placed the 'hook_info' member in the writethrough-only portion of the per_bio_data structure.
Given that the overwrite optimization may be used for writeback the 'hook_info' member but be placed above the 'cache' member of the per_bio_data structure. Any members above 'cache' are available from both writeback and writethrough modes' per_bio_data structure.
--- drivers/md/dm-cache-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-cache-target.c +1 -1
@@ -283,6 +283,7 @@ struct per_bio_data { bool tick:1; unsigned req_nr:2;struct dm_deferred_entry *all_io_entry; +struct dm_hook_info hook_info;/* * writethrough fields. These MUST remain at the end of this
@@ -291,7 +292,6 @@ struct per_bio_data {*/ struct cache *cache;dm_cblock_t cblock; -struct dm_hook_info hook_info;struct dm_bio_details bio_details; };
Signature · 1 line
1.8.1.4
PATCH 2/2 dm cache: do not add migration to completed list before unhooking bio
When completing an overwrite bio ,in overwrite_endio(), the associated migration should not be added to the 'completed_migrations' until the bio's fields are restored with dm_unhook_bio().
Otherwise, do_worker() can race to process 'completed_migrations' before dm_unhook_bio() -- so the bio's bi_end_io is incorrect. This is unlikely to cause any problems given the current code but should be fixed on the basis of correctness.
Also, the cache's spinlock only needs to be held when manipulating the 'completed_migrations' list -- other changes don't need protection.
--- drivers/md/dm-cache-target.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/md/dm-cache-target.c +4 -2
@@ -1002,13 +1002,15 @@ static void overwrite_endio(struct bio *bio, int err)struct per_bio_data *pb =get_per_bio_data (bio, pb_data_size);unsigned long flags; +dm_unhook_bio (&pb->hook_info, bio); +if (err) mg->err = true; + mg->requeue_holder = false; +spin_lock_irqsave (&cache->lock, flags);list_add_tail (&mg->list, &cache->completed_migrations); -dm_unhook_bio (&pb->hook_info, bio); - mg->requeue_holder = false;spin_unlock_irqrestore (&cache->lock, flags);wake_worker (cache);
Signature · 1 line
1.8.1.4