2 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2006-2008 Red Hat GmbH
5 * This file is released under the GPL.
8 #include "dm-exception-store.h"
12 #include <linux/pagemap.h>
13 #include <linux/vmalloc.h>
14 #include <linux/slab.h>
15 #include <linux/dm-io.h>
17 #define DM_MSG_PREFIX "transient snapshot"
19 /*-----------------------------------------------------------------
20 * Implementation of the store for non-persistent snapshots.
21 *---------------------------------------------------------------*/
26 static void transient_destroy(struct dm_exception_store *store)
28 kfree(store->context);
31 static int transient_read_metadata(struct dm_exception_store *store)
36 static int transient_prepare(struct dm_exception_store *store,
37 struct dm_snap_exception *e)
39 struct transient_c *tc = (struct transient_c *) store->context;
40 sector_t size = get_dev_size(store->snap->cow->bdev);
42 if (size < (tc->next_free + store->snap->chunk_size))
45 e->new_chunk = sector_to_chunk(store->snap, tc->next_free);
46 tc->next_free += store->snap->chunk_size;
51 static void transient_commit(struct dm_exception_store *store,
52 struct dm_snap_exception *e,
53 void (*callback) (void *, int success),
54 void *callback_context)
57 callback(callback_context, 1);
60 static void transient_fraction_full(struct dm_exception_store *store,
61 sector_t *numerator, sector_t *denominator)
63 *numerator = ((struct transient_c *) store->context)->next_free;
64 *denominator = get_dev_size(store->snap->cow->bdev);
67 int dm_create_transient(struct dm_exception_store *store)
69 struct transient_c *tc;
71 store->destroy = transient_destroy;
72 store->read_metadata = transient_read_metadata;
73 store->prepare_exception = transient_prepare;
74 store->commit_exception = transient_commit;
75 store->drop_snapshot = NULL;
76 store->fraction_full = transient_fraction_full;
78 tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL);
88 int dm_transient_snapshot_init(void)
93 void dm_transient_snapshot_exit(void)