linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] uuid: Add helpers for finding UUID from an array
@ 2019-08-27 11:49 Heikki Krogerus
  2019-08-27 11:54 ` Christoph Hellwig
  2019-08-27 14:11 ` Andy Shevchenko
  0 siblings, 2 replies; 4+ messages in thread
From: Heikki Krogerus @ 2019-08-27 11:49 UTC (permalink / raw)
  To: Christoph Hellwig, Andy Shevchenko; +Cc: linux-kernel

Matching function that compares every UUID in an array to a
given UUID with guid_equal().

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
Hi,

I don't have a user for these helpers, but since they are pretty
trivial, I figured that might as well propose them in any case.
Though, I think there was somebody proposing of doing the same thing
that these helpers do at one point, but just the hard way in the
drivers, right Andy?

thanks,
---
 include/linux/uuid.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index 0c631e2a73b6..13e4d99f26dd 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -48,6 +48,16 @@ static inline bool guid_is_null(const guid_t *guid)
 	return guid_equal(guid, &guid_null);
 }
 
+static inline bool guid_match(const guid_t *guids, const guid_t *guid)
+{
+	const guid_t *id;
+
+	for (id = guids; !guid_is_null(id); id++)
+		if (guid_equal(id, guid))
+			return true;
+	return false;
+}
+
 static inline bool uuid_equal(const uuid_t *u1, const uuid_t *u2)
 {
 	return memcmp(u1, u2, sizeof(uuid_t)) == 0;
@@ -63,6 +73,16 @@ static inline bool uuid_is_null(const uuid_t *uuid)
 	return uuid_equal(uuid, &uuid_null);
 }
 
+static inline bool uuid_match(const uuid_t *uuids, const uuid_t *uuid)
+{
+	const uuid_t *id;
+
+	for (id = uuids; !uuid_is_null(id); id++)
+		if (uuid_equal(id, uuid))
+			return true;
+	return false;
+}
+
 void generate_random_uuid(unsigned char uuid[16]);
 
 extern void guid_gen(guid_t *u);
-- 
2.23.0.rc1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] uuid: Add helpers for finding UUID from an array
  2019-08-27 11:49 [PATCH] uuid: Add helpers for finding UUID from an array Heikki Krogerus
@ 2019-08-27 11:54 ` Christoph Hellwig
  2019-08-27 12:26   ` Heikki Krogerus
  2019-08-27 14:11 ` Andy Shevchenko
  1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2019-08-27 11:54 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Christoph Hellwig, Andy Shevchenko, linux-kernel

On Tue, Aug 27, 2019 at 02:49:18PM +0300, Heikki Krogerus wrote:
> Matching function that compares every UUID in an array to a
> given UUID with guid_equal().
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> Hi,
> 
> I don't have a user for these helpers, but since they are pretty
> trivial, I figured that might as well propose them in any case.
> Though, I think there was somebody proposing of doing the same thing
> that these helpers do at one point, but just the hard way in the
> drivers, right Andy?

XFS has something similar in xfs_uuid_mount, except that it also
tracks empty slots.  That beeing said I'm pretty sure if you ask willy
he's suggest to just convert the table to an xarray instead :)

So I'm defintively curious what the users would be where we just check
a table, but don't also add something to the table.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] uuid: Add helpers for finding UUID from an array
  2019-08-27 11:54 ` Christoph Hellwig
@ 2019-08-27 12:26   ` Heikki Krogerus
  0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2019-08-27 12:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Andy Shevchenko, linux-kernel

On Tue, Aug 27, 2019 at 01:54:18PM +0200, Christoph Hellwig wrote:
> On Tue, Aug 27, 2019 at 02:49:18PM +0300, Heikki Krogerus wrote:
> > Matching function that compares every UUID in an array to a
> > given UUID with guid_equal().
> > 
> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > ---
> > Hi,
> > 
> > I don't have a user for these helpers, but since they are pretty
> > trivial, I figured that might as well propose them in any case.
> > Though, I think there was somebody proposing of doing the same thing
> > that these helpers do at one point, but just the hard way in the
> > drivers, right Andy?
> 
> XFS has something similar in xfs_uuid_mount, except that it also
> tracks empty slots.  That beeing said I'm pretty sure if you ask willy
> he's suggest to just convert the table to an xarray instead :)
> 
> So I'm defintively curious what the users would be where we just check
> a table, but don't also add something to the table.

I prepared this patch (already some time ago) as part of a series that
was meant to move the ACPI _DSD uuids "prp_guids" in
drivers/acpi/property.c to the drivers instead (so in practice, get
rid of prp_guids). I never send that series out because it would have
only worked with ACPI enumerated devices, so not with for example PCI
enumerated devices which also may have _DSD device properties.

I'm sending this patch out just because after this I'm dropping it
from my development branch. If somebody else finds it useful, great,
let's push it forward, but if there is nobody interested, or if there
is possibly even better way of handling arrays like prp_guids (please
note that I'm not going to work on that ;-), then let's just forget
about the it.

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] uuid: Add helpers for finding UUID from an array
  2019-08-27 11:49 [PATCH] uuid: Add helpers for finding UUID from an array Heikki Krogerus
  2019-08-27 11:54 ` Christoph Hellwig
@ 2019-08-27 14:11 ` Andy Shevchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2019-08-27 14:11 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Christoph Hellwig, linux-kernel

On Tue, Aug 27, 2019 at 02:49:18PM +0300, Heikki Krogerus wrote:
> Matching function that compares every UUID in an array to a
> given UUID with guid_equal().

> I don't have a user for these helpers, but since they are pretty
> trivial, I figured that might as well propose them in any case.
> Though, I think there was somebody proposing of doing the same thing
> that these helpers do at one point, but just the hard way in the
> drivers, right Andy?


Candidates to use a helper
~~~~~~~~~~~~~~~~~~~~~~~~~~

acpi_is_property_guid(): seems like a candidate
nfit_spa_type(): seems like a candidate

xfs_uuid_unmount(): it looks for dups and holes

lmLogFileSystem(): it looks for holes


Below just users where UUID is a member of structure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

visorbus_match() has two deviations: it uses embedded member and according to
code it allows having duplicate UUIDs, though it seems a side effect of not
strictly written code.

publish_vbus_dev_info()
tee_client_device_match()
hv_vmbus_dev_match()
hv_get_dev_type()
mei_cl_device_find()
ishtp_fw_cl_by_uuid()
is_unsupported_vmbus_devs()

...and few more.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-27 14:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-27 11:49 [PATCH] uuid: Add helpers for finding UUID from an array Heikki Krogerus
2019-08-27 11:54 ` Christoph Hellwig
2019-08-27 12:26   ` Heikki Krogerus
2019-08-27 14:11 ` Andy Shevchenko

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).