From patchwork Sun Apr 19 07:30:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Wise X-Patchwork-Id: 11498201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A2C016CA for ; Mon, 20 Apr 2020 07:07:31 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 60C502078E for ; Mon, 20 Apr 2020 07:07:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YLP0LAMA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60C502078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bonedaddy.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587366450; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4BpwkfZRU5zfmgu/l6gi4n6s2DpTL7jl5O59onusOKA=; b=YLP0LAMAdIx7npZs+n9Seuh5F06BnxjrsCVXOX0C5R7wR6+a50MRVrPki5KUuxpZDdLs0a 0TZ0jCZNpVPPqhMMh5O5Kec3xYgYamsDWSHm7FQgHZTJCWGeRQ9onjVNqJxoX9Pq6nQqdc xsNfAxS/BSJHS5Ageok7dboNdD+RF3k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-eYKjHvkxNt2nwA5jbNVRoQ-1; Mon, 20 Apr 2020 03:07:28 -0400 X-MC-Unique: eYKjHvkxNt2nwA5jbNVRoQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2114B1005510; Mon, 20 Apr 2020 07:07:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0F6F2B479; Mon, 20 Apr 2020 07:07:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B9D8B93902; Mon, 20 Apr 2020 07:07:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03J7lfDV003159 for ; Sun, 19 Apr 2020 03:47:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 91CE55C28F; Sun, 19 Apr 2020 07:47:41 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx01.redhat.com (mimecast05.extmail.prod.ext.phx2.redhat.com [10.5.110.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CA945C1BB for ; Sun, 19 Apr 2020 07:47:39 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B80828018A1 for ; Sun, 19 Apr 2020 07:47:38 +0000 (UTC) Received: from master.debian.org (master.debian.org [82.195.75.110]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-256-nYhLcFTUNPCSl3fB7OFpWw-1; Sun, 19 Apr 2020 03:45:28 -0400 X-MC-Unique: nYhLcFTUNPCSl3fB7OFpWw-1 Received: from pabs by master.debian.org with local (Exim 4.92) (envelope-from ) id 1jQ4Q5-00040V-QM; Sun, 19 Apr 2020 07:31:13 +0000 From: Paul Wise To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, linux-kernel@vger.kernel.org Date: Sun, 19 Apr 2020 15:30:24 +0800 Message-Id: <20200419073026.197967-2-pabs3@bonedaddy.net> In-Reply-To: <20200419073026.197967-1-pabs3@bonedaddy.net> References: <20200419073026.197967-1-pabs3@bonedaddy.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03J7lfDV003159 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Mon, 20 Apr 2020 03:06:56 -0400 Cc: Paul Wise Subject: [dm-devel] [PATCH 1/3] dm: add support for targets that allow discard when one device does X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Rename the discards_supported variable to discard_support since the discard support isn't just turned on or off and there are now three types of discard support for dm targets. Switch discard_support to using an enum so that the other types of discard support (all devices or ignore devices) can be accommodated. This is needed so that dm raid and dm raid1 can support discard for arrays of devices of varying discard support where this is safe. Signed-off-by: Paul Wise --- drivers/md/dm-cache-target.c | 2 +- drivers/md/dm-clone-target.c | 2 +- drivers/md/dm-log-writes.c | 2 +- drivers/md/dm-table.c | 32 +++++++++++++++++++++----------- drivers/md/dm-thin.c | 8 ++++---- drivers/md/dm-zoned-target.c | 2 +- include/linux/device-mapper.h | 13 ++++++++----- include/uapi/linux/dm-ioctl.h | 4 ++-- 8 files changed, 39 insertions(+), 26 deletions(-) diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index d3bb355819a4..9aba81324579 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c @@ -2459,7 +2459,7 @@ static int cache_create(struct cache_args *ca, struct cache **result) ti->flush_supported = true; ti->num_discard_bios = 1; - ti->discards_supported = true; + ti->discard_support = DM_DISCARD_IGN_DEVS; ti->per_io_data_size = sizeof(struct per_bio_data); diff --git a/drivers/md/dm-clone-target.c b/drivers/md/dm-clone-target.c index 5ce96ddf1ce1..f5b2c1998628 100644 --- a/drivers/md/dm-clone-target.c +++ b/drivers/md/dm-clone-target.c @@ -1938,7 +1938,7 @@ static int clone_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->flush_supported = true; /* Enable discards */ - ti->discards_supported = true; + ti->discard_support = DM_DISCARD_IGN_DEVS; ti->num_discard_bios = 1; ti->private = clone; diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c index 8ea20b56b4d6..9414214c250d 100644 --- a/drivers/md/dm-log-writes.c +++ b/drivers/md/dm-log-writes.c @@ -593,7 +593,7 @@ static int log_writes_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_flush_bios = 1; ti->flush_supported = true; ti->num_discard_bios = 1; - ti->discards_supported = true; + ti->discard_support = DM_DISCARD_IGN_DEVS; ti->per_io_data_size = sizeof(struct per_bio_data); ti->private = lc; return 0; diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 0a2cc197f62b..0e5a38da0ca8 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -789,8 +789,8 @@ int dm_table_add_target(struct dm_table *t, const char *type, t->highs[t->num_targets++] = tgt->begin + tgt->len - 1; - if (!tgt->num_discard_bios && tgt->discards_supported) - DMWARN("%s: %s: ignoring discards_supported because num_discard_bios is zero.", + if (!tgt->num_discard_bios && (tgt->discard_support != DM_DISCARD_ALL_DEVS)) + DMWARN("%s: %s: ignoring discard support because num_discard_bios is zero.", dm_device_name(t->md), type); return 0; @@ -1786,6 +1786,14 @@ static bool dm_table_supports_write_zeroes(struct dm_table *t) return true; } +static int device_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); +} + static int device_not_discard_capable(struct dm_target *ti, struct dm_dev *dev, sector_t start, sector_t len, void *data) { @@ -1805,15 +1813,17 @@ static bool dm_table_supports_discards(struct dm_table *t) if (!ti->num_discard_bios) return false; - /* - * 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; + if (ti->discard_support == DM_DISCARD_IGN_DEVS) { + continue; + } else if (ti->discard_support == DM_DISCARD_ANY_DEVS) { + if (!ti->type->iterate_devices || + !ti->type->iterate_devices(ti, device_discard_capable, NULL)) + return false; + } else { + if (!ti->type->iterate_devices || + ti->type->iterate_devices(ti, device_not_discard_capable, NULL)) + return false; + } } return true; diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index fa8d5464c1fb..f9384e1a44ce 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -3402,11 +3402,11 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) ti->num_discard_bios = 1; /* - * Setting 'discards_supported' circumvents the normal - * stacking of discard limits (this keeps the pool and + * Setting this circumvents the normal stacking + * of discard limits (this keeps the pool and * thin devices' discard limits consistent). */ - ti->discards_supported = true; + ti->discard_support = DM_DISCARD_IGN_DEVS; } ti->private = pt; @@ -4266,7 +4266,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) /* In case the pool supports discards, pass them on. */ if (tc->pool->pf.discard_enabled) { - ti->discards_supported = true; + ti->discard_support = DM_DISCARD_IGN_DEVS; ti->num_discard_bios = 1; } diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c index f4f83d39b3dc..76e7886cba9e 100644 --- a/drivers/md/dm-zoned-target.c +++ b/drivers/md/dm-zoned-target.c @@ -796,7 +796,7 @@ static int dmz_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_write_zeroes_bios = 1; ti->per_io_data_size = sizeof(struct dmz_bioctx); ti->flush_supported = true; - ti->discards_supported = true; + ti->discard_support = DM_DISCARD_IGN_DEVS; /* The exposed capacity is the number of chunks that can be mapped */ ti->len = (sector_t)dmz_nr_chunks(dmz->metadata) << dev->zone_nr_sectors_shift; diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index af48d9da3916..67cb0f7427e4 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -252,6 +252,12 @@ struct target_type { #define DM_TARGET_ZONED_HM 0x00000040 #define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM) +enum dm_discard_mode { + DM_DISCARD_ALL_DEVS = 0, + DM_DISCARD_ANY_DEVS = 1, + DM_DISCARD_IGN_DEVS = 2, +}; + struct dm_target { struct dm_table *table; struct target_type *type; @@ -315,11 +321,8 @@ struct dm_target { */ bool flush_supported:1; - /* - * Set if this target needs to receive discards regardless of - * whether or not its underlying devices have support. - */ - bool discards_supported:1; + /* Use to specify the discard support of this target */ + enum dm_discard_mode discard_support; }; /* Each target can link one of these into the table */ diff --git a/include/uapi/linux/dm-ioctl.h b/include/uapi/linux/dm-ioctl.h index 6622912c2342..360bd55c1681 100644 --- a/include/uapi/linux/dm-ioctl.h +++ b/include/uapi/linux/dm-ioctl.h @@ -272,9 +272,9 @@ enum { #define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) #define DM_VERSION_MAJOR 4 -#define DM_VERSION_MINOR 42 +#define DM_VERSION_MINOR 43 #define DM_VERSION_PATCHLEVEL 0 -#define DM_VERSION_EXTRA "-ioctl (2020-02-27)" +#define DM_VERSION_EXTRA "-ioctl (2020-04-14)" /* Status bits */ #define DM_READONLY_FLAG (1 << 0) /* In/Out */ From patchwork Sun Apr 19 07:30:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Wise X-Patchwork-Id: 11498197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F5386CA for ; Mon, 20 Apr 2020 07:07:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E57292078E for ; Mon, 20 Apr 2020 07:07:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RFPzRl8V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E57292078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bonedaddy.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587366442; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lU7Rt/rsoOJWezeU1/5IL+uEA/a3dqrwF0THpgTQcyg=; b=RFPzRl8VQhc7+jjKbYET3vY7yOrar+GFYiQZvkr0/iT1DHc+D521luSSMXRMj550AP+hMA FmsXzoFezM77VX9KvcShKbT3/L+L2nPZsDmyu4abzY2sKm01M6kPaA7jmKmoIeqw1nNJ/2 YZzxJgeI/hQlYOkfMRE8oVmQ8pcxIww= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-71-QUtiKavZM5-x9DSs2H7fIw-1; Mon, 20 Apr 2020 03:07:21 -0400 X-MC-Unique: QUtiKavZM5-x9DSs2H7fIw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38C3F18C35A3; Mon, 20 Apr 2020 07:07:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 154BEA188F; Mon, 20 Apr 2020 07:07:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 59D0318089D6; Mon, 20 Apr 2020 07:07:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03J7jQm2003013 for ; Sun, 19 Apr 2020 03:45:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BCD71003215; Sun, 19 Apr 2020 07:45:26 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9643E1003345 for ; Sun, 19 Apr 2020 07:45:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 383C48EE331 for ; Sun, 19 Apr 2020 07:45:24 +0000 (UTC) Received: from master.debian.org (master.debian.org [82.195.75.110]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-rClfPctUNNSNQkXh4J3KpQ-1; Sun, 19 Apr 2020 03:45:20 -0400 X-MC-Unique: rClfPctUNNSNQkXh4J3KpQ-1 Received: from pabs by master.debian.org with local (Exim 4.92) (envelope-from ) id 1jQ4Q9-00040e-4Q; Sun, 19 Apr 2020 07:31:17 +0000 From: Paul Wise To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, linux-kernel@vger.kernel.org Date: Sun, 19 Apr 2020 15:30:25 +0800 Message-Id: <20200419073026.197967-3-pabs3@bonedaddy.net> In-Reply-To: <20200419073026.197967-1-pabs3@bonedaddy.net> References: <20200419073026.197967-1-pabs3@bonedaddy.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03J7jQm2003013 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Mon, 20 Apr 2020 03:06:56 -0400 Cc: Paul Wise Subject: [dm-devel] [PATCH 2/3] dm raid: only check for RAID 4/5/6 once during discard support setup X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com The RAID level 4/5/6 check no longer looks at the devices in the array, so it isn't necessary for it to be checked once for each device, so check it before the loop over the devices. This makes the code cleaner and easier to understand since it disentangles whole-array checks from per-device checks. Commit 48920ff2a5a9 ("block: remove the discard_zeroes_data flag") removed the per-device discard_zeroes_data check since REQ_OP_WRITE_ZEROES operation was used everywhere and commit 48cf06bc5f50 ("dm raid: add discard support for RAID levels 4, 5 and 6") introduced the RAID 4/5/6 check. Signed-off-by: Paul Wise --- drivers/md/dm-raid.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index 9a18bef0a5ff..0f95e50e62a8 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -2944,13 +2944,16 @@ static int rs_setup_reshape(struct raid_set *rs) static void configure_discard_support(struct raid_set *rs) { int i; - bool raid456; struct dm_target *ti = rs->ti; /* * XXX: RAID level 4,5,6 require zeroing for safety. */ - raid456 = rs_is_raid456(rs); + if (rs_is_raid456(rs) && !devices_handle_discard_safely) { + DMERR("raid456 discard support disabled due to discard_zeroes_data uncertainty."); + DMERR("Set dm-raid.devices_handle_discard_safely=Y to override."); + return; + } for (i = 0; i < rs->raid_disks; i++) { struct request_queue *q; @@ -2961,14 +2964,6 @@ static void configure_discard_support(struct raid_set *rs) q = bdev_get_queue(rs->dev[i].rdev.bdev); if (!q || !blk_queue_discard(q)) return; - - if (raid456) { - if (!devices_handle_discard_safely) { - DMERR("raid456 discard support disabled due to discard_zeroes_data uncertainty."); - DMERR("Set dm-raid.devices_handle_discard_safely=Y to override."); - return; - } - } } ti->num_discard_bios = 1; From patchwork Sun Apr 19 07:30:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Wise X-Patchwork-Id: 11498199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 85D15913 for ; Mon, 20 Apr 2020 07:07:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 471A22078E for ; Mon, 20 Apr 2020 07:07:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WNywog6k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 471A22078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bonedaddy.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587366447; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EvzvcKcbiEN1d/mwvpwbFkTOKTrN+qrPZKHRsjjALZ8=; b=WNywog6ks4Zoxcb0zS1qcWw/B9eN8mQ578YHjiFtfrSNLmuJj4J7Cko6IJhI0iF6tCrafb uAGSzR0ndLW452rUbiS+HrebiHt8XJosbvroc2FEdZ5vRUDV55qq0GJ7HxyY7/pdBNG2pO oNCzijl8eGnjh7pC7DQZJdzXawTU488= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-GHoM2N1DPqexPem-PmoDAg-1; Mon, 20 Apr 2020 03:07:24 -0400 X-MC-Unique: GHoM2N1DPqexPem-PmoDAg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 496AE1050945; Mon, 20 Apr 2020 07:07:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2427F2B479; Mon, 20 Apr 2020 07:07:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D2A3618089D5; Mon, 20 Apr 2020 07:07:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03J7jW03003026 for ; Sun, 19 Apr 2020 03:45:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id F2DD12166B28; Sun, 19 Apr 2020 07:45:31 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF15A2166B27 for ; Sun, 19 Apr 2020 07:45:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A8D08101A55A for ; Sun, 19 Apr 2020 07:45:29 +0000 (UTC) Received: from master.debian.org (master.debian.org [82.195.75.110]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-gx7EzL2QM6-QCoxr54ZvUQ-1; Sun, 19 Apr 2020 03:45:24 -0400 X-MC-Unique: gx7EzL2QM6-QCoxr54ZvUQ-1 Received: from pabs by master.debian.org with local (Exim 4.92) (envelope-from ) id 1jQ4QD-00040m-1R; Sun, 19 Apr 2020 07:31:21 +0000 From: Paul Wise To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, linux-kernel@vger.kernel.org Date: Sun, 19 Apr 2020 15:30:26 +0800 Message-Id: <20200419073026.197967-4-pabs3@bonedaddy.net> In-Reply-To: <20200419073026.197967-1-pabs3@bonedaddy.net> References: <20200419073026.197967-1-pabs3@bonedaddy.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03J7jW03003026 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Mon, 20 Apr 2020 03:06:56 -0400 Cc: Paul Wise Subject: [dm-devel] [PATCH 3/3] dm raid/raid1: enable discard support when any devices support discard X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com This will allow fstrim to work on filesystems on dm RAID arrays with both HDDs and SSDs or dm raid SSD arrays with varying discard support, which should increase the lifetime of the SSDs that support discard. This makes dm raid and dm raid1 (mirroring) consistent with md raid, which supports discard when only some of the devices support discard. The existing code prevents this from being enabled with RAID 4/5/6, which require more certainty about the behaviour of underlying devices after a discard has been issued and processed. Simply enable discard and return from the configure_discard_support function when any of the underlying devices has support for discards, since there are now no other checks in the device check loop. Mixed discard support for md RAID types was added in these commits: commit c83057a1f4f9 ("md: raid 0 supports TRIM") commit 2ff8cc2c6d4e ("md: raid 1 supports TRIM") commit 532a2a3fba8d ("md: raid 10 supports TRIM") commit f1cad2b68ed1 ("md: linear supports TRIM") Signed-off-by: Paul Wise --- drivers/md/dm-raid.c | 8 ++++++-- drivers/md/dm-raid1.c | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index 0f95e50e62a8..63f5d05021a9 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -2962,11 +2962,15 @@ static void configure_discard_support(struct raid_set *rs) continue; q = bdev_get_queue(rs->dev[i].rdev.bdev); - if (!q || !blk_queue_discard(q)) + if (q && blk_queue_discard(q)) { + ti->discard_support = DM_DISCARD_ANY_DEVS; + ti->num_discard_bios = 1; return; + } } - ti->num_discard_bios = 1; + ti->discard_support = DM_DISCARD_ALL_DEVS; + ti->num_discard_bios = 0; } /* diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c index 089aed57e083..2bfed681dd3f 100644 --- a/drivers/md/dm-raid1.c +++ b/drivers/md/dm-raid1.c @@ -1114,6 +1114,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto err_free_context; ti->num_flush_bios = 1; + ti->discard_support = DM_DISCARD_ANY_DEVS; ti->num_discard_bios = 1; ti->per_io_data_size = sizeof(struct dm_raid1_bio_record);