From patchwork Tue Jul 15 19:40:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 4558261 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 49A5B9F295 for ; Tue, 15 Jul 2014 19:43:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 60C292017E for ; Tue, 15 Jul 2014 19:43:46 +0000 (UTC) Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mail.kernel.org (Postfix) with ESMTP id 78E2920123 for ; Tue, 15 Jul 2014 19:43:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6FJeVsX023582; Tue, 15 Jul 2014 15:40:31 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s6FJeUNY009150 for ; Tue, 15 Jul 2014 15:40:30 -0400 Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6FJeT6d032578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 15 Jul 2014 15:40:30 -0400 Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id s6FJeTkN023472; Tue, 15 Jul 2014 15:40:29 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id s6FJeT4B023468; Tue, 15 Jul 2014 15:40:29 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Tue, 15 Jul 2014 15:40:29 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: "Alasdair G. Kergon" , Mike Snitzer , Jonathan Brassow , Edward Thornber , "Martin K. Petersen" , Jens Axboe , Christoph Hellwig In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [dm-devel] [PATCH 9/15] dm: implement copy 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch implements basic copy support for device mapper core. Individual targets can enable copy support by setting ti->copy_supported. Device mapper device advertises copy support if at least one target supports copy and for this target, at least one underlying device supports copy. Signed-off-by: Mikulas Patocka --- drivers/md/dm-table.c | 9 +++++++++ drivers/md/dm.c | 42 +++++++++++++++++++++++++++++++++++++++--- include/linux/device-mapper.h | 5 +++++ 3 files changed, 53 insertions(+), 3 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: linux-3.16-rc5/drivers/md/dm.c =================================================================== --- linux-3.16-rc5.orig/drivers/md/dm.c 2014-07-14 16:26:24.000000000 +0200 +++ linux-3.16-rc5/drivers/md/dm.c 2014-07-14 16:41:15.000000000 +0200 @@ -1403,6 +1403,31 @@ static int __send_write_same(struct clon return __send_changing_extent_only(ci, get_num_write_same_bios, NULL); } +static int __send_copy(struct clone_info *ci) +{ + struct dm_target *ti; + sector_t bound; + + ti = dm_table_find_target(ci->map, ci->sector); + if (!dm_target_is_valid(ti)) + return -EIO; + + if (!ti->copy_supported) + return -EOPNOTSUPP; + + bound = max_io_len(ci->sector, ti); + + if (unlikely(ci->sector_count > bound)) + return -EOPNOTSUPP; + + __clone_and_map_simple_bio(ci, ti, 0, NULL, NULL); + + ci->sector += ci->sector_count; + ci->sector_count = 0; + + return 0; +} + /* * Select the correct strategy for processing a non-flush bio. */ @@ -1416,6 +1441,8 @@ static int __split_and_process_non_flush return __send_discard(ci); else if (unlikely(bio->bi_rw & REQ_WRITE_SAME)) return __send_write_same(ci); + else if (unlikely(bio->bi_rw & REQ_COPY)) + return __send_copy(ci); ti = dm_table_find_target(ci->map, ci->sector); if (!dm_target_is_valid(ti)) @@ -1500,6 +1527,11 @@ static int dm_merge_bvec(struct request_ if (!dm_target_is_valid(ti)) goto out; + if (unlikely((bvm->bi_rw & REQ_COPY) != 0)) { + if (!ti->copy_supported) + goto out_ret_max_size; + } + /* * Find maximum amount of I/O that won't need splitting */ @@ -1523,17 +1555,21 @@ static int dm_merge_bvec(struct request_ * entries. So always set max_size to 0, and the code below allows * just one page. */ - else if (queue_max_hw_sectors(q) <= PAGE_SIZE >> 9) + else if (likely(!(bvm->bi_rw & REQ_COPY)) && + queue_max_hw_sectors(q) <= PAGE_SIZE >> 9) max_size = 0; out: - dm_put_live_table_fast(md); /* * Always allow an entire first page */ - if (max_size <= biovec->bv_len && !(bvm->bi_size >> SECTOR_SHIFT)) + if (likely(!(bvm->bi_rw & REQ_COPY)) && + max_size <= biovec->bv_len && !(bvm->bi_size >> SECTOR_SHIFT)) max_size = biovec->bv_len; +out_ret_max_size: + dm_put_live_table_fast(md); + return max_size; } Index: linux-3.16-rc5/include/linux/device-mapper.h =================================================================== --- linux-3.16-rc5.orig/include/linux/device-mapper.h 2014-07-14 16:26:24.000000000 +0200 +++ linux-3.16-rc5/include/linux/device-mapper.h 2014-07-14 16:41:15.000000000 +0200 @@ -251,6 +251,11 @@ struct dm_target { * Set if this target does not return zeroes on discarded blocks. */ bool discard_zeroes_data_unsupported:1; + + /* + * Set if the target supports XCOPY. + */ + bool copy_supported:1; }; /* Each target can link one of these into the table */ Index: linux-3.16-rc5/drivers/md/dm-table.c =================================================================== --- linux-3.16-rc5.orig/drivers/md/dm-table.c 2014-07-14 16:26:25.000000000 +0200 +++ linux-3.16-rc5/drivers/md/dm-table.c 2014-07-14 16:41:15.000000000 +0200 @@ -489,6 +489,11 @@ static int dm_set_device_limits(struct d q->limits.alignment_offset, (unsigned long long) start << SECTOR_SHIFT); + if (ti->copy_supported) + limits->max_copy_sectors = + min_not_zero(limits->max_copy_sectors, + bdev_get_queue(bdev)->limits.max_copy_sectors); + /* * Check if merge fn is supported. * If not we'll force DM to use PAGE_SIZE or @@ -1298,6 +1303,10 @@ combine_limits: dm_device_name(table->md), (unsigned long long) ti->begin, (unsigned long long) ti->len); + + limits->max_copy_sectors = + min_not_zero(limits->max_copy_sectors, + ti_limits.max_copy_sectors); } return validate_hardware_logical_block_alignment(table, limits);