Now that the exception store implementations are capable of
caching the exceptions on their own, we need a new function
added to the API to allow us to lookup the exceptions.
Adding 'lookup_exception' to the exception store API.
/*
+ * Look up an exception. For certain exception stores,
+ * this function /may/ block. The caller must specify whether
+ * they can tolerate this. If the function would block and the
+ * user specified can_block=0, -EWOULDBLK will be returned.
+ */
+ int (*lookup_exception) (struct dm_exception_store *store,
+ struct dm_exception **e,
+ chunk_t old, int can_block);
+
+ /*
* The snapshot is invalid, note this in the metadata.
*/
void (*drop_snapshot) (struct dm_exception_store *store);
Index: linux-2.6/drivers/md/dm-snap-persistent.c
================================================== =================
--- linux-2.6.orig/drivers/md/dm-snap-persistent.c
+++ linux-2.6/drivers/md/dm-snap-persistent.c
@@ -711,6 +711,17 @@ static void persistent_commit_exception(
ps->callback_count = 0;
}
@@ -1015,7 +1015,15 @@ static int snapshot_map(struct dm_target
}
/* If the block is already remapped - use that, else remap it */
- e = dm_lookup_exception(s->complete, chunk);
+ rtn = s->store->type->lookup_exception(s->store, &e, chunk, 0);
+ if (rtn) {
+ /*
+ * Could be -EWOULDBLOCK, but we don't handle that yet
+ * and there are currently no exception store
+ * implementations that would require us to.
+ */
+ BUG();
+ }
if (e) {
remap_exception(s, e, bio, chunk);
goto out_unlock;
@@ -1134,7 +1142,7 @@ static int snapshot_status(struct dm_tar
*---------------------------------------------------------------*/
static int __origin_write(struct list_head *snapshots, struct bio *bio)
{
- int r = DM_MAPIO_REMAPPED, first = 0;
+ int rtn, r = DM_MAPIO_REMAPPED, first = 0;
struct dm_snapshot *snap;
struct dm_exception *e;
struct dm_snap_pending_exception *pe, *next_pe, *primary_pe = NULL;
@@ -1168,7 +1176,16 @@ static int __origin_write(struct list_he
* ref_count is initialised to 1 so pending_complete()
* won't destroy the primary_pe while we're inside this loop.
*/
- e = dm_lookup_exception(snap->complete, chunk);
+ rtn = snap->store->type->lookup_exception(snap->store, &e,
+ chunk, 0);
+ if (rtn) {
+ /*
+ * Could be -EWOULDBLOCK, but we don't handle that yet
+ * and there are currently no exception store
+ * implementations that would require us to.
+ */
+ BUG();
+ }
if (e)
goto next_snapshot;
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
03-17-2009, 01:04 PM
Jonathan Brassow
dm-exception-store-add-lookup-to-API.patch
Now that the exception store implementations are capable of
caching the exceptions on their own, we need a new function
added to the API to allow us to lookup the exceptions.
Adding 'lookup_exception' to the exception store API.
/*
+ * Look up an exception. Common errors include:
+ * -ENOENT : exception not found
+ * -EWOULDBLOCK: blocking op required and can_block=0
+ *
+ * If 'new_chunk' is NULL, the caller simply wants to
+ * know if the exception exists (0) or not (-ENOENT).
+ */
+ int (*lookup_exception) (struct dm_exception_store *store,
+ chunk_t old, chunk_t *new_chunk,
+ int can_block);
+
+ /*
* The snapshot is invalid, note this in the metadata.
*/
void (*drop_snapshot) (struct dm_exception_store *store);
Index: linux-2.6/drivers/md/dm-snap-persistent.c
================================================== =================
--- linux-2.6.orig/drivers/md/dm-snap-persistent.c
+++ linux-2.6/drivers/md/dm-snap-persistent.c
@@ -721,6 +721,23 @@ static void persistent_commit_exception(
ps->callback_count = 0;
}
/* If the block is already remapped - use that, else remap it */
- e = dm_lookup_exception(s->complete, chunk);
- if (e) {
- remap_exception(s, e, bio, chunk);
+ rtn = s->store->type->lookup_exception(s->store, chunk, &new_chunk, 0);
+ if (!rtn) {
+ remap_exception(s, bio, new_chunk);
goto out_unlock;
}
/*
+ * Could be -EWOULDBLOCK, but we don't handle that yet
+ * and there are currently no exception store
+ * implementations that would require us to.
+ */
+ BUG_ON(rtn != -ENOENT);
+
+ /*
* Write to snapshot - higher level takes care of RW/RO
* flags so we should only get this if we are
* writeable.
@@ -1035,7 +1037,7 @@ static int snapshot_map(struct dm_target
goto out_unlock;
}
r = DM_MAPIO_SUBMITTED;
@@ -1136,9 +1138,8 @@ static int snapshot_status(struct dm_tar
*---------------------------------------------------------------*/
static int __origin_write(struct list_head *snapshots, struct bio *bio)
{
- int r = DM_MAPIO_REMAPPED, first = 0;
+ int rtn, r = DM_MAPIO_REMAPPED, first = 0;
struct dm_snapshot *snap;
- struct dm_exception *e;
struct dm_snap_pending_exception *pe, *next_pe, *primary_pe = NULL;
chunk_t chunk;
LIST_HEAD(pe_queue);
@@ -1170,10 +1171,18 @@ static int __origin_write(struct list_he
* ref_count is initialised to 1 so pending_complete()
* won't destroy the primary_pe while we're inside this loop.
*/
- e = dm_lookup_exception(snap->complete, chunk);
- if (e)
+ rtn = snap->store->type->lookup_exception(snap->store, chunk,
+ NULL, 0);
+ if (!rtn)
goto next_snapshot;
+ /*
+ * Could be -EWOULDBLOCK, but we don't handle that yet
+ * and there are currently no exception store
+ * implementations that would require us to.
+ */
+ BUG_ON(rtn != -ENOENT);
+
pe = __find_pending_exception(snap, bio);
if (!pe) {
__invalidate_snapshot(snap, -ENOMEM);
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel