Break up the snapshot constructor and destructor functions to
isolate the portions that allocate and initialize the dm_snapshot
structure. This structure will become the bulk of what is shared
as we move to a snapshot model that is tolerant of shared exception
stores. This will help us minimize code change as we add the new
sharing structures to the constructor/destructor procedure.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
- s->pending = dm_exception_table_create(hash_size, 0,
- alloc_pending_exception, s,
- free_pending_exception, NULL);
- if (!s->pending) {
- ti->error = "Unable to allocate hash table space";
+ /*
+ * Allocate the snapshot
+ */
+ s = alloc_snapshot(hash_size);
+ if (!s) {
r = -ENOMEM;
- goto bad_hash_table;
- }
-
- r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client);
- if (r) {
- ti->error = "Could not create kcopyd client";
- goto bad_kcopyd;
- }
-
- s->pending_pool = mempool_create_slab_pool(MIN_IOS, pending_cache);
- if (!s->pending_pool) {
- ti->error = "Could not allocate mempool for pending exceptions";
- goto bad_pending_pool;
- }
-
- s->tracked_chunk_pool = mempool_create_slab_pool(MIN_IOS,
- tracked_chunk_cache);
- if (!s->tracked_chunk_pool) {
- ti->error = "Could not allocate tracked_chunk mempool for "
- "tracking reads";
- goto bad_tracked_chunk_pool;
+ ti->error = "Failed to create snapshot structure";
+ goto bad_alloc_snapshot;
}
- for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
- INIT_HLIST_HEAD(&s->tracked_chunk_hash[i]);
-
- spin_lock_init(&s->tracked_chunk_lock);
- bio_list_init(&s->queued_bios);
- INIT_WORK(&s->queued_bios_work, flush_queued_bios);
+ s->origin = origin;
+ s->store = store;
/* Add snapshot to the list of snapshots for this origin */
/* Exceptions aren't triggered till snapshot_resume() is called */
if (register_snapshot(s)) {
r = -EINVAL;
- ti->error = "Cannot register snapshot origin";
+ ti->error = "Cannot register snapshot with origin";
goto bad_load_and_register;
}
@@ -555,24 +604,12 @@ static int snapshot_ctr(struct dm_target
return 0;
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
03-25-2009, 08:38 PM
Jonathan Brassow
DM Snapshot: split ctr and dtr
Patch name: dm-snap-split-ctr-and-dtr.patch
Break up the snapshot constructor and destructor functions to
isolate the portions that allocate and initialize the dm_snapshot
structure. This structure will become the bulk of what is shared
as we move to a snapshot model that is tolerant of shared exception
stores. This will help us minimize code change as we add the new
sharing structures to the constructor/destructor procedure.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
- s->pending = dm_exception_table_create(hash_size, 0,
- alloc_pending_exception, s,
- free_pending_exception, NULL);
- if (!s->pending) {
- ti->error = "Unable to allocate hash table space";
+ /*
+ * Allocate the snapshot
+ */
+ s = alloc_snapshot(hash_size);
+ if (!s) {
r = -ENOMEM;
- goto bad_hash_table;
- }
-
- r = dm_kcopyd_client_create(SNAPSHOT_PAGES, &s->kcopyd_client);
- if (r) {
- ti->error = "Could not create kcopyd client";
- goto bad_kcopyd;
- }
-
- s->pending_pool = mempool_create_slab_pool(MIN_IOS, pending_cache);
- if (!s->pending_pool) {
- ti->error = "Could not allocate mempool for pending exceptions";
- goto bad_pending_pool;
- }
-
- s->tracked_chunk_pool = mempool_create_slab_pool(MIN_IOS,
- tracked_chunk_cache);
- if (!s->tracked_chunk_pool) {
- ti->error = "Could not allocate tracked_chunk mempool for "
- "tracking reads";
- goto bad_tracked_chunk_pool;
+ ti->error = "Failed to create snapshot structure";
+ goto bad_alloc_snapshot;
}
- for (i = 0; i < DM_TRACKED_CHUNK_HASH_SIZE; i++)
- INIT_HLIST_HEAD(&s->tracked_chunk_hash[i]);
-
- spin_lock_init(&s->tracked_chunk_lock);
- bio_list_init(&s->queued_bios);
- INIT_WORK(&s->queued_bios_work, flush_queued_bios);
+ s->origin = origin;
+ s->store = store;
/* Add snapshot to the list of snapshots for this origin */
/* Exceptions aren't triggered till snapshot_resume() is called */
if (register_snapshot(s)) {
r = -EINVAL;
- ti->error = "Cannot register snapshot origin";
+ ti->error = "Cannot register snapshot with origin";
goto bad_load_and_register;
}
@@ -555,24 +604,12 @@ static int snapshot_ctr(struct dm_target
return 0;