From: Yu Kuai <yukuai1@huaweicloud.com>
To: Yu Kuai <yukuai@kernel.org>,
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,
yangerkun@huawei.com, yi.zhang@huawei.com,
johnny.chenyi@huawei.com, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v4 11/11] md/md-llbitmap: introduce new lockless bitmap
Date: Fri, 1 Aug 2025 10:00:41 +0800 [thread overview]
Message-ID: <f282237e-be12-b178-0e25-3a73bd20d77c@huaweicloud.com> (raw)
In-Reply-To: <20250721171557.34587-12-yukuai@kernel.org>
Hi,
在 2025/07/22 1:15, Yu Kuai 写道:
> +static int llbitmap_read_sb(struct llbitmap *llbitmap)
> +{
> + struct mddev *mddev = llbitmap->mddev;
> + unsigned long daemon_sleep;
> + unsigned long chunksize;
> + unsigned long events;
> + struct page *sb_page;
> + bitmap_super_t *sb;
> + int ret = -EINVAL;
> +
> + if (!mddev->bitmap_info.offset) {
> + pr_err("md/llbitmap: %s: no super block found", mdname(mddev));
> + return -EINVAL;
> + }
> +
> + sb_page = llbitmap_read_page(llbitmap, 0);
> + if (IS_ERR(sb_page)) {
> + pr_err("md/llbitmap: %s: read super block failed",
> + mdname(mddev));
There should return -EIO directly here.
> + ret = -EIO;
> + goto out;
And the out tag can be removed.
Thanks,
Kuai
> + }
> +
> + sb = kmap_local_page(sb_page);
> + if (sb->magic != cpu_to_le32(BITMAP_MAGIC)) {
> + pr_err("md/llbitmap: %s: invalid super block magic number",
> + mdname(mddev));
> + goto out_put_page;
> + }
> +
> + if (sb->version != cpu_to_le32(BITMAP_MAJOR_LOCKLESS)) {
> + pr_err("md/llbitmap: %s: invalid super block version",
> + mdname(mddev));
> + goto out_put_page;
> + }
> +
> + if (memcmp(sb->uuid, mddev->uuid, 16)) {
> + pr_err("md/llbitmap: %s: bitmap superblock UUID mismatch\n",
> + mdname(mddev));
> + goto out_put_page;
> + }
> +
> + if (mddev->bitmap_info.space == 0) {
> + int room = le32_to_cpu(sb->sectors_reserved);
> +
> + if (room)
> + mddev->bitmap_info.space = room;
> + else
> + mddev->bitmap_info.space = mddev->bitmap_info.default_space;
> + }
> + llbitmap->flags = le32_to_cpu(sb->state);
> + if (test_and_clear_bit(BITMAP_FIRST_USE, &llbitmap->flags)) {
> + ret = llbitmap_init(llbitmap);
> + goto out_put_page;
> + }
> +
> + chunksize = le32_to_cpu(sb->chunksize);
> + if (!is_power_of_2(chunksize)) {
> + pr_err("md/llbitmap: %s: chunksize not a power of 2",
> + mdname(mddev));
> + goto out_put_page;
> + }
> +
> + if (chunksize < DIV_ROUND_UP(mddev->resync_max_sectors,
> + mddev->bitmap_info.space << SECTOR_SHIFT)) {
> + pr_err("md/llbitmap: %s: chunksize too small %lu < %llu / %lu",
> + mdname(mddev), chunksize, mddev->resync_max_sectors,
> + mddev->bitmap_info.space);
> + goto out_put_page;
> + }
> +
> + daemon_sleep = le32_to_cpu(sb->daemon_sleep);
> + if (daemon_sleep < 1 || daemon_sleep > MAX_SCHEDULE_TIMEOUT / HZ) {
> + pr_err("md/llbitmap: %s: daemon sleep %lu period out of range",
> + mdname(mddev), daemon_sleep);
> + goto out_put_page;
> + }
> +
> + events = le64_to_cpu(sb->events);
> + if (events < mddev->events) {
> + pr_warn("md/llbitmap :%s: bitmap file is out of date (%lu < %llu) -- forcing full recovery",
> + mdname(mddev), events, mddev->events);
> + set_bit(BITMAP_STALE, &llbitmap->flags);
> + }
> +
> + sb->sync_size = cpu_to_le64(mddev->resync_max_sectors);
> + mddev->bitmap_info.chunksize = chunksize;
> + mddev->bitmap_info.daemon_sleep = daemon_sleep;
> +
> + llbitmap->barrier_idle = DEFAULT_BARRIER_IDLE;
> + llbitmap->chunksize = chunksize;
> + llbitmap->chunks = DIV_ROUND_UP(mddev->resync_max_sectors, chunksize);
> + llbitmap->chunkshift = ffz(~chunksize);
> + ret = llbitmap_cache_pages(llbitmap);
> +
> +out_put_page:
> + __free_page(sb_page);
> +out:
> + kunmap_local(sb);
> + return ret;
> +}
next prev parent reply other threads:[~2025-08-01 2:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 17:15 [PATCH v4 00/11] md/llbitmap: md/md-llbitmap: introduce a new lockless bitmap Yu Kuai
2025-07-21 17:15 ` [PATCH v4 01/11] md: add a new parameter 'offset' to md_super_write() Yu Kuai
2025-07-21 17:15 ` [PATCH v4 02/11] md: factor out a helper raid_is_456() Yu Kuai
2025-07-21 17:15 ` [PATCH v4 03/11] md/md-bitmap: support discard for bitmap ops Yu Kuai
2025-07-21 17:15 ` [PATCH v4 04/11] md: add a new mddev field 'bitmap_id' Yu Kuai
2025-07-21 17:15 ` [PATCH v4 05/11] md/md-bitmap: add a new sysfs api bitmap_type Yu Kuai
2025-07-21 17:15 ` [PATCH v4 06/11] md/md-bitmap: delay registration of bitmap_ops until creating bitmap Yu Kuai
2025-07-22 6:07 ` Hannes Reinecke
2025-07-21 17:15 ` [PATCH v4 07/11] md/md-bitmap: add a new method skip_sync_blocks() in bitmap_operations Yu Kuai
2025-07-21 17:15 ` [PATCH v4 08/11] md/md-bitmap: add a new method blocks_synced() " Yu Kuai
2025-07-21 17:15 ` [PATCH v4 09/11] md: add a new recovery_flag MD_RECOVERY_LAZY_RECOVER Yu Kuai
2025-07-21 17:15 ` [PATCH v4 10/11] md/md-bitmap: make method bitmap_ops->daemon_work optional Yu Kuai
2025-07-21 17:15 ` [PATCH v4 11/11] md/md-llbitmap: introduce new lockless bitmap Yu Kuai
2025-08-01 2:00 ` Yu Kuai [this message]
2025-07-22 8:29 ` [PATCH v4 00/11] md/llbitmap: md/md-llbitmap: introduce a " Li Nan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f282237e-be12-b178-0e25-3a73bd20d77c@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=agk@redhat.co \
--cc=corbet@lwn.net \
--cc=dm-devel@lists.linux.dev \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=johnny.chenyi@huawei.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
--cc=song@kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai3@huawei.com \
--cc=yukuai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).