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-rc5-devel/drivers/md/dm-exception-store.c =================================================================== --- linux-2.6.26-rc5-devel.orig/drivers/md/dm-exception-store.c 2008-06-16 22:02:08.000000000 +0200 +++ linux-2.6.26-rc5-devel/drivers/md/dm-exception-store.c 2008-06-16 22:02:20.000000000 +0200 @@ -454,7 +454,7 @@ 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); @@ -511,9 +511,11 @@ /* * Read the metadata. */ - r = read_exceptions(ps); - if (r) - return r; + if (!will_handover) { + r = read_exceptions(ps); + if (r) + return r; + } } return 0; @@ -666,7 +668,7 @@ 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-rc5-devel/drivers/md/dm-snap.c =================================================================== --- linux-2.6.26-rc5-devel.orig/drivers/md/dm-snap.c 2008-06-16 22:02:15.000000000 +0200 +++ linux-2.6.26-rc5-devel/drivers/md/dm-snap.c 2008-06-16 22:02:20.000000000 +0200 @@ -644,7 +644,7 @@ 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 bad8; Index: linux-2.6.26-rc5-devel/drivers/md/dm-snap.h =================================================================== --- linux-2.6.26-rc5-devel.orig/drivers/md/dm-snap.h 2008-06-16 22:02:15.000000000 +0200 +++ linux-2.6.26-rc5-devel/drivers/md/dm-snap.h 2008-06-16 22:02:20.000000000 +0200 @@ -108,8 +108,12 @@ /* * 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.