From patchwork Sun May 28 10:19:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9752443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D7E2602F0 for ; Sun, 28 May 2017 10:25:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1505822701 for ; Sun, 28 May 2017 10:25:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09EFE2843F; Sun, 28 May 2017 10:25:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A86C222701 for ; Sun, 28 May 2017 10:25:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751351AbdE1KU5 (ORCPT ); Sun, 28 May 2017 06:20:57 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:34887 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750979AbdE1KUz (ORCPT ); Sun, 28 May 2017 06:20:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=tM8TbuNI5lGFK4ysTgjqchmTPYMcLDzLpyaYPgoFSC8=; b=I5sRpHypB+a1jMrumBL6fKBnA vueguDbyLK7Cn/Mrlij30qr1O2GWSZGj9mu8HFjO7RdB/zcj566B2BhhxYH7y2B/u1bZ9+pyfVzHB 2PJhws8uWhkcR1fTego5aGGp1HylS4O0zCfgWGQkNVuQB90VHDTjXx+926fipS2XmDEWhrfJGNJoo 9uPw/RwO7z9ok930kI+Wo2+k6oIFxkIJKXyokWJNCpfC/YiVb1Qus4rfJWpZjEIYbWeLbKLgLaIQC AGZTJ72j/g6a30RY8oeIuLehPfVfU98PxyDVf+RTNJ73o1eB5MhYmNhZmzm+9lqViFO9dWeiRC44I BpetDt8tw==; Received: from shol69.static.otenet.gr ([83.235.170.67] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1dEvJZ-0005Mp-45; Sun, 28 May 2017 10:20:49 +0000 From: Christoph Hellwig To: Andy Shevchenko , Amir Goldstein , linux-fsdevel@vger.kernel.org Cc: Shaohua Li , Dan Williams , David Howells , Steven Whitehouse , Mimi Zohar , linux-xfs@vger.kernel.org, linux-raid@vger.kernel.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 09/22] uuid: hoist uuid_is_null() helper from libnvdimm Date: Sun, 28 May 2017 13:19:55 +0300 Message-Id: <20170528102008.30276-10-hch@lst.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170528102008.30276-1-hch@lst.de> References: <20170528102008.30276-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hoist the libnvdimm helper as an inline helper to linux/uuid.h using an auxiliary const variable uuid_null in lib/uuid.c. [hch: also add the guid variant. Both do the same but I'd like to keep casts to a minimum] The common helper uses the new abstract type uuid_t * instead of u8 *. Suggested-by: Christoph Hellwig Signed-off-by: Amir Goldstein [hch: added guid_is_null] Signed-off-by: Christoph Hellwig Acked-by: Dan Williams Reviewed-by: Andy Shevchenko --- drivers/nvdimm/btt_devs.c | 9 +-------- include/linux/uuid.h | 13 +++++++++++++ lib/uuid.c | 5 +++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c index ae00dc0d9791..4c989bb9a8a0 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c @@ -222,13 +222,6 @@ struct device *nd_btt_create(struct nd_region *nd_region) return dev; } -static bool uuid_is_null(u8 *uuid) -{ - static const u8 null_uuid[16]; - - return (memcmp(uuid, null_uuid, 16) == 0); -} - /** * nd_btt_arena_is_valid - check if the metadata layout is valid * @nd_btt: device with BTT geometry and backing device info @@ -249,7 +242,7 @@ bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super) if (memcmp(super->signature, BTT_SIG, BTT_SIG_LEN) != 0) return false; - if (!uuid_is_null(super->parent_uuid)) + if (!guid_is_null((guid_t *)&super->parent_uuid)) if (memcmp(super->parent_uuid, parent_uuid, 16) != 0) return false; diff --git a/include/linux/uuid.h b/include/linux/uuid.h index b4b147f52d6c..06224311b0d0 100644 --- a/include/linux/uuid.h +++ b/include/linux/uuid.h @@ -35,6 +35,9 @@ typedef struct { */ #define UUID_STRING_LEN 36 +extern const guid_t guid_null; +extern const uuid_t uuid_null; + static inline bool guid_equal(const guid_t *u1, const guid_t *u2) { return memcmp(u1, u2, sizeof(guid_t)) == 0; @@ -45,6 +48,11 @@ static inline void guid_copy(guid_t *dst, const guid_t *src) memcpy(dst, src, sizeof(guid_t)); } +static inline bool guid_is_null(guid_t *guid) +{ + return guid_equal(guid, &guid_null); +} + static inline bool uuid_equal(const uuid_t *u1, const uuid_t *u2) { return memcmp(u1, u2, sizeof(uuid_t)) == 0; @@ -55,6 +63,11 @@ static inline void uuid_copy(uuid_t *dst, const uuid_t *src) memcpy(dst, src, sizeof(uuid_t)); } +static inline bool uuid_is_null(uuid_t *uuid) +{ + return uuid_equal(uuid, &uuid_null); +} + void generate_random_uuid(unsigned char uuid[16]); extern void guid_gen(guid_t *u); diff --git a/lib/uuid.c b/lib/uuid.c index 003bf6823003..25145bfb0eaa 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -21,6 +21,11 @@ #include #include +const guid_t guid_null; +EXPORT_SYMBOL(guid_null); +const uuid_t uuid_null; +EXPORT_SYMBOL(uuid_null); + const u8 guid_index[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; const u8 uuid_index[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};