From patchwork Fri Jun 19 07:50:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kiyoshi Ueda X-Patchwork-Id: 31309 X-Patchwork-Delegate: agk@redhat.com Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5J7p4hI001061 for ; Fri, 19 Jun 2009 07:51:04 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 8240661A18B; Fri, 19 Jun 2009 03:51:04 -0400 (EDT) Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id n5J7p1fr021702 for ; Fri, 19 Jun 2009 03:51:02 -0400 Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with SMTP id n5J7p1rM004367; Fri, 19 Jun 2009 03:51:01 -0400 Received: from tyo202.gate.nec.co.jp (TYO202.gate.nec.co.jp [202.32.8.206]) by mx1.redhat.com (8.13.8/8.13.8) with SMTP id n5J7o1O8015792; Fri, 19 Jun 2009 03:50:02 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.160]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id n5J7o1eI023379; Fri, 19 Jun 2009 16:50:01 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id n5J7o1820334; Fri, 19 Jun 2009 16:50:01 +0900 (JST) Received: from mailsv.linux.bs1.fc.nec.co.jp (mailsv.linux.bs1.fc.nec.co.jp [10.34.125.2]) by mailsv3.nec.co.jp (8.13.8/8.13.4) with ESMTP id n5J7o0aj017329; Fri, 19 Jun 2009 16:50:00 +0900 (JST) Received: from elcondor.linux.bs1.fc.nec.co.jp (elcondor.linux.bs1.fc.nec.co.jp [10.34.125.195]) by mailsv.linux.bs1.fc.nec.co.jp (Postfix) with ESMTP id 8CCAEE482EB; Fri, 19 Jun 2009 16:50:00 +0900 (JST) Message-ID: <4A3B4328.6010609@ct.jp.nec.com> Date: Fri, 19 Jun 2009 16:50:00 +0900 From: Kiyoshi Ueda User-Agent: Thunderbird 2.0.0.21 (X11/20090320) MIME-Version: 1.0 To: Alasdair Kergon References: <4A3B40D4.1040905@ct.jp.nec.com> In-Reply-To: <4A3B40D4.1040905@ct.jp.nec.com> X-RedHat-Spam-Score: -0.761 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-Scanned-By: MIMEDefang 2.63 on 172.16.48.31 X-loop: dm-devel@redhat.com Cc: device-mapper development Subject: [dm-devel] [PATCH 2/4] dm core: clean up completion handling of clone bio X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com This patch cleans up completion handling of clone bio. struct bio has ->bi_destructor to complete itself, so use it for request-based dm, too. Since the destructor can be called before the request is fully cloned, the 'struct request *rq' of struct dm_rq_clone_bio_info has been replaced with 'struct dm_rq_target_io *tio' so that the destructor can find 'tio' safely (i.e. not via rq->end_io_data). Signed-off-by: Kiyoshi Ueda Signed-off-by: Jun'ichi Nomura Cc: Alasdair G Kergon --- drivers/md/dm.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: 2.6.31-rc/drivers/md/dm.c =================================================================== --- 2.6.31-rc.orig/drivers/md/dm.c +++ 2.6.31-rc/drivers/md/dm.c @@ -78,7 +78,7 @@ struct dm_rq_target_io { */ struct dm_rq_clone_bio_info { struct bio *orig; - struct request *rq; + struct dm_rq_target_io *tio; }; union map_info *dm_get_mapinfo(struct bio *bio) @@ -666,12 +666,10 @@ static void clone_endio(struct bio *bio, static void end_clone_bio(struct bio *clone, int error) { struct dm_rq_clone_bio_info *info = clone->bi_private; - struct dm_rq_target_io *tio = info->rq->end_io_data; + struct dm_rq_target_io *tio = info->tio; struct bio *bio = info->orig; unsigned int nr_bytes = info->orig->bi_size; - free_bio_info(tio->md, info); - clone->bi_private = tio->md->bs; bio_put(clone); if (tio->error) @@ -712,18 +710,13 @@ static void end_clone_bio(struct bio *cl blk_update_request(tio->orig, 0, nr_bytes); } -static void free_bio_clone(struct mapped_device *md, struct request *clone) +static void free_bio_clone(struct request *clone) { struct bio *bio; - struct dm_rq_clone_bio_info *info; while ((bio = clone->bio) != NULL) { clone->bio = bio->bi_next; - info = bio->bi_private; - free_bio_info(md, info); - - bio->bi_private = md->bs; bio_put(bio); } } @@ -761,13 +754,12 @@ static void dm_unprep_request(struct req { struct request *clone = rq->special; struct dm_rq_target_io *tio = clone->end_io_data; - struct mapped_device *md = tio->md; rq->special = NULL; rq->cmd_flags &= ~REQ_DONTPREP; - free_bio_clone(md, clone); - free_rq_tio(md, tio); + free_bio_clone(clone); + free_rq_tio(tio->md, tio); } /* @@ -1396,6 +1388,15 @@ void dm_dispatch_request(struct request } EXPORT_SYMBOL_GPL(dm_dispatch_request); +static void dm_rq_bio_destructor(struct bio *bio) +{ + struct dm_rq_clone_bio_info *info = bio->bi_private; + struct mapped_device *md = info->tio->md; + + free_bio_info(md, info); + bio_free(bio, md->bs); +} + static void copy_request_info(struct request *clone, struct request *rq) { clone->cpu = rq->cpu; @@ -1414,8 +1415,9 @@ static void copy_request_info(struct req } static int clone_request_bios(struct request *clone, struct request *rq, - struct mapped_device *md) + struct dm_rq_target_io *tio) { + struct mapped_device *md = tio->md; struct bio *bio, *clone_bio; struct dm_rq_clone_bio_info *info; @@ -1440,9 +1442,9 @@ static int clone_request_bios(struct req goto free_and_out; } - clone_bio->bi_destructor = dm_bio_destructor; + clone_bio->bi_destructor = dm_rq_bio_destructor; clone_bio->bi_end_io = end_clone_bio; - info->rq = clone; + info->tio = tio; info->orig = bio; clone_bio->bi_private = info; @@ -1456,7 +1458,7 @@ static int clone_request_bios(struct req return 0; free_and_out: - free_bio_clone(md, clone); + free_bio_clone(clone); return -ENOMEM; } @@ -1468,7 +1470,7 @@ static int setup_clone(struct request *c blk_rq_init(NULL, clone); - r = clone_request_bios(clone, rq, tio->md); + r = clone_request_bios(clone, rq, tio); if (r) return r;