From nobody Fri Oct 3 15:32:43 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91D4F2BEFEE; Fri, 29 Aug 2025 08:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756455204; cv=none; b=NZ1bVi0cTUe8ED96H6XDkKvOtvNC/so9zbfoT+nQrjHLVns1ijjo6krty7vimZAvgQj/JLN+uLXXnuqDA52Hy3rAxDYpRAwi8ycvUZC6AzVPWlaZmlxa+tHt/r9VBhape0jOECxqQUe7OQHgASnif+qVs8JsQrALXOL3pDjLsyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756455204; c=relaxed/simple; bh=M5Y9WPsTPOlhH/LEZk1KfLpI+CUDIfIo56iJZ1L59OQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ojwLytyu6FxDsh4XAwlGHMWHZtxDpi+NcBQiR385NrvulmWDSMqDfPDi1On41aOq80mVxrEKETlcK2ARLj0xVTFhhrv70QBPcEqQDjq1g5TDSrOqMJObRSaRCgqspOpe8QdSvOsGOOY62uoamKS5R3Dh0Q7RmbeFcRJpL4Z6tSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4cCrcW4t2gzYQvd2; Fri, 29 Aug 2025 16:13:15 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 3140C1A12BA; Fri, 29 Aug 2025 16:13:14 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgB3wY0RYbFohAO2Ag--.45648S9; Fri, 29 Aug 2025 16:13:13 +0800 (CST) From: Yu Kuai To: hch@infradead.org, xni@redhat.com, colyli@kernel.org, linan122@huawei.com, corbet@lwn.net, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, song@kernel.org, yukuai3@huawei.com, hare@suse.de Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com, johnny.chenyi@huawei.com, hailan@yukuai.org.cn Subject: [PATCH v7 md-6.18 05/11] md/md-bitmap: add a new sysfs api bitmap_type Date: Fri, 29 Aug 2025 16:04:20 +0800 Message-Id: <20250829080426.1441678-6-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250829080426.1441678-1-yukuai1@huaweicloud.com> References: <20250829080426.1441678-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgB3wY0RYbFohAO2Ag--.45648S9 X-Coremail-Antispam: 1UD129KBjvJXoWxKryDWr1rJr1rAry8Gr1fXrb_yoW7ZFWkpF WxKryayrZ5ArsxXr17J3WDuF1SqrWvy39xt3sa93sYkry5WrnxAFyfK3WrtwnrCr95CF47 ZFs8JFWUWryjvF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCY1x0262kKe7AKxVW8ZVWrXwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkE bVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67 AF67kF1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI 42IY6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF 4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBI daVFxhVjvjDU0xZFpf9x0pRQJ5wUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ Content-Type: text/plain; charset="utf-8" From: Yu Kuai The api will be used by mdadm to set bitmap_type while creating new array or assembling array, prepare to add a new bitmap. Currently available options are: cat /sys/block/md0/md/bitmap_type none [bitmap] Signed-off-by: Yu Kuai Reviewed-by: Hannes Reinecke Reviewed-by: Xiao Ni Reviewed-by: Li Nan --- Documentation/admin-guide/md.rst | 73 ++++++++++++++++------------ drivers/md/md.c | 81 ++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 30 deletions(-) diff --git a/Documentation/admin-guide/md.rst b/Documentation/admin-guide/m= d.rst index 4ff2cc291d18..356d2a344f08 100644 --- a/Documentation/admin-guide/md.rst +++ b/Documentation/admin-guide/md.rst @@ -347,6 +347,49 @@ All md devices contain: active-idle like active, but no writes have been seen for a while (safe_mode_= delay). =20 + consistency_policy + This indicates how the array maintains consistency in case of unexpec= ted + shutdown. It can be: + + none + Array has no redundancy information, e.g. raid0, linear. + + resync + Full resync is performed and all redundancy is regenerated when the + array is started after unclean shutdown. + + bitmap + Resync assisted by a write-intent bitmap. + + journal + For raid4/5/6, journal device is used to log transactions and replay + after unclean shutdown. + + ppl + For raid5 only, Partial Parity Log is used to close the write hole = and + eliminate resync. + + The accepted values when writing to this file are ``ppl`` and ``resyn= c``, + used to enable and disable PPL. + + uuid + This indicates the UUID of the array in the following format: + xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + + bitmap_type + [RW] When read, this file will display the current and available + bitmap for this array. The currently active bitmap will be enclosed + in [] brackets. Writing an bitmap name or ID to this file will switch + control of this array to that new bitmap. Note that writing a new + bitmap for created array is forbidden. + + none + No bitmap + bitmap + The default internal bitmap + +If bitmap_type is bitmap, then the md device will also contain: + bitmap/location This indicates where the write-intent bitmap for the array is stored. @@ -401,36 +444,6 @@ All md devices contain: once the array becomes non-degraded, and this fact has been recorded in the metadata. =20 - consistency_policy - This indicates how the array maintains consistency in case of unexpec= ted - shutdown. It can be: - - none - Array has no redundancy information, e.g. raid0, linear. - - resync - Full resync is performed and all redundancy is regenerated when the - array is started after unclean shutdown. - - bitmap - Resync assisted by a write-intent bitmap. - - journal - For raid4/5/6, journal device is used to log transactions and replay - after unclean shutdown. - - ppl - For raid5 only, Partial Parity Log is used to close the write hole = and - eliminate resync. - - The accepted values when writing to this file are ``ppl`` and ``resyn= c``, - used to enable and disable PPL. - - uuid - This indicates the UUID of the array in the following format: - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - - As component devices are added to an md array, they appear in the ``md`` directory as new directories named:: =20 diff --git a/drivers/md/md.c b/drivers/md/md.c index 82c84bdabe79..aeae0d4854dc 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4207,6 +4207,86 @@ new_level_store(struct mddev *mddev, const char *buf= , size_t len) static struct md_sysfs_entry md_new_level =3D __ATTR(new_level, 0664, new_level_show, new_level_store); =20 +static ssize_t +bitmap_type_show(struct mddev *mddev, char *page) +{ + struct md_submodule_head *head; + unsigned long i; + ssize_t len =3D 0; + + if (mddev->bitmap_id =3D=3D ID_BITMAP_NONE) + len +=3D sprintf(page + len, "[none] "); + else + len +=3D sprintf(page + len, "none "); + + xa_lock(&md_submodule); + xa_for_each(&md_submodule, i, head) { + if (head->type !=3D MD_BITMAP) + continue; + + if (mddev->bitmap_id =3D=3D head->id) + len +=3D sprintf(page + len, "[%s] ", head->name); + else + len +=3D sprintf(page + len, "%s ", head->name); + } + xa_unlock(&md_submodule); + + len +=3D sprintf(page + len, "\n"); + return len; +} + +static ssize_t +bitmap_type_store(struct mddev *mddev, const char *buf, size_t len) +{ + struct md_submodule_head *head; + enum md_submodule_id id; + unsigned long i; + int err =3D 0; + + xa_lock(&md_submodule); + + if (mddev->bitmap_ops) { + err =3D -EBUSY; + goto out; + } + + if (cmd_match(buf, "none")) { + mddev->bitmap_id =3D ID_BITMAP_NONE; + goto out; + } + + xa_for_each(&md_submodule, i, head) { + if (head->type =3D=3D MD_BITMAP && cmd_match(buf, head->name)) { + mddev->bitmap_id =3D head->id; + goto out; + } + } + + err =3D kstrtoint(buf, 10, &id); + if (err) + goto out; + + if (id =3D=3D ID_BITMAP_NONE) { + mddev->bitmap_id =3D id; + goto out; + } + + head =3D xa_load(&md_submodule, id); + if (head && head->type =3D=3D MD_BITMAP) { + mddev->bitmap_id =3D id; + goto out; + } + + err =3D -ENOENT; + +out: + xa_unlock(&md_submodule); + return err ? err : len; +} + +static struct md_sysfs_entry md_bitmap_type =3D +__ATTR(bitmap_type, 0664, bitmap_type_show, bitmap_type_store); + static ssize_t layout_show(struct mddev *mddev, char *page) { @@ -5813,6 +5893,7 @@ __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize= _policy_show, static struct attribute *md_default_attrs[] =3D { &md_level.attr, &md_new_level.attr, + &md_bitmap_type.attr, &md_layout.attr, &md_raid_disks.attr, &md_uuid.attr, --=20 2.39.2