From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=35908 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6qZE-0005Ou-Ci for qemu-devel@nongnu.org; Fri, 15 Oct 2010 16:07:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6qZC-0000zU-H4 for qemu-devel@nongnu.org; Fri, 15 Oct 2010 16:07:52 -0400 Received: from mail-qy0-f173.google.com ([209.85.216.173]:38292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6qZC-0000zP-Dy for qemu-devel@nongnu.org; Fri, 15 Oct 2010 16:07:50 -0400 Received: by qyk36 with SMTP id 36so1471728qyk.4 for ; Fri, 15 Oct 2010 13:07:50 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <1287151553-16894-2-git-send-email-Jes.Sorensen@redhat.com> References: <1287151553-16894-1-git-send-email-Jes.Sorensen@redhat.com> <1287151553-16894-2-git-send-email-Jes.Sorensen@redhat.com> From: Blue Swirl Date: Fri, 15 Oct 2010 20:07:29 +0000 Message-ID: Subject: Re: [Qemu-devel] [PATCH 1/9] Move QEMU OS dependant library functions to OS specific files Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jes.Sorensen@redhat.com Cc: qemu-devel@nongnu.org On Fri, Oct 15, 2010 at 2:05 PM, wrote: > From: Jes Sorensen > > This moves library functions used by both QEMU and the QEMU tools, > such as qemu-img, qemu-nbd etc. from osdep.c to os-{posix,win32}-lib.c $ find . \( -name '*posix*.c' -o -name '*win32*.c' \) -print ./os-win32.c ./block/raw-posix.c ./block/raw-win32.c ./posix-aio-compat.c ./os-posix.c ./net/tap-win32.c Please use something like osdep-{posix,win32}.c or oslib-{posix,win32}.c. > > In addition it introduces oslib-obj.y to the Makefile set to be > included by the various targets, instead of relying on these library > functions magically getting included via block-obj-y. > > Signed-off-by: Jes Sorensen > --- > =C2=A0Makefile =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A06 ++-- > =C2=A0Makefile.objs =C2=A0| =C2=A0 =C2=A09 ++++++- > =C2=A0os-posix-lib.c | =C2=A0 65 ++++++++++++++++++++++++++++++++++++++++= +++++++++++ > =C2=A0os-win32-lib.c | =C2=A0 71 ++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++ > =C2=A0osdep.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 70 --------------------= ----------------------------------- > =C2=A05 files changed, 147 insertions(+), 74 deletions(-) > =C2=A0create mode 100644 os-posix-lib.c > =C2=A0create mode 100644 os-win32-lib.c > > diff --git a/Makefile b/Makefile > index 252c817..0b3751d 100644 > --- a/Makefile > +++ b/Makefile > @@ -129,11 +129,11 @@ version-obj-$(CONFIG_WIN32) +=3D version.o > =C2=A0qemu-img.o: qemu-img-cmds.h > =C2=A0qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o: $(GENERATED_HEADERS) > > -qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(trace-obj-y) $(= block-obj-y) $(qobject-obj-y) $(version-obj-y) > +qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(oslib-obj-y) $(= trace-obj-y) $(block-obj-y) $(qobject-obj-y) $(version-obj-y) > > -qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(trace-obj-y) $(= block-obj-y) $(qobject-obj-y) $(version-obj-y) > +qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(oslib-obj-y) $(= trace-obj-y) $(block-obj-y) $(qobject-obj-y) $(version-obj-y) > > -qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(trace-obj-y= ) $(block-obj-y) $(qobject-obj-y) $(version-obj-y) > +qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(oslib-obj-y= ) $(trace-obj-y) $(block-obj-y) $(qobject-obj-y) $(version-obj-y) > > =C2=A0qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx > =C2=A0 =C2=A0 =C2=A0 =C2=A0$(call quiet-command,sh $(SRC_PATH)/hxtool -h = < $< > $@," =C2=A0GEN =C2=A0 $@") > diff --git a/Makefile.objs b/Makefile.objs > index 816194a..4281ae8 100644 > --- a/Makefile.objs > +++ b/Makefile.objs > @@ -5,10 +5,16 @@ qobject-obj-y +=3D qjson.o json-lexer.o json-streamer.o= json-parser.o > =C2=A0qobject-obj-y +=3D qerror.o > > =C2=A0###################################################################= #### > +# os-obj-y is code depending on the OS (win32 vs posix) The comment, variable name and file names are also all different. > +oslib-obj-y =3D osdep.o > +oslib-obj-$(CONFIG_WIN32) +=3D os-win32-lib.o > +oslib-obj-$(CONFIG_POSIX) +=3D os-posix-lib.o > + > +####################################################################### > =C2=A0# block-obj-y is code used by both qemu system emulation and qemu-i= mg > > =C2=A0block-obj-y =3D cutils.o cache-utils.o qemu-malloc.o qemu-option.o = module.o > -block-obj-y +=3D nbd.o block.o aio.o aes.o osdep.o qemu-config.o > +block-obj-y +=3D nbd.o block.o aio.o aes.o qemu-config.o > =C2=A0block-obj-$(CONFIG_POSIX) +=3D posix-aio-compat.o > =C2=A0block-obj-$(CONFIG_LINUX_AIO) +=3D linux-aio.o > > @@ -50,6 +56,7 @@ common-obj-y +=3D $(net-obj-y) > =C2=A0common-obj-y +=3D $(qobject-obj-y) > =C2=A0common-obj-$(CONFIG_LINUX) +=3D $(fsdev-obj-$(CONFIG_LINUX)) > =C2=A0common-obj-y +=3D readline.o console.o cursor.o async.o qemu-error.= o > +common-obj-y +=3D $(oslib-obj-y) > =C2=A0common-obj-$(CONFIG_WIN32) +=3D os-win32.o > =C2=A0common-obj-$(CONFIG_POSIX) +=3D os-posix.o > > diff --git a/os-posix-lib.c b/os-posix-lib.c > new file mode 100644 > index 0000000..83e5101 > --- /dev/null > +++ b/os-posix-lib.c > @@ -0,0 +1,65 @@ > +/* > + * os-posix-lib.c > + * > + * Copyright (c) 2003-2008 Fabrice Bellard > + * Copyright (c) 2010 Red Hat, Inc. > + * > + * QEMU library functions on POSIX which are shared between QEMU and > + * the QEMU tools. > + * > + * Permission is hereby granted, free of charge, to any person obtaining= a copy > + * of this software and associated documentation files (the "Software"),= to deal > + * in the Software without restriction, including without limitation the= rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or = sell > + * copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be includ= ed in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRE= SS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILI= TY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHA= LL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR = OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISI= NG FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING= S IN > + * THE SOFTWARE. > + */ > + > +#include "config-host.h" > +#include "sysemu.h" > +#include "trace.h" > +#include "net/slirp.h" > +#include "qemu-options.h" I don't think all of these are really needed, please trim. > + > +void *qemu_memalign(size_t alignment, size_t size) > +{ > + =C2=A0 =C2=A0void *ptr; > +#if defined(_POSIX_C_SOURCE) && !defined(__sun__) > + =C2=A0 =C2=A0int ret; > + =C2=A0 =C2=A0ret =3D posix_memalign(&ptr, alignment, size); > + =C2=A0 =C2=A0if (ret !=3D 0) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "Failed to allocate %zu B: %= s\n", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0size, strerror(r= et)); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0abort(); > + =C2=A0 =C2=A0} > +#elif defined(CONFIG_BSD) > + =C2=A0 =C2=A0ptr =3D oom_check(valloc(size)); > +#else > + =C2=A0 =C2=A0ptr =3D oom_check(memalign(alignment, size)); > +#endif > + =C2=A0 =C2=A0trace_qemu_memalign(alignment, size, ptr); > + =C2=A0 =C2=A0return ptr; > +} > + > +/* alloc shared memory pages */ > +void *qemu_vmalloc(size_t size) > +{ > + =C2=A0 =C2=A0return qemu_memalign(getpagesize(), size); > +} > + > +void qemu_vfree(void *ptr) > +{ > + =C2=A0 =C2=A0trace_qemu_vfree(ptr); > + =C2=A0 =C2=A0free(ptr); > +} > diff --git a/os-win32-lib.c b/os-win32-lib.c > new file mode 100644 > index 0000000..80e713a > --- /dev/null > +++ b/os-win32-lib.c > @@ -0,0 +1,71 @@ > +/* > + * os-win32.c > + * > + * Copyright (c) 2003-2008 Fabrice Bellard > + * Copyright (c) 2010 Red Hat, Inc. > + * > + * QEMU library functions for win32 which are shared between QEMU and > + * the QEMU tools. > + * > + * Permission is hereby granted, free of charge, to any person obtaining= a copy > + * of this software and associated documentation files (the "Software"),= to deal > + * in the Software without restriction, including without limitation the= rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or = sell > + * copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be includ= ed in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRE= SS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILI= TY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHA= LL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR = OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISI= NG FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING= S IN > + * THE SOFTWARE. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "config-host.h" > +#include "sysemu.h" > +#include "trace.h" > +#include "qemu-options.h" Ditto.