All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Yang Erkun <yangerkun@huaweicloud.com>
Cc: axboe@kernel.dk, ulf.hansson@linaro.org, hch@lst.de,
	yukuai3@huawei.com, houtao1@huawei.com,
	penguin-kernel@i-love.sakura.ne.jp, linux-block@vger.kernel.org,
	yangerkun@huawei.com
Subject: Re: [PATCH] brd: defer automatic disk creation until module initialization succeeds
Date: Mon, 28 Oct 2024 10:44:09 +0100	[thread overview]
Message-ID: <20241028094409.GA31248@lst.de> (raw)
In-Reply-To: <20241028090726.2958921-1-yangerkun@huaweicloud.com>

On Mon, Oct 28, 2024 at 05:07:26PM +0800, Yang Erkun wrote:
> Fix this problem by following what loop_init() does. Besides,
> reintroduce brd_devices_mutex to help serialize modifications to
> brd_list.

This looks generally good.  Minor comments below:

> +	snprintf(buf, DISK_NAME_LEN, "ram%d", i);
> +	mutex_lock(&brd_devices_mutex);
> +	list_for_each_entry(brd, &brd_devices, brd_list) {
> +		if (brd->brd_number == i) {
> +			mutex_unlock(&brd_devices_mutex);
> +			err = -EEXIST;
> +			goto out;

This now prints an error message for an already existing
device, which should not happen for the module_init case,
but will happen all the time for the probe callback, and
is really annoying.  Please drop that part of the change.

> +		}
> +	}
>  	brd = kzalloc(sizeof(*brd), GFP_KERNEL);
> +	if (!brd) {
> +		mutex_unlock(&brd_devices_mutex);
> +		err = -ENOMEM;
> +		goto out;
> +	}
>  	brd->brd_number		= i;
>  	list_add_tail(&brd->brd_list, &brd_devices);
> +	mutex_unlock(&brd_devices_mutex);

And maybe just split the whole locked section into a
brd_find_or_alloc_device helper to make verifying the locking easier?

> +	mutex_lock(&brd_devices_mutex);
>  	list_del(&brd->brd_list);
> +	mutex_unlock(&brd_devices_mutex);
>  	kfree(brd);

> +		mutex_lock(&brd_devices_mutex);
>  		list_del(&brd->brd_list);
> +		mutex_unlock(&brd_devices_mutex);
>  		kfree(brd);

Maybe a brd_free_device helper for this pattern would be nice as well.

> +	brd_check_and_reset_par();
> +	brd_debugfs_dir = debugfs_create_dir("ramdisk_pages", NULL);
>  
>  	if (__register_blkdev(RAMDISK_MAJOR, "ramdisk", brd_probe)) {
> -		err = -EIO;
> -		goto out_free;
> +		pr_info("brd: module NOT loaded !!!\n");
> +		debugfs_remove_recursive(brd_debugfs_dir);
> +		return -EIO;

I'd keep an error handling goto for this to keep the main path
straight.


  reply	other threads:[~2024-10-28  9:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-28  9:07 [PATCH] brd: defer automatic disk creation until module initialization succeeds Yang Erkun
2024-10-28  9:44 ` Christoph Hellwig [this message]
2024-10-28 11:14   ` yangerkun
2024-10-28 11:29   ` Yu Kuai
2024-10-28 16:13     ` Christoph Hellwig
2024-10-29  3:12       ` Yu Kuai

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=20241028094409.GA31248@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=houtao1@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=ulf.hansson@linaro.org \
    --cc=yangerkun@huawei.com \
    --cc=yangerkun@huaweicloud.com \
    --cc=yukuai3@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.