[Qemu-devel] [PATCH 4/5] libcacard: replace qemu thread primitives with glib ones
Replace QemuMutex with GMutex and QemuCond with GCond (with corresponding function changes), to make libcacard independent of qemu internal functions. Also replace single instance pstrcpy() in vcard_emul_nss.c to strncpy(). This reverts commit 2e679780ae86c6ca8. After this step, none of libcacard internals use any qemu-provided symbols. Maybe it's a good idea to stop including qemu-common.h internally too. Signed-off-by: Michael Tokarev m...@tls.msk.ru --- libcacard/Makefile |8 +--- libcacard/event.c | 25 - libcacard/vcard_emul_nss.c |3 ++- libcacard/vreader.c| 19 +-- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/libcacard/Makefile b/libcacard/Makefile index 6b06448..89a5942 100644 --- a/libcacard/Makefile +++ b/libcacard/Makefile @@ -3,13 +3,7 @@ libcacard_includedir=$(includedir)/cacard TOOLS += vscclient$(EXESUF) # objects linked into a shared library, built with libtool with -fPIC if required -libcacard-obj-y = $(stub-obj-y) $(libcacard-y) -libcacard-obj-y += util/osdep.o util/cutils.o util/qemu-timer-common.o -libcacard-obj-y += util/error.o util/qemu-error.o -libcacard-obj-$(CONFIG_WIN32) += util/oslib-win32.o util/qemu-thread-win32.o -libcacard-obj-$(CONFIG_POSIX) += util/oslib-posix.o util/qemu-thread-posix.o -libcacard-obj-y += $(filter trace/%, $(util-obj-y)) - +libcacard-obj-y = $(libcacard-y) libcacard-lobj-y=$(patsubst %.o,%.lo,$(libcacard-obj-y)) # libtool will build the .o files, too diff --git a/libcacard/event.c b/libcacard/event.c index 2d7500f..be11596 100644 --- a/libcacard/event.c +++ b/libcacard/event.c @@ -6,7 +6,6 @@ */ #include qemu-common.h -#include qemu/thread.h #include vcard.h #include vreader.h @@ -43,13 +42,13 @@ vevent_delete(VEvent *vevent) static VEvent *vevent_queue_head; static VEvent *vevent_queue_tail; -static QemuMutex vevent_queue_lock; -static QemuCond vevent_queue_condition; +static GMutex vevent_queue_lock; +static GCond vevent_queue_condition; void vevent_queue_init(void) { -qemu_mutex_init(vevent_queue_lock); -qemu_cond_init(vevent_queue_condition); +g_mutex_init_static(vevent_queue_lock); +g_cond_init_static(vevent_queue_condition); vevent_queue_head = vevent_queue_tail = NULL; } @@ -57,7 +56,7 @@ void vevent_queue_vevent(VEvent *vevent) { vevent-next = NULL; -qemu_mutex_lock(vevent_queue_lock); +g_mutex_lock(vevent_queue_lock); if (vevent_queue_head) { assert(vevent_queue_tail); vevent_queue_tail-next = vevent; @@ -65,8 +64,8 @@ vevent_queue_vevent(VEvent *vevent) vevent_queue_head = vevent; } vevent_queue_tail = vevent; -qemu_cond_signal(vevent_queue_condition); -qemu_mutex_unlock(vevent_queue_lock); +g_cond_signal(vevent_queue_condition); +g_mutex_unlock(vevent_queue_lock); } /* must have lock */ @@ -86,11 +85,11 @@ VEvent *vevent_wait_next_vevent(void) { VEvent *vevent; -qemu_mutex_lock(vevent_queue_lock); +g_mutex_lock(vevent_queue_lock); while ((vevent = vevent_dequeue_vevent()) == NULL) { -qemu_cond_wait(vevent_queue_condition, vevent_queue_lock); +g_cond_wait(vevent_queue_condition, vevent_queue_lock); } -qemu_mutex_unlock(vevent_queue_lock); +g_mutex_unlock(vevent_queue_lock); return vevent; } @@ -98,9 +97,9 @@ VEvent *vevent_get_next_vevent(void) { VEvent *vevent; -qemu_mutex_lock(vevent_queue_lock); +g_mutex_lock(vevent_queue_lock); vevent = vevent_dequeue_vevent(); -qemu_mutex_unlock(vevent_queue_lock); +g_mutex_unlock(vevent_queue_lock); return vevent; } diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c index ee2dfae..0892462 100644 --- a/libcacard/vcard_emul_nss.c +++ b/libcacard/vcard_emul_nss.c @@ -1162,7 +1162,8 @@ vcard_emul_options(const char *args) NEXT_TOKEN(vname) NEXT_TOKEN(type_params) type_params_length = MIN(type_params_length, sizeof(type_str)-1); -pstrcpy(type_str, type_params_length, type_params); +strncpy(type_str, type_params, type_params_length); +type_str[type_params_length] = 0; type = vcard_emul_type_from_string(type_str); NEXT_TOKEN(type_params) diff --git a/libcacard/vreader.c b/libcacard/vreader.c index 5793d73..91799b4 100644 --- a/libcacard/vreader.c +++ b/libcacard/vreader.c @@ -9,10 +9,8 @@ #undef G_LOG_DOMAIN #endif #define G_LOG_DOMAIN libcacard -#include glib.h #include qemu-common.h -#include qemu/thread.h #include vcard.h #include vcard_emul.h @@ -28,7 +26,7 @@ struct VReaderStruct { VCard *card; char *name; vreader_id_t id; -QemuMutex lock; +GMutex lock; VReaderEmul *reader_private; VReaderEmulFree reader_private_free; }; @@ -97,13 +95,13 @@ apdu_ins_to_string(int ins) static inline void vreader_lock(VReader *reader) {
[Qemu-devel] [PATCH 1/5] do not call g_thread_init() for glib = 2.31
glib = 2.31 always enables thread support and g_thread_supported() is #defined to 1, there's no need to call g_thread_init() anymore, and it definitely does not need to report error which never happens. Keep code for old 2.31 glibc anyway for now, just #ifdef it differently. Signed-off-by: Michael Tokarev m...@tls.msk.ru --- coroutine-gthread.c |7 ++- util/osdep.c| 21 + 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/coroutine-gthread.c b/coroutine-gthread.c index d3e5b99..a61efe0 100644 --- a/coroutine-gthread.c +++ b/coroutine-gthread.c @@ -115,14 +115,11 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data) static void __attribute__((constructor)) coroutine_init(void) { -if (!g_thread_supported()) { #if !GLIB_CHECK_VERSION(2, 31, 0) +if (!g_thread_supported()) { g_thread_init(NULL); -#else -fprintf(stderr, glib threading failed to initialize.\n); -exit(1); -#endif } +#endif init_coroutine_cond(); } diff --git a/util/osdep.c b/util/osdep.c index a9029f8..b2bd154 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -436,23 +436,20 @@ int socket_init(void) return 0; } -/* Ensure that glib is running in multi-threaded mode */ +#if !GLIB_CHECK_VERSION(2, 31, 0) +/* Ensure that glib is running in multi-threaded mode + * Old versions of glib require explicit initialization. Failure to do + * this results in the single-threaded code paths being taken inside + * glib. For example, the g_slice allocator will not be thread-safe + * and cause crashes. + */ static void __attribute__((constructor)) thread_init(void) { if (!g_thread_supported()) { -#if !GLIB_CHECK_VERSION(2, 31, 0) -/* Old versions of glib require explicit initialization. Failure to do - * this results in the single-threaded code paths being taken inside - * glib. For example, the g_slice allocator will not be thread-safe - * and cause crashes. - */ -g_thread_init(NULL); -#else -fprintf(stderr, glib threading failed to initialize.\n); -exit(1); -#endif + g_thread_init(NULL); } } +#endif #ifndef CONFIG_IOVEC /* helper function for iov_send_recv() */ -- 1.7.10.4
[Qemu-devel] [PATCH 5/5] libcacard: actually use symbols file
libtool has an argument for .syms file, which is -export-symbols. There's no argument `-export-syms', and it looks like at least on linux, -export-syms is just ignored. Use the correct argument, -export-symbols, to actually get the right export list. Signed-off-by: Michael Tokarev m...@tls.msk.ru Reviewed-by: Alon Levy al...@redhat.com --- libcacard/Makefile |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcacard/Makefile b/libcacard/Makefile index 89a5942..b620c28 100644 --- a/libcacard/Makefile +++ b/libcacard/Makefile @@ -18,7 +18,7 @@ vscclient$(EXESUF): libcacard/vscclient.o libcacard.la # Rules for building libcacard standalone library libcacard.la: LDFLAGS += -rpath $(libdir) -no-undefined \ - -export-syms $(SRC_PATH)/libcacard/libcacard.syms + -export-symbols $(SRC_PATH)/libcacard/libcacard.syms libcacard.la: LIBS = $(libcacard_libs) libcacard.la: $(libcacard-lobj-y) $(call LINK,$^) -- 1.7.10.4
[Qemu-devel] [PATCH 3/5] vscclient: use glib thread primitives not qemu
Use glib-provided thread primitives in vscclient, not qemu thread primitives. This way, vscclient becomes more stand-alone. Signed-off-by: Michael Tokarev m...@tls.msk.ru --- libcacard/vscclient.c | 75 + 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c index 3477ab3..5f87d1c 100644 --- a/libcacard/vscclient.c +++ b/libcacard/vscclient.c @@ -12,12 +12,10 @@ #ifndef _WIN32 #include netdb.h +#define closesocket(x) close(x) #endif -#include glib.h #include qemu-common.h -#include qemu/thread.h -#include qemu/sockets.h #include vscard_common.h @@ -54,7 +52,7 @@ print_usage(void) { static GIOChannel *channel_socket; static GByteArray *socket_to_send; -static QemuMutex socket_to_send_lock; +static GMutex socket_to_send_lock; static guint socket_tag; static void @@ -103,7 +101,7 @@ send_msg( ) { VSCMsgHeader mhHeader; -qemu_mutex_lock(socket_to_send_lock); +g_mutex_lock(socket_to_send_lock); if (verbose 10) { printf(sending type=%d id=%u, len =%u (0x%x)\n, @@ -117,18 +115,18 @@ send_msg( g_byte_array_append(socket_to_send, (guint8 *)msg, length); g_idle_add(socket_prepare_sending, NULL); -qemu_mutex_unlock(socket_to_send_lock); +g_mutex_unlock(socket_to_send_lock); return 0; } static VReader *pending_reader; -static QemuMutex pending_reader_lock; -static QemuCond pending_reader_condition; +static GMutex pending_reader_lock; +static GCond pending_reader_condition; #define MAX_ATR_LEN 40 -static void * -event_thread(void *arg) +static gpointer +event_thread(gpointer arg) { unsigned char atr[MAX_ATR_LEN]; int atr_len = MAX_ATR_LEN; @@ -149,20 +147,20 @@ event_thread(void *arg) /* ignore events from readers qemu has rejected */ /* if qemu is still deciding on this reader, wait to see if need to * forward this event */ -qemu_mutex_lock(pending_reader_lock); +g_mutex_lock(pending_reader_lock); if (!pending_reader || (pending_reader != event-reader)) { /* wasn't for a pending reader, this reader has already been * rejected by qemu */ -qemu_mutex_unlock(pending_reader_lock); +g_mutex_unlock(pending_reader_lock); vevent_delete(event); continue; } /* this reader hasn't been told its status from qemu yet, wait for * that status */ while (pending_reader != NULL) { -qemu_cond_wait(pending_reader_condition, pending_reader_lock); +g_cond_wait(pending_reader_condition, pending_reader_lock); } -qemu_mutex_unlock(pending_reader_lock); +g_mutex_unlock(pending_reader_lock); /* now recheck the id */ reader_id = vreader_get_id(event-reader); if (reader_id == VSCARD_UNDEFINED_READER_ID) { @@ -178,12 +176,12 @@ event_thread(void *arg) /* wait until qemu has responded to our first reader insert * before we send a second. That way we won't confuse the responses * */ -qemu_mutex_lock(pending_reader_lock); +g_mutex_lock(pending_reader_lock); while (pending_reader != NULL) { -qemu_cond_wait(pending_reader_condition, pending_reader_lock); +g_cond_wait(pending_reader_condition, pending_reader_lock); } pending_reader = vreader_reference(event-reader); -qemu_mutex_unlock(pending_reader_lock); +g_mutex_unlock(pending_reader_lock); reader_name = vreader_get_name(event-reader); if (verbose 10) { printf( READER INSERT: %s\n, reader_name); @@ -246,7 +244,6 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming) int num_capabilities = 1 + ((mhHeader-length - sizeof(VSCMsgInit)) / sizeof(uint32_t)); int i; -QemuThread thread_id; incoming-version = ntohl(incoming-version); if (incoming-version != VSCARD_VERSION) { @@ -269,7 +266,7 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming) send_msg(VSC_ReaderRemove, VSCARD_MINIMAL_READER_ID, NULL, 0); /* launch the event_thread. This will trigger reader adds for all the * existing readers */ -qemu_thread_create(thread_id, vsc/event, event_thread, NULL, 0); +g_thread_new(vsc/event, event_thread, NULL); return 0; } @@ -379,26 +376,26 @@ do_socket_read(GIOChannel *source, case VSC_Error: error_msg = (VSCMsgError *) pbSendBuffer; if (error_msg-code == VSC_SUCCESS) { -qemu_mutex_lock(pending_reader_lock); +g_mutex_lock(pending_reader_lock); if (pending_reader) {
[Qemu-devel] [PATCH 0/5] glib thread interface and libcacard cleanups
Basically libgthread has been rewritten in glib version 2.31, and old ways to use thread primitives stopped working while new ways appeared. The two interfaces were sufficiently different to warrant large ifdeffery across all code using it. Here's a patchset which tries to clean usage of glib thread interface across this major rewrite. The main change was that certain primitives - conditionals and mutexes - were dynamic-only before 2.31 (ie, should be allocated using foo_new() and freed using foo_free()), while in 2.31 and up, _new()/_free() has been deprecated, and new primitives, _init()/_clear(), were added. So before 2.31, we had to declare a pointer call foo_new() to allocate actual object, and use this pointer when calling all functions which use this object, while in 2.31+, we have to declare actual object and use its address when calling functions. The trick to make this stuff happy for old glib which I used is to re-define actual type to be a pointer to that type, using #define, like this: #define GMutex GMutex* so every time the code refers to GMutex it actually refers to a pointer to that object. Plus wrapper #define and inline functioins which accept such a pointer and call actual glib function after dereferencing it, like this: static inline g_forward_compat_mutex_lock(GMutex **mutex) { g_mutex_lock(*mutex); } #undef g_mutex_lock #define g_mutex_lock(mutex) g_forward_compat_mutex_lock(mutex) This way, we use new, 2.31+, glib interface everywhere, but for pre-2.31 glib, this interface is wrapped using old API and by converting the actual object to a pointer to actual object behind the scenes. It is hackish, but this allows to write very very clean, new-style, code, and compile it with old glib. The only difference with actual new interface is that in new, 2.31+, glib, those objects, when declared statically, don't need to be initialized and will just work when passed to their functions. While for old interface, actual objects needs to be allocated using g_foo_new(). So I added a set of functions, g_foo_init_static(), which should be called in the same place where old code expected to have g_foo_new(). For new interface those functions evaluates to nothing, but for old interface they call the allocation routine. It is not the same as g_foo_init(), -- I wanted to distinguish this _static() method from regular init() (tho any of those can be used), because it is easy this way to find places in the code which can benefit from cleanups later when we'll drop support for glib 2.31. The series consists of 5 patches: - do not call g_thread_init() for glib = 2.31 This is a cleanup patch, cleaning g_thread_init() call. In 2.31+, threads are always enabled and initialized (and glib can't be built without threads), and g_thread_supported() is #defined to be 1. So the #ifdeffery didn't make any sense to start with, especially printing error message and aborting if !g_thread_supported(). - glib-compat.h: add new thread API emulation on top of pre-2.31 API This is the main and largest part. Introducing described above compatibility layer into include/glib-compat.h. This patch also cleans up direct usage of GCond and GMutex in the code in 2 fles: coroutine-gthread.c and trace/simple.c. In the latter, whole ifdeffery is eliminated this way completely, while in the latter, there's one more primitive which received rewrite in the same version of glib, -- thread private data, GPrivate and GStaticPrivate, which still uses #ifdefs. I had to introduce the compat layer together with the changes in usage, because else the ifdeffery around usage conflicts with the compat layer. In coroutine-gthread.c, I also replaced GStaticMutex (from old glib) with regular GMutex. The thing is that actually, GStaticMutex was very similar to what I've done with the actual object vs a pointer to object - it works in term of GMutex, but stores just a pointer of it, and allocates it on demand dynamically. Using GMutex directly makes it a bit faster. - vscclient: use glib thread primitives not qemu - libcacard: replace qemu thread primitives with glib ones convert libcacard from qemu thread primitives to glib thread primitives using the new compatibility layer. This way, libcacard becomes stand-alone library and does not depend on qemu anymore, so programs using it are not required to mess with qemu objects. an unrelated-to-glib change which I had to apply to libcacard here was to replace pstrcpy() back to strncpy(). The reverse conversion has been done in the past, this patch reverts it back to usage of strncpy(). and we've some tiny OS-compat code added to vscclient.c here. - libcacard: actually use symbols file this is the change which started whole series. This patch makes export list for libcacard.so to be strict, exporting only really necessary symbols, omitting internal symbols. Previously, libcacard used and exported many of qemu internals,
[Qemu-devel] [PATCH 2/5] glib-compat.h: add new thread API emulation on top of pre-2.31 API
Thread API changed in glib-2.31 significantly. Before that version, conditionals and mutexes were only allocated dynamically, using _new()/_free() interface. in 2.31 and up, they're allocated statically as regular variables, and old interface is deprecated. (Note: glib docs says the new interface is available since version 2.32, but it was actually introduced in version 2.31). Create the new interface using old primitives, re-defining the base types (GCond and GMutex) to be pointers. Replace #ifdeffery around GCond and GMutex in trace/simple.c and coroutine-gthread.c too because it does not work anymore with the new glib-compat.h. Signed-off-by: Michael Tokarev m...@tls.msk.ru --- coroutine-gthread.c | 30 +- include/glib-compat.h | 103 + trace/simple.c| 50 +++- 3 files changed, 126 insertions(+), 57 deletions(-) diff --git a/coroutine-gthread.c b/coroutine-gthread.c index a61efe0..a4813d9 100644 --- a/coroutine-gthread.c +++ b/coroutine-gthread.c @@ -30,20 +30,14 @@ typedef struct { CoroutineAction action; } CoroutineGThread; -static GStaticMutex coroutine_lock = G_STATIC_MUTEX_INIT; +static GMutex coroutine_lock; +static GCond coroutine_cond; /* GLib 2.31 and beyond deprecated various parts of the thread API, * but the new interfaces are not available in older GLib versions * so we have to cope with both. */ #if GLIB_CHECK_VERSION(2, 31, 0) -/* Default zero-initialisation is sufficient for 2.31+ GCond */ -static GCond the_coroutine_cond; -static GCond *coroutine_cond = the_coroutine_cond; -static inline void init_coroutine_cond(void) -{ -} - /* Awkwardly, the GPrivate API doesn't provide a way to update the * GDestroyNotify handler for the coroutine key dynamically. So instead * we track whether or not the CoroutineGThread should be freed on @@ -84,11 +78,6 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data) #else /* Handle older GLib versions */ -static GCond *coroutine_cond; -static inline void init_coroutine_cond(void) -{ -coroutine_cond = g_cond_new(); -} static GStaticPrivate coroutine_key = G_STATIC_PRIVATE_INIT; @@ -121,21 +110,22 @@ static void __attribute__((constructor)) coroutine_init(void) } #endif -init_coroutine_cond(); +g_cond_init_static(coroutine_cond); +g_mutex_init_static(coroutine_lock); } static void coroutine_wait_runnable_locked(CoroutineGThread *co) { while (!co-runnable) { -g_cond_wait(coroutine_cond, g_static_mutex_get_mutex(coroutine_lock)); +g_cond_wait(coroutine_cond, coroutine_lock); } } static void coroutine_wait_runnable(CoroutineGThread *co) { -g_static_mutex_lock(coroutine_lock); +g_mutex_lock(coroutine_lock); coroutine_wait_runnable_locked(co); -g_static_mutex_unlock(coroutine_lock); +g_mutex_unlock(coroutine_lock); } static gpointer coroutine_thread(gpointer opaque) @@ -177,17 +167,17 @@ CoroutineAction qemu_coroutine_switch(Coroutine *from_, CoroutineGThread *from = DO_UPCAST(CoroutineGThread, base, from_); CoroutineGThread *to = DO_UPCAST(CoroutineGThread, base, to_); -g_static_mutex_lock(coroutine_lock); +g_mutex_lock(coroutine_lock); from-runnable = false; from-action = action; to-runnable = true; to-action = action; -g_cond_broadcast(coroutine_cond); +g_cond_broadcast(coroutine_cond); if (action != COROUTINE_TERMINATE) { coroutine_wait_runnable_locked(from); } -g_static_mutex_unlock(coroutine_lock); +g_mutex_unlock(coroutine_lock); return from-action; } diff --git a/include/glib-compat.h b/include/glib-compat.h index 8aa77af..7f13c71 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -5,6 +5,7 @@ * * Authors: * Anthony Liguori aligu...@us.ibm.com + * Michael Tokarev m...@tls.msk.ru * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -24,4 +25,106 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function, } #endif + +#if !GLIB_CHECK_VERSION(2, 31, 0) +/* before glib-2.31, GMutex and GCond was dynamic-only. + * We redefine GMutex to GMutex* and create new _init()/_clear() + * primitives using old _new()/_free() primitives. + * The tricky part is to re-define the types. + * g_forward_compat_ prefix is used for inline functions. + * This is done as both inline function and a macro because original + * glib symbols which we redefine were actually macros. + */ + +#define GMutex GMutex * +#define GCond GCond * + +static inline void g_mutex_init(GMutex *mutex) +{ + *mutex = g_mutex_new(); +} + +static inline void g_mutex_clear(GMutex *mutex) +{ + g_mutex_free(*mutex); + *mutex = NULL; +} + +#define g_mutex_init_static(mutex) g_mutex_init(mutex) +#define g_mutex_clear_static(mutex) g_mutex_clear(mutex) +
Re: [Qemu-devel] [PATCH 1/3] megasas: add MegaRAID SAS 2108 emulation
On 04/28/2014 05:20 PM, Andreas Färber wrote: Am 28.04.2014 15:01, schrieb Hannes Reinecke: The 2108 chip supports MSI and MSI-X, so update the emulation to support both chips. Signed-off-by: Hannes Reinecke h...@suse.de --- hw/scsi/megasas.c| 138 ++- hw/scsi/mfi.h| 7 +++ include/hw/pci/pci_ids.h | 1 + 3 files changed, 134 insertions(+), 12 deletions(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index baee46f..519e3bc 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c [...] @@ -2116,6 +2168,25 @@ static const VMStateDescription vmstate_megasas = { } }; +static const VMStateDescription vmstate_megasas_gen2 = { +.name = megasas-gen2, +.version_id = 0, +.minimum_version_id = 0, +.minimum_version_id_old = 0, +.fields = (VMStateField[]) { +VMSTATE_PCIE_DEVICE(parent_obj, MegasasState), +VMSTATE_MSIX(parent_obj, MegasasState), + +VMSTATE_INT32(fw_state, MegasasState), +VMSTATE_INT32(intr_mask, MegasasState), +VMSTATE_INT32(doorbell, MegasasState), +VMSTATE_UINT64(reply_queue_pa, MegasasState), +VMSTATE_UINT64(consumer_pa, MegasasState), +VMSTATE_UINT64(producer_pa, MegasasState), +VMSTATE_END_OF_LIST() +} +}; + static void megasas_scsi_uninit(PCIDevice *d) { MegasasState *s = MEGASAS(d); [...] @@ -2278,9 +2357,44 @@ static const TypeInfo megasas_info = { .class_init = megasas_class_init, }; +static Property megasas_gen2_properties[] = { +DEFINE_PROP_UINT32(max_sge, MegasasState, fw_sge, + MEGASAS_DEFAULT_SGE), +DEFINE_PROP_UINT32(max_cmds, MegasasState, fw_cmds, + MEGASAS_DEFAULT_FRAMES), +DEFINE_PROP_STRING(hba_serial, MegasasState, hba_serial), +DEFINE_PROP_UINT64(sas_address, MegasasState, sas_addr, 0), +DEFINE_PROP_BIT(use_msi, MegasasState, flags, +MEGASAS_FLAG_USE_MSI, true), +DEFINE_PROP_BIT(use_msix, MegasasState, flags, +MEGASAS_FLAG_USE_MSIX, true), +DEFINE_PROP_BIT(use_jbod, MegasasState, flags, +MEGASAS_FLAG_USE_JBOD, false), +DEFINE_PROP_END_OF_LIST(), +}; + +static void megasas_gen2_class_init(ObjectClass *oc, void *data) +{ +PCIDeviceClass *pc = PCI_DEVICE_CLASS(oc); +DeviceClass *dc = DEVICE_CLASS(oc); + +pc-device_id = PCI_DEVICE_ID_LSI_SAS0079; +pc-subsystem_id = 0x9261; +dc-props = megasas_gen2_properties; +dc-desc = LSI MegaRAID SAS 2108; +dc-vmsd = vmstate_megasas_gen2; +} + +static TypeInfo megasas_gen2_info = { static const +.name = TYPE_MEGASAS_GEN2, +.parent = TYPE_MEGASAS, +.class_init = megasas_gen2_class_init, +}; + static void megasas_register_types(void) { type_register_static(megasas_info); +type_register_static(megasas_gen2_info); } type_init(megasas_register_types) I note that there is still no qtest in this series. We need to draw a line somewhere. Have you tested this device at all? I would expect it to fail horribly due to the use_jbod property being defined on derived and parent type! Ah. No, it doesn't fail. System works happily. Further, deriving the new model from the original one conflicts with my series for QOM'ifying -vmsd similar to -props. Please use an abstract base type with dc-vmsd == NULL if we need to keep the VMSDs separate. sighOf course. Would've been too easy./sigh For those who do not follow qemu-devel on a daily basis, can you elaborate somewhat on how this should be done? IE would it be sufficient to have one base class and two derived classes, so that the current 'megasas' would move to a derived class? But in doing so, how do I prevent the base class from showing up in the list of possible drivers? Is there some example in the code where this is already done? Cheers, Hannes -- Dr. Hannes Reinecke zSeries Storage h...@suse.de +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
[Qemu-devel] [PATCH] configure: Enable dead code (lzo, snappy, quorum)
Those options were not enabled by default, even when the build environment would have supported them, so the corresponding code was not compiled in normal test builds like on build bots. Signed-off-by: Stefan Weil s...@weilnetz.de --- I'm not sure whether this patch is trivial enough for qemu-trivial. Are there any disadvantages when this code is enabled? Stefan configure | 39 --- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 2fbec59..0faadd7 100755 --- a/configure +++ b/configure @@ -301,8 +301,8 @@ libusb= usb_redir= glx= zlib=yes -lzo=no -snappy=no +lzo= +snappy= guest_agent= guest_agent_with_vss=no vss_win32_sdk= @@ -323,7 +323,7 @@ vte= tpm=no libssh2= vhdx= -quorum=no +quorum= # parse CC options first for opt do @@ -1023,8 +1023,12 @@ for opt do ;; --disable-zlib-test) zlib=no ;; + --disable-lzo) lzo=no + ;; --enable-lzo) lzo=yes ;; + --disable-snappy) snappy=no + ;; --enable-snappy) snappy=yes ;; --enable-guest-agent) guest_agent=yes @@ -1722,13 +1726,14 @@ if test $lzo != no ; then int main(void) { lzo_version(); return 0; } EOF if compile_prog -llzo2 ; then -: +libs_softmmu=$libs_softmmu -llzo2 +lzo=yes else -error_exit lzo check failed \ -Make sure to have the lzo libs and headers installed. +if test $lzo = yes; then +feature_not_found liblzo2 Install liblzo2 devel +fi +lzo=no fi - -libs_softmmu=$libs_softmmu -llzo2 fi ## @@ -1740,13 +1745,14 @@ if test $snappy != no ; then int main(void) { snappy_max_compressed_length(4096); return 0; } EOF if compile_prog -lsnappy ; then -: +libs_softmmu=$libs_softmmu -lsnappy +snappy=yes else -error_exit snappy check failed \ -Make sure to have the snappy libs and headers installed. +if test $snappy = yes; then +feature_not_found libsnappy Install libsnappy devel +fi +snappy=no fi - -libs_softmmu=$libs_softmmu -lsnappy fi ## @@ -2172,9 +2178,12 @@ if compile_prog $quorum_tls_cflags $quorum_tls_libs ; then libs_softmmu=$quorum_tls_libs $libs_softmmu libs_tools=$quorum_tls_libs $libs_softmmu QEMU_CFLAGS=$QEMU_CFLAGS $quorum_tls_cflags + quorum=yes else - echo gnutls 2.10.0 required to compile Quorum - exit 1 + if test $quorum = yes; then +feature_not_found gnutls gnutls 2.10.0 required to compile Quorum + fi + quorum=no fi fi -- 1.7.10.4
Re: [Qemu-devel] [patch 2/2] target-i386: block migration and savevm if invariant tsc is exposed
Il 28/04/2014 21:23, Eduardo Habkost ha scritto: Makes sense. Basically -cpu host,migratable=yes is close to libvirt's host-model and Alex Graf's proposed -cpu best. Should we call it -cpu best and drop migratability of -cpu host? -cpu best is different from the modes above. It means use the best existing CPU model (from the pre-defined table) that can run on this host. Yes, it's not exactly the same. In practice the behavior should be close. And it would have the same ambiguities we found on -cpu host: if a CPU model in the table have invtsc enabled, should it be considered a candidate for -cpu best, or not? No CPU model in the table should have invtsc enabled. :) Paolo
[Qemu-devel] [PATCH] qga: Fix typo (plural) in comment
Signed-off-by: Stefan Weil s...@weilnetz.de --- qga/main.c |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/main.c b/qga/main.c index d838c3e..38219c9 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1110,7 +1110,7 @@ int main(int argc, char **argv) if (ga_is_frozen(s)) { if (daemonize) { -/* delay opening/locking of pidfile till filesystem are unfrozen */ +/* delay opening/locking of pidfile till filesystems are unfrozen */ s-deferred_options.pid_filepath = pid_filepath; become_daemon(NULL); } -- 1.7.10.4
[Qemu-devel] [PATCH 4/3] qemu-socket: Clean up inet_connect_opts()
Separate the search for a working addrinfo from the code that does something with it. Makes for a clearer search loop. Use a local Error * to simplify resetting the error in the search loop. Signed-off-by: Markus Armbruster arm...@redhat.com --- Forgot to include this one. inet_connect_opts() admittedly isn't in the character backend subsystem, just used by it. Hope it's close enough for review and commit. util/qemu-sockets.c | 28 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 8818d7c..627e609 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -354,6 +354,7 @@ static struct addrinfo *inet_parse_connect_opts(QemuOpts *opts, Error **errp) int inet_connect_opts(QemuOpts *opts, Error **errp, NonBlockingConnectHandler *callback, void *opaque) { +Error *local_err = NULL; struct addrinfo *res, *e; int sock = -1; bool in_progress; @@ -372,24 +373,27 @@ int inet_connect_opts(QemuOpts *opts, Error **errp, } for (e = res; e != NULL; e = e-ai_next) { -if (error_is_set(errp)) { -error_free(*errp); -*errp = NULL; -} +error_free(local_err); +local_err = NULL; if (connect_state != NULL) { connect_state-current_addr = e; } -sock = inet_connect_addr(e, in_progress, connect_state, errp); -if (in_progress) { -return sock; -} else if (sock = 0) { -/* non blocking socket immediate success, call callback */ -if (callback != NULL) { -callback(sock, opaque); -} +sock = inet_connect_addr(e, in_progress, connect_state, local_err); +if (sock = 0) { break; } } + +if (sock 0) { +error_propagate(errp, local_err); +} else if (in_progress) { +/* wait_for_connect() will do the rest */ +return sock; +} else { +if (callback) { +callback(sock, opaque); +} +} g_free(connect_state); freeaddrinfo(res); return sock; -- 1.8.1.4
Re: [Qemu-devel] [PATCH] Makefile: Fix per-object variables for Makefile.target
Il 29/04/2014 05:29, Fam Zheng ha scritto: The compiling is done in a subdir, so the extraction of per-object libs and cflags are referencing objects with ../ prefixed. So prefix the per-object variables foo.o-cflags and foo.o-libs to ../foo.o-cflags and ../foo.o-libs. Signed-off-by: Fam Zheng f...@redhat.com --- Makefile.target | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile.target b/Makefile.target index ba12340..3a30aad 100644 --- a/Makefile.target +++ b/Makefile.target @@ -146,11 +146,12 @@ obj-y-save := $(obj-y) block-obj-y := common-obj-y := include $(SRC_PATH)/Makefile.objs -dummy := $(call unnest-vars,.., \ - block-obj-y \ - block-obj-m \ - common-obj-y \ - common-obj-m) +vars := block-obj-y \ +block-obj-m \ +common-obj-y \ +common-obj-m +dummy := $(foreach v,$(vars),$(call fix-obj-vars,$v,../)) +dummy := $(call unnest-vars,.., $(vars)) # Now restore obj-y obj-y := $(obj-y-save) What about this instead, does it do the same? diff --git a/rules.mak b/rules.mak index 5c454d8..7038576 100644 --- a/rules.mak +++ b/rules.mak @@ -228,6 +228,7 @@ endef define unnest-vars $(eval obj := $1) $(eval nested-vars := $2) +$(foreach v,$(nested-vars),$(call fix-obj-vars,$v,$(if $(obj),$(obj)/))) $(eval old-nested-dirs := ) $(call unnest-vars-1) $(if $1,$(foreach v,$(nested-vars),$(eval \ Regarding Michael's objection, I do have a simplification patch pending to use subdir-y instead of embedding directories in the object variables. That does make things a bit simpler. Paolo
Re: [Qemu-devel] [PATCH 4/3] qemu-socket: Clean up inet_connect_opts()
In-Reply-To missing, sorry! Markus Armbruster arm...@redhat.com writes: Separate the search for a working addrinfo from the code that does something with it. Makes for a clearer search loop. Use a local Error * to simplify resetting the error in the search loop. Signed-off-by: Markus Armbruster arm...@redhat.com --- Forgot to include this one. inet_connect_opts() admittedly isn't in the character backend subsystem, just used by it. Hope it's close enough for review and commit. util/qemu-sockets.c | 28 1 file changed, 16 insertions(+), 12 deletions(-)
Re: [Qemu-devel] [PATCH] MAINTAINERS: addresses for responsible disclosure
On Mon, Apr 28, 2014 at 09:00:40PM +, Liguori, Anthony wrote: I think this is a bit overkill. Hmm to clarify, this forces people to send info about 0 day exploits over the internet in cleartext. What do we get in return for sacrificing the privacy? A small convenience of not typing in 3 addresses? Many projects use private mailing lists for this purpose. True that some others do this but frankly I don't understand it. Maybe this tradeoff starts to make sense if the list of subscribers is large? Regards, Anthony Liguori From: Michael S. Tsirkin [m...@redhat.com] Sent: Monday, April 28, 2014 10:53 AM To: Liguori, Anthony Cc: Peter Maydell; Anthony Liguori; qemu-devel; Stefan Hajnoczi; Andreas Färber Subject: Re: [Qemu-devel] [PATCH] MAINTAINERS: addresses for responsible disclosure On Mon, Apr 28, 2014 at 05:35:38PM +0300, Michael S. Tsirkin wrote: I'll play around once I get the password. From what I've seen so far, I'm not sure it's the right server to use for security :( I did some more reseach and savannah does not seem to support any encryption for its lists: neither TLS nor PGP. This would mean that all communication has to be in the clear. I think that for this use, we would be better off with an option that can guarantee a measure of privacy. For now simply listing specific addresses and GPG keys looks like the only way. Makes sense? I would really like us to get an agreement on this so we can start making progress on harder issues such as agreeing on a security policy. The list now appears here https://lists.nongnu.org/mailman/listinfo under the heading Below is a listing of all the public mailing lists on lists.nongnu.org. The list page https://lists.nongnu.org/mailman/listinfo/qemu-security also seems to even have a link to public archives - it's not live but its presence might scare people away. We definitely do not want this list to be public - it's so people who want to do the responsible disclosure process can get some response and possibly help. If someone just wants to go public there's always qemu-devel. I guess we can configure it to actually be non-public, but hiding information seems unlikely to be one of savannah's strong points. I know if I was asked to post sensitive information to such a list I would hesitate, which isn't the effect we are trying to achieve here. On Mon, Apr 28, 2014 at 01:57:26PM +, Liguori, Anthony wrote: https://lists.nongnu.org/mailman/admin/qemu-security Has been created but it will take 24-48 hours for Savannah to do it's thing. I'll send out the mailing list password to Michael and Peter once it is created. Regards, Anthony Liguori From: Michael S. Tsirkin [m...@redhat.com] Sent: Monday, April 28, 2014 6:39 AM To: Peter Maydell Cc: Anthony Liguori; qemu-devel; Stefan Hajnoczi; Andreas Färber; Liguori, Anthony Subject: Re: [Qemu-devel] [PATCH] MAINTAINERS: addresses for responsible disclosure On Mon, Apr 28, 2014 at 02:24:45PM +0100, Peter Maydell wrote: On 17 April 2014 19:54, Michael S. Tsirkin m...@redhat.com wrote: On Thu, Apr 17, 2014 at 09:10:12AM -0700, Anthony Liguori wrote: On Thu, Apr 17, 2014 at 6:54 AM, Michael S. Tsirkin m...@redhat.com wrote: People sometimes detect security issues in upstream QEMU and don't know where to report them in a non-public way. Of course whoever just wants full disclosure can just go public, but there's nothing specified for non-public - until recently Anthony was doing this informally. As I started doing this recently anyway, I can handle this on the QEMU side in a more formal way. Adding a secalert mailing list as well - they are the ones who is actually opening CVEs, communicating issues to all downstreams etc, and they are already handling this for upstream, not just Red Hat. Keeping Anthony's address around in case he wants to be informed. Signed-off-by: Michael S. Tsirkin m...@redhat.com What about using qemu-secur...@nongnu.org and creating that as a moderated mailing list with no public archive? That way there's a single contact point and there can be many people backing it up to make sure that disclosures are handled very quickly. Also I'd like a more explicit name, we don't want general security related discussions on that list. qemu-secal...@nongnu.org ? OK, so do we want to: (a) commit this patch as-is (b) set up the proposed mailing list? If (b), who has the admin rights to do that? I don't feel strongly either way. thanks -- PMM Way I see it, as long as it has the same people, it probably doesn't matter :)
Re: [Qemu-devel] [PATCH] configure: Enable dead code (lzo, snappy, quorum)
On 04/29/2014 02:21 PM, Stefan Weil wrote: Those options were not enabled by default, even when the build environment would have supported them, so the corresponding code was not compiled in normal test builds like on build bots. Signed-off-by: Stefan Weils...@weilnetz.de Reviewed-by: Qiao Nuohan qiaonuo...@cn.fujitsu.com --- I'm not sure whether this patch is trivial enough for qemu-trivial. Are there any disadvantages when this code is enabled? Stefan configure | 39 --- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 2fbec59..0faadd7 100755 --- a/configure +++ b/configure @@ -301,8 +301,8 @@ libusb= usb_redir= glx= zlib=yes -lzo=no -snappy=no +lzo= +snappy= guest_agent= guest_agent_with_vss=no vss_win32_sdk= @@ -323,7 +323,7 @@ vte= tpm=no libssh2= vhdx= -quorum=no +quorum= # parse CC options first for opt do @@ -1023,8 +1023,12 @@ for opt do ;; --disable-zlib-test) zlib=no ;; + --disable-lzo) lzo=no + ;; --enable-lzo) lzo=yes ;; + --disable-snappy) snappy=no + ;; --enable-snappy) snappy=yes ;; --enable-guest-agent) guest_agent=yes @@ -1722,13 +1726,14 @@ if test $lzo != no ; then int main(void) { lzo_version(); return 0; } EOF if compile_prog -llzo2 ; then -: +libs_softmmu=$libs_softmmu -llzo2 +lzo=yes else -error_exit lzo check failed \ -Make sure to have the lzo libs and headers installed. +if test $lzo = yes; then +feature_not_found liblzo2 Install liblzo2 devel +fi +lzo=no fi - -libs_softmmu=$libs_softmmu -llzo2 fi ## @@ -1740,13 +1745,14 @@ if test $snappy != no ; then int main(void) { snappy_max_compressed_length(4096); return 0; } EOF if compile_prog -lsnappy ; then -: +libs_softmmu=$libs_softmmu -lsnappy +snappy=yes else -error_exit snappy check failed \ -Make sure to have the snappy libs and headers installed. +if test $snappy = yes; then +feature_not_found libsnappy Install libsnappy devel +fi +snappy=no fi - -libs_softmmu=$libs_softmmu -lsnappy fi ## @@ -2172,9 +2178,12 @@ if compile_prog $quorum_tls_cflags $quorum_tls_libs ; then libs_softmmu=$quorum_tls_libs $libs_softmmu libs_tools=$quorum_tls_libs $libs_softmmu QEMU_CFLAGS=$QEMU_CFLAGS $quorum_tls_cflags + quorum=yes else - echo gnutls 2.10.0 required to compile Quorum - exit 1 + if test $quorum = yes; then +feature_not_found gnutls gnutls 2.10.0 required to compile Quorum + fi + quorum=no fi fi -- Regards Qiao Nuohan
[Qemu-devel] E1000 emulation in QEMU (address range)
Hi !! Can anyone tell me, what IO and mem address range is used by e1000 emulation in QEMU ??
Re: [Qemu-devel] KVM call agenda for 2014-04-28
On Mon, Apr 28, 2014 at 05:34:34PM +0200, Markus Armbruster wrote: Juan Quintela quint...@redhat.com writes: Hi Please, send any topic that you are interested in covering. [...] I'd like to have these things settled sooner than five minutes before the scheduled hour, so here goes: call or no call? Agenda? If not too late, I'd like to discuss our security process. Do we as the project generally agree to use responsible disclosure policy http://en.wikipedia.org/wiki/Responsible_disclosure ?
[Qemu-devel] [Bug 1313816] Re: qemu should close sound device when no more needs.
This will not work if qemu is chrooted, because audio devices (/dev) aren't usually available there. So at least a naive approach should not be used. If nothing else, it should be an option. But really, with pulseaudio backend, there should be no need to go this route and to add new code. -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1313816 Title: qemu should close sound device when no more needs. Status in QEMU: New Bug description: I use alsa directly or via pulseaudio on qemu. And I use xmms2 as well as qemu. When I use alsa, one of xmms2 or qemu can play sound. When I use pulseaudio with qemu and pulseaudio -k, and pulseaudio --start, qemu can't play sound. I think that: - qemu should open sound device when needs. - qemu should close sound device when no more needs. One of xmms2 or qemu can play sound, but both of them rarely play sound at the same time. qemu occurs error on pulseaudio -k, but once close and open the device, the error will be recovered, I hope. Host: slackware64 14.1, linux kernel 3.14.2 Qemu: 2.0.0 QEMU_AUDIO_DRV=pa /usr/local/bin/qemu-system-x86_64 -enable-kvm -hda /dosc/win8_x64.img -soundhw hda -boot c -m 2G -cpu host -usb -usbdevice tablet -display sdl -rtc base=localtime Guest: Windows 8.1 x64 To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1313816/+subscriptions
Re: [Qemu-devel] [PATCH] -nographic sometimes adds an extra chardev for stdio
On Mo, 2014-04-28 at 11:00 -0400, Mike Day wrote: When the deprecated -nographic option is used with the -mon option in readline mode, qemu will create a second character device for stdio and place it over the stdio chardev put into place by the -mon option. This causes the terminal to stop echoeing characters upon exit from Qemu. Welcome to the fun world of default devices. We'd love to get rid of them as they also cause other similar grief, but we can't if we want maintain backward compatibility :( I strongly suggest to simply use '-nodefaults' if default devices get into your way. Defining the serial line the way you want it using '-serial $args' or '-device isa-serial,$args' will work (in that specific case) too. I don't feel like adding more band-aid to paper over the fundamental issue. Too much band-aid tends to cause other unwanted side effects. cheers, Gerd
Re: [Qemu-devel] [PATCH] linux-user: avoid using glibc internals
On Wed, 23 Apr 2014 19:00:41 +0100 Peter Maydell peter.mayd...@linaro.org wrote: On 23 April 2014 15:59, Natanael Copa nc...@alpinelinux.org wrote: Avoid using glibc specific internals. Calculate the sigevent pad size is calculated in similar way as kernel does it. This is needed for building with musl libc. Thanks for this patch -- is this the only fix that was needed, or are there more to come? There are more patches needed to make it build and run with musl libc. Those were not mine, but I can try clean them up and submit those if here is interest for it. The problem this patch resolves was introduced with qemu 2.0. It would be nice to be a little more specific in the patch summary line about the change, like: linux-user: avoid using glibc internals in definition of target_sigevent struct Agree. Signed-off-by: Natanael Copa nc...@alpinelinux.org --- linux-user/syscall.c | 2 +- linux-user/syscall_defs.h | 6 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9864813..c8989b6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -406,7 +406,7 @@ static int sys_inotify_init1(int flags) #endif #define __NR_sys_ppoll __NR_ppoll _syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds, - struct timespec *, timeout, const __sigset_t *, sigmask, + struct timespec *, timeout, const sigset_t *, sigmask, size_t, sigsetsize) #endif diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index fdf9a47..450f71b 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2552,12 +2552,16 @@ struct target_timer_t { abi_ulong ptr; }; +#define TARGET_SIGEV_MAX_SIZE 64 +#define TARGET_SIGEV_PREAMABLE_SIZE (sizeof(int32_t) * 2 + sizeof(target_sigval_t)) This is wrong for 64 bit MIPS, I think; compare the kernel's MIPS-specific override: http://lxr.linux.no/#linux+v3.14.1/arch/mips/include/uapi/asm/siginfo.h#L13 I suggest /* This is architecture-specific but most architectures use the default */ #ifdef TARGET_MIPS #define TARGET_SIGEV_PREAMBLE_SIZE (sizeof(int32_t) * 2 + sizeof(abi_long)) #else TARGET_SIGEV_PREAMBLE_SIZE (sizeof(int32_t) * 2 + sizeof(target_sigval_t)) #endif I'm not entirely sure this is required -- our target_sigval_t looks like it ought to be sizeof(abi_long) for MIPS so I don't know why the kernel needs this override and we apparently don't. Perhaps our target_sigval_t definition is slightly wrong? Anyway, putting in the override can't hurt and might avoid subtle issues later on if target_sigval_t does turn out to be broken and need changing... Ok. No problem. (Note also that 'PREAMBLE' only has one 'A'.) whoops. +#define TARGET_SIGEV_PAD_SIZE ((TARGET_SIGEV_MAX_SIZE - TARGET_SIGEV_PREAMABLE_SIZE) / sizeof(int32_t)) This line looks like it has more than 80 chars; if so, it should be folded. (You can check using scripts/checkpatch.pl.) I wasn't sure of the folding rules. struct target_sigevent { target_sigval_t sigev_value; int32_t sigev_signo; int32_t sigev_notify; union { -int32_t _pad[ARRAY_SIZE(((struct sigevent *)0)-_sigev_un._pad)]; +int32_t _pad[TARGET_SIGEV_PAD_SIZE]; int32_t _tid; struct { -- 1.9.2 Looks good overall though. thanks -- PMM I'll fix and resend. Thanks for feedback. -nc
Re: [Qemu-devel] [PATCH] Makefile: Fix per-object variables for Makefile.target
On Tue, 04/29 08:29, Paolo Bonzini wrote: Il 29/04/2014 05:29, Fam Zheng ha scritto: The compiling is done in a subdir, so the extraction of per-object libs and cflags are referencing objects with ../ prefixed. So prefix the per-object variables foo.o-cflags and foo.o-libs to ../foo.o-cflags and ../foo.o-libs. Signed-off-by: Fam Zheng f...@redhat.com --- Makefile.target | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile.target b/Makefile.target index ba12340..3a30aad 100644 --- a/Makefile.target +++ b/Makefile.target @@ -146,11 +146,12 @@ obj-y-save := $(obj-y) block-obj-y := common-obj-y := include $(SRC_PATH)/Makefile.objs -dummy := $(call unnest-vars,.., \ - block-obj-y \ - block-obj-m \ - common-obj-y \ - common-obj-m) +vars := block-obj-y \ +block-obj-m \ +common-obj-y \ +common-obj-m +dummy := $(foreach v,$(vars),$(call fix-obj-vars,$v,../)) +dummy := $(call unnest-vars,.., $(vars)) # Now restore obj-y obj-y := $(obj-y-save) What about this instead, does it do the same? Yes, it's better! Fam diff --git a/rules.mak b/rules.mak index 5c454d8..7038576 100644 --- a/rules.mak +++ b/rules.mak @@ -228,6 +228,7 @@ endef define unnest-vars $(eval obj := $1) $(eval nested-vars := $2) +$(foreach v,$(nested-vars),$(call fix-obj-vars,$v,$(if $(obj),$(obj)/))) $(eval old-nested-dirs := ) $(call unnest-vars-1) $(if $1,$(foreach v,$(nested-vars),$(eval \ Regarding Michael's objection, I do have a simplification patch pending to use subdir-y instead of embedding directories in the object variables. That does make things a bit simpler. Paolo
[Qemu-devel] [PATCH] mirror: Fix resource leak when bdrv_getlength fails
The direct return will skip releasing of all the resouces at immediate_exit, don't miss that. Signed-off-by: Fam Zheng f...@redhat.com --- block/mirror.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index 2618c37..56dfee2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -326,7 +326,8 @@ static void coroutine_fn mirror_run(void *opaque) s-common.len = bdrv_getlength(bs); if (s-common.len = 0) { block_job_completed(s-common, s-common.len); -return; +ret = s-common.len; +goto immediate_exit; } length = (bdrv_getlength(bs) + s-granularity - 1) / s-granularity; -- 1.9.2
[Qemu-devel] [PATCH v3] mirror: Check for bdrv_get_info result
bdrv_get_info could fail. Add check before using the returned value. Signed-off-by: Fam Zheng f...@redhat.com --- v3: Don't leak things, jump to immediate_exit. (Kevin) Signed-off-by: Fam Zheng f...@redhat.com --- block/mirror.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index 2618c37..fbea051 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -339,7 +339,11 @@ static void coroutine_fn mirror_run(void *opaque) bdrv_get_backing_filename(s-target, backing_filename, sizeof(backing_filename)); if (backing_filename[0] !s-target-backing_hd) { -bdrv_get_info(s-target, bdi); +ret = bdrv_get_info(s-target, bdi); +if (ret 0) { +block_job_completed(s-common, ret); +goto immediate_exit; +} if (s-granularity bdi.cluster_size) { s-buf_size = MAX(s-buf_size, bdi.cluster_size); s-cow_bitmap = bitmap_new(length); -- 1.9.2
[Qemu-devel] [PATCH] linux-user: avoid using glibc internals in _syscall5 and in definition of target_sigevent struct
Use the public sigset_t instead of the glibc specific internal __sigset_t in _syscall. Calculate the sigevent pad size is calculated in similar way as kernel does it instead of using glibc internal field _pad. This is needed for building with musl libc. Signed-off-by: Natanael Copa nc...@alpinelinux.org --- Changes since v1: - Be more specific in commit message. - Special handling for target MIPS 64 - Fix typo of PREAMBLE - Fold lines longer than 80 chars to make scripts/checkpatch.pl happy - Replace tabs with spaces to make scripts/checkpatch.pl happy linux-user/syscall.c | 2 +- linux-user/syscall_defs.h | 16 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9864813..c8989b6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -406,7 +406,7 @@ static int sys_inotify_init1(int flags) #endif #define __NR_sys_ppoll __NR_ppoll _syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds, - struct timespec *, timeout, const __sigset_t *, sigmask, + struct timespec *, timeout, const sigset_t *, sigmask, size_t, sigsetsize) #endif diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index fdf9a47..5dd96b2 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2552,12 +2552,26 @@ struct target_timer_t { abi_ulong ptr; }; +#define TARGET_SIGEV_MAX_SIZE 64 + +/* This is architecture-specific but most architectures use the default */ +#ifdef TARGET_MIPS +#define TARGET_SIGEV_PREAMBLE_SIZE (sizeof(int32_t) * 2 + sizeof(abi_long)) +#else +#define TARGET_SIGEV_PREAMBLE_SIZE (sizeof(int32_t) * 2 \ ++ sizeof(target_sigval_t)) +#endif + +#define TARGET_SIGEV_PAD_SIZE ((TARGET_SIGEV_MAX_SIZE \ +- TARGET_SIGEV_PREAMABLE_SIZE) \ + / sizeof(int32_t)) + struct target_sigevent { target_sigval_t sigev_value; int32_t sigev_signo; int32_t sigev_notify; union { -int32_t _pad[ARRAY_SIZE(((struct sigevent *)0)-_sigev_un._pad)]; +int32_t _pad[TARGET_SIGEV_PAD_SIZE]; int32_t _tid; struct { -- 1.9.2
Re: [Qemu-devel] [PATCH 3/5] vscclient: use glib thread primitives not qemu
Hey, On Tue, Apr 29, 2014 at 10:02:26AM +0400, Michael Tokarev wrote: Use glib-provided thread primitives in vscclient, not qemu thread primitives. This way, vscclient becomes more stand-alone. For what it's worth, this patch has a few non-threading related bits in it because of the removal of #include qemu/sockets.h I guess.
Re: [Qemu-devel] [PATCH 3/5] vscclient: use glib thread primitives not qemu
29.04.2014 12:03, Christophe Fergeau wrote: Hey, On Tue, Apr 29, 2014 at 10:02:26AM +0400, Michael Tokarev wrote: Use glib-provided thread primitives in vscclient, not qemu thread primitives. This way, vscclient becomes more stand-alone. For what it's worth, this patch has a few non-threading related bits in it because of the removal of #include qemu/sockets.h I guess. Yes indeed, the commit message can be a bit more accurate. It removes usage of qemu sockets too -- the only socket interface it needed is socket(AF_INET, SOCK_STREAM), which I used instead of qemu_socket(). Plus a cal to WSAStartup for a windows platform. There's no need to use whole libqemuutil.a (which pulls in another pile of symbols) just for the 2 tiny functions. I'll mention this in the improved commit message. Thank you! /mjt
Re: [Qemu-devel] [PATCH 1/5] do not call g_thread_init() for glib = 2.31
On Tue, Apr 29, 2014 at 10:02:24AM +0400, Michael Tokarev wrote: glib = 2.31 always enables thread support and g_thread_supported() is #defined to 1, there's no need to call g_thread_init() anymore, and it definitely does not need to report error which never happens. Keep code for old 2.31 glibc anyway for now, just #ifdef it differently. This looks good to me, ACK Signed-off-by: Michael Tokarev m...@tls.msk.ru --- coroutine-gthread.c |7 ++- util/osdep.c| 21 + 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/coroutine-gthread.c b/coroutine-gthread.c index d3e5b99..a61efe0 100644 --- a/coroutine-gthread.c +++ b/coroutine-gthread.c @@ -115,14 +115,11 @@ static inline GThread *create_thread(GThreadFunc func, gpointer data) static void __attribute__((constructor)) coroutine_init(void) { -if (!g_thread_supported()) { #if !GLIB_CHECK_VERSION(2, 31, 0) +if (!g_thread_supported()) { g_thread_init(NULL); -#else -fprintf(stderr, glib threading failed to initialize.\n); -exit(1); -#endif } +#endif init_coroutine_cond(); } diff --git a/util/osdep.c b/util/osdep.c index a9029f8..b2bd154 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -436,23 +436,20 @@ int socket_init(void) return 0; } -/* Ensure that glib is running in multi-threaded mode */ +#if !GLIB_CHECK_VERSION(2, 31, 0) +/* Ensure that glib is running in multi-threaded mode + * Old versions of glib require explicit initialization. Failure to do + * this results in the single-threaded code paths being taken inside + * glib. For example, the g_slice allocator will not be thread-safe + * and cause crashes. + */ static void __attribute__((constructor)) thread_init(void) { if (!g_thread_supported()) { -#if !GLIB_CHECK_VERSION(2, 31, 0) -/* Old versions of glib require explicit initialization. Failure to do - * this results in the single-threaded code paths being taken inside - * glib. For example, the g_slice allocator will not be thread-safe - * and cause crashes. - */ -g_thread_init(NULL); -#else -fprintf(stderr, glib threading failed to initialize.\n); -exit(1); -#endif + g_thread_init(NULL); } } +#endif #ifndef CONFIG_IOVEC /* helper function for iov_send_recv() */ -- 1.7.10.4
Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic
Il 07/04/2014 17:36, Michael S. Tsirkin ha scritto: * What if there would be more handlers that could or should handle event for device? That's actually very useful. We could scan top to bottom so e.g. acpi can intercept bridges. Be careful about top to bottom. Does top-to-bottom mean by bus or by composition? This has been a huge can of worms in the discussions about recursive realization. One thing we could do is to always go through /machine even before invoking the bus handler. Then /machine can do machine-specific checks to interpose the PCI host bridge and/or the ACPI device's hotplug handlers. But this can be done on top of this series, it has nothing to do with memory hotplug and this one is already big enough! Paolo
Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic
On Tue, Apr 29, 2014 at 10:12:34AM +0200, Paolo Bonzini wrote: Il 07/04/2014 17:36, Michael S. Tsirkin ha scritto: * What if there would be more handlers that could or should handle event for device? That's actually very useful. We could scan top to bottom so e.g. acpi can intercept bridges. Be careful about top to bottom. Does top-to-bottom mean by bus or by composition? This has been a huge can of worms in the discussions about recursive realization. One thing we could do is to always go through /machine even before invoking the bus handler. Then /machine can do machine-specific checks to interpose the PCI host bridge and/or the ACPI device's hotplug handlers. But this can be done on top of this series, it has nothing to do with memory hotplug and this one is already big enough! Paolo Yes, new functionality does not need to be added in this patchset. But to repeat what I was saying, this check (that object passed in is a PCI DEVICE) belongs in acpi_pcihp_device_plug_cb and should not be piix specific, I don't want to duplicate this logic in q35 later. Similar checks should be added in shpc_device_hotplug_cb pcie_cap_slot_hotplug_cb for consistency. -- MST
Re: [Qemu-devel] [PATCH 4/5] libcacard: replace qemu thread primitives with glib ones
Hey, patch looks good On Tue, Apr 29, 2014 at 10:02:27AM +0400, Michael Tokarev wrote: Replace QemuMutex with GMutex and QemuCond with GCond (with corresponding function changes), to make libcacard independent of qemu internal functions. Also replace single instance pstrcpy() in vcard_emul_nss.c to strncpy(). This reverts commit 2e679780ae86c6ca8. An alternative would be to use g_strlcpy which guarantees nul-termination. Christophe
Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic
On Fri, Apr 11, 2014 at 09:40:19PM -0400, Paolo Bonzini wrote: Il 07/04/2014 11:19, Michael S. Tsirkin ha scritto: This means we can't cleanly implement an option for guest to disable ACPI and switch to native if supported, like the ACPI spec allows. If we change hotplug code to walk the tree top down and invoke all callbacks, then it will be fixed in a cleaner way: bridges would just do: if (dev-bus != self) { set_error return; } and suddently pci host can trap callbacks and redirect to acpi if it wants to. I think this should be handled by making the q35 PCI host bridge implement HotplugHandler itself, possibly overriding the parent's implementation. Paolo Yes but it needs to be dynamic, i.e. q35 should be able to say at runtime I can't handle this hotplug, pass it up to parent rather than just checking callback is NULL.
Re: [Qemu-devel] [PATCH 4/5] libcacard: replace qemu thread primitives with glib ones
Il 29/04/2014 10:26, Christophe Fergeau ha scritto: Replace QemuMutex with GMutex and QemuCond with GCond (with corresponding function changes), to make libcacard independent of qemu internal functions. Also replace single instance pstrcpy() in vcard_emul_nss.c to strncpy(). This reverts commit 2e679780ae86c6ca8. An alternative would be to use g_strlcpy which guarantees nul-termination. Yes, that is better. Paolo
Re: [Qemu-devel] [PATCH] linux-user: avoid using glibc internals
On Wed, 23 Apr 2014 19:00:41 +0100 Peter Maydell peter.mayd...@linaro.org wrote: On 23 April 2014 15:59, Natanael Copa nc...@alpinelinux.org wrote: Avoid using glibc specific internals. Calculate the sigevent pad size is calculated in similar way as kernel does it. This is needed for building with musl libc. Thanks for this patch -- is this the only fix that was needed, or are there more to come? Alpine Linux actually also needs the previously posted patch: http://lists.gnu.org/archive/html/qemu-devel/2013-07/msg00774.html Thanks! -nc
Re: [Qemu-devel] [PATCH 4/5] libcacard: replace qemu thread primitives with glib ones
29.04.2014 12:38, Paolo Bonzini wrote: Il 29/04/2014 10:26, Christophe Fergeau ha scritto: Replace QemuMutex with GMutex and QemuCond with GCond (with corresponding function changes), to make libcacard independent of qemu internal functions. Also replace single instance pstrcpy() in vcard_emul_nss.c to strncpy(). This reverts commit 2e679780ae86c6ca8. An alternative would be to use g_strlcpy which guarantees nul-termination. Yes, that is better. Actually in this very place it isn't really important, given we always know the exact length of the source and are able to adjust it to fit into the buffer. With g_strlcat() code becomes a bit more ugly... ;) But mind you, this is the least important change in the whole patchset. We are risking to dig into unimportant details and miss forest for the trees in the result. Thanks, /mjt
[Qemu-devel] [PATCH 0/2] usb: mtp: incremental fixes
Hi, Resending updates for the two mtp patches which has review comments. cheers, Gerd Gerd Hoffmann (2): usb: mtp: fix possible buffer overflow usb: mtp: reply INCOMPLETE_TRANSFER on read errors hw/usb/dev-mtp.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 1.8.3.1
[Qemu-devel] [PATCH 2/2] usb: mtp: reply INCOMPLETE_TRANSFER on read errors
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- hw/usb/dev-mtp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 62428d8..943f930 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -50,6 +50,7 @@ enum mtp_code { RES_INVALID_TRANSACTION_ID = 0x2004, RES_OPERATION_NOT_SUPPORTED= 0x2005, RES_PARAMETER_NOT_SUPPORTED= 0x2006, +RES_INCOMPLETE_TRANSFER= 0x2007, RES_INVALID_STORAGE_ID = 0x2008, RES_INVALID_OBJECT_HANDLE = 0x2009, RES_SPEC_BY_FORMAT_UNSUPPORTED = 0x2014, @@ -946,7 +947,8 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p) } rc = read(d-fd, d-data, dlen); if (rc != dlen) { -fprintf(stderr, %s: TODO: handle read error\n, __func__); +memset(d-data, 0, dlen); +s-result-code = RES_INCOMPLETE_TRANSFER; } usb_packet_copy(p, d-data, dlen); } -- 1.8.3.1
[Qemu-devel] [PATCH 1/2] usb: mtp: fix possible buffer overflow
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- hw/usb/dev-mtp.c | 8 1 file changed, 8 insertions(+) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index b6eaeae..62428d8 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -998,6 +998,14 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p) cmd.argc = (le32_to_cpu(container.length) - sizeof(container)) / sizeof(uint32_t); cmd.trans = le32_to_cpu(container.trans); +if (cmd.argc ARRAY_SIZE(cmd.argv)) { +cmd.argc = ARRAY_SIZE(cmd.argv); +} +if (p-iov.size sizeof(container) + cmd.argc * sizeof(uint32_t)) { +trace_usb_mtp_stall(s-dev.addr, packet too small); +p-status = USB_RET_STALL; +return; +} usb_packet_copy(p, params, cmd.argc * sizeof(uint32_t)); for (i = 0; i cmd.argc; i++) { cmd.argv[i] = le32_to_cpu(params[i]); -- 1.8.3.1
Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic
Il 29/04/2014 09:25, Michael S. Tsirkin ha scritto: But to repeat what I was saying, this check (that object passed in is a PCI DEVICE) belongs in acpi_pcihp_device_plug_cb and should not be piix specific, I don't want to duplicate this logic in q35 later. Similar checks should be added in shpc_device_hotplug_cb pcie_cap_slot_hotplug_cb for consistency. I disagree. In fact, I think the opposite is true: the three functions you mention should take a PCIDevice*, and when this is done acpi_memory_plug_cb should be changed to take a DIMMDevice* too. Paolo
Re: [Qemu-devel] [PATCH] block: Add '--version' option to qemu-img
Am 28.04.2014 um 20:37 hat Jeff Cody geschrieben: This allows qemu-img to print out version information, without needing to print the long help wall of text. While there, perform some minor whitespace cleanup, and remove the unused option_index variable in the call to getopt_long(). Reported-by: Eric Blake ebl...@redhat.com Signed-off-by: Jeff Cody jc...@redhat.com Thanks, applied to the block branch. Kevin
Re: [Qemu-devel] KVM call agenda for 2014-04-28
On 28.04.2014, at 17:34, Markus Armbruster arm...@redhat.com wrote: Juan Quintela quint...@redhat.com writes: Hi Please, send any topic that you are interested in covering. [...] I'd like to have these things settled sooner than five minutes before the scheduled hour, so here goes: call or no call? Agenda? I don't think we managed to fully conclude on a good way to assign sysbus/platbus devices into the guest using configuration data only, did we? Would be good to put that on today's agenda again and conclude on something, so people who need it can work into the right direction. Alex
Re: [Qemu-devel] KVM call agenda for 2014-04-28
On 29 April 2014 06:51, Michael S. Tsirkin m...@redhat.com wrote: If not too late, I'd like to discuss our security process. Do we as the project generally agree to use responsible disclosure policy http://en.wikipedia.org/wiki/Responsible_disclosure ? I think something like that makes sense. I'm a bit wary that we write up some complicated policy that we're not then in practice capable of executing given our level of resources. We should certainly write out some documentation though... thanks -- PMM
Re: [Qemu-devel] [PATCHv2 RESEND] block/iscsi: speed up read for unallocated sectors
Am 28.04.2014 16:56, schrieb Paolo Bonzini: Il 28/04/2014 16:41, Peter Lieven ha scritto: What if opt_unmap_gran is 32K or lower? In this case you're not using an allocationmap. As written I am fine with lowering this to 4K. Follow-Up or v3? Follow up is okay. 2 follow ups send. I also added some comments about the threshold to explain its meaning. Peter
[Qemu-devel] [PULL 0/1] hda-audio: fix non-mixer codecs
Hi, pretty short audio patch queue, featuring a single hda-audio fix. please pull, Gerd The following changes since commit e2da502c003b9a91b4aea7684959192bd07c1f1d: Merge remote-tracking branch 'remotes/otubo/seccomp' into staging (2014-04-28 14:14:35 +0100) are available in the git repository at: git://git.kraxel.org/qemu tags/pull-audio-4 for you to fetch changes up to 4843877e5d7d9ef4fdd29ac14ee1ce55531a0fc4: hda-audio: fix non-mixer codecs (2014-04-29 10:46:29 +0200) hda-audio: fix non-mixer codecs Gerd Hoffmann (1): hda-audio: fix non-mixer codecs hw/audio/hda-codec.c | 3 +++ 1 file changed, 3 insertions(+)
[Qemu-devel] [PULL 1/1] hda-audio: fix non-mixer codecs
They don't advertise mixer support, but still allow the guest change mixer settings. Add a check to avoid it. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- hw/audio/hda-codec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c index a67ca91..48c6ead 100644 --- a/hw/audio/hda-codec.c +++ b/hw/audio/hda-codec.c @@ -261,6 +261,9 @@ static void hda_audio_set_amp(HDAAudioStream *st) left = left * 255 / QEMU_HDA_AMP_STEPS; right = right * 255 / QEMU_HDA_AMP_STEPS; +if (!st-state-mixer) { +return; +} if (st-output) { AUD_set_volume_out(st-voice.out, muted, left, right); } else { -- 1.8.3.1
[Qemu-devel] [PATCH V26 01/32] QemuOpts: move find_desc_by_name ahead for later calling
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- util/qemu-option.c | 28 ++-- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 8bbc3ad..808aef4 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -173,6 +173,20 @@ static void parse_option_number(const char *name, const char *value, } } +static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc, +const char *name) +{ +int i; + +for (i = 0; desc[i].name != NULL; i++) { +if (strcmp(desc[i].name, name) == 0) { +return desc[i]; +} +} + +return NULL; +} + void parse_option_size(const char *name, const char *value, uint64_t *ret, Error **errp) { @@ -637,20 +651,6 @@ static bool opts_accepts_any(const QemuOpts *opts) return opts-list-desc[0].name == NULL; } -static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc, -const char *name) -{ -int i; - -for (i = 0; desc[i].name != NULL; i++) { -if (strcmp(desc[i].name, name) == 0) { -return desc[i]; -} -} - -return NULL; -} - int qemu_opt_unset(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); -- 1.8.4.5
[Qemu-devel] [PATCH V26 03/32] QemuOpts: repurpose qemu_opts_print to replace print_option_parameters
Currently this function is not used anywhere. In later patches, it will replace print_option_parameters. To avoid print info changes, change qemu_opts_print from fprintf stderr to printf to keep consistent with print_option_parameters, remove last printf and print size/number with opt-value.uint instead of opt-str. Signed-off-by: Chunyan Liu cy...@suse.com --- util/qemu-option.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 5346c90..2be6995 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -925,7 +925,7 @@ void qemu_opts_print(QemuOpts *opts) if (desc[0].name == NULL) { QTAILQ_FOREACH(opt, opts-head, next) { -fprintf(stderr, %s=\%s\ , opt-name, opt-str); +printf(%s=\%s\ , opt-name, opt-str); } return; } @@ -938,12 +938,14 @@ void qemu_opts_print(QemuOpts *opts) continue; } if (desc-type == QEMU_OPT_STRING) { -fprintf(stderr, %s='%s' , desc-name, value); +printf(%s='%s' , desc-name, value); +} else if ((desc-type == QEMU_OPT_SIZE || +desc-type == QEMU_OPT_NUMBER) opt) { +printf(%s=% PRId64 , desc-name, opt-value.uint); } else { -fprintf(stderr, %s=%s , desc-name, value); +printf(%s=%s , desc-name, value); } } -fprintf(stderr, \n); } static int opts_do_parse(QemuOpts *opts, const char *params, -- 1.8.4.5
Re: [Qemu-devel] [PATCH 4/5] libcacard: replace qemu thread primitives with glib ones
Il 29/04/2014 10:42, Michael Tokarev ha scritto: Also replace single instance pstrcpy() in vcard_emul_nss.c to strncpy(). This reverts commit 2e679780ae86c6ca8. An alternative would be to use g_strlcpy which guarantees nul-termination. Yes, that is better. Actually in this very place it isn't really important, given we always know the exact length of the source and are able to adjust it to fit into the buffer. With g_strlcat() code becomes a bit more ugly... ;) Uh, now I looked at NEXT_TOKEN and g_strlcpy suddenly becomes less palatable. mempcpy would be nice actually, like *mempcpy(dest, src, type_params_length) = 0; but it is not portable and not wrapped by glib. Another good alternative is char *type_str; ... type_str = g_strndup(type_params, type_params_length); type = vcard_emul_type_from_string(type_str); g_free(type_str); Paolo
[Qemu-devel] [PATCH V26 05/32] QemuOpts: change opt-name|str from (const char *) to (char *)
qemu_opt_del() already assumes that all QemuOpt instances contain malloc'd name and value; but it had to cast away const because opts_start_struct() was doing its own thing and using static storage instead. By using the correct type and malloced strings everywhere, the usage of this struct becomes clearer. Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option_int.h | 4 ++-- qapi/opts-visitor.c | 10 +++--- util/qemu-option.c| 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h index 8212fa4..6432c1a 100644 --- a/include/qemu/option_int.h +++ b/include/qemu/option_int.h @@ -30,8 +30,8 @@ #include qemu/error-report.h struct QemuOpt { -const char *name; -const char *str; +char *name; +char *str; const QemuOptDesc *desc; union { diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 5d830a2..7a64f4e 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char *kind, if (ov-opts_root-id != NULL) { ov-fake_id_opt = g_malloc0(sizeof *ov-fake_id_opt); -ov-fake_id_opt-name = id; -ov-fake_id_opt-str = ov-opts_root-id; +ov-fake_id_opt-name = g_strdup(id); +ov-fake_id_opt-str = g_strdup(ov-opts_root-id); opts_visitor_insert(ov-unprocessed_opts, ov-fake_id_opt); } } @@ -177,7 +177,11 @@ opts_end_struct(Visitor *v, Error **errp) } g_hash_table_destroy(ov-unprocessed_opts); ov-unprocessed_opts = NULL; -g_free(ov-fake_id_opt); +if (ov-fake_id_opt) { +g_free(ov-fake_id_opt-name); +g_free(ov-fake_id_opt-str); +g_free(ov-fake_id_opt); +} ov-fake_id_opt = NULL; } diff --git a/util/qemu-option.c b/util/qemu-option.c index 2be6995..69cdf3f 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp) static void qemu_opt_del(QemuOpt *opt) { QTAILQ_REMOVE(opt-opts-head, opt, next); -g_free((/* !const */ char*)opt-name); -g_free((/* !const */ char*)opt-str); +g_free(opt-name); +g_free(opt-str); g_free(opt); } -- 1.8.4.5
[Qemu-devel] [PATCH V26 00/32] replace QEMUOptionParameter with QemuOpts
This patch series is to replace QEMUOptionParameter with QemuOpts, so that only one Qemu Option structure is kept in QEMU code. --- Changes to v25: * split v25 2/31 (add def_value_str to QemuOptDesc) into two patches: 1st patch adds def_value_str, 2nd patch repurpose qemu_opts_print. * update 4/32 qapi command line description. * update 12/32 (change block layer to support both) according to Eric's comments. * small update to gluster.c * rebase to latest code All patches are also available from: https://github.com/chunyanliu/qemu/commits/QemuOpts Chunyan Liu (31): QemuOpts: move find_desc_by_name ahead for later calling QemuOpts: add def_value_str to QemuOptDesc QemuOpts: repurpose qemu_opts_print to replace print_option_parameters qapi: output def_value_str when query command line options QemuOpts: change opt-name|str from (const char *) to (char *) QemuOpts: move qemu_opt_del ahead for later calling QemuOpts: add qemu_opt_get_*_del functions for replace work QemuOpts: add qemu_opts_print_help to replace print_option_help QemuOpts: add conversion between QEMUOptionParameter to QemuOpts QemuOpts: add qemu_opts_append to replace append_option_parameters QemuOpts: check NULL input for qemu_opts_del change block layer to support both QemuOpts and QEMUOptionParamter vvfat.c: handle cross_driver's create_options and create_opts cow.c: replace QEMUOptionParameter with QemuOpts gluster.c: replace QEMUOptionParameter with QemuOpts iscsi.c: replace QEMUOptionParameter with QemuOpts nfs.c: replace QEMUOptionParameter with QemuOpts qcow.c: replace QEMUOptionParameter with QemuOpts qcow2.c: replace QEMUOptionParameter with QemuOpts qed.c: replace QEMUOptionParameter with QemuOpts raw-posix.c: replace QEMUOptionParameter with QemuOpts raw-win32.c: replace QEMUOptionParameter with QemuOpts raw_bsd.c: replace QEMUOptionParameter with QemuOpts rbd.c: replace QEMUOptionParameter with QemuOpts sheepdog.c: replace QEMUOptionParameter with QemuOpts ssh.c: replace QEMUOptionParameter with QemuOpts vdi.c: replace QEMUOptionParameter with QemuOpts vhdx.c: replace QEMUOptionParameter with QemuOpts vmdk.c: replace QEMUOptionParameter with QemuOpts vpc.c: replace QEMUOptionParameter with QemuOpts cleanup QEMUOptionParameter Michael Buesch (1): slirp/smb: Move ncalrpc directory to tmp
[Qemu-devel] [PATCH V26 08/32] QemuOpts: add qemu_opts_print_help to replace print_option_help
print_option_help takes QEMUOptionParameter as parameter, add qemu_opts_print_help to take QemuOptsList as parameter for later replace work. Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h | 1 + util/qemu-option.c| 13 + 2 files changed, 14 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index 6653e43..fbf5dc2 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -166,5 +166,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); void qemu_opts_print(QemuOpts *opts); int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, int abort_on_failure); +void qemu_opts_print_help(QemuOptsList *list); #endif diff --git a/util/qemu-option.c b/util/qemu-option.c index 32e1d50..adb7c3c 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -553,6 +553,19 @@ void print_option_help(QEMUOptionParameter *list) } } +void qemu_opts_print_help(QemuOptsList *list) +{ +QemuOptDesc *desc; + +assert(list); +desc = list-desc; +printf(Supported options:\n); +while (desc desc-name) { +printf(%-16s %s\n, desc-name, + desc-help ? desc-help : No description available); +desc++; +} +} /* -- */ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) -- 1.8.4.5
[Qemu-devel] [PATCH V26 10/32] QemuOpts: add qemu_opts_append to replace append_option_parameters
For later merge .create_opts of drv and proto_drv in qemu-img commands. Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Leandro Dorileo l...@dorileo.org Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h | 5 util/qemu-option.c| 65 +++ 2 files changed, 70 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index e98e8ef..44d9961 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -176,5 +176,10 @@ void qemu_opts_print_help(QemuOptsList *list); void qemu_opts_free(QemuOptsList *list); QEMUOptionParameter *opts_to_params(QemuOpts *opts); QemuOptsList *params_to_opts(QEMUOptionParameter *list); +/* FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts. + */ +QemuOptsList *qemu_opts_append(QemuOptsList *dst, + QemuOptsList *list, + QEMUOptionParameter *param); #endif diff --git a/util/qemu-option.c b/util/qemu-option.c index 93ffcd5..4de99b3 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1498,3 +1498,68 @@ void qemu_opts_free(QemuOptsList *list) g_free(list); } + +/* Realloc dst option list and append options either from an option list (list) + * or a QEMUOptionParameter (param) to it. dst could be NULL or a malloced list. + * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts. + */ +QemuOptsList *qemu_opts_append(QemuOptsList *dst, + QemuOptsList *list, + QEMUOptionParameter *param) +{ +size_t num_opts, num_dst_opts; +QemuOptsList *tmp_list = NULL; +QemuOptDesc *desc; +bool need_init = false; + +assert(!(list param)); +if (!param !list) { +return dst; +} + +if (param) { +list = tmp_list = params_to_opts(param); +} + +/* If dst is NULL, after realloc, some area of dst should be initialized + * before adding options to it. + */ +if (!dst) { +need_init = true; +} + +num_opts = count_opts_list(dst); +num_dst_opts = num_opts; +num_opts += count_opts_list(list); +dst = g_realloc(dst, sizeof(QemuOptsList) + +(num_opts + 1) * sizeof(QemuOptDesc)); +if (need_init) { +dst-name = NULL; +dst-implied_opt_name = NULL; +QTAILQ_INIT(dst-head); +dst-allocated = true; +} +dst-desc[num_dst_opts].name = NULL; + +/* (const char *) members of result dst are malloced, need free. */ +assert(dst-allocated); +/* append list-desc to dst-desc */ +if (list) { +desc = list-desc; +while (desc desc-name) { +if (find_desc_by_name(dst-desc, desc-name) == NULL) { +dst-desc[num_dst_opts].name = g_strdup(desc-name); +dst-desc[num_dst_opts].type = desc-type; +dst-desc[num_dst_opts].help = g_strdup(desc-help); +dst-desc[num_dst_opts].def_value_str = + g_strdup(desc-def_value_str); +num_dst_opts++; +dst-desc[num_dst_opts].name = NULL; +} +desc++; +} +} + +g_free(tmp_list); +return dst; +} -- 1.8.4.5
[Qemu-devel] [PATCH V26 04/32] qapi: output def_value_str when query command line options
Change qapi interfaces to output the newly added def_value_str when querying command line options. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- Changes to V25: * update @default description in .json file qapi-schema.json | 5 - qmp-commands.hx| 2 ++ util/qemu-config.c | 4 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/qapi-schema.json b/qapi-schema.json index 0b00427..880829d 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4088,12 +4088,15 @@ # # @help: #optional human readable text string, not suitable for parsing. # +# @default: #optional default value string (since 2.1) +# # Since 1.5 ## { 'type': 'CommandLineParameterInfo', 'data': { 'name': 'str', 'type': 'CommandLineParameterType', -'*help': 'str' } } +'*help': 'str', +'*default': 'str' } } ## # @CommandLineOptionInfo: diff --git a/qmp-commands.hx b/qmp-commands.hx index ed3ab92..1271332 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2895,6 +2895,8 @@ Each array entry contains the following: or 'size') - help: human readable description of the parameter (json-string, optional) +- default: default value string for the parameter + (json-string, optional) Example: diff --git a/util/qemu-config.c b/util/qemu-config.c index f4e4f38..ba375c0 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -82,6 +82,10 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) info-has_help = true; info-help = g_strdup(desc[i].help); } +if (desc[i].def_value_str) { +info-has_q_default = true; +info-q_default = g_strdup(desc[i].def_value_str); +} entry = g_malloc0(sizeof(*entry)); entry-value = info; -- 1.8.4.5
[Qemu-devel] [PATCH V26 07/32] QemuOpts: add qemu_opt_get_*_del functions for replace work
Add qemu_opt_get_del, qemu_opt_get_bool_del, qemu_opt_get_number_del and qemu_opt_get_size_del to replace the same handling of QEMUOptionParameter (get and delete). Several drivers are coded to parse a known subset of options, then remove them from the list before handing all remaining options to a second driver for further option processing. get_*_del makes it easier to retrieve a known option (or its default) and remove it from the list all in one action. Share common helper function: For qemu_opt_get_bool/size/number, they and their get_*_del counterpart could share most of the code except whether or not deleting the opt from option list, so generate common helper functions. For qemu_opt_get and qemu_opt_get_del, keep code duplication, since 1. qemu_opt_get_del returns malloc'd memory while qemu_opt_get returns in-place memory 2. qemu_opt_get_del returns (char *), qemu_opt_get returns (const char *), and could not change to (char *), since in one case, it will return desc-def_value_str, which is (const char *). Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h | 6 +++ util/qemu-option.c| 116 -- 2 files changed, 109 insertions(+), 13 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index c3b0a91..6653e43 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -111,6 +111,7 @@ struct QemuOptsList { }; const char *qemu_opt_get(QemuOpts *opts, const char *name); +char *qemu_opt_get_del(QemuOpts *opts, const char *name); /** * qemu_opt_has_help_opt: * @opts: options to search for a help request @@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts); bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval); uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval); +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name, + uint64_t defval); +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, + uint64_t defval); int qemu_opt_unset(QemuOpts *opts, const char *name); int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, diff --git a/util/qemu-option.c b/util/qemu-option.c index 4d2d4d1..32e1d50 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -575,6 +575,19 @@ static void qemu_opt_del(QemuOpt *opt) g_free(opt); } +/* qemu_opt_set allows many settings for the same option. + * This function deletes all settings for an option. + */ +static void qemu_opt_del_all(QemuOpts *opts, const char *name) +{ +QemuOpt *opt, *next_opt; + +QTAILQ_FOREACH_SAFE(opt, opts-head, next, next_opt) { +if (!strcmp(opt-name, name)) +qemu_opt_del(opt); +} +} + const char *qemu_opt_get(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); @@ -588,6 +601,34 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name) return opt ? opt-str : NULL; } +/* Get a known option (or its default) and remove it from the list + * all in one action. Return a malloced string of the option value. + * Result must be freed by caller with g_free(). + */ +char *qemu_opt_get_del(QemuOpts *opts, const char *name) +{ +QemuOpt *opt; +const QemuOptDesc *desc; +char *str = NULL; + +if (opts == NULL) { +return NULL; +} + +opt = qemu_opt_find(opts, name); +if (!opt) { +desc = find_desc_by_name(opts-list-desc, name); +if (desc desc-def_value_str) { +str = g_strdup(desc-def_value_str); +} +return str; +} +str = opt-str; +opt-str = NULL; +qemu_opt_del_all(opts, name); +return str; +} + bool qemu_opt_has_help_opt(QemuOpts *opts) { QemuOpt *opt; @@ -600,50 +641,99 @@ bool qemu_opt_has_help_opt(QemuOpts *opts) return false; } -bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) +static bool qemu_opt_get_bool_helper(QemuOpts *opts, const char *name, + bool defval, bool del) { QemuOpt *opt = qemu_opt_find(opts, name); +bool ret = defval; if (opt == NULL) { const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name); if (desc desc-def_value_str) { -parse_option_bool(name, desc-def_value_str, defval, error_abort); +parse_option_bool(name, desc-def_value_str, ret, error_abort); } -return defval; +return ret; } assert(opt-desc opt-desc-type == QEMU_OPT_BOOL); -return opt-value.boolean; +ret = opt-value.boolean; +if
[Qemu-devel] [PATCH V26 02/32] QemuOpts: add def_value_str to QemuOptDesc
Add def_value_str (default value) to QemuOptDesc, to replace function of the default value in QEMUOptionParameter. Improve qemu_opts_get_* functions: if find opt, return opt-str; otherwise, if desc-def_value_str is set, return desc-def_value_str; otherwise, return input defval. Improve qemu_opts_print: if option is set, print opt-str; otherwise, if desc-def_value_str is set, also print it. It will replace print_option_parameters. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- Changes to V25: * split v25 patch into two: this one and next one. * this patch is the same as v22 which is reviewed-by Eric. include/qemu/option.h | 3 ++- util/qemu-option.c| 56 ++- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index 8c0ac34..c3b0a91 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -99,6 +99,7 @@ typedef struct QemuOptDesc { const char *name; enum QemuOptType type; const char *help; +const char *def_value_str; } QemuOptDesc; struct QemuOptsList { @@ -156,7 +157,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict); void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp); typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); -int qemu_opts_print(QemuOpts *opts, void *dummy); +void qemu_opts_print(QemuOpts *opts); int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, int abort_on_failure); diff --git a/util/qemu-option.c b/util/qemu-option.c index 808aef4..5346c90 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -570,6 +570,13 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) const char *qemu_opt_get(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); + +if (!opt) { +const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name); +if (desc desc-def_value_str) { +return desc-def_value_str; +} +} return opt ? opt-str : NULL; } @@ -589,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) { QemuOpt *opt = qemu_opt_find(opts, name); -if (opt == NULL) +if (opt == NULL) { +const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name); +if (desc desc-def_value_str) { +parse_option_bool(name, desc-def_value_str, defval, error_abort); +} return defval; +} assert(opt-desc opt-desc-type == QEMU_OPT_BOOL); return opt-value.boolean; } @@ -599,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval) { QemuOpt *opt = qemu_opt_find(opts, name); -if (opt == NULL) +if (opt == NULL) { +const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name); +if (desc desc-def_value_str) { +parse_option_number(name, desc-def_value_str, defval, +error_abort); +} return defval; +} assert(opt-desc opt-desc-type == QEMU_OPT_NUMBER); return opt-value.uint; } @@ -609,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval) { QemuOpt *opt = qemu_opt_find(opts, name); -if (opt == NULL) +if (opt == NULL) { +const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name); +if (desc desc-def_value_str) { +parse_option_size(name, desc-def_value_str, defval, error_abort); +} return defval; +} assert(opt-desc opt-desc-type == QEMU_OPT_SIZE); return opt-value.uint; } @@ -895,17 +918,32 @@ void qemu_opts_del(QemuOpts *opts) g_free(opts); } -int qemu_opts_print(QemuOpts *opts, void *dummy) +void qemu_opts_print(QemuOpts *opts) { QemuOpt *opt; +QemuOptDesc *desc = opts-list-desc; -fprintf(stderr, %s: %s:, opts-list-name, -opts-id ? opts-id : noid); -QTAILQ_FOREACH(opt, opts-head, next) { -fprintf(stderr, %s=\%s\, opt-name, opt-str); +if (desc[0].name == NULL) { +QTAILQ_FOREACH(opt, opts-head, next) { +fprintf(stderr, %s=\%s\ , opt-name, opt-str); +} +return; +} +for (; desc desc-name; desc++) { +const char *value; +QemuOpt *opt = qemu_opt_find(opts, desc-name); + +value = opt ? opt-str : desc-def_value_str; +if (!value) { +continue; +} +if (desc-type == QEMU_OPT_STRING) { +fprintf(stderr, %s='%s' , desc-name, value); +} else { +fprintf(stderr, %s=%s , desc-name, value); +} } fprintf(stderr, \n); -return 0; } static int opts_do_parse(QemuOpts *opts, const char *params, -- 1.8.4.5
[Qemu-devel] [PATCH V26 09/32] QemuOpts: add conversion between QEMUOptionParameter to QemuOpts
Add two temp conversion functions between QEMUOptionParameter to QemuOpts, so that next patch can use it. It will simplify later patch for easier review. And will be finally removed after all backend drivers switch to QemuOpts. Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h | 9 +++ util/qemu-option.c| 153 ++ 2 files changed, 162 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index fbf5dc2..e98e8ef 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -103,6 +103,12 @@ typedef struct QemuOptDesc { } QemuOptDesc; struct QemuOptsList { +/* FIXME: Temp used for QEMUOptionParamter-QemuOpts conversion to + * indicate the need to free memory. Will remove after all drivers + * switch to QemuOpts. + */ +bool allocated; + const char *name; const char *implied_opt_name; bool merge_lists; /* Merge multiple uses of option into a single list? */ @@ -167,5 +173,8 @@ void qemu_opts_print(QemuOpts *opts); int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, int abort_on_failure); void qemu_opts_print_help(QemuOptsList *list); +void qemu_opts_free(QemuOptsList *list); +QEMUOptionParameter *opts_to_params(QemuOpts *opts); +QemuOptsList *params_to_opts(QEMUOptionParameter *list); #endif diff --git a/util/qemu-option.c b/util/qemu-option.c index adb7c3c..93ffcd5 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1345,3 +1345,156 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, loc_pop(loc); return rc; } + +static size_t count_opts_list(QemuOptsList *list) +{ +QemuOptDesc *desc = NULL; +size_t num_opts = 0; + +if (!list) { +return 0; +} + +desc = list-desc; +while (desc desc-name) { +num_opts++; +desc++; +} + +return num_opts; +} + +/* Convert QEMUOptionParameter to QemuOpts + * FIXME: this function will be removed after all drivers + * switch to QemuOpts + */ +QemuOptsList *params_to_opts(QEMUOptionParameter *list) +{ +QemuOptsList *opts = NULL; +size_t num_opts, i = 0; + +if (!list) { +return NULL; +} + +num_opts = count_option_parameters(list); +opts = g_malloc0(sizeof(QemuOptsList) + + (num_opts + 1) * sizeof(QemuOptDesc)); +QTAILQ_INIT(opts-head); +/* (const char *) members will point to malloced space and need to free */ +opts-allocated = true; + +while (list list-name) { +opts-desc[i].name = g_strdup(list-name); +opts-desc[i].help = g_strdup(list-help); +switch (list-type) { +case OPT_FLAG: +opts-desc[i].type = QEMU_OPT_BOOL; +opts-desc[i].def_value_str = +g_strdup(list-value.n ? on : off); +break; + +case OPT_NUMBER: +opts-desc[i].type = QEMU_OPT_NUMBER; +if (list-value.n) { +opts-desc[i].def_value_str = +g_strdup_printf(% PRIu64, list-value.n); +} +break; + +case OPT_SIZE: +opts-desc[i].type = QEMU_OPT_SIZE; +if (list-value.n) { +opts-desc[i].def_value_str = +g_strdup_printf(% PRIu64, list-value.n); +} +break; + +case OPT_STRING: +opts-desc[i].type = QEMU_OPT_STRING; +opts-desc[i].def_value_str = g_strdup(list-value.s); +break; +} + +i++; +list++; +} + +return opts; +} + +/* convert QemuOpts to QEMUOptionParameter + * Note: result QEMUOptionParameter has shorter lifetime than + * input QemuOpts. + * FIXME: this function will be removed after all drivers + * switch to QemuOpts + */ +QEMUOptionParameter *opts_to_params(QemuOpts *opts) +{ +QEMUOptionParameter *dest = NULL; +QemuOptDesc *desc; +size_t num_opts, i = 0; +const char *tmp; + +if (!opts || !opts-list || !opts-list-desc) { +return NULL; +} +assert(!opts_accepts_any(opts)); + +num_opts = count_opts_list(opts-list); +dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter)); + +desc = opts-list-desc; +while (desc desc-name) { +dest[i].name = desc-name; +dest[i].help = desc-help; +dest[i].assigned = qemu_opt_find(opts, desc-name) ? true : false; +switch (desc-type) { +case QEMU_OPT_STRING: +dest[i].type = OPT_STRING; +tmp = qemu_opt_get(opts, desc-name); +dest[i].value.s = g_strdup(tmp); +break; + +case QEMU_OPT_BOOL: +dest[i].type = OPT_FLAG; +dest[i].value.n = qemu_opt_get_bool(opts, desc-name, 0) ? 1 : 0; +break; + +case QEMU_OPT_NUMBER: +
[Qemu-devel] [PATCH V26 11/32] QemuOpts: check NULL input for qemu_opts_del
To simplify later using of qemu_opts_del, accept NULL input. Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- util/qemu-option.c | 4 1 file changed, 4 insertions(+) diff --git a/util/qemu-option.c b/util/qemu-option.c index 4de99b3..2667e16 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1010,6 +1010,10 @@ void qemu_opts_del(QemuOpts *opts) { QemuOpt *opt; +if (opts == NULL) { +return; +} + for (;;) { opt = QTAILQ_FIRST(opts-head); if (opt == NULL) -- 1.8.4.5
[Qemu-devel] [PATCH V26 15/32] gluster.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- Changes to V25: * fix create_opts, OPT_STRING - QEMU_OPT_STRING block/gluster.c | 81 ++--- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 8836085..c72ca77 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -471,13 +471,14 @@ static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset, #endif static int qemu_gluster_create(const char *filename, -QEMUOptionParameter *options, Error **errp) + QemuOpts *opts, Error **errp) { struct glfs *glfs; struct glfs_fd *fd; int ret = 0; int prealloc = 0; int64_t total_size = 0; +char *tmp = NULL; GlusterConf *gconf = g_malloc0(sizeof(GlusterConf)); glfs = qemu_gluster_init(gconf, filename, errp); @@ -486,24 +487,21 @@ static int qemu_gluster_create(const char *filename, goto out; } -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n / BDRV_SECTOR_SIZE; -} else if (!strcmp(options-name, BLOCK_OPT_PREALLOC)) { -if (!options-value.s || !strcmp(options-value.s, off)) { -prealloc = 0; -} else if (!strcmp(options-value.s, full) -gluster_supports_zerofill()) { -prealloc = 1; -} else { -error_setg(errp, Invalid preallocation mode: '%s' - or GlusterFS doesn't support zerofill API, - options-value.s); -ret = -EINVAL; -goto out; -} -} -options++; +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; + +tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); +if (!tmp || !strcmp(tmp, off)) { +prealloc = 0; +} else if (!strcmp(tmp, full) + gluster_supports_zerofill()) { +prealloc = 1; +} else { +error_setg(errp, Invalid preallocation mode: '%s' + or GlusterFS doesn't support zerofill API, +tmp); +ret = -EINVAL; +goto out; } fd = glfs_creat(glfs, gconf-image, @@ -525,6 +523,7 @@ static int qemu_gluster_create(const char *filename, } } out: +g_free(tmp); qemu_gluster_gconf_free(gconf); if (glfs) { glfs_fini(glfs); @@ -688,18 +687,22 @@ static int qemu_gluster_has_zero_init(BlockDriverState *bs) return 0; } -static QEMUOptionParameter qemu_gluster_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_PREALLOC, -.type = OPT_STRING, -.help = Preallocation mode (allowed values: off, full) -}, -{ NULL } +static QemuOptsList qemu_gluster_create_opts = { +.name = qemu-gluster-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_PREALLOC, +.type = QEMU_OPT_STRING, +.help = Preallocation mode (allowed values: off, full) +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_gluster = { @@ -712,7 +715,7 @@ static BlockDriver bdrv_gluster = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort= qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, -.bdrv_create = qemu_gluster_create, +.bdrv_create2 = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate= qemu_gluster_truncate, @@ -726,7 +729,7 @@ static BlockDriver bdrv_gluster = { #ifdef CONFIG_GLUSTERFS_ZEROFILL .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes, #endif -.create_options = qemu_gluster_create_options, +.create_opts = qemu_gluster_create_opts, }; static BlockDriver bdrv_gluster_tcp = { @@ -739,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort= qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, -.bdrv_create = qemu_gluster_create, +.bdrv_create2 = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate=
[Qemu-devel] [PATCH V26 12/32] change block layer to support both QemuOpts and QEMUOptionParamter
Change block layer to support both QemuOpts and QEMUOptionParameter. After this patch, it will change backend drivers one by one. At the end, QEMUOptionParameter will be removed and only QemuOpts is kept. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- Changes to V25: * fix Eric's comments: * update bdrv_create_co_entry and bdrv_amend_options code, to let it more readable. * add assertion in bdrv_register. * improve comments to create_opts in header file. block.c | 158 -- block/cow.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/qed.c | 2 +- block/raw_bsd.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 4 +- block/vvfat.c | 2 +- include/block/block.h | 7 +- include/block/block_int.h | 13 +++- qemu-img.c| 94 +-- 12 files changed, 180 insertions(+), 110 deletions(-) diff --git a/block.c b/block.c index 4745712..124f045 100644 --- a/block.c +++ b/block.c @@ -328,6 +328,13 @@ void bdrv_register(BlockDriver *bdrv) } } +if (bdrv-bdrv_create) { +assert(!bdrv-bdrv_create2 !bdrv-create_opts); +assert(!bdrv-bdrv_amend_options2); +} else if (bdrv-bdrv_create2) { +assert(!bdrv-bdrv_create !bdrv-create_options); +assert(!bdrv-bdrv_amend_options); +} QLIST_INSERT_HEAD(bdrv_drivers, bdrv, list); } @@ -419,6 +426,7 @@ typedef struct CreateCo { BlockDriver *drv; char *filename; QEMUOptionParameter *options; +QemuOpts *opts; int ret; Error *err; } CreateCo; @@ -430,8 +438,28 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque) CreateCo *cco = opaque; assert(cco-drv); +assert(!(cco-options cco-opts)); -ret = cco-drv-bdrv_create(cco-filename, cco-options, local_err); +if (cco-drv-bdrv_create2) { +QemuOptsList *opts_list = NULL; +if (cco-options) { +opts_list = params_to_opts(cco-options); +cco-opts = qemu_opts_create(opts_list, NULL, 0, error_abort); +} +ret = cco-drv-bdrv_create2(cco-filename, cco-opts, local_err); +if (cco-options) { +qemu_opts_del(cco-opts); +qemu_opts_free(opts_list); +} +} else { +if (cco-opts) { +cco-options = opts_to_params(cco-opts); +} +ret = cco-drv-bdrv_create(cco-filename, cco-options, local_err); +if (cco-opts) { +free_option_parameters(cco-options); +} +} if (local_err) { error_propagate(cco-err, local_err); } @@ -439,7 +467,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque) } int bdrv_create(BlockDriver *drv, const char* filename, -QEMUOptionParameter *options, Error **errp) +QEMUOptionParameter *options, +QemuOpts *opts, Error **errp) { int ret; @@ -448,11 +477,12 @@ int bdrv_create(BlockDriver *drv, const char* filename, .drv = drv, .filename = g_strdup(filename), .options = options, +.opts = opts, .ret = NOT_DONE, .err = NULL, }; -if (!drv-bdrv_create) { +if (!drv-bdrv_create !drv-bdrv_create2) { error_setg(errp, Driver '%s' does not support image creation, drv-format_name); ret = -ENOTSUP; goto out; @@ -484,7 +514,7 @@ out: } int bdrv_create_file(const char* filename, QEMUOptionParameter *options, - Error **errp) + QemuOpts *opts, Error **errp) { BlockDriver *drv; Error *local_err = NULL; @@ -496,7 +526,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options, return -ENOENT; } -ret = bdrv_create(drv, filename, options, local_err); +ret = bdrv_create(drv, filename, options, opts, local_err); if (local_err) { error_propagate(errp, local_err); } @@ -1184,7 +1214,8 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp) char *tmp_filename = g_malloc0(PATH_MAX + 1); int64_t total_size; BlockDriver *bdrv_qcow2; -QEMUOptionParameter *create_options; +QemuOptsList *create_opts = NULL; +QemuOpts *opts = NULL; QDict *snapshot_options; BlockDriverState *bs_snapshot; Error *local_err; @@ -1209,13 +1240,20 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp) } bdrv_qcow2 = bdrv_find_format(qcow2); -create_options = parse_option_parameters(, bdrv_qcow2-create_options, - NULL); - -set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size); -ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, local_err); -free_option_parameters(create_options);
[Qemu-devel] [PATCH V26 06/32] QemuOpts: move qemu_opt_del ahead for later calling
In later patch, qemu_opt_get_del functions will be added, they will first get the option value, then call qemu_opt_del to remove the option from opt list. To prepare for that purpose, move qemu_opt_del ahead first. Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- util/qemu-option.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 69cdf3f..4d2d4d1 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -567,6 +567,14 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) return NULL; } +static void qemu_opt_del(QemuOpt *opt) +{ +QTAILQ_REMOVE(opt-opts-head, opt, next); +g_free(opt-name); +g_free(opt-str); +g_free(opt); +} + const char *qemu_opt_get(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); @@ -661,14 +669,6 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp) } } -static void qemu_opt_del(QemuOpt *opt) -{ -QTAILQ_REMOVE(opt-opts-head, opt, next); -g_free(opt-name); -g_free(opt-str); -g_free(opt); -} - static bool opts_accepts_any(const QemuOpts *opts) { return opts-list-desc[0].name == NULL; -- 1.8.4.5
[Qemu-devel] [PATCH V26 24/32] rbd.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/rbd.c | 63 + 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index dbc79f4..f878877 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -282,8 +282,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf) return ret; } -static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) { int64_t bytes = 0; int64_t objsize; @@ -306,24 +305,18 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options, } /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -bytes = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_CLUSTER_SIZE)) { -if (options-value.n) { -objsize = options-value.n; -if ((objsize - 1) objsize) {/* not a power of 2? */ -error_report(obj size needs to be power of 2); -return -EINVAL; -} -if (objsize 4096) { -error_report(obj size too small); -return -EINVAL; -} -obj_order = ffs(objsize) - 1; -} +bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0); +if (objsize) { +if ((objsize - 1) objsize) {/* not a power of 2? */ +error_report(obj size needs to be power of 2); +return -EINVAL; +} +if (objsize 4096) { +error_report(obj size too small); +return -EINVAL; } -options++; +obj_order = ffs(objsize) - 1; } clientname = qemu_rbd_parse_clientname(conf, clientname_buf); @@ -900,18 +893,22 @@ static BlockDriverAIOCB* qemu_rbd_aio_discard(BlockDriverState *bs, } #endif -static QEMUOptionParameter qemu_rbd_create_options[] = { -{ - .name = BLOCK_OPT_SIZE, - .type = OPT_SIZE, - .help = Virtual disk size -}, -{ - .name = BLOCK_OPT_CLUSTER_SIZE, - .type = OPT_SIZE, - .help = RBD object size -}, -{NULL} +static QemuOptsList qemu_rbd_create_opts = { +.name = rbd-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_CLUSTER_SIZE, +.type = QEMU_OPT_SIZE, +.help = RBD object size +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_rbd = { @@ -920,10 +917,10 @@ static BlockDriver bdrv_rbd = { .bdrv_needs_filename = true, .bdrv_file_open = qemu_rbd_open, .bdrv_close = qemu_rbd_close, -.bdrv_create= qemu_rbd_create, +.bdrv_create2 = qemu_rbd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_get_info = qemu_rbd_getinfo, -.create_options = qemu_rbd_create_options, +.create_opts= qemu_rbd_create_opts, .bdrv_getlength = qemu_rbd_getlength, .bdrv_truncate = qemu_rbd_truncate, .protocol_name = rbd, -- 1.8.4.5
[Qemu-devel] [PATCH V26 18/32] qcow.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/qcow.c | 72 ++-- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 9411aef..b4ce133 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -662,35 +662,29 @@ static void qcow_close(BlockDriverState *bs) error_free(s-migration_blocker); } -static int qcow_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) { int header_size, backing_filename_len, l1_size, shift, i; QCowHeader header; uint8_t *tmp; int64_t total_size = 0; -const char *backing_file = NULL; +char *backing_file = NULL; int flags = 0; Error *local_err = NULL; int ret; BlockDriverState *qcow_bs; /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n / 512; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -backing_file = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_ENCRYPT)) { -flags |= options-value.n ? BLOCK_FLAG_ENCRYPT : 0; -} -options++; +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512; +backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { +flags |= BLOCK_FLAG_ENCRYPT; } -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto cleanup; } qcow_bs = NULL; @@ -698,7 +692,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options, BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto cleanup; } ret = bdrv_truncate(qcow_bs, 0); @@ -769,6 +763,8 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options, ret = 0; exit: bdrv_unref(qcow_bs); +cleanup: +g_free(backing_file); return ret; } @@ -881,24 +877,28 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } - -static QEMUOptionParameter qcow_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, -{ -.name = BLOCK_OPT_ENCRYPT, -.type = OPT_FLAG, -.help = Encrypt the image -}, -{ NULL } +static QemuOptsList qcow_create_opts = { +.name = qcow-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(qcow_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_BACKING_FILE, +.type = QEMU_OPT_STRING, +.help = File name of a base image +}, +{ +.name = BLOCK_OPT_ENCRYPT, +.type = QEMU_OPT_BOOL, +.help = Encrypt the image, +.def_value_str = off +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_qcow = { @@ -907,8 +907,8 @@ static BlockDriver bdrv_qcow = { .bdrv_probe= qcow_probe, .bdrv_open = qcow_open, .bdrv_close= qcow_close, -.bdrv_reopen_prepare = qcow_reopen_prepare, -.bdrv_create = qcow_create, +.bdrv_reopen_prepare= qcow_reopen_prepare, +.bdrv_create2 = qcow_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_readv = qcow_co_readv, @@ -920,7 +920,7 @@ static BlockDriver bdrv_qcow = { .bdrv_write_compressed = qcow_write_compressed, .bdrv_get_info = qcow_get_info, -.create_options = qcow_create_options, +.create_opts= qcow_create_opts, }; static void bdrv_qcow_init(void) -- 1.8.4.5
[Qemu-devel] [PATCH V26 14/32] cow.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/cow.c | 54 ++ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/block/cow.c b/block/cow.c index 26cf4a5..fb2cd68 100644 --- a/block/cow.c +++ b/block/cow.c @@ -324,31 +324,24 @@ static void cow_close(BlockDriverState *bs) { } -static int cow_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int cow_create(const char *filename, QemuOpts *opts, Error **errp) { struct cow_header_v2 cow_header; struct stat st; int64_t image_sectors = 0; -const char *image_filename = NULL; +char *image_filename = NULL; Error *local_err = NULL; int ret; BlockDriverState *cow_bs; /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -image_sectors = options-value.n / 512; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -image_filename = options-value.s; -} -options++; -} +image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512; +image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto exit; } cow_bs = NULL; @@ -356,7 +349,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options, BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto exit; } memset(cow_header, 0, sizeof(cow_header)); @@ -389,22 +382,27 @@ static int cow_create(const char *filename, QEMUOptionParameter *options, } exit: +g_free(image_filename); bdrv_unref(cow_bs); return ret; } -static QEMUOptionParameter cow_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, -{ NULL } +static QemuOptsList cow_create_opts = { +.name = cow-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(cow_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_BACKING_FILE, +.type = QEMU_OPT_STRING, +.help = File name of a base image +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_cow = { @@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = { .bdrv_probe = cow_probe, .bdrv_open = cow_open, .bdrv_close = cow_close, -.bdrv_create= cow_create, +.bdrv_create2 = cow_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_read = cow_co_read, .bdrv_write = cow_co_write, .bdrv_co_get_block_status = cow_co_get_block_status, -.create_options = cow_create_options, +.create_opts= cow_create_opts, }; static void bdrv_cow_init(void) -- 1.8.4.5
[Qemu-devel] [PATCH V26 20/32] qed.c: replace QEMUOptionParameter with QemuOpts
One extra change is to define QED_DEFAULT_CLUSTER_SIZE = 65536 instead of 64 * 1024; because: according to existing create_options, cluster size has default value = QED_DEFAULT_CLUSTER_SIZE, after switching to create_opts, this has to be stringized and set to .def_value_str. That is, .def_value_str = stringify(QED_DEFAULT_CLUSTER_SIZE), so the QED_DEFAULT_CLUSTER_SIZE could not be a expression. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/qed.c | 114 block/qed.h | 3 +- 2 files changed, 61 insertions(+), 56 deletions(-) diff --git a/block/qed.c b/block/qed.c index 2982640..f7380e1 100644 --- a/block/qed.c +++ b/block/qed.c @@ -621,55 +621,53 @@ out: return ret; } -static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int bdrv_qed_create(const char *filename, QemuOpts *opts, Error **errp) { uint64_t image_size = 0; uint32_t cluster_size = QED_DEFAULT_CLUSTER_SIZE; uint32_t table_size = QED_DEFAULT_TABLE_SIZE; -const char *backing_file = NULL; -const char *backing_fmt = NULL; - -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -image_size = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -backing_file = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FMT)) { -backing_fmt = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_CLUSTER_SIZE)) { -if (options-value.n) { -cluster_size = options-value.n; -} -} else if (!strcmp(options-name, BLOCK_OPT_TABLE_SIZE)) { -if (options-value.n) { -table_size = options-value.n; -} -} -options++; -} +char *backing_file = NULL; +char *backing_fmt = NULL; +int ret; + +image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); +backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT); +cluster_size = qemu_opt_get_size_del(opts, + BLOCK_OPT_CLUSTER_SIZE, + QED_DEFAULT_CLUSTER_SIZE); +table_size = qemu_opt_get_size_del(opts, BLOCK_OPT_TABLE_SIZE, + QED_DEFAULT_TABLE_SIZE); if (!qed_is_cluster_size_valid(cluster_size)) { error_setg(errp, QED cluster size must be within range [%u, %u] and power of 2, QED_MIN_CLUSTER_SIZE, QED_MAX_CLUSTER_SIZE); -return -EINVAL; +ret = -EINVAL; +goto finish; } if (!qed_is_table_size_valid(table_size)) { error_setg(errp, QED table size must be within range [%u, %u] and power of 2, QED_MIN_TABLE_SIZE, QED_MAX_TABLE_SIZE); -return -EINVAL; +ret = -EINVAL; +goto finish; } if (!qed_is_image_size_valid(image_size, cluster_size, table_size)) { error_setg(errp, QED image size must be a non-zero multiple of cluster size and less than % PRIu64 bytes, qed_max_image_size(cluster_size, table_size)); -return -EINVAL; +ret = -EINVAL; +goto finish; } -return qed_create(filename, cluster_size, image_size, table_size, - backing_file, backing_fmt, errp); +ret = qed_create(filename, cluster_size, image_size, table_size, + backing_file, backing_fmt, errp); + +finish: +g_free(backing_file); +g_free(backing_fmt); +return ret; } typedef struct { @@ -1595,43 +1593,51 @@ static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result, return qed_check(s, result, !!fix); } -static QEMUOptionParameter qed_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size (in bytes) -}, { -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, { -.name = BLOCK_OPT_BACKING_FMT, -.type = OPT_STRING, -.help = Image format of the base image -}, { -.name = BLOCK_OPT_CLUSTER_SIZE, -.type = OPT_SIZE, -.help = Cluster size (in bytes), -.value = { .n = QED_DEFAULT_CLUSTER_SIZE }, -}, { -.name = BLOCK_OPT_TABLE_SIZE, -.type = OPT_SIZE, -.help = L1/L2 table size (in clusters) -}, -{ /* end of list */ } +static QemuOptsList qed_create_opts = { +.name = qed-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(qed_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +
[Qemu-devel] [PATCH V26 16/32] iscsi.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/iscsi.c | 34 -- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index a30202b..e4a127b 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1391,8 +1391,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset) return 0; } -static int iscsi_create(const char *filename, QEMUOptionParameter *options, -Error **errp) +static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp) { int ret = 0; int64_t total_size = 0; @@ -1403,13 +1402,8 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options, bs = bdrv_new(, error_abort); /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, size)) { -total_size = options-value.n / BDRV_SECTOR_SIZE; -} -options++; -} - +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; bs-opaque = g_malloc0(sizeof(struct IscsiLun)); iscsilun = bs-opaque; @@ -1460,13 +1454,17 @@ static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } -static QEMUOptionParameter iscsi_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ NULL } +static QemuOptsList iscsi_create_opts = { +.name = iscsi-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_iscsi = { @@ -1477,8 +1475,8 @@ static BlockDriver bdrv_iscsi = { .bdrv_needs_filename = true, .bdrv_file_open = iscsi_open, .bdrv_close = iscsi_close, -.bdrv_create = iscsi_create, -.create_options = iscsi_create_options, +.bdrv_create2= iscsi_create, +.create_opts = iscsi_create_opts, .bdrv_reopen_prepare = iscsi_reopen_prepare, .bdrv_getlength = iscsi_getlength, -- 1.8.4.5
[Qemu-devel] [PATCH V26 21/32] raw-posix.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/raw-posix.c | 59 +-- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 1688e16..e72f449 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1234,8 +1234,7 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs) return (int64_t)st.st_blocks * 512; } -static int raw_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int raw_create(const char *filename, QemuOpts *opts, Error **errp) { int fd; int result = 0; @@ -1244,12 +1243,8 @@ static int raw_create(const char *filename, QEMUOptionParameter *options, strstart(filename, file:, filename); /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n / BDRV_SECTOR_SIZE; -} -options++; -} +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); @@ -1410,13 +1405,17 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } -static QEMUOptionParameter raw_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ NULL } +static QemuOptsList raw_create_opts = { +.name = raw-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_file = { @@ -1431,7 +1430,7 @@ static BlockDriver bdrv_file = { .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, .bdrv_close = raw_close, -.bdrv_create = raw_create, +.bdrv_create2 = raw_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = raw_co_get_block_status, .bdrv_co_write_zeroes = raw_co_write_zeroes, @@ -1448,7 +1447,7 @@ static BlockDriver bdrv_file = { .bdrv_get_allocated_file_size = raw_get_allocated_file_size, -.create_options = raw_create_options, +.create_opts = raw_create_opts, }; /***/ @@ -1769,7 +1768,7 @@ static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs, return -ENOTSUP; } -static int hdev_create(const char *filename, QEMUOptionParameter *options, +static int hdev_create(const char *filename, QemuOpts *opts, Error **errp) { int fd; @@ -1790,12 +1789,8 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options, (void)has_prefix; /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, size)) { -total_size = options-value.n / BDRV_SECTOR_SIZE; -} -options++; -} +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; fd = qemu_open(filename, O_WRONLY | O_BINARY); if (fd 0) { @@ -1832,8 +1827,8 @@ static BlockDriver bdrv_host_device = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, -.bdrv_create= hdev_create, -.create_options = raw_create_options, +.bdrv_create2= hdev_create, +.create_opts = raw_create_opts, .bdrv_co_write_zeroes = hdev_co_write_zeroes, .bdrv_aio_readv= raw_aio_readv, @@ -1976,8 +1971,8 @@ static BlockDriver bdrv_host_floppy = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, -.bdrv_create= hdev_create, -.create_options = raw_create_options, +.bdrv_create2= hdev_create, +.create_opts = raw_create_opts, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev= raw_aio_writev, @@ -2101,8 +2096,8 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, -.bdrv_create= hdev_create, -.create_options = raw_create_options, +.bdrv_create2= hdev_create, +.create_opts = raw_create_opts, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev= raw_aio_writev, @@ -2232,8 +2227,8 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit =
[Qemu-devel] [PATCH V26 28/32] vhdx.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/vhdx.c | 99 +--- block/vhdx.h | 1 + 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index a9fcf6b..525becb 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1716,8 +1716,7 @@ exit: *. ~ --- ~ ~ ~ ---. * 1MB */ -static int vhdx_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) { int ret = 0; uint64_t image_size = (uint64_t) 2 * GiB; @@ -1730,24 +1729,15 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, gunichar2 *creator = NULL; glong creator_items; BlockDriverState *bs; -const char *type = NULL; +char *type = NULL; VHDXImageType image_type; Error *local_err = NULL; -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -image_size = options-value.n; -} else if (!strcmp(options-name, VHDX_BLOCK_OPT_LOG_SIZE)) { -log_size = options-value.n; -} else if (!strcmp(options-name, VHDX_BLOCK_OPT_BLOCK_SIZE)) { -block_size = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_SUBFMT)) { -type = options-value.s; -} else if (!strcmp(options-name, VHDX_BLOCK_OPT_ZERO)) { -use_zero_blocks = options-value.n != 0; -} -options++; -} +image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0); +block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0); +type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); +use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, false); if (image_size VHDX_MAX_IMAGE_SIZE) { error_setg_errno(errp, EINVAL, Image size too large; max of 64TB); @@ -1756,7 +1746,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, } if (type == NULL) { -type = dynamic; +type = g_strdup(dynamic); } if (!strcmp(type, dynamic)) { @@ -1796,7 +1786,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, block_size = block_size VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX : block_size; -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_propagate(errp, local_err); goto exit; @@ -1856,6 +1846,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options, delete_and_exit: bdrv_unref(bs); exit: +g_free(type); g_free(creator); return ret; } @@ -1878,37 +1869,41 @@ static int vhdx_check(BlockDriverState *bs, BdrvCheckResult *result, return 0; } -static QEMUOptionParameter vhdx_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size; max of 64TB. -}, -{ -.name = VHDX_BLOCK_OPT_LOG_SIZE, -.type = OPT_SIZE, -.value.n = 1 * MiB, -.help = Log size; min 1MB. -}, -{ -.name = VHDX_BLOCK_OPT_BLOCK_SIZE, -.type = OPT_SIZE, -.value.n = 0, -.help = Block Size; min 1MB, max 256MB. \ -0 means auto-calculate based on image size. -}, -{ -.name = BLOCK_OPT_SUBFMT, -.type = OPT_STRING, -.help = VHDX format type, can be either 'dynamic' or 'fixed'. \ -Default is 'dynamic'. -}, -{ -.name = VHDX_BLOCK_OPT_ZERO, -.type = OPT_FLAG, -.help = Force use of payload blocks of type 'ZERO'. Non-standard. -}, -{ NULL } +static QemuOptsList vhdx_create_opts = { +.name = vhdx-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head), +.desc = { +{ + .name = BLOCK_OPT_SIZE, + .type = QEMU_OPT_SIZE, + .help = Virtual disk size; max of 64TB. + }, + { + .name = VHDX_BLOCK_OPT_LOG_SIZE, + .type = QEMU_OPT_SIZE, + .def_value_str = stringify(DEFAULT_LOG_SIZE), + .help = Log size; min 1MB. + }, + { + .name = VHDX_BLOCK_OPT_BLOCK_SIZE, + .type = QEMU_OPT_SIZE, + .def_value_str = stringify(0), + .help = Block Size; min 1MB, max 256MB. \ + 0 means auto-calculate based on image size. + }, + { + .name = BLOCK_OPT_SUBFMT, + .type = QEMU_OPT_STRING, + .help = VHDX format type, can be either 'dynamic'
[Qemu-devel] [PATCH V26 23/32] raw_bsd.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/raw_bsd.c | 27 +++ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/block/raw_bsd.c b/block/raw_bsd.c index 9ae5fc2..ee797fd 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -29,13 +29,17 @@ #include block/block_int.h #include qemu/option.h -static QEMUOptionParameter raw_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ 0 } +static QemuOptsList raw_create_opts = { +.name = raw-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ /* end of list */ } +} }; static int raw_reopen_prepare(BDRVReopenState *reopen_state, @@ -139,13 +143,12 @@ static int raw_has_zero_init(BlockDriverState *bs) return bdrv_has_zero_init(bs-file); } -static int raw_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int raw_create(const char *filename, QemuOpts *opts, Error **errp) { Error *local_err = NULL; int ret; -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (local_err) { error_propagate(errp, local_err); } @@ -177,7 +180,7 @@ static BlockDriver bdrv_raw = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_open= raw_open, .bdrv_close = raw_close, -.bdrv_create = raw_create, +.bdrv_create2 = raw_create, .bdrv_co_readv= raw_co_readv, .bdrv_co_writev = raw_co_writev, .bdrv_co_write_zeroes = raw_co_write_zeroes, @@ -194,7 +197,7 @@ static BlockDriver bdrv_raw = { .bdrv_lock_medium = raw_lock_medium, .bdrv_ioctl = raw_ioctl, .bdrv_aio_ioctl = raw_aio_ioctl, -.create_options = raw_create_options[0], +.create_opts = raw_create_opts, .bdrv_has_zero_init = raw_has_zero_init }; -- 1.8.4.5
[Qemu-devel] [PATCH V26 25/32] sheepdog.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/sheepdog.c | 108 --- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 0eb33ee..9f280f6 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1626,12 +1626,13 @@ static int parse_redundancy(BDRVSheepdogState *s, const char *opt) return 0; } -static int sd_create(const char *filename, QEMUOptionParameter *options, +static int sd_create(const char *filename, QemuOpts *opts, Error **errp) { int ret = 0; uint32_t vid = 0; char *backing_file = NULL; +char *buf = NULL; BDRVSheepdogState *s; char tag[SD_MAX_VDI_TAG_LEN]; uint32_t snapid; @@ -1650,31 +1651,26 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, goto out; } -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -s-inode.vdi_size = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -backing_file = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_PREALLOC)) { -if (!options-value.s || !strcmp(options-value.s, off)) { -prealloc = false; -} else if (!strcmp(options-value.s, full)) { -prealloc = true; -} else { -error_report(Invalid preallocation mode: '%s', - options-value.s); -ret = -EINVAL; -goto out; -} -} else if (!strcmp(options-name, BLOCK_OPT_REDUNDANCY)) { -if (options-value.s) { -ret = parse_redundancy(s, options-value.s); -if (ret 0) { -goto out; -} -} +s-inode.vdi_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); +buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); +if (!buf || !strcmp(buf, off)) { +prealloc = false; +} else if (!strcmp(buf, full)) { +prealloc = true; +} else { +error_report(Invalid preallocation mode: '%s', buf); +ret = -EINVAL; +goto out; +} + +g_free(buf); +buf = qemu_opt_get_del(opts, BLOCK_OPT_REDUNDANCY); +if (buf) { +ret = parse_redundancy(s, buf); +if (ret 0) { +goto out; } -options++; } if (s-inode.vdi_size SD_MAX_VDI_SIZE) { @@ -1724,6 +1720,8 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, ret = sd_prealloc(filename); out: +g_free(backing_file); +g_free(buf); g_free(s); return ret; } @@ -2490,28 +2488,32 @@ static int64_t sd_get_allocated_file_size(BlockDriverState *bs) return size; } -static QEMUOptionParameter sd_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, -{ -.name = BLOCK_OPT_PREALLOC, -.type = OPT_STRING, -.help = Preallocation mode (allowed values: off, full) -}, -{ -.name = BLOCK_OPT_REDUNDANCY, -.type = OPT_STRING, -.help = Redundancy of the image -}, -{ NULL } +static QemuOptsList sd_create_opts = { +.name = sheepdog-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(sd_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_BACKING_FILE, +.type = QEMU_OPT_STRING, +.help = File name of a base image +}, +{ +.name = BLOCK_OPT_PREALLOC, +.type = QEMU_OPT_STRING, +.help = Preallocation mode (allowed values: off, full) +}, +{ +.name = BLOCK_OPT_REDUNDANCY, +.type = QEMU_OPT_STRING, +.help = Redundancy of the image +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_sheepdog = { @@ -2521,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_needs_filename = true, .bdrv_file_open = sd_open, .bdrv_close = sd_close, -.bdrv_create= sd_create, +.bdrv_create2 = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, .bdrv_get_allocated_file_size = sd_get_allocated_file_size, @@ -2541,7 +2543,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_save_vmstate = sd_save_vmstate, .bdrv_load_vmstate = sd_load_vmstate, -.create_options =
[Qemu-devel] [PATCH V26 19/32] qcow2.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/qcow2.c | 265 +++--- include/qemu/option.h | 1 + util/qemu-option.c| 2 +- 3 files changed, 143 insertions(+), 125 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 49985e3..96c78df 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -31,6 +31,7 @@ #include qapi/qmp/qerror.h #include qapi/qmp/qbool.h #include trace.h +#include qemu/option_int.h /* Differences with QCOW: @@ -1593,7 +1594,7 @@ static int preallocate(BlockDriverState *bs) static int qcow2_create2(const char *filename, int64_t total_size, const char *backing_file, const char *backing_format, int flags, size_t cluster_size, int prealloc, - QEMUOptionParameter *options, int version, + QemuOpts *opts, int version, Error **errp) { /* Calculate cluster_bits */ @@ -1625,7 +1626,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, Error *local_err = NULL; int ret; -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_propagate(errp, local_err); return ret; @@ -1761,11 +1762,11 @@ out: return ret; } -static int qcow2_create(const char *filename, QEMUOptionParameter *options, -Error **errp) +static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) { -const char *backing_file = NULL; -const char *backing_fmt = NULL; +char *backing_file = NULL; +char *backing_fmt = NULL; +char *buf = NULL; uint64_t sectors = 0; int flags = 0; size_t cluster_size = DEFAULT_CLUSTER_SIZE; @@ -1775,64 +1776,66 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options, int ret; /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -sectors = options-value.n / 512; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -backing_file = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FMT)) { -backing_fmt = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_ENCRYPT)) { -flags |= options-value.n ? BLOCK_FLAG_ENCRYPT : 0; -} else if (!strcmp(options-name, BLOCK_OPT_CLUSTER_SIZE)) { -if (options-value.n) { -cluster_size = options-value.n; -} -} else if (!strcmp(options-name, BLOCK_OPT_PREALLOC)) { -if (!options-value.s || !strcmp(options-value.s, off)) { -prealloc = 0; -} else if (!strcmp(options-value.s, metadata)) { -prealloc = 1; -} else { -error_setg(errp, Invalid preallocation mode: '%s', - options-value.s); -return -EINVAL; -} -} else if (!strcmp(options-name, BLOCK_OPT_COMPAT_LEVEL)) { -if (!options-value.s) { -/* keep the default */ -} else if (!strcmp(options-value.s, 0.10)) { -version = 2; -} else if (!strcmp(options-value.s, 1.1)) { -version = 3; -} else { -error_setg(errp, Invalid compatibility level: '%s', - options-value.s); -return -EINVAL; -} -} else if (!strcmp(options-name, BLOCK_OPT_LAZY_REFCOUNTS)) { -flags |= options-value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0; -} -options++; +sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512; +backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); +backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT); +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { +flags |= BLOCK_FLAG_ENCRYPT; +} +cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, + DEFAULT_CLUSTER_SIZE); +buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); +if (!buf || !strcmp(buf, off)) { +prealloc = 0; +} else if (!strcmp(buf, metadata)) { +prealloc = 1; +} else { +error_setg(errp, Invalid preallocation mode: '%s', buf); +ret = -EINVAL; +goto finish; +} +g_free(buf); +buf = qemu_opt_get_del(opts, BLOCK_OPT_COMPAT_LEVEL); +if (!buf) { +/* keep the default */ +} else if (!strcmp(buf, 0.10)) { +version = 2; +} else if (!strcmp(buf, 1.1)) { +version = 3; +} else { +error_setg(errp, Invalid compatibility level: '%s', buf); +ret = -EINVAL; +goto finish; +} + +if
[Qemu-devel] [PATCH V26 27/32] vdi.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/vdi.c | 73 + 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 820cd37..950cf46 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -672,8 +672,7 @@ static int vdi_co_write(BlockDriverState *bs, return ret; } -static int vdi_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int vdi_create(const char *filename, QemuOpts *opts, Error **errp) { int fd; int result = 0; @@ -688,25 +687,18 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options, logout(\n); /* Read out options. */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -bytes = options-value.n; +bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); #if defined(CONFIG_VDI_BLOCK_SIZE) -} else if (!strcmp(options-name, BLOCK_OPT_CLUSTER_SIZE)) { -if (options-value.n) { -/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */ -block_size = options-value.n; -} +/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */ +block_size = qemu_opt_get_size_del(opts, + BLOCK_OPT_CLUSTER_SIZE, + DEFAULT_CLUSTER_SIZE); #endif #if defined(CONFIG_VDI_STATIC_IMAGE) -} else if (!strcmp(options-name, BLOCK_OPT_STATIC)) { -if (options-value.n) { -image_type = VDI_TYPE_STATIC; -} -#endif -} -options++; +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) { +image_type = VDI_TYPE_STATIC; } +#endif if (bytes VDI_DISK_SIZE_MAX) { result = -ENOTSUP; @@ -796,29 +788,34 @@ static void vdi_close(BlockDriverState *bs) error_free(s-migration_blocker); } -static QEMUOptionParameter vdi_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, +static QemuOptsList vdi_create_opts = { +.name = vdi-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(vdi_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, #if defined(CONFIG_VDI_BLOCK_SIZE) -{ -.name = BLOCK_OPT_CLUSTER_SIZE, -.type = OPT_SIZE, -.help = VDI cluster (block) size, -.value = { .n = DEFAULT_CLUSTER_SIZE }, -}, +{ +.name = BLOCK_OPT_CLUSTER_SIZE, +.type = QEMU_OPT_SIZE, +.help = VDI cluster (block) size, +.def_value_str = stringify(DEFAULT_CLUSTER_SIZE) +}, #endif #if defined(CONFIG_VDI_STATIC_IMAGE) -{ -.name = BLOCK_OPT_STATIC, -.type = OPT_FLAG, -.help = VDI static (pre-allocated) image -}, +{ +.name = BLOCK_OPT_STATIC, +.type = QEMU_OPT_BOOL, +.help = VDI static (pre-allocated) image, +.def_value_str = off +}, #endif -/* TODO: An additional option to set UUID values might be useful. */ -{ NULL } +/* TODO: An additional option to set UUID values might be useful. */ +{ /* end of list */ } +} }; static BlockDriver bdrv_vdi = { @@ -828,7 +825,7 @@ static BlockDriver bdrv_vdi = { .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_reopen_prepare = vdi_reopen_prepare, -.bdrv_create = vdi_create, +.bdrv_create2 = vdi_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = vdi_co_get_block_status, .bdrv_make_empty = vdi_make_empty, @@ -840,7 +837,7 @@ static BlockDriver bdrv_vdi = { .bdrv_get_info = vdi_get_info, -.create_options = vdi_create_options, +.create_opts = vdi_create_opts, .bdrv_check = vdi_check, }; -- 1.8.4.5
[Qemu-devel] [PATCH V26 17/32] nfs.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Chunyan Liu cy...@suse.com --- block/nfs.c | 12 +++- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index 9fa831f..8633c04 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -357,20 +357,14 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags, return 0; } -static int nfs_file_create(const char *url, QEMUOptionParameter *options, - Error **errp) +static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp) { int ret = 0; int64_t total_size = 0; NFSClient *client = g_malloc0(sizeof(NFSClient)); /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, size)) { -total_size = options-value.n; -} -options++; -} +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); ret = nfs_client_open(client, url, O_CREAT, errp); if (ret 0) { @@ -427,7 +421,7 @@ static BlockDriver bdrv_nfs = { .bdrv_file_open = nfs_file_open, .bdrv_close = nfs_file_close, -.bdrv_create = nfs_file_create, +.bdrv_create2= nfs_file_create, .bdrv_co_readv = nfs_co_readv, .bdrv_co_writev= nfs_co_writev, -- 1.8.4.5
Re: [Qemu-devel] [PATCH 3/4] target-ppc: ppc can be either endian
On 28.04.14 14:47, Andreas Färber wrote: [fixing Bharata's address] Am 28.04.2014 13:29, schrieb Greg Kurz: POWER7, POWER7+ and POWER8 families use the ILE bit of the LPCR special purpose register to decide the endianness to use when entering interrupt handlers. When running a linux guest, this provides a hint on the endianness used by the kernel. From a qemu point of view, the information is needed for legacy virtio QEMU :) - and Linux while at it? support and crash dump support as well. Suggested-by: Benjamin Herrenschmidt b...@kernel.crashing.org Suggested-by: Alexander Graf ag...@suse.de Signed-off-by: Greg Kurz gk...@linux.vnet.ibm.com --- target-ppc/cpu-qom.h|2 ++ target-ppc/misc_helper.c|7 +++ target-ppc/translate_init.c | 16 3 files changed, 25 insertions(+) diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h index 47dc8e6..c20473a 100644 --- a/target-ppc/cpu-qom.h +++ b/target-ppc/cpu-qom.h @@ -76,6 +76,7 @@ typedef struct PowerPCCPUClass { int (*handle_mmu_fault)(PowerPCCPU *cpu, target_ulong eaddr, int rwx, int mmu_idx); #endif +bool (*interrupts_big_endian)(CPUPPCState *env); Please do not add *any* new functions with a CPUPPCState argument, especially not in my shiny new PowerPCCPUClass. ;) } PowerPCCPUClass; /** @@ -118,6 +119,7 @@ int ppc64_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, void *opaque); int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque); +bool ppc_cpu_interrupts_big_endian(CPUState *cs); #ifndef CONFIG_USER_ONLY extern const struct VMStateDescription vmstate_ppc_cpu; #endif diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 2eb2fa6..0e548ff 100644 --- a/target-ppc/misc_helper.c +++ b/target-ppc/misc_helper.c @@ -120,3 +120,10 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +bool ppc_cpu_interrupts_big_endian(CPUState *cs) +{ +PowerPCCPU *cpu = POWERPC_CPU(cs); +PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); White line after variable declaration block, please. +return pcc-interrupts_big_endian(cpu-env); +} diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 823c63c..0d5492f 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -3102,6 +3102,18 @@ static int check_pow_hid0_74xx (CPUPPCState *env) return 0; } +static bool interrupts_big_endian_always(CPUPPCState *env) ppc_cpu_... as a convention for a function accepting PowerPCCPU *cpu as main argument. Further, note that we are working towards compiling multiple targets into one binary, so at least ppc_... for non-static ones please. +{ +return true; +} + +#ifdef TARGET_PPC64 +static bool interrupts_big_endian_POWER7(CPUPPCState *env) Alex, do we prefer lowercase for new code? If this was a POWER7 only function I think the naming would make sense. But it isn't - it works on POWER8 just as well. Why not call it interrupts_big_endian_lpcr()? Alex
[Qemu-devel] [PATCH V26 29/32] vmdk.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/vmdk.c | 123 ++- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 3802863..490f6a6 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1682,17 +1682,16 @@ static int filename_decompose(const char *filename, char *path, char *prefix, return VMDK_OK; } -static int vmdk_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) { int idx = 0; BlockDriverState *new_bs = NULL; Error *local_err; char *desc = NULL; int64_t total_size = 0, filesize; -const char *adapter_type = NULL; -const char *backing_file = NULL; -const char *fmt = NULL; +char *adapter_type = NULL; +char *backing_file = NULL; +char *fmt = NULL; int flags = 0; int ret = 0; bool flat, split, compress; @@ -1732,24 +1731,19 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, goto exit; } /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_ADAPTER_TYPE)) { -adapter_type = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -backing_file = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_COMPAT6)) { -flags |= options-value.n ? BLOCK_FLAG_COMPAT6 : 0; -} else if (!strcmp(options-name, BLOCK_OPT_SUBFMT)) { -fmt = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_ZEROED_GRAIN)) { -zeroed_grain |= options-value.n; -} -options++; +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE); +backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) { +flags |= BLOCK_FLAG_COMPAT6; +} +fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) { +zeroed_grain = true; } + if (!adapter_type) { -adapter_type = ide; +adapter_type = g_strdup(ide); } else if (strcmp(adapter_type, ide) strcmp(adapter_type, buslogic) strcmp(adapter_type, lsilogic) @@ -1765,7 +1759,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, } if (!fmt) { /* Default format to monolithicSparse */ -fmt = monolithicSparse; +fmt = g_strdup(monolithicSparse); } else if (strcmp(fmt, monolithicFlat) strcmp(fmt, monolithicSparse) strcmp(fmt, twoGbMaxExtentSparse) @@ -1866,7 +1860,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, if (!split !flat) { desc_offset = 0x200; } else { -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_setg_errno(errp, -ret, Could not create image file); goto exit; @@ -1896,6 +1890,9 @@ exit: if (new_bs) { bdrv_unref(new_bs); } +g_free(adapter_type); +g_free(backing_file); +g_free(fmt); g_free(desc); g_string_free(ext_desc_lines, true); return ret; @@ -2063,41 +2060,47 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs) return spec_info; } -static QEMUOptionParameter vmdk_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_ADAPTER_TYPE, -.type = OPT_STRING, -.help = Virtual adapter type, can be one of -ide (default), lsilogic, buslogic or legacyESX -}, -{ -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, -{ -.name = BLOCK_OPT_COMPAT6, -.type = OPT_FLAG, -.help = VMDK version 6 image -}, -{ -.name = BLOCK_OPT_SUBFMT, -.type = OPT_STRING, -.help = -VMDK flat extent format, can be one of -{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} -}, -{ -.name = BLOCK_OPT_ZEROED_GRAIN, -.type = OPT_FLAG, -.help = Enable efficient zero writes using the zeroed-grain GTE feature -}, -{ NULL } +static QemuOptsList vmdk_create_opts = { +
Re: [Qemu-devel] [PATCH 4/3] qemu-socket: Clean up inet_connect_opts()
Il 29/04/2014 08:28, Markus Armbruster ha scritto: Separate the search for a working addrinfo from the code that does something with it. Makes for a clearer search loop. Use a local Error * to simplify resetting the error in the search loop. Signed-off-by: Markus Armbruster arm...@redhat.com --- Forgot to include this one. inet_connect_opts() admittedly isn't in the character backend subsystem, just used by it. Hope it's close enough for review and commit. util/qemu-sockets.c | 28 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 8818d7c..627e609 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -354,6 +354,7 @@ static struct addrinfo *inet_parse_connect_opts(QemuOpts *opts, Error **errp) int inet_connect_opts(QemuOpts *opts, Error **errp, NonBlockingConnectHandler *callback, void *opaque) { +Error *local_err = NULL; struct addrinfo *res, *e; int sock = -1; bool in_progress; @@ -372,24 +373,27 @@ int inet_connect_opts(QemuOpts *opts, Error **errp, } for (e = res; e != NULL; e = e-ai_next) { -if (error_is_set(errp)) { -error_free(*errp); -*errp = NULL; -} +error_free(local_err); +local_err = NULL; if (connect_state != NULL) { connect_state-current_addr = e; } -sock = inet_connect_addr(e, in_progress, connect_state, errp); -if (in_progress) { -return sock; -} else if (sock = 0) { -/* non blocking socket immediate success, call callback */ -if (callback != NULL) { -callback(sock, opaque); -} +sock = inet_connect_addr(e, in_progress, connect_state, local_err); +if (sock = 0) { break; } } + +if (sock 0) { +error_propagate(errp, local_err); +} else if (in_progress) { +/* wait_for_connect() will do the rest */ +return sock; +} else { +if (callback) { +callback(sock, opaque); +} +} g_free(connect_state); freeaddrinfo(res); return sock; Nicer indeed. Reviewed-by: Paolo Bonzini pbonz...@redhat.com
Re: [Qemu-devel] [PATCH 1/4] dump: Make DumpState and endian conversion routines available for arch-specific dump code
On 28.04.14 13:29, Greg Kurz wrote: From: Bharata B Rao bhar...@linux.vnet.ibm.com Make DumpState and endian conversion routines available for arch-specific dump code by moving into dump.h. DumpState will be needed by arch-specific dump code to access target endian information from DumpState-ArchDumpInfo. Also break the dependency of dump.h from stubs/dump.c by creating a separate dump-arch.h. This patch doesn't change any functionality. Signed-off-by: Bharata B Rao bhar...@linux.ibm.com [ rebased on top of current master branch, Greg Kurz gk...@linux.vnet.ibm.com ] Signed-off-by: Greg Kurz gk...@linux.vnet.ibm.com --- dump.c | 39 +++- include/sysemu/dump-arch.h | 28 ++ include/sysemu/dump.h | 48 +++- stubs/dump.c |2 +- 4 files changed, 70 insertions(+), 47 deletions(-) create mode 100644 include/sysemu/dump-arch.h diff --git a/dump.c b/dump.c index 14b3d1d..13c9bf2 100644 --- a/dump.c +++ b/dump.c @@ -36,7 +36,7 @@ #define ELF_MACHINE_UNAME Unknown #endif -static uint16_t cpu_convert_to_target16(uint16_t val, int endian) +uint16_t cpu_convert_to_target16(uint16_t val, int endian) This is quite some heavy pollution of the global name space. Alex
[Qemu-devel] [PATCH V26 26/32] ssh.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/ssh.c | 32 +++- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index aa63c9d..3a5eead 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -642,17 +642,20 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags, return ret; } -static QEMUOptionParameter ssh_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ NULL } +static QemuOptsList ssh_create_opts = { +.name = ssh-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(ssh_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ /* end of list */ } +} }; -static int ssh_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int ssh_create(const char *filename, QemuOpts *opts, Error **errp) { int r, ret; Error *local_err = NULL; @@ -665,12 +668,7 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options, ssh_state_init(s); /* Get desired file size. */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n; -} -options++; -} +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); DPRINTF(total_size=% PRIi64, total_size); uri_options = qdict_new(); @@ -1044,14 +1042,14 @@ static BlockDriver bdrv_ssh = { .instance_size= sizeof(BDRVSSHState), .bdrv_parse_filename = ssh_parse_filename, .bdrv_file_open = ssh_file_open, -.bdrv_create = ssh_create, +.bdrv_create2 = ssh_create, .bdrv_close = ssh_close, .bdrv_has_zero_init = ssh_has_zero_init, .bdrv_co_readv= ssh_co_readv, .bdrv_co_writev = ssh_co_writev, .bdrv_getlength = ssh_getlength, .bdrv_co_flush_to_disk= ssh_co_flush, -.create_options = ssh_create_options, +.create_opts = ssh_create_opts, }; static void bdrv_ssh_init(void) -- 1.8.4.5
[Qemu-devel] [PATCH V26 30/32] vpc.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/vpc.c | 62 + 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 2e25f57..8ebf424 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -738,12 +738,11 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t total_size) return ret; } -static int vpc_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) { uint8_t buf[1024]; VHDFooter *footer = (VHDFooter *) buf; -QEMUOptionParameter *disk_type_param; +char *disk_type_param; int fd, i; uint16_t cyls = 0; uint8_t heads = 0; @@ -754,16 +753,16 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, int ret = -EIO; /* Read out options */ -total_size = get_option_parameter(options, BLOCK_OPT_SIZE)-value.n; - -disk_type_param = get_option_parameter(options, BLOCK_OPT_SUBFMT); -if (disk_type_param disk_type_param-value.s) { -if (!strcmp(disk_type_param-value.s, dynamic)) { +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); +if (disk_type_param) { +if (!strcmp(disk_type_param, dynamic)) { disk_type = VHD_DYNAMIC; -} else if (!strcmp(disk_type_param-value.s, fixed)) { +} else if (!strcmp(disk_type_param, fixed)) { disk_type = VHD_FIXED; } else { -return -EINVAL; +ret = -EINVAL; +goto out; } } else { disk_type = VHD_DYNAMIC; @@ -772,7 +771,8 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, /* Create the file */ fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (fd 0) { -return -EIO; +ret = -EIO; +goto out; } /* @@ -837,8 +837,10 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, ret = create_fixed_disk(fd, buf, total_size); } - fail: +fail: qemu_close(fd); +out: +g_free(disk_type_param); return ret; } @@ -866,20 +868,24 @@ static void vpc_close(BlockDriverState *bs) error_free(s-migration_blocker); } -static QEMUOptionParameter vpc_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_SUBFMT, -.type = OPT_STRING, -.help = -Type of virtual hard disk format. Supported formats are -{dynamic (default) | fixed} -}, -{ NULL } +static QemuOptsList vpc_create_opts = { +.name = vpc-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_SUBFMT, +.type = QEMU_OPT_STRING, +.help = +Type of virtual hard disk format. Supported formats are +{dynamic (default) | fixed} +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_vpc = { @@ -890,14 +896,14 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare= vpc_reopen_prepare, -.bdrv_create= vpc_create, +.bdrv_create2 = vpc_create, .bdrv_read = vpc_co_read, .bdrv_write = vpc_co_write, .bdrv_get_info = vpc_get_info, -.create_options = vpc_create_options, +.create_opts= vpc_create_opts, .bdrv_has_zero_init = vpc_has_zero_init, }; -- 1.8.4.5
[Qemu-devel] [PATCH v2] target-ppc: ppc can be either endian
POWER7, POWER7+ and POWER8 families use the ILE bit of the LPCR special purpose register to decide the endianness to use when entering interrupt handlers. When running a Linux guest, this provides a hint on the endianness used by the kernel. From a QEMU point of view, the information is needed for legacy virtio support and crash dump support as well. Suggested-by: Benjamin Herrenschmidt b...@kernel.crashing.org Suggested-by: Alexander Graf ag...@suse.de Signed-off-by: Greg Kurz gk...@linux.vnet.ibm.com --- Changes for v2: - the interrupts_big_endian method now takes a PowerPCCPU * arg - added the ppc_cpu_ prefix to the interrupts_big_endian_* functions - added white line in ppc_cpu_interrupts_big_endian() - s/qemu/QEMU and s/linux/Linux in the commit message Andreas, I did not lowercase ppc_cpu_interrupts_big_endian_POWER7 as most of the recent additions for POWER8 and POWER7+ have uppercase in the function names. Regards. -- Greg target-ppc/cpu-qom.h|2 ++ target-ppc/misc_helper.c|8 target-ppc/translate_init.c | 16 3 files changed, 26 insertions(+) diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h index 47dc8e6..beec3ab 100644 --- a/target-ppc/cpu-qom.h +++ b/target-ppc/cpu-qom.h @@ -76,6 +76,7 @@ typedef struct PowerPCCPUClass { int (*handle_mmu_fault)(PowerPCCPU *cpu, target_ulong eaddr, int rwx, int mmu_idx); #endif +bool (*interrupts_big_endian)(PowerPCCPU *cpu); } PowerPCCPUClass; /** @@ -118,6 +119,7 @@ int ppc64_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, void *opaque); int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque); +bool ppc_cpu_interrupts_big_endian(CPUState *cs); #ifndef CONFIG_USER_ONLY extern const struct VMStateDescription vmstate_ppc_cpu; #endif diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 2eb2fa6..2bc3ba3 100644 --- a/target-ppc/misc_helper.c +++ b/target-ppc/misc_helper.c @@ -120,3 +120,11 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +bool ppc_cpu_interrupts_big_endian(CPUState *cs) +{ +PowerPCCPU *cpu = POWERPC_CPU(cs); +PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + +return pcc-interrupts_big_endian(cpu); +} diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 7f53c33..0355813 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -3102,6 +3102,18 @@ static int check_pow_hid0_74xx (CPUPPCState *env) return 0; } +static bool ppc_cpu_interrupts_big_endian_always(PowerPCCPU *cpu) +{ +return true; +} + +#ifdef TARGET_PPC64 +static bool ppc_cpu_interrupts_big_endian_POWER7(PowerPCCPU *cpu) +{ +return !(cpu-env.spr[SPR_LPCR] LPCR_ILE); +} +#endif + /*/ /* PowerPC implementations definitions */ @@ -7089,6 +7101,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data) POWERPC_FLAG_VSX; pcc-l1_dcache_size = 0x8000; pcc-l1_icache_size = 0x8000; +pcc-interrupts_big_endian = ppc_cpu_interrupts_big_endian_POWER7; } POWERPC_FAMILY(POWER7P)(ObjectClass *oc, void *data) @@ -7132,6 +7145,7 @@ POWERPC_FAMILY(POWER7P)(ObjectClass *oc, void *data) POWERPC_FLAG_VSX; pcc-l1_dcache_size = 0x8000; pcc-l1_icache_size = 0x8000; +pcc-interrupts_big_endian = ppc_cpu_interrupts_big_endian_POWER7; } static void init_proc_POWER8(CPUPPCState *env) @@ -7189,6 +7203,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data) POWERPC_FLAG_VSX; pcc-l1_dcache_size = 0x8000; pcc-l1_icache_size = 0x8000; +pcc-interrupts_big_endian = ppc_cpu_interrupts_big_endian_POWER7; } #endif /* defined (TARGET_PPC64) */ @@ -8511,6 +8526,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) pcc-parent_realize = dc-realize; pcc-pvr = CPU_POWERPC_DEFAULT_MASK; pcc-pvr_mask = CPU_POWERPC_DEFAULT_MASK; +pcc-interrupts_big_endian = ppc_cpu_interrupts_big_endian_always; dc-realize = ppc_cpu_realizefn; dc-unrealize = ppc_cpu_unrealizefn;
Re: [Qemu-devel] [PATCHv2 RESEND] block/iscsi: speed up read for unallocated sectors
Il 29/04/2014 10:57, Peter Lieven ha scritto: Am 28.04.2014 16:56, schrieb Paolo Bonzini: Il 28/04/2014 16:41, Peter Lieven ha scritto: What if opt_unmap_gran is 32K or lower? In this case you're not using an allocationmap. As written I am fine with lowering this to 4K. Follow-Up or v3? Follow up is okay. 2 follow ups send. I also added some comments about the threshold to explain its meaning. Applying all three patches. Paolo
Re: [Qemu-devel] [PATCH 1/4] dump: Make DumpState and endian conversion routines available for arch-specific dump code
On Tue, 29 Apr 2014 11:16:51 +0200 Alexander Graf ag...@suse.de wrote: On 28.04.14 13:29, Greg Kurz wrote: From: Bharata B Rao bhar...@linux.vnet.ibm.com Make DumpState and endian conversion routines available for arch-specific dump code by moving into dump.h. DumpState will be needed by arch-specific dump code to access target endian information from DumpState-ArchDumpInfo. Also break the dependency of dump.h from stubs/dump.c by creating a separate dump-arch.h. This patch doesn't change any functionality. Signed-off-by: Bharata B Rao bhar...@linux.ibm.com [ rebased on top of current master branch, Greg Kurz gk...@linux.vnet.ibm.com ] Signed-off-by: Greg Kurz gk...@linux.vnet.ibm.com --- dump.c | 39 +++- include/sysemu/dump-arch.h | 28 ++ include/sysemu/dump.h | 48 +++- stubs/dump.c |2 +- 4 files changed, 70 insertions(+), 47 deletions(-) create mode 100644 include/sysemu/dump-arch.h diff --git a/dump.c b/dump.c index 14b3d1d..13c9bf2 100644 --- a/dump.c +++ b/dump.c @@ -36,7 +36,7 @@ #define ELF_MACHINE_UNAME Unknown #endif -static uint16_t cpu_convert_to_target16(uint16_t val, int endian) +uint16_t cpu_convert_to_target16(uint16_t val, int endian) This is quite some heavy pollution of the global name space. Alex What about moving the declarations from dump.h to a PPC only header file then ? -- Gregory Kurz kurzg...@fr.ibm.com gk...@linux.vnet.ibm.com Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)562 165 496 Anarchy is about taking complete responsibility for yourself. Alan Moore.
Re: [Qemu-devel] [PATCH v2] target-ppc: ppc can be either endian
On 29.04.14 11:15, Greg Kurz wrote: POWER7, POWER7+ and POWER8 families use the ILE bit of the LPCR special purpose register to decide the endianness to use when entering interrupt handlers. When running a Linux guest, this provides a hint on the endianness used by the kernel. From a QEMU point of view, the information is needed for legacy virtio support and crash dump support as well. Suggested-by: Benjamin Herrenschmidt b...@kernel.crashing.org Suggested-by: Alexander Graf ag...@suse.de Signed-off-by: Greg Kurz gk...@linux.vnet.ibm.com --- Changes for v2: - the interrupts_big_endian method now takes a PowerPCCPU * arg - added the ppc_cpu_ prefix to the interrupts_big_endian_* functions - added white line in ppc_cpu_interrupts_big_endian() - s/qemu/QEMU and s/linux/Linux in the commit message Andreas, I did not lowercase ppc_cpu_interrupts_big_endian_POWER7 as most of the recent additions for POWER8 and POWER7+ have uppercase in the function names. Regards. -- Greg target-ppc/cpu-qom.h|2 ++ target-ppc/misc_helper.c|8 target-ppc/translate_init.c | 16 3 files changed, 26 insertions(+) diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h index 47dc8e6..beec3ab 100644 --- a/target-ppc/cpu-qom.h +++ b/target-ppc/cpu-qom.h @@ -76,6 +76,7 @@ typedef struct PowerPCCPUClass { int (*handle_mmu_fault)(PowerPCCPU *cpu, target_ulong eaddr, int rwx, int mmu_idx); #endif +bool (*interrupts_big_endian)(PowerPCCPU *cpu); } PowerPCCPUClass; /** @@ -118,6 +119,7 @@ int ppc64_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, void *opaque); int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque); +bool ppc_cpu_interrupts_big_endian(CPUState *cs); #ifndef CONFIG_USER_ONLY extern const struct VMStateDescription vmstate_ppc_cpu; #endif diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 2eb2fa6..2bc3ba3 100644 --- a/target-ppc/misc_helper.c +++ b/target-ppc/misc_helper.c @@ -120,3 +120,11 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +bool ppc_cpu_interrupts_big_endian(CPUState *cs) +{ +PowerPCCPU *cpu = POWERPC_CPU(cs); +PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + +return pcc-interrupts_big_endian(cpu); No need for this. Please open code this helper in the calling code. Alex
Re: [Qemu-devel] [PATCH 3/4] target-ppc: ppc can be either endian
On Tue, 29 Apr 2014 11:14:12 +0200 Alexander Graf ag...@suse.de wrote: On 28.04.14 14:47, Andreas Färber wrote: [fixing Bharata's address] Am 28.04.2014 13:29, schrieb Greg Kurz: POWER7, POWER7+ and POWER8 families use the ILE bit of the LPCR special purpose register to decide the endianness to use when entering interrupt handlers. When running a linux guest, this provides a hint on the endianness used by the kernel. From a qemu point of view, the information is needed for legacy virtio QEMU :) - and Linux while at it? support and crash dump support as well. Suggested-by: Benjamin Herrenschmidt b...@kernel.crashing.org Suggested-by: Alexander Graf ag...@suse.de Signed-off-by: Greg Kurz gk...@linux.vnet.ibm.com --- target-ppc/cpu-qom.h|2 ++ target-ppc/misc_helper.c|7 +++ target-ppc/translate_init.c | 16 3 files changed, 25 insertions(+) diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h index 47dc8e6..c20473a 100644 --- a/target-ppc/cpu-qom.h +++ b/target-ppc/cpu-qom.h @@ -76,6 +76,7 @@ typedef struct PowerPCCPUClass { int (*handle_mmu_fault)(PowerPCCPU *cpu, target_ulong eaddr, int rwx, int mmu_idx); #endif +bool (*interrupts_big_endian)(CPUPPCState *env); Please do not add *any* new functions with a CPUPPCState argument, especially not in my shiny new PowerPCCPUClass. ;) } PowerPCCPUClass; /** @@ -118,6 +119,7 @@ int ppc64_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, void *opaque); int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque); +bool ppc_cpu_interrupts_big_endian(CPUState *cs); #ifndef CONFIG_USER_ONLY extern const struct VMStateDescription vmstate_ppc_cpu; #endif diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 2eb2fa6..0e548ff 100644 --- a/target-ppc/misc_helper.c +++ b/target-ppc/misc_helper.c @@ -120,3 +120,10 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +bool ppc_cpu_interrupts_big_endian(CPUState *cs) +{ +PowerPCCPU *cpu = POWERPC_CPU(cs); +PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); White line after variable declaration block, please. +return pcc-interrupts_big_endian(cpu-env); +} diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 823c63c..0d5492f 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -3102,6 +3102,18 @@ static int check_pow_hid0_74xx (CPUPPCState *env) return 0; } +static bool interrupts_big_endian_always(CPUPPCState *env) ppc_cpu_... as a convention for a function accepting PowerPCCPU *cpu as main argument. Further, note that we are working towards compiling multiple targets into one binary, so at least ppc_... for non-static ones please. +{ +return true; +} + +#ifdef TARGET_PPC64 +static bool interrupts_big_endian_POWER7(CPUPPCState *env) Alex, do we prefer lowercase for new code? If this was a POWER7 only function I think the naming would make sense. But it isn't - it works on POWER8 just as well. Why not call it interrupts_big_endian_lpcr()? Sure, I'll do this right now. Alex -- Gregory Kurz kurzg...@fr.ibm.com gk...@linux.vnet.ibm.com Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)562 165 496 Anarchy is about taking complete responsibility for yourself. Alan Moore.
[Qemu-devel] [PATCH V26 14/32] cow.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/cow.c | 54 ++ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/block/cow.c b/block/cow.c index 26cf4a5..fb2cd68 100644 --- a/block/cow.c +++ b/block/cow.c @@ -324,31 +324,24 @@ static void cow_close(BlockDriverState *bs) { } -static int cow_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int cow_create(const char *filename, QemuOpts *opts, Error **errp) { struct cow_header_v2 cow_header; struct stat st; int64_t image_sectors = 0; -const char *image_filename = NULL; +char *image_filename = NULL; Error *local_err = NULL; int ret; BlockDriverState *cow_bs; /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -image_sectors = options-value.n / 512; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -image_filename = options-value.s; -} -options++; -} +image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512; +image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto exit; } cow_bs = NULL; @@ -356,7 +349,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options, BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto exit; } memset(cow_header, 0, sizeof(cow_header)); @@ -389,22 +382,27 @@ static int cow_create(const char *filename, QEMUOptionParameter *options, } exit: +g_free(image_filename); bdrv_unref(cow_bs); return ret; } -static QEMUOptionParameter cow_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, -{ NULL } +static QemuOptsList cow_create_opts = { +.name = cow-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(cow_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_BACKING_FILE, +.type = QEMU_OPT_STRING, +.help = File name of a base image +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_cow = { @@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = { .bdrv_probe = cow_probe, .bdrv_open = cow_open, .bdrv_close = cow_close, -.bdrv_create= cow_create, +.bdrv_create2 = cow_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_read = cow_co_read, .bdrv_write = cow_co_write, .bdrv_co_get_block_status = cow_co_get_block_status, -.create_options = cow_create_options, +.create_opts= cow_create_opts, }; static void bdrv_cow_init(void) -- 1.8.4.5
[Qemu-devel] [PATCH V26 24/32] rbd.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/rbd.c | 63 + 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index dbc79f4..f878877 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -282,8 +282,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf) return ret; } -static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) { int64_t bytes = 0; int64_t objsize; @@ -306,24 +305,18 @@ static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options, } /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -bytes = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_CLUSTER_SIZE)) { -if (options-value.n) { -objsize = options-value.n; -if ((objsize - 1) objsize) {/* not a power of 2? */ -error_report(obj size needs to be power of 2); -return -EINVAL; -} -if (objsize 4096) { -error_report(obj size too small); -return -EINVAL; -} -obj_order = ffs(objsize) - 1; -} +bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0); +if (objsize) { +if ((objsize - 1) objsize) {/* not a power of 2? */ +error_report(obj size needs to be power of 2); +return -EINVAL; +} +if (objsize 4096) { +error_report(obj size too small); +return -EINVAL; } -options++; +obj_order = ffs(objsize) - 1; } clientname = qemu_rbd_parse_clientname(conf, clientname_buf); @@ -900,18 +893,22 @@ static BlockDriverAIOCB* qemu_rbd_aio_discard(BlockDriverState *bs, } #endif -static QEMUOptionParameter qemu_rbd_create_options[] = { -{ - .name = BLOCK_OPT_SIZE, - .type = OPT_SIZE, - .help = Virtual disk size -}, -{ - .name = BLOCK_OPT_CLUSTER_SIZE, - .type = OPT_SIZE, - .help = RBD object size -}, -{NULL} +static QemuOptsList qemu_rbd_create_opts = { +.name = rbd-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_CLUSTER_SIZE, +.type = QEMU_OPT_SIZE, +.help = RBD object size +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_rbd = { @@ -920,10 +917,10 @@ static BlockDriver bdrv_rbd = { .bdrv_needs_filename = true, .bdrv_file_open = qemu_rbd_open, .bdrv_close = qemu_rbd_close, -.bdrv_create= qemu_rbd_create, +.bdrv_create2 = qemu_rbd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_get_info = qemu_rbd_getinfo, -.create_options = qemu_rbd_create_options, +.create_opts= qemu_rbd_create_opts, .bdrv_getlength = qemu_rbd_getlength, .bdrv_truncate = qemu_rbd_truncate, .protocol_name = rbd, -- 1.8.4.5
[Qemu-devel] [PATCH V26 06/32] QemuOpts: move qemu_opt_del ahead for later calling
In later patch, qemu_opt_get_del functions will be added, they will first get the option value, then call qemu_opt_del to remove the option from opt list. To prepare for that purpose, move qemu_opt_del ahead first. Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- util/qemu-option.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 69cdf3f..4d2d4d1 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -567,6 +567,14 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) return NULL; } +static void qemu_opt_del(QemuOpt *opt) +{ +QTAILQ_REMOVE(opt-opts-head, opt, next); +g_free(opt-name); +g_free(opt-str); +g_free(opt); +} + const char *qemu_opt_get(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); @@ -661,14 +669,6 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp) } } -static void qemu_opt_del(QemuOpt *opt) -{ -QTAILQ_REMOVE(opt-opts-head, opt, next); -g_free(opt-name); -g_free(opt-str); -g_free(opt); -} - static bool opts_accepts_any(const QemuOpts *opts) { return opts-list-desc[0].name == NULL; -- 1.8.4.5
[Qemu-devel] [PATCH V26 22/32] raw-win32.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/raw-win32.c | 38 +++--- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/block/raw-win32.c b/block/raw-win32.c index 48cb2c2..b00d7fc 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -475,8 +475,7 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs) return st.st_size; } -static int raw_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int raw_create(const char *filename, QemuOpts *opts, Error **errp) { int fd; int64_t total_size = 0; @@ -484,12 +483,8 @@ static int raw_create(const char *filename, QEMUOptionParameter *options, strstart(filename, file:, filename); /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n / 512; -} -options++; -} +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512; fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); @@ -503,13 +498,18 @@ static int raw_create(const char *filename, QEMUOptionParameter *options, return 0; } -static QEMUOptionParameter raw_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ NULL } + +static QemuOptsList raw_create_opts = { +.name = raw-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_file = { @@ -518,9 +518,9 @@ static BlockDriver bdrv_file = { .instance_size = sizeof(BDRVRawState), .bdrv_needs_filename = true, .bdrv_parse_filename = raw_parse_filename, -.bdrv_file_open= raw_open, -.bdrv_close= raw_close, -.bdrv_create = raw_create, +.bdrv_file_open = raw_open, +.bdrv_close = raw_close, +.bdrv_create2 = raw_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_aio_readv = raw_aio_readv, @@ -532,7 +532,7 @@ static BlockDriver bdrv_file = { .bdrv_get_allocated_file_size = raw_get_allocated_file_size, -.create_options = raw_create_options, +.create_opts= raw_create_opts, }; /***/ -- 1.8.4.5
[Qemu-devel] [PATCH V26 07/32] QemuOpts: add qemu_opt_get_*_del functions for replace work
Add qemu_opt_get_del, qemu_opt_get_bool_del, qemu_opt_get_number_del and qemu_opt_get_size_del to replace the same handling of QEMUOptionParameter (get and delete). Several drivers are coded to parse a known subset of options, then remove them from the list before handing all remaining options to a second driver for further option processing. get_*_del makes it easier to retrieve a known option (or its default) and remove it from the list all in one action. Share common helper function: For qemu_opt_get_bool/size/number, they and their get_*_del counterpart could share most of the code except whether or not deleting the opt from option list, so generate common helper functions. For qemu_opt_get and qemu_opt_get_del, keep code duplication, since 1. qemu_opt_get_del returns malloc'd memory while qemu_opt_get returns in-place memory 2. qemu_opt_get_del returns (char *), qemu_opt_get returns (const char *), and could not change to (char *), since in one case, it will return desc-def_value_str, which is (const char *). Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h | 6 +++ util/qemu-option.c| 116 -- 2 files changed, 109 insertions(+), 13 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index c3b0a91..6653e43 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -111,6 +111,7 @@ struct QemuOptsList { }; const char *qemu_opt_get(QemuOpts *opts, const char *name); +char *qemu_opt_get_del(QemuOpts *opts, const char *name); /** * qemu_opt_has_help_opt: * @opts: options to search for a help request @@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts); bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval); uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); +bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval); +uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name, + uint64_t defval); +uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, + uint64_t defval); int qemu_opt_unset(QemuOpts *opts, const char *name); int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, diff --git a/util/qemu-option.c b/util/qemu-option.c index 4d2d4d1..32e1d50 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -575,6 +575,19 @@ static void qemu_opt_del(QemuOpt *opt) g_free(opt); } +/* qemu_opt_set allows many settings for the same option. + * This function deletes all settings for an option. + */ +static void qemu_opt_del_all(QemuOpts *opts, const char *name) +{ +QemuOpt *opt, *next_opt; + +QTAILQ_FOREACH_SAFE(opt, opts-head, next, next_opt) { +if (!strcmp(opt-name, name)) +qemu_opt_del(opt); +} +} + const char *qemu_opt_get(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); @@ -588,6 +601,34 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name) return opt ? opt-str : NULL; } +/* Get a known option (or its default) and remove it from the list + * all in one action. Return a malloced string of the option value. + * Result must be freed by caller with g_free(). + */ +char *qemu_opt_get_del(QemuOpts *opts, const char *name) +{ +QemuOpt *opt; +const QemuOptDesc *desc; +char *str = NULL; + +if (opts == NULL) { +return NULL; +} + +opt = qemu_opt_find(opts, name); +if (!opt) { +desc = find_desc_by_name(opts-list-desc, name); +if (desc desc-def_value_str) { +str = g_strdup(desc-def_value_str); +} +return str; +} +str = opt-str; +opt-str = NULL; +qemu_opt_del_all(opts, name); +return str; +} + bool qemu_opt_has_help_opt(QemuOpts *opts) { QemuOpt *opt; @@ -600,50 +641,99 @@ bool qemu_opt_has_help_opt(QemuOpts *opts) return false; } -bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval) +static bool qemu_opt_get_bool_helper(QemuOpts *opts, const char *name, + bool defval, bool del) { QemuOpt *opt = qemu_opt_find(opts, name); +bool ret = defval; if (opt == NULL) { const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name); if (desc desc-def_value_str) { -parse_option_bool(name, desc-def_value_str, defval, error_abort); +parse_option_bool(name, desc-def_value_str, ret, error_abort); } -return defval; +return ret; } assert(opt-desc opt-desc-type == QEMU_OPT_BOOL); -return opt-value.boolean; +ret = opt-value.boolean; +if
[Qemu-devel] [PATCH V26 08/32] QemuOpts: add qemu_opts_print_help to replace print_option_help
print_option_help takes QEMUOptionParameter as parameter, add qemu_opts_print_help to take QemuOptsList as parameter for later replace work. Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h | 1 + util/qemu-option.c| 13 + 2 files changed, 14 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index 6653e43..fbf5dc2 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -166,5 +166,6 @@ typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); void qemu_opts_print(QemuOpts *opts); int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, int abort_on_failure); +void qemu_opts_print_help(QemuOptsList *list); #endif diff --git a/util/qemu-option.c b/util/qemu-option.c index 32e1d50..adb7c3c 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -553,6 +553,19 @@ void print_option_help(QEMUOptionParameter *list) } } +void qemu_opts_print_help(QemuOptsList *list) +{ +QemuOptDesc *desc; + +assert(list); +desc = list-desc; +printf(Supported options:\n); +while (desc desc-name) { +printf(%-16s %s\n, desc-name, + desc-help ? desc-help : No description available); +desc++; +} +} /* -- */ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name) -- 1.8.4.5
[Qemu-devel] [PATCH V26 15/32] gluster.c: replace QEMUOptionParameter with QemuOpts
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- Changes to V25: * fix create_opts, OPT_STRING - QEMU_OPT_STRING block/gluster.c | 81 ++--- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 8836085..c72ca77 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -471,13 +471,14 @@ static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset, #endif static int qemu_gluster_create(const char *filename, -QEMUOptionParameter *options, Error **errp) + QemuOpts *opts, Error **errp) { struct glfs *glfs; struct glfs_fd *fd; int ret = 0; int prealloc = 0; int64_t total_size = 0; +char *tmp = NULL; GlusterConf *gconf = g_malloc0(sizeof(GlusterConf)); glfs = qemu_gluster_init(gconf, filename, errp); @@ -486,24 +487,21 @@ static int qemu_gluster_create(const char *filename, goto out; } -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n / BDRV_SECTOR_SIZE; -} else if (!strcmp(options-name, BLOCK_OPT_PREALLOC)) { -if (!options-value.s || !strcmp(options-value.s, off)) { -prealloc = 0; -} else if (!strcmp(options-value.s, full) -gluster_supports_zerofill()) { -prealloc = 1; -} else { -error_setg(errp, Invalid preallocation mode: '%s' - or GlusterFS doesn't support zerofill API, - options-value.s); -ret = -EINVAL; -goto out; -} -} -options++; +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; + +tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); +if (!tmp || !strcmp(tmp, off)) { +prealloc = 0; +} else if (!strcmp(tmp, full) + gluster_supports_zerofill()) { +prealloc = 1; +} else { +error_setg(errp, Invalid preallocation mode: '%s' + or GlusterFS doesn't support zerofill API, +tmp); +ret = -EINVAL; +goto out; } fd = glfs_creat(glfs, gconf-image, @@ -525,6 +523,7 @@ static int qemu_gluster_create(const char *filename, } } out: +g_free(tmp); qemu_gluster_gconf_free(gconf); if (glfs) { glfs_fini(glfs); @@ -688,18 +687,22 @@ static int qemu_gluster_has_zero_init(BlockDriverState *bs) return 0; } -static QEMUOptionParameter qemu_gluster_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_PREALLOC, -.type = OPT_STRING, -.help = Preallocation mode (allowed values: off, full) -}, -{ NULL } +static QemuOptsList qemu_gluster_create_opts = { +.name = qemu-gluster-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_PREALLOC, +.type = QEMU_OPT_STRING, +.help = Preallocation mode (allowed values: off, full) +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_gluster = { @@ -712,7 +715,7 @@ static BlockDriver bdrv_gluster = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort= qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, -.bdrv_create = qemu_gluster_create, +.bdrv_create2 = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate= qemu_gluster_truncate, @@ -726,7 +729,7 @@ static BlockDriver bdrv_gluster = { #ifdef CONFIG_GLUSTERFS_ZEROFILL .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes, #endif -.create_options = qemu_gluster_create_options, +.create_opts = qemu_gluster_create_opts, }; static BlockDriver bdrv_gluster_tcp = { @@ -739,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = { .bdrv_reopen_commit = qemu_gluster_reopen_commit, .bdrv_reopen_abort= qemu_gluster_reopen_abort, .bdrv_close = qemu_gluster_close, -.bdrv_create = qemu_gluster_create, +.bdrv_create2 = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, .bdrv_truncate=
[Qemu-devel] [PATCH V26 32/32] QemuOpts: cleanup tmp 'allocated' member from QemuOptsList
Now only qemu_opts_append uses 'allocated' to indicate free memory. For this function only, we can also let result list's (const char *) members point to input list's members, only if the input list has longer lifetime than result list. In current code, that is true. So, we can remove the 'allocated' member from QemuOptsList definition to keep code clean. Signed-off-by: Chunyan Liu cy...@suse.com --- Changes to V25: * update function comments to follow Stefan's suggestion include/qemu/option.h | 6 -- util/qemu-option.c| 27 +++ 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index 921eccd..59bea75 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -63,12 +63,6 @@ typedef struct QemuOptDesc { } QemuOptDesc; struct QemuOptsList { -/* FIXME: Temp used for QEMUOptionParamter-QemuOpts conversion to - * indicate the need to free memory. Will remove after all drivers - * switch to QemuOpts. - */ -bool allocated; - const char *name; const char *implied_opt_name; bool merge_lists; /* Merge multiple uses of option into a single list? */ diff --git a/util/qemu-option.c b/util/qemu-option.c index 27c61db..53785fc 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1076,26 +1076,13 @@ static size_t count_opts_list(QemuOptsList *list) void qemu_opts_free(QemuOptsList *list) { -/* List members point to new malloced space and need to be freed. - * FIXME: - * Introduced for QEMUOptionParamter-QemuOpts conversion. - * Will remove after all drivers switch to QemuOpts. - */ -if (list list-allocated) { -QemuOptDesc *desc = list-desc; -while (desc desc-name) { -g_free((char *)desc-name); -g_free((char *)desc-help); -g_free((char *)desc-def_value_str); -desc++; -} -} - g_free(list); } /* Realloc dst option list and append options from an option list (list) * to it. dst could be NULL or a malloced list. + * The lifetime of dst must be shorter than the input list because the + * QemuOptDesc-name, -help, and -def_value_str strings are shared. */ QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list) @@ -1124,23 +,15 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst, dst-name = NULL; dst-implied_opt_name = NULL; QTAILQ_INIT(dst-head); -dst-allocated = true; } dst-desc[num_dst_opts].name = NULL; -/* (const char *) members of result dst are malloced, need free. */ -assert(dst-allocated); /* append list-desc to dst-desc */ if (list) { desc = list-desc; while (desc desc-name) { if (find_desc_by_name(dst-desc, desc-name) == NULL) { -dst-desc[num_dst_opts].name = g_strdup(desc-name); -dst-desc[num_dst_opts].type = desc-type; -dst-desc[num_dst_opts].help = g_strdup(desc-help); -dst-desc[num_dst_opts].def_value_str = - g_strdup(desc-def_value_str); -num_dst_opts++; +dst-desc[num_dst_opts++] = *desc; dst-desc[num_dst_opts].name = NULL; } desc++; -- 1.8.4.5
[Qemu-devel] [PATCH V26 01/32] QemuOpts: move find_desc_by_name ahead for later calling
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- util/qemu-option.c | 28 ++-- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 8bbc3ad..808aef4 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -173,6 +173,20 @@ static void parse_option_number(const char *name, const char *value, } } +static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc, +const char *name) +{ +int i; + +for (i = 0; desc[i].name != NULL; i++) { +if (strcmp(desc[i].name, name) == 0) { +return desc[i]; +} +} + +return NULL; +} + void parse_option_size(const char *name, const char *value, uint64_t *ret, Error **errp) { @@ -637,20 +651,6 @@ static bool opts_accepts_any(const QemuOpts *opts) return opts-list-desc[0].name == NULL; } -static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc, -const char *name) -{ -int i; - -for (i = 0; desc[i].name != NULL; i++) { -if (strcmp(desc[i].name, name) == 0) { -return desc[i]; -} -} - -return NULL; -} - int qemu_opt_unset(QemuOpts *opts, const char *name) { QemuOpt *opt = qemu_opt_find(opts, name); -- 1.8.4.5
[Qemu-devel] [PATCH V26 04/32] qapi: output def_value_str when query command line options
Change qapi interfaces to output the newly added def_value_str when querying command line options. Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- Changes to V25: * update @default description in .json file qapi-schema.json | 5 - qmp-commands.hx| 2 ++ util/qemu-config.c | 4 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/qapi-schema.json b/qapi-schema.json index 0b00427..880829d 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4088,12 +4088,15 @@ # # @help: #optional human readable text string, not suitable for parsing. # +# @default: #optional default value string (since 2.1) +# # Since 1.5 ## { 'type': 'CommandLineParameterInfo', 'data': { 'name': 'str', 'type': 'CommandLineParameterType', -'*help': 'str' } } +'*help': 'str', +'*default': 'str' } } ## # @CommandLineOptionInfo: diff --git a/qmp-commands.hx b/qmp-commands.hx index ed3ab92..1271332 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2895,6 +2895,8 @@ Each array entry contains the following: or 'size') - help: human readable description of the parameter (json-string, optional) +- default: default value string for the parameter + (json-string, optional) Example: diff --git a/util/qemu-config.c b/util/qemu-config.c index f4e4f38..ba375c0 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -82,6 +82,10 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) info-has_help = true; info-help = g_strdup(desc[i].help); } +if (desc[i].def_value_str) { +info-has_q_default = true; +info-q_default = g_strdup(desc[i].def_value_str); +} entry = g_malloc0(sizeof(*entry)); entry-value = info; -- 1.8.4.5
[Qemu-devel] [PATCH V26 21/32] raw-posix.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/raw-posix.c | 59 +-- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 1688e16..e72f449 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1234,8 +1234,7 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs) return (int64_t)st.st_blocks * 512; } -static int raw_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int raw_create(const char *filename, QemuOpts *opts, Error **errp) { int fd; int result = 0; @@ -1244,12 +1243,8 @@ static int raw_create(const char *filename, QEMUOptionParameter *options, strstart(filename, file:, filename); /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n / BDRV_SECTOR_SIZE; -} -options++; -} +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); @@ -1410,13 +1405,17 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } -static QEMUOptionParameter raw_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ NULL } +static QemuOptsList raw_create_opts = { +.name = raw-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_file = { @@ -1431,7 +1430,7 @@ static BlockDriver bdrv_file = { .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, .bdrv_close = raw_close, -.bdrv_create = raw_create, +.bdrv_create2 = raw_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_get_block_status = raw_co_get_block_status, .bdrv_co_write_zeroes = raw_co_write_zeroes, @@ -1448,7 +1447,7 @@ static BlockDriver bdrv_file = { .bdrv_get_allocated_file_size = raw_get_allocated_file_size, -.create_options = raw_create_options, +.create_opts = raw_create_opts, }; /***/ @@ -1769,7 +1768,7 @@ static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs, return -ENOTSUP; } -static int hdev_create(const char *filename, QEMUOptionParameter *options, +static int hdev_create(const char *filename, QemuOpts *opts, Error **errp) { int fd; @@ -1790,12 +1789,8 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options, (void)has_prefix; /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, size)) { -total_size = options-value.n / BDRV_SECTOR_SIZE; -} -options++; -} +total_size = +qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE; fd = qemu_open(filename, O_WRONLY | O_BINARY); if (fd 0) { @@ -1832,8 +1827,8 @@ static BlockDriver bdrv_host_device = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, -.bdrv_create= hdev_create, -.create_options = raw_create_options, +.bdrv_create2= hdev_create, +.create_opts = raw_create_opts, .bdrv_co_write_zeroes = hdev_co_write_zeroes, .bdrv_aio_readv= raw_aio_readv, @@ -1976,8 +1971,8 @@ static BlockDriver bdrv_host_floppy = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, -.bdrv_create= hdev_create, -.create_options = raw_create_options, +.bdrv_create2= hdev_create, +.create_opts = raw_create_opts, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev= raw_aio_writev, @@ -2101,8 +2096,8 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, -.bdrv_create= hdev_create, -.create_options = raw_create_options, +.bdrv_create2= hdev_create, +.create_opts = raw_create_opts, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev= raw_aio_writev, @@ -2232,8 +2227,8 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit =
[Qemu-devel] [PATCH V26 29/32] vmdk.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/vmdk.c | 123 ++- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 3802863..490f6a6 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1682,17 +1682,16 @@ static int filename_decompose(const char *filename, char *path, char *prefix, return VMDK_OK; } -static int vmdk_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) { int idx = 0; BlockDriverState *new_bs = NULL; Error *local_err; char *desc = NULL; int64_t total_size = 0, filesize; -const char *adapter_type = NULL; -const char *backing_file = NULL; -const char *fmt = NULL; +char *adapter_type = NULL; +char *backing_file = NULL; +char *fmt = NULL; int flags = 0; int ret = 0; bool flat, split, compress; @@ -1732,24 +1731,19 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, goto exit; } /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n; -} else if (!strcmp(options-name, BLOCK_OPT_ADAPTER_TYPE)) { -adapter_type = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -backing_file = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_COMPAT6)) { -flags |= options-value.n ? BLOCK_FLAG_COMPAT6 : 0; -} else if (!strcmp(options-name, BLOCK_OPT_SUBFMT)) { -fmt = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_ZEROED_GRAIN)) { -zeroed_grain |= options-value.n; -} -options++; +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE); +backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) { +flags |= BLOCK_FLAG_COMPAT6; +} +fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) { +zeroed_grain = true; } + if (!adapter_type) { -adapter_type = ide; +adapter_type = g_strdup(ide); } else if (strcmp(adapter_type, ide) strcmp(adapter_type, buslogic) strcmp(adapter_type, lsilogic) @@ -1765,7 +1759,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, } if (!fmt) { /* Default format to monolithicSparse */ -fmt = monolithicSparse; +fmt = g_strdup(monolithicSparse); } else if (strcmp(fmt, monolithicFlat) strcmp(fmt, monolithicSparse) strcmp(fmt, twoGbMaxExtentSparse) @@ -1866,7 +1860,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options, if (!split !flat) { desc_offset = 0x200; } else { -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_setg_errno(errp, -ret, Could not create image file); goto exit; @@ -1896,6 +1890,9 @@ exit: if (new_bs) { bdrv_unref(new_bs); } +g_free(adapter_type); +g_free(backing_file); +g_free(fmt); g_free(desc); g_string_free(ext_desc_lines, true); return ret; @@ -2063,41 +2060,47 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs) return spec_info; } -static QEMUOptionParameter vmdk_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_ADAPTER_TYPE, -.type = OPT_STRING, -.help = Virtual adapter type, can be one of -ide (default), lsilogic, buslogic or legacyESX -}, -{ -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, -{ -.name = BLOCK_OPT_COMPAT6, -.type = OPT_FLAG, -.help = VMDK version 6 image -}, -{ -.name = BLOCK_OPT_SUBFMT, -.type = OPT_STRING, -.help = -VMDK flat extent format, can be one of -{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} -}, -{ -.name = BLOCK_OPT_ZEROED_GRAIN, -.type = OPT_FLAG, -.help = Enable efficient zero writes using the zeroed-grain GTE feature -}, -{ NULL } +static QemuOptsList vmdk_create_opts = { +
[Qemu-devel] [PATCH V26 03/32] QemuOpts: repurpose qemu_opts_print to replace print_option_parameters
Currently this function is not used anywhere. In later patches, it will replace print_option_parameters. To avoid print info changes, change qemu_opts_print from fprintf stderr to printf to keep consistent with print_option_parameters, remove last printf and print size/number with opt-value.uint instead of opt-str. Signed-off-by: Chunyan Liu cy...@suse.com --- util/qemu-option.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 5346c90..2be6995 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -925,7 +925,7 @@ void qemu_opts_print(QemuOpts *opts) if (desc[0].name == NULL) { QTAILQ_FOREACH(opt, opts-head, next) { -fprintf(stderr, %s=\%s\ , opt-name, opt-str); +printf(%s=\%s\ , opt-name, opt-str); } return; } @@ -938,12 +938,14 @@ void qemu_opts_print(QemuOpts *opts) continue; } if (desc-type == QEMU_OPT_STRING) { -fprintf(stderr, %s='%s' , desc-name, value); +printf(%s='%s' , desc-name, value); +} else if ((desc-type == QEMU_OPT_SIZE || +desc-type == QEMU_OPT_NUMBER) opt) { +printf(%s=% PRId64 , desc-name, opt-value.uint); } else { -fprintf(stderr, %s=%s , desc-name, value); +printf(%s=%s , desc-name, value); } } -fprintf(stderr, \n); } static int opts_do_parse(QemuOpts *opts, const char *params, -- 1.8.4.5
[Qemu-devel] [PATCH V26 30/32] vpc.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/vpc.c | 62 + 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 2e25f57..8ebf424 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -738,12 +738,11 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t total_size) return ret; } -static int vpc_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) { uint8_t buf[1024]; VHDFooter *footer = (VHDFooter *) buf; -QEMUOptionParameter *disk_type_param; +char *disk_type_param; int fd, i; uint16_t cyls = 0; uint8_t heads = 0; @@ -754,16 +753,16 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, int ret = -EIO; /* Read out options */ -total_size = get_option_parameter(options, BLOCK_OPT_SIZE)-value.n; - -disk_type_param = get_option_parameter(options, BLOCK_OPT_SUBFMT); -if (disk_type_param disk_type_param-value.s) { -if (!strcmp(disk_type_param-value.s, dynamic)) { +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); +disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); +if (disk_type_param) { +if (!strcmp(disk_type_param, dynamic)) { disk_type = VHD_DYNAMIC; -} else if (!strcmp(disk_type_param-value.s, fixed)) { +} else if (!strcmp(disk_type_param, fixed)) { disk_type = VHD_FIXED; } else { -return -EINVAL; +ret = -EINVAL; +goto out; } } else { disk_type = VHD_DYNAMIC; @@ -772,7 +771,8 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, /* Create the file */ fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (fd 0) { -return -EIO; +ret = -EIO; +goto out; } /* @@ -837,8 +837,10 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options, ret = create_fixed_disk(fd, buf, total_size); } - fail: +fail: qemu_close(fd); +out: +g_free(disk_type_param); return ret; } @@ -866,20 +868,24 @@ static void vpc_close(BlockDriverState *bs) error_free(s-migration_blocker); } -static QEMUOptionParameter vpc_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_SUBFMT, -.type = OPT_STRING, -.help = -Type of virtual hard disk format. Supported formats are -{dynamic (default) | fixed} -}, -{ NULL } +static QemuOptsList vpc_create_opts = { +.name = vpc-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_SUBFMT, +.type = QEMU_OPT_STRING, +.help = +Type of virtual hard disk format. Supported formats are +{dynamic (default) | fixed} +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_vpc = { @@ -890,14 +896,14 @@ static BlockDriver bdrv_vpc = { .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare= vpc_reopen_prepare, -.bdrv_create= vpc_create, +.bdrv_create2 = vpc_create, .bdrv_read = vpc_co_read, .bdrv_write = vpc_co_write, .bdrv_get_info = vpc_get_info, -.create_options = vpc_create_options, +.create_opts= vpc_create_opts, .bdrv_has_zero_init = vpc_has_zero_init, }; -- 1.8.4.5
[Qemu-devel] [PATCH V26 18/32] qcow.c: replace QEMUOptionParameter with QemuOpts
Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com Signed-off-by: Chunyan Liu cy...@suse.com --- block/qcow.c | 72 ++-- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 9411aef..b4ce133 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -662,35 +662,29 @@ static void qcow_close(BlockDriverState *bs) error_free(s-migration_blocker); } -static int qcow_create(const char *filename, QEMUOptionParameter *options, - Error **errp) +static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) { int header_size, backing_filename_len, l1_size, shift, i; QCowHeader header; uint8_t *tmp; int64_t total_size = 0; -const char *backing_file = NULL; +char *backing_file = NULL; int flags = 0; Error *local_err = NULL; int ret; BlockDriverState *qcow_bs; /* Read out options */ -while (options options-name) { -if (!strcmp(options-name, BLOCK_OPT_SIZE)) { -total_size = options-value.n / 512; -} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) { -backing_file = options-value.s; -} else if (!strcmp(options-name, BLOCK_OPT_ENCRYPT)) { -flags |= options-value.n ? BLOCK_FLAG_ENCRYPT : 0; -} -options++; +total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512; +backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); +if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { +flags |= BLOCK_FLAG_ENCRYPT; } -ret = bdrv_create_file(filename, options, NULL, local_err); +ret = bdrv_create_file(filename, NULL, opts, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto cleanup; } qcow_bs = NULL; @@ -698,7 +692,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options, BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, local_err); if (ret 0) { error_propagate(errp, local_err); -return ret; +goto cleanup; } ret = bdrv_truncate(qcow_bs, 0); @@ -769,6 +763,8 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options, ret = 0; exit: bdrv_unref(qcow_bs); +cleanup: +g_free(backing_file); return ret; } @@ -881,24 +877,28 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } - -static QEMUOptionParameter qcow_create_options[] = { -{ -.name = BLOCK_OPT_SIZE, -.type = OPT_SIZE, -.help = Virtual disk size -}, -{ -.name = BLOCK_OPT_BACKING_FILE, -.type = OPT_STRING, -.help = File name of a base image -}, -{ -.name = BLOCK_OPT_ENCRYPT, -.type = OPT_FLAG, -.help = Encrypt the image -}, -{ NULL } +static QemuOptsList qcow_create_opts = { +.name = qcow-create-opts, +.head = QTAILQ_HEAD_INITIALIZER(qcow_create_opts.head), +.desc = { +{ +.name = BLOCK_OPT_SIZE, +.type = QEMU_OPT_SIZE, +.help = Virtual disk size +}, +{ +.name = BLOCK_OPT_BACKING_FILE, +.type = QEMU_OPT_STRING, +.help = File name of a base image +}, +{ +.name = BLOCK_OPT_ENCRYPT, +.type = QEMU_OPT_BOOL, +.help = Encrypt the image, +.def_value_str = off +}, +{ /* end of list */ } +} }; static BlockDriver bdrv_qcow = { @@ -907,8 +907,8 @@ static BlockDriver bdrv_qcow = { .bdrv_probe= qcow_probe, .bdrv_open = qcow_open, .bdrv_close= qcow_close, -.bdrv_reopen_prepare = qcow_reopen_prepare, -.bdrv_create = qcow_create, +.bdrv_reopen_prepare= qcow_reopen_prepare, +.bdrv_create2 = qcow_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_readv = qcow_co_readv, @@ -920,7 +920,7 @@ static BlockDriver bdrv_qcow = { .bdrv_write_compressed = qcow_write_compressed, .bdrv_get_info = qcow_get_info, -.create_options = qcow_create_options, +.create_opts= qcow_create_opts, }; static void bdrv_qcow_init(void) -- 1.8.4.5
Re: [Qemu-devel] [PATCH] spapr_pci: Fix maximum IRQ number check in ibm, change-msi
On 29.04.14 05:17, Alexey Kardashevskiy wrote: Recently a check for maximum supported MSIX vectors number has been added. However the check always assumed that MSIX is the only case and failed on devices which have MSI but do not have MSIX such as QEMU's PCI Bridge. This results in assert in xics_alloc_block() as req_num is zero. This adds a check for MSI vectors number too. Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- I posted recently a memory corruption fix, patch spapr_pci: Fix number of returned vectors in ibm, change-msi. However it breaks QEMU's PCI bridge so here is a patch. I would prepare a patch to replace the one in agrag/ppc-next ad01ba7 but it has Cc: qemu-sta...@nongnu.org in it so I am afraid it could make it to some other tree already (did not it?). Sorry for missing that. This is embarassing :( You're lucky - the patch didn't get out of my queue yet. I've squashed this patch into the previous, broken commit and qemu-stable will only get CC'ed on the resulting, working patch. Alex
[Qemu-devel] [PATCH V26 05/32] QemuOpts: change opt-name|str from (const char *) to (char *)
qemu_opt_del() already assumes that all QemuOpt instances contain malloc'd name and value; but it had to cast away const because opts_start_struct() was doing its own thing and using static storage instead. By using the correct type and malloced strings everywhere, the usage of this struct becomes clearer. Reviewed-by: Eric Blake ebl...@redhat.com Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option_int.h | 4 ++-- qapi/opts-visitor.c | 10 +++--- util/qemu-option.c| 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h index 8212fa4..6432c1a 100644 --- a/include/qemu/option_int.h +++ b/include/qemu/option_int.h @@ -30,8 +30,8 @@ #include qemu/error-report.h struct QemuOpt { -const char *name; -const char *str; +char *name; +char *str; const QemuOptDesc *desc; union { diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 5d830a2..7a64f4e 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -143,8 +143,8 @@ opts_start_struct(Visitor *v, void **obj, const char *kind, if (ov-opts_root-id != NULL) { ov-fake_id_opt = g_malloc0(sizeof *ov-fake_id_opt); -ov-fake_id_opt-name = id; -ov-fake_id_opt-str = ov-opts_root-id; +ov-fake_id_opt-name = g_strdup(id); +ov-fake_id_opt-str = g_strdup(ov-opts_root-id); opts_visitor_insert(ov-unprocessed_opts, ov-fake_id_opt); } } @@ -177,7 +177,11 @@ opts_end_struct(Visitor *v, Error **errp) } g_hash_table_destroy(ov-unprocessed_opts); ov-unprocessed_opts = NULL; -g_free(ov-fake_id_opt); +if (ov-fake_id_opt) { +g_free(ov-fake_id_opt-name); +g_free(ov-fake_id_opt-str); +g_free(ov-fake_id_opt); +} ov-fake_id_opt = NULL; } diff --git a/util/qemu-option.c b/util/qemu-option.c index 2be6995..69cdf3f 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -664,8 +664,8 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp) static void qemu_opt_del(QemuOpt *opt) { QTAILQ_REMOVE(opt-opts-head, opt, next); -g_free((/* !const */ char*)opt-name); -g_free((/* !const */ char*)opt-str); +g_free(opt-name); +g_free(opt-str); g_free(opt); } -- 1.8.4.5
[Qemu-devel] [PATCH V26 10/32] QemuOpts: add qemu_opts_append to replace append_option_parameters
For later merge .create_opts of drv and proto_drv in qemu-img commands. Reviewed-by: Stefan Hajnoczi stefa...@redhat.com Reviewed-by: Eric Blake ebl...@redhat.com Reviewed-by: Leandro Dorileo l...@dorileo.org Signed-off-by: Chunyan Liu cy...@suse.com --- include/qemu/option.h | 5 util/qemu-option.c| 65 +++ 2 files changed, 70 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index e98e8ef..44d9961 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -176,5 +176,10 @@ void qemu_opts_print_help(QemuOptsList *list); void qemu_opts_free(QemuOptsList *list); QEMUOptionParameter *opts_to_params(QemuOpts *opts); QemuOptsList *params_to_opts(QEMUOptionParameter *list); +/* FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts. + */ +QemuOptsList *qemu_opts_append(QemuOptsList *dst, + QemuOptsList *list, + QEMUOptionParameter *param); #endif diff --git a/util/qemu-option.c b/util/qemu-option.c index 93ffcd5..4de99b3 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1498,3 +1498,68 @@ void qemu_opts_free(QemuOptsList *list) g_free(list); } + +/* Realloc dst option list and append options either from an option list (list) + * or a QEMUOptionParameter (param) to it. dst could be NULL or a malloced list. + * FIXME: will remove QEMUOptionParameter after all drivers switch to QemuOpts. + */ +QemuOptsList *qemu_opts_append(QemuOptsList *dst, + QemuOptsList *list, + QEMUOptionParameter *param) +{ +size_t num_opts, num_dst_opts; +QemuOptsList *tmp_list = NULL; +QemuOptDesc *desc; +bool need_init = false; + +assert(!(list param)); +if (!param !list) { +return dst; +} + +if (param) { +list = tmp_list = params_to_opts(param); +} + +/* If dst is NULL, after realloc, some area of dst should be initialized + * before adding options to it. + */ +if (!dst) { +need_init = true; +} + +num_opts = count_opts_list(dst); +num_dst_opts = num_opts; +num_opts += count_opts_list(list); +dst = g_realloc(dst, sizeof(QemuOptsList) + +(num_opts + 1) * sizeof(QemuOptDesc)); +if (need_init) { +dst-name = NULL; +dst-implied_opt_name = NULL; +QTAILQ_INIT(dst-head); +dst-allocated = true; +} +dst-desc[num_dst_opts].name = NULL; + +/* (const char *) members of result dst are malloced, need free. */ +assert(dst-allocated); +/* append list-desc to dst-desc */ +if (list) { +desc = list-desc; +while (desc desc-name) { +if (find_desc_by_name(dst-desc, desc-name) == NULL) { +dst-desc[num_dst_opts].name = g_strdup(desc-name); +dst-desc[num_dst_opts].type = desc-type; +dst-desc[num_dst_opts].help = g_strdup(desc-help); +dst-desc[num_dst_opts].def_value_str = + g_strdup(desc-def_value_str); +num_dst_opts++; +dst-desc[num_dst_opts].name = NULL; +} +desc++; +} +} + +g_free(tmp_list); +return dst; +} -- 1.8.4.5