All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Alexander Atanasov <alex@zazolabs.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>
Subject: Re: ublk invert part scan bit logic
Date: Thu, 12 Feb 2026 21:17:19 +0800	[thread overview]
Message-ID: <aY3S32Qotb59tAik@fedora> (raw)
In-Reply-To: <9e656591-a57c-474c-b3dd-8ee1f75ca9a7@zazolabs.com>

On Thu, Feb 12, 2026 at 03:08:17PM +0200, Alexander Atanasov wrote:
> Hi,
> 
> On 12.02.26 13:05, Jens Axboe wrote:
> > Hi,
> > 
> > For ublk, there's this logic in in ublk_ctrl_start_dev():
> > 
> > /* Skip partition scan if disabled by user */
> > if (ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN) {
> > 	clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> > } else {
> > 	/* Schedule async partition scan for trusted daemons */
> > 	if (!ub->unprivileged_daemons)
> > 		schedule_work(&ub->partition_scan_work);
> > }
> > 
> > where the
> > 
> > clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> > 
> > seems reversed? Why is GD_SUPPRESS_PART_SCAN being cleared if
> > UBLK_F_NO_AUTO_PART_SCAN is set? Added in:
> > 
> > 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag")
> > 
> 
> There is more to this :
> a comment few lines above states that:
> 	 * For unprivileged daemons, keep GD_SUPPRESS_PART_SCAN set
> 	 * permanently.
> 	 */
> 	set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> 
> next in ublk_partition_scan_work it is
> if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
> it is not used anywhere else but at least for debug it is good to stay
> and align with the comment.

Actually ioctl(BLKRRPART) does require CAP_SYS_ADMIN, so either we
modify above comment or not clear GD_SUPPRESS_PART_SCAN for
ub->unprivileged_daemons.

> 
> So if i've untwisted it right:
> do not clear the bit before scanning and invert logic to clear the
> bit only(enable) scan only if UBLK_F_NO_AUTO_PART_SCAN is not requested
> by the user for a trusted daemon.
> 
> Ming - what do you think?
> 
> -- 
> have fun,
> alex
> 
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3c918db4905c..0d6d840b4f21 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -2361,7 +2361,7 @@ static void ublk_partition_scan_work(struct
> work_struct *work)
>         if (!disk)
>                 return;
> 
> -       if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
> +       if (WARN_ON_ONCE(test_bit(GD_SUPPRESS_PART_SCAN,
>                                              &disk->state)))

This way will fail future ioctl(BLKRRPART).

>                 goto out;
> 
> @@ -4429,13 +4429,13 @@ static int ublk_ctrl_start_dev(struct ublk_device
> *ub,
> 
>         set_bit(UB_STATE_USED, &ub->state);
> 
> -       /* Skip partition scan if disabled by user */
> -       if (ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN) {
> +       /* Skip partition scan if disabled by user only for trusted daemons
> */
> +       if (!ub->unprivileged_daemons &&
> +           !(ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN)) {

The above change looks fine.

> +               /* Enable partition scanning */
>                 clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
> -       } else {
>                 /* Schedule async partition scan for trusted daemons */
> -               if (!ub->unprivileged_daemons)
> -                       schedule_work(&ub->partition_scan_work);
> +               schedule_work(&ub->partition_scan_work);

We shouldn't or can't schedule the part scan work in case of
ub->unprivileged_daemons.

Thanks,
Ming


  reply	other threads:[~2026-02-12 13:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-12 11:05 ublk invert part scan bit logic Jens Axboe
2026-02-12 12:42 ` Ming Lei
2026-02-12 12:48   ` Jens Axboe
2026-02-12 13:02     ` Ming Lei
2026-02-12 14:04       ` Hannes Reinecke
2026-02-12 14:22         ` Ming Lei
2026-02-12 15:06           ` Hannes Reinecke
2026-02-12 18:26           ` Alexander Atanasov
2026-02-12 13:08 ` Alexander Atanasov
2026-02-12 13:17   ` Ming Lei [this message]
2026-02-12 18:03     ` Alexander Atanasov

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=aY3S32Qotb59tAik@fedora \
    --to=ming.lei@redhat.com \
    --cc=alex@zazolabs.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.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 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.