Received: from eggs.gnu.org ([2001:4830:134:3::10]:43903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bY65C-000532-90 for qemu-devel@nongnu.org; Fri, 12 Aug 2016 02:36:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bY659-0001Il-At for qemu-devel@nongnu.org; Fri, 12 Aug 2016 02:36:40 -0400 Date: Fri, 12 Aug 2016 14:29:24 +0800 From: Fam Zheng Message-ID: <20160812062924.GE2759@al.usersys.redhat.com> References: <1470977536-18209-1-git-send-email-famz@redhat.com> <1470977536-18209-2-git-send-email-famz@redhat.com> <8dff3fef-5d8b-27e2-bfd7-7cc7bc92cd9c@twiddle.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8dff3fef-5d8b-27e2-bfd7-7cc7bc92cd9c@twiddle.net> Subject: Re: [Qemu-devel] [PATCH v5 1/9] util: Add UUID API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: qemu-devel@nongnu.org, kwolf@redhat.com, qemu-block@nongnu.org, sw@weilnetz.de, jcody@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com, pbonzini@redhat.com, mreitz@redhat.com On Fri, 08/12 07:24, Richard Henderson wrote: > On 08/12/2016 05:52 AM, Fam Zheng wrote: > >+/* Version 4 UUID (pseudo random numbers), RFC4122 4.4. */ > >+ > >+typedef struct { > >+ union { > >+ unsigned char data[16]; > >+ struct { > >+ /* Generated in BE endian, can be swapped with qemu_uuid_bswap. */ > > Nit: BE endian is redundant. big-endian or just BE, please. > > >+ uint32_t time_low; > >+ uint16_t time_mid; > >+ uint16_t time_high_and_version; > >+ uint8_t clock_seq_and_reserved; > >+ uint8_t clock_seq_low; > >+ uint8_t node[6]; > >+ } fields; > >+ }; > >+} QemuUUID; > > Wait, didn't you just tell me that you *couldn't* add this union > because of the packed usage within some file? I was just saying even with this union added, packed usage can still result in unaligned QemuUUID allocation, in theory. That's why I said I could assert too. (In practise the only qemu_uuid_bswap is putting QemuUUID in a packed struct, but that is happily aligned.) > > But of course if you're going to do this, you should actually use these fields, > > >+ /* Set the two most significant bits (bits 6 and 7) of the > >+ clock_seq_hi_and_reserved to zero and one, respectively. */ > >+ uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80; > >+ /* Set the four most significant bits (bits 12 through 15) of the > >+ time_hi_and_version field to the 4-bit version number. > >+ */ > >+ uuid->data[6] = (uuid->data[6] & 0xf) | 0x40; > > Here, Using these fields here requires an extra cpu_to_be16s for no compelling reason, so I refrained to. Fam > > >+void qemu_uuid_bswap(QemuUUID *uuid) > >+{ > >+ assert(QEMU_IS_ALIGNED((uint64_t)uuid, sizeof(uint32_t))); > >+ bswap32s(&uuid->fields.time_low); > >+ bswap16s(&uuid->fields.time_mid); > >+ bswap16s(&uuid->fields.time_high_and_version); > > And then you don't need this assert. > > > r~ >