public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] uuid: Add inline helpers to operate on raw buffers
@ 2019-07-16 15:04 Andy Shevchenko
  2019-07-16 15:04 ` [PATCH v2 2/3] Btrfs: Switch to use new generic UUID API Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Andy Shevchenko @ 2019-07-16 15:04 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Lu Fengqi, linux-btrfs,
	Christoph Hellwig
  Cc: Andy Shevchenko, David Sterba

Sometimes we may need to copy UUID from or to the raw buffer, which
is provided outside of kernel and can't be declared as UUID type.
With current API this operation will require an explicit casting
to one of UUID types and length, that is always a constant
derived as sizeof of the certain UUID type.

Provide a helpful set of inline helpers to minimize developer's effort
in the cases when raw buffers are involved.

Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/uuid.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/include/linux/uuid.h b/include/linux/uuid.h
index 0c631e2a73b6..b8e431d65222 100644
--- a/include/linux/uuid.h
+++ b/include/linux/uuid.h
@@ -43,11 +43,26 @@ static inline void guid_copy(guid_t *dst, const guid_t *src)
 	memcpy(dst, src, sizeof(guid_t));
 }
 
+static inline void guid_copy_from_raw(guid_t *dst, const __u8 *src)
+{
+	memcpy(dst, (const guid_t *)src, sizeof(guid_t));
+}
+
+static inline void guid_copy_to_raw(__u8 *dst, const guid_t *src)
+{
+	memcpy((guid_t *)dst, src, sizeof(guid_t));
+}
+
 static inline bool guid_is_null(const guid_t *guid)
 {
 	return guid_equal(guid, &guid_null);
 }
 
+static inline bool guid_is_null_raw(const __u8 *guid)
+{
+	return guid_equal((const guid_t *)guid, &guid_null);
+}
+
 static inline bool uuid_equal(const uuid_t *u1, const uuid_t *u2)
 {
 	return memcmp(u1, u2, sizeof(uuid_t)) == 0;
@@ -58,16 +73,41 @@ static inline void uuid_copy(uuid_t *dst, const uuid_t *src)
 	memcpy(dst, src, sizeof(uuid_t));
 }
 
+static inline void uuid_copy_from_raw(uuid_t *dst, const __u8 *src)
+{
+	memcpy(dst, (const uuid_t *)src, sizeof(uuid_t));
+}
+
+static inline void uuid_copy_to_raw(__u8 *dst, const uuid_t *src)
+{
+	memcpy((uuid_t *)dst, src, sizeof(uuid_t));
+}
+
 static inline bool uuid_is_null(const uuid_t *uuid)
 {
 	return uuid_equal(uuid, &uuid_null);
 }
 
+static inline bool uuid_is_null_raw(const __u8 *uuid)
+{
+	return uuid_equal((const uuid_t *)uuid, &uuid_null);
+}
+
 void generate_random_uuid(unsigned char uuid[16]);
 
 extern void guid_gen(guid_t *u);
 extern void uuid_gen(uuid_t *u);
 
+static inline void guid_gen_raw(__u8 *guid)
+{
+	guid_gen((guid_t *)guid);
+}
+
+static inline void uuid_gen_raw(__u8 *uuid)
+{
+	uuid_gen((uuid_t *)uuid);
+}
+
 bool __must_check uuid_is_valid(const char *uuid);
 
 extern const u8 guid_index[16];
-- 
2.20.1


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

end of thread, other threads:[~2019-07-18 17:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-16 15:04 [PATCH v2 1/3] uuid: Add inline helpers to operate on raw buffers Andy Shevchenko
2019-07-16 15:04 ` [PATCH v2 2/3] Btrfs: Switch to use new generic UUID API Andy Shevchenko
2019-07-16 15:04 ` [PATCH v2 3/3] uuid: Remove no more needed macro Andy Shevchenko
2019-07-16 15:11 ` [PATCH v2 1/3] uuid: Add inline helpers to operate on raw buffers Christoph Hellwig
2019-07-16 15:22   ` Andy Shevchenko
2019-07-17 15:37     ` David Sterba
2019-07-17 15:53       ` Andy Shevchenko
2019-07-18  5:39       ` Christoph Hellwig
2019-07-18 17:52         ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox