Re: [libvirt] [PATCH v3] qemu: Allow UEFI paths to be specified at compile time
On 20.01.2015 18:20, Martin Kletzander wrote: On Wed, Jan 14, 2015 at 04:28:33PM +0100, Michal Privoznik wrote: Up until now there are just two ways how to specify UEFI paths to libvirt. The first one is editing qemu.conf, the other is editing qemu_conf.c and recompile which is not that fancy. So, new configure option is introduced: --with-loader-nvram which takes a list of pairs of UEFI firmware and NVRAM store. This way, the compiled in defaults can be passed during compile time without need to change the code itself. Signed-off-by: Michal Privoznik mpriv...@redhat.com --- configure.ac | 32 + src/qemu/qemu.conf | 12 +-- src/qemu/qemu_conf.c | 41 ++ src/qemu/test_libvirtd_qemu.aug.in | 1 + .../domaincaps-qemu_1.6.50-1.xml | 1 + tests/domaincapstest.c | 15 6 files changed, 85 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 9d12079..164cfad 100644 --- a/configure.ac +++ b/configure.ac @@ -2786,6 +2786,38 @@ AC_ARG_WITH([default-editor], [DEFAULT_EDITOR=vi]) AC_DEFINE_UNQUOTED([DEFAULT_EDITOR], [$DEFAULT_EDITOR], [Default editor to use]) +AC_ARG_WITH([loader-nvram], + [AS_HELP_STRING([--with-loader-nvram], +[Pass list of pairs of loader:nvram paths. Both + pairs and list items are separated by a colon. + @:default=paths to OVMF and its clones@:@])], + [with_loader_nvram=${withval}], + [with_loader_nvram=no]) + +if test $with_loader_nvram != no; then +IFS=':' read -a loader_arr ${with_loader_nvram} + This will fail miserably on freebsd and basically everything out there that's not bash, I guess. At least for csh and dash this is an invalid line. +loader_str_c={ +nvram_str_c={ +for ((indx=0; indx${#loader_arr[@]}; indx+=2)); do Same here. It's basically not a very good idea to use shell scripts here, mainly for such operations. I wanted to check the list at build time. But okay, I can do that at runtime as well. Even thought it has a disadvantage that if passed list is malformed nobody will notice until the first start of the daemon. +loader=${loader_arr[[indx]]} +nvram=${loader_arr[[indx+1]]} + +if test -z $loader || test -z $nvram; then +AC_MSG_ERROR([Malformed loader-nvram list]) +fi + +loader_str_c=$loader_str_c \$loader\, +nvram_str_c=$nvram_str_c \$nvram\, +done + +loader_str_c=$loader_str_c } +nvram_str_c=$nvram_str_c } + +AC_DEFINE_UNQUOTED([DEFAULT_LOADER], [$loader_str_c], [Array of loader paths]) +AC_DEFINE_UNQUOTED([DEFAULT_NVRAM], [$nvram_str_c], [Array of nvram paths]) +fi + # Some GNULIB base64 symbols clash with a kerberos library AC_DEFINE_UNQUOTED([isbase64],[libvirt_gl_isbase64],[Hack to avoid symbol clash]) AC_DEFINE_UNQUOTED([base64_encode],[libvirt_gl_base64_encode],[Hack to avoid symbol clash]) diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index c6db568..1c589a2 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -506,6 +506,12 @@ # however, have different variables store. Therefore the nvram is # a list of strings when a single item is in form of: # ${PATH_TO_UEFI_FW}:${PATH_TO_UEFI_VARS}. -# Later, when libvirt creates per domain variable store, this -# list is searched for the master image. -#nvram = [ /usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd ] +# Later, when libvirt creates per domain variable store, this list is +# searched for the master image. The UEFI firmware can be called +# differently for different guest architectures. For instance, it's OVMF +# for x86_64 and i686, but it's AAVMF for aarch64. The libvirt default +# follows this scheme. +#nvram = [ +# /usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd, +# /usr/share/AAVMF/AAVMF_CODE.fd:/usr/share/AAVMF/AAVMF_VARS.fd +#] diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 9539231..728d01e 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -107,13 +107,21 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def) VIR_FREE(def); } -#define VIR_QEMU_LOADER_FILE_PATH /usr/share/OVMF/OVMF_CODE.fd -#define VIR_QEMU_NVRAM_FILE_PATH /usr/share/OVMF/OVMF_VARS.fd +#define VIR_QEMU_OVMF_LOADER_PATH /usr/share/AAVMF/AAVMF_CODE.fd +#define VIR_QEMU_OVMF_NVRAM_PATH /usr/share/AAVMF/AAVMF_VARS.fd +#define VIR_QEMU_AAVMF_LOADER_PATH /usr/share/OVMF/OVMF_CODE.fd +#define VIR_QEMU_AAVMF_NVRAM_PATH /usr/share/OVMF/OVMF_VARS.fd virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) { virQEMUDriverConfigPtr cfg; +#if defined(DEFAULT_LOADER) defined(DEFAULT_NVRAM) +const char *loader[] = DEFAULT_LOADER; +const char *nvram[] = DEFAULT_NVRAM; +size_t i; +#endif + if
Re: [libvirt] [PATCH 2/2] esx_vi: fix possible segfault
On Wed, Jan 21, 2015 at 18:09:28 +0100, Pavel Hrdina wrote: Clang found possible dereference of NULL pointer which is right. Function 'esxVI_LookupTaskInfoByTask' should find a task info. The issue is that we could return 0 and leave 'taksInfo' pointer NULL because if there is no match we simply end the search loop end set 'result' to 0. Every caller count on the fact that if the return value is 0 than it's safe to dereference 'taskInfo'. We should return 0 only in case we found something and the '*taskInfo' is not NULL. Signed-off-by: Pavel Hrdina phrd...@redhat.com --- src/esx/esx_vi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index a87f2c0..752d32a 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -3298,7 +3298,8 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, } } -result = 0; +if (*taskInfo) +result = 0; I think a more obvious fix would be to move setting of result to zero into the condition that breaks the loop. In that case, result gets set to 0 only if the entry was found. cleanup: esxVI_String_Free(propertyNameList); ACK with or without that change. I think that this wasn't discovered due to the fact that the correct entry is always in the list and is always first as we haven't seen reports for spamming the warning. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] util: Functions for getting/setting device options
On 01/19/2015 11:18 AM, akrow...@linux.vnet.ibm.com wrote: From: Tony Krowiak akrow...@linux.vnet.ibm.com This patch provides the utility functions needed to synchronize the rxfilter changes made to a guest domain with the corresponding macvtap devices on the host: * Get/set PROMISC flag * Get/set ALLMULTI, MULTICAST Signed-off-by: Tony Krowiak akrow...@linux.vnet.ibm.com --- src/libvirt_private.syms |6 + src/util/virnetdev.c | 346 ++ src/util/virnetdev.h | 14 ++ 3 files changed, 366 insertions(+), 0 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a2eec83..6b49b08 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1646,6 +1646,9 @@ virNetDevGetVirtualFunctionInfo; virNetDevGetVirtualFunctions; virNetDevGetVLanID; virNetDevIsOnline; +virNetDevIsPromiscuous; +virNetDevIsRcvAllMulti; +virNetDevIsRcvMulti; virNetDevIsVirtualFunction; virNetDevLinkDump; virNetDevReplaceMacAddress; @@ -1663,6 +1666,9 @@ virNetDevSetMTUFromDevice; virNetDevSetName; virNetDevSetNamespace; virNetDevSetOnline; +virNetDevSetPromiscuous; +virNetDevSetRcvAllMulti; +virNetDevSetRcvMulti; virNetDevSetupControl; virNetDevValidateConfig; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index ef96b2b..c610f5b 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -2337,6 +2337,333 @@ int virNetDevDelMulti(const char *ifname ATTRIBUTE_UNUSED, } #endif There's a lot of duplicated code here. Rather than completely reimplementing the contents of virNetDev(Set|Is)Online for each of these, how about making two static helper functions: int virNetDevGetIFFlag(const char *ifname, int flag, bool *val) int virNetDevSetIFFlag(const char *ifname, int flag, bool val) then the exported function for each flag would simply be, eg: int virNetDevGetPromiscuous(const char *ifname, bool *promiscuous) { return virNetDevGetIFFlag(ifname, IFF_PROMISC, promiscuous); } int virNetDevSetPromiscuous(const char *ifname, bool promiscuous) { return virNetDevSetIFFlag(ifname, IFF_PROMISC, promiscuous); } (also reimplement virNetDev(Set|Is)Online based on the helper functions) Because IFF_blah may not exist on all platforms, you'll need to provide the stub implementation of the toplevel functions, rather than stubs for virNetDev(Get|Set)IFFlag(), but it's still much less code. Oh, and I would define *all* of these SIOC[SG]IFFLAGS-using functions inside a single #if, rather than a separate one for each. Finally, although the existing function for Online uses Is as the verb in its name, I think it is more proper to use Get, so all the functions you named virNetDevIsBlah should be named virNetDevGetBlah instead (rename virNetDevIsOnline while you're at it - don't forget to change the name in the symfile). -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: change macvtap device options in response to NIC_RX_FILTER_CHANGED
(I didn't try make syntax-check, but am assuming you have and that it passes) On 01/19/2015 11:18 AM, akrow...@linux.vnet.ibm.com wrote: From: Tony Krowiak akrow...@linux.vnet.ibm.com This patch supplies the funtionality of synchronizing the host macvtap device options with the guest device's in response to the NIC_RX_FILTER_CHANGED event. supplies the functionality of sounds too busy and doesn't add anything. Instead maybe say This patch enables synchronization of the host macvtap options The following device options will be synchronized: * PROMISC * MULTICAST * ALLMULTI Signed-off-by: Tony Krowiak akrow...@linux.vnet.ibm.com --- src/qemu/qemu_driver.c | 92 1 files changed, 92 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5994558..141f91a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4168,6 +4168,93 @@ syncNicRxFilterHostMulticast(char *ifname, virNetDevRxFilterPtr guestFilter, static void +syncNicRxFilterPromiscMode(char *ifname, virNetDevRxFilterPtr guestFilter, + virNetDevRxFilterPtr hostFilter) +{ +bool promisc; +bool setpromisc = false; + +/* Set macvtap promisc mode to true if the guest has vlans defined */ +/* or synchronize the macvtap promisc mode if different from guest */ +if (guestFilter-vlan.nTable 0) { +if (!hostFilter-promiscuous) { +setpromisc = true; +promisc = true; +} +} else if (hostFilter-promiscuous != guestFilter-promiscuous) { +setpromisc = true; +promisc = guestFilter-promiscuous; +} + +if (setpromisc) { +if (virNetDevSetPromiscuous(ifname, promisc) 0) { +VIR_WARN(Couldn't set PROMISC flag to %s for device %s + while responding to NIC_RX_FILTER_CHANGED, + promisc ? true : false, ifname); +} +} +} + + +static void +syncNicRxFilterMultiMode(char *ifname, virNetDevRxFilterPtr guestFilter, + virNetDevRxFilterPtr hostFilter) +{ +if (hostFilter-multicast.mode != guestFilter-multicast.mode) { +switch (guestFilter-multicast.mode) { If you typecast the above to virNetDevRxFilterMode, then replace the default below with VIR_NETDEV_RX_FILTER_MODE_NONE, we will get a nice reminder to add a new case if a new value is ever added to the enum. +case VIR_NETDEV_RX_FILTER_MODE_ALL: +if (virNetDevSetRcvAllMulti(ifname, true)) { + +VIR_WARN(Couldn't set allmulticast flag to 'on' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} +break; + +case VIR_NETDEV_RX_FILTER_MODE_NORMAL: +if (virNetDevSetRcvMulti(ifname, true)) { + +VIR_WARN(Couldn't set multicast flag to 'on' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} + +if (virNetDevSetRcvAllMulti(ifname, false)) { +VIR_WARN(Couldn't set allmulticast flag to 'off' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} +break; + +default: I think this should use VIR_NETDEV_RX_FILTER_MODE_NONE instead of default. See above. +if (virNetDevSetRcvAllMulti(ifname, false)) { +VIR_WARN(Couldn't set allmulticast flag to 'off' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} + +if (virNetDevSetRcvMulti(ifname, false)) { +VIR_WARN(Couldn't set multicast flag to 'off' for + device %s while responding to + NIC_RX_FILTER_CHANGED, + ifname); +} +break; +} +} +} + + +static void +syncNicRxFilterDeviceOptions(char *ifname, virNetDevRxFilterPtr guestFilter, + virNetDevRxFilterPtr hostFilter) +{ +syncNicRxFilterPromiscMode(ifname, guestFilter, hostFilter); +syncNicRxFilterMultiMode(ifname, guestFilter, hostFilter); +} + + +static void syncNicRxFilterMulticast(char *ifname, virNetDevRxFilterPtr guestFilter, virNetDevRxFilterPtr hostFilter) @@ -4250,9 +4337,14 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver, * attributes to match those of the guest network device: * - MAC address * - Multicast MAC address table +
[libvirt] [PATCH v4 2/2] qemu: Add AAVMF to the list of known UEFIs
Well, even though users can pass the list of UEFI:NVRAM pairs at the configure time, we may maintain the list of widely available UEFI ourselves too. And as arm64 begin to rises, OVMF was ported there too. With a slight name change - it's called AAVMF, with AAVMF_CODE.fd being the UEFI firmware and AAVMF_VARS.fd being the NVRAM store file. Signed-off-by: Michal Privoznik mpriv...@redhat.com --- src/qemu/qemu.conf | 12 +--- src/qemu/qemu_conf.c | 18 +++--- src/qemu/test_libvirtd_qemu.aug.in | 1 + .../domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml | 1 + tests/domaincapstest.c | 1 + 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index c6db568..1c589a2 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -506,6 +506,12 @@ # however, have different variables store. Therefore the nvram is # a list of strings when a single item is in form of: # ${PATH_TO_UEFI_FW}:${PATH_TO_UEFI_VARS}. -# Later, when libvirt creates per domain variable store, this -# list is searched for the master image. -#nvram = [ /usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd ] +# Later, when libvirt creates per domain variable store, this list is +# searched for the master image. The UEFI firmware can be called +# differently for different guest architectures. For instance, it's OVMF +# for x86_64 and i686, but it's AAVMF for aarch64. The libvirt default +# follows this scheme. +#nvram = [ +# /usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd, +# /usr/share/AAVMF/AAVMF_CODE.fd:/usr/share/AAVMF/AAVMF_VARS.fd +#] diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 3e51b49..9a15208 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -150,8 +150,10 @@ virQEMUDriverConfigLoaderNVRAMParse(virQEMUDriverConfigPtr cfg, } -#define VIR_QEMU_LOADER_FILE_PATH /usr/share/OVMF/OVMF_CODE.fd -#define VIR_QEMU_NVRAM_FILE_PATH /usr/share/OVMF/OVMF_VARS.fd +#define VIR_QEMU_OVMF_LOADER_PATH /usr/share/AAVMF/AAVMF_CODE.fd +#define VIR_QEMU_OVMF_NVRAM_PATH /usr/share/AAVMF/AAVMF_VARS.fd +#define VIR_QEMU_AAVMF_LOADER_PATH /usr/share/OVMF/OVMF_CODE.fd +#define VIR_QEMU_AAVMF_NVRAM_PATH /usr/share/OVMF/OVMF_VARS.fd virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) { @@ -307,13 +309,15 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) #else -if (VIR_ALLOC_N(cfg-loader, 1) 0 || -VIR_ALLOC_N(cfg-nvram, 1) 0) +if (VIR_ALLOC_N(cfg-loader, 2) 0 || +VIR_ALLOC_N(cfg-nvram, 2) 0) goto error; -cfg-nloader = 1; +cfg-nloader = 2; -if (VIR_STRDUP(cfg-loader[0], VIR_QEMU_LOADER_FILE_PATH) 0 || -VIR_STRDUP(cfg-nvram[0], VIR_QEMU_NVRAM_FILE_PATH) 0) +if (VIR_STRDUP(cfg-loader[0], VIR_QEMU_OVMF_LOADER_PATH) 0 || +VIR_STRDUP(cfg-nvram[0], VIR_QEMU_OVMF_NVRAM_PATH) 0 || +VIR_STRDUP(cfg-loader[1], VIR_QEMU_AAVMF_LOADER_PATH) 0 || +VIR_STRDUP(cfg-nvram[1], VIR_QEMU_AAVMF_NVRAM_PATH) 0) goto error; #endif diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index 30fd27e..fc4935b 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -76,4 +76,5 @@ module Test_libvirtd_qemu = { log_timestamp = 0 } { nvram { 1 = /usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd } +{ 2 = /usr/share/AAVMF/AAVMF_CODE.fd:/usr/share/AAVMF/AAVMF_VARS.fd } } diff --git a/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml b/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml index 346ef65..37d2102 100644 --- a/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml +++ b/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml @@ -5,6 +5,7 @@ archx86_64/arch os supported='yes' loader supported='yes' + value/usr/share/AAVMF/AAVMF_CODE.fd/value value/usr/share/OVMF/OVMF_CODE.fd/value enum name='type' valuerom/value diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 5ec03a4..de417b9 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -127,6 +127,7 @@ fillQemuCaps(virDomainCapsPtr domCaps, VIR_FREE(loader-values.values[--loader-values.nvalues]); if (fillStringValues(loader-values, + /usr/share/AAVMF/AAVMF_CODE.fd, /usr/share/OVMF/OVMF_CODE.fd, NULL) 0) return -1; -- 2.0.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v4 0/2] Allow UEFI paths to be specified at compile time
diff to v3: - basically the patch is split into two patches - dropped shell script in to configure.ac Michal Privoznik (2): qemu: Allow UEFI paths to be specified at compile time qemu: Add AAVMF to the list of known UEFIs configure.ac | 12 src/qemu/qemu.conf | 12 +++- src/qemu/qemu_conf.c | 68 +++--- src/qemu/test_libvirtd_qemu.aug.in | 1 + .../domaincaps-qemu_1.6.50-1.xml | 1 + tests/domaincapstest.c | 16 ++--- 6 files changed, 93 insertions(+), 17 deletions(-) -- 2.0.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v4 1/2] qemu: Allow UEFI paths to be specified at compile time
Up until now there are just two ways how to specify UEFI paths to libvirt. The first one is editing qemu.conf, the other is editing qemu_conf.c and recompile which is not that fancy. So, new configure option is introduced: --with-loader-nvram which takes a list of pairs of UEFI firmware and NVRAM store. This way, the compiled in defaults can be passed during compile time without need to change the code itself. Signed-off-by: Michal Privoznik mpriv...@redhat.com --- configure.ac | 12 src/qemu/qemu_conf.c | 50 ++ tests/domaincapstest.c | 15 --- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index f370475..7153fa5 100644 --- a/configure.ac +++ b/configure.ac @@ -2789,6 +2789,18 @@ AC_ARG_WITH([default-editor], [DEFAULT_EDITOR=vi]) AC_DEFINE_UNQUOTED([DEFAULT_EDITOR], [$DEFAULT_EDITOR], [Default editor to use]) +AC_ARG_WITH([loader-nvram], + [AS_HELP_STRING([--with-loader-nvram], +[Pass list of pairs of loader:nvram paths. Both + pairs and list items are separated by a colon. + @:default=paths to OVMF and its clones@:@])], + [if test $withval = no; then +withval= + fi + AC_DEFINE_UNQUOTED([DEFAULT_LOADER_NVRAM], + [$withval], + [List of laoder:nvram pairs])]) + # Some GNULIB base64 symbols clash with a kerberos library AC_DEFINE_UNQUOTED([isbase64],[libvirt_gl_isbase64],[Hack to avoid symbol clash]) AC_DEFINE_UNQUOTED([base64_encode],[libvirt_gl_base64_encode],[Hack to avoid symbol clash]) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index a24c5c5..3e51b49 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -107,6 +107,49 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def) VIR_FREE(def); } + +static int ATTRIBUTE_UNUSED +virQEMUDriverConfigLoaderNVRAMParse(virQEMUDriverConfigPtr cfg, +const char *list) +{ +int ret = -1; +char **token; +size_t i; + +if (!(token = virStringSplit(list, :, 0))) +goto cleanup; + +for (i = 0; token[i]; i += 2) { +if (!token[i] || !token[i + 1] || +STREQ(token[i], ) || STREQ(token[i + 1], )) { +virReportError(VIR_ERR_INTERNAL_ERROR, + _(Invalid --with-loader-nvram list: %s), + list); +goto cleanup; +} +} + +if (i) { +if (VIR_ALLOC_N(cfg-loader, (i + 1) / 2) 0 || +VIR_ALLOC_N(cfg-nvram, (i + 1) / 2) 0) +goto cleanup; +cfg-nloader = (i + 1) / 2; + +while (i) { +if (VIR_STRDUP(cfg-loader[(i - 1) / 2 ], token[i - 2]) 0 || +VIR_STRDUP(cfg-nvram[(i - 1) / 2], token[i - 1]) 0) +goto cleanup; +i -= 2; +} +} + +ret = 0; + cleanup: +virStringFreeList(token); +return ret; +} + + #define VIR_QEMU_LOADER_FILE_PATH /usr/share/OVMF/OVMF_CODE.fd #define VIR_QEMU_NVRAM_FILE_PATH /usr/share/OVMF/OVMF_VARS.fd @@ -258,6 +301,12 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) cfg-logTimestamp = true; +#ifdef DEFAULT_LOADER_NVRAM +if (virQEMUDriverConfigLoaderNVRAMParse(cfg, DEFAULT_LOADER_NVRAM) 0) +goto error; + +#else + if (VIR_ALLOC_N(cfg-loader, 1) 0 || VIR_ALLOC_N(cfg-nvram, 1) 0) goto error; @@ -266,6 +315,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) if (VIR_STRDUP(cfg-loader[0], VIR_QEMU_LOADER_FILE_PATH) 0 || VIR_STRDUP(cfg-nvram[0], VIR_QEMU_NVRAM_FILE_PATH) 0) goto error; +#endif return cfg; diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 70d2ef3..5ec03a4 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -105,6 +105,7 @@ fillQemuCaps(virDomainCapsPtr domCaps, struct fillQemuCapsData *data = (struct fillQemuCapsData *) opaque; virQEMUCapsPtr qemuCaps = data-qemuCaps; virQEMUDriverConfigPtr cfg = data-cfg; +virDomainCapsLoaderPtr loader = domCaps-os.loader; if (virQEMUCapsFillDomainCaps(domCaps, qemuCaps, cfg-loader, cfg-nloader) 0) @@ -122,14 +123,14 @@ fillQemuCaps(virDomainCapsPtr domCaps, /* Moreover, as of f05b6a918e28 we are expecting to see * OVMF_CODE.fd file which may not exists everywhere. */ -if (!domCaps-os.loader.values.nvalues) { -virDomainCapsLoaderPtr loader = domCaps-os.loader; +while (loader-values.nvalues) +VIR_FREE(loader-values.values[--loader-values.nvalues]); + +if (fillStringValues(loader-values, + /usr/share/OVMF/OVMF_CODE.fd, + NULL) 0) +return -1; -if (fillStringValues(loader-values, - /usr/share/OVMF/OVMF_CODE.fd, -
[libvirt] [PATCH 5/5] qemu: reorder PCI slot assignment functions
In previous commit a chunk of code got moved in to a separate static function qemuValidateDevicePCISlotsChipsets. This function then invokes chipset specific functions which are defined as static as well. For these reasons it is necessary to either have a forward declaration or slightly reorder definitions. --- src/qemu/qemu_command.c | 255 1 file changed, 128 insertions(+), 127 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index dbcc854..280a18a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1458,133 +1458,6 @@ qemuDomainPCIBusFullyReserved(virDomainPCIAddressBusPtr bus) return true; } -int -qemuDomainAssignPCIAddresses(virDomainDefPtr def, - virQEMUCapsPtr qemuCaps, - virDomainObjPtr obj) -{ -int ret = -1; -virDomainPCIAddressSetPtr addrs = NULL; -qemuDomainObjPrivatePtr priv = NULL; - -if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { -int max_idx = -1; -int nbuses = 0; -size_t i; -int rv; -int resflags = 0; -bool buses_reserved = false; - -virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPE_PCI; - -for (i = 0; i def-ncontrollers; i++) { -if (def-controllers[i]-type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) { -if ((int) def-controllers[i]-idx max_idx) -max_idx = def-controllers[i]-idx; -} -} - -nbuses = max_idx + 1; - -if (nbuses 0 -virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PCI_BRIDGE)) { -virDomainDeviceInfo info; - -/* 1st pass to figure out how many PCI bridges we need */ -if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, true))) -goto cleanup; - -if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) 0) -goto cleanup; - -for (i = 0; i nbuses; i++) { -if (qemuDomainPCIBusFullyReserved(addrs-buses[i])) -resflags |= 1 i; -} -buses_reserved = (resflags ~((~0) nbuses)); - -if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) 0) -goto cleanup; - -/* Reserve 1 extra slot for a (potential) bridge only if buses - * are not fully reserved yet - */ -if (!buses_reserved -virDomainPCIAddressReserveNextSlot(addrs, info, flags) 0) -goto cleanup; - -for (i = 1; i addrs-nbuses; i++) { -virDomainPCIAddressBusPtr bus = addrs-buses[i]; - -if ((rv = virDomainDefMaybeAddController( - def, VIR_DOMAIN_CONTROLLER_TYPE_PCI, - i, bus-model)) 0) -goto cleanup; -/* If we added a new bridge, we will need one more address */ -if (rv 0 -virDomainPCIAddressReserveNextSlot(addrs, info, flags) 0) -goto cleanup; -} -nbuses = addrs-nbuses; -virDomainPCIAddressSetFree(addrs); -addrs = NULL; - -} else if (max_idx 0) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s, - _(PCI bridges are not supported - by this QEMU binary)); -goto cleanup; -} - -if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, false))) -goto cleanup; - -if (qemuDomainSupportsPCI(def)) { -if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) 0) -goto cleanup; -if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) 0) -goto cleanup; -} - -for (i = 0; i def-ncontrollers; i++) { -/* check if every PCI bridge controller's ID is greater than - * the bus it is placed onto - */ -virDomainControllerDefPtr cont = def-controllers[i]; -int idx = cont-idx; -int bus = cont-info.addr.pci.bus; -if (cont-type == VIR_DOMAIN_CONTROLLER_TYPE_PCI -cont-model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE -idx = bus) { -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _(failed to create PCI bridge - on bus %d: bus is fully reserved), - bus); -goto cleanup; -} -} -} - -if (obj obj-privateData) { -priv = obj-privateData; -if (addrs) { -/* if this is the live domain object, we persist the PCI addresses*/ -virDomainPCIAddressSetFree(priv-pciaddrs); -priv-persistentAddrs = 1; -priv-pciaddrs = addrs; -addrs =
[libvirt] [PATCH 4/5] qemu: move PCI slot assignment for PIIX3, Q35 into a separate function
In order to be able to test for fully reserved PCI buses, assignment of PCI slots for integrated devices needs to be moved to a separate function. This also might be a good preparation if we decide to add support for other chipsets as well. --- src/qemu/qemu_command.c | 45 ++--- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 99b06ee..dbcc854 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1494,6 +1494,9 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, true))) goto cleanup; +if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) 0) +goto cleanup; + for (i = 0; i nbuses; i++) { if (qemuDomainPCIBusFullyReserved(addrs-buses[i])) resflags |= 1 i; @@ -1537,6 +1540,8 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, goto cleanup; if (qemuDomainSupportsPCI(def)) { +if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) 0) +goto cleanup; if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) 0) goto cleanup; } @@ -1996,6 +2001,27 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, return ret; } +static int +qemuValidateDevicePCISlotsChipsets(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps, + virDomainPCIAddressSetPtr addrs) +{ +if ((STRPREFIX(def-os.machine, pc-0.) || +STRPREFIX(def-os.machine, pc-1.) || +STRPREFIX(def-os.machine, pc-i440) || +STREQ(def-os.machine, pc) || +STRPREFIX(def-os.machine, rhel)) +qemuValidateDevicePCISlotsPIIX3(def, qemuCaps, addrs) 0) { +return -1; +} + +if (qemuDomainMachineIsQ35(def) +qemuDomainValidateDevicePCISlotsQ35(def, qemuCaps, addrs) 0) { +return -1; +} + +return 0; +} /* * This assigns static PCI slots to all configured devices. @@ -2014,6 +2040,9 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, * - PIIX3 ISA bridge, IDE controller, something else unknown, USB controller (slot 1) * - Video (slot 2) * + * - These integrated devices were already added by + *qemuValidateDevicePCISlotsChipsets invoked right before this function + * * Incrementally assign slots from 3 onwards: * * - Net @@ -2031,27 +2060,13 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr def, */ int qemuAssignDevicePCISlots(virDomainDefPtr def, - virQEMUCapsPtr qemuCaps, + virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED, virDomainPCIAddressSetPtr addrs) { size_t i, j; virDomainPCIConnectFlags flags; virDevicePCIAddress tmp_addr; -if ((STRPREFIX(def-os.machine, pc-0.) || -STRPREFIX(def-os.machine, pc-1.) || -STRPREFIX(def-os.machine, pc-i440) || -STREQ(def-os.machine, pc) || -STRPREFIX(def-os.machine, rhel)) -qemuValidateDevicePCISlotsPIIX3(def, qemuCaps, addrs) 0) { -goto error; -} - -if (qemuDomainMachineIsQ35(def) -qemuDomainValidateDevicePCISlotsQ35(def, qemuCaps, addrs) 0) { -goto error; -} - /* PCI controllers */ for (i = 0; i def-ncontrollers; i++) { if (def-controllers[i]-type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) { -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/2] xenapi_driver: fix copy-paste typo
Clang found that we are passing variable with wrong enum type to 'xenapiCrashExitEnum2virDomainLifecycle' function. This is probably copy-paste typo as the correct variable exists in the code, but it isn't used. Signed-off-by: Pavel Hrdina phrd...@redhat.com --- src/xenapi/xenapi_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index c5118ec..cef53ec 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1504,7 +1504,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) defPtr-onReboot = xenapiNormalExitEnum2virDomainLifecycle(action); enum xen_on_crash_behaviour crash; if (xen_vm_get_actions_after_crash(session, crash, vm)) -defPtr-onCrash = xenapiCrashExitEnum2virDomainLifecycle(action); +defPtr-onCrash = xenapiCrashExitEnum2virDomainLifecycle(crash); xen_vm_get_platform(session, result, vm); if (result != NULL) { size_t i; -- 2.0.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] esx_vi: fix possible segfault
Clang found possible dereference of NULL pointer which is right. Function 'esxVI_LookupTaskInfoByTask' should find a task info. The issue is that we could return 0 and leave 'taksInfo' pointer NULL because if there is no match we simply end the search loop end set 'result' to 0. Every caller count on the fact that if the return value is 0 than it's safe to dereference 'taskInfo'. We should return 0 only in case we found something and the '*taskInfo' is not NULL. Signed-off-by: Pavel Hrdina phrd...@redhat.com --- src/esx/esx_vi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index a87f2c0..752d32a 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -3298,7 +3298,8 @@ esxVI_LookupTaskInfoByTask(esxVI_Context *ctx, } } -result = 0; +if (*taskInfo) +result = 0; cleanup: esxVI_String_Free(propertyNameList); -- 2.0.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] xenapi_driver: fix copy-paste typo
On Wed, Jan 21, 2015 at 18:09:27 +0100, Pavel Hrdina wrote: Clang found that we are passing variable with wrong enum type to 'xenapiCrashExitEnum2virDomainLifecycle' function. This is probably copy-paste typo as the correct variable exists in the code, but it isn't used. Signed-off-by: Pavel Hrdina phrd...@redhat.com --- src/xenapi/xenapi_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) ACK, safe for release. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 0/5] Revert and fix PCI bridge auto-add to extend default bus
Erik Skultety (5): qemu: Remove dead code in qemuDomainAssignPCIAddresses revert patch conf: virDomainDefMaybeAddController tweak return code qemu: Fix auto-adding PCI bridge when all slots are reserved qemu: move PCI slot assignment for PIIX3, Q35 into a separate function qemu: reorder PCI slot assignment functions src/conf/domain_conf.c | 2 +- src/qemu/qemu_command.c | 264 2 files changed, 154 insertions(+), 112 deletions(-) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/5] conf: virDomainDefMaybeAddController tweak return code
Previously the function returned either -1 in case of an error or 0 on success. However, we should also distinguish between a case we successfully added a controller and a case there wasn't a need to add any controller --- src/conf/domain_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8792f5e..9ff3819 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12416,7 +12416,7 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return -1; } -return 0; +return 1; } -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/5] qemu: Remove dead code in qemuDomainAssignPCIAddresses revert patch
As it turned out, fix of dead code 419a22 changed the affected condition from never true to always true, so better fix would be to change the return code of virDomainMaybeAddController from 0 to 1 if a new bridge has been added, thus distinguishing case when we didn't need to add any controller and case we successfully added one. The return code is changed in the next commit --- src/qemu/qemu_command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c041ee7..cdf02a6 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1510,7 +1510,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, i, bus-model)) 0) goto cleanup; /* If we added a new bridge, we will need one more address */ -if (rv == 0 +if (rv 0 virDomainPCIAddressReserveNextSlot(addrs, info, flags) 0) goto cleanup; } -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 3/5] qemu: Fix auto-adding PCI bridge when all slots are reserved
Commit 93c8ca tried to fix the issue with auto-adding of a PCI bridge controller, it worked well when the slots were reserved by devices with user defined addresses without any other devices with unspecified PCI addresses present in the XML. However, if another device with unspecified PCI addresses appeared in the domain's XML, the same problem occurred as the BZ below references. This patch fixes the issue by not creating any additional bridges when not necessary. Now let's say all the buses corresponding to the number of PCI controllers present in the domain's XML got fully reserved by devices with user defined addresses. If there are no other devices present in the XML, no need to create both an additional PCI bus and a bridge controller. If however there are still some PCI devices waiting to get a slot assigned by qemuAssignDevicePCISlots, this means an additional bus needs to be created along with a corresponding bridge controller. This scenario now results in an reasonable error instead of generating wrong qemu command line. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1132900 --- src/qemu/qemu_command.c | 42 ++ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index cdf02a6..99b06ee 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1472,6 +1472,9 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, int nbuses = 0; size_t i; int rv; +int resflags = 0; +bool buses_reserved = false; + virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPE_PCI; for (i = 0; i def-ncontrollers; i++) { @@ -1490,17 +1493,22 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, /* 1st pass to figure out how many PCI bridges we need */ if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, true))) goto cleanup; + +for (i = 0; i nbuses; i++) { +if (qemuDomainPCIBusFullyReserved(addrs-buses[i])) +resflags |= 1 i; +} +buses_reserved = (resflags ~((~0) nbuses)); + if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) 0) goto cleanup; -for (i = 0; i addrs-nbuses; i++) { -if (!qemuDomainPCIBusFullyReserved(addrs-buses[i])) { - -/* Reserve 1 extra slot for a (potential) bridge */ -if (virDomainPCIAddressReserveNextSlot(addrs, info, flags) 0) -goto cleanup; -} -} +/* Reserve 1 extra slot for a (potential) bridge only if buses + * are not fully reserved yet + */ +if (!buses_reserved +virDomainPCIAddressReserveNextSlot(addrs, info, flags) 0) +goto cleanup; for (i = 1; i addrs-nbuses; i++) { virDomainPCIAddressBusPtr bus = addrs-buses[i]; @@ -1532,6 +1540,24 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, if (qemuAssignDevicePCISlots(def, qemuCaps, addrs) 0) goto cleanup; } + +for (i = 0; i def-ncontrollers; i++) { +/* check if every PCI bridge controller's ID is greater than + * the bus it is placed onto + */ +virDomainControllerDefPtr cont = def-controllers[i]; +int idx = cont-idx; +int bus = cont-info.addr.pci.bus; +if (cont-type == VIR_DOMAIN_CONTROLLER_TYPE_PCI +cont-model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE +idx = bus) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(failed to create PCI bridge + on bus %d: bus is fully reserved), + bus); +goto cleanup; +} +} } if (obj obj-privateData) { -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 0/2] fix two issues found by clang
Pavel Hrdina (2): xenapi_driver: fix copy-paste typo esx_vi: fix possible segfault src/esx/esx_vi.c | 3 ++- src/xenapi/xenapi_driver.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) -- 2.0.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: change macvtap device options in response to NIC_RX_FILTER_CHANGED
On 01/21/2015 01:44 PM, Laine Stump wrote: (I didn't try make syntax-check, but am assuming you have and that it passes) On 01/19/2015 11:18 AM, akrow...@linux.vnet.ibm.com wrote: From: Tony Krowiak akrow...@linux.vnet.ibm.com This patch supplies the funtionality of synchronizing the host macvtap device options with the guest device's in response to the NIC_RX_FILTER_CHANGED event. supplies the functionality of sounds too busy and doesn't add anything. Instead maybe say This patch enables synchronization of the host macvtap options Okie dokie. The following device options will be synchronized: * PROMISC * MULTICAST * ALLMULTI Signed-off-by: Tony Krowiak akrow...@linux.vnet.ibm.com --- src/qemu/qemu_driver.c | 92 1 files changed, 92 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5994558..141f91a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4168,6 +4168,93 @@ syncNicRxFilterHostMulticast(char *ifname, virNetDevRxFilterPtr guestFilter, static void +syncNicRxFilterPromiscMode(char *ifname, virNetDevRxFilterPtr guestFilter, + virNetDevRxFilterPtr hostFilter) +{ +bool promisc; +bool setpromisc = false; + +/* Set macvtap promisc mode to true if the guest has vlans defined */ +/* or synchronize the macvtap promisc mode if different from guest */ +if (guestFilter-vlan.nTable 0) { +if (!hostFilter-promiscuous) { +setpromisc = true; +promisc = true; +} +} else if (hostFilter-promiscuous != guestFilter-promiscuous) { +setpromisc = true; +promisc = guestFilter-promiscuous; +} + +if (setpromisc) { +if (virNetDevSetPromiscuous(ifname, promisc) 0) { +VIR_WARN(Couldn't set PROMISC flag to %s for device %s + while responding to NIC_RX_FILTER_CHANGED, + promisc ? true : false, ifname); +} +} +} + + +static void +syncNicRxFilterMultiMode(char *ifname, virNetDevRxFilterPtr guestFilter, + virNetDevRxFilterPtr hostFilter) +{ +if (hostFilter-multicast.mode != guestFilter-multicast.mode) { +switch (guestFilter-multicast.mode) { If you typecast the above to virNetDevRxFilterMode, then replace the default below with VIR_NETDEV_RX_FILTER_MODE_NONE, we will get a nice reminder to add a new case if a new value is ever added to the enum. Okay, will do. +case VIR_NETDEV_RX_FILTER_MODE_ALL: +if (virNetDevSetRcvAllMulti(ifname, true)) { + +VIR_WARN(Couldn't set allmulticast flag to 'on' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} +break; + +case VIR_NETDEV_RX_FILTER_MODE_NORMAL: +if (virNetDevSetRcvMulti(ifname, true)) { + +VIR_WARN(Couldn't set multicast flag to 'on' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} + +if (virNetDevSetRcvAllMulti(ifname, false)) { +VIR_WARN(Couldn't set allmulticast flag to 'off' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} +break; + +default: I think this should use VIR_NETDEV_RX_FILTER_MODE_NONE instead of default. See above. +if (virNetDevSetRcvAllMulti(ifname, false)) { +VIR_WARN(Couldn't set allmulticast flag to 'off' for + device %s while responding to + NIC_RX_FILTER_CHANGED, ifname); +} + +if (virNetDevSetRcvMulti(ifname, false)) { +VIR_WARN(Couldn't set multicast flag to 'off' for + device %s while responding to + NIC_RX_FILTER_CHANGED, + ifname); +} +break; +} +} +} + + +static void +syncNicRxFilterDeviceOptions(char *ifname, virNetDevRxFilterPtr guestFilter, + virNetDevRxFilterPtr hostFilter) +{ +syncNicRxFilterPromiscMode(ifname, guestFilter, hostFilter); +syncNicRxFilterMultiMode(ifname, guestFilter, hostFilter); +} + + +static void syncNicRxFilterMulticast(char *ifname, virNetDevRxFilterPtr guestFilter, virNetDevRxFilterPtr hostFilter) @@ -4250,9 +4337,14 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver, * attributes to match those of the guest network device: * - MAC address * - Multicast MAC address table + * - Device
Re: [libvirt] [PATCH 1/2] util: Functions for getting/setting device options
On 01/21/2015 01:34 PM, Laine Stump wrote: On 01/19/2015 11:18 AM, akrow...@linux.vnet.ibm.com wrote: From: Tony Krowiak akrow...@linux.vnet.ibm.com This patch provides the utility functions needed to synchronize the rxfilter changes made to a guest domain with the corresponding macvtap devices on the host: * Get/set PROMISC flag * Get/set ALLMULTI, MULTICAST Signed-off-by: Tony Krowiak akrow...@linux.vnet.ibm.com --- src/libvirt_private.syms |6 + src/util/virnetdev.c | 346 ++ src/util/virnetdev.h | 14 ++ 3 files changed, 366 insertions(+), 0 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a2eec83..6b49b08 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1646,6 +1646,9 @@ virNetDevGetVirtualFunctionInfo; virNetDevGetVirtualFunctions; virNetDevGetVLanID; virNetDevIsOnline; +virNetDevIsPromiscuous; +virNetDevIsRcvAllMulti; +virNetDevIsRcvMulti; virNetDevIsVirtualFunction; virNetDevLinkDump; virNetDevReplaceMacAddress; @@ -1663,6 +1666,9 @@ virNetDevSetMTUFromDevice; virNetDevSetName; virNetDevSetNamespace; virNetDevSetOnline; +virNetDevSetPromiscuous; +virNetDevSetRcvAllMulti; +virNetDevSetRcvMulti; virNetDevSetupControl; virNetDevValidateConfig; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index ef96b2b..c610f5b 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -2337,6 +2337,333 @@ int virNetDevDelMulti(const char *ifname ATTRIBUTE_UNUSED, } #endif There's a lot of duplicated code here. Rather than completely reimplementing the contents of virNetDev(Set|Is)Online for each of these, how about making two static helper functions: int virNetDevGetIFFlag(const char *ifname, int flag, bool *val) int virNetDevSetIFFlag(const char *ifname, int flag, bool val) then the exported function for each flag would simply be, eg: int virNetDevGetPromiscuous(const char *ifname, bool *promiscuous) { return virNetDevGetIFFlag(ifname, IFF_PROMISC, promiscuous); } int virNetDevSetPromiscuous(const char *ifname, bool promiscuous) { return virNetDevSetIFFlag(ifname, IFF_PROMISC, promiscuous); } (also reimplement virNetDev(Set|Is)Online based on the helper functions) Because IFF_blah may not exist on all platforms, you'll need to provide the stub implementation of the toplevel functions, rather than stubs for virNetDev(Get|Set)IFFlag(), but it's still much less code. Oh, and I would define *all* of these SIOC[SG]IFFLAGS-using functions inside a single #if, rather than a separate one for each. Finally, although the existing function for Online uses Is as the verb in its name, I think it is more proper to use Get, so all the functions you named virNetDevIsBlah should be named virNetDevGetBlah instead (rename virNetDevIsOnline while you're at it - don't forget to change the name in the symfile). Sounds like a plan. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: add a check when cold-plug a Chr device
On 12/09/2014 01:48 AM, Luyao Huang wrote: Add a func just check the base target type which qemu support. But i still doubt this will be useful , we already have a check when we try to start the vm. And this check only check the target type, and the other things will be done in virDomainChrDefParseXML. Signed-off-by: Luyao Huang lhu...@redhat.com --- src/qemu/qemu_hotplug.c | 64 + 1 file changed, 64 insertions(+) I forgot to add that this didn't build without: --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -145,6 +145,8 @@ virDomainBlockedReasonTypeFromString; virDomainBlockedReasonTypeToString; virDomainCapabilitiesPolicyTypeToString; virDomainCapsFeatureTypeToString; +virDomainChrChannelTargetTypeFromString; +virDomainChrChannelTargetTypeToString; virDomainChrConsoleTargetTypeFromString; virDomainChrConsoleTargetTypeToString; virDomainChrDefForeach; Since it seems you'll be resending your patches, I'll wait for your patches before proceeding... John diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b9a0cee..fe91ec7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1384,10 +1384,74 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver, } +static int +qemuDomainChrCheckDefSupport(virDomainChrDefPtr chr) +{ +int ret = -1; + +switch (chr-deviceType) { +case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: +switch ((virDomainChrSerialTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: +ret = 0; +break; + +default: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported serial target type %s for qemu), + NULLSTR(virDomainChrSerialTargetTypeToString(chr-targetType))); +break; +} +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL: +ret = 0; +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL: +switch ((virDomainChrChannelTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO: +ret = 0; +break; + +default: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported channel target type %s for qemu), + NULLSTR(virDomainChrChannelTargetTypeToString(chr-targetType))); +break; +} +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: +switch ((virDomainChrConsoleTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLP: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLPLM: +ret = 0; +break; + +default: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported console target type %s for qemu), + NULLSTR(virDomainChrConsoleTargetTypeToString(chr-targetType))); +break; +} +break; +} + +return ret; +} + int qemuDomainChrInsert(virDomainDefPtr vmdef, virDomainChrDefPtr chr) { +if (qemuDomainChrCheckDefSupport(chr) 0) +return -1; + if (chr-deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE chr-targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/3] Grant access to helpers
On Tuesday, January 20, 2015 09:08:04 AM Cedric Bosdonnat wrote: On Mon, 2015-01-19 at 18:25 -0700, Mike Latimer wrote: Apparmor must not prevent access to required helper programs. The following helpers should be allowed to run in unconfined execution mode: - libvirt_parthelper - libvirt_iohelper --- examples/apparmor/usr.sbin.libvirtd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/apparmor/usr.sbin.libvirtd b/examples/apparmor/usr.sbin.libvirtd index 9917836..ab6572a 100644 --- a/examples/apparmor/usr.sbin.libvirtd +++ b/examples/apparmor/usr.sbin.libvirtd @@ -57,6 +57,8 @@ audit deny /sys/kernel/security/apparmor/.* rwxl, /sys/kernel/security/apparmor/profiles r, /usr/{lib,lib64}/libvirt/* PUxr, + /usr/{lib,lib64}/libvirt/libvirt_parthelper Ux, + /usr/{lib,lib64}/libvirt/libvirt_iohelper Ux, /etc/libvirt/hooks/** rmix, /etc/xen/scripts/** rmix, Can't we find a way to have them run with inherited profile (ix)? Letting them run completely unprofiled may not be the best solution. Seems like the apparmor profile for libvirtd is pretty wide open, so I'm not sure if there will be much of a difference between those two settings. I'm also not sure how best to test the functionality of those helpers to find out... I don't mind if the patch is committed with ix. We can always change it later if we find a definitive reason to use Ux. ;) Thanks, Mike -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: add a check when cold-plug a Chr device
On 01/22/2015 07:16 AM, John Ferlan wrote: On 12/09/2014 01:48 AM, Luyao Huang wrote: Add a func just check the base target type which qemu support. But i still doubt this will be useful , we already have a check when we try to start the vm. And this check only check the target type, and the other things will be done in virDomainChrDefParseXML. Signed-off-by: Luyao Huang lhu...@redhat.com --- src/qemu/qemu_hotplug.c | 64 + 1 file changed, 64 insertions(+) I forgot to add that this didn't build without: --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -145,6 +145,8 @@ virDomainBlockedReasonTypeFromString; virDomainBlockedReasonTypeToString; virDomainCapabilitiesPolicyTypeToString; virDomainCapsFeatureTypeToString; +virDomainChrChannelTargetTypeFromString; +virDomainChrChannelTargetTypeToString; virDomainChrConsoleTargetTypeFromString; virDomainChrConsoleTargetTypeToString; virDomainChrDefForeach; Since it seems you'll be resending your patches, I'll wait for your patches before proceeding1... Thanks a lot for pointing out, I will add these code in next version. John diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b9a0cee..fe91ec7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1384,10 +1384,74 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver, } +static int +qemuDomainChrCheckDefSupport(virDomainChrDefPtr chr) +{ +int ret = -1; + +switch (chr-deviceType) { +case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: +switch ((virDomainChrSerialTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: +ret = 0; +break; + +default: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported serial target type %s for qemu), + NULLSTR(virDomainChrSerialTargetTypeToString(chr-targetType))); +break; +} +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL: +ret = 0; +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL: +switch ((virDomainChrChannelTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO: +ret = 0; +break; + +default: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported channel target type %s for qemu), + NULLSTR(virDomainChrChannelTargetTypeToString(chr-targetType))); +break; +} +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: +switch ((virDomainChrConsoleTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLP: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLPLM: +ret = 0; +break; + +default: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported console target type %s for qemu), + NULLSTR(virDomainChrConsoleTargetTypeToString(chr-targetType))); +break; +} +break; +} + +return ret; +} + int qemuDomainChrInsert(virDomainDefPtr vmdef, virDomainChrDefPtr chr) { +if (qemuDomainChrCheckDefSupport(chr) 0) +return -1; + if (chr-deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE chr-targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, Luyao -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] 右键列表订阅
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v3 1/2] qemu: output error when try to hotplug unsupport console
https://bugzilla.redhat.com/show_bug.cgi?id=1164627 When using 'virsh attach-device' to hotplug an unsupported console type into a qemu guest, the attachment will erroneously allows the attachment. This patch will check to ensure that only the support target types are used for a running guest. NB, Although a guest can be defined with an improper target, startup will cause failure. Signed-off-by: Luyao Huang lhu...@redhat.com --- src/qemu/qemu_command.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c041ee7..df87e1e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10067,13 +10067,17 @@ qemuBuildConsoleChrDeviceStr(char **deviceStr, break; case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL: +break; case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE: case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN: case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML: case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC: case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ: case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST: -break; +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported console target type %s), + NULLSTR(virDomainChrConsoleTargetTypeToString(chr-targetType))); +goto cleanup; } ret = 0; -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v3 2/2] qemu: add a target type check when hot/cold-plug a Chr device
https://bugzilla.redhat.com/show_bug.cgi?id=1164627 Add a func just check the base target type which qemu support. And this check will help to avoid add a qemu unsupport target type chr device to a running guest(hotplug) or to the guest inactive XML (coldplug, will effect next boot) And this check only check the target type, and other things have been checked in virDomainChrDefParseXML. Signed-off-by: Luyao Huang lhu...@redhat.com --- src/libvirt_private.syms | 2 ++ src/qemu/qemu_hotplug.c | 67 2 files changed, 69 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a2eec83..7fb722d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -145,6 +145,8 @@ virDomainBlockedReasonTypeFromString; virDomainBlockedReasonTypeToString; virDomainCapabilitiesPolicyTypeToString; virDomainCapsFeatureTypeToString; +virDomainChrChannelTargetTypeFromString; +virDomainChrChannelTargetTypeToString; virDomainChrConsoleTargetTypeFromString; virDomainChrConsoleTargetTypeToString; virDomainChrDefForeach; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 9ed96dc..2e02d05 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1401,10 +1401,77 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver, } +static int +qemuDomainChrCheckDefSupport(virDomainChrDefPtr chr) +{ +switch (chr-deviceType) { +case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: +switch ((virDomainChrSerialTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: +break; + +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported serial target type %s for qemu), + NULLSTR(virDomainChrSerialTargetTypeToString(chr-targetType))); +return -1; +break; +} +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL: +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL: +switch ((virDomainChrChannelTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO: +break; + +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE: +case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported channel target type %s for qemu), + NULLSTR(virDomainChrChannelTargetTypeToString(chr-targetType))); +return -1; +break; +} +break; + +case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: +switch ((virDomainChrConsoleTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLP: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SCLPLM: +break; + +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ: +case VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST: +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unsupported console target type %s for qemu), + NULLSTR(virDomainChrConsoleTargetTypeToString(chr-targetType))); +return -1; +break; +} +break; +} + +return 0; +} + int qemuDomainChrInsert(virDomainDefPtr vmdef, virDomainChrDefPtr chr) { +if (qemuDomainChrCheckDefSupport(chr) 0) +return -1; + if (chr-deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE chr-targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 2/2] qemu: add a target type check when hot/cold-plug a Chr device
On Thu, Jan 22, 2015 at 10:28:19 +0800, Luyao Huang wrote: https://bugzilla.redhat.com/show_bug.cgi?id=1164627 Add a func just check the base target type which qemu support. And this check will help to avoid add a qemu unsupport target type chr device to a running guest(hotplug) or to the guest inactive XML (coldplug, will effect next boot) You can get exactly the same behavior adding the device by specifying a new XML containing the device (via virsh edit for example). Unfortunately the unsupported devices can't be checked in the post parse callback as it would make existing VMs with broken config disappear. Additionally even if you forbid known-bad targets you still even with this code can get a failure by adding a SCLP console on a x86 machine: console type='pty' target type='sclp' port='0'/ /console Starting such VM gets you: error: unsupported configuration: sclp console requires QEMU to support s390-sclp This kind of failure depends on the actual qemu process running the VM and can be checked only when the VM is starting. And this check only check the target type, and other things have been checked in virDomainChrDefParseXML. Signed-off-by: Luyao Huang lhu...@redhat.com --- src/libvirt_private.syms | 2 ++ src/qemu/qemu_hotplug.c | 67 2 files changed, 69 insertions(+) Said this. I don't think it's worth adding the check to the coldplug path. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 8/8] Removing probing of secondary drivers
On 21.01.2015 11:15, Daniel P. Berrange wrote: On Wed, Jan 21, 2015 at 11:08:54AM +0100, Michal Privoznik wrote: On 20.01.2015 17:37, Daniel P. Berrange wrote: For stateless, client side drivers, it is never correct to probe for secondary drivers. It is only ever appropriate to use the secondary driver that is associated with the hypervisor in question. As a result the ESX HyperV drivers have both been forced to do hacks where they register no-op drivers for the ones they don't implement. For stateful, server side drivers, we always just want to use the same built-in shared driver. The exception is virtualbox which is really a stateless driver and so wants to use its own server side secondary drivers. To deal with this virtualbox has to be built as 3 separate loadable modules to allow registration to work in the right order. This can all be simplified by introducing a new struct recording the precise set of secondary drivers each hypervisor driver wants struct _virConnectDriver { virHypervisorDriverPtr hypervisorDriver; virInterfaceDriverPtr interfaceDriver; virNetworkDriverPtr networkDriver; virNodeDeviceDriverPtr nodeDeviceDriver; virNWFilterDriverPtr nwfilterDriver; virSecretDriverPtr secretDriver; virStorageDriverPtr storageDriver; }; Instead of registering the hypervisor driver, we now just register a virConnectDriver instead. This allows us to remove all probing of secondary drivers. Once we have chosen the primary driver, we immediately know the correct secondary drivers to use. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- daemon/libvirtd.c | 19 +- src/Makefile.am | 63 +-- src/bhyve/bhyve_driver.c| 14 +- src/check-driverimpls.pl| 3 +- src/datatypes.c | 12 -- src/driver-hypervisor.h | 3 - src/driver-interface.h | 9 - src/driver-network.h| 11 +- src/driver-nodedev.h| 8 +- src/driver-nwfilter.h | 13 +- src/driver-secret.h | 12 +- src/driver-storage.h| 12 +- src/driver.h| 54 +++--- src/esx/esx_device_monitor.c| 74 src/esx/esx_device_monitor.h| 28 --- src/esx/esx_driver.c| 25 +-- src/esx/esx_interface_driver.c | 37 +--- src/esx/esx_interface_driver.h | 4 +- src/esx/esx_network_driver.c| 37 +--- src/esx/esx_network_driver.h| 4 +- src/esx/esx_nwfilter_driver.c | 74 src/esx/esx_nwfilter_driver.h | 28 --- src/esx/esx_secret_driver.c | 72 --- src/esx/esx_secret_driver.h | 27 --- src/esx/esx_storage_driver.c| 37 +--- src/esx/esx_storage_driver.h| 4 +- src/hyperv/hyperv_device_monitor.c | 71 --- src/hyperv/hyperv_device_monitor.h | 28 --- src/hyperv/hyperv_driver.c | 25 +-- src/hyperv/hyperv_interface_driver.c| 71 --- src/hyperv/hyperv_interface_driver.h| 28 --- src/hyperv/hyperv_network_driver.c | 71 --- src/hyperv/hyperv_network_driver.h | 28 --- src/hyperv/hyperv_nwfilter_driver.c | 71 --- src/hyperv/hyperv_nwfilter_driver.h | 28 --- src/hyperv/hyperv_secret_driver.c | 71 --- src/hyperv/hyperv_secret_driver.h | 28 --- src/hyperv/hyperv_storage_driver.c | 71 --- src/hyperv/hyperv_storage_driver.h | 28 --- src/interface/interface_backend_netcf.c | 26 +-- src/interface/interface_backend_udev.c | 25 +-- src/libvirt.c | 323 ++-- src/libvirt_private.syms| 14 +- src/libxl/libxl_driver.c| 10 +- src/lxc/lxc_driver.c| 10 +- src/network/bridge_driver.c | 25 +-- src/node_device/node_device_driver.c| 10 +- src/node_device/node_device_hal.c | 26 +-- src/node_device/node_device_udev.c | 23 +-- src/nwfilter/nwfilter_driver.c | 25 +-- src/openvz/openvz_driver.c | 12 +- src/phyp/phyp_driver.c | 64 +-- src/qemu/qemu_driver.c | 10 +- src/remote/remote_driver.c | 152 ++- src/secret/secret_driver.c | 25 +-- src/storage/storage_driver.c| 25 +-- src/test/test_driver.c | 156 ++- src/uml/uml_driver.c| 10 +- src/vbox/vbox_common.c | 1 - src/vbox/vbox_driver.c | 47 ++--- src/vbox/vbox_network.c | 32 src/vbox/vbox_storage.c | 30 --- src/vmware/vmware_driver.c | 12 +-
Re: [libvirt] [PATCH 8/8] Removing probing of secondary drivers
On 20.01.2015 17:37, Daniel P. Berrange wrote: For stateless, client side drivers, it is never correct to probe for secondary drivers. It is only ever appropriate to use the secondary driver that is associated with the hypervisor in question. As a result the ESX HyperV drivers have both been forced to do hacks where they register no-op drivers for the ones they don't implement. For stateful, server side drivers, we always just want to use the same built-in shared driver. The exception is virtualbox which is really a stateless driver and so wants to use its own server side secondary drivers. To deal with this virtualbox has to be built as 3 separate loadable modules to allow registration to work in the right order. This can all be simplified by introducing a new struct recording the precise set of secondary drivers each hypervisor driver wants struct _virConnectDriver { virHypervisorDriverPtr hypervisorDriver; virInterfaceDriverPtr interfaceDriver; virNetworkDriverPtr networkDriver; virNodeDeviceDriverPtr nodeDeviceDriver; virNWFilterDriverPtr nwfilterDriver; virSecretDriverPtr secretDriver; virStorageDriverPtr storageDriver; }; Instead of registering the hypervisor driver, we now just register a virConnectDriver instead. This allows us to remove all probing of secondary drivers. Once we have chosen the primary driver, we immediately know the correct secondary drivers to use. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- daemon/libvirtd.c | 19 +- src/Makefile.am | 63 +-- src/bhyve/bhyve_driver.c| 14 +- src/check-driverimpls.pl| 3 +- src/datatypes.c | 12 -- src/driver-hypervisor.h | 3 - src/driver-interface.h | 9 - src/driver-network.h| 11 +- src/driver-nodedev.h| 8 +- src/driver-nwfilter.h | 13 +- src/driver-secret.h | 12 +- src/driver-storage.h| 12 +- src/driver.h| 54 +++--- src/esx/esx_device_monitor.c| 74 src/esx/esx_device_monitor.h| 28 --- src/esx/esx_driver.c| 25 +-- src/esx/esx_interface_driver.c | 37 +--- src/esx/esx_interface_driver.h | 4 +- src/esx/esx_network_driver.c| 37 +--- src/esx/esx_network_driver.h| 4 +- src/esx/esx_nwfilter_driver.c | 74 src/esx/esx_nwfilter_driver.h | 28 --- src/esx/esx_secret_driver.c | 72 --- src/esx/esx_secret_driver.h | 27 --- src/esx/esx_storage_driver.c| 37 +--- src/esx/esx_storage_driver.h| 4 +- src/hyperv/hyperv_device_monitor.c | 71 --- src/hyperv/hyperv_device_monitor.h | 28 --- src/hyperv/hyperv_driver.c | 25 +-- src/hyperv/hyperv_interface_driver.c| 71 --- src/hyperv/hyperv_interface_driver.h| 28 --- src/hyperv/hyperv_network_driver.c | 71 --- src/hyperv/hyperv_network_driver.h | 28 --- src/hyperv/hyperv_nwfilter_driver.c | 71 --- src/hyperv/hyperv_nwfilter_driver.h | 28 --- src/hyperv/hyperv_secret_driver.c | 71 --- src/hyperv/hyperv_secret_driver.h | 28 --- src/hyperv/hyperv_storage_driver.c | 71 --- src/hyperv/hyperv_storage_driver.h | 28 --- src/interface/interface_backend_netcf.c | 26 +-- src/interface/interface_backend_udev.c | 25 +-- src/libvirt.c | 323 ++-- src/libvirt_private.syms| 14 +- src/libxl/libxl_driver.c| 10 +- src/lxc/lxc_driver.c| 10 +- src/network/bridge_driver.c | 25 +-- src/node_device/node_device_driver.c| 10 +- src/node_device/node_device_hal.c | 26 +-- src/node_device/node_device_udev.c | 23 +-- src/nwfilter/nwfilter_driver.c | 25 +-- src/openvz/openvz_driver.c | 12 +- src/phyp/phyp_driver.c | 64 +-- src/qemu/qemu_driver.c | 10 +- src/remote/remote_driver.c | 152 ++- src/secret/secret_driver.c | 25 +-- src/storage/storage_driver.c| 25 +-- src/test/test_driver.c | 156 ++- src/uml/uml_driver.c| 10 +- src/vbox/vbox_common.c | 1 - src/vbox/vbox_driver.c | 47 ++--- src/vbox/vbox_network.c | 32 src/vbox/vbox_storage.c | 30 --- src/vmware/vmware_driver.c | 12 +- src/xen/xen_driver.c| 11 +- src/xenapi/xenapi_driver.c | 10 +-
Re: [libvirt] [PATCH 0/8] Refactoring driver registration
On 20.01.2015 17:37, Daniel P. Berrange wrote: This series continues on my previous work to refactor the driver registration process. With this patch series applied, there is no probing of secondary drivers any more. Once the hypervisor driver is chosen, the correct secondary drivers are immediately known. This enables a bunch of hacks to be removed from the ESX, HyperV and VirtualBox drivers. The final remaining problem will be to address the circular dependancy problems wrt to the secrets and storage drivers. Daniel P. Berrange (8): Remove use of secretPrivateData from secret driver Remove use of nwfilterPrivateData from nwfilter driver Remove use of storagePrivateData/networkPrivateData from vbox Remove use of nodeDevicePrivateData from nodeDev driver Remove use of interfacePrivateData from udev driver Remove all secondary driver private data fields don't disable state driver when libvirtd is not built Removing probing of secondary drivers daemon/libvirtd.c | 19 +- src/Makefile.am | 69 +-- src/bhyve/bhyve_driver.c| 14 +- src/check-driverimpls.pl| 3 +- src/conf/domain_nwfilter.c | 5 +- src/conf/domain_nwfilter.h | 6 +- src/datatypes.c | 12 -- src/datatypes.h | 6 - src/driver-hypervisor.h | 3 - src/driver-interface.h | 9 - src/driver-network.h| 11 +- src/driver-nodedev.h| 8 +- src/driver-nwfilter.h | 13 +- src/driver-secret.h | 12 +- src/driver-storage.h| 12 +- src/driver.h| 60 +++--- src/esx/esx_device_monitor.c| 74 src/esx/esx_device_monitor.h| 28 --- src/esx/esx_driver.c| 25 +-- src/esx/esx_interface_driver.c | 37 +--- src/esx/esx_interface_driver.h | 4 +- src/esx/esx_network_driver.c| 37 +--- src/esx/esx_network_driver.h| 4 +- src/esx/esx_nwfilter_driver.c | 74 src/esx/esx_nwfilter_driver.h | 28 --- src/esx/esx_secret_driver.c | 72 --- src/esx/esx_secret_driver.h | 27 --- src/esx/esx_storage_driver.c| 37 +--- src/esx/esx_storage_driver.h| 4 +- src/hyperv/hyperv_device_monitor.c | 71 --- src/hyperv/hyperv_device_monitor.h | 28 --- src/hyperv/hyperv_driver.c | 25 +-- src/hyperv/hyperv_interface_driver.c| 71 --- src/hyperv/hyperv_interface_driver.h| 28 --- src/hyperv/hyperv_network_driver.c | 71 --- src/hyperv/hyperv_network_driver.h | 28 --- src/hyperv/hyperv_nwfilter_driver.c | 71 --- src/hyperv/hyperv_nwfilter_driver.h | 28 --- src/hyperv/hyperv_secret_driver.c | 71 --- src/hyperv/hyperv_secret_driver.h | 28 --- src/hyperv/hyperv_storage_driver.c | 71 --- src/hyperv/hyperv_storage_driver.h | 28 --- src/interface/interface_backend_netcf.c | 26 +-- src/interface/interface_backend_udev.c | 120 ++-- src/libvirt.c | 327 ++-- src/libvirt_daemon.syms | 15 -- src/libvirt_internal.h | 2 - src/libvirt_private.syms| 19 +- src/libxl/libxl_driver.c| 10 +- src/lxc/lxc_driver.c| 13 +- src/lxc/lxc_process.c | 8 +- src/lxc/lxc_process.h | 3 +- src/network/bridge_driver.c | 25 +-- src/node_device/node_device_driver.c| 78 +++- src/node_device/node_device_driver.h| 6 +- src/node_device/node_device_hal.c | 106 --- src/node_device/node_device_udev.c | 78 +++- src/nwfilter/nwfilter_driver.c | 132 + src/openvz/openvz_driver.c | 12 +- src/phyp/phyp_driver.c | 64 +-- src/qemu/qemu_command.c | 8 +- src/qemu/qemu_command.h | 1 - src/qemu/qemu_driver.c | 12 +- src/qemu/qemu_hotplug.c | 12 +- src/qemu/qemu_hotplug.h | 1 - src/qemu/qemu_process.c | 10 +- src/remote/remote_driver.c | 158 ++- src/secret/secret_driver.c | 215 + src/storage/storage_driver.c| 25 +-- src/test/test_driver.c | 156 ++- src/uml/uml_conf.c | 9 +- src/uml/uml_driver.c| 10 +- src/vbox/vbox_common.c | 1 - src/vbox/vbox_driver.c | 47 ++--- src/vbox/vbox_network.c
Re: [libvirt] [PATCH 8/8] Removing probing of secondary drivers
On Wed, Jan 21, 2015 at 11:08:54AM +0100, Michal Privoznik wrote: On 20.01.2015 17:37, Daniel P. Berrange wrote: For stateless, client side drivers, it is never correct to probe for secondary drivers. It is only ever appropriate to use the secondary driver that is associated with the hypervisor in question. As a result the ESX HyperV drivers have both been forced to do hacks where they register no-op drivers for the ones they don't implement. For stateful, server side drivers, we always just want to use the same built-in shared driver. The exception is virtualbox which is really a stateless driver and so wants to use its own server side secondary drivers. To deal with this virtualbox has to be built as 3 separate loadable modules to allow registration to work in the right order. This can all be simplified by introducing a new struct recording the precise set of secondary drivers each hypervisor driver wants struct _virConnectDriver { virHypervisorDriverPtr hypervisorDriver; virInterfaceDriverPtr interfaceDriver; virNetworkDriverPtr networkDriver; virNodeDeviceDriverPtr nodeDeviceDriver; virNWFilterDriverPtr nwfilterDriver; virSecretDriverPtr secretDriver; virStorageDriverPtr storageDriver; }; Instead of registering the hypervisor driver, we now just register a virConnectDriver instead. This allows us to remove all probing of secondary drivers. Once we have chosen the primary driver, we immediately know the correct secondary drivers to use. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- daemon/libvirtd.c | 19 +- src/Makefile.am | 63 +-- src/bhyve/bhyve_driver.c| 14 +- src/check-driverimpls.pl| 3 +- src/datatypes.c | 12 -- src/driver-hypervisor.h | 3 - src/driver-interface.h | 9 - src/driver-network.h| 11 +- src/driver-nodedev.h| 8 +- src/driver-nwfilter.h | 13 +- src/driver-secret.h | 12 +- src/driver-storage.h| 12 +- src/driver.h| 54 +++--- src/esx/esx_device_monitor.c| 74 src/esx/esx_device_monitor.h| 28 --- src/esx/esx_driver.c| 25 +-- src/esx/esx_interface_driver.c | 37 +--- src/esx/esx_interface_driver.h | 4 +- src/esx/esx_network_driver.c| 37 +--- src/esx/esx_network_driver.h| 4 +- src/esx/esx_nwfilter_driver.c | 74 src/esx/esx_nwfilter_driver.h | 28 --- src/esx/esx_secret_driver.c | 72 --- src/esx/esx_secret_driver.h | 27 --- src/esx/esx_storage_driver.c| 37 +--- src/esx/esx_storage_driver.h| 4 +- src/hyperv/hyperv_device_monitor.c | 71 --- src/hyperv/hyperv_device_monitor.h | 28 --- src/hyperv/hyperv_driver.c | 25 +-- src/hyperv/hyperv_interface_driver.c| 71 --- src/hyperv/hyperv_interface_driver.h| 28 --- src/hyperv/hyperv_network_driver.c | 71 --- src/hyperv/hyperv_network_driver.h | 28 --- src/hyperv/hyperv_nwfilter_driver.c | 71 --- src/hyperv/hyperv_nwfilter_driver.h | 28 --- src/hyperv/hyperv_secret_driver.c | 71 --- src/hyperv/hyperv_secret_driver.h | 28 --- src/hyperv/hyperv_storage_driver.c | 71 --- src/hyperv/hyperv_storage_driver.h | 28 --- src/interface/interface_backend_netcf.c | 26 +-- src/interface/interface_backend_udev.c | 25 +-- src/libvirt.c | 323 ++-- src/libvirt_private.syms| 14 +- src/libxl/libxl_driver.c| 10 +- src/lxc/lxc_driver.c| 10 +- src/network/bridge_driver.c | 25 +-- src/node_device/node_device_driver.c| 10 +- src/node_device/node_device_hal.c | 26 +-- src/node_device/node_device_udev.c | 23 +-- src/nwfilter/nwfilter_driver.c | 25 +-- src/openvz/openvz_driver.c | 12 +- src/phyp/phyp_driver.c | 64 +-- src/qemu/qemu_driver.c | 10 +- src/remote/remote_driver.c | 152 ++- src/secret/secret_driver.c | 25 +-- src/storage/storage_driver.c| 25 +-- src/test/test_driver.c | 156 ++- src/uml/uml_driver.c| 10 +- src/vbox/vbox_common.c | 1 - src/vbox/vbox_driver.c | 47 ++--- src/vbox/vbox_network.c | 32 src/vbox/vbox_storage.c | 30
Re: [libvirt] [PATCH 2/2] qemu: add a check when cold-plug a Chr device
On 01/21/2015 04:10 AM, lhuang wrote: On 01/21/2015 03:00 AM, John Ferlan wrote: On 12/09/2014 01:48 AM, Luyao Huang wrote: Add a func just check the base target type which qemu support. But i still doubt this will be useful , we already have a check when we try to start the vm. And this check only check the target type, and the other things will be done in virDomainChrDefParseXML. The commit message needs some massaging. Essentially, this patch fixes the condition where if a guest has been started and someone uses attach-device with (or without) the --config option, then these checks will avoid the next guest being modified, correct? Right This will also cause an error earlier that patch 1/2 as qemuDomainChrInsert is called in the path before qemuDomainAttachDeviceLive Yes and if this patch have been pushed then the patch 1/2 will be a patch for improving exist code. ChrInsert is called after qemuBuildConsoleChrDeviceStr in AttachDevice. We should error out earlier and include the first patch too. Signed-off-by: Luyao Huang lhu...@redhat.com --- src/qemu/qemu_hotplug.c | 64 + 1 file changed, 64 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b9a0cee..fe91ec7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1384,10 +1384,74 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver, } +static int +qemuDomainChrCheckDefSupport(virDomainChrDefPtr chr) +{ +int ret = -1; + +switch (chr-deviceType) { +case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: +switch ((virDomainChrSerialTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: +ret = 0; +break; + +default: Typically in switches listing other options rather than default: The point of casting it to virDomainChrSerialTargetType is to catch all the unhandled values and it only works if there's no default: clause. Also I don't think we need the ret variable at all. Just return 0 at the end of the function, or -1 if we reached an unsupported combination. I think perhaps this one is better than 1/2, but will see if my responses result in other opinions... Even if this one fixes the bug, 1/2 is nice to have. Thanks for pointing out and i forgot cc Jan and Pavel when sent this patch, maybe they have some other opinions. No need to cc me, I am subscribed to the list. :) Jan signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 12/12] qemu_driver: detect threads corresponding to Vcpus
After hotplugging the CPUs, we need to re-detect threads corresponding to Vcpus. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 271 src/qemu/qemu_driver.h | 8 ++ src/qemu/qemu_hotplug.c | 7 ++ 3 files changed, 152 insertions(+), 134 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 004bc35..09ac088 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4357,89 +4357,49 @@ static void qemuProcessEventHandler(void *data, void *opaque) VIR_FREE(processEvent); } -static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, - virDomainObjPtr vm, - unsigned int nvcpus) +/* After hotplugging the CPUs we need to re-detect threads corresponding + * * to the virtual CPUs. Some older versions don't provide the thread ID + * * or don't have the info cpus command (and they don't support multiple + ** CPUs anyways), so errors in the re-detection will not be treated + * * fatal */ +int +qemuDomainDetectVcpu(virQEMUDriverPtr driver, + virDomainObjPtr vm, + int apic_id, + bool plug) { qemuDomainObjPrivatePtr priv = vm-privateData; -size_t i; -int rc = 1; -int ret = -1; int oldvcpus = vm-def-vcpus; int vcpus = oldvcpus; pid_t *cpupids = NULL; int ncpupids; +int ret = -1; virCgroupPtr cgroup_vcpu = NULL; char *mem_mask = NULL; -uint32_t apic_id; - -qemuDomainObjEnterMonitor(driver, vm); - -/* We need different branches here, because we want to offline - * in reverse order to onlining, so any partial fail leaves us in a - * reasonably sensible state */ -if (nvcpus vcpus) { -for (i = vcpus; i nvcpus; i++) { -/* Online new CPU */ -apic_id = virDomainCPUGetFreeApicID(vm-def); -rc = qemuMonitorSetCPU(priv-mon, apic_id, true); -if (rc == 0) -goto unsupported; -if (rc 0) -goto exit_monitor; - -vcpus++; -ignore_value(virBitmapSetBit(vm-def-apic_id_map, apic_id)); -} -} else { -for (i = vcpus - 1; i = nvcpus; i--) { -/* Offline old CPU */ -rc = qemuMonitorSetCPU(priv-mon, i, false); -if (rc == 0) -goto unsupported; -if (rc 0) -goto exit_monitor; - -vcpus--; -} -} - -/* hotplug succeeded */ +int idx = 0; +size_t i; +int *thread = NULL; ret = 0; +if (plug) +vcpus++; +else +vcpus--; + +qemuDomainObjEnterMonitor(driver, vm); -/* After hotplugging the CPUs we need to re-detect threads corresponding - * to the virtual CPUs. Some older versions don't provide the thread ID - * or don't have the info cpus command (and they don't support multiple - * CPUs anyways), so errors in the re-detection will not be treated - * fatal */ -if ((ncpupids = qemuMonitorGetCPUInfo(priv-mon, cpupids)) = 0) { +if ((ncpupids = qemuMonitorGetCPUInfo(priv-mon, cpupids)) = 0){ virResetLastError(); -goto exit_monitor; -} -if (qemuDomainObjExitMonitor(driver, vm) 0) { -ret = -1; goto cleanup; } -/* check if hotplug has failed */ -if (vcpus oldvcpus ncpupids == oldvcpus) { -virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, - _(qemu didn't unplug the vCPUs properly)); -vcpus = oldvcpus; -ret = -1; -goto cleanup; +for (i = 0; i apic_id; i++) { +if (virBitmapIsSet(vm-def-apic_id_map, i)) +idx++; } -if (ncpupids != vcpus) { -virReportError(VIR_ERR_INTERNAL_ERROR, - _(got wrong number of vCPU pids from QEMU monitor. - got %d, wanted %d), - ncpupids, vcpus); -vcpus = oldvcpus; -ret = -1; +if (VIR_ALLOC_N(thread, vcpus) 0) goto cleanup; -} if (virDomainNumatuneGetMode(vm-def-numatune, -1) == VIR_DOMAIN_NUMATUNE_MEM_STRICT @@ -4448,105 +4408,148 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, mem_mask, -1) 0) goto cleanup; -if (nvcpus oldvcpus) { -for (i = oldvcpus; i nvcpus; i++) { -if (priv-cgroup) { -int rv = -1; -/* Create cgroup for the onlined vcpu */ -if (virCgroupNewVcpu(priv-cgroup, i, true, cgroup_vcpu) 0) -goto cleanup; - -if (mem_mask -virCgroupSetCpusetMems(cgroup_vcpu, mem_mask) 0) -goto cleanup; +if (vcpus oldvcpus) { +if (priv-cgroup) { +int rv = -1; +
[libvirt] [RFC PATCH 10/12] qemu: implement cpu device hotunplug on live level
This patch implements live hotunplug of a cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 2 ++ src/qemu/qemu_hotplug.c | 66 + src/qemu/qemu_hotplug.h | 4 +++ 3 files changed, 72 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ddc7eeb..004bc35 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7077,6 +7077,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret = qemuDomainDetachChrDevice(driver, vm, dev-data.chr); break; case VIR_DOMAIN_DEVICE_CPU: +ret = qemuDomainDetachCPUDevice(driver, vm, dev-data.cpu); +break; case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index bff0d14..41013d9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2876,6 +2876,20 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, static int +qemuDomainRemoveCPUDevice(virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ +VIR_DEBUG(Removing cpu device %s from domain %p %s, + cpu-info.alias, vm, vm-def-name); + +virDomainCPURemove(vm-def, cpu); +virDomainCPUDefFree(cpu); + +return 0; +} + + +static int qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr) @@ -2941,6 +2955,9 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, break; case VIR_DOMAIN_DEVICE_CPU: +qemuDomainRemoveCPUDevice(vm, dev-data.cpu); +break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: @@ -3841,3 +3858,52 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, VIR_FREE(devstr); return ret; } + +int qemuDomainDetachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ +int ret = -1; +qemuDomainObjPrivatePtr priv = vm-privateData; +virDomainDefPtr vmdef = vm-def; +virDomainCPUDefPtr tmpCPU; +int rc = 0; + +if (!(tmpCPU = virDomainCPUFind(vmdef, cpu))) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(device not present in domain configration)); +return ret; +} + +if (!virQEMUCapsGet(priv-qemuCaps, QEMU_CAPS_DEVICE)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(qemu does not support -device)); +} + +if (!tmpCPU-info.alias) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(detaching cpu device without id is not supported)); +return ret; +} + +qemuDomainMarkDeviceForRemoval(vm, tmpCPU-info); + +qemuDomainObjEnterMonitor(driver, vm); +if (qemuMonitorDelDevice(priv-mon, tmpCPU-info.alias) 0) { +qemuDomainObjExitMonitor(driver, vm); +goto cleanup; +} +qemuDomainObjExitMonitor(driver, vm); + +ignore_value(virBitmapClearBit(vm-def-apic_id_map, tmpCPU-apic_id)); + +rc = qemuDomainWaitForDeviceRemoval(vm); +if (rc == 0 || rc == 1) +ret = qemuDomainRemoveCPUDevice(vm, tmpCPU); +else +goto cleanup; + + cleanup: +qemuDomainResetDeviceRemoval(vm); +return ret; +} diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 6cdead3..5ec7b23 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -113,6 +113,10 @@ qemuDomainAttachCPUDevice(virQEMUDriverPtr driver, int qemuDomainCPUInsert(virDomainDefPtr vmdef, virDomainCPUDefPtr cpu); +int +qemuDomainDetachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu); int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 11/12] qemu_monitor_json: sort JSON array of cpu info
JSON array of cpu info is sorted in order to find thread id of cpu smoothly. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/libvirt_private.syms | 1 + src/qemu/qemu_monitor_json.c | 31 +-- src/util/virbitmap.c | 2 +- src/util/virbitmap.h | 2 ++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 032e9a9..d2c7c73 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1042,6 +1042,7 @@ virBitmapFree; virBitmapGetBit; virBitmapIsAllClear; virBitmapIsAllSet; +virBitmapIsSet; virBitmapLastSetBit; virBitmapNew; virBitmapNewCopy; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index da5c14d..96a964c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1162,6 +1162,21 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon) return ret; } +static int +qemuCPUInfoCompare(const void *a, + const void *b) +{ +virJSONValuePtr *entrya = (virJSONValuePtr *)a; +virJSONValuePtr *entryb = (virJSONValuePtr *)b; +int ia; +int ib; + +virJSONValueObjectGetNumberInt(*entrya, CPU, ia); +virJSONValueObjectGetNumberInt(*entryb, CPU, ib); + +return ia - ib; +} + /* * [ { CPU: 0, current: true, halted: false, pc: 3227107138 }, @@ -1176,6 +1191,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr reply, size_t i; int *threads = NULL; int ncpus; +virJSONValuePtr *entryarray = NULL; if (!(data = virJSONValueObjectGet(reply, return))) { virReportError(VIR_ERR_INTERNAL_ERROR, %s, @@ -1198,16 +1214,26 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr reply, if (VIR_ALLOC_N(threads, ncpus) 0) goto cleanup; +if (VIR_ALLOC_N(entryarray, ncpus) 0) +goto cleanup; + for (i = 0; i ncpus; i++) { virJSONValuePtr entry = virJSONValueArrayGet(data, i); -int thread; if (!entry) { virReportError(VIR_ERR_INTERNAL_ERROR, %s, _(cpu information was missing an array element)); goto cleanup; } -if (virJSONValueObjectGetNumberInt(entry, thread_id, thread) 0) { +entryarray[i] = entry; +} + +qsort(entryarray, ncpus, sizeof(entryarray[0]), qemuCPUInfoCompare); + +for (i = 0; i ncpus; i++) { +int thread; +if (virJSONValueObjectGetNumberInt(entryarray[i], thread_id, thread) 0) { + /* Some older qemu versions don't report the thread_id, * so treat this as non-fatal, simply returning no data */ ret = 0; @@ -1223,6 +1249,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr reply, cleanup: VIR_FREE(threads); +VIR_FREE(entryarray); return ret; } diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 05c50e4..168b8db 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -153,7 +153,7 @@ int virBitmapClearBit(virBitmapPtr bitmap, size_t b) } /* Helper function. caller must ensure b bitmap-max_bit */ -static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b) +bool virBitmapIsSet(virBitmapPtr bitmap, size_t b) { return !!(bitmap-map[VIR_BITMAP_UNIT_OFFSET(b)] VIR_BITMAP_BIT(b)); } diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 565264c..57fb195 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -60,6 +60,8 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) int virBitmapClearBit(virBitmapPtr bitmap, size_t b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +bool virBitmapIsSet(virBitmapPtr bitmap, size_t b); + /* * Get setting of bit position @b in @bitmap and store in @result */ -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 04/12] domain_conf: introduce cpu device hotplug helpers
virDomainCPUFind - to find a cpu within VM def virDomainCPUInsert - wrapper for inserting a new cpu device into VM def virDomainCPURemove - wrapper for removing cpu from VM def Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 59 src/conf/domain_conf.h | 13 +++ src/libvirt_private.syms | 3 +++ 3 files changed, 75 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1f05056..45f954f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12142,6 +12142,65 @@ virDomainChrRemove(virDomainDefPtr vmdef, return ret; } +int +virDomainCPUInsert(virDomainDefPtr vmdef, + virDomainCPUDefPtr cpu) +{ +return VIR_APPEND_ELEMENT(vmdef-cpus, vmdef-ncpus, cpu); +} + +bool +virDomainCPUEquals(virDomainCPUDefPtr src, + virDomainCPUDefPtr tgt) +{ +bool ret = false; + +if (!src || !tgt) +return src == tgt; + +if (src-apic_id == tgt-apic_id) +ret = true; + +return ret; +} + +virDomainCPUDefPtr +virDomainCPUFind(virDomainDefPtr def, + virDomainCPUDefPtr target) +{ +virDomainCPUDefPtr cpu; +size_t i; + +for (i = 0; i def-ncpus; i++) { +cpu = def-cpus[i]; +if (virDomainCPUEquals(cpu, target)) +return cpu; +} + +return NULL; +} + +virDomainCPUDefPtr +virDomainCPURemove(virDomainDefPtr vmdef, + virDomainCPUDefPtr cpu) +{ +virDomainCPUDefPtr ret; +size_t i; + +for (i = 0; i vmdef-ncpus; i++) { +ret = vmdef-cpus[i]; + +if (virDomainCPUEquals(ret, cpu)) +break; +} + +if (i == vmdef-ncpus) +return NULL; + +VIR_DELETE_ELEMENT(vmdef-cpus, i, vmdef-ncpus); +return ret; +} + char * virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 618eef3..4b71052 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2674,6 +2674,19 @@ virDomainChrDefPtr virDomainChrRemove(virDomainDefPtr vmdef, virDomainChrDefPtr chr); +int +virDomainCPUInsert(virDomainDefPtr vmdef, + virDomainCPUDefPtr cpu); +bool +virDomainCPUEquals(virDomainCPUDefPtr src, + virDomainCPUDefPtr tgt); +virDomainCPUDefPtr +virDomainCPUFind(virDomainDefPtr def, + virDomainCPUDefPtr cpu); +virDomainCPUDefPtr +virDomainCPURemove(virDomainDefPtr vmdef, + virDomainCPUDefPtr cpu); + int virDomainSaveXML(const char *configDir, virDomainDefPtr def, const char *xml); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9ceff71..032e9a9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -167,6 +167,9 @@ virDomainChrTcpProtocolTypeToString; virDomainChrTypeFromString; virDomainChrTypeToString; virDomainCPUDefFree; +virDomainCPUInsert; +virDomainCPUFind; +virDomainCPURemove; virDomainClockBasisTypeToString; virDomainClockOffsetTypeFromString; virDomainClockOffsetTypeToString; -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 09/12] qemu: implement cpu device hotplug on live level
This patch implements live hotplug of a cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 6 ++ src/qemu/qemu_hotplug.c | 55 + src/qemu/qemu_hotplug.h | 7 +++ 3 files changed, 68 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a88f6b4..ddc7eeb 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6995,6 +6995,12 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, break; case VIR_DOMAIN_DEVICE_CPU: +ret = qemuDomainAttachCPUDevice(driver, vm, +dev-data.cpu); +if (!ret) +dev-data.cpu = NULL; +break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f6d7667..bff0d14 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1541,6 +1541,61 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, return ret; } +int +qemuDomainCPUInsert(virDomainDefPtr vmdef, +virDomainCPUDefPtr cpu) +{ +if (virDomainCPUFind(vmdef, cpu)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(cpu already exists)); +return -1; +} + +if (virDomainCPUInsert(vmdef, cpu) 0) +return -1; + +return 0; +} + +int qemuDomainAttachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ +int ret = -1; +char *devstr = NULL; +qemuDomainObjPrivatePtr priv = vm-privateData; +virDomainDefPtr vmdef = vm-def; + +if (!virQEMUCapsGet(priv-qemuCaps, QEMU_CAPS_DEVICE)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(qemu does not support -device)); +goto cleanup;; +} + +if (qemuAssignDeviceCPUAlias(vmdef, cpu, -1) 0) +goto cleanup; + +if (qemuBuildCPUDeviceStr(devstr, cpu, priv-qemuCaps) 0) +goto cleanup; + +if (qemuDomainCPUInsert(vmdef, cpu) 0) +goto cleanup; + +qemuDomainObjEnterMonitor(driver, vm); +if (devstr qemuMonitorAddDevice(priv-mon, devstr) 0) { +qemuDomainObjExitMonitor(driver, vm); +goto cleanup; +} +qemuDomainObjExitMonitor(driver, vm); + +ignore_value(virBitmapSetBit(vm-def-apic_id_map, cpu-apic_id)); +ret = 0; + + cleanup: +VIR_FREE(devstr); +return ret; +} + static int qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 19ab9a0..6cdead3 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -106,6 +106,13 @@ qemuDomainChrInsert(virDomainDefPtr vmdef, virDomainChrDefPtr qemuDomainChrRemove(virDomainDefPtr vmdef, virDomainChrDefPtr chr); +int +qemuDomainAttachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu); +int +qemuDomainCPUInsert(virDomainDefPtr vmdef, +virDomainCPUDefPtr cpu); int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 05/12] qemu_driver: implement cpu device hotplug on config level
The config level requires an insert or remove from domain definition structure. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ecdf5c6..a88f6b4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7316,6 +7316,11 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps, break; case VIR_DOMAIN_DEVICE_CPU: +if (virDomainCPUInsert(vmdef, dev-data.cpu) 0) +return -1; +dev-data.cpu = NULL; +break; + case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_VIDEO: @@ -7352,6 +7357,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, virDomainControllerDefPtr cont, det_cont; virDomainChrDefPtr chr; virDomainFSDefPtr fs; +virDomainCPUDefPtr cpu; int idx; switch ((virDomainDeviceType) dev-type) { @@ -7433,6 +7439,14 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, break; case VIR_DOMAIN_DEVICE_CPU: +if (!(cpu = virDomainCPURemove(vmdef, dev-data.cpu))) +return -1; + +virDomainCPUDefFree(cpu); +virDomainCPUDefFree(dev-data.cpu); +dev-data.cpu = NULL; +break; + case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_VIDEO: -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 06/12] qemu_command: introduce a func for cpu device alias assignment
This function used to set a alias name for cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_command.c | 32 src/qemu/qemu_command.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c041ee7..69d0a2a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -946,6 +946,34 @@ qemuAssignDeviceChrAlias(virDomainDefPtr def, } int +qemuAssignDeviceCPUAlias(virDomainDefPtr def, + virDomainCPUDefPtr cpu, + int idx) +{ +if (idx == -1) { +size_t i; +idx = 0; + +for (i = 0; i def-ncpus; i++) { +int thisidx; +if ((thisidx = qemuDomainDeviceAliasIndex(def-cpus[i]-info, cpu)) 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, %s, + _(unable to determine device index from CPU device)); +return -1; +} + +if (thisidx = idx) +idx = thisidx + 1; +} +} + +if (virAsprintf(cpu-info.alias, cpu%d, idx) 0) +return -1; + +return 0; +} + +int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { size_t i; @@ -1015,6 +1043,10 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) if (qemuAssignDeviceChrAlias(def, def-consoles[i], i) 0) return -1; } +for (i = 0; i def-ncpus; i++) { +if (qemuAssignDeviceCPUAlias(def, def-cpus[i], i) 0) +return -1; +} for (i = 0; i def-nhubs; i++) { if (virAsprintf(def-hubs[i]-info.alias, hub%zu, i) 0) return -1; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index dcc7127..2898876 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -264,6 +264,9 @@ int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr r int qemuAssignDeviceChrAlias(virDomainDefPtr def, virDomainChrDefPtr chr, ssize_t idx); +int qemuAssignDeviceCPUAlias(virDomainDefPtr def, + virDomainCPUDefPtr cpu, + int idx); int qemuParseKeywords(const char *str, -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 03/11] domain_conf: add support for memory device configuration in XML
This patch adds configuration support for the memory device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 16 +++- src/conf/domain_conf.h | 30 ++ src/qemu/qemu_driver.c | 6 ++ src/qemu/qemu_hotplug.c | 1 + 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d7f7a9e..ea41cbd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -236,7 +236,8 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST, rng, shmem, tpm, - panic) + panic, + dimm) VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST, none, @@ -1981,6 +1982,7 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def) case VIR_DOMAIN_DEVICE_PANIC: virDomainPanicDefFree(def-data.panic); break; +case VIR_DOMAIN_DEVICE_DIMM: case VIR_DOMAIN_DEVICE_LAST: case VIR_DOMAIN_DEVICE_NONE: break; @@ -2687,6 +2689,8 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device) return device-data.tpm-info; case VIR_DOMAIN_DEVICE_PANIC: return device-data.panic-info; +case VIR_DOMAIN_DEVICE_DIMM: +return device-data.dimm-info; /* The following devices do not contain virDomainDeviceInfo */ case VIR_DOMAIN_DEVICE_LEASE: @@ -2917,6 +2921,12 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def, if (cb(def, device, def-panic-info, opaque) 0) return -1; } +device.type = VIR_DOMAIN_DEVICE_DIMM; +for (i = 0; i def-ndimms; i++) { +device.data.dimm = def-dimms[i]; +if (cb(def, device, def-dimms[i]-info, opaque) 0) +return -1; +} /* Coverity is not very happy with this - all dead_error_condition */ #if !STATIC_ANALYSIS @@ -2948,6 +2958,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def, case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: +case VIR_DOMAIN_DEVICE_DIMM: case VIR_DOMAIN_DEVICE_LAST: case VIR_DOMAIN_DEVICE_RNG: break; @@ -11175,6 +11186,7 @@ virDomainDeviceDefParse(const char *xmlStr, if (!(dev-data.panic = virDomainPanicDefParseXML(node))) goto error; break; +case VIR_DOMAIN_DEVICE_DIMM: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: break; @@ -16035,6 +16047,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src, case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: case VIR_DOMAIN_DEVICE_SHMEM: +case VIR_DOMAIN_DEVICE_DIMM: break; } #endif @@ -21482,6 +21495,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, case VIR_DOMAIN_DEVICE_PANIC: rc = virDomainPanicDefFormat(buf, src-data.panic); break; +case VIR_DOMAIN_DEVICE_DIMM: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index d746272..c4ebbd4 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -132,6 +132,9 @@ typedef virDomainIdMapDef *virDomainIdMapDefPtr; typedef struct _virDomainPanicDef virDomainPanicDef; typedef virDomainPanicDef *virDomainPanicDefPtr; +typedef struct _virDomainDimmDef virDomainDimmDef; +typedef virDomainDimmDef *virDomainDimmDefPtr; + /* forward declarations virDomainChrSourceDef, required by * virDomainNetDef */ @@ -168,6 +171,7 @@ typedef enum { VIR_DOMAIN_DEVICE_SHMEM, VIR_DOMAIN_DEVICE_TPM, VIR_DOMAIN_DEVICE_PANIC, +VIR_DOMAIN_DEVICE_DIMM, VIR_DOMAIN_DEVICE_LAST } virDomainDeviceType; @@ -198,6 +202,7 @@ struct _virDomainDeviceDef { virDomainShmemDefPtr shmem; virDomainTPMDefPtr tpm; virDomainPanicDefPtr panic; +virDomainDimmDefPtr dimm; } data; }; @@ -1982,6 +1987,28 @@ struct _virDomainHugePage { unsigned long long size;/* hugepage size in KiB */ }; +typedef enum { + VIR_DOMAIN_MEMORY_BACKEND_RAM = 0, + VIR_DOMAIN_MEMORY_BACKEND_FILE, + + VIR_DOMAIN_MEMORY_BACKEND_LAST +} virDomainMemoryBackend; + +struct _virDomainDimmDef { +char *driver; +int addr; /* default value: 0, means that address is auto-allocated*/ +int node; +int slot; + +struct { +virDomainMemoryBackend type; +unsigned long long size; /* in kibibytes */ +char *mem_path; +} backend; + +virDomainDeviceInfo info; +}; + typedef struct _virDomainCputune virDomainCputune; typedef virDomainCputune *virDomainCputunePtr; @@ -2161,6 +2188,9 @@ struct _virDomainDef { size_t nshmems; virDomainShmemDefPtr *shmems; +size_t ndimms; +virDomainDimmDefPtr *dimms; + /* Only 1 */ virDomainWatchdogDefPtr watchdog; virDomainMemballoonDefPtr
[libvirt] [RFC PATCH 2/3] qemu: introduce qemuDomainRemoveDimmDevice
This func being introduced is responsible for deleting memory backend and removing dimm from VM def. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_hotplug.c | 41 + 1 file changed, 41 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b7ca41e..8a0594f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2931,6 +2931,44 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, } +static int +qemuDomainRemoveDimmDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDimmDefPtr dimm) +{ +virObjectEventPtr event; +char *objAlias = NULL; +qemuDomainObjPrivatePtr priv = vm-privateData; +int ret = -1; + +VIR_DEBUG(Removing dimm device %s from domain %p %s, + dimm-info.alias, vm, vm-def-name); + +if (virAsprintf(objAlias, obj%s, dimm-info.alias) 0) +goto cleanup; + +qemuDomainObjEnterMonitor(driver, vm); +if (qemuMonitorDelMemoryBackend(priv-mon, objAlias) 0) { +qemuDomainObjExitMonitor(driver, vm); +goto cleanup; +} +qemuDomainObjExitMonitor(driver, vm); + +event = virDomainEventDeviceRemovedNewFromObj(vm, dimm-info.alias); +if (event) +qemuDomainEventQueue(driver, event); + +virDomainDimmRemove(vm-def, dimm); +virDomainDimmDefFree(dimm); + +ret = 0; + + cleanup: +VIR_FREE(objAlias); +return ret; +} + + int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -2956,6 +2994,9 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, break; case VIR_DOMAIN_DEVICE_DIMM: +qemuDomainRemoveDimmDevice(driver, vm, dev-data.dimm); +break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 0/3] qemu: add support to hot-unplug memory device
If you apply the patchset on your qemu [RESEND PATCH v1 00/13] QEmu memory hot unplug support. https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg00583.html, qemu can support memory hot-unplug. So this patchset will make libvirt support hot-unplug memory device for qemu driver. This series is based on the following patchset [RFC PATCH 00/11] qemu: add support to hotplug memory device. https://www.redhat.com/archives/libvir-list/2015-January/msg00728.html Zhu Guihua (3): qemu_monitor: introduce qemuMonitorDelMemoryBackend qemu: introduce qemuDomainRemoveDimmDevice qemu: implement dimm device hot-unplug on live level src/qemu/qemu_driver.c | 2 ++ src/qemu/qemu_hotplug.c | 95 + src/qemu/qemu_hotplug.h | 3 ++ src/qemu/qemu_monitor.c | 20 +++ src/qemu/qemu_monitor.h | 2 ++ 5 files changed, 122 insertions(+) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 1/3] qemu_monitor: introduce qemuMonitorDelMemoryBackend
The function being introduced is responsibel for excuting 'object_del' command to hot remove memory backend. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_monitor.c | 20 src/qemu/qemu_monitor.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 1db8ad0..c94a8d0 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4219,6 +4219,26 @@ int qemuMonitorAddMemoryBackend(qemuMonitorPtr mon, return -1; } +int qemuMonitorDelMemoryBackend(qemuMonitorPtr mon, +const char *objID) +{ +VIR_DEBUG(mon=%p objID=%s, mon, objID); + +if (!mon) { +virReportError(VIR_ERR_INVALID_ARG, %s, + _(monitor must not be NULL)); +return -1; +} + +if (!mon-json) { +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, + _(JSON monitor is required)); +return -1; +} + +return qemuMonitorDelObject(mon, objID); +} + int qemuMonitorAttachCharDev(qemuMonitorPtr mon, const char *chrID, virDomainChrSourceDefPtr chr) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 9a69611..7f02627 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -866,6 +866,8 @@ int qemuMonitorGetTPMTypes(qemuMonitorPtr mon, int qemuMonitorAddMemoryBackend(qemuMonitorPtr mon, const char *objID, virDomainDimmDefPtr dimm); +int qemuMonitorDelMemoryBackend(qemuMonitorPtr mon, +const char *objID); int qemuMonitorAttachCharDev(qemuMonitorPtr mon, const char *chrID, -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 3/3] qemu: implement dimm device hot-unplug on live level
Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 2 ++ src/qemu/qemu_hotplug.c | 54 + src/qemu/qemu_hotplug.h | 3 +++ 3 files changed, 59 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 76ff7b5..61a4ead 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7074,6 +7074,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret = qemuDomainDetachChrDevice(driver, vm, dev-data.chr); break; case VIR_DOMAIN_DEVICE_DIMM: +ret = qemuDomainDetachDimmDevice(driver, vm, dev-data.dimm); +break; case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 8a0594f..4895f95 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3897,3 +3897,57 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, VIR_FREE(devstr); return ret; } + +int qemuDomainDetachDimmDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDimmDefPtr dimm) +{ +int ret = -1; +qemuDomainObjPrivatePtr priv = vm-privateData; +virDomainDefPtr vmdef = vm-def; +virDomainDimmDefPtr tmpDimm; +int rc; + +if (!(tmpDimm = virDomainDimmFind(vmdef, dimm))) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(device not present in domain configration)); +return ret; +} + +if (!virQEMUCapsGet(priv-qemuCaps, QEMU_CAPS_DEVICE)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(qemu does not support -device)); +return ret; +} + +if (!tmpDimm-info.alias) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(detaching dimm device without alias name is not suported)); +return ret; +} + +qemuDomainMarkDeviceForRemoval(vm, tmpDimm-info); + +qemuDomainObjEnterMonitor(driver, vm); +if (qemuMonitorDelDevice(priv-mon, tmpDimm-info.alias) 0) { +qemuDomainObjExitMonitor(driver, vm); +goto cleanup; +} +qemuDomainObjExitMonitor(driver, vm); + +virDomainAuditMemory(vm, vm-def-mem.cur_balloon, + vm-def-mem.cur_balloon - tmpDimm-backend.size, + update, true); + +ignore_value(virBitmapClearBit(vm-def-mem.dimm_slot_map, tmpDimm-slot)); + +rc = qemuDomainWaitForDeviceRemoval(vm); +if (rc == 0 || rc == 1) +ret = qemuDomainRemoveDimmDevice(driver, vm, tmpDimm); +else +goto cleanup; + + cleanup: +qemuDomainResetDeviceRemoval(vm); +return ret; +} diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 1e9f7b3..f47a849 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -98,6 +98,9 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr); +int qemuDomainDetachDimmDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDimmDefPtr dimm); int -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 03/12] domain_conf: introduce cpu def helpers
On Wed, Jan 21, 2015 at 16:00:55 +0800, Zhu Guihua wrote: virDomainCPUDefFree - free memory allocated virDomainCPUDefParseXML - parse job type virDomainCPUDefFormat - output job type This patch lacks addition to the RNG schemas that would describe the elements that are added and the correct values. Also lacks change to the docs/formatdomain.html.in Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 100 + 1 file changed, 100 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e036d75..1f05056 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c ... + +static virDomainCPUDefPtr +virDomainCPUDefParseXML(xmlNodePtr node, virDomainDefPtr def) +{ +char *driver = NULL; +char *apic_id = NULL; +virDomainCPUDefPtr dev; + +if (!(dev = virDomainCPUDefNew())) +return NULL; + +driver = virXMLPropString(node, driver); The driver should rather be an enum value that is parsed from the string rather than stroing an inline string. This limits the namespace of devices libvirt supports but simplifies all matching of the driver later on. +if (driver == NULL) { +virReportError(VIR_ERR_XML_ERROR, %s, + _(missing cpu device driver)); +goto error; +} +dev-driver = driver; + +apic_id = virXMLPropString(node, apic_id); + +if (!apic_id) +dev-apic_id = virDomainCPUGetFreeApicID(def); +else +dev-apic_id = atoi (apic_id); Atoi is not allowed, use virStrToLong* instead. Also spaces after function name is forbidden. + +driver = NULL; +apic_id = NULL; + + cleanup: +VIR_FREE(driver); +VIR_FREE(apic_id); + +return dev; + + error: +virDomainCPUDefFree(dev); +dev = NULL; +goto cleanup; +} + virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, @@ -11187,6 +11253,9 @@ virDomainDeviceDefParse(const char *xmlStr, goto error; break; case VIR_DOMAIN_DEVICE_CPU: +if (!(dev-data.cpu = virDomainCPUDefParseXML(node, (virDomainDefPtr)def))) +goto error; +break; case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: break; @@ -18142,6 +18211,31 @@ virDomainChrDefFormat(virBufferPtr buf, } static int +virDomainCPUDefFormat(virBufferPtr buf, + virDomainCPUDefPtr def, + unsigned int flags) +{ +char *apic_id = NULL; + +ignore_value(virAsprintf(apic_id, %d, def-apic_id)); + +virBufferAsprintf(buf, cpu driver='%s', def-driver); + +virBufferEscapeString(buf, apic_id='%s', apic_id); Um? Why not virBufferAsprintf(buf, apic_id='%d', apic_id)? You won't need the intermediate string. Also it leaks the apic_id string. + +virBufferAddLit(buf, \n); +virBufferAdjustIndent(buf, 2); + +if (virDomainDeviceInfoFormat(buf, def-info, flags) 0) +return -1; + +virBufferAdjustIndent(buf, -2); +virBufferAddLit(buf, /cpu\n); + +return 0; +} + +static int Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 10/12] qemu: implement cpu device hotunplug on live level
On Wed, Jan 21, 2015 at 16:01:02 +0800, Zhu Guihua wrote: This patch implements live hotunplug of a cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 2 ++ src/qemu/qemu_hotplug.c | 66 + src/qemu/qemu_hotplug.h | 4 +++ 3 files changed, 72 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ddc7eeb..004bc35 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7077,6 +7077,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret = qemuDomainDetachChrDevice(driver, vm, dev-data.chr); break; case VIR_DOMAIN_DEVICE_CPU: +ret = qemuDomainDetachCPUDevice(driver, vm, dev-data.cpu); +break; case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index bff0d14..41013d9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2876,6 +2876,20 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, static int +qemuDomainRemoveCPUDevice(virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ +VIR_DEBUG(Removing cpu device %s from domain %p %s, + cpu-info.alias, vm, vm-def-name); + +virDomainCPURemove(vm-def, cpu); +virDomainCPUDefFree(cpu); If cpu is not identical (in meaning of being the same pointer), just a definition denoting the same device this will leak the definition that was previously stored in vm-def. + +return 0; +} + + +static int qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr) Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 02/12] domain_conf: add support for cpu device configuration in XML
This patch adds configuration support for the cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 14 ++ src/conf/domain_conf.h | 19 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 6 ++ src/qemu/qemu_hotplug.c | 1 + 5 files changed, 41 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1631421..e036d75 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -231,6 +231,7 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST, redirdev, smartcard, chr, + cpu, memballoon, nvram, rng, @@ -1981,6 +1982,7 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def) case VIR_DOMAIN_DEVICE_PANIC: virDomainPanicDefFree(def-data.panic); break; +case VIR_DOMAIN_DEVICE_CPU: case VIR_DOMAIN_DEVICE_LAST: case VIR_DOMAIN_DEVICE_NONE: break; @@ -2675,6 +2677,8 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device) return device-data.smartcard-info; case VIR_DOMAIN_DEVICE_CHR: return device-data.chr-info; +case VIR_DOMAIN_DEVICE_CPU: +return device-data.cpu-info; case VIR_DOMAIN_DEVICE_MEMBALLOON: return device-data.memballoon-info; case VIR_DOMAIN_DEVICE_NVRAM: @@ -2857,6 +2861,12 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def, if (cb(def, device, def-consoles[i]-info, opaque) 0) return -1; } +device.type = VIR_DOMAIN_DEVICE_CPU; +for (i = 0; i def-ncpus; i++) { +device.data.cpu = def-cpus[i]; +if (cb(def, device, def-cpus[i]-info, opaque) 0) +return -1; +} device.type = VIR_DOMAIN_DEVICE_INPUT; for (i = 0; i def-ninputs; i++) { device.data.input = def-inputs[i]; @@ -2943,6 +2953,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def, case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_CHR: +case VIR_DOMAIN_DEVICE_CPU: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_SHMEM: @@ -11175,6 +11186,7 @@ virDomainDeviceDefParse(const char *xmlStr, if (!(dev-data.panic = virDomainPanicDefParseXML(node))) goto error; break; +case VIR_DOMAIN_DEVICE_CPU: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: break; @@ -16015,6 +16027,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src, case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_CHR: +case VIR_DOMAIN_DEVICE_CPU: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_LAST: @@ -21463,6 +21476,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, case VIR_DOMAIN_DEVICE_PANIC: rc = virDomainPanicDefFormat(buf, src-data.panic); break; +case VIR_DOMAIN_DEVICE_CPU: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8869d26..618eef3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -108,6 +108,9 @@ typedef virDomainSmartcardDef *virDomainSmartcardDefPtr; typedef struct _virDomainChrDef virDomainChrDef; typedef virDomainChrDef *virDomainChrDefPtr; +typedef struct _virDomainCPUDef virDomainCPUDef; +typedef virDomainCPUDef *virDomainCPUDefPtr; + typedef struct _virDomainMemballoonDef virDomainMemballoonDef; typedef virDomainMemballoonDef *virDomainMemballoonDefPtr; @@ -162,6 +165,7 @@ typedef enum { VIR_DOMAIN_DEVICE_REDIRDEV, VIR_DOMAIN_DEVICE_SMARTCARD, VIR_DOMAIN_DEVICE_CHR, +VIR_DOMAIN_DEVICE_CPU, VIR_DOMAIN_DEVICE_MEMBALLOON, VIR_DOMAIN_DEVICE_NVRAM, VIR_DOMAIN_DEVICE_RNG, @@ -192,6 +196,7 @@ struct _virDomainDeviceDef { virDomainRedirdevDefPtr redirdev; virDomainSmartcardDefPtr smartcard; virDomainChrDefPtr chr; +virDomainCPUDefPtr cpu; virDomainMemballoonDefPtr memballoon; virDomainNVRAMDefPtr nvram; virDomainRNGDefPtr rng; @@ -1158,6 +1163,13 @@ struct _virDomainChrDef { virSecurityDeviceLabelDefPtr *seclabels; }; +struct _virDomainCPUDef { +char *driver; +int apic_id; + +virDomainDeviceInfo info; +}; + typedef enum { VIR_DOMAIN_SMARTCARD_TYPE_HOST, VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES, @@ -2130,6 +2142,9 @@ struct _virDomainDef { size_t nsmartcards; virDomainSmartcardDefPtr *smartcards; +size_t ncpus; +virDomainCPUDefPtr *cpus; + size_t nserials; virDomainChrDefPtr *serials; @@ -2342,6 +2357,7 @@ void virDomainActualNetDefFree(virDomainActualNetDefPtr def); void virDomainNetDefFree(virDomainNetDefPtr def); void
[libvirt] [RFC PATCH 01/12] domain_conf: allocate cpu's apic id dynamically
Add a bitmap apic_idmap to store status of APIC IDs. If you want to use an APIC ID, you can find a minimum value which has not been used in the bitmap. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 15 +++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 5 - 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8792f5e..1631421 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12895,6 +12895,12 @@ virDomainDefParseXML(xmlDocPtr xml, } } +if (!(def-apic_id_map = virBitmapNew(def-maxvcpus))) +goto error; + +for (i = 0; i def-vcpus; i++) +ignore_value(virBitmapSetBit(def-apic_id_map, i)); + tmp = virXPathString(string(./vcpu[1]/@placement), ctxt); if (tmp) { if ((def-placement_mode = @@ -16288,6 +16294,15 @@ virDomainVcpuPinDel(virDomainDefPtr def, int vcpu) } } +uint32_t +virDomainCPUGetFreeApicID(virDomainDefPtr def) +{ +int i; +i = virBitmapNextClearBit(def-apic_id_map, 0); + +return i; +} + int virDomainEmulatorPinAdd(virDomainDefPtr def, unsigned char *cpumap, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 09ab194..8869d26 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2062,6 +2062,7 @@ struct _virDomainDef { unsigned short maxvcpus; int placement_mode; virBitmapPtr cpumask; +virBitmapPtr apic_id_map; unsigned int iothreads; @@ -2530,6 +2531,8 @@ int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list, void virDomainVcpuPinDel(virDomainDefPtr def, int vcpu); +uint32_t virDomainCPUGetFreeApicID(virDomainDefPtr def); + int virDomainEmulatorPinAdd(virDomainDefPtr def, unsigned char *cpumap, int maplen); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a2eec83..d08e400 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -426,6 +426,7 @@ virDomainVcpuPinDefFree; virDomainVcpuPinDel; virDomainVcpuPinFindByVcpu; virDomainVcpuPinIsDuplicate; +virDomainCPUGetFreeApicID; virDomainVideoDefaultRAM; virDomainVideoDefaultType; virDomainVideoDefFree; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5994558..6bc7d8d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4371,6 +4371,7 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, int ncpupids; virCgroupPtr cgroup_vcpu = NULL; char *mem_mask = NULL; +uint32_t apic_id; qemuDomainObjEnterMonitor(driver, vm); @@ -4380,13 +4381,15 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver, if (nvcpus vcpus) { for (i = vcpus; i nvcpus; i++) { /* Online new CPU */ -rc = qemuMonitorSetCPU(priv-mon, i, true); +apic_id = virDomainCPUGetFreeApicID(vm-def); +rc = qemuMonitorSetCPU(priv-mon, apic_id, true); if (rc == 0) goto unsupported; if (rc 0) goto exit_monitor; vcpus++; +ignore_value(virBitmapSetBit(vm-def-apic_id_map, apic_id)); } } else { for (i = vcpus - 1; i = nvcpus; i--) { -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 00/12] qemu: add support to hot-plug/unplug cpu device
If you apply the folowing patchset [PATCH v3 0/7] cpu: add device_add foo-x86_64-cpu support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01552.html, and [PATCH v2 00/11] cpu: add i386 cpu hot remove support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01557.html, qemu can support hotplug and hot-unplug cpu device. So this patch series will make libvirt support hotplug and hot-unplug cpu device for qemu driver, and now only supports one cpu driver which is 'qemu64-x86_64-cpu'. The cpu device's xml like this: cpu driver='qemu64-x86_64-cpu' apic_id='3' Zhu Guihua (12): domain_conf: allocate cpu's apic id dynamically domain_conf: add support for cpu device configuration in XML domain_conf: introduce cpu def helpers domain_conf: introduce cpu device hotplug helpers qemu_driver: implement cpu device hotplug on config level qemu_command: introduce a func for cpu device alias assignment qemu: implement support for qemu64-x86_64-cpu qemu: introduce qemuBuildCPUDeviceStr qemu: implement cpu device hotplug on live level qemu: implement cpu device hotunplug on live level qemu_monitor_json: sort JSON array of cpu info qemu_driver: detect threads corresponding to Vcpus src/conf/domain_conf.c | 188 +++ src/conf/domain_conf.h | 35 + src/libvirt_private.syms | 6 + src/qemu/qemu_capabilities.c | 3 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 83 +++- src/qemu/qemu_command.h | 8 ++ src/qemu/qemu_driver.c | 296 --- src/qemu/qemu_driver.h | 8 ++ src/qemu/qemu_hotplug.c | 129 +++ src/qemu/qemu_hotplug.h | 11 ++ src/qemu/qemu_monitor_json.c | 31 - src/util/virbitmap.c | 2 +- src/util/virbitmap.h | 2 + 14 files changed, 668 insertions(+), 135 deletions(-) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 08/12] qemu: introduce qemuBuildCPUDeviceStr
qemuBuildCPUDeviceStr being introduced is responsible for creating command line argument for '-device' for given cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_command.c | 50 + src/qemu/qemu_command.h | 5 + 2 files changed, 55 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2ee3e10..824ad29 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5956,6 +5956,50 @@ static char *qemuBuildTPMDevStr(const virDomainDef *def, } +int +qemuBuildCPUDeviceStr(char **deviceStr, + virDomainCPUDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ +virBuffer buf = VIR_BUFFER_INITIALIZER; + +if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU64_CPU)) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(%s not supported in this QEMU binary), dev-driver); +goto error; +} + +virBufferAsprintf(buf, %s,id=%s,apic-id=%d, + dev-driver, dev-info.alias, + dev-apic_id); + +if (virBufferCheckError(buf) 0) +goto error; + +*deviceStr = virBufferContentAndReset(buf); +return 0; + + error: +virBufferFreeAndReset(buf); +return -1; +} + +static int +qemuBuildCPUDeviceCommandLine(virCommandPtr cmd, + virDomainCPUDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ +char *devstr = NULL; + +if (qemuBuildCPUDeviceStr(devstr, dev, qemuCaps) 0) +return -1; + +virCommandAddArgList(cmd, -device, devstr, NULL); +VIR_FREE(devstr); +return 0; +} + + static char *qemuBuildSmbiosBiosStr(virSysinfoDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -9862,6 +9906,12 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; } +/* add cpu devices */ +for (i = 0; i def-ncpus; i++) { +if (qemuBuildCPUDeviceCommandLine(cmd, def-cpus[i], qemuCaps) 0) +goto error; +} + if (def-nvram) { if (ARCH_IS_PPC64(def-os.arch) STRPREFIX(def-os.machine, pseries)) { diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 2898876..ab161b1 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -92,6 +92,11 @@ qemuBuildChrDeviceStr(char **deviceStr, virDomainChrDefPtr chr, virQEMUCapsPtr qemuCaps); +int +qemuBuildCPUDeviceStr(char **deviceStr, + virDomainCPUDefPtr cpu, + virQEMUCapsPtr qemuCaps); + /* With vlan == -1, use netdev syntax, else old hostnet */ char *qemuBuildHostNetStr(virDomainNetDefPtr net, virQEMUDriverPtr driver, -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 07/12] qemu: implement support for qemu64-x86_64-cpu
This patch adds a new capability bit QEMU_CAPS_QEMU64_X86_64_CPU. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 13f3cd3..56bb588 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -277,6 +277,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, vmware-svga.vgamem_mb, qxl.vgamem_mb, qxl-vga.vgamem_mb, + qemu64-x86_64-cpu, ); @@ -1524,6 +1525,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { usb-audio, QEMU_CAPS_OBJECT_USB_AUDIO }, { iothread, QEMU_CAPS_OBJECT_IOTHREAD}, { ivshmem, QEMU_CAPS_DEVICE_IVSHMEM }, +{ qemu64-x86_64-cpu, QEMU_CAPS_DEVICE_QEMU64_CPU }, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { @@ -3157,6 +3159,7 @@ virQEMUCapsInitArchQMPBasic(virQEMUCapsPtr qemuCaps, virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_ACPI); virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_HPET); virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_KVM_PIT); +virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_QEMU64_CPU); } ret = 0; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 12e1688..479fe4c 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -223,6 +223,7 @@ typedef enum { QEMU_CAPS_VMWARE_SVGA_VGAMEM = 181, /* -device vmware-svga.vgamem_mb */ QEMU_CAPS_QXL_VGAMEM = 182, /* -device qxl.vgamem_mb */ QEMU_CAPS_QXL_VGA_VGAMEM = 183, /* -device qxl-vga.vgamem_mb */ +QEMU_CAPS_DEVICE_QEMU64_CPU = 184, /* -device qemu64-x86_64-cpu */ QEMU_CAPS_LAST, /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 69d0a2a..2ee3e10 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5876,7 +5876,6 @@ qemuBuildRNGDeviceArgs(virCommandPtr cmd, return ret; } - static char *qemuBuildTPMBackendStr(const virDomainDef *def, virQEMUCapsPtr qemuCaps, const char *emulator) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 04/11] domain_conf: introduce dimm def helpers
virDomainDimmDefFree - free memory allocated for dimm virDomainDimmDefParseXML - parse job type virDomainDimmDefFormat - output job type Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 196 +++ src/conf/domain_conf.h | 4 + src/libvirt_private.syms | 3 + 3 files changed, 203 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ea41cbd..d4da728 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -751,6 +751,10 @@ VIR_ENUM_IMPL(virDomainRNGBackend, random, egd); +VIR_ENUM_IMPL(virDomainMemoryBackend, VIR_DOMAIN_MEMORY_BACKEND_LAST, + ram, + file); + VIR_ENUM_IMPL(virDomainTPMModel, VIR_DOMAIN_TPM_MODEL_LAST, tpm-tis) @@ -1733,6 +1737,22 @@ void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def) VIR_FREE(def); } +void virDomainDimmDefFree(virDomainDimmDefPtr def) +{ +if (!def) +return; + +if (def-driver) +VIR_FREE(def-driver); +if (def-backend.type == VIR_DOMAIN_MEMORY_BACKEND_FILE +def-backend.mem_path) +VIR_FREE(def-backend.mem_path); + +virDomainDeviceInfoClear(def-info); + +VIR_FREE(def); +} + void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def) { if (!def) @@ -1983,6 +2003,8 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def) virDomainPanicDefFree(def-data.panic); break; case VIR_DOMAIN_DEVICE_DIMM: +virDomainDimmDefFree(def-data.dimm); +break; case VIR_DOMAIN_DEVICE_LAST: case VIR_DOMAIN_DEVICE_NONE: break; @@ -10203,6 +10225,132 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, goto cleanup; } +virDomainDimmDefPtr +virDomainDimmDefNew(void) +{ +virDomainDimmDefPtr def = NULL; + +if (VIR_ALLOC(def) 0) +return NULL; + +return def; +} + +/* Parse the XML definition for a dimm + * + * The XML looks like this: + * + * dimm driver='pc-dimm' addr='0' node='0' slot='1' + * backend type='ram' size='128000'/ + * /dimm + * + */ +static virDomainDimmDefPtr +virDomainDimmDefParseXML(xmlNodePtr node, + virDomainDefPtr def) +{ +virDomainDimmDefPtr dev; +xmlNodePtr cur; +char *driver = NULL; +char *addr = NULL; +char *nodeid = NULL; +char *slot = NULL; +char *type = NULL; +char *size = NULL; +char *mem_path = NULL; + +if (!(dev = virDomainDimmDefNew())) +return NULL; + +driver = virXMLPropString(node, driver); +if (driver == NULL) { +virReportError(VIR_ERR_XML_ERROR, %s, + _(missing memory device driver)); +goto error; +} + +addr = virXMLPropString(node, addr); +nodeid = virXMLPropString(node, node); +slot = virXMLPropString(node, slot); + +cur = node-children; +while (cur != NULL) { +if (cur-type == XML_ELEMENT_NODE) { +type = virXMLPropString(cur, type); +if (type != NULL) { +if ((int)(dev-backend.type = virDomainMemoryBackendTypeFromString(type)) 0) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unknown memory backend type '%s'), type); +goto error; +} +} else { +virReportError(VIR_ERR_XML_ERROR, %s, + _(missing memory backend)); +goto error; +} + +size = virXMLPropString(cur, size); +if (size == NULL) { +virReportError(VIR_ERR_XML_ERROR, %s, + _(missing memory backend's size)); +goto error; +} else { +dev-backend.size = atoi (size); +} + +if (dev-backend.type == VIR_DOMAIN_MEMORY_BACKEND_FILE) { +mem_path = virXMLPropString(cur, mem_path); +if (mem_path == NULL) { +virReportError(VIR_ERR_XML_ERROR, %s, + _(mem_path property not set)); +goto error; +} else { +dev-backend.mem_path = mem_path; +} +} +} + +cur = cur-next; +} + +dev-driver = driver; +if (!addr) +dev-addr = 0; +else +dev-addr = atoi (addr); +if (!nodeid) +dev-node = 0; +else +dev-node = atoi (nodeid); +if (!slot) +dev-slot = virDomainDimmGetFreeSlot(def); +else +dev-slot = atoi (slot); + cleanup: +driver = NULL; +addr = NULL; +nodeid = NULL; +slot = NULL; +type = NULL; +size = NULL; +mem_path = NULL; + +VIR_FREE(driver); +VIR_FREE(addr); +VIR_FREE(nodeid); +VIR_FREE(slot); +VIR_FREE(type); +VIR_FREE(size); +VIR_FREE(mem_path); + +return dev; + + error: +
[libvirt] [RFC PATCH 00/11] qemu: add support to hotplug memory device
Now qemu has already supported memory hotplug, so this patchset will make libvirt support hotplug memory device for qemu driver. First, add two parameters slots and maxmem for memory hotplug, and the xml format can be like this. memory slot='10'102400/memory maxMemory1024000/maxMemory Second, memory device's xml format can be like this. dimm driver='pc-dimm' addr='0' node='0' slot='1' backend type='ram' size='131072'/ /dimm Zhu Guihua (11): domain_conf: support slots and maxmem properties in memory xml domain_conf: introduce virDomainDimmGetFreeSlot domain_conf: add support for memory device configuration in XML domain_conf: introduce dimm def helpers domain_conf: introduce dimm device hotplug helpers qemu: implement dimm device hotplug on config level qemu_monitor: introduce qemuMonitorAddMemoryBackend qemu_command: introduce a func for memory device alias qemu: implement support for pc-dimm qemu: introduce qemuBuildDimmDeviceStr qemu: implement dimm device hotplug on live level src/conf/domain_conf.c | 306 ++- src/conf/domain_conf.h | 54 src/libvirt_private.syms | 6 + src/qemu/qemu_capabilities.c | 3 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 110 +++- src/qemu/qemu_command.h | 7 + src/qemu/qemu_driver.c | 26 src/qemu/qemu_hotplug.c | 71 ++ src/qemu/qemu_hotplug.h | 5 + src/qemu/qemu_monitor.c | 54 src/qemu/qemu_monitor.h | 4 + 12 files changed, 644 insertions(+), 3 deletions(-) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 11/11] qemu: implement dimm device hotplug on live level
This patch implements live hotplug of a memory device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 6 + src/qemu/qemu_hotplug.c | 70 + src/qemu/qemu_hotplug.h | 5 3 files changed, 81 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a7a50e0..76ff7b5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6992,6 +6992,12 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, break; case VIR_DOMAIN_DEVICE_DIMM: +ret = qemuDomainAttachDimmDevice(driver, vm, + dev-data.dimm); +if (!ret) +dev-data.dimm = NULL; +break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f83cb1c..b7ca41e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1776,6 +1776,76 @@ static virDomainNetDefPtr *qemuDomainFindNet(virDomainObjPtr vm, static int +qemuDomainDimmInsert(virDomainDefPtr vmdef, +virDomainDimmDefPtr dimm) +{ +if (virDomainDimmFind(vmdef, dimm)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(pc-dimm already exists)); +return -1; +} + +if (virDomainDimmInsert(vmdef, dimm) 0) +return -1; + +return 0; +} + +int qemuDomainAttachDimmDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDimmDefPtr dimm) +{ +int ret = -1; +char *devstr = NULL; +qemuDomainObjPrivatePtr priv = vm-privateData; +virDomainDefPtr vmdef = vm-def; +char *objAlias = NULL; + +if (!virQEMUCapsGet(priv-qemuCaps, QEMU_CAPS_DEVICE)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(qemu does not support -device)); +goto cleanup;; +} + +if (qemuAssignDeviceDimmAlias(vmdef, dimm, -1) 0) +goto cleanup; + +if (virAsprintf(objAlias, obj%s, dimm-info.alias) 0) +goto cleanup; + +if (qemuBuildDimmDeviceStr(devstr, dimm, priv-qemuCaps) 0) +goto cleanup; + +if (qemuDomainDimmInsert(vmdef, dimm) 0) +goto cleanup; + +qemuDomainObjEnterMonitor(driver, vm); + +if (qemuMonitorAddMemoryBackend(priv-mon, objAlias, dimm) 0) { +qemuDomainObjExitMonitor(driver, vm); +goto cleanup; +} + +if (devstr qemuMonitorAddDevice(priv-mon, devstr) 0) { +qemuDomainObjExitMonitor(driver, vm); +goto cleanup; +} + +qemuDomainObjExitMonitor(driver, vm); +virDomainAuditMemory(vm, vm-def-mem.cur_balloon, + vm-def-mem.cur_balloon + dimm-backend.size, + update, true); + +ignore_value(virBitmapSetBit(vm-def-mem.dimm_slot_map, dimm-slot)); +ret = 0; + + cleanup: +VIR_FREE(devstr); +VIR_FREE(objAlias); +return ret; +} + +static int qemuDomainChangeNetBridge(virDomainObjPtr vm, virDomainNetDefPtr olddev, virDomainNetDefPtr newdev) diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 19ab9a0..1e9f7b3 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -107,6 +107,11 @@ virDomainChrDefPtr qemuDomainChrRemove(virDomainDefPtr vmdef, virDomainChrDefPtr chr); +int +qemuDomainAttachDimmDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDimmDefPtr dimm); + int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev); -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 00/12] qemu: add support to hot-plug/unplug cpu device
On Wed, Jan 21, 2015 at 16:00:52 +0800, Zhu Guihua wrote: If you apply the folowing patchset [PATCH v3 0/7] cpu: add device_add foo-x86_64-cpu support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01552.html, and [PATCH v2 00/11] cpu: add i386 cpu hot remove support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01557.html, qemu can support hotplug and hot-unplug cpu device. So this patch series will make libvirt support hotplug and hot-unplug cpu device for qemu driver, and now only supports one cpu driver which is 'qemu64-x86_64-cpu'. The cpu device's xml like this: cpu driver='qemu64-x86_64-cpu' apic_id='3' Libvirt already implements vCPU hotplug and unplug via virDomainSetVcpusFlags() API and implements this API also for the qemu driver. Granted that the existing code uses older comands but that can be tweaked to support the new stuff too. Additionally the new cpu subelement of devices doesn't seem necessary: - There's only one model that can be plugged - Configuring the APIC id doesn't make much sense for users - nothing else can be configured I have following questions though: Is there a difference in specifying the cpu via the -device option and via the legacy -cpu argument? Is there a plan to have more than one cpu model that can be plugged? Can more than one cpu model be plugged to the same VM at the same time? In general I don't think it's necessary to add the new device type and we should rather improve the existing API to support the new device type. More comments will be inline in the patches. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 02/12] domain_conf: add support for cpu device configuration in XML
On Wed, Jan 21, 2015 at 16:00:54 +0800, Zhu Guihua wrote: This patch adds configuration support for the cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 14 ++ src/conf/domain_conf.h | 19 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 6 ++ src/qemu/qemu_hotplug.c | 1 + 5 files changed, 41 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1631421..e036d75 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2857,6 +2861,12 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def, if (cb(def, device, def-consoles[i]-info, opaque) 0) return -1; } +device.type = VIR_DOMAIN_DEVICE_CPU; +for (i = 0; i def-ncpus; i++) { +device.data.cpu = def-cpus[i]; +if (cb(def, device, def-cpus[i]-info, opaque) 0) +return -1; +} device.type = VIR_DOMAIN_DEVICE_INPUT; for (i = 0; i def-ninputs; i++) { device.data.input = def-inputs[i]; @@ -16015,6 +16027,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src, case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_CHR: +case VIR_DOMAIN_DEVICE_CPU: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_LAST: The ABI stability check code needs to be implemented. @@ -21463,6 +21476,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, case VIR_DOMAIN_DEVICE_PANIC: rc = virDomainPanicDefFormat(buf, src-data.panic); break; +case VIR_DOMAIN_DEVICE_CPU: The copy function needs to be impelemnted too (I didn't check next patch thoug yet) case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8869d26..618eef3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -108,6 +108,9 @@ typedef virDomainSmartcardDef *virDomainSmartcardDefPtr; typedef struct _virDomainChrDef virDomainChrDef; typedef virDomainChrDef *virDomainChrDefPtr; +typedef struct _virDomainCPUDef virDomainCPUDef; +typedef virDomainCPUDef *virDomainCPUDefPtr; + typedef struct _virDomainMemballoonDef virDomainMemballoonDef; typedef virDomainMemballoonDef *virDomainMemballoonDefPtr; @@ -1158,6 +1163,13 @@ struct _virDomainChrDef { virSecurityDeviceLabelDefPtr *seclabels; }; +struct _virDomainCPUDef { +char *driver; +int apic_id; + +virDomainDeviceInfo info; I've looked through the next patch and you don't parse any device info for the CPU type. Is it necessary to have it present at all in that case? +}; + typedef enum { VIR_DOMAIN_SMARTCARD_TYPE_HOST, VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES, @@ -2342,6 +2357,7 @@ void virDomainActualNetDefFree(virDomainActualNetDefPtr def); void virDomainNetDefFree(virDomainNetDefPtr def); void virDomainSmartcardDefFree(virDomainSmartcardDefPtr def); void virDomainChrDefFree(virDomainChrDefPtr def); +void virDomainCPUDefFree(virDomainCPUDefPtr def); Function declarations should be along with function definitions. void virDomainChrSourceDefFree(virDomainChrSourceDefPtr def); int virDomainChrSourceDefCopy(virDomainChrSourceDefPtr src, virDomainChrSourceDefPtr dest); @@ -2387,6 +2403,8 @@ void virDomainDefFree(virDomainDefPtr vm); virDomainChrDefPtr virDomainChrDefNew(void); +virDomainCPUDefPtr virDomainCPUDefNew(void); + Same here virDomainDefPtr virDomainDefNew(const char *name, const unsigned char *uuid, int id); @@ -2805,6 +2823,7 @@ VIR_ENUM_DECL(virDomainChrChannelTarget) VIR_ENUM_DECL(virDomainChrConsoleTarget) VIR_ENUM_DECL(virDomainChrSerialTarget) VIR_ENUM_DECL(virDomainSmartcard) +VIR_ENUM_DECL(virDomainCPU) VIR_ENUM_DECL(virDomainChr) VIR_ENUM_DECL(virDomainChrTcpProtocol) VIR_ENUM_DECL(virDomainChrSpicevmc) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d08e400..9ceff71 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -166,6 +166,7 @@ virDomainChrTcpProtocolTypeFromString; virDomainChrTcpProtocolTypeToString; virDomainChrTypeFromString; virDomainChrTypeToString; +virDomainCPUDefFree; Breaks make syntax-check again: Expected symbol virDomainCPUDefFree is not in ELF library The symbols entry can be added only when the function is defined. virDomainClockBasisTypeToString; virDomainClockOffsetTypeFromString; virDomainClockOffsetTypeToString; Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 08/12] qemu: introduce qemuBuildCPUDeviceStr
On Wed, Jan 21, 2015 at 16:01:00 +0800, Zhu Guihua wrote: qemuBuildCPUDeviceStr being introduced is responsible for creating command line argument for '-device' for given cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_command.c | 50 + src/qemu/qemu_command.h | 5 + 2 files changed, 55 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2ee3e10..824ad29 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5956,6 +5956,50 @@ static char *qemuBuildTPMDevStr(const virDomainDef *def, } +int +qemuBuildCPUDeviceStr(char **deviceStr, + virDomainCPUDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ +virBuffer buf = VIR_BUFFER_INITIALIZER; + +if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU64_CPU)) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(%s not supported in this QEMU binary), dev-driver); You blindly assume that the user passed the correct model here and not any other invalid string. As I've already said, having this converted to an enum makes things easier. +goto error; +} + +virBufferAsprintf(buf, %s,id=%s,apic-id=%d, + dev-driver, dev-info.alias, + dev-apic_id); Having a buffer for a single virBufferAsprintf case is a bit overkill. + +if (virBufferCheckError(buf) 0) +goto error; + +*deviceStr = virBufferContentAndReset(buf); +return 0; + + error: +virBufferFreeAndReset(buf); +return -1; +} + +static int +qemuBuildCPUDeviceCommandLine(virCommandPtr cmd, + virDomainCPUDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ +char *devstr = NULL; + +if (qemuBuildCPUDeviceStr(devstr, dev, qemuCaps) 0) +return -1; + +virCommandAddArgList(cmd, -device, devstr, NULL); +VIR_FREE(devstr); +return 0; +} + + static char *qemuBuildSmbiosBiosStr(virSysinfoDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -9862,6 +9906,12 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; } +/* add cpu devices */ +for (i = 0; i def-ncpus; i++) { +if (qemuBuildCPUDeviceCommandLine(cmd, def-cpus[i], qemuCaps) 0) +goto error; +} As I've asked before. The question here is whether this is equivalent with just increasing the vCPU count in the -cpu argument. If not it will require a bit more work for setting cgroups, numa pinning and other stuff. If they are equivalent we should use that instead and have the existing code do the magic. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 11/12] qemu_monitor_json: sort JSON array of cpu info
On Wed, Jan 21, 2015 at 16:01:03 +0800, Zhu Guihua wrote: JSON array of cpu info is sorted in order to find thread id of cpu smoothly. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/libvirt_private.syms | 1 + src/qemu/qemu_monitor_json.c | 31 +-- src/util/virbitmap.c | 2 +- src/util/virbitmap.h | 2 ++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 032e9a9..d2c7c73 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1042,6 +1042,7 @@ virBitmapFree; virBitmapGetBit; virBitmapIsAllClear; virBitmapIsAllSet; +virBitmapIsSet; This function is not used anywhere in this patch. Is this (and the other related hunks) here by accident? virBitmapLastSetBit; virBitmapNew; virBitmapNewCopy; Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 00/12] qemu: add support to hot-plug/unplug cpu device
On Wed, Jan 21, 2015 at 04:00:52PM +0800, Zhu Guihua wrote: If you apply the folowing patchset [PATCH v3 0/7] cpu: add device_add foo-x86_64-cpu support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01552.html, and [PATCH v2 00/11] cpu: add i386 cpu hot remove support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01557.html, qemu can support hotplug and hot-unplug cpu device. So this patch series will make libvirt support hotplug and hot-unplug cpu device for qemu driver, and now only supports one cpu driver which is 'qemu64-x86_64-cpu'. The cpu device's xml like this: cpu driver='qemu64-x86_64-cpu' apic_id='3' Do we really need to expose this 'qemu64-x86_64-cpu' string to apps. It feels like a rather low level QEMU private implementation detail to me that apps should not need to know or care about. I think libvirt should always just do the right thing to make cpu hotplug work. Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 0/3] qemu: add support to hot-unplug memory device
On Wed, Jan 21, 2015 at 16:32:05 +0800, Zhu Guihua wrote: If you apply the patchset on your qemu [RESEND PATCH v1 00/13] QEmu memory hot unplug support. https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg00583.html, qemu can support memory hot-unplug. So this patchset will make libvirt support hot-unplug memory device for qemu driver. This series is based on the following patchset [RFC PATCH 00/11] qemu: add support to hotplug memory device. https://www.redhat.com/archives/libvir-list/2015-January/msg00728.html As with the hotplug series. I'm already working on incorporating this in a better way, thus I won't review this series in detail nor merge it. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 00/12] qemu: add support to hot-plug/unplug cpu device
On Wed, Jan 21, 2015 at 04:00:52PM +0800, Zhu Guihua wrote: If you apply the folowing patchset [PATCH v3 0/7] cpu: add device_add foo-x86_64-cpu support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01552.html, and [PATCH v2 00/11] cpu: add i386 cpu hot remove support https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg01557.html, qemu can support hotplug and hot-unplug cpu device. So this patch series will make libvirt support hotplug and hot-unplug cpu device for qemu driver, and now only supports one cpu driver which is 'qemu64-x86_64-cpu'. Also I'm wondering how this interacts with CPU topology. eg lets say you configure a 16 vCPU guest, and set topology to 2 sockets, 4 cores, 2 threads. Does this hotplug allow you to plug/unplug individual threads - ie each invididual vCPU, or does it only allow plug/unplug of sockets - ie 8 vCPUs at a time in this topology. Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 03/12] domain_conf: introduce cpu def helpers
virDomainCPUDefFree - free memory allocated virDomainCPUDefParseXML - parse job type virDomainCPUDefFormat - output job type Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 100 + 1 file changed, 100 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e036d75..1f05056 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1913,6 +1913,19 @@ void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def) VIR_FREE(def); } +void virDomainCPUDefFree(virDomainCPUDefPtr def) +{ +if (!def) +return; + +if (def-driver) +VIR_FREE(def-driver); + +virDomainDeviceInfoClear(def-info); + +VIR_FREE(def); +} + void virDomainDeviceDefFree(virDomainDeviceDefPtr def) { if (!def) @@ -1983,6 +1996,8 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def) virDomainPanicDefFree(def-data.panic); break; case VIR_DOMAIN_DEVICE_CPU: +virDomainCPUDefFree(def-data.cpu); +break; case VIR_DOMAIN_DEVICE_LAST: case VIR_DOMAIN_DEVICE_NONE: break; @@ -11052,6 +11067,57 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt, return ret; } +virDomainCPUDefPtr +virDomainCPUDefNew(void) +{ +virDomainCPUDefPtr def = NULL; + +if (VIR_ALLOC(def) 0) +return NULL; + +return def; +} + +static virDomainCPUDefPtr +virDomainCPUDefParseXML(xmlNodePtr node, virDomainDefPtr def) +{ +char *driver = NULL; +char *apic_id = NULL; +virDomainCPUDefPtr dev; + +if (!(dev = virDomainCPUDefNew())) +return NULL; + +driver = virXMLPropString(node, driver); +if (driver == NULL) { +virReportError(VIR_ERR_XML_ERROR, %s, + _(missing cpu device driver)); +goto error; +} +dev-driver = driver; + +apic_id = virXMLPropString(node, apic_id); + +if (!apic_id) +dev-apic_id = virDomainCPUGetFreeApicID(def); +else +dev-apic_id = atoi (apic_id); + +driver = NULL; +apic_id = NULL; + + cleanup: +VIR_FREE(driver); +VIR_FREE(apic_id); + +return dev; + + error: +virDomainCPUDefFree(dev); +dev = NULL; +goto cleanup; +} + virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, @@ -11187,6 +11253,9 @@ virDomainDeviceDefParse(const char *xmlStr, goto error; break; case VIR_DOMAIN_DEVICE_CPU: +if (!(dev-data.cpu = virDomainCPUDefParseXML(node, (virDomainDefPtr)def))) +goto error; +break; case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: break; @@ -18142,6 +18211,31 @@ virDomainChrDefFormat(virBufferPtr buf, } static int +virDomainCPUDefFormat(virBufferPtr buf, + virDomainCPUDefPtr def, + unsigned int flags) +{ +char *apic_id = NULL; + +ignore_value(virAsprintf(apic_id, %d, def-apic_id)); + +virBufferAsprintf(buf, cpu driver='%s', def-driver); + +virBufferEscapeString(buf, apic_id='%s', apic_id); + +virBufferAddLit(buf, \n); +virBufferAdjustIndent(buf, 2); + +if (virDomainDeviceInfoFormat(buf, def-info, flags) 0) +return -1; + +virBufferAdjustIndent(buf, -2); +virBufferAddLit(buf, /cpu\n); + +return 0; +} + +static int virDomainSmartcardDefFormat(virBufferPtr buf, virDomainSmartcardDefPtr def, unsigned int flags) @@ -20062,6 +20156,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, goto error; } +for (n = 0; n def-ncpus; n++) +if (virDomainCPUDefFormat(buf, def-cpus[n], flags) 0) +goto error; + if (def-nvram) virDomainNVRAMDefFormat(buf, def-nvram, flags); @@ -21477,6 +21575,8 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, rc = virDomainPanicDefFormat(buf, src-data.panic); break; case VIR_DOMAIN_DEVICE_CPU: +rc = virDomainCPUDefFormat(buf, src-data.cpu, flags); +break; case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_MEMBALLOON: -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 07/11] qemu_monitor: introduce qemuMonitorAddMemoryBackend
The function being introduced is responsible for excuting 'object_add' command to hot add memory backend. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_monitor.c | 54 + src/qemu/qemu_monitor.h | 4 2 files changed, 58 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 6882a50..1db8ad0 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4165,6 +4165,60 @@ int qemuMonitorGetTPMTypes(qemuMonitorPtr mon, return qemuMonitorJSONGetTPMTypes(mon, tpmtypes); } +int qemuMonitorAddMemoryBackend(qemuMonitorPtr mon, +const char *objID, +virDomainDimmDefPtr dimm) +{ +VIR_DEBUG(mon=%p objID=%s dimm=%p, + mon, objID, dimm); + +virJSONValuePtr props = NULL; +const char *type = NULL; + +if (!mon) { +virReportError(VIR_ERR_INVALID_ARG, %s, + _(monitor must not be NULL)); +goto cleanup; +} + +if (!mon-json) { +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s, + _(JSON monitor is required)); +goto cleanup; +} + +if (!(props = virJSONValueNewObject())) +goto cleanup; + +switch (dimm-backend.type) { +case VIR_DOMAIN_MEMORY_BACKEND_RAM: +type = memory-backend-ram; +if ( virJSONValueObjectAppendNumberUlong(props, +size, dimm-backend.size * 1024) 0) +goto cleanup; +break; + +case VIR_DOMAIN_MEMORY_BACKEND_FILE: +type = memory-backend-file; +if (virJSONValueObjectAppendNumberUlong(props, size, +dimm-backend.size * 1024) 0) +goto cleanup; +if (virJSONValueObjectAppendString(props, mem-path, + dimm-backend.mem_path) 0) +goto cleanup; +break; + +default: +break; +} + +return qemuMonitorAddObject(mon, type, objID, props); + + cleanup: +virJSONValueFree(props); +return -1; +} + int qemuMonitorAttachCharDev(qemuMonitorPtr mon, const char *chrID, virDomainChrSourceDefPtr chr) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 133d42d..9a69611 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -863,6 +863,10 @@ int qemuMonitorGetTPMModels(qemuMonitorPtr mon, int qemuMonitorGetTPMTypes(qemuMonitorPtr mon, char ***tpmtypes); +int qemuMonitorAddMemoryBackend(qemuMonitorPtr mon, +const char *objID, +virDomainDimmDefPtr dimm); + int qemuMonitorAttachCharDev(qemuMonitorPtr mon, const char *chrID, virDomainChrSourceDefPtr chr); -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 08/11] qemu_command: introduce a func for memory device alias
This function used to set a alias name for memory device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_command.c | 32 src/qemu/qemu_command.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 536abc3..68fdab7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -946,6 +946,34 @@ qemuAssignDeviceChrAlias(virDomainDefPtr def, } int +qemuAssignDeviceDimmAlias(virDomainDefPtr def, + virDomainDimmDefPtr dimm, + int idx) +{ +if (idx == -1) { +size_t i; +idx = 0; + +for (i = 0; i def-ndimms; i++) { +int thisidx; +if ((thisidx = qemuDomainDeviceAliasIndex(def-dimms[i]-info, dimm)) 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, %s, + _(unable to determine device index from dimm device)); +return -1; +} + +if (thisidx = idx) +idx = thisidx + 1; +} +} + +if (virAsprintf(dimm-info.alias, dimm%d, idx) 0) +return -1; + +return 0; +} + +int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { size_t i; @@ -1039,6 +1067,10 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) if (virAsprintf(def-rngs[i]-info.alias, rng%zu, i) 0) return -1; } +for (i = 0; i def-ndimms; i++) { +if (qemuAssignDeviceDimmAlias(def, def-dimms[i], i) 0) +return -1; +} if (def-tpm) { if (virAsprintf(def-tpm-info.alias, tpm%d, 0) 0) return -1; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index dcc7127..512d444 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -264,6 +264,9 @@ int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr r int qemuAssignDeviceChrAlias(virDomainDefPtr def, virDomainChrDefPtr chr, ssize_t idx); +int qemuAssignDeviceDimmAlias(virDomainDefPtr def, + virDomainDimmDefPtr dimm, + int idx); int qemuParseKeywords(const char *str, -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 01/11] domain_conf: support slots and maxmem properties in memory xml
Add properties slots and maxmem, so as to support memory hotplug. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 22 ++ src/conf/domain_conf.h | 4 src/qemu/qemu_command.c | 28 ++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8792f5e..526f2da 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12594,6 +12594,7 @@ virDomainDefParseXML(xmlDocPtr xml, long id = -1; virDomainDefPtr def; unsigned long count; +unsigned int slots; bool uuid_generated = false; virHashTablePtr bootHash = NULL; bool usb_none = false; @@ -12723,6 +12724,21 @@ virDomainDefParseXML(xmlDocPtr xml, def-mem.cur_balloon, false, true) 0) goto error; +n = virXPathUInt(string(./memory[1]/@slots), ctxt, slots); +if (n == -2) { +virReportError(VIR_ERR_XML_ERROR, %s, + _(maximum slots for memory devices + must be an integer)); +goto error; +} else if (n == -1) { +def-mem.slots = -1; +} else { +def-mem.slots = slots; +if (virDomainParseMemory(./maxMemory[1], NULL, ctxt, + def-mem.maxmem, true, true) 0) +goto error; +} + /* and info about it */ if ((tmp = virXPathString(string(./memory[1]/@dumpCore), ctxt)) (def-mem.dump_core = virTristateSwitchTypeFromString(tmp)) = 0) { @@ -19319,12 +19335,18 @@ virDomainDefFormatInternal(virDomainDefPtr def, if (def-mem.dump_core) virBufferAsprintf(buf, dumpCore='%s', virTristateSwitchTypeToString(def-mem.dump_core)); +if (def-mem.slots def-mem.maxmem) +virBufferAsprintf(buf, slot='%u', + def-mem.slots); virBufferAsprintf(buf, unit='KiB'%llu/memory\n, def-mem.max_balloon); virBufferAsprintf(buf, currentMemory unit='KiB'%llu/currentMemory\n, def-mem.cur_balloon); +if (def-mem.slots def-mem.maxmem) +virBufferAsprintf(buf, maxMemory unit='KiB'%llu/maxMemory\n, + def-mem.maxmem); /* add blkiotune only if there are any */ if (def-blkio.weight) { blkio = true; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 09ab194..731d14f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2018,6 +2018,10 @@ struct _virDomainMemtune { unsigned long long cur_balloon; /* in kibibytes, capped at ulong thanks to virDomainGetInfo */ +unsigned int slots; /* the maximum slots for memory devices */ +unsigned long long maxmem; /* in kibibytes, the maximum memory + for the guest */ + virDomainHugePagePtr hugepages; size_t nhugepages; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c041ee7..536abc3 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6598,6 +6598,26 @@ qemuBuildMachineArgStr(virCommandPtr cmd, } static char * +qemuBuildMemArgStr(virDomainDefPtr def) +{ +virBuffer buf = VIR_BUFFER_INITIALIZER; + +def-mem.max_balloon = VIR_DIV_UP(def-mem.max_balloon, 1024) * 1024; + +virBufferAsprintf(buf, %lluM, def-mem.max_balloon / 1024); +if (def-mem.slots != -1) { +def-mem.maxmem = VIR_DIV_UP(def-mem.maxmem, 1024) * 1024; +virBufferAsprintf(buf, ,slots=%u, def-mem.slots); +virBufferAsprintf(buf, ,maxmem=%lluM, def-mem.maxmem / 1024); +} + +if (virBufferCheckError(buf) 0) +return NULL; + +return virBufferContentAndReset(buf); +} + +static char * qemuBuildSmpArgStr(const virDomainDef *def, virQEMUCapsPtr qemuCaps) { @@ -7796,6 +7816,7 @@ qemuBuildCommandLine(virConnectPtr conn, char uuid[VIR_UUID_STRING_BUFLEN]; char *cpu; char *smp; +char *mem; int last_good_net = -1; bool hasHwVirt = false; virCommandPtr cmd = NULL; @@ -7929,8 +7950,11 @@ qemuBuildCommandLine(virConnectPtr conn, * XML to reflect our rounding. */ virCommandAddArg(cmd, -m); -def-mem.max_balloon = VIR_DIV_UP(def-mem.max_balloon, 1024) * 1024; -virCommandAddArgFormat(cmd, %llu, def-mem.max_balloon / 1024); +if (!(mem = qemuBuildMemArgStr(def))) +goto error; +virCommandAddArg(cmd, mem); +VIR_FREE(mem); + if (def-mem.nhugepages (!def-cpu || !def-cpu-ncells)) { const long system_page_size = sysconf(_SC_PAGESIZE) / 1024; char *mem_path = NULL; -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 06/11] qemu: implement dimm device hotplug on config level
The config level requires an insert or remove from domain definition structure. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d017a84..a7a50e0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7313,6 +7313,11 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps, break; case VIR_DOMAIN_DEVICE_DIMM: +if (virDomainDimmInsert(vmdef, dev-data.dimm) 0) +return -1; +dev-data.dimm = NULL; +break; + case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_VIDEO: @@ -7349,6 +7354,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, virDomainControllerDefPtr cont, det_cont; virDomainChrDefPtr chr; virDomainFSDefPtr fs; +virDomainDimmDefPtr dimm; int idx; switch ((virDomainDeviceType) dev-type) { @@ -7430,6 +7436,14 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef, break; case VIR_DOMAIN_DEVICE_DIMM: +if (!(dimm = virDomainDimmRemove(vmdef, dev-data.dimm))) +return -1; + +virDomainDimmDefFree(dimm); +virDomainDimmDefFree(dev-data.dimm); +dev-data.dimm = NULL; +break; + case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_VIDEO: -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 10/11] qemu: introduce qemuBuildDimmDeviceStr
qemuBuildDimmDeviceStr being introduced is responsible for creating command line argument for '-device' for given dimm device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_command.c | 50 + src/qemu/qemu_command.h | 4 2 files changed, 54 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 68fdab7..ff72f46 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7735,6 +7735,49 @@ qemuBuildChrDeviceCommandLine(virCommandPtr cmd, return 0; } +int +qemuBuildDimmDeviceStr(char **deviceStr, + virDomainDimmDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ +virBuffer buf = VIR_BUFFER_INITIALIZER; + +if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PC_DIMM)) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(%s not supported in this QEMU binary), dev-driver); +goto error; +} + +virBufferAsprintf(buf, %s,id=%s,addr=%d,node=%d,slot=%d,memdev=obj%s, + dev-driver, dev-info.alias, dev-addr, + dev-node, dev-slot, dev-info.alias); + +if (virBufferCheckError(buf) 0) +goto error; + +*deviceStr = virBufferContentAndReset(buf); +return 0; + + error: +virBufferFreeAndReset(buf); +return -1; +} + +static int +qemuBuildDimmDeviceCommandLine(virCommandPtr cmd, + virDomainDimmDefPtr dev, + virQEMUCapsPtr qemuCaps) +{ +char *devstr = NULL; + +if (qemuBuildDimmDeviceStr(devstr, dev, qemuCaps) 0) +return -1; + +virCommandAddArgList(cmd, -device, devstr, NULL); +VIR_FREE(devstr); +return 0; +} + static int qemuBuildDomainLoaderCommandLine(virCommandPtr cmd, virDomainDefPtr def, @@ -9887,6 +9930,13 @@ qemuBuildCommandLine(virConnectPtr conn, goto error; } +if (def-ndimms) { +for (i = 0; i def-ndimms; i++) { +if (qemuBuildDimmDeviceCommandLine(cmd, def-dimms[i], qemuCaps) 0) +goto error; +} +} + if (def-nvram) { if (ARCH_IS_PPC64(def-os.arch) STRPREFIX(def-os.machine, pseries)) { diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 512d444..c9d2eb7 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -148,6 +148,10 @@ char *qemuBuildMemballoonDevStr(virDomainDefPtr domainDef, virDomainMemballoonDefPtr dev, virQEMUCapsPtr qemuCaps); +int qemuBuildDimmDeviceStr(char **deviceStr, + virDomainDimmDefPtr dimm, + virQEMUCapsPtr qemuCaps); + char *qemuBuildUSBInputDevStr(virDomainDefPtr domainDef, virDomainInputDefPtr dev, virQEMUCapsPtr qemuCaps); -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 09/11] qemu: implement support for pc-dimm
This patch adds a new capability bit QEMU_CAPS_PC_DIMM. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 4 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 13f3cd3..42e7e85 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -277,6 +277,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, vmware-svga.vgamem_mb, qxl.vgamem_mb, qxl-vga.vgamem_mb, + pc-dimm, ); @@ -1524,6 +1525,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = { { usb-audio, QEMU_CAPS_OBJECT_USB_AUDIO }, { iothread, QEMU_CAPS_OBJECT_IOTHREAD}, { ivshmem, QEMU_CAPS_DEVICE_IVSHMEM }, +{pc-dimm, QEMU_CAPS_DEVICE_PC_DIMM}, }; static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = { @@ -3121,6 +3123,7 @@ virQEMUCapsInitQMPBasic(virQEMUCapsPtr qemuCaps) virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE); virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY); virQEMUCapsSet(qemuCaps, QEMU_CAPS_HOST_PCI_MULTIDOMAIN); +virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_PC_DIMM); } /* Capabilities that are architecture depending diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 12e1688..bab0cca 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -223,6 +223,7 @@ typedef enum { QEMU_CAPS_VMWARE_SVGA_VGAMEM = 181, /* -device vmware-svga.vgamem_mb */ QEMU_CAPS_QXL_VGAMEM = 182, /* -device qxl.vgamem_mb */ QEMU_CAPS_QXL_VGA_VGAMEM = 183, /* -device qxl-vga.vgamem_mb */ +QEMU_CAPS_DEVICE_PC_DIMM = 184, /* -device pc-dimm */ QEMU_CAPS_LAST, /* this must always be the last item */ } virQEMUCapsFlags; -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 02/11] domain_conf: introduce virDomainDimmGetFreeSlot
Add a bitmap dimm_slot_map to store status of slots. If you want to use a slot, you can find a minimum value which has not been used in the bitmap. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 12 src/conf/domain_conf.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 526f2da..d7f7a9e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12739,6 +12739,9 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } +if (!(def-mem.dimm_slot_map = virBitmapNew(def-mem.slots))) +goto error; + /* and info about it */ if ((tmp = virXPathString(string(./memory[1]/@dumpCore), ctxt)) (def-mem.dump_core = virTristateSwitchTypeFromString(tmp)) = 0) { @@ -16205,6 +16208,15 @@ virDomainDefAddImplicitControllers(virDomainDefPtr def) return 0; } +int +virDomainDimmGetFreeSlot(virDomainDefPtr def) +{ +int i; +i = virBitmapNextClearBit(def-mem.dimm_slot_map, 0); + +return i; +} + /* Check if vcpupin with same vcpuid already exists. * Return 1 if exists, 0 if not. */ int diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 731d14f..d746272 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2021,6 +2021,7 @@ struct _virDomainMemtune { unsigned int slots; /* the maximum slots for memory devices */ unsigned long long maxmem; /* in kibibytes, the maximum memory for the guest */ +virBitmapPtr dimm_slot_map; virDomainHugePagePtr hugepages; size_t nhugepages; @@ -2526,6 +2527,8 @@ int virDomainDefCompatibleDevice(virDomainDefPtr def, virDomainDeviceDefPtr dev, virDomainDeviceAction action); +int virDomainDimmGetFreeSlot(virDomainDefPtr def); + int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list, size_t *nvcpupin, unsigned char *cpumap, -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 01/12] domain_conf: allocate cpu's apic id dynamically
On Wed, Jan 21, 2015 at 16:00:53 +0800, Zhu Guihua wrote: Add a bitmap apic_idmap to store status of APIC IDs. If you want to use an APIC ID, you can find a minimum value which has not been used in the bitmap. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 15 +++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 5 - 4 files changed, 23 insertions(+), 1 deletion(-) ... diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a2eec83..d08e400 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -426,6 +426,7 @@ virDomainVcpuPinDefFree; virDomainVcpuPinDel; virDomainVcpuPinFindByVcpu; virDomainVcpuPinIsDuplicate; +virDomainCPUGetFreeApicID; virDomainVideoDefaultRAM; virDomainVideoDefaultType; virDomainVideoDefFree; make syntax-check enforces that this file is ordered by file and then by function name. Please order this hunk correctly and run make syntax-check before the submission. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 05/11] domain_conf: introduce dimm device hotplug helpers
virDomainDimmFind - to find a dimm within VM def virDomainDimmInsert - wrapper for inserting a new dimm into VM def virDomainDimmRemove - wrapper for removing dimm from VM def Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/conf/domain_conf.c | 60 src/conf/domain_conf.h | 13 +++ src/libvirt_private.syms | 3 +++ 3 files changed, 76 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d4da728..ff39b70 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11790,6 +11790,66 @@ virDomainHasDiskMirror(virDomainObjPtr vm) return false; } +int +virDomainDimmInsert(virDomainDefPtr vmdef, +virDomainDimmDefPtr dimm) +{ +return VIR_APPEND_ELEMENT(vmdef-dimms, vmdef-ndimms, dimm); +} + +bool +virDomainDimmEquals(virDomainDimmDefPtr src, +virDomainDimmDefPtr tgt) +{ +bool ret = false; + +if (!src || !tgt) +return src == tgt; + +if (src-slot == tgt-slot) +ret = true; + +return ret; +} + +virDomainDimmDefPtr +virDomainDimmFind(virDomainDefPtr def, + virDomainDimmDefPtr target) +{ +virDomainDimmDefPtr dimm; +size_t i; + +for (i = 0; i def-ndimms; i++) { +dimm = def-dimms[i]; + +if (virDomainDimmEquals(dimm, target)) +return dimm; +} + +return NULL; +} + +virDomainDimmDefPtr +virDomainDimmRemove(virDomainDefPtr vmdef, +virDomainDimmDefPtr dimm) +{ +virDomainDimmDefPtr ret; +size_t i; + +for (i = 0; i vmdef-ndimms; i++) { +ret = vmdef-dimms[i]; + +if (virDomainDimmEquals(ret, dimm)) +break; +} + +if (i == vmdef-ndimms) +return NULL; + +VIR_DELETE_ELEMENT(vmdef-dimms, i, vmdef-ndimms); +return ret; +} + int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net) { /* hostdev net devices must also exist in the hostdevs array */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4864dc3..b46b28a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2602,6 +2602,19 @@ int virDomainDiskSourceParse(xmlNodePtr node, bool virDomainHasDiskMirror(virDomainObjPtr vm); +int +virDomainDimmInsert(virDomainDefPtr vmdef, +virDomainDimmDefPtr dimm); +bool +virDomainDimmEquals(virDomainDimmDefPtr src, +virDomainDimmDefPtr tgt); +virDomainDimmDefPtr +virDomainDimmFind(virDomainDefPtr def, + virDomainDimmDefPtr dimm); +virDomainDimmDefPtr +virDomainDimmRemove(virDomainDefPtr def, +virDomainDimmDefPtr dimm); + int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net); virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device); int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c5daf5b..092c1c6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -217,6 +217,9 @@ virDomainDeviceInfoCopy; virDomainDeviceInfoIterate; virDomainDeviceTypeToString; virDomainDimmDefFree; +virDomainDimmFind; +virDomainDimmInsert; +virDomainDimmRemove; virDomainDiskBusTypeToString; virDomainDiskCacheTypeFromString; virDomainDiskCacheTypeToString; -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 07/12] qemu: implement support for qemu64-x86_64-cpu
On Wed, Jan 21, 2015 at 16:00:59 +0800, Zhu Guihua wrote: This patch adds a new capability bit QEMU_CAPS_QEMU64_X86_64_CPU. Misleading subject. This patch adds the capability, but does not impelment support for the device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) ... diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 69d0a2a..2ee3e10 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5876,7 +5876,6 @@ qemuBuildRNGDeviceArgs(virCommandPtr cmd, return ret; } - Spurious whitespace change. static char *qemuBuildTPMBackendStr(const virDomainDef *def, virQEMUCapsPtr qemuCaps, const char *emulator) Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 09/12] qemu: implement cpu device hotplug on live level
On Wed, Jan 21, 2015 at 16:01:01 +0800, Zhu Guihua wrote: This patch implements live hotplug of a cpu device. Signed-off-by: Zhu Guihua zhugh.f...@cn.fujitsu.com --- src/qemu/qemu_driver.c | 6 ++ src/qemu/qemu_hotplug.c | 55 + src/qemu/qemu_hotplug.h | 7 +++ 3 files changed, 68 insertions(+) ... diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f6d7667..bff0d14 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1541,6 +1541,61 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, return ret; } +int +qemuDomainCPUInsert(virDomainDefPtr vmdef, +virDomainCPUDefPtr cpu) +{ +if (virDomainCPUFind(vmdef, cpu)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(cpu already exists)); +return -1; +} + +if (virDomainCPUInsert(vmdef, cpu) 0) +return -1; + +return 0; +} + +int qemuDomainAttachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ +int ret = -1; +char *devstr = NULL; +qemuDomainObjPrivatePtr priv = vm-privateData; +virDomainDefPtr vmdef = vm-def; + +if (!virQEMUCapsGet(priv-qemuCaps, QEMU_CAPS_DEVICE)) { +virReportError(VIR_ERR_OPERATION_INVALID, %s, + _(qemu does not support -device)); +goto cleanup;; +} + +if (qemuAssignDeviceCPUAlias(vmdef, cpu, -1) 0) +goto cleanup; + +if (qemuBuildCPUDeviceStr(devstr, cpu, priv-qemuCaps) 0) +goto cleanup; + +if (qemuDomainCPUInsert(vmdef, cpu) 0) +goto cleanup; + +qemuDomainObjEnterMonitor(driver, vm); +if (devstr qemuMonitorAddDevice(priv-mon, devstr) 0) { +qemuDomainObjExitMonitor(driver, vm); +goto cleanup; +} +qemuDomainObjExitMonitor(driver, vm); This function recently changed it's prototype and requires the return value to be checked. Rebasing to upstream will break build. + +ignore_value(virBitmapSetBit(vm-def-apic_id_map, cpu-apic_id)); +ret = 0; + + cleanup: +VIR_FREE(devstr); +return ret; +} + static int qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, virDomainObjPtr vm,a Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [RFC PATCH 00/11] qemu: add support to hotplug memory device
On Wed, Jan 21, 2015 at 16:20:16 +0800, Zhu Guihua wrote: Now qemu has already supported memory hotplug, so this patchset will make libvirt support hotplug memory device for qemu driver. As I'm already working on this I can see a few problems with your series. First, add two parameters slots and maxmem for memory hotplug, and the xml format can be like this. memory slot='10'102400/memory maxMemory1024000/maxMemory Second, memory device's xml format can be like this. dimm driver='pc-dimm' addr='0' node='0' slot='1' Your code states that addr=0 auto-allocates the address, but I don't see any code that would retrieve it afterwards. Without that the migration can't work reliably. backend type='ram' size='131072'/ Your code doesn't support specifying source nodes for the memory device. This wouldn't work with libvirt with numa pinnnig enabled. Aditionally the target numa node mode that is configured in the numatune section is not honored. The hugepage backend (memory-backend-file) part in your impl requires the user to specify the path for the memory device. Libvirt has a lot code that does this detection and it should be reused. /dimm I'm pretty far in my effort so I think it's not worth for you to continue working on this feature. Peter signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] RFC: Building a virtlogd daemon
With QEMU there are a couple of areas where QEMU ends up logging data to a file on the host. - stdout/err - connected to /var/log/libvirt/qemu/$GUEST.log - serial/parallel/console when used with type=file The stdout/err is typically very small, typically only getting data when an error occurs in QEMU resulting in it existing. In the past there was the chance of it getting lots of data - eg spice used to write tonnes of data on stderr during normal operation, so a guest OS could cause large data to be saved to the host log file. This is harder todo now, but still theoretically possible. The serial/parallel/console log files can be arbitrarily sized and under complete control of the guest OS - it can write whatever it wants with no limits. In both these cases we would prefer to be able to limit the amount of data a guest can write to the host file, so we have a finite cap on disk usage. You might suggest using logrotate, but that only runs periodically so between invocations of logrotate the log files can still grow to arbitrary size. This is inherant problem in doing the log rotation out of band / asynchronously OpenStack has a further problem it would like to solve. It wants to record all guest serial port data to a log file, as it has an API for a client user to read historically captured data from the serial port. This is done using type=file chardev At the same time it wants to expose an interactive console for client users to interact with the guest. This is done using type=unix or type=pty chardevs. The obvious problem is that a single serial/parallel/console device can only be connected to one chardev backend at a time. A very long time ago (5-6 years?) I submitted patches to allow multiple chardev backends in QEMU but they were rejected. Downstream projects like OpenStack have considered setting up console log handling service themselves, but my view is that this is a problem that all users of libvirt face, so libvirt should provide a standard solution to it. This avoids each downstream app reinventing the wheel. So I'm intending to create a standalone virtlogd daemon to address this problem. Similarly to virtlockd, it will be able to re-exec itelf so that upgrades can be done with no interruption to logging, and libvirtd will talk to it over a simple RPC protocol. - For stdout/stderr - libvirtd will ask virtlogd will provide a pipe FD that can be connected to the guest stdout/err, in the sme way libvirtd provides a file FD today. - virtlogd will read from this pipe and write the data to /var/log/libvirt/qemu/$GUEST.log - virtlogd will either truncate or rotate the $GUEST.log file when it reaches a declared certain size limit. - For serial/parallel/console - libvirtd will ask virtlogd to setup a pair of UNIX domain sockets listening on /var/run/virtlogd/qemu/$GUEST.guest /var/run/virtlogd/qemu/$GUEST.client - libvirtd will ask virtlogd to (optionally) write the data to a file /var/log/virtlogd/qemu/$GUEST.log (Or /var/log/libvirt/qemu/$GUEST-$DEVICE.log perhaps, where $DEVICE is the alias string from the console, serial or parallel device ?) - QEMU will be told to connect to this $GUEST.guest socket with the type=unix chardev backend - The virDomainOpenConsole API will connect to the $GUEST.client socket - virtlogd will read data from $GUEST.guest socket and write it to $GUEST.client and optionally $GUEST.log too - virtlogd will read data from $GUEST.client socket and write it to $GUEST.guest socket - virtlogd will either truncate or rotate the $GUEST.log file when it reaches a declared certain size limit. So at the end of this we will have strictly size limited log files which can rotated at the size threshold, and the ability to have interactive console sessions and file logging at the same time. Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 7/9] domain_conf: Read and Write quorum config
Add the capabiltty to libvirt to parse and format the quorum syntax as described here: http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/domain_conf.c | 165 +++-- 1 file changed, 120 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 849e63a..64fe06b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5605,20 +5605,58 @@ virDomainDiskSourceParse(xmlNodePtr node, } +static bool +virDomainDiskThresholdParse(virStorageSourcePtr src, +xmlNodePtr node) +{ +char *threshold = virXMLPropString(node, threshold); +int ret; + +if (!threshold) { +virReportError(VIR_ERR_XML_ERROR, + %s, _(missing threshold in quorum)); +return false; +} +ret = virStrToLong_ul(threshold, NULL, 10, src-threshold); +if (ret 0 || src-threshold 2) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unexpected threshold %s), + threshold must be a decimal number superior to 2 + and inferior to the number of children); +VIR_FREE(threshold); +return false; +} +VIR_FREE(threshold); +return true; +} + + static int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, - virStorageSourcePtr src) + virStorageSourcePtr src, + xmlNodePtr node, + size_t pos) { virStorageSourcePtr backingStore = NULL; xmlNodePtr save_ctxt = ctxt-node; -xmlNodePtr source; +xmlNodePtr source = NULL; +xmlNodePtr cur = NULL; char *type = NULL; char *format = NULL; int ret = -1; +size_t i = 0; -if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { -ret = 0; -goto cleanup; +if (src-type == VIR_STORAGE_TYPE_QUORUM) { +if (!node) { +ret = 0; +goto cleanup; +} +ctxt-node = node; +} else { +if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { +ret = 0; +goto cleanup; +} } if (VIR_ALLOC(backingStore) 0) @@ -5650,6 +5688,22 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, goto cleanup; } +if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) { +if (!virDomainDiskThresholdParse(backingStore, node)) +goto cleanup; + +for (cur = node-children, i = 0; cur != NULL; cur = cur-next) { +if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if (virStorageSourcePushBackingStore(backingStore) == false) +goto cleanup; +if ((virDomainDiskBackingStoreParse(ctxt, backingStore, cur, i) 0)) +goto cleanup; +++i; +} +} +goto exit; +} + if (!(source = virXPathNode(./source, ctxt))) { virReportError(VIR_ERR_XML_ERROR, %s, _(missing disk backing store source)); @@ -5657,10 +5711,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, } if (virDomainDiskSourceParse(source, ctxt, backingStore) 0 || -virDomainDiskBackingStoreParse(ctxt, backingStore) 0) +virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0) 0) goto cleanup; -virStorageSourceSetBackingStore(src, backingStore, 0); + exit: +virStorageSourceSetBackingStore(src, backingStore, pos); ret = 0; cleanup: @@ -5672,7 +5727,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, return ret; } - #define VENDOR_LEN 8 #define PRODUCT_LEN 16 @@ -6166,6 +6220,12 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } else if (xmlStrEqual(cur-name, BAD_CAST boot)) { /* boot is parsed as part of virDomainDeviceInfoParseXML */ +} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if (virStorageSourcePushBackingStore(def-src) == false) +goto error; +if (virDomainDiskBackingStoreParse(ctxt, def-src, cur, + def-src-nBackingStores - 1) 0) +goto error; } } cur = cur-next; @@ -6189,12 +6249,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def-device = VIR_DOMAIN_DISK_DEVICE_DISK; } +if (def-src-type == VIR_STORAGE_TYPE_QUORUM +!virDomainDiskThresholdParse(def-src, node)) +goto error; + +snapshot = virXMLPropString(node, snapshot); + /* Only CDROM and Floppy devices are allowed missing source path * to indicate no media present. LUN is for raw access CD-ROMs * that are
[libvirt] [libvirt-test-API][PATCH] Add network_dhcp_leases test case to conf
For running the case, should setup testing environment before the case, and clean up the environment after the case. --- cases/basic_network.conf | 55 1 file changed, 55 insertions(+) diff --git a/cases/basic_network.conf b/cases/basic_network.conf index e9abd57..3ab9cb1 100644 --- a/cases/basic_network.conf +++ b/cases/basic_network.conf @@ -216,3 +216,58 @@ network:destroy networkname $defaultnetname +network:update +networkname +default +command +add-first +section +ip-dhcp-host +xml +xmls/ip-dhcp-host.xml + +domain:install_linux_cdrom +guestname +dhcplease +guestos +rhel6 +guestarch +$defaultarch +vcpu +$defaultvcpu +memory +$defaultmem +hddriver +$defaulthd +nicdriver +$defaultnic +macaddr +00:16:3e:77:e2:ed + +network:network_dhcp_leases +networkname +default + +network:network_dhcp_leases +networkname +default +macaddr +00:16:3e:77:e2:ed + +network:update +networkname +default +command +delete +section +ip-dhcp-host +xml +xmls/ip-dhcp-host.xml + +domain:destroy +guestname +dhcplease + +domain:undefine +guestname +dhcplease -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: add a check when cold-plug a Chr device
On 01/21/2015 08:00 PM, Ján Tomko wrote: On 01/21/2015 04:10 AM, lhuang wrote: On 01/21/2015 03:00 AM, John Ferlan wrote: On 12/09/2014 01:48 AM, Luyao Huang wrote: Add a func just check the base target type which qemu support. But i still doubt this will be useful , we already have a check when we try to start the vm. And this check only check the target type, and the other things will be done in virDomainChrDefParseXML. The commit message needs some massaging. Essentially, this patch fixes the condition where if a guest has been started and someone uses attach-device with (or without) the --config option, then these checks will avoid the next guest being modified, correct? Right This will also cause an error earlier that patch 1/2 as qemuDomainChrInsert is called in the path before qemuDomainAttachDeviceLive Yes and if this patch have been pushed then the patch 1/2 will be a patch for improving exist code. ChrInsert is called after qemuBuildConsoleChrDeviceStr in AttachDevice. We should error out earlier and include the first patch too. Thanks for pointing out, error output more earlier more better :) Signed-off-by: Luyao Huang lhu...@redhat.com --- src/qemu/qemu_hotplug.c | 64 + 1 file changed, 64 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b9a0cee..fe91ec7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1384,10 +1384,74 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver, } +static int +qemuDomainChrCheckDefSupport(virDomainChrDefPtr chr) +{ +int ret = -1; + +switch (chr-deviceType) { +case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: +switch ((virDomainChrSerialTargetType) chr-targetType) { +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: +case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB: +ret = 0; +break; + +default: Typically in switches listing other options rather than default: The point of casting it to virDomainChrSerialTargetType is to catch all the unhandled values and it only works if there's no default: clause. Also I don't think we need the ret variable at all. Just return 0 at the end of the function, or -1 if we reached an unsupported combination. Good idea ! i will remove the ret and use return in these place. I think perhaps this one is better than 1/2, but will see if my responses result in other opinions... Even if this one fixes the bug, 1/2 is nice to have. Thanks for pointing out and i forgot cc Jan and Pavel when sent this patch, maybe they have some other opinions. No need to cc me, I am subscribed to the list. :) I just saw other people cc the people who help review the patch when send a new version patch to upstream, so i think it is better to cc the people who help review the patch when write a new version. Thanks a lot for your review. Jan Luyao -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-test-API][PATCH] Add network_dhcp_leases test case
The network_dhcp_leases.py uses DHCPLeases() to validate new API virNetworkGetDHCPLeases of libvirt. --- repos/network/network_dhcp_leases.py | 277 +++ 1 file changed, 277 insertions(+) create mode 100644 repos/network/network_dhcp_leases.py diff --git a/repos/network/network_dhcp_leases.py b/repos/network/network_dhcp_leases.py new file mode 100644 index 000..29ee529 --- /dev/null +++ b/repos/network/network_dhcp_leases.py @@ -0,0 +1,277 @@ +#!/usr/bin/env python +#test DHCPLeases() API for libvirt + +import os +import time +import libvirt +from libvirt import libvirtError +from utils import utils +from src import sharedmod + +required_params = ('networkname',) +optional_params = {'macaddr': ''} + +LEASE_FILE = /var/lib/libvirt/dnsmasq/ + +def check_ip(ipaddr, logger): + + return a string according to ip address type, return 'ipv4' for ipv4, + return 'ipv6' for ipv6, return False for others + +addr4 = ipaddr.strip().split('.') +addr6 = ipaddr.strip().split(':') +if len(addr4) == 4: +iptype = ipv4 +elif len(addr6) == 6: +iptype = ipv6 +else: +return False +return iptype + +def get_network_type(ipaddr,logger): + + return 0 or 1 for ipv4/ipv6, this function will be used in + check_ipv4_values()/check_ipv6_values() + +if check_ip(ipaddr, logger) == ipv4: +return 0 +elif check_ip(ipaddr, logger) == ipv6: +return 1 + +def get_bridge_name(network,logger): + + get bridge name under specified network from specified network conf + +CONF_NETWORK = LEASE_FILE + network + .conf +GREP_BRIDGE = grep \^interface=\ %s | awk -F\=\ '{print $2}' +status, output = utils.exec_cmd(GREP_BRIDGE % CONF_NETWORK, shell=True) +if not status: +pass +else: +logger.error(\ + GREP_BRIDGE + \ + error) +logger.error(output) +return False +return output[0] + +def get_ip_prefix(network, iptype, logger): + + get ip prefix according to IP type + +br = get_bridge_name(network, logger) +PREFIX = ip -4 -o ad show %s | awk '{print $4}'|awk -F\/\ '{print $2}' +PREFIX_6 = ip -6 -o ad show %s|awk '{print $4}'|awk -F\/\ '{print $2}' +if iptype == ipv4: +status, output = utils.exec_cmd(PREFIX % br, shell=True) +elif iptype == ipv6: +status, output = utils.exec_cmd(PREFIX_6 % br, shell=True) +if not status: +pass +else: +logger.error(\ + GREP_BRIDGE + \ + error) +logger.error(output) +return False +return output[0] + +def get_info_from_dnsmasq(network,macaddr,logger): + + generate dict for lease info from virtual network's lease file + +title = ['expirytime','mac','ipaddr','hostname','clientid'] +output_list = [] +lease_dnsmasq = [] +temp = [] +remove_list = [] +GREP_MAC = grep -w %s + + LEASE_FILE_DNSMASQ +CAT_FILE = cat + + LEASE_FILE_DNSMASQ + +status, output = utils.exec_cmd(CAT_FILE, shell=True) +if not status: +for i in range(0, len(output)): +output_list = [] +output_str = output[i] +for item in output_str.split( ): +output_list.append(item) +lease_dnsmasq.append(dict(zip(title,output_list))) + +#due to no mac field in IPv6 line, so do nothing here temporarily. +if macaddr != None: + pass + +#remove bridge duid line +for i in range(0, len(lease_dnsmasq)): +if lease_dnsmasq[i]['expirytime'] == 'duid': +remove_list.append(lease_dnsmasq[i]) + +for i in range(0, len(remove_list)): +lease_dnsmasq.remove(remove_list[i]) + +#remove expiry leases +for i in range(0, len(lease_dnsmasq)): +temp = int(lease_dnsmasq[i]['expirytime']) +lease_dnsmasq[i]['expirytime'] = temp + +remove_list = [] +for i in range(0, len(lease_dnsmasq)): +if time.time() = int(lease_dnsmasq[i]['expirytime']): +remove_list.append(lease_dnsmasq[i]) + +for i in range(0, len(remove_list)): +lease_dnsmasq.remove(remove_list[i]) + +#replace * to None +for i in range(0, len(lease_dnsmasq)): +if lease_dnsmasq[i]['hostname'] == *: +lease_dnsmasq[i]['hostname'] = None +if lease_dnsmasq[i]['clientid'] == *: +lease_dnsmasq[i]['clientid'] = None + +return lease_dnsmasq +else: +logger.error(\ + CAT_FILE + \ + error) +logger.error(output) +return False + +def compare_values(op1, op2, network, iptype, logger): + + check all printed values from API + +dnsmasq = op1 +api = op2 +temp = int(api['expirytime']) +api['expirytime'] = temp + +for j in range(0,len(dnsmasq)): +if dnsmasq[j]['hostname'] == api['hostname'] and \
Re: [libvirt] [PATCH 1/2] Introduce btrfsCloneFile for btrfs COW copy
On 01/21/2015 08:06 AM, Chen, Hanxiao wrote: -Original Message- From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com] On Behalf Of Chen, Hanxiao Sent: Monday, January 19, 2015 2:26 PM To: Ján Tomko; libvir-list@redhat.com Subject: Re: [libvirt] [PATCH 1/2] Introduce btrfsCloneFile for btrfs COW copy -Original Message- From: Ján Tomko [mailto:jto...@redhat.com] Sent: Friday, January 16, 2015 10:21 PM To: Chen, Hanxiao/陈 晗霄; libvir-list@redhat.com [snip] +#define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int) + Instead of redefining the constants, can we check for btrfs.h at configure time and wrap the function in #ifdef BTRFS_IOC_CLONE ? We need to install btrfs-progs-devel for BTRFS_IOC_CLONE in btrfs/ioctl.h. So it should be easy to just define magic number and issue a ioctl, than add a dependency on btrfs-progs-devel. Do we need to add a LIBVIRT_CHECK_PKG for btrfs-progs-devel? I can see BTRFS_IOC_CLONE in linux/btrfs.h, which is part of kernel-headers on RHEL 7. Anyway, we should be checking for the header file via AC_CHECK_HEADER (preferably only when we're building with the storage driver that will use it), not a distro-specific package name. Jan signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] RFC: Building a virtlogd daemon
Very good idea! 2015-01-21 15:12 GMT+03:00 Daniel P. Berrange berra...@redhat.com: With QEMU there are a couple of areas where QEMU ends up logging data to a file on the host. - stdout/err - connected to /var/log/libvirt/qemu/$GUEST.log - serial/parallel/console when used with type=file The stdout/err is typically very small, typically only getting data when an error occurs in QEMU resulting in it existing. In the past there was the chance of it getting lots of data - eg spice used to write tonnes of data on stderr during normal operation, so a guest OS could cause large data to be saved to the host log file. This is harder todo now, but still theoretically possible. The serial/parallel/console log files can be arbitrarily sized and under complete control of the guest OS - it can write whatever it wants with no limits. In both these cases we would prefer to be able to limit the amount of data a guest can write to the host file, so we have a finite cap on disk usage. You might suggest using logrotate, but that only runs periodically so between invocations of logrotate the log files can still grow to arbitrary size. This is inherant problem in doing the log rotation out of band / asynchronously OpenStack has a further problem it would like to solve. It wants to record all guest serial port data to a log file, as it has an API for a client user to read historically captured data from the serial port. This is done using type=file chardev At the same time it wants to expose an interactive console for client users to interact with the guest. This is done using type=unix or type=pty chardevs. The obvious problem is that a single serial/parallel/console device can only be connected to one chardev backend at a time. A very long time ago (5-6 years?) I submitted patches to allow multiple chardev backends in QEMU but they were rejected. Downstream projects like OpenStack have considered setting up console log handling service themselves, but my view is that this is a problem that all users of libvirt face, so libvirt should provide a standard solution to it. This avoids each downstream app reinventing the wheel. So I'm intending to create a standalone virtlogd daemon to address this problem. Similarly to virtlockd, it will be able to re-exec itelf so that upgrades can be done with no interruption to logging, and libvirtd will talk to it over a simple RPC protocol. - For stdout/stderr - libvirtd will ask virtlogd will provide a pipe FD that can be connected to the guest stdout/err, in the sme way libvirtd provides a file FD today. - virtlogd will read from this pipe and write the data to /var/log/libvirt/qemu/$GUEST.log - virtlogd will either truncate or rotate the $GUEST.log file when it reaches a declared certain size limit. - For serial/parallel/console - libvirtd will ask virtlogd to setup a pair of UNIX domain sockets listening on /var/run/virtlogd/qemu/$GUEST.guest /var/run/virtlogd/qemu/$GUEST.client - libvirtd will ask virtlogd to (optionally) write the data to a file /var/log/virtlogd/qemu/$GUEST.log (Or /var/log/libvirt/qemu/$GUEST-$DEVICE.log perhaps, where $DEVICE is the alias string from the console, serial or parallel device ?) - QEMU will be told to connect to this $GUEST.guest socket with the type=unix chardev backend - The virDomainOpenConsole API will connect to the $GUEST.client socket - virtlogd will read data from $GUEST.guest socket and write it to $GUEST.client and optionally $GUEST.log too - virtlogd will read data from $GUEST.client socket and write it to $GUEST.guest socket - virtlogd will either truncate or rotate the $GUEST.log file when it reaches a declared certain size limit. So at the end of this we will have strictly size limited log files which can rotated at the size threshold, and the ability to have interactive console sessions and file logging at the same time. Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- Vasiliy Tolstov, e-mail: v.tols...@selfip.ru jabber: v...@selfip.ru -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 0/9] qemu: Add quorum support to libvirt
The purpose of these patches is to introduce quorum for libvirt I've try to follow this proposal: http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html This feature ask for 6 task: 1) Allow a _virStorageSource to contain more than one backing store. Therefore we have to treat the field virStorageSourcePtr backingStores as an array instead of a pointer. But doing that, most of the backingStore field would be an array contening only one element. So I've decide to allocate the array only if there is more than 1 backing store in a _virStorageSource. Because all the actual libvirt code use the backingStore field as a pointer and we needs want to change that, I've decide to encapsulate the backingStore field to simplifie the array manipulation. 2) Add the missing field a quorum need in _virStorageSource and the VIR_STORAGE_TYPE_QUORUM and VIR_STORAGE_FILE_QUORUM in their respectives enums. 3) Parse and format the xml Because a quorum allows to have more than one backing store at the same level we need to change virDomainDiskDefFormat and virDomainDiskDefParseXML to call virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse in a loop. virDomainDiskBackingStoreFormat and virDomainDiskBackingStoreParse can call themself recursively in a loop because a quorum can contain another quorum 4) Add nodename We need to add nodename support in _virStorageSource because qemu use them for their child. 5) Build qemu string As for the xml, we have to call the function which create quorum recursively. But this task have the problem explained here: http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html The _virStorageSource missing some informations that can be passed to a child, and therefore this version of quorum is incomplet. 6) Allow to hotplug/change a disk in a quorum This part is not present in these patches because for this task we have to use blockdev-add, and currently libvirt use device_add for hotpluging that doesn't allow to hotplug quorum childs. There is 3 way to handle this problem: 1) create a virDomainBlockDevAdd function in libvirt witch call blockdev-add. 2) use blockdev-add instead of device_add in qemuMonitorJSONAddDevice 3) write a hack which uses blockdev-add when only attaching quorum (but i'm pretty sure this solution is not the good one) V2: -Rebase on master -Add Documentation Matthias Gatto (9): virstoragefile: Add virStorageSourceGetBackingStore virstoragefile: Always use virStorageSourceGetBackingStore to get backing store virstoragefile: Add virStorageSourceSetBackingStore virstoragefile: Always use virStorageSourceSetBackingStore to set backing store virstoragefile: Treat backingStore as a pointer or an array virstoragefile: Add quorum in virstoragefile domain_conf: Read and Write quorum config qemu: Add quorum support in qemuBuildDriveDevStr virstoragefile: Add node-name docs/formatdomain.html.in | 27 - docs/schemas/storagecommon.rng| 1 + docs/schemas/storagevol.rng | 1 + src/conf/domain_conf.c| 193 ++ src/conf/storage_conf.c | 25 +++-- src/libvirt_private.syms | 3 + src/qemu/qemu_cgroup.c| 4 +- src/qemu/qemu_command.c | 114 src/qemu/qemu_domain.c| 2 +- src/qemu/qemu_driver.c| 20 ++-- src/qemu/qemu_migration.c | 1 + src/security/security_dac.c | 2 +- src/security/security_selinux.c | 4 +- src/security/virt-aa-helper.c | 2 +- src/storage/storage_backend.c | 30 +++--- src/storage/storage_backend_fs.c | 35 +++--- src/storage/storage_backend_gluster.c | 8 +- src/storage/storage_backend_logical.c | 8 +- src/storage/storage_driver.c | 2 +- src/util/virstoragefile.c | 138 +--- src/util/virstoragefile.h | 12 +++ tests/virstoragetest.c| 18 ++-- 22 files changed, 518 insertions(+), 132 deletions(-) -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 3/9] virstoragefile: Add virStorageSourceSetBackingStore
As explained for virStorageSourceGetBackingStore, quorum allows multiple backing store, this make the operation to set bs complex because we have to check if the backingStore is used as an array or a pointer, and set it differently in both case. In order to help the manipulation of backing store, I've added a function virStorageSourceSetBackingStore. For now virStorageSourceSetBackingStore don't handle the case where we have more than one backing store in virStorageSource. Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 10 ++ src/util/virstoragefile.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3f4d02c..980235b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2033,6 +2033,7 @@ virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; +virStorageSourceSetBackingStore; virStorageTypeFromString; virStorageTypeToString; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 052debf..84eefa3 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1806,6 +1806,16 @@ virStorageSourceGetBackingStore(const virStorageSource *src, } +virStorageSourcePtr +virStorageSourceSetBackingStore(virStorageSourcePtr src, +virStorageSourcePtr backingStore, +size_t pos ATTRIBUTE_UNUSED) +{ +src-backingStore = backingStore; +return src-backingStore; +} + + /** * virStorageSourcePtr: * diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index c37ddcf..d5cf7e6 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -289,6 +289,9 @@ struct _virStorageSource { # define DEV_BSIZE 512 # endif +virStorageSourcePtr virStorageSourceSetBackingStore(virStorageSourcePtr src, +virStorageSourcePtr backingStore, +size_t pos); virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos); -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] Entering freeze for libvirt-1.2.12
As planned I tagged the release candidate 1 in git and pushed signed tarballs and rpms to the usual place: ftp://libvirt.org/libvirt/ Seems to work fine for me, but my testing is limited. Give it a try especially on other architectures or OSes. Plan is to release an rc2 by the dn of the week and the final next Tuesday assuming everythings goes smoothly ! thanks, Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veill...@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 2/9] virstoragefile: Always use virStorageSourceGetBackingStore to get backing store
Uniformize backing store usage by calling virStorageSourceGetBackingStore instead of setting backing store manually. Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/domain_conf.c| 7 --- src/conf/storage_conf.c | 18 ++ src/qemu/qemu_cgroup.c| 4 ++-- src/qemu/qemu_domain.c| 2 +- src/qemu/qemu_driver.c| 12 ++-- src/security/security_dac.c | 2 +- src/security/security_selinux.c | 4 ++-- src/security/virt-aa-helper.c | 2 +- src/storage/storage_backend.c | 30 -- src/storage/storage_backend_fs.c | 31 +-- src/storage/storage_backend_gluster.c | 8 +--- src/storage/storage_backend_logical.c | 6 +++--- src/util/virstoragefile.c | 20 ++-- tests/virstoragetest.c| 14 +++--- 14 files changed, 85 insertions(+), 75 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8792f5e..0668a5b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16704,7 +16704,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, /* We currently don't output seclabels for backing chain element */ if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) 0 || virDomainDiskBackingStoreFormat(buf, -backingStore-backingStore, + virStorageSourceGetBackingStore(backingStore, 0), backingStore-backingStoreRaw, idx + 1) 0) return -1; @@ -16826,7 +16826,8 @@ virDomainDiskDefFormat(virBufferPtr buf, /* Don't format backingStore to inactive XMLs until the code for * persistent storage of backing chains is ready. */ if (!(flags VIR_DOMAIN_DEF_FORMAT_INACTIVE) -virDomainDiskBackingStoreFormat(buf, def-src-backingStore, +virDomainDiskBackingStoreFormat(buf, + virStorageSourceGetBackingStore(def-src, 0), def-src-backingStoreRaw, 1) 0) return -1; @@ -20868,7 +20869,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, } } -for (tmp = disk-src; tmp; tmp = tmp-backingStore) { +for (tmp = disk-src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) { int actualType = virStorageSourceGetActualType(tmp); /* execute the callback only for local storage */ if (actualType != VIR_STORAGE_TYPE_NETWORK diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index e9aaa8a..f4f7e24 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1339,20 +1339,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, } if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) { +virStorageSourcePtr backingStorePtr; if (VIR_ALLOC(ret-target.backingStore) 0) goto error; -ret-target.backingStore-path = backingStore; +backingStorePtr = virStorageSourceGetBackingStore(ret-target, 0); +backingStorePtr-path = backingStore; backingStore = NULL; if (options-formatFromString) { char *format = virXPathString(string(./backingStore/format/@type), ctxt); if (format == NULL) -ret-target.backingStore-format = options-defaultFormat; +backingStorePtr-format = options-defaultFormat; else -ret-target.backingStore-format = (options-formatFromString)(format); +backingStorePtr-format = (options-formatFromString)(format); -if (ret-target.backingStore-format 0) { +if (backingStorePtr-format 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(unknown volume format type %s), format); VIR_FREE(format); @@ -1361,9 +1363,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, VIR_FREE(format); } -if (VIR_ALLOC(ret-target.backingStore-perms) 0) +if (VIR_ALLOC(backingStorePtr-perms) 0) goto error; -if (virStorageDefParsePerms(ctxt, ret-target.backingStore-perms, +if (virStorageDefParsePerms(ctxt, backingStorePtr-perms, ./backingStore/permissions, DEFAULT_VOL_PERM_MODE) 0) goto error; @@ -1641,9 +1643,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, def-target, target) 0) goto cleanup; -if (def-target.backingStore +if (virStorageSourceGetBackingStore((def-target), 0) virStorageVolTargetDefFormat(options, buf, -
[libvirt] [PATCH v2 8/9] qemu: Add quorum support in qemuBuildDriveDevStr
Allow to libvirt to build the quorum string used by quemu. Add 2 static functions: qemuBuildQuorumStr and qemuBuildAndAppendDriveStrToVirBuffer. qemuBuildQuorumStr is made because a quorum can have another quorum as a child, so we may need to call qemuBuildQuorumStr recursively. qemuBuildQuorumFileSourceStr was basically made to share the code use to build the source between qemuBuildQuorumStr and qemuBuildDriveStr, but there is some difference betwin the syntax use by libvirt to declare a disk and the one qemu need to build a quorum: a quorum need a syntaxe like: domaine_name.children.X.file.filename=filename where libvirt don't use file.filename= but directly file=. Therfore I use this function only for quorum. But as explained in the cover letter and here: http://www.redhat.com/archives/libvir-list/2014-October/msg00529.html We miss some informations in _virStorageSource to have a complet quorum support in libvirt. Ideally I'd like to refactore virDomainDiskDefFormat to allow qemuBuildQuorumStr to call this function in a loop. Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/qemu/qemu_command.c | 110 1 file changed, 110 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2ee3ac3..be7f66c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3185,6 +3185,111 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk) return -1; } +static bool +qemuBuildQuorumFileSourceStr(virConnectPtr conn, + virStorageSourcePtr src, + virBuffer *opt, + const char *toAppend) +{ +char *source = NULL; +int actualType = virStorageSourceGetActualType(src); + +if (qemuGetDriveSourceString(src, conn, source) 0) +goto error; + +if (source) { + +virBufferAsprintf(opt, ,%sfilename=, toAppend); + +switch (actualType) { +case VIR_STORAGE_TYPE_DIR: +/* QEMU only supports magic FAT format for now */ +if (src-format 0 +src-format != VIR_STORAGE_FILE_FAT) { +virReportError(VIR_ERR_INTERNAL_ERROR, + _(unsupported disk driver type for '%s'), + virStorageFileFormatTypeToString(src-format)); +goto error; +} + +if (!src-readonly) { +virReportError(VIR_ERR_INTERNAL_ERROR, %s, + _(cannot create virtual FAT disks in read-write mode)); +goto error; +} + +virBufferAddLit(opt, fat:); + +break; + +default: +break; +} +virBufferAsprintf(opt, %s, source); +} + +return true; + error: +return false; +} + + +static bool +qemuBuildQuorumStr(virConnectPtr conn, + virDomainDiskDefPtr disk, + virStorageSourcePtr src, + virBuffer *opt, + const char *toAppend) +{ +char *tmp = NULL; +int ret; +virStorageSourcePtr backingStore; +size_t i; + +if (!src-threshold) { +virReportError(VIR_ERR_INTERNAL_ERROR, %s, + _(threshold missing in the quorum configuration)); +return false; +} +if (src-nBackingStores 2) { +virReportError(VIR_ERR_INTERNAL_ERROR, %s, + _(a quorum must have at last 2 children)); +return false; +} +if (src-threshold src-nBackingStores) { +virReportError(VIR_ERR_INTERNAL_ERROR, %s, + _(threshold must not exceed the number of childrens)); +return false; +} +virBufferAsprintf(opt, ,%svote-threshold=%lu, + toAppend, src-threshold); +for (i = 0; i src-nBackingStores; ++i) { +backingStore = virStorageSourceGetBackingStore(src, i); +ret = virAsprintf(tmp, %schildren.%lu.file., toAppend, i); +if (ret 0) +return false; + +virBufferAsprintf(opt, ,%schildren.%lu.driver=%s, + toAppend, i, + virStorageFileFormatTypeToString(backingStore-format)); + +if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == false) +goto error; + +/* This operation avoid me to made another copy */ +tmp[ret - sizeof(file)] = '\0'; +if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) { +if (!qemuBuildQuorumStr(conn, disk, backingStore, opt, tmp)) +goto error; +} +VIR_FREE(tmp); +} +return true; + error: +VIR_FREE(tmp); +return false; +} + /* Qemu 1.2 and later have a binary flag -enable-fips that must be * used for VNC auth to obey FIPS settings; but the flag only @@ -3657,6 +3762,11 @@ qemuBuildDriveStr(virConnectPtr conn,
[libvirt] [PATCH v2 5/9] virstoragefile: Treat backingStore as a pointer or an array
As explain in the former patchs, backingStore can be treat an array or a pointer. If we have only one backingStore we have to use it as a normal ptr but if there is more backing store, we use it as a pointer's array. Because it would be complicated to expend backingStore manually, and do the convertion from a pointer to an array, I've created the virStorageSourcePushBackingStore function to help. This function allocate an array of pointer only if there is more than 1 bs. Because we can not remove a child from a quorum, i didn't create the function virStorageSourcePopBackingStore. I've changed virStorageSourceBackingStoreClear, virStorageSourceSetBackingStore and virStorageSourceGetBackingStore to handle the case where backingStore is an array. Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/storage_conf.c | 7 ++- src/libvirt_private.syms | 1 + src/storage/storage_backend_fs.c | 2 + src/storage/storage_backend_logical.c | 2 +- src/util/virstoragefile.c | 89 --- src/util/virstoragefile.h | 2 + 6 files changed, 94 insertions(+), 9 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index fac85fa..41887eb 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1343,7 +1343,12 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (VIR_ALLOC(backingStorePtr) 0) goto error; -backingStorePtr = virStorageSourceSetBackingStore(ret-target, backingStorePtr, 0); +if (!virStorageSourcePushBackingStore(ret-target)) +goto error; + +backingStorePtr = virStorageSourceSetBackingStore(ret-target, + backingStorePtr, + ret-target.nBackingStores - 1); backingStorePtr-path = backingStore; backingStore = NULL; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 980235b..5752907 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2033,6 +2033,7 @@ virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; +virStorageSourcePushBackingStore; virStorageSourceSetBackingStore; virStorageTypeFromString; virStorageTypeToString; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index a3b6688..0d8c5ad 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -112,6 +112,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, if (VIR_ALLOC(backingStore) 0) goto cleanup; +if (virStorageSourcePushBackingStore(target) == false) +goto cleanup; virStorageSourceSetBackingStore(target, backingStore, 0); backingStore-type = VIR_STORAGE_TYPE_NETWORK; backingStore-path = meta-backingStoreRaw; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index fcec31f..cd8de85 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -148,7 +148,7 @@ virStorageBackendLogicalMakeVol(char **const groups, * lv is created with --virtualsize). */ if (groups[1] !STREQ(groups[1], ) (groups[1][0] != '[')) { -if (VIR_ALLOC(vol-target.backingStore) 0) +if (virStorageSourcePushBackingStore(vol-target) == false) goto cleanup; if (virAsprintf(virStorageSourceGetBackingStore(vol-target, 0)-path, %s/%s, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index ba38827..554aa8b 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1798,21 +1798,88 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src) } +/** + * virStorageSourceGetBackingStore: + * @src: virStorageSourcePtr containing the backing stores + * @pos: position of the backing store to get + * + * return the backingStore at the position of @pos + */ virStorageSourcePtr -virStorageSourceGetBackingStore(const virStorageSource *src, -size_t pos ATTRIBUTE_UNUSED) +virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos) +{ +if (!src-backingStore || (pos 1 pos = src-nBackingStores)) +return NULL; +if (src-nBackingStores 2) +return src-backingStore; +return ((virStorageSourcePtr *)src-backingStore)[pos]; +} + + +/** + * virStorageSourcePushBackingStore: + * @src: virStorageSourcePtr to allocate the new backing store + * + * Allocate size for a new backingStorePtr in src-backingStore + * and update src-nBackingStores + * If we have less than 2 backing stores, we treat src-backingStore + * as a pointer otherwise we treat it as an array of virStorageSourcePtr + */ +bool
[libvirt] [PATCH v2 9/9] virstoragefile: Add node-name
Add nodename inside virstoragefile During xml backingStore parsing, look for a nodename attribute in the disk declaration if this one is a quorum, if a nodename is found, add it to the virStorageSource otherwise create a new one with a random name. Take inspiration from this patch to create the nodename: http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03209.html Durring xml backingStore formating, look for a nodename attribute inside the virStorageSource struct, and add it to the disk element. Use the nodename to create the quorum in qemuBuildQuorumStr. Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- docs/formatdomain.html.in | 7 +++ src/conf/domain_conf.c| 25 + src/qemu/qemu_command.c | 3 +++ src/util/virstoragefile.c | 4 src/util/virstoragefile.h | 1 + 5 files changed, 40 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 7ab8cbb..1e1baf8 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2135,6 +2135,13 @@ codevda[2]/code refers to the backing store with codeindex='2'/code of the disk with codevda/code target. /dd + dtcodenodename/code attribute + span class=sincesince 1.2.13/span/dt + dd +When the backing store is a quorum child, we can use this attribute +to define the node-name of a child. If this atribute is undefine, +a random nodename is generate. + /dd dtcodeformat/code sub-element/dt dd The codeformat/code element contains codetype/code diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 64fe06b..e674960 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -56,6 +56,7 @@ #include network_conf.h #include virtpm.h #include virstring.h +#include virrandom.h #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -5631,6 +5632,8 @@ virDomainDiskThresholdParse(virStorageSourcePtr src, } +#define GEN_NODE_NAME_PREFIXlibvirt +#define GEN_NODE_NAME_MAX_LEN (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8) static int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, virStorageSourcePtr src, @@ -5642,6 +5645,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, xmlNodePtr source = NULL; xmlNodePtr cur = NULL; char *type = NULL; +char *nodeName = NULL; char *format = NULL; int ret = -1; size_t i = 0; @@ -5675,6 +5679,23 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, goto cleanup; } +if (src-type == VIR_STORAGE_TYPE_QUORUM) { +if ((nodeName = virXMLPropString(ctxt-node, nodename))) { +backingStore-nodeName = nodeName; +} else { +int len; +if (VIR_ALLOC_N(nodeName, GEN_NODE_NAME_MAX_LEN) 0) +goto cleanup; +snprintf(nodeName, GEN_NODE_NAME_MAX_LEN, + %s%08x, GEN_NODE_NAME_PREFIX, (int)pos); +len = strlen(nodeName); +while (len GEN_NODE_NAME_MAX_LEN - 1) +nodeName[len++] = virRandomInt('Z' - 'A') + 'A'; +nodeName[GEN_NODE_NAME_MAX_LEN - 1] = '\0'; +backingStore-nodeName = nodeName; +} +} + if (!(format = virXPathString(string(./format/@type), ctxt))) { virReportError(VIR_ERR_XML_ERROR, %s, _(missing disk backing store format)); @@ -5726,6 +5747,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, ctxt-node = save_ctxt; return ret; } +#undef GEN_NODE_NAME_PREFIX +#undef GEN_NODE_NAME_MAX_LEN #define VENDOR_LEN 8 #define PRODUCT_LEN 16 @@ -16770,6 +16793,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, type, idx); if (backingStore-threshold) virBufferAsprintf(buf, threshold='%lu', backingStore-threshold); +if (backingStore-nodeName) +virBufferAsprintf(buf, nodename='%s', backingStore-nodeName); virBufferAddLit(buf, \n); virBufferAdjustIndent(buf, 2); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index be7f66c..5a5e9cd 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3273,6 +3273,9 @@ qemuBuildQuorumStr(virConnectPtr conn, toAppend, i, virStorageFileFormatTypeToString(backingStore-format)); +virBufferAsprintf(opt, ,%schildren.%lu.node-name=%s, + toAppend, i, backingStore-nodeName); + if (qemuBuildQuorumFileSourceStr(conn, backingStore, opt, tmp) == false) goto error; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d0aa404..1623618 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1961,6 +1961,9 @@ virStorageSourceCopy(const virStorageSource *src, !(ret-auth =
[libvirt] [PATCH v2 1/9] virstoragefile: Add virStorageSourceGetBackingStore
Create virStorageSourceGetBackingStore function in preparation for quorum: Actually, if we want to get a backing store inside a virStorageSource we have to do it manually(src-backingStore = backingStore). The problem is that with a quorum, a virStorageSource can contain multiple backing stores, and src-backingStore can be treated as a virStorageSourcePtr or a virStorageSourcePtrPtr. Due to these reason, we need to simplify the manipulation of virStorageSource, and create a function to get the asked backingStore in a virStorageSource For now, this function only return the backingStore field Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 8 src/util/virstoragefile.h | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a2eec83..3f4d02c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2023,6 +2023,7 @@ virStorageSourceClear; virStorageSourceCopy; virStorageSourceFree; virStorageSourceGetActualType; +virStorageSourceGetBackingStore; virStorageSourceGetSecurityLabelDef; virStorageSourceInitChainElement; virStorageSourceIsEmpty; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 7a4f9a0..dc6cf8f 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1798,6 +1798,14 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src) } +virStorageSourcePtr +virStorageSourceGetBackingStore(const virStorageSource *src, +size_t pos ATTRIBUTE_UNUSED) +{ +return src-backingStore; +} + + /** * virStorageSourcePtr: * diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index b4c3808..c37ddcf 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -289,6 +289,9 @@ struct _virStorageSource { # define DEV_BSIZE 512 # endif +virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource *src, +size_t pos); + int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid); int virStorageFileProbeFormatFromBuf(const char *path, char *buf, -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 6/9] virstoragefile: Add quorum in virstoragefile
Add VIR_STORAGE_TYPE_QUORUM in virStorageType. Add VIR_STORAGE_FILE_QUORUM in virStorageFileFormat. Add threshold value in _virStorageSource Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- docs/formatdomain.html.in | 20 ++-- docs/schemas/storagecommon.rng | 1 + docs/schemas/storagevol.rng| 1 + src/conf/domain_conf.c | 2 ++ src/qemu/qemu_command.c| 1 + src/qemu/qemu_driver.c | 4 src/qemu/qemu_migration.c | 1 + src/util/virstoragefile.c | 25 + src/util/virstoragefile.h | 3 +++ 9 files changed, 48 insertions(+), 10 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f8d5f89..7ab8cbb 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1839,8 +1839,9 @@ dd Valid values are file, block, dir (span class=sincesince 0.7.5/span), -network (span class=sincesince 0.8.7/span), or -volume (span class=sincesince 1.0.5/span) +network (span class=sincesince 0.8.7/span), +volume (span class=sincesince 1.0.5/span), or +quorum (span class=sincesince 1.2.13/span) and refer to the underlying source for the disk. /dd dtcodedevice/code attribute @@ -1901,6 +1902,14 @@ codesnapshot='yes'/code with a transient disk generally does not make sense. /dd + dtcodethreshold/code attribute + span class=sincesince 1.2.13/span/dt +dd +Only use with a quorum disk. +Indicate the minimum of positive vote a quorum must have to validate +a data to be write. The minimum value is 2. The number of backingStores +contain by the quorum must be superior to the threshold. +/dd /dl /dd dtcodesource/code/dt @@ -1971,6 +1980,11 @@ 'file=/dev/disk/by-path/ip-example.com:3260-iscsi-iqn.2013-07.com.example:iscsi-pool-lun-1'). /p /dd +dtcodetype='quorum'/code +span class=sincesince 1.2.13/span/dt + dd + A quorum contain no source element, but a serie of backingStores instead. + /dd /dl With file, block, and volume, one or more optional sub-elements codeseclabel/code, a href=#seclabeldescribed @@ -2102,6 +2116,8 @@ codebackingStore/code element means the sibling source is self-contained and is not based on any backing store. The following attributes and sub-elements are supported in +span class=sinceSince 1.2.11/span. This elements is used to +describe a quorum child. codebackingStore/code: dl dtcodetype/code attribute/dt diff --git a/docs/schemas/storagecommon.rng b/docs/schemas/storagecommon.rng index 5f71b10..ba9f485 100644 --- a/docs/schemas/storagecommon.rng +++ b/docs/schemas/storagecommon.rng @@ -76,6 +76,7 @@ valuefat/value valuevhd/value valueploop/value + valuequorum/value ref name='storageFormatBacking'/ /choice /define diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng index 7450547..a718576 100644 --- a/docs/schemas/storagevol.rng +++ b/docs/schemas/storagevol.rng @@ -20,6 +20,7 @@ valuedir/value valuenetwork/value valuenetdir/value +valuequorum/value /choice /attribute /optional diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d6b888..849e63a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5581,6 +5581,7 @@ virDomainDiskSourceParse(xmlNodePtr node, if (virDomainDiskSourcePoolDefParse(node, src-srcpool) 0) goto cleanup; break; +case VIR_STORAGE_TYPE_QUORUM: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -16643,6 +16644,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf, skipSeclabels); break; +case VIR_STORAGE_TYPE_QUORUM: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7e1f3d0..2ee3ac3 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3104,6 +3104,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src, goto cleanup; break; +case VIR_STORAGE_TYPE_QUORUM: case VIR_STORAGE_TYPE_VOLUME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b3afccd..88a24fb 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12984,6 +12984,7 @@
Re: [libvirt] [PATCH v2] systemd: fix build without dbus
On 01/19/2015 02:36 PM, Daniel P. Berrange wrote: The virDBusMethodCall method has a DBusError as one of its parameters. If the caller wants to pass a non-NULL value for this, it immediately makes the calling code require DBus at build time. This has led to breakage of non-DBus builds several times. It is desirable that only the virdbus.c file should need WITH_DBUS conditionals, so we must ideally remove the DBusError parameter from the method. We can't simply raise a libvirt error, since the whole point of this parameter is to give the callers a way to check if the error is one they want to ignore, without having the logs polluted with an error message. So, we add a virErrorPtr parameter which the caller can then either ignore or raise using virSetError. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- src/util/virdbus.c | 31 +++ src/util/virdbus.h | 4 ++-- src/util/virfirewall.c | 29 ++--- src/util/virsystemd.c | 15 +++ 4 files changed, 34 insertions(+), 45 deletions(-) In v2: - Removed left over debug statements diff --git a/src/util/virdbus.c b/src/util/virdbus.c index d9665c1..3522ae0 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -1522,7 +1522,7 @@ static int virDBusCall(DBusConnection *conn, DBusMessage *call, DBusMessage **replyout, -DBusError *error) +virErrorPtr error) { DBusMessage *reply = NULL; @@ -1530,8 +1530,9 @@ virDBusCall(DBusConnection *conn, int ret = -1; const char *iface, *member, *path, *dest; -if (!error) -dbus_error_init(localerror); +dbus_error_init(localerror); +if (error) +memset(error, 0, sizeof(*error)); iface = dbus_message_get_interface(call); member = dbus_message_get_member(call); @@ -1545,13 +1546,20 @@ virDBusCall(DBusConnection *conn, if (!(reply = dbus_connection_send_with_reply_and_block(conn, call, VIR_DBUS_METHOD_CALL_TIMEOUT_MILLIS, -error ? error : localerror))) { +localerror))) { PROBE(DBUS_METHOD_ERROR, '%s.%s' on '%s' at '%s' error %s: %s, iface, member, path, dest, - error ? error-name : localerror.name, - error ? error-message : localerror.message); + localerror.name, + localerror.message); if (error) { +error-level = VIR_ERR_ERROR; +error-code = VIR_ERR_DBUS_SERVICE; +error-domain = VIR_FROM_DBUS; +if (VIR_STRDUP(error-message, localerror.message) 0) +goto cleanup; +if (VIR_STRDUP(error-str1, localerror.name) 0) +goto cleanup; ret = 0; } else { virReportError(VIR_ERR_DBUS_SERVICE, _(%s: %s), member, @@ -1567,8 +1575,9 @@ virDBusCall(DBusConnection *conn, ret = 0; cleanup: -if (!error) -dbus_error_free(localerror); +if (ret 0 error) +virResetError(error); +dbus_error_free(localerror); if (reply) { if (ret == 0 replyout) *replyout = reply; @@ -1616,7 +1625,7 @@ virDBusCall(DBusConnection *conn, */ int virDBusCallMethod(DBusConnection *conn, DBusMessage **replyout, - DBusError *error, + virErrorPtr error, const char *destination, const char *path, const char *iface, @@ -1634,8 +1643,6 @@ int virDBusCallMethod(DBusConnection *conn, if (ret 0) goto cleanup; -ret = -1; - ret = virDBusCall(conn, call, replyout, error); cleanup: @@ -1832,7 +1839,7 @@ int virDBusCreateReply(DBusMessage **reply ATTRIBUTE_UNUSED, int virDBusCallMethod(DBusConnection *conn ATTRIBUTE_UNUSED, DBusMessage **reply ATTRIBUTE_UNUSED, - DBusError *error ATTRIBUTE_UNUSED, + virErrorPtr error ATTRIBUTE_UNUSED, const char *destination ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, const char *iface ATTRIBUTE_UNUSED, diff --git a/src/util/virdbus.h b/src/util/virdbus.h index d0c7de2..e2b8d2b 100644 --- a/src/util/virdbus.h +++ b/src/util/virdbus.h @@ -28,7 +28,7 @@ # else # define DBusConnection void # define DBusMessage void -# define DBusError void +# define dbus_message_unref(m) do {} while (0) # endif # include internal.h @@ -62,7 +62,7 @@ int virDBusCreateReplyV(DBusMessage **reply, int virDBusCallMethod(DBusConnection *conn, DBusMessage **reply, -
Re: [libvirt] [PATCH v2] systemd: fix build without dbus
On Wed, Jan 21, 2015 at 03:15:31PM +0100, Ján Tomko wrote: On 01/19/2015 02:36 PM, Daniel P. Berrange wrote: The virDBusMethodCall method has a DBusError as one of its parameters. If the caller wants to pass a non-NULL value for this, it immediately makes the calling code require DBus at build time. This has led to breakage of non-DBus builds several times. It is desirable that only the virdbus.c file should need WITH_DBUS conditionals, so we must ideally remove the DBusError parameter from the method. We can't simply raise a libvirt error, since the whole point of this parameter is to give the callers a way to check if the error is one they want to ignore, without having the logs polluted with an error message. So, we add a virErrorPtr parameter which the caller can then either ignore or raise using virSetError. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- src/util/virdbus.c | 31 +++ src/util/virdbus.h | 4 ++-- src/util/virfirewall.c | 29 ++--- src/util/virsystemd.c | 15 +++ 4 files changed, 34 insertions(+), 45 deletions(-) @@ -820,11 +808,9 @@ virFirewallApplyRuleFirewallD(virFirewallRulePtr rule, */ if (ignoreErrors) { VIR_DEBUG(Ignoring error '%s': '%s', - error.name, error.message); + error.str1, error.message); } else { -virReportError(VIR_ERR_INTERNAL_ERROR, - _(Unable to apply rule '%s'), - error.message); +virSetError(error); If ignoreErrors is false, we should be reporting the error, not just setting it. virRaiseErrorFull seems to be the only virError call writing to the log. Oh, hmm, yes that is a problem. Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store
Replace the parts of the code where a backing store is set manually with virStorageSourceSetBackingStore Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/domain_conf.c | 2 +- src/conf/storage_conf.c | 4 ++-- src/qemu/qemu_driver.c | 4 ++-- src/storage/storage_backend_fs.c | 8 src/storage/storage_driver.c | 2 +- src/util/virstoragefile.c| 8 +--- tests/virstoragetest.c | 4 ++-- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0668a5b..9d6b888 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5659,7 +5659,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, virDomainDiskBackingStoreParse(ctxt, backingStore) 0) goto cleanup; -src-backingStore = backingStore; +virStorageSourceSetBackingStore(src, backingStore, 0); ret = 0; cleanup: diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index f4f7e24..fac85fa 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1340,10 +1340,10 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if ((backingStore = virXPathString(string(./backingStore/path), ctxt))) { virStorageSourcePtr backingStorePtr; -if (VIR_ALLOC(ret-target.backingStore) 0) +if (VIR_ALLOC(backingStorePtr) 0) goto error; -backingStorePtr = virStorageSourceGetBackingStore(ret-target, 0); +backingStorePtr = virStorageSourceSetBackingStore(ret-target, backingStorePtr, 0); backingStorePtr-path = backingStore; backingStore = NULL; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 547d2b5..b3afccd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13500,13 +13500,13 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, /* Update vm in place to match changes. */ tmp = disk-src; disk-src = virStorageSourceGetBackingStore(tmp, 0); -tmp-backingStore = NULL; +virStorageSourceSetBackingStore(tmp, NULL, 0); virStorageSourceFree(tmp); if (persistDisk) { tmp = persistDisk-src; persistDisk-src = virStorageSourceGetBackingStore(tmp, 0); -tmp-backingStore = NULL; +virStorageSourceSetBackingStore(tmp, NULL, 0); virStorageSourceFree(tmp); } } diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 56cfc56..a3b6688 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -97,8 +97,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, goto cleanup; if (meta-backingStoreRaw) { -backingStore = virStorageSourceGetBackingStore(target, 0); -if (!(backingStore = virStorageSourceNewFromBacking(meta))) +if (!(backingStore = virStorageSourceSetBackingStore(target, + virStorageSourceNewFromBacking(meta), + 0))) goto cleanup; backingStore-format = backingStoreFormat; @@ -111,8 +112,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, if (VIR_ALLOC(backingStore) 0) goto cleanup; - -target-backingStore = backingStore; +virStorageSourceSetBackingStore(target, backingStore, 0); backingStore-type = VIR_STORAGE_TYPE_NETWORK; backingStore-path = meta-backingStoreRaw; meta-backingStoreRaw = NULL; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 66dc994..eeb2a4c 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2899,7 +2899,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src, goto cleanup; } -src-backingStore = backingStore; +virStorageSourceSetBackingStore(src, backingStore, 0); backingStore = NULL; ret = 0; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 84eefa3..ba38827 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1891,8 +1891,10 @@ virStorageSourceCopy(const virStorageSource *src, goto error; if (backingChain virStorageSourceGetBackingStore(src, 0)) { -if (!(ret-backingStore = virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0), - true))) +if (!virStorageSourceSetBackingStore(ret, + virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0), + true), + 0)) goto error; } @@ -2029,7 +2031,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def) /* recursively free backing chain */
Re: [libvirt] [PATCH v2] systemd: fix build without dbus
On 01/19/2015 02:36 PM, Daniel P. Berrange wrote: The virDBusMethodCall method has a DBusError as one of its parameters. If the caller wants to pass a non-NULL value for this, it immediately makes the calling code require DBus at build time. This has led to breakage of non-DBus builds several times. It is desirable that only the virdbus.c file should need WITH_DBUS conditionals, so we must ideally remove the DBusError parameter from the method. We can't simply raise a libvirt error, since the whole point of this parameter is to give the callers a way to check if the error is one they want to ignore, without having the logs polluted with an error message. So, we add a virErrorPtr parameter which the caller can then either ignore or raise using virSetError. Signed-off-by: Daniel P. Berrange berra...@redhat.com --- src/util/virdbus.c | 31 +++ src/util/virdbus.h | 4 ++-- src/util/virfirewall.c | 29 ++--- src/util/virsystemd.c | 15 +++ 4 files changed, 34 insertions(+), 45 deletions(-) @@ -820,11 +808,9 @@ virFirewallApplyRuleFirewallD(virFirewallRulePtr rule, */ if (ignoreErrors) { VIR_DEBUG(Ignoring error '%s': '%s', - error.name, error.message); + error.str1, error.message); } else { -virReportError(VIR_ERR_INTERNAL_ERROR, - _(Unable to apply rule '%s'), - error.message); +virSetError(error); If ignoreErrors is false, we should be reporting the error, not just setting it. virRaiseErrorFull seems to be the only virError call writing to the log. goto cleanup; } } else { diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 3eea5c2..0b71b26 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -280,21 +280,20 @@ int virSystemdCreateMachine(const char *name, Before, as, 1, libvirt-guests.service) 0) goto cleanup; -if (dbus_error_is_set(error)) { +if (error.level == VIR_ERR_ERROR) { if (STREQ_NULLABLE(org.freedesktop.DBus.Error.UnknownMethod, - error.name)) { + error.str1)) { VIR_INFO(CreateMachineWithNetwork isn't supported, switching to legacy CreateMachine method for systemd-machined); -dbus_error_free(error); +virResetError(error); virAtomicIntSet(hasCreateWithNetwork, 0); /* Could re-structure without Using goto, but this * avoids another atomic read which would trigger * another memory barrier */ goto fallback; } -virReportError(VIR_ERR_DBUS_SERVICE, - _(CreateMachineWithNetwork: %s), - error.message ? error.message : _(unknown error)); +virSetError(error); +virResetError(error); Same here. Jan goto cleanup; } } else { signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list