From patchwork Wed Mar 1 20:41:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 13156486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FB8CC7EE23 for ; Wed, 1 Mar 2023 20:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbjCAUlq (ORCPT ); Wed, 1 Mar 2023 15:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbjCAUlo (ORCPT ); Wed, 1 Mar 2023 15:41:44 -0500 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B5C34D62D for ; Wed, 1 Mar 2023 12:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=NAwBkP+hDpEg0MRUhqFonvkBRhC/h4PEyxznskx06tY=; b=RuTnQI84KDk8aoCe3j4oH7CqBv /fsIRDw/6oCOEQbxLgbNwFSFDw/X9Gru/AugSEgYSV66g42TRHx9Npec2/99gz84pbWRP5jzY1aI4 /b5EU+IYfINlT7nRYvaBwCZHqinHXwTexcxOHYbn90cbTW6RZC4b1Sa4XAAhP/U0U9WJI5c12t/Sd jS+1oxwJnbgBq6yJQUaERrhpER8kQjT5mI1Vl7lkq8jo/W07Yu7cUqnHRj/UrzU99PyBIqrc/VIoU byodGIa5/Sb6Od1f29015FvOWqkNK57q8zxkAD3SvILaSjVPUVDaaLnyYR3K42LLOrzPCrclCV20e ytIVpYfA==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pXTGd-006cu9-HQ; Wed, 01 Mar 2023 13:41:40 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1pXTGb-000ADg-28; Wed, 01 Mar 2023 13:41:37 -0700 From: Logan Gunthorpe To: linux-raid@vger.kernel.org, Jes Sorensen Cc: Guoqing Jiang , Xiao Ni , Mariusz Tkaczyk , Coly Li , Chaitanya Kulkarni , Jonmichael Hands , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Kinga Tanska , Chaitanya Kulkarni Date: Wed, 1 Mar 2023 13:41:29 -0700 Message-Id: <20230301204135.39230-2-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230301204135.39230-1-logang@deltatee.com> References: <20230301204135.39230-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-raid@vger.kernel.org, jes@trained-monkey.org, guoqing.jiang@linux.dev, xni@redhat.com, colyli@suse.de, jm@chia.net, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, mariusz.tkaczyk@linux.intel.com, kinga.tanska@linux.intel.com, chaitanyak@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH mdadm v7 1/7] Create: goto abort_locked instead of return 1 in error path X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org The return 1 after the fstat_is_blkdev() check should be replaced with an error return that goes through the error path to unlock resources locked by this function. Signed-off-by: Logan Gunthorpe Acked-by: Kinga Tanska Reviewed-by: Xiao Ni Reviewed-by: Chaitanya Kulkarni Acked-by: Coly Li --- Create.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Create.c b/Create.c index 953e73722518..2e8203ecdccd 100644 --- a/Create.c +++ b/Create.c @@ -939,7 +939,7 @@ int Create(struct supertype *st, char *mddev, goto abort_locked; } if (!fstat_is_blkdev(fd, dv->devname, &rdev)) - return 1; + goto abort_locked; inf->disk.major = major(rdev); inf->disk.minor = minor(rdev); } From patchwork Wed Mar 1 20:41:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 13156490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D24B1C7EE23 for ; Wed, 1 Mar 2023 20:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229445AbjCAUlv (ORCPT ); Wed, 1 Mar 2023 15:41:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbjCAUlo (ORCPT ); Wed, 1 Mar 2023 15:41:44 -0500 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF8574BEAF for ; Wed, 1 Mar 2023 12:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=stGI78jIhqffCka1jx/cbQWc8n0frmK0hbho5OsNw8k=; b=MssYbUh69YgZEMcTKWVwnO953K /bOwKJax5Nd+8iKd9bdQ+DqDxagEjTuXCQhkKg+KSY2/cFYCIW7roJMCch69nGS1KmMXx1C2evH6V 6WS8Z9XxUcJ+diPvsFo011OSQYBc3PRcGqNVQ2bswI39XRyzTWmWsZviZDmwuZwAszd/Ivl0gTvTP lE9CDVkeBr5TJElyeD5TsRMLslULSqkg4e0yQzUwLGzmhmhUvANEHR+uLaxngJsDWYPyxH0PPyygq MfwaqCzQMKazvmnH4THeLWIrYZw0F/6uf3WTc+rIkg8r6+KHnWFe35NbRa+DYHH3mf7zX4ltpREVT 0kp5dUYQ==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pXTGd-006cuA-HP; Wed, 01 Mar 2023 13:41:40 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1pXTGb-000ADj-6Q; Wed, 01 Mar 2023 13:41:37 -0700 From: Logan Gunthorpe To: linux-raid@vger.kernel.org, Jes Sorensen Cc: Guoqing Jiang , Xiao Ni , Mariusz Tkaczyk , Coly Li , Chaitanya Kulkarni , Jonmichael Hands , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Kinga Tanska , Chaitanya Kulkarni Date: Wed, 1 Mar 2023 13:41:30 -0700 Message-Id: <20230301204135.39230-3-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230301204135.39230-1-logang@deltatee.com> References: <20230301204135.39230-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-raid@vger.kernel.org, jes@trained-monkey.org, guoqing.jiang@linux.dev, xni@redhat.com, colyli@suse.de, jm@chia.net, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, mariusz.tkaczyk@linux.intel.com, kinga.tanska@linux.intel.com, chaitanyak@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH mdadm v7 2/7] Create: remove safe_mode_delay local variable X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org All .getinfo_super() call sets the info.safe_mode_delay variables to a constant value, so no matter what the current state is that function will always set it to the same value. Create() calls .getinfo_super() multiple times while creating the array. The value is stored in a local variable for every disk in the loop to add disks (so the last disc call takes precedence). The local variable is then used in the call to sysfs_set_safemode(). This can be simplified by using info.safe_mode_delay directly. The info variable had .getinfo_super() called on it early in the function so, by the reasoning above, it will have the same value as the local variable which can thus be removed. Doing this allows for factoring out code from Create() in a subsequent patch. Signed-off-by: Logan Gunthorpe Acked-by: Kinga Tanska Reviewed-by: Xiao Ni Reviewed-by: Chaitanya Kulkarni Acked-by: Coly Li --- Create.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Create.c b/Create.c index 2e8203ecdccd..8ded81dc265d 100644 --- a/Create.c +++ b/Create.c @@ -137,7 +137,6 @@ int Create(struct supertype *st, char *mddev, int did_default = 0; int do_default_layout = 0; int do_default_chunk = 0; - unsigned long safe_mode_delay = 0; char chosen_name[1024]; struct map_ent *map = NULL; unsigned long long newsize; @@ -952,7 +951,6 @@ int Create(struct supertype *st, char *mddev, goto abort_locked; } st->ss->getinfo_super(st, inf, NULL); - safe_mode_delay = inf->safe_mode_delay; if (have_container && c->verbose > 0) pr_err("Using %s for device %d\n", @@ -1065,7 +1063,7 @@ int Create(struct supertype *st, char *mddev, "readonly"); break; } - sysfs_set_safemode(&info, safe_mode_delay); + sysfs_set_safemode(&info, info.safe_mode_delay); if (err) { pr_err("failed to activate array.\n"); ioctl(mdfd, STOP_ARRAY, NULL); From patchwork Wed Mar 1 20:41:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 13156492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A92E1C7EE33 for ; Wed, 1 Mar 2023 20:41:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbjCAUlx (ORCPT ); Wed, 1 Mar 2023 15:41:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbjCAUlp (ORCPT ); Wed, 1 Mar 2023 15:41:45 -0500 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9B1E4DBD2 for ; Wed, 1 Mar 2023 12:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=qah3q9NrSIcofz18MJnGHpYM+PqRvm2TM9pC0oVl/Jw=; b=PZtVmDkJJ/5v+aXiIZARFyTI+d gSQFOphHb1HtfS1oqCN4Ju2+Kr38VWnlgwQ5E9lGrZ5MP20LMzWsGloPtCGW1fa966e7lar9+TKu3 w6X+NvPAoxkiqzdO2Pm77bdbzAOvPO80r74sOLQ+eLsyVcJSo8+Zj76j3mVlCadsYm35mZm/I/2s7 I4Uc+3gdB5WHSZUFanJC/DKd+d5b7o07SiSJOEDWBLqqAyWpfWkv41RTFTWQa0cXymxa0ZQ8OQ3SP dFynW7hrZNaxmJoPEPrSMpUe1LCNSOHelUP2rvnP/V2+jTLjXHQFhs3OWXgDscUg+Nu6k+iemqiVr jsF2oFPQ==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pXTGd-006cuB-HQ; Wed, 01 Mar 2023 13:41:41 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1pXTGb-000ADm-Am; Wed, 01 Mar 2023 13:41:37 -0700 From: Logan Gunthorpe To: linux-raid@vger.kernel.org, Jes Sorensen Cc: Guoqing Jiang , Xiao Ni , Mariusz Tkaczyk , Coly Li , Chaitanya Kulkarni , Jonmichael Hands , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Kinga Tanska , Chaitanya Kulkarni Date: Wed, 1 Mar 2023 13:41:31 -0700 Message-Id: <20230301204135.39230-4-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230301204135.39230-1-logang@deltatee.com> References: <20230301204135.39230-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-raid@vger.kernel.org, jes@trained-monkey.org, guoqing.jiang@linux.dev, xni@redhat.com, colyli@suse.de, jm@chia.net, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, mariusz.tkaczyk@linux.intel.com, kinga.tanska@linux.intel.com, chaitanyak@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH mdadm v7 3/7] Create: Factor out add_disks() helpers X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org The Create function is massive with a very large number of variables. Reading and understanding the function is almost impossible. To help with this, factor out the two pass loop that adds the disks to the array. This moves about 160 lines into three new helper functions and removes a bunch of local variables from the main Create function. The main new helper function add_disks() does the two pass loop and calls into add_disk_to_super() and update_metadata(). Factoring out the latter two helpers also helps to reduce a ton of indentation. No functional changes intended. Signed-off-by: Logan Gunthorpe Acked-by: Kinga Tanska Reviewed-by: Xiao Ni Reviewed-by: Chaitanya Kulkarni Acked-by: Coly Li --- Create.c | 382 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 213 insertions(+), 169 deletions(-) diff --git a/Create.c b/Create.c index 8ded81dc265d..6a0446644e04 100644 --- a/Create.c +++ b/Create.c @@ -91,6 +91,214 @@ int default_layout(struct supertype *st, int level, int verbose) return layout; } +static int add_disk_to_super(int mdfd, struct shape *s, struct context *c, + struct supertype *st, struct mddev_dev *dv, + struct mdinfo *info, int have_container, int major_num) +{ + dev_t rdev; + int fd; + + if (dv->disposition == 'j') { + info->disk.raid_disk = MD_DISK_ROLE_JOURNAL; + info->disk.state = (1<disk.raid_disk < s->raiddisks) { + info->disk.state = (1<disk.state = 0; + } + + if (dv->writemostly == FlagSet) { + if (major_num == BITMAP_MAJOR_CLUSTERED) { + pr_err("Can not set %s --write-mostly with a clustered bitmap\n",dv->devname); + return 1; + } else { + info->disk.state |= (1<failfast == FlagSet) + info->disk.state |= (1<ss->external && st->container_devnm[0]) + fd = open(dv->devname, O_RDWR); + else + fd = open(dv->devname, O_RDWR|O_EXCL); + + if (fd < 0) { + pr_err("failed to open %s after earlier success - aborting\n", + dv->devname); + return 1; + } + if (!fstat_is_blkdev(fd, dv->devname, &rdev)) + return 1; + info->disk.major = major(rdev); + info->disk.minor = minor(rdev); + } + if (fd >= 0) + remove_partitions(fd); + if (st->ss->add_to_super(st, &info->disk, fd, dv->devname, + dv->data_offset)) { + ioctl(mdfd, STOP_ARRAY, NULL); + return 1; + } + st->ss->getinfo_super(st, info, NULL); + + if (have_container && c->verbose > 0) + pr_err("Using %s for device %d\n", + map_dev(info->disk.major, info->disk.minor, 0), + info->disk.number); + + if (!have_container) { + /* getinfo_super might have lost these ... */ + info->disk.major = major(rdev); + info->disk.minor = minor(rdev); + } + + return 0; +} + +static int update_metadata(int mdfd, struct shape *s, struct supertype *st, + struct map_ent **map, struct mdinfo *info, + char *chosen_name) +{ + struct mdinfo info_new; + struct map_ent *me = NULL; + + /* check to see if the uuid has changed due to these + * metadata changes, and if so update the member array + * and container uuid. Note ->write_init_super clears + * the subarray cursor such that ->getinfo_super once + * again returns container info. + */ + st->ss->getinfo_super(st, &info_new, NULL); + if (st->ss->external && is_container(s->level) && + !same_uuid(info_new.uuid, info->uuid, 0)) { + map_update(map, fd2devnm(mdfd), + info_new.text_version, + info_new.uuid, chosen_name); + me = map_by_devnm(map, st->container_devnm); + } + + if (st->ss->write_init_super(st)) { + st->ss->free_super(st); + return 1; + } + + /* + * Before activating the array, perform extra steps + * required to configure the internal write-intent + * bitmap. + */ + if (info_new.consistency_policy == CONSISTENCY_POLICY_BITMAP && + st->ss->set_bitmap && st->ss->set_bitmap(st, info)) { + st->ss->free_super(st); + return 1; + } + + /* update parent container uuid */ + if (me) { + char *path = xstrdup(me->path); + + st->ss->getinfo_super(st, &info_new, NULL); + map_update(map, st->container_devnm, info_new.text_version, + info_new.uuid, path); + free(path); + } + + flush_metadata_updates(st); + st->ss->free_super(st); + + return 0; +} + +static int add_disks(int mdfd, struct mdinfo *info, struct shape *s, + struct context *c, struct supertype *st, + struct map_ent **map, struct mddev_dev *devlist, + int total_slots, int have_container, int insert_point, + int major_num, char *chosen_name) +{ + struct mddev_dev *moved_disk = NULL; + int pass, raid_disk_num, dnum; + struct mddev_dev *dv; + struct mdinfo *infos; + int ret = 0; + + infos = xmalloc(sizeof(*infos) * total_slots); + enable_fds(total_slots); + for (pass = 1; pass <= 2; pass++) { + for (dnum = 0, raid_disk_num = 0, dv = devlist; dv; + dv = (dv->next) ? (dv->next) : moved_disk, dnum++) { + if (dnum >= total_slots) + abort(); + if (dnum == insert_point) { + raid_disk_num += 1; + moved_disk = dv; + continue; + } + if (strcasecmp(dv->devname, "missing") == 0) { + raid_disk_num += 1; + continue; + } + if (have_container) + moved_disk = NULL; + if (have_container && dnum < total_slots - 1) + /* repeatedly use the container */ + moved_disk = dv; + + switch(pass) { + case 1: + infos[dnum] = *info; + infos[dnum].disk.number = dnum; + infos[dnum].disk.raid_disk = raid_disk_num++; + + if (dv->disposition == 'j') + raid_disk_num--; + + ret = add_disk_to_super(mdfd, s, c, st, dv, + &infos[dnum], have_container, + major_num); + if (ret) + goto out; + + break; + case 2: + infos[dnum].errors = 0; + + ret = add_disk(mdfd, st, info, &infos[dnum]); + if (ret) { + pr_err("ADD_NEW_DISK for %s failed: %s\n", + dv->devname, strerror(errno)); + if (errno == EINVAL && + info->array.level == 0) { + pr_err("Possibly your kernel doesn't support RAID0 layouts.\n"); + pr_err("Either upgrade, or use --layout=dangerous\n"); + } + goto out; + } + break; + } + if (!have_container && + dv == moved_disk && dnum != insert_point) break; + } + + if (pass == 1) { + ret = update_metadata(mdfd, s, st, map, info, + chosen_name); + if (ret) + goto out; + } + } + +out: + free(infos); + return ret; +} + int Create(struct supertype *st, char *mddev, char *name, int *uuid, int subdevs, struct mddev_dev *devlist, @@ -117,7 +325,7 @@ int Create(struct supertype *st, char *mddev, unsigned long long minsize = 0, maxsize = 0; char *mindisc = NULL; char *maxdisc = NULL; - int dnum, raid_disk_num; + int dnum; struct mddev_dev *dv; dev_t rdev; int fail = 0, warn = 0; @@ -126,14 +334,13 @@ int Create(struct supertype *st, char *mddev, int missing_disks = 0; int insert_point = subdevs * 2; /* where to insert a missing drive */ int total_slots; - int pass; int rv; int bitmap_fd; int have_container = 0; int container_fd = -1; int need_mdmon = 0; unsigned long long bitmapsize; - struct mdinfo info, *infos; + struct mdinfo info; int did_default = 0; int do_default_layout = 0; int do_default_chunk = 0; @@ -869,174 +1076,11 @@ int Create(struct supertype *st, char *mddev, } } - infos = xmalloc(sizeof(*infos) * total_slots); - enable_fds(total_slots); - for (pass = 1; pass <= 2; pass++) { - struct mddev_dev *moved_disk = NULL; /* the disk that was moved out of the insert point */ - - for (dnum = 0, raid_disk_num = 0, dv = devlist; dv; - dv = (dv->next) ? (dv->next) : moved_disk, dnum++) { - int fd; - struct mdinfo *inf = &infos[dnum]; - - if (dnum >= total_slots) - abort(); - if (dnum == insert_point) { - raid_disk_num += 1; - moved_disk = dv; - continue; - } - if (strcasecmp(dv->devname, "missing") == 0) { - raid_disk_num += 1; - continue; - } - if (have_container) - moved_disk = NULL; - if (have_container && dnum < info.array.raid_disks - 1) - /* repeatedly use the container */ - moved_disk = dv; - - switch(pass) { - case 1: - *inf = info; - - inf->disk.number = dnum; - inf->disk.raid_disk = raid_disk_num++; - - if (dv->disposition == 'j') { - inf->disk.raid_disk = MD_DISK_ROLE_JOURNAL; - inf->disk.state = (1<disk.raid_disk < s->raiddisks) - inf->disk.state = (1<disk.state = 0; - - if (dv->writemostly == FlagSet) { - if (major_num == BITMAP_MAJOR_CLUSTERED) { - pr_err("Can not set %s --write-mostly with a clustered bitmap\n",dv->devname); - goto abort_locked; - } else - inf->disk.state |= (1<failfast == FlagSet) - inf->disk.state |= (1<ss->external && - st->container_devnm[0]) - fd = open(dv->devname, O_RDWR); - else - fd = open(dv->devname, O_RDWR|O_EXCL); - - if (fd < 0) { - pr_err("failed to open %s after earlier success - aborting\n", - dv->devname); - goto abort_locked; - } - if (!fstat_is_blkdev(fd, dv->devname, &rdev)) - goto abort_locked; - inf->disk.major = major(rdev); - inf->disk.minor = minor(rdev); - } - if (fd >= 0) - remove_partitions(fd); - if (st->ss->add_to_super(st, &inf->disk, - fd, dv->devname, - dv->data_offset)) { - ioctl(mdfd, STOP_ARRAY, NULL); - goto abort_locked; - } - st->ss->getinfo_super(st, inf, NULL); - - if (have_container && c->verbose > 0) - pr_err("Using %s for device %d\n", - map_dev(inf->disk.major, - inf->disk.minor, - 0), dnum); - - if (!have_container) { - /* getinfo_super might have lost these ... */ - inf->disk.major = major(rdev); - inf->disk.minor = minor(rdev); - } - break; - case 2: - inf->errors = 0; - - rv = add_disk(mdfd, st, &info, inf); - - if (rv) { - pr_err("ADD_NEW_DISK for %s failed: %s\n", - dv->devname, strerror(errno)); - if (errno == EINVAL && - info.array.level == 0) { - pr_err("Possibly your kernel doesn't support RAID0 layouts.\n"); - pr_err("Either upgrade, or use --layout=dangerous\n"); - } - goto abort_locked; - } - break; - } - if (!have_container && - dv == moved_disk && dnum != insert_point) break; - } - if (pass == 1) { - struct mdinfo info_new; - struct map_ent *me = NULL; - - /* check to see if the uuid has changed due to these - * metadata changes, and if so update the member array - * and container uuid. Note ->write_init_super clears - * the subarray cursor such that ->getinfo_super once - * again returns container info. - */ - st->ss->getinfo_super(st, &info_new, NULL); - if (st->ss->external && !is_container(s->level) && - !same_uuid(info_new.uuid, info.uuid, 0)) { - map_update(&map, fd2devnm(mdfd), - info_new.text_version, - info_new.uuid, chosen_name); - me = map_by_devnm(&map, st->container_devnm); - } - - if (st->ss->write_init_super(st)) { - st->ss->free_super(st); - goto abort_locked; - } - /* - * Before activating the array, perform extra steps - * required to configure the internal write-intent - * bitmap. - */ - if (info_new.consistency_policy == - CONSISTENCY_POLICY_BITMAP && - st->ss->set_bitmap && - st->ss->set_bitmap(st, &info)) { - st->ss->free_super(st); - goto abort_locked; - } - - /* update parent container uuid */ - if (me) { - char *path = xstrdup(me->path); - - st->ss->getinfo_super(st, &info_new, NULL); - map_update(&map, st->container_devnm, - info_new.text_version, - info_new.uuid, path); - free(path); - } + if (add_disks(mdfd, &info, s, c, st, &map, devlist, total_slots, + have_container, insert_point, major_num, chosen_name)) + goto abort_locked; - flush_metadata_updates(st); - st->ss->free_super(st); - } - } map_unlock(&map); - free(infos); if (is_container(s->level)) { /* No need to start. But we should signal udev to From patchwork Wed Mar 1 20:41:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 13156488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40A54C7EE30 for ; Wed, 1 Mar 2023 20:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229600AbjCAUlr (ORCPT ); Wed, 1 Mar 2023 15:41:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbjCAUlo (ORCPT ); Wed, 1 Mar 2023 15:41:44 -0500 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D056B4D611 for ; Wed, 1 Mar 2023 12:41:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=kBLUrMfj96VnuddDnFW4w0tRfUwNheqenqtSfXWU4CY=; b=ECP/HcGW0UPTZOJYFZaUkOZtqD jdLHsUwSVuHY9/7GgJFFnmzZhVH/Wlp4/LmWFUkEsGF6zXUkPoP6Fmr5YZF86mW4UyJWL3mOf5lGe D1w9Z7hC6/sZDKpgYPAh1huSjqzVOFk/PxCiGKyZD5OVivi4wXxFackIsDT9748Wka0QK7+sPcnKW P2XYVa0MrFuWGnwx/9mGs0Tg3DL1oY37Suh5ZVZ2xxn9SAHjI4KODH7ekmAQfDgs+N8+fSJWFCgjp y0oTwhwiW1WCvtAD8zcxwrZGf96zgbkLILfthlsaC+7Ne7N4KXGe9F+yM6MT23ZX/sL60fqODbVz0 L/ZYcsYg==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pXTGd-006cuC-HR; Wed, 01 Mar 2023 13:41:40 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1pXTGb-000ADp-Hn; Wed, 01 Mar 2023 13:41:37 -0700 From: Logan Gunthorpe To: linux-raid@vger.kernel.org, Jes Sorensen Cc: Guoqing Jiang , Xiao Ni , Mariusz Tkaczyk , Coly Li , Chaitanya Kulkarni , Jonmichael Hands , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Kinga Tanska , Chaitanya Kulkarni Date: Wed, 1 Mar 2023 13:41:32 -0700 Message-Id: <20230301204135.39230-5-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230301204135.39230-1-logang@deltatee.com> References: <20230301204135.39230-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-raid@vger.kernel.org, jes@trained-monkey.org, guoqing.jiang@linux.dev, xni@redhat.com, colyli@suse.de, jm@chia.net, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, mariusz.tkaczyk@linux.intel.com, kinga.tanska@linux.intel.com, chaitanyak@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH mdadm v7 4/7] mdadm: Introduce pr_info() X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org Feedback was given to avoid informational pr_err() calls that print to stderr, even though that's done all through out the code. Using printf() directly doesn't maintain the same format (an "mdadm" prefix on every line. So introduce pr_info() which prints to stdout with the same format and use it for a couple informational pr_err() calls in Create(). Future work can make this call used in more cases. Signed-off-by: Logan Gunthorpe Acked-by: Kinga Tanska Reviewed-by: Xiao Ni Reviewed-by: Chaitanya Kulkarni Acked-by: Coly Li Acked-by: Paul Menzel --- Create.c | 7 ++++--- mdadm.h | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Create.c b/Create.c index 6a0446644e04..4acda30c5256 100644 --- a/Create.c +++ b/Create.c @@ -984,11 +984,12 @@ int Create(struct supertype *st, char *mddev, mdi = sysfs_read(-1, devnm, GET_VERSION); - pr_err("Creating array inside %s container %s\n", + pr_info("Creating array inside %s container %s\n", mdi?mdi->text_version:"managed", devnm); sysfs_free(mdi); } else - pr_err("Defaulting to version %s metadata\n", info.text_version); + pr_info("Defaulting to version %s metadata\n", + info.text_version); } map_update(&map, fd2devnm(mdfd), info.text_version, @@ -1145,7 +1146,7 @@ int Create(struct supertype *st, char *mddev, ioctl(mdfd, RESTART_ARRAY_RW, NULL); } if (c->verbose >= 0) - pr_err("array %s started.\n", mddev); + pr_info("array %s started.\n", mddev); if (st->ss->external && st->container_devnm[0]) { if (need_mdmon) start_mdmon(st->container_devnm); diff --git a/mdadm.h b/mdadm.h index 13f8b4cb5a6b..8bd65fba1887 100644 --- a/mdadm.h +++ b/mdadm.h @@ -1852,6 +1852,8 @@ static inline int xasprintf(char **strp, const char *fmt, ...) { #endif #define cont_err(fmt ...) fprintf(stderr, " " fmt) +#define pr_info(fmt, args...) printf("%s: "fmt, Name, ##args) + void *xmalloc(size_t len); void *xrealloc(void *ptr, size_t len); void *xcalloc(size_t num, size_t size); From patchwork Wed Mar 1 20:41:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 13156491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 633E0C7EE30 for ; Wed, 1 Mar 2023 20:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbjCAUlw (ORCPT ); Wed, 1 Mar 2023 15:41:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbjCAUlp (ORCPT ); Wed, 1 Mar 2023 15:41:45 -0500 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A164DBD9 for ; Wed, 1 Mar 2023 12:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=QIFni+W95awHo5HhIPApV6g4C6FJcsi1PdGBpU2mUgY=; b=tW5fQPo69jgDDs9gW5jsAuIoge ZnhOw8lua9F21NtxPbitXUs6gapGTqKDBa3m5BbQZoVw7mwznFlSKMoJ3pwmkpamrMGuRd5u9EsEp RREcQm4JAzmTPLH1md2AhiS53FiHboA9aF5JIZz0SSQlBktWx3cfvw3QGZBzYpUNoigpi08WzTh7i Neq8DXRealeGb/Ox4+PoTcZYqfG3SWDXKLHPe2/2Vt5PnK3PA4b+PWZPD+RGmWLO7+p27weSP97Ll Ve29I6T0zbC7DU0bph/ukDa7jpZU+kb0nB5uqcP1FljSKarQjPQ8lhMnJcZOReG6W6nT+C3TEERxX /h1qRRyg==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pXTGf-006cu9-2m; Wed, 01 Mar 2023 13:41:42 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1pXTGb-000ADs-LY; Wed, 01 Mar 2023 13:41:37 -0700 From: Logan Gunthorpe To: linux-raid@vger.kernel.org, Jes Sorensen Cc: Guoqing Jiang , Xiao Ni , Mariusz Tkaczyk , Coly Li , Chaitanya Kulkarni , Jonmichael Hands , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Kinga Tanska , Chaitanya Kulkarni Date: Wed, 1 Mar 2023 13:41:33 -0700 Message-Id: <20230301204135.39230-6-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230301204135.39230-1-logang@deltatee.com> References: <20230301204135.39230-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-raid@vger.kernel.org, jes@trained-monkey.org, guoqing.jiang@linux.dev, xni@redhat.com, colyli@suse.de, jm@chia.net, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, mariusz.tkaczyk@linux.intel.com, kinga.tanska@linux.intel.com, chaitanyak@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH mdadm v7 5/7] mdadm: Add --write-zeros option for Create X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org Add the --write-zeros option for Create which will send a write zeros request to all the disks before assembling the array. After zeroing the array, the disks will be in a known clean state and the initial sync may be skipped. Writing zeroes is best used when there is a hardware offload method to zero the data. But even still, zeroing can take several minutes on a large device. Because of this, all disks are zeroed in parallel using their own forked process and a message is printed to the user. The main process will proceed only after all the zeroing processes have completed successfully. Signed-off-by: Logan Gunthorpe Acked-by: Kinga Tanska Reviewed-by: Xiao Ni Reviewed-by: Chaitanya Kulkarni Acked-by: Coly Li --- Create.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- ReadMe.c | 2 + mdadm.c | 9 +++ mdadm.h | 5 ++ 4 files changed, 190 insertions(+), 2 deletions(-) diff --git a/Create.c b/Create.c index 4acda30c5256..bbe9e13dc76d 100644 --- a/Create.c +++ b/Create.c @@ -26,6 +26,10 @@ #include "md_u.h" #include "md_p.h" #include +#include +#include +#include +#include static int round_size_and_verify(unsigned long long *size, int chunk) { @@ -91,9 +95,149 @@ int default_layout(struct supertype *st, int level, int verbose) return layout; } +static pid_t write_zeroes_fork(int fd, struct shape *s, struct supertype *st, + struct mddev_dev *dv) + +{ + const unsigned long long req_size = 1 << 30; + unsigned long long offset_bytes, size_bytes, sz; + sigset_t sigset; + int ret = 0; + pid_t pid; + + size_bytes = KIB_TO_BYTES(s->size); + + /* + * If size_bytes is zero, this is a zoned raid array where + * each disk is of a different size and uses its full + * disk. Thus zero the entire disk. + */ + if (!size_bytes && !get_dev_size(fd, dv->devname, &size_bytes)) + return -1; + + if (dv->data_offset != INVALID_SECTORS) + offset_bytes = SEC_TO_BYTES(dv->data_offset); + else + offset_bytes = SEC_TO_BYTES(st->data_offset); + + pr_info("zeroing data from %lld to %lld on: %s\n", + offset_bytes, size_bytes, dv->devname); + + pid = fork(); + if (pid < 0) { + pr_err("Could not fork to zero disks: %s\n", strerror(errno)); + return pid; + } else if (pid != 0) { + return pid; + } + + sigemptyset(&sigset); + sigaddset(&sigset, SIGINT); + sigprocmask(SIG_UNBLOCK, &sigset, NULL); + + while (size_bytes) { + /* + * Split requests to the kernel into 1GB chunks seeing the + * fallocate() call is not interruptible and blocking a + * ctrl-c for several minutes is not desirable. + * + * 1GB is chosen as a compromise: the user may still have + * to wait several seconds if they ctrl-c on devices that + * zero slowly, but will reduce the number of requests + * required and thus the overhead on devices that perform + * better. + */ + sz = size_bytes; + if (sz >= req_size) + sz = req_size; + + if (fallocate(fd, FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE, + offset_bytes, sz)) { + pr_err("zeroing %s failed: %s\n", dv->devname, + strerror(errno)); + ret = 1; + break; + } + + offset_bytes += sz; + size_bytes -= sz; + } + + exit(ret); +} + +static int wait_for_zero_forks(int *zero_pids, int count) +{ + int wstatus, ret = 0, i, sfd, wait_count = 0; + struct signalfd_siginfo fdsi; + bool interrupted = false; + sigset_t sigset; + ssize_t s; + + for (i = 0; i < count; i++) + if (zero_pids[i]) + wait_count++; + if (!wait_count) + return 0; + + sigemptyset(&sigset); + sigaddset(&sigset, SIGINT); + sigaddset(&sigset, SIGCHLD); + sigprocmask(SIG_BLOCK, &sigset, NULL); + + sfd = signalfd(-1, &sigset, 0); + if (sfd < 0) { + pr_err("Unable to create signalfd: %s\n", strerror(errno)); + return 1; + } + + while (1) { + s = read(sfd, &fdsi, sizeof(fdsi)); + if (s != sizeof(fdsi)) { + pr_err("Invalid signalfd read: %s\n", strerror(errno)); + close(sfd); + return 1; + } + + if (fdsi.ssi_signo == SIGINT) { + printf("\n"); + pr_info("Interrupting zeroing processes, please wait...\n"); + interrupted = true; + } else if (fdsi.ssi_signo == SIGCHLD) { + if (!--wait_count) + break; + } + } + + close(sfd); + + for (i = 0; i < count; i++) { + if (!zero_pids[i]) + continue; + + waitpid(zero_pids[i], &wstatus, 0); + zero_pids[i] = 0; + if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus)) + ret = 1; + } + + if (interrupted) { + pr_err("zeroing interrupted!\n"); + return 1; + } + + if (ret) + pr_err("zeroing failed!\n"); + else + pr_info("zeroing finished\n"); + + return ret; +} + static int add_disk_to_super(int mdfd, struct shape *s, struct context *c, struct supertype *st, struct mddev_dev *dv, - struct mdinfo *info, int have_container, int major_num) + struct mdinfo *info, int have_container, int major_num, + int *zero_pid) { dev_t rdev; int fd; @@ -148,6 +292,14 @@ static int add_disk_to_super(int mdfd, struct shape *s, struct context *c, } st->ss->getinfo_super(st, info, NULL); + if (fd >= 0 && s->write_zeroes) { + *zero_pid = write_zeroes_fork(fd, s, st, dv); + if (*zero_pid <= 0) { + ioctl(mdfd, STOP_ARRAY, NULL); + return 1; + } + } + if (have_container && c->verbose > 0) pr_err("Using %s for device %d\n", map_dev(info->disk.major, info->disk.minor, 0), @@ -224,10 +376,23 @@ static int add_disks(int mdfd, struct mdinfo *info, struct shape *s, { struct mddev_dev *moved_disk = NULL; int pass, raid_disk_num, dnum; + int zero_pids[total_slots]; struct mddev_dev *dv; struct mdinfo *infos; + sigset_t sigset, orig_sigset; int ret = 0; + /* + * Block SIGINT so the main thread will always wait for the + * zeroing processes when being interrupted. Otherwise the + * zeroing processes will finish their work in the background + * keeping the disk busy. + */ + sigemptyset(&sigset); + sigaddset(&sigset, SIGINT); + sigprocmask(SIG_BLOCK, &sigset, &orig_sigset); + memset(zero_pids, 0, sizeof(zero_pids)); + infos = xmalloc(sizeof(*infos) * total_slots); enable_fds(total_slots); for (pass = 1; pass <= 2; pass++) { @@ -261,7 +426,7 @@ static int add_disks(int mdfd, struct mdinfo *info, struct shape *s, ret = add_disk_to_super(mdfd, s, c, st, dv, &infos[dnum], have_container, - major_num); + major_num, &zero_pids[dnum]); if (ret) goto out; @@ -287,6 +452,10 @@ static int add_disks(int mdfd, struct mdinfo *info, struct shape *s, } if (pass == 1) { + ret = wait_for_zero_forks(zero_pids, total_slots); + if (ret) + goto out; + ret = update_metadata(mdfd, s, st, map, info, chosen_name); if (ret) @@ -295,7 +464,10 @@ static int add_disks(int mdfd, struct mdinfo *info, struct shape *s, } out: + if (ret) + wait_for_zero_forks(zero_pids, total_slots); free(infos); + sigprocmask(SIG_SETMASK, &orig_sigset, NULL); return ret; } diff --git a/ReadMe.c b/ReadMe.c index bd8d50d28661..db251ed2f3d4 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -138,6 +138,7 @@ struct option long_options[] = { {"size", 1, 0, 'z'}, {"auto", 1, 0, Auto}, /* also for --assemble */ {"assume-clean",0,0, AssumeClean }, + {"write-zeroes",0,0, WriteZeroes }, {"metadata", 1, 0, 'e'}, /* superblock format */ {"bitmap", 1, 0, Bitmap}, {"bitmap-chunk", 1, 0, BitmapChunk}, @@ -390,6 +391,7 @@ char Help_create[] = " --write-journal= : Specify journal device for RAID-4/5/6 array\n" " --consistency-policy= : Specify the policy that determines how the array\n" " -k : maintains consistency in case of unexpected shutdown.\n" +" --write-zeroes : Write zeroes to the disks before creating. This will bypass initial sync.\n" "\n" ; diff --git a/mdadm.c b/mdadm.c index 57e8e6fa64b9..4685ad6b06c2 100644 --- a/mdadm.c +++ b/mdadm.c @@ -590,6 +590,10 @@ int main(int argc, char *argv[]) s.assume_clean = 1; continue; + case O(CREATE, WriteZeroes): + s.write_zeroes = 1; + continue; + case O(GROW,'n'): case O(CREATE,'n'): case O(BUILD,'n'): /* number of raid disks */ @@ -1251,6 +1255,11 @@ int main(int argc, char *argv[]) } } + if (s.write_zeroes && !s.assume_clean) { + pr_info("Disk zeroing requested, setting --assume-clean to skip resync\n"); + s.assume_clean = 1; + } + if (!mode && devs_found) { mode = MISC; devmode = 'Q'; diff --git a/mdadm.h b/mdadm.h index 8bd65fba1887..211cfcd54f92 100644 --- a/mdadm.h +++ b/mdadm.h @@ -275,6 +275,9 @@ static inline void __put_unaligned32(__u32 val, void *p) #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) +#define KIB_TO_BYTES(x) ((x) << 10) +#define SEC_TO_BYTES(x) ((x) << 9) + extern const char Name[]; struct md_bb_entry { @@ -435,6 +438,7 @@ extern char Version[], Usage[], Help[], OptionHelp[], */ enum special_options { AssumeClean = 300, + WriteZeroes, BitmapChunk, WriteBehind, ReAdd, @@ -640,6 +644,7 @@ struct shape { int bitmap_chunk; char *bitmap_file; int assume_clean; + bool write_zeroes; int write_behind; unsigned long long size; unsigned long long data_offset; From patchwork Wed Mar 1 20:41:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 13156489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A85BC678D4 for ; Wed, 1 Mar 2023 20:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbjCAUlt (ORCPT ); Wed, 1 Mar 2023 15:41:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbjCAUlo (ORCPT ); Wed, 1 Mar 2023 15:41:44 -0500 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 873FB4DBCD for ; Wed, 1 Mar 2023 12:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=GRnYe8AEcFDL2HVmbgZ2j6ZuzB48ZOMQ4epIhUeq+j8=; b=VZZv9tXJnI5aITW+dUl0ytcz7Z 8Z01PvZ2FKExpAULq5qOvUEigyj1jzQ4GjuzwwxJrd2ihgOgnW+JBEJnGaPn5W06KVmB9TfPsINfG l3d2/Ff25azZehQ+z1hD342O3WKhCOjIbrcVbkSDgClaRSefunfGazdWsh2bLHR79cGsDtkgVDLME Mrfopll3dQiJEJ6k8ZL7fAczZaC6NVeRzv8KPInlgMX3KIqBGkIGGLaEa8BZWt/A3brhBnPtQRnUd JGq5aGWm9xR9Ajhb49Eze7zvNvDhkjcUMt1+PNHaPbi3gnH15Fl38u+IMZZ9R7iBlZ56gkJe6hDEI cQJoQnUw==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pXTGe-006cuC-Br; Wed, 01 Mar 2023 13:41:41 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1pXTGb-000ADv-QO; Wed, 01 Mar 2023 13:41:37 -0700 From: Logan Gunthorpe To: linux-raid@vger.kernel.org, Jes Sorensen Cc: Guoqing Jiang , Xiao Ni , Mariusz Tkaczyk , Coly Li , Chaitanya Kulkarni , Jonmichael Hands , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Kinga Tanska , Chaitanya Kulkarni Date: Wed, 1 Mar 2023 13:41:34 -0700 Message-Id: <20230301204135.39230-7-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230301204135.39230-1-logang@deltatee.com> References: <20230301204135.39230-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-raid@vger.kernel.org, jes@trained-monkey.org, guoqing.jiang@linux.dev, xni@redhat.com, colyli@suse.de, jm@chia.net, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, mariusz.tkaczyk@linux.intel.com, kinga.tanska@linux.intel.com, chaitanyak@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH mdadm v7 6/7] tests/00raid5-zero: Introduce test to exercise --write-zeros. X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org Attempt to create a raid5 array with --write-zeros. If it is successful check the array to ensure it is in sync. If it is unsuccessful and an unsupported error is printed, skip the test. Signed-off-by: Logan Gunthorpe Acked-by: Kinga Tanska Reviewed-by: Xiao Ni Reviewed-by: Chaitanya Kulkarni Acked-by: Coly Li --- tests/00raid5-zero | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/00raid5-zero diff --git a/tests/00raid5-zero b/tests/00raid5-zero new file mode 100644 index 000000000000..7d0f05a12539 --- /dev/null +++ b/tests/00raid5-zero @@ -0,0 +1,12 @@ + +if mdadm -CfR $md0 -l 5 -n3 $dev0 $dev1 $dev2 --write-zeroes ; then + check nosync + echo check > /sys/block/md0/md/sync_action; + check wait +elif grep "zeroing [^ ]* failed: Operation not supported" \ + $targetdir/stderr; then + echo "write-zeros not supported, skipping" +else + echo >&2 "ERROR: mdadm return failure without not supported message" + exit 1 +fi From patchwork Wed Mar 1 20:41:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Gunthorpe X-Patchwork-Id: 13156487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E37C7EE33 for ; Wed, 1 Mar 2023 20:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbjCAUls (ORCPT ); Wed, 1 Mar 2023 15:41:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjCAUlo (ORCPT ); Wed, 1 Mar 2023 15:41:44 -0500 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8730E4DBC8 for ; Wed, 1 Mar 2023 12:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=2Hg3vSAwWQuL/w6wWsKr04np3XKVq0j5C9lulcMzPCg=; b=g8mXUABeqx6ZZJ1n2q9+5qU1L0 hj0DnzmgvPt043BV4sqAGkJXNbZxfGoR/pkJrrhuua/gzcBKmGUE+HqTe6Ox70kDrCa53xuhJaFd1 GuCNgN7wki/rNomKlGZ5sYgP9jHePElYnaOivRKsg8COEZEL/e5bbbYMSt3CysjfN6edWPb/CqNFg rCOc8dEmimpuYq5l+x2u/sLNABwK96HU6ZVViRLcIHsKgMFCNokXqag2YX+bU+88JF36iYUzDcYlT B7IAQu60wMe+ls/KKMExLfmR3gHLuKWMraQDsJA60VvgQl2LotN2O+hCuGa2iirXKffwM08rxH0ze f6h7BnLA==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pXTGe-006cuA-BH; Wed, 01 Mar 2023 13:41:41 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1pXTGb-000ADy-UQ; Wed, 01 Mar 2023 13:41:37 -0700 From: Logan Gunthorpe To: linux-raid@vger.kernel.org, Jes Sorensen Cc: Guoqing Jiang , Xiao Ni , Mariusz Tkaczyk , Coly Li , Chaitanya Kulkarni , Jonmichael Hands , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe , Kinga Tanska , Chaitanya Kulkarni Date: Wed, 1 Mar 2023 13:41:35 -0700 Message-Id: <20230301204135.39230-8-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230301204135.39230-1-logang@deltatee.com> References: <20230301204135.39230-1-logang@deltatee.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-raid@vger.kernel.org, jes@trained-monkey.org, guoqing.jiang@linux.dev, xni@redhat.com, colyli@suse.de, jm@chia.net, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com, mariusz.tkaczyk@linux.intel.com, kinga.tanska@linux.intel.com, chaitanyak@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH mdadm v7 7/7] manpage: Add --write-zeroes option to manpage X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org Document the new --write-zeroes option in the manpage. Signed-off-by: Logan Gunthorpe Acked-by: Kinga Tanska Reviewed-by: Xiao Ni Reviewed-by: Chaitanya Kulkarni Acked-by: Coly Li --- mdadm.8.in | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mdadm.8.in b/mdadm.8.in index 64f71ed1df43..6f0f6c13baf1 100644 --- a/mdadm.8.in +++ b/mdadm.8.in @@ -837,6 +837,22 @@ array is resynced at creation. From Linux version 3.0, .B \-\-assume\-clean can be used with that command to avoid the automatic resync. +.TP +.BR \-\-write-zeroes +When creating an array, send write zeroes requests to all the block +devices. This should zero the data area on all disks such that the +initial sync is not necessary and, if successfull, will behave +as if +.B \-\-assume\-clean +was specified. +.IP +This is intended for use with devices that have hardware offload for +zeroing, but despite this zeroing can still take several minutes for +large disks. Thus a message is printed before and after zeroing and +each disk is zeroed in parallel with the others. +.IP +This is only meaningful with --create. + .TP .BR \-\-backup\-file= This is needed when @@ -1370,7 +1386,7 @@ and .B layout\-alternate options are for RAID0 arrays with non-uniform devices size that were in use before Linux 5.4. If the array was being used with Linux 3.13 or -earlier, then to assemble the array on a new kernel, +earlier, then to assemble the array on a new kernel, .B \-\-update=layout\-original must be given. If the array was created and used with a kernel from Linux 3.14 to Linux 5.3, then