This patch rearranges the pending_complete() code so that the functional changes in the track-snapshot-reads patch are clearer. By consolidating the several error paths with the non-error path, we can move error_snapshot_bios() and __flush_bios() inline to make things clearer. Index: linux-2.6.16.i686/drivers/md/dm-snap.c =================================================================== --- linux-2.6.16.i686.orig/drivers/md/dm-snap.c 2006-04-15 01:12:54.000000000 -0400 +++ linux-2.6.16.i686/drivers/md/dm-snap.c 2006-04-15 01:13:11.000000000 -0400 @@ -611,26 +611,6 @@ static void error_bios(struct bio *bio) } } -static inline void error_snapshot_bios(struct pending_exception *pe) -{ - error_bios(bio_list_get(&pe->snapshot_bios)); -} - -static struct bio *__flush_bios(struct pending_exception *pe) -{ - /* - * If this pe is involved in a write to the origin and - * it is the last sibling to complete then release - * the bios for the original write to the origin. - */ - - if (pe->primary_pe && - atomic_dec_and_test(&pe->primary_pe->sibling_count)) - return bio_list_get(&pe->primary_pe->origin_bios); - - return NULL; -} - static void __invalidate_snapshot(struct dm_snapshot *s, struct pending_exception *pe, int err) { @@ -659,15 +639,13 @@ static void pending_complete(struct pend struct pending_exception *primary_pe; struct dm_snapshot *s = pe->snap; struct bio *flush = NULL; + int error = 0; if (!success) { /* Read/write error - snapshot is unusable */ down_write(&s->lock); __invalidate_snapshot(s, pe, -EIO); - flush = __flush_bios(pe); - up_write(&s->lock); - - error_snapshot_bios(pe); + error = 1; goto out; } @@ -675,40 +653,44 @@ static void pending_complete(struct pend if (!e) { down_write(&s->lock); __invalidate_snapshot(s, pe, -ENOMEM); - flush = __flush_bios(pe); - up_write(&s->lock); - - error_snapshot_bios(pe); + error = 1; goto out; } *e = pe->e; - /* - * Add a proper exception, and remove the - * in-flight exception from the list. - */ down_write(&s->lock); if (!s->valid) { - flush = __flush_bios(pe); - up_write(&s->lock); - free_exception(e); - - error_snapshot_bios(pe); + error = 1; goto out; } + /* + * Add a proper exception, and remove the + * in-flight exception from the list. + */ insert_exception(&s->complete, e); remove_exception(&pe->e); - flush = __flush_bios(pe); + + out: + primary_pe = pe->primary_pe; + + /* + * If this pe is involved in a write to the origin and + * it is the last sibling to complete then release + * the bios for the original write to the origin. + */ + if (primary_pe && + atomic_dec_and_test(&primary_pe->sibling_count)) + flush = bio_list_get(&primary_pe->origin_bios); up_write(&s->lock); /* Submit any pending write bios */ - flush_bios(bio_list_get(&pe->snapshot_bios)); - - out: - primary_pe = pe->primary_pe; + if (!error) + flush_bios(bio_list_get(&pe->snapshot_bios)); + else + error_bios(bio_list_get(&pe->snapshot_bios)); /* * Free the pe if it's not linked to an origin write or if