From patchwork Fri Apr 21 03:55:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9691731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 752416037F for ; Fri, 21 Apr 2017 03:56:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6865A28334 for ; Fri, 21 Apr 2017 03:56:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BB9B285E6; Fri, 21 Apr 2017 03:56:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1E8628334 for ; Fri, 21 Apr 2017 03:56:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1035042AbdDUD4x (ORCPT ); Thu, 20 Apr 2017 23:56:53 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:33859 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1035040AbdDUD4t (ORCPT ); Thu, 20 Apr 2017 23:56:49 -0400 X-IronPort-AV: E=Sophos;i="5.37,228,1488816000"; d="scan'208";a="12016868" Received: from mail-bl2nam02lp0080.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([207.46.163.80]) by ob1.hgst.iphmx.com with ESMTP; 21 Apr 2017 11:56:38 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=uBAOlbmBlSRoTmuEFFAVI+HV6KCOGxawXa6SSyFlNM0=; b=BWrDVCDl2UuCSkUpM4MwXPseBzDFPLv2p2HkHWiqzmznriscoQ4EL2JkyM7fKCR/4k1KcUeLxHRZ2MdOiY7ezAl79E0mZZRGrvhK/bypNactrRaJklwpT78LvarliBHbZWHb+tX3Dso3Z1HIFBaE7WF0AaHyxjhQaI00TlR+vx0= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.173) by SN1PR04MB1983.namprd04.prod.outlook.com (10.166.69.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Fri, 21 Apr 2017 03:56:34 +0000 From: damien.lemoal@wdc.com To: dm-devel@redhat.com, Mike Snitzer , Alasdair Kergon Cc: Hannes Reinecke , Christoph Hellwig , Bart Van Assche , linux-block@vger.kernel.org, Damien Le Moal Subject: [PATCH 09/10] dm-kcopyd: Add sequential write feature Date: Fri, 21 Apr 2017 12:55:57 +0900 Message-Id: <20170421035558.2657-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170421035558.2657-1-damien.lemoal@wdc.com> References: <20170421035558.2657-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Originating-IP: [199.255.44.173] X-ClientProxiedBy: MWHPR10CA0052.namprd10.prod.outlook.com (10.169.238.14) To SN1PR04MB1983.namprd04.prod.outlook.com (10.166.69.143) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 695d7429-726c-4f1f-46f7-08d4886a683b X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401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SzHmPPO8ZI2x22GFSLCDzjOKAL7xOh+I1UcxCLV++M8qhaC2McrBha3dNGfsdXNwD8A1VlBfLGbRbPs+IglhuU68e+ZNIvRFDHTsNESMQTlY/LTHwOgbPCkZpk=; 20:rTfz9qKbi/eN/lpANDDQnatHh7wQAe4Hxi0tZK4kZtWIwPNbfm4zJ1R2dCSY3c/DYN4tbZogiNOWiufk9eckuqLXbgLlz8xhFEwXIQ8BTNuuhaHmz+re6PFHes9ovbAEe7IIcfwyNJq35DQNu8RgC6aN+BGAECDemdFYZvavBvaJB6kOevFEleN6W7hwnY8FWwfEv0JznB9sP/825TiXhV+zudyqObwaUoS3gE+ST7R1nSXbmomtuZl5QRFsgoLSmI+BjTQFYIJvrBPP8YzOqkKUAjJV1BI9c2iwjt1gTtf/UIVLlkj19Nih24Q1kVDNI/wwL+/Bmkdzjgz1J35ZC3eTSSbbx0Qkr9oLbirvB/8pz8u2qMySEigLHbX53/MplgX1DeXZtSIemPlCuUTyVISOKVH5XSi6NfM0qqlaA2Jey/lC25kyJjN02fvvZsM0VA1S/+bGf4ugqajYZiRMWKH1+E6+xqVVm/6Bp8g8yTvLs0SADgEDBK3J9ljcZrH/ WDCIPOUTBOUND: EOP-TRUE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123555025)(6072148); SRVR:SN1PR04MB1983; BCL:0; PCL:0; RULEID:; SRVR:SN1PR04MB1983; X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 4:Og5UUxv6D4RD1zohsZtW4hAmEzb/tI5A+z/2MmM6y7gAYyI586axaUrRkwtxmyLvl8Rf+OsRl2cb2N1C/T05CfEeI53LgY6TBWXyGTU2iuvt5acBRjg9vZ+4duoJR2qpz4TM7ksc/Ai856pwGnG53QVGTv8dZBs+fak9BIj1q2lV8m7TUabgp9DLKERAUL1K3xd/ur06wSrSzFRu2mxLafUj0CvqT3BiP0+Jq0b8+a3kP7PSllicZfKiJ3nATQxd2T/Nkh0vOgvjpTkh+HP4XzHqDX/VI6LTbsFKmhZkon1k9eLKAuCEaIcHBoyWD2nf/Bw0qJlTN8zNTqI9hSdVfQ/D1EHXIbInH9fvfpgS7F99d9IlWsi89Pr5NZ8dSjOlv2V/yTkgk8Cky2BGW2BHqlWAC8byyM7AwaY5xOhQHVM5WORmb6i6OisgcYnZv3/j26dnsWsN99/jplwfnFKW6xwMvkOyCQ83IudsMEteLUEh0p2UR5RbC1gzSosiA+NLhJyu6GAiJZ24AJZqa/YUehjDB0Q59crW+KVeZJYGD0hpvaXX/RqDNwyvEz6zdDajP3oib7eR8SBHJ0R28Z/bdK90RleTQjp1tABG7Llm4jWL0SFAewWwSmHgTZKiig3BxvLJfLAp4Ic1CZ/59difU63eyhV7lRDfDnlGU+5f3SIphyc+fVbfiC2DqdlP9JHogO4Mvv29Zobj73lJb8mI7ARSiRAaEV2JKoZhotwoxW8= X-Forefront-PRVS: 02843AA9E0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39400400002)(39850400002)(39450400003)(39840400002)(39860400002)(39410400002)(8676002)(5003940100001)(50466002)(48376002)(3846002)(2906002)(38730400002)(6116002)(36756003)(86362001)(4326008)(50226002)(1076002)(6636002)(2950100002)(6666003)(6486002)(305945005)(6512007)(53936002)(47776003)(66066001)(50986999)(54906002)(189998001)(5660300001)(76176999)(85782001)(7736002)(9686003)(33646002)(25786009)(42186005)(85772001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR04MB1983; H:washi.fujisawa.hgst.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR04MB1983; 23:o1RgoqHArKanmQZtlBIADqzO5z6d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M+nX7oZo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 7:D+y/+mFVaTt6XVpts3brBpcJpUK3IeYoc30tHo/H6SZKYqmb/T8KWVbOuG/BCcuezp8IFQdxTSTesve3blpZME9txkZy55caU06gld13TMvXmLN1PFgFNuQew7kZUk8isOzphLCTF2bptsftQcWLfiqVKlqCd38nvP2JduNx8s64oLxlsN9AQlPHffRAb6P9bAyDTCG1CTcvYiEieUWGC27NudmrYMdVGjDfGFItiEMpzj54BZ+qsOKvZmuasbqSEHg71PkMUs3ANQQ4e7PDH5N+4ssN7AjJI1R8qC1q2W2ozR69xeEMLq0v9XrZ4grKvufYbROsajNL+/M+RrOnuQ==; 20:lgPqcWD9PSUanAOBJjJR5ZyQHcFvWBmz+LTvRBMYiO2bGwkBBjFHiZ4b2Fc/FJNWsXIlj8JPoyJq+bnBePcI8T0ILlcEZlrIZppI67LCYViz0C65UqWHaYiu2pkz8r1a2ibJxoSvXme8xtiIf+PMLB5elxhZ+PoXuvZEJcZNV8U= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2017 03:56:34.1441 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR04MB1983 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Damien Le Moal When copyying blocks to host-managed zoned block devices, writes must be sequential. dm_kcopyd_copy() does not howerver guarantee this as writes are issued in the completion order of reads, and reads may complete out of order despite being issued sequentially. Fix this by introducing the DM_KCOPYD_WRITE_SEQ flag. This can be specified by the user when calling dm_kcopyd_copy() and is set automatically if one of the destinations is a host-managed zoned block device. For a split job, the master job maintains the write position at which writes must be issued. This is checked with the pop() function which is modify to not return any write I/O sub job that is not at the correct write position. When DM_KCOPYD_WRITE_SEQ is specified for a job, errors cannot be ignored and the flag DM_KCOPYD_IGNORE_ERROR is ignored, even if specified by the user. Signed-off-by: Damien Le Moal --- drivers/md/dm-kcopyd.c | 68 +++++++++++++++++++++++++++++++++++++++++++++-- include/linux/dm-kcopyd.h | 1 + 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-kcopyd.c b/drivers/md/dm-kcopyd.c index 9e9d04cb..477846e 100644 --- a/drivers/md/dm-kcopyd.c +++ b/drivers/md/dm-kcopyd.c @@ -356,6 +356,7 @@ struct kcopyd_job { struct mutex lock; atomic_t sub_jobs; sector_t progress; + sector_t write_ofst; struct kcopyd_job *master_job; }; @@ -386,6 +387,34 @@ void dm_kcopyd_exit(void) * Functions to push and pop a job onto the head of a given job * list. */ +static struct kcopyd_job *pop_io_job(struct list_head *jobs, + struct dm_kcopyd_client *kc) +{ + struct kcopyd_job *job; + + /* + * For I/O jobs, pop any read, any write without sequential write + * constraint and sequential writes that are at the right position. + */ + list_for_each_entry(job, jobs, list) { + + if (job->rw == READ || + !test_bit(DM_KCOPYD_WRITE_SEQ, &job->flags)) { + list_del(&job->list); + return job; + } + + if (job->write_ofst == job->master_job->write_ofst) { + job->master_job->write_ofst += job->source.count; + list_del(&job->list); + return job; + } + + } + + return NULL; +} + static struct kcopyd_job *pop(struct list_head *jobs, struct dm_kcopyd_client *kc) { @@ -395,8 +424,12 @@ static struct kcopyd_job *pop(struct list_head *jobs, spin_lock_irqsave(&kc->job_lock, flags); if (!list_empty(jobs)) { - job = list_entry(jobs->next, struct kcopyd_job, list); - list_del(&job->list); + if (jobs == &kc->io_jobs) { + job = pop_io_job(jobs, kc); + } else { + job = list_entry(jobs->next, struct kcopyd_job, list); + list_del(&job->list); + } } spin_unlock_irqrestore(&kc->job_lock, flags); @@ -506,6 +539,14 @@ static int run_io_job(struct kcopyd_job *job) .client = job->kc->io_client, }; + /* + * If we need to write sequentially and some reads or writes failed, + * no point in continuing. + */ + if (test_bit(DM_KCOPYD_WRITE_SEQ, &job->flags) && + job->master_job->write_err) + return -EIO; + io_job_start(job->kc->throttle); if (job->rw == READ) @@ -655,6 +696,7 @@ static void segment_complete(int read_err, unsigned long write_err, int i; *sub_job = *job; + sub_job->write_ofst = progress; sub_job->source.sector += progress; sub_job->source.count = count; @@ -723,6 +765,27 @@ int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from, job->num_dests = num_dests; memcpy(&job->dests, dests, sizeof(*dests) * num_dests); + /* + * If one of the destination is a host-managed zoned block device, + * we need to write sequentially. If one of the destination is a + * host-aware device, then leave it to the caller to choose what to do. + */ + if (!test_bit(DM_KCOPYD_WRITE_SEQ, &job->flags)) { + for (i = 0; i < job->num_dests; i++) { + if (bdev_zoned_model(dests[i].bdev) == BLK_ZONED_HM) { + set_bit(DM_KCOPYD_WRITE_SEQ, &job->flags); + break; + } + } + } + + /* + * If we need to write sequentially, errors cannot be ignored. + */ + if (test_bit(DM_KCOPYD_WRITE_SEQ, &job->flags) && + test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) + clear_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags); + if (from) { job->source = *from; job->pages = NULL; @@ -746,6 +809,7 @@ int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from, job->fn = fn; job->context = context; job->master_job = job; + job->write_ofst = 0; if (job->source.count <= SUB_JOB_SIZE) dispatch_job(job); diff --git a/include/linux/dm-kcopyd.h b/include/linux/dm-kcopyd.h index f486d63..cfac858 100644 --- a/include/linux/dm-kcopyd.h +++ b/include/linux/dm-kcopyd.h @@ -20,6 +20,7 @@ #define DM_KCOPYD_MAX_REGIONS 8 #define DM_KCOPYD_IGNORE_ERROR 1 +#define DM_KCOPYD_WRITE_SEQ 2 struct dm_kcopyd_throttle { unsigned throttle;