From patchwork Wed Nov 13 22:33:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Harper X-Patchwork-Id: 3179891 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8684FC045B for ; Wed, 13 Nov 2013 22:33:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D8D120939 for ; Wed, 13 Nov 2013 22:33:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 976D720124 for ; Wed, 13 Nov 2013 22:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751047Ab3KMWd2 (ORCPT ); Wed, 13 Nov 2013 17:33:28 -0500 Received: from mail.bendigoit.com.au ([203.16.207.99]:42533 "EHLO smtp2.bendigoit.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751003Ab3KMWd1 convert rfc822-to-8bit (ORCPT ); Wed, 13 Nov 2013 17:33:27 -0500 Received: from bitcom1.int.sbss.com.au ([2002:cb10:e0fe:201:a5ca:4fd3:14f:ad5d]) by smtp2.bendigoit.com.au with esmtp (Exim 4.80) (envelope-from ) id 1Vgj00-0004aD-AO; Thu, 14 Nov 2013 09:33:24 +1100 Received: from BITCOM1.int.sbss.com.au ([fe80::a5ca:4fd3:14f:ad5d]) by BITCOM1.int.sbss.com.au ([fe80::a5ca:4fd3:14f:ad5d%12]) with mapi id 14.01.0438.000; Thu, 14 Nov 2013 09:33:23 +1100 From: James Harper To: Noah Watkins CC: Sage Weil , "ceph-devel@vger.kernel.org" Subject: RE: libuuid vs boost uuid Thread-Topic: libuuid vs boost uuid Thread-Index: Ac7dDndGMWCVRI2JS9GPS/QNk6ripf//WLsA//4LABCAA3B/AIAFWoQA//7Zb/CAAZraAP//RJqQ Date: Wed, 13 Nov 2013 22:33:22 +0000 Message-ID: <6035A0D088A63A46850C3988ED045A4B665EA52D@BITCOM1.int.sbss.com.au> References: <6035A0D088A63A46850C3988ED045A4B665E1FB8@BITCOM1.int.sbss.com.au> <6035A0D088A63A46850C3988ED045A4B665E29B6@BITCOM1.int.sbss.com.au> <6035A0D088A63A46850C3988ED045A4B665EA2F6@BITCOM1.int.sbss.com.au> <3C1A0909-F08C-44EE-AF1A-61E91460C764@inktank.com> In-Reply-To: <3C1A0909-F08C-44EE-AF1A-61E91460C764@inktank.com> Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [2002:cb10:e0fe:301:b06a:6e10:4628:b37f] x-tm-as-product-ver: SMEX-10.2.0.3176-7.000.1014-20290.002 x-tm-as-result: No--38.765500-0.000000-31 x-tm-as-user-approved-sender: Yes x-tm-as-user-blocked-sender: No MIME-Version: 1.0 X-Really-From-Bendigo-IT: magichashvalue Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch follows. When I wrote it I was just thinking it would be used for win32 build, hence the #ifdef. As I said before, it compiles but I haven't tested it. I can clean it up a bit and resend it with a signed-off-by if anyone wants to pick it up and follow it through sooner than I can. I don't know how boost behaves if the uuid parse fails (exception maybe?) so that would need resolving too. In addition, a bunch of ceph files include the libuuid header directly, even though all the ones I've found don't appear to need it, so they need to be fixed for a clean compile under win32, and to remove dependency on libuuid. There may also be other cases that need work, in particular anything that memcpy's into the 16 byte uuid directly. See patch for MStatfsReply.h where a minor tweak was necessary. (if anyone is interested, I have librados and librbd compiling under mingw32, but I can't get boost to build its thread library so I don't get a clean link, and there are probably other link errors too. I've run out of time for doing much more on this for the moment) James --- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/include/uuid.h b/src/include/uuid.h index 942b807..201ac76 100644 --- a/src/include/uuid.h +++ b/src/include/uuid.h @@ -8,6 +8,70 @@ #include "encoding.h" #include +#if defined(_WIN32) + +#include +#include +#include +#include +#include + +struct uuid_d { + boost::uuids::uuid uuid; + + uuid_d() { + uuid = boost::uuids::nil_uuid(); + } + + bool is_zero() const { + return uuid.is_nil(); + //return boost::uuids::uuid::is_nil(uuid); + } + + void generate_random() { + boost::uuids::random_generator gen; + uuid = gen(); + } + + bool parse(const char *s) { + boost::uuids::string_generator gen; + uuid = gen(s); + return true; + // what happens if parse fails? + } + void print(char *s) { + std::string str = boost::lexical_cast(uuid); + memcpy(s, str.c_str(), 37); + } + + void encode(bufferlist& bl) const { + ::encode_raw(uuid, bl); + } + void decode(bufferlist::iterator& p) const { + ::decode_raw(uuid, p); + } + + uuid_d& operator=(const uuid_d& r) { + uuid = r.uuid; + return *this; + } +}; +WRITE_CLASS_ENCODER(uuid_d) + +inline std::ostream& operator<<(std::ostream& out, const uuid_d& u) { + //char b[37]; diff --git a/src/include/uuid.h b/src/include/uuid.h index 942b807..201ac76 100644 --- a/src/include/uuid.h +++ b/src/include/uuid.h @@ -8,6 +8,70 @@ #include "encoding.h" #include +#if defined(_WIN32) + +#include +#include +#include +#include +#include + +struct uuid_d { + boost::uuids::uuid uuid; + + uuid_d() { + uuid = boost::uuids::nil_uuid(); + } + + bool is_zero() const { + return uuid.is_nil(); + //return boost::uuids::uuid::is_nil(uuid); + } + + void generate_random() { + boost::uuids::random_generator gen; + uuid = gen(); + } + + bool parse(const char *s) { + boost::uuids::string_generator gen; + uuid = gen(s); + return true; + // what happens if parse fails? + } + void print(char *s) { + std::string str = boost::lexical_cast(uuid); + memcpy(s, str.c_str(), 37); + } + + void encode(bufferlist& bl) const { + ::encode_raw(uuid, bl); + } + void decode(bufferlist::iterator& p) const { + ::decode_raw(uuid, p); + } + + uuid_d& operator=(const uuid_d& r) { + uuid = r.uuid; + return *this; + } +}; +WRITE_CLASS_ENCODER(uuid_d) + +inline std::ostream& operator<<(std::ostream& out, const uuid_d& u) { + //char b[37]; + //uuid_unparse(u.uuid, b); + return out << u.uuid; +} + +inline bool operator==(const uuid_d& l, const uuid_d& r) { + return l.uuid == r.uuid; +} + +inline bool operator!=(const uuid_d& l, const uuid_d& r) { + return l.uuid != r.uuid; +} +#else extern "C" { #include #include @@ -56,6 +120,6 @@ inline bool operator==(const uuid_d& l, const uuid_d& r) { inline bool operator!=(const uuid_d& l, const uuid_d& r) { return uuid_compare(l.uuid, r.uuid) != 0; } - +#endif #endif diff --git a/src/messages/MStatfsReply.h b/src/messages/MStatfsReply.h index 8ceec9c..40a5bdd 100644 --- a/src/messages/MStatfsReply.h +++ b/src/messages/MStatfsReply.h @@ -22,7 +22,7 @@ public: MStatfsReply() : Message(CEPH_MSG_STATFS_REPLY) {} MStatfsReply(uuid_d &f, tid_t t, epoch_t epoch) : Message(CEPH_MSG_STATFS_REPLY) { - memcpy(&h.fsid, f.uuid, sizeof(h.fsid)); + memcpy(&h.fsid, &f.uuid, sizeof(h.fsid)); header.tid = t; h.version = epoch; }