Linux block layer
 help / color / mirror / Atom feed
From: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Christoph Hellwig <hch@lst.de>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	Jens Axboe <axboe@kernel.dk>,
	Damien Le Moal <Damien.LeMoal@wdc.com>,
	Johannes Thumshirn <Johannes.Thumshirn@wdc.com>
Subject: Re: [PATCH] block: Fix partition check for host-aware zoned block devices
Date: Tue, 19 Oct 2021 09:52:37 +0000	[thread overview]
Message-ID: <20211019095237.ndbi3xarxkddmfut@shindev> (raw)
In-Reply-To: <YWrhCiWGjfxqAca2@casper.infradead.org>

On Oct 16, 2021 / 15:26, Matthew Wilcox wrote:
> On Sat, Oct 16, 2021 at 06:34:50AM +0200, Christoph Hellwig wrote:
> > On Fri, Oct 15, 2021 at 11:07:40AM +0900, Shin'ichiro Kawasaki wrote:
> > > To fix the issues, call the helper function disk_has_partitions() in
> > > place of disk->part_tbl empty check. Since the function was removed with
> > > the commit a33df75c6328, reimplement it to walk through entries in the
> > > xarray disk->part_tbl.
> > 
> > Looks good,
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > 
> > Matthew,
> > 
> > we talked about possiblig adding a xa_nr_entries helper a while ago.
> > This would be a good place for it, as we could just check
> > xa_nr_entries() > 1 for example.
> 
> Do I understand the problem correctly, that you don't actually want to
> know whether there's more than one entry in the array, but rather that
> there's an entry at an index other than 0?
> 
> If so, that's an easy question to answer, we just don't have a helper
> for it yet.  Something like this should do:
> 
> static inline bool xa_is_trivial(const struct xarray *xa)
> {
> 	void *entry = READ_ONCE(xa->xa_head);
> 
> 	return entry || !xa_is_node(entry);
> }
> 
> Probably needs a better name than that.

Thanks for the discussion. Based on the code above, I tried following hunk
below, and confirmed the new helper function can be used to fix the issue I
found. Good. To make it work, I needed to change the logical operator in the
function from OR to AND. As for the function name, my mere suggestion is
xa_has_single_entry(), but this may not be the best.

I would like to ask advice on the next action for the fix. If my original patch
can go to upstream first, I think the changes for this new xarray helper can be
done later. This approach would be good if the new helper will not be propagated
to the stable branches. Another approach is to do both of this new helper
introduction and the issue fix at this moment. Which approach is the better?


diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index a91e3d90df8a..7a31c9423d01 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -1238,6 +1238,20 @@ static inline unsigned long xa_to_sibling(const void *entry)
 	return xa_to_internal(entry);
 }
 
+/**
+ * xa_has_single_entry() - Does it have an entry at an index other than 0?
+ * @entry: XArray entry.
+ *
+ * Context: Any context.
+ * Return: %true if there is no entry at an index other than 0.
+ */
+static inline bool xa_has_single_entry(const struct xarray *xa)
+{
+	const void *entry = READ_ONCE(xa->xa_head);
+
+	return entry && !xa_is_node(entry);
+}
+
 /**
  * xa_is_sibling() - Is the entry a sibling entry?
  * @entry: Entry retrieved from the XArray


-- 
Best Regards,
Shin'ichiro Kawasaki

      parent reply	other threads:[~2021-10-19  9:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15  2:07 [PATCH] block: Fix partition check for host-aware zoned block devices Shin'ichiro Kawasaki
2021-10-15  7:32 ` Johannes Thumshirn
2021-10-16  4:34 ` Christoph Hellwig
2021-10-16 14:26   ` Matthew Wilcox
2021-10-18  8:22     ` Christoph Hellwig
2021-10-19  9:52     ` Shinichiro Kawasaki [this message]

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=20211019095237.ndbi3xarxkddmfut@shindev \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=willy@infradead.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