FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 03-17-2009, 06:07 PM
Alasdair G Kergon
 
Default check for completed exception after dropped lock

----- Forwarded message from Mikulas Patocka <mpatocka@redhat.com> -----

Date: Wed, 25 Feb 2009 12:58:10 -0500 (EST)
From: Mikulas Patocka <mpatocka@redhat.com>
Subject: [PATCH 2/3] check for completed exception after dropped lock
To: dm-devek@redhat.com
cc: Alasdair G Kergon <agk@redhat.com>

Move allocation of alloc_pending_exception to the caller.

It is uncommon and bug-prone to drop a lock in a function that is called with
the lock held, so this is moved up.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
drivers/md/dm-snap.c | 42 ++++++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 18 deletions(-)

Index: linux-2.6.29-rc6-devel/drivers/md/dm-snap.c
================================================== =================
--- linux-2.6.29-rc6-devel.orig/drivers/md/dm-snap.c 2009-02-25 18:26:10.000000000 +0100
+++ linux-2.6.29-rc6-devel/drivers/md/dm-snap.c 2009-02-25 18:30:30.000000000 +0100
@@ -992,23 +992,10 @@ lookup_pending_exception(struct dm_snaps
* this.
*/
static struct dm_snap_pending_exception *
-__find_pending_exception(struct dm_snapshot *s, struct bio *bio)
+__find_pending_exception(struct dm_snapshot *s,
+ struct dm_snap_pending_exception *pe, chunk_t chunk)
{
- struct dm_snap_pending_exception *pe, *pe2;
- chunk_t chunk = sector_to_chunk(s, bio->bi_sector);
-
- /*
- * Create a new pending exception, we don't want
- * to hold the lock while we do this.
- */
- up_write(&s->lock);
- pe = alloc_pending_exception(s);
- down_write(&s->lock);
-
- if (!s->valid) {
- free_pending_exception(pe);
- return NULL;
- }
+ struct dm_snap_pending_exception *pe2;

pe2 = lookup_pending_exception(s, chunk);
if (pe2) {
@@ -1083,7 +1070,17 @@ static int snapshot_map(struct dm_target
if (bio_rw(bio) == WRITE) {
pe = lookup_pending_exception(s, chunk);
if (!pe) {
- pe = __find_pending_exception(s, bio);
+ up_write(&s->lock);
+ pe = alloc_pending_exception(s);
+ down_write(&s->lock);
+
+ if (!s->valid) {
+ free_pending_exception(pe);
+ r = -EIO;
+ goto out_unlock;
+ }
+
+ pe = __find_pending_exception(s, pe, chunk);
if (!pe) {
__invalidate_snapshot(s, -ENOMEM);
r = -EIO;
@@ -1220,7 +1217,16 @@ static int __origin_write(struct list_he

pe = lookup_pending_exception(snap, chunk);
if (!pe) {
- pe = __find_pending_exception(snap, bio);
+ up_write(&snap->lock);
+ pe = alloc_pending_exception(snap);
+ down_write(&snap->lock);
+
+ if (!snap->valid) {
+ free_pending_exception(pe);
+ goto next_snapshot;
+ }
+
+ pe = __find_pending_exception(snap, pe, chunk);
if (!pe) {
__invalidate_snapshot(snap, -ENOMEM);
goto next_snapshot;

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 03-17-2009, 06:08 PM
Alasdair G Kergon
 
Default check for completed exception after dropped lock

----- Forwarded message from Mikulas Patocka <mpatocka@redhat.com> -----

Date: Wed, 25 Feb 2009 14:26:08 -0500 (EST)
From: Mikulas Patocka <mpatocka@redhat.com>
Subject: Re: [PATCH 2/3] check for completed exception after dropped lock
To: dm-devek@redhat.com
cc: Alasdair G Kergon <agk@redhat.com>

> - up_write(&s->lock);
> - pe = alloc_pending_exception(s);
> - down_write(&s->lock);

BTW. shouldn't this rw-semaphore be replaced with a mutex or normal
semaphore? It is never locked for read. (it used to be in locked for reads
in RHEL-4). Mutex has better performance than a rw-semaphore --- it takes
fewer cycles and it also guarantees first-in-first-out ordering.

Mikulas

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 07:29 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org