Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 38091
b: refs/heads/master
c: ba40a2a
h: refs/heads/master
i:
  38089: 50372a5
  38087: 6ea0a31
v: v3
  • Loading branch information
Alasdair G Kergon authored and Linus Torvalds committed Oct 3, 2006
1 parent 0524009 commit eb15ce7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 47 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 927ffe7c9a156e259aae31c07dd76072c459ec57
refs/heads/master: ba40a2aa6e6f3d084cf35c8b872fc9f18f91231f
72 changes: 26 additions & 46 deletions trunk/drivers/md/dm-snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
{
struct exception *e;
struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
int copy_needed = 0;
int r = 1;
chunk_t chunk;
struct pending_exception *pe = NULL;
Expand All @@ -866,29 +865,28 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
if (unlikely(bio_barrier(bio)))
return -EOPNOTSUPP;

/* FIXME: should only take write lock if we need
* to copy an exception */
down_write(&s->lock);

if (!s->valid) {
r = -EIO;
goto out_unlock;
}

/* If the block is already remapped - use that, else remap it */
e = lookup_exception(&s->complete, chunk);
if (e) {
remap_exception(s, e, bio);
goto out_unlock;
}

/*
* Write to snapshot - higher level takes care of RW/RO
* flags so we should only get this if we are
* writeable.
*/
if (bio_rw(bio) == WRITE) {

/* FIXME: should only take write lock if we need
* to copy an exception */
down_write(&s->lock);

if (!s->valid) {
r = -EIO;
goto out_unlock;
}

/* If the block is already remapped - use that, else remap it */
e = lookup_exception(&s->complete, chunk);
if (e) {
remap_exception(s, e, bio);
goto out_unlock;
}

pe = __find_pending_exception(s, bio);
if (!pe) {
__invalidate_snapshot(s, pe, -ENOMEM);
Expand All @@ -899,45 +897,27 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
remap_exception(s, &pe->e, bio);
bio_list_add(&pe->snapshot_bios, bio);

r = 0;

if (!pe->started) {
/* this is protected by snap->lock */
pe->started = 1;
copy_needed = 1;
}

r = 0;

out_unlock:
up_write(&s->lock);

if (copy_needed)
up_write(&s->lock);
start_copy(pe);
} else {
goto out;
}
} else
/*
* FIXME: this read path scares me because we
* always use the origin when we have a pending
* exception. However I can't think of a
* situation where this is wrong - ejt.
*/
bio->bi_bdev = s->origin->bdev;

/* Do reads */
down_read(&s->lock);

if (!s->valid) {
up_read(&s->lock);
return -EIO;
}

/* See if it it has been remapped */
e = lookup_exception(&s->complete, chunk);
if (e)
remap_exception(s, e, bio);
else
bio->bi_bdev = s->origin->bdev;

up_read(&s->lock);
}

out_unlock:
up_write(&s->lock);
out:
return r;
}

Expand Down

0 comments on commit eb15ce7

Please sign in to comment.