Received: by 10.223.185.116 with SMTP id b49csp823485wrg; Sat, 10 Feb 2018 21:14:14 -0800 (PST) X-Google-Smtp-Source: AH8x227Ci379QRRILm7UV+cdYrEzsD5KKsdic4KmdSV7ZV+82yYniqiAiEn449k3DPTFkyAZVzeJ X-Received: by 10.99.119.72 with SMTP id s69mr6070628pgc.224.1518326054166; Sat, 10 Feb 2018 21:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326054; cv=none; d=google.com; s=arc-20160816; b=r7RJKHVf75MG9WJnbtrb5KOwsOLWZRg/pCRUDsBKdmNEi7wDbQovtfyuThOLRpZ+/g 51cI8EMLTZkAfeI3nKrmzimlqISrHjPc4hG9WaN4rILeleoWFtT2LbDy51lBOFw8gx32 PJUAm/04f/DkLT9o/bb9To2L1ANIiXV6Gck8JOjQYWU8+4l9AeP3xYk4tUtibSgeRuKw c0cQ/4BCBno2WphCQ5jsH8tySvp07+iNzidU2/LbnDrU2BgyF9d9Wke9HOCSuXeV/V8W iBPprkmDLuagbW9xvqLxQYttwg3fE9NhOrvZxUt7dLH6KRz+vHXTpII5ERr7PCjDY1Ym UjWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=cH7maObCjXLl6LJXthF/TofwFb+axSCTPTa/wWMKPVc=; b=C+YlSuB/1vkbszNYZ5Po30b1tnKgIexBq9wqPFZH75ZgO2Vpbu4+ggwdSKqQ1uQR8F NHezIeW1jjJEsgj6DKpfYZYwIo5snSM/IlNoyDUBYQ6/2zXz3MRRNCQZLzApWShUZtcq A82WSzrnrGfB2UR/DtOquaXnz4SwHUW2sKzKIjkHkGqyP7eLIzkNO4HVCUGn0VVLaYsu Hk/oi7XFWI2PE8O0coG15UtYeW+7pl8zHb7XAvvmfL25kLlSfol9wH00xZuWELwhCaSB ihq2O0YuB5QjDIv9rAi+AGJbG6+ai8DSS/6MjJ7iNzizCXqK4nrAUvo230WnRD3FgSHx KIJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7si59243pgq.527.2018.02.10.21.14.00; Sat, 10 Feb 2018 21:14:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753992AbeBKFM3 (ORCPT + 99 others); Sun, 11 Feb 2018 00:12:29 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41415 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752632AbeBKEdl (ORCPT ); Sat, 10 Feb 2018 23:33:41 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKe-0002hQ-7X; Sun, 11 Feb 2018 04:33:40 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKY-0004Uy-5l; Sun, 11 Feb 2018 04:33:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Mike Snitzer" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 44/79] dm: discard support requires all targets in a table support discards In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Mike Snitzer commit 8a74d29d541cd86569139c6f3f44b2d210458071 upstream. A DM device with a mix of discard capabilities (due to some underlying devices not having discard support) _should_ just return -EOPNOTSUPP for the region of the device that doesn't support discards (even if only by way of the underlying driver formally not supporting discards). BUT, that does ask the underlying driver to handle something that it never advertised support for. In doing so we're exposing users to the potential for a underlying disk driver hanging if/when a discard is issued a the device that is incapable and never claimed to support discards. Fix this by requiring that each DM target in a DM table provide discard support as a prereq for a DM device to advertise support for discards. This may cause some configurations that were happily supporting discards (even in the face of a mix of discard support) to stop supporting discards -- but the risk of users hitting driver hangs, and forced reboots, outweighs supporting those fringe mixed discard configurations. Signed-off-by: Mike Snitzer [bwh: Backported to 3.2: adjust context] Signed-off-by: Ben Hutchings --- drivers/md/dm-table.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1584,12 +1584,12 @@ struct mapped_device *dm_table_get_md(st } EXPORT_SYMBOL(dm_table_get_md); -static int device_discard_capable(struct dm_target *ti, struct dm_dev *dev, - sector_t start, sector_t len, void *data) +static int device_not_discard_capable(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) { struct request_queue *q = bdev_get_queue(dev->bdev); - return q && blk_queue_discard(q); + return q && !blk_queue_discard(q); } bool dm_table_supports_discards(struct dm_table *t) @@ -1597,26 +1597,22 @@ bool dm_table_supports_discards(struct d struct dm_target *ti; unsigned i = 0; - /* - * Unless any target used by the table set discards_supported, - * require at least one underlying device to support discards. - * t->devices includes internal dm devices such as mirror logs - * so we need to use iterate_devices here, which targets - * supporting discard selectively must provide. - */ while (i < dm_table_get_num_targets(t)) { ti = dm_table_get_target(t, i++); if (!ti->num_discard_requests) - continue; + return false; - if (ti->discards_supported) - return 1; - - if (ti->type->iterate_devices && - ti->type->iterate_devices(ti, device_discard_capable, NULL)) - return 1; + /* + * Either the target provides discard support (as implied by setting + * 'discards_supported') or it relies on _all_ data devices having + * discard support. + */ + if (!ti->discards_supported && + (!ti->type->iterate_devices || + ti->type->iterate_devices(ti, device_not_discard_capable, NULL))) + return false; } - return 0; + return true; }