Don't read metadata if we are going to do handover. This saves memory (without the patch, the exception store would consume twice more memory while doing handover). If the handover doesn't happen (due to user abusing dmsetup), the snapshot is marked as invalid. Signed-off-by: Mikulas Patocka --- drivers/md/dm-exception-store.c | 12 +++++++----- drivers/md/dm-snap.c | 2 +- drivers/md/dm-snap.h | 6 +++++- 3 files changed, 13 insertions(+), 7 deletions(-) Index: linux-2.6.26-fast/drivers/md/dm-exception-store.c =================================================================== --- linux-2.6.26-fast.orig/drivers/md/dm-exception-store.c 2008-07-23 23:01:00.000000000 +0200 +++ linux-2.6.26-fast/drivers/md/dm-exception-store.c 2008-07-23 23:01:06.000000000 +0200 @@ -493,7 +493,7 @@ static void persistent_destroy(struct ex kfree(ps); } -static int persistent_read_metadata(struct exception_store *store) +static int persistent_read_metadata(struct exception_store *store, int will_handover) { int r, uninitialized_var(new_snapshot); struct pstore *ps = get_info(store); @@ -551,9 +551,11 @@ static int persistent_read_metadata(stru /* * Read the metadata. */ - r = read_exceptions(ps); - if (r) - return r; + if (!will_handover) { + r = read_exceptions(ps); + if (r) + return r; + } } return 0; @@ -715,7 +717,7 @@ static void transient_destroy(struct exc kfree(store->context); } -static int transient_read_metadata(struct exception_store *store) +static int transient_read_metadata(struct exception_store *store, int will_handover) { return 0; } Index: linux-2.6.26-fast/drivers/md/dm-snap.c =================================================================== --- linux-2.6.26-fast.orig/drivers/md/dm-snap.c 2008-07-23 23:01:04.000000000 +0200 +++ linux-2.6.26-fast/drivers/md/dm-snap.c 2008-07-23 23:01:06.000000000 +0200 @@ -647,7 +647,7 @@ static int snapshot_ctr(struct dm_target up_read(&_origins_lock); /* Metadata must only be loaded into one table at once */ - r = s->store.read_metadata(&s->store); + r = s->store.read_metadata(&s->store, s->handover); if (r < 0) { ti->error = "Failed to read snapshot metadata"; goto bad_load_and_register; Index: linux-2.6.26-fast/drivers/md/dm-snap.h =================================================================== --- linux-2.6.26-fast.orig/drivers/md/dm-snap.h 2008-07-23 23:01:04.000000000 +0200 +++ linux-2.6.26-fast/drivers/md/dm-snap.h 2008-07-23 23:01:06.000000000 +0200 @@ -108,8 +108,12 @@ struct exception_store { /* * The target shouldn't read the COW device until this is * called. + * + * will_handover means that there is anothe snapshot active --- we have + * to setup chunk size but won't have to read any exceptions, because + * exceptions will be handed from the active snapshot. */ - int (*read_metadata) (struct exception_store *store); + int (*read_metadata) (struct exception_store *store, int will_handover); /* * Find somewhere to store the next exception.