From nobody Mon Oct 6 13:41:21 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A1A9A2E1722; Mon, 21 Jul 2025 17:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753118220; cv=none; b=k7AywPHWRaxXbqsGXByh7uKT81cUqnd+YwEKkB4YLz60GnyTDJzFbKDXmdxTqtilBVi/vXjBy6Y6g9/tgcXm4cFOs8h/PKdbO9MzXyXkNWf1YluZg6v7o1zRRimfTT+6LE0t5tG8goT6cMb54s6+B0NH9ptr6BGkC0qF+GgSZPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753118220; c=relaxed/simple; bh=bWkHncUbHYnUl0jNTrmSEGJ0xFxtkxi421XTKr2yRfk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d5XahZF3zHK368uCvCvmRCqbSnM1yr0cuOSiKPfSBFL1OJhWl/2DGYjzTeAa95GO2dIxfGHnfn0p7QytLsVbcXJ7Kw4bb60IZhzbYywem4sQV1V1JDGlGGnTd55WzE8VqIFk9sPIeuykd15SVMKc/Az3jHN2n9RYTqcc63YKbis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=smSt87PG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="smSt87PG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43681C4CEF4; Mon, 21 Jul 2025 17:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753118220; bh=bWkHncUbHYnUl0jNTrmSEGJ0xFxtkxi421XTKr2yRfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=smSt87PGImxrAS89BsJ8TiTnsqZMNI0eWPLPMondAMta2CowRQ1IPQaO0a1neATeL hBRGXFhopzo57wXadi0SzdlwQ38QqJsMdipFEXiswM5iQryHsJhKVd5aELXBAtCVsc yNJcT26I2REYi2HGT/FqInM9RT8jIk7fkTJVSNBaQgfKQbrtSEKWG+RJFpjsTBlGdT 12rmKR9RLabANZnwLUWek5F4G8SRmvkttRa0+IcY1n6cwMdCYxbgBrPA2He6JH1FiP 2nZAKgBxiH1Fi/82KcZ08Czq3nJMLqlWdRkx2cXRIeye4yRqKCMFZRtOXGPfKCc1N+ WFOj/jUzmjhbw== From: Yu Kuai To: corbet@lwn.net, agk@redhat.co, snitzer@kernel.org, mpatocka@redhat.com, hch@lst.de, song@kernel.org, hare@suse.de Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, yukuai3@huawei.com, yangerkun@huawei.com, yi.zhang@huawei.com, johnny.chenyi@huawei.com Subject: [PATCH v4 05/11] md/md-bitmap: add a new sysfs api bitmap_type Date: Tue, 22 Jul 2025 01:15:51 +0800 Message-ID: <20250721171557.34587-6-yukuai@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250721171557.34587-1-yukuai@kernel.org> References: <20250721171557.34587-1-yukuai@kernel.org> 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 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 --- 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 c0499bd8a2aa..41da352ccbde 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4197,6 +4197,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) { @@ -5761,6 +5841,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.43.0