Re: [libvirt] [PATCH 1/1] Add NVRAM device
Hello, Does anyone have any comments? On 2013年02月22日 17:09, Li Zhang wrote: From: Li Zhang For pSeries guest in QEMU, NVRAM is one kind of spapr-vio device. Users are allowed to specify spapr-vio devices'address. But NVRAM is not supported in libvirt. So this patch is to add NVRAM device to allow users to specify its address. In QEMU, NVRAM device's address is specified by "-global spapr-nvram.reg=x". In libvirt, XML file is defined as the following: Signed-off-by: Li Zhang --- src/conf/domain_conf.c | 83 ++- src/conf/domain_conf.h | 10 ++ src/qemu/qemu_command.c | 31 ++ src/qemu/qemu_command.h |2 ++ 4 files changed, 125 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 10f361c..8c1e8ae 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -175,7 +175,8 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST, "redirdev", "smartcard", "chr", - "memballoon") + "memballoon", + "nvram") VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST, "none", @@ -1442,6 +1443,16 @@ void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def) VIR_FREE(def); } +void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def) +{ +if (!def) +return; + +virDomainDeviceInfoClear(&def->info); + +VIR_FREE(def); +} + void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def) { if (!def) @@ -1602,6 +1613,7 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def) case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_CHR: case VIR_DOMAIN_DEVICE_MEMBALLOON: +case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_LAST: break; } @@ -1791,6 +1803,7 @@ void virDomainDefFree(virDomainDefPtr def) virDomainWatchdogDefFree(def->watchdog); virDomainMemballoonDefFree(def->memballoon); +virDomainNVRAMDefFree(def->nvram); for (i = 0; i < def->nseclabels; i++) virSecurityLabelDefFree(def->seclabels[i]); @@ -2342,6 +2355,12 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def, if (cb(def, &device, &def->memballoon->info, opaque) < 0) return -1; } +if (def->nvram) { +device.type = VIR_DOMAIN_DEVICE_NVRAM; +device.data.nvram = def->nvram; +if (cb(def, &device, &def->nvram->info, opaque) < 0) +return -1; +} device.type = VIR_DOMAIN_DEVICE_HUB; for (i = 0; i < def->nhubs ; i++) { device.data.hub = def->hubs[i]; @@ -7461,6 +7480,23 @@ error: goto cleanup; } +static virDomainNVRAMDefPtr +virDomainNVRAMDefParseXML(const xmlNodePtr node, + unsigned int flags) +{ + virDomainNVRAMDefPtr def; + +if (VIR_ALLOC(def) < 0) { +virReportOOMError(); +return NULL; +} + +if ( virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0 ) +return NULL; + +return def; +} + static virSysinfoDefPtr virSysinfoParseXML(const xmlNodePtr node, xmlXPathContextPtr ctxt) @@ -10572,6 +10608,32 @@ virDomainDefParseXML(virCapsPtr caps, } } +def->nvram = NULL; +if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0) { +goto error; +} + +if (n > 1) { +virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("only a single nvram device is supported")); +goto error; +} + +if (n > 0) { +virDomainNVRAMDefPtr nvram = +virDomainNVRAMDefParseXML(nodes[0], flags); +if (!nvram) +goto error; +def->nvram = nvram; +VIR_FREE(nodes); +} else { +virDomainNVRAMDefPtr nvram; +if (VIR_ALLOC(nvram) < 0) +goto no_memory; +nvram->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE; +def->nvram = nvram; +} + /* analysis of the hub devices */ if ((n = virXPathNodeSet("./devices/hub", ctxt, &nodes)) < 0) { goto error; @@ -13547,6 +13609,21 @@ virDomainMemballoonDefFormat(virBufferPtr buf, } static int +virDomainNVRAMDefFormat(virBufferPtr buf, + virDomainNVRAMDefPtr def, + unsigned int flags) +{ +virBufferAsprintf(buf, "\n"); +if (virDomainDeviceInfoIsSet(&def->info, flags)) +if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) +return -1; + + virBufferAddLit(buf, "\n"); + + return 0; +} + +static int virDomainSysinfoDefFormat(virBufferPtr buf, virSysinfoDefPtr def) { @@ -14787,6 +14864,9 @@ virDomainDefFormatInternal(virDomainDefPtr def, if (def->memballoon) virDomainMemballoonDefFormat(buf, def->memballoon, flag
[libvirt] [PATCH 1/1] Add NVRAM device
From: Li Zhang For pSeries guest in QEMU, NVRAM is one kind of spapr-vio device. Users are allowed to specify spapr-vio devices'address. But NVRAM is not supported in libvirt. So this patch is to add NVRAM device to allow users to specify its address. In QEMU, NVRAM device's address is specified by "-global spapr-nvram.reg=x". In libvirt, XML file is defined as the following: Signed-off-by: Li Zhang --- src/conf/domain_conf.c | 83 ++- src/conf/domain_conf.h | 10 ++ src/qemu/qemu_command.c | 31 ++ src/qemu/qemu_command.h |2 ++ 4 files changed, 125 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 10f361c..8c1e8ae 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -175,7 +175,8 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST, "redirdev", "smartcard", "chr", - "memballoon") + "memballoon", + "nvram") VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST, "none", @@ -1442,6 +1443,16 @@ void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def) VIR_FREE(def); } +void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def) +{ +if (!def) +return; + +virDomainDeviceInfoClear(&def->info); + +VIR_FREE(def); +} + void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def) { if (!def) @@ -1602,6 +1613,7 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def) case VIR_DOMAIN_DEVICE_SMARTCARD: case VIR_DOMAIN_DEVICE_CHR: case VIR_DOMAIN_DEVICE_MEMBALLOON: +case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_LAST: break; } @@ -1791,6 +1803,7 @@ void virDomainDefFree(virDomainDefPtr def) virDomainWatchdogDefFree(def->watchdog); virDomainMemballoonDefFree(def->memballoon); +virDomainNVRAMDefFree(def->nvram); for (i = 0; i < def->nseclabels; i++) virSecurityLabelDefFree(def->seclabels[i]); @@ -2342,6 +2355,12 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def, if (cb(def, &device, &def->memballoon->info, opaque) < 0) return -1; } +if (def->nvram) { +device.type = VIR_DOMAIN_DEVICE_NVRAM; +device.data.nvram = def->nvram; +if (cb(def, &device, &def->nvram->info, opaque) < 0) +return -1; +} device.type = VIR_DOMAIN_DEVICE_HUB; for (i = 0; i < def->nhubs ; i++) { device.data.hub = def->hubs[i]; @@ -7461,6 +7480,23 @@ error: goto cleanup; } +static virDomainNVRAMDefPtr +virDomainNVRAMDefParseXML(const xmlNodePtr node, + unsigned int flags) +{ + virDomainNVRAMDefPtr def; + +if (VIR_ALLOC(def) < 0) { +virReportOOMError(); +return NULL; +} + +if ( virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0 ) +return NULL; + +return def; +} + static virSysinfoDefPtr virSysinfoParseXML(const xmlNodePtr node, xmlXPathContextPtr ctxt) @@ -10572,6 +10608,32 @@ virDomainDefParseXML(virCapsPtr caps, } } +def->nvram = NULL; +if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0) { +goto error; +} + +if (n > 1) { +virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("only a single nvram device is supported")); +goto error; +} + +if (n > 0) { +virDomainNVRAMDefPtr nvram = +virDomainNVRAMDefParseXML(nodes[0], flags); +if (!nvram) +goto error; +def->nvram = nvram; +VIR_FREE(nodes); +} else { +virDomainNVRAMDefPtr nvram; +if (VIR_ALLOC(nvram) < 0) +goto no_memory; +nvram->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE; +def->nvram = nvram; +} + /* analysis of the hub devices */ if ((n = virXPathNodeSet("./devices/hub", ctxt, &nodes)) < 0) { goto error; @@ -13547,6 +13609,21 @@ virDomainMemballoonDefFormat(virBufferPtr buf, } static int +virDomainNVRAMDefFormat(virBufferPtr buf, + virDomainNVRAMDefPtr def, + unsigned int flags) +{ +virBufferAsprintf(buf, "\n"); +if (virDomainDeviceInfoIsSet(&def->info, flags)) +if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) +return -1; + + virBufferAddLit(buf, "\n"); + + return 0; +} + +static int virDomainSysinfoDefFormat(virBufferPtr buf, virSysinfoDefPtr def) { @@ -14787,6 +14864,9 @@ virDomainDefFormatInternal(virDomainDefPtr def, if (def->memballoon) virDomainMemballoonDefFormat(buf, def->memballoon, flags); +if (def->nvram) +virDomainNVRAMDefFormat(buf, def->nvram, flags); + virBufferAddLit(buf, " \n"); virBufferAdjustIn