From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Egger Subject: Re: [PATCH] blktap2: portability fixes Date: Wed, 24 Jun 2009 15:57:13 +0200 Message-ID: <200906241557.13912.Christoph.Egger@amd.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary-00=_5CjQKeSDu6/trqw" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org --Boundary-00=_5CjQKeSDu6/trqw Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Oh, indeed! It's always good to have a second pair of eyes over it. Attached patch implements blk_uuid_to_string() for NetBSD correctly. I hope, this is the last iteration over blktap2. Signed-off-by: Christoph Egger On Wednesday 24 June 2009 15:07:50 Keir Fraser wrote: > I changed this some and applied as c/s 19832. Of particular note is that > your definition of blk_uuid_to_string() was very broken; all that could be > said of it is that it builds, but it was fundamentally broken for both > Linux and NetBSD. Note that uuid_to_string() itself allocates a string > buffer and returns a pointer to it -- so you need to copy that string to > the buffer passed to blk_uuid_to_string() and then free it. I didn't > implement that bit for you, so you need to provide a patch to fix NetBSD's > blk_uuid_to_string(). > > -- Keir > > On 24/06/2009 13:24, "Christoph Egger" wrote: > > Patch is attached. > > uuid is totally different in Linux and in NetBSD. > > uuid_t is a char array in Linux and a struct in NetBSD. > > Making NetBSD uuid look like Linux uuid doesn't work at all and > > neither the other way around. > > I renamed your uuid.h header to avoid a recursive inclusion > > of the same header. > > I created an uuid abstraction with a Linux and NetBSD implementation. > > > > I also fixed a bug in vhd_create_batmap() which slipped in previously. > > iconv() is a bit nasty to make it compile on both NetBSD and Linux. > > > > Signed-off-by: Christoph Egger > > > > On Tuesday 23 June 2009 18:25:19 Keir Fraser wrote: > >> This didn't have a prayer of building on Linux. I fixed it up for Linux > >> and applied as c/s 19817. It's probably broken for netbsd now, but you > >> should be able to provide a small fixup patch for that. > >> > >> -- Keir > >> > >> On 23/06/2009 13:29, "Christoph Egger" wrote: > >>> Hi! > >>> > >>> Attached patch makes blktap2 build on NetBSD. > >>> > >>> - Use standard off_t and lseek() instead of non-portable off64_t and > >>> lseek64() - Use uuid API as documented in DCE 1.1 RPC specification > >>> - Add NetBSD implementation for blk_getimagesize() and > >>> blk_getsectorsize() - Use blk_getimagesize() and blk_getsectorsize() > >>> - Fix uuid header check > >>> > >>> Signed-off-by: Christoph Egger -- ---to satisfy European Law for business letters: Advanced Micro Devices GmbH Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Thomas M. McCoy, Giuliano Meroni Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632 --Boundary-00=_5CjQKeSDu6/trqw Content-Type: text/x-diff; charset="iso-8859-1"; name="xen_blktap2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xen_blktap2.diff" diff -r f1fec38c8228 tools/blktap2/include/blk_uuid.h --- a/tools/blktap2/include/blk_uuid.h Wed Jun 24 14:03:20 2009 +0100 +++ b/tools/blktap2/include/blk_uuid.h Wed Jun 24 15:45:27 2009 +0200 @@ -45,7 +45,7 @@ static inline void blk_uuid_generate(blk uuid_generate(uuid->uuid); } -static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out) +static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size) { uuid_unparse(uuid->uuid, out); } @@ -74,6 +74,7 @@ static inline int blk_uuid_compare(blk_u #include #include +#include typedef uuid_t blk_uuid_t; @@ -89,10 +90,13 @@ static inline void blk_uuid_generate(blk uuid_create((uuid_t *)uuid, &status); } -static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out) +static inline void blk_uuid_to_string(blk_uuid_t *uuid, char *out, size_t size) { uint32_t status; - uuid_to_string((uuid_t *)uuid, &out, &status); + char *_out = NULL; + uuid_to_string((uuid_t *)uuid, &_out, &status); + strlcpy(out, _out, size); + free(_out); } static inline void blk_uuid_from_string(blk_uuid_t *uuid, const char *in) diff -r f1fec38c8228 tools/blktap2/vhd/lib/libvhd.c --- a/tools/blktap2/vhd/lib/libvhd.c Wed Jun 24 14:03:20 2009 +0100 +++ b/tools/blktap2/vhd/lib/libvhd.c Wed Jun 24 15:45:27 2009 +0200 @@ -1335,7 +1335,7 @@ vhd_macx_encode_location(char *name, cha snprintf(uri, ibl+1, "file://%s", name); if (iconv(cd, -#if defined(__linux__) || (__Linux__) +#if defined(__linux__) || defined(__Linux__) (char **) #endif &urip, &ibl, &uri_utf8p, &obl) == (size_t)-1 || @@ -1425,7 +1425,7 @@ vhd_w2u_encode_location(char *name, char } if (iconv(cd, -#if defined(__linux__) || (__Linux__) +#if defined(__linux__) || defined(__Linux__) (char **) #endif &urip, &ibl, &uri_utf16p, &obl) == (size_t)-1 || diff -r f1fec38c8228 tools/blktap2/vhd/lib/vhd-util-read.c --- a/tools/blktap2/vhd/lib/vhd-util-read.c Wed Jun 24 14:03:20 2009 +0100 +++ b/tools/blktap2/vhd/lib/vhd-util-read.c Wed Jun 24 15:45:27 2009 +0200 @@ -78,7 +78,7 @@ vhd_print_header(vhd_context_t *vhd, vhd (err ? "failed to read name" : name)); free(name); - blk_uuid_to_string(&h->prt_uuid, uuid); + blk_uuid_to_string(&h->prt_uuid, uuid, sizeof(uuid)); printf("Parent UUID : %s\n", uuid); vhd_time_to_string(h->prt_ts, time_str); @@ -153,7 +153,7 @@ vhd_print_footer(vhd_footer_t *f, int he printf("Checksum : 0x%x|0x%x (%s)\n", f->checksum, cksm, f->checksum == cksm ? "Good!" : "Bad!"); - blk_uuid_to_string(&f->uuid, uuid); + blk_uuid_to_string(&f->uuid, uuid, sizeof(uuid)); printf("UUID : %s\n", uuid); printf("Saved state : %s\n", f->saved == 0 ? "No" : "Yes"); --Boundary-00=_5CjQKeSDu6/trqw Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --Boundary-00=_5CjQKeSDu6/trqw--