From patchwork Mon Sep 24 22:34:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1500851 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork1.kernel.org (Postfix) with ESMTP id 100643FE80 for ; Mon, 24 Sep 2012 22:39:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8OMb5j6030520; Mon, 24 Sep 2012 18:37:05 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8OMZu73009260 for ; Mon, 24 Sep 2012 18:35:56 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8OMZpN1006342 for ; Mon, 24 Sep 2012 18:35:51 -0400 Received: from mail-pb0-f46.google.com (mail-pb0-f46.google.com [209.85.160.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8OMZVob029736 for ; Mon, 24 Sep 2012 18:35:50 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so7786705pbb.33 for ; Mon, 24 Sep 2012 15:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=a8Yue2ZUz4z5C2kqALwBdMY09N2I2+b/+qKlzxX36HA=; b=FCldwEh5dpjchQelt3WZ7iUpv535sdoIBSW1LBmdCOfonv/ndcFLs5BurS0WRKAsqc 5SguxMZHIm7Ng3ttTUfAAyLggoocdrZ3Wqgdf5g7LceIOt8r5I+QZDru4FnsM/MzEMXg ciN04M5KGSBkxlWePJJjqmaK5RD97YmDuyr9nClw5HDZ/atitaCLhMSIVY5fXs8YJDMr C9k4D35bux9xxC0PN57WDZsMaBLn2IFsGS2CXB8DIaxAmBHb5i7cDPUquAx6fvlOvoC0 qaTEWr9Ip2yCV+wRQAlx0M5yyC3NgV3hQ5BNidc+PjbyEpW05zTrWtQzSoFk3gF7HXfE 1cOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=a8Yue2ZUz4z5C2kqALwBdMY09N2I2+b/+qKlzxX36HA=; b=ehEUQscekSDT4foqTgKhI27td61EBORWv6VBgnkXT0egJDZ81oLvarK7q22YqfJiiP FhwsC9SECzPHZYRzwbFjTp6VSUdcj+oKkZADwbIZ1skdtnzrJw94eN/jjtAi3hmtV6eX fQdE+OQ1Xx+cJYqD4BLHtc6NKh/ex+yn/n1OAV8sRYvlZgUR2eMUB+BRTIaYtEkb6G6L EBjzSqyPFxRw0b99hlHdQ5Ey+nLr8GzvykBkF6eT2uiFUVSyAYghflWvCGNOPiZndB+y ajNebsBgmKknDkVXugJeEFT31fn5pljCen9FEVVHNkCGqOhmqJdnFKimEWMgKNC92uIg mtVQ== Received: by 10.68.203.195 with SMTP id ks3mr40446683pbc.79.1348526150163; Mon, 24 Sep 2012 15:35:50 -0700 (PDT) Received: by 10.68.203.195 with SMTP id ks3mr40446663pbc.79.1348526150073; Mon, 24 Sep 2012 15:35:50 -0700 (PDT) Received: from formenos.mtv.corp.google.com (formenos.mtv.corp.google.com [172.18.110.66]) by mx.google.com with ESMTPS id nu8sm133316pbc.45.2012.09.24.15.35.49 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 15:35:49 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Date: Mon, 24 Sep 2012 15:34:57 -0700 Message-Id: <1348526106-17074-18-git-send-email-koverstreet@google.com> In-Reply-To: <1348526106-17074-1-git-send-email-koverstreet@google.com> References: <1348526106-17074-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQkyIRfJ48lnGpPuT0+mYmjgkxTETLhvyGGSpf361gLFhvli38cupui/w496sQsMYw3xhjPco8v/n3g+3JqXq4AckYAbumESWI8jnM2KxRRmR7DqDLk3jHOIkWrAbcOiXDpRiLyaTMBPmvc5gudsD5NoJNhLD1v6wz9lpsO8ZqkpOM8fFaFTPlulONXLnlxsewjpHPEM X-RedHat-Spam-Score: -3.512 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: axboe@kernel.dk, Jiri Kosina , Kent Overstreet , tj@kernel.org, vgoyal@redhat.com Subject: [dm-devel] [PATCH v3 17/26] pktcdvd: use bio_copy_data() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Signed-off-by: Kent Overstreet CC: Jens Axboe CC: Jiri Kosina --- drivers/block/pktcdvd.c | 79 ++++++++----------------------------------------- 1 file changed, 12 insertions(+), 67 deletions(-) diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 2c27744..783c96c 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -948,31 +948,6 @@ static int pkt_set_segment_merging(struct pktcdvd_device *pd, struct request_que } /* - * Copy CD_FRAMESIZE bytes from src_bio into a destination page - */ -static void pkt_copy_bio_data(struct bio *src_bio, int seg, int offs, struct page *dst_page, int dst_offs) -{ - unsigned int copy_size = CD_FRAMESIZE; - - while (copy_size > 0) { - struct bio_vec *src_bvl = bio_iovec_idx(src_bio, seg); - void *vfrom = kmap_atomic(src_bvl->bv_page) + - src_bvl->bv_offset + offs; - void *vto = page_address(dst_page) + dst_offs; - int len = min_t(int, copy_size, src_bvl->bv_len - offs); - - BUG_ON(len < 0); - memcpy(vto, vfrom, len); - kunmap_atomic(vfrom); - - seg++; - offs = 0; - dst_offs += len; - copy_size -= len; - } -} - -/* * Copy all data for this packet to pkt->pages[], so that * a) The number of required segments for the write bio is minimized, which * is necessary for some scsi controllers. @@ -1325,55 +1300,35 @@ try_next_bio: */ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) { - struct bio *bio; int f; - int frames_write; struct bio_vec *bvec = pkt->w_bio->bi_io_vec; + bio_reset(pkt->w_bio); + pkt->w_bio->bi_sector = pkt->sector; + pkt->w_bio->bi_bdev = pd->bdev; + pkt->w_bio->bi_end_io = pkt_end_io_packet_write; + pkt->w_bio->bi_private = pkt; + + /* XXX: locking? */ for (f = 0; f < pkt->frames; f++) { bvec[f].bv_page = pkt->pages[(f * CD_FRAMESIZE) / PAGE_SIZE]; bvec[f].bv_offset = (f * CD_FRAMESIZE) % PAGE_SIZE; + if (!bio_add_page(pkt->w_bio, bvec[f].bv_page, CD_FRAMESIZE, bvec[f].bv_offset)) + BUG(); } + VPRINTK(DRIVER_NAME": vcnt=%d\n", pkt->w_bio->bi_vcnt); /* * Fill-in bvec with data from orig_bios. */ - frames_write = 0; spin_lock(&pkt->lock); - bio_list_for_each(bio, &pkt->orig_bios) { - int segment = bio->bi_idx; - int src_offs = 0; - int first_frame = (bio->bi_sector - pkt->sector) / (CD_FRAMESIZE >> 9); - int num_frames = bio->bi_size / CD_FRAMESIZE; - BUG_ON(first_frame < 0); - BUG_ON(first_frame + num_frames > pkt->frames); - for (f = first_frame; f < first_frame + num_frames; f++) { - struct bio_vec *src_bvl = bio_iovec_idx(bio, segment); - - while (src_offs >= src_bvl->bv_len) { - src_offs -= src_bvl->bv_len; - segment++; - BUG_ON(segment >= bio->bi_vcnt); - src_bvl = bio_iovec_idx(bio, segment); - } + bio_copy_data(pkt->w_bio, pkt->orig_bios.head); - if (src_bvl->bv_len - src_offs >= CD_FRAMESIZE) { - bvec[f].bv_page = src_bvl->bv_page; - bvec[f].bv_offset = src_bvl->bv_offset + src_offs; - } else { - pkt_copy_bio_data(bio, segment, src_offs, - bvec[f].bv_page, bvec[f].bv_offset); - } - src_offs += CD_FRAMESIZE; - frames_write++; - } - } pkt_set_state(pkt, PACKET_WRITE_WAIT_STATE); spin_unlock(&pkt->lock); VPRINTK("pkt_start_write: Writing %d frames for zone %llx\n", - frames_write, (unsigned long long)pkt->sector); - BUG_ON(frames_write != pkt->write_size); + pkt->write_size, (unsigned long long)pkt->sector); if (test_bit(PACKET_MERGE_SEGS, &pd->flags) || (pkt->write_size < pkt->frames)) { pkt_make_local_copy(pkt, bvec); @@ -1383,16 +1338,6 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) } /* Start the write request */ - bio_reset(pkt->w_bio); - pkt->w_bio->bi_sector = pkt->sector; - pkt->w_bio->bi_bdev = pd->bdev; - pkt->w_bio->bi_end_io = pkt_end_io_packet_write; - pkt->w_bio->bi_private = pkt; - for (f = 0; f < pkt->frames; f++) - if (!bio_add_page(pkt->w_bio, bvec[f].bv_page, CD_FRAMESIZE, bvec[f].bv_offset)) - BUG(); - VPRINTK(DRIVER_NAME": vcnt=%d\n", pkt->w_bio->bi_vcnt); - atomic_set(&pkt->io_wait, 1); pkt->w_bio->bi_rw = WRITE; pkt_queue_bio(pd, pkt->w_bio);