diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c1e0ea736a0056d3c7f69d4b5f6bdfd4224ca535..ffdbe953d9f7016f6109e1dfc10d58ba0106bb9b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4370,6 +4370,17 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, def->norelabel = false; } + /* Always parse model */ + p = virXPathStringLimit("string(./@model)", + VIR_SECURITY_MODEL_BUFLEN-1, ctxt); + def->model = p; + + /* For the model 'none' none of the following labels is going to be + * present. Hence, return now. */ + + if (STREQ_NULLABLE(def->model, "none")) + return def; + /* Only parse label, if using static labels, or * if the 'live' VM XML is requested */ @@ -4408,11 +4419,6 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, def->baselabel = p; } - /* Always parse model */ - p = virXPathStringLimit("string(./@model)", - VIR_SECURITY_MODEL_BUFLEN-1, ctxt); - def->model = p; - return def; error: @@ -14177,7 +14183,9 @@ virDomainEventActionDefFormat(virBufferPtr buf, static void -virSecurityLabelDefFormat(virBufferPtr buf, virSecurityLabelDefPtr def) +virSecurityLabelDefFormat(virBufferPtr buf, + virSecurityLabelDefPtr def, + unsigned flags) { const char *sectype = virDomainSeclabelTypeToString(def->type); @@ -14196,7 +14204,9 @@ virSecurityLabelDefFormat(virBufferPtr buf, virSecurityLabelDefPtr def) virBufferAsprintf(buf, "model && STRNEQ(def->model, "none")) + /* When generating state XML do include the model */ + if (flags & VIR_DOMAIN_XML_INTERNAL_STATUS || + STRNEQ_NULLABLE(def->model, "none")) virBufferEscapeString(buf, " model='%s'", def->model); if (def->type == VIR_DOMAIN_SECLABEL_NONE) { @@ -17107,7 +17117,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAdjustIndent(buf, 2); for (n = 0; n < def->nseclabels; n++) - virSecurityLabelDefFormat(buf, def->seclabels[n]); + virSecurityLabelDefFormat(buf, def->seclabels[n], flags); virBufferAdjustIndent(buf, -2); if (def->namespaceData && def->ns.format) { diff --git a/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-relabel.args b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-relabel.args new file mode 100644 index 0000000000000000000000000000000000000000..8bef54646634da462dd44ebbfcb12e1674bd6e03 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-relabel.args @@ -0,0 +1,6 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 -S -M pc -m 214 -smp 1 -nographic -monitor \ +unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \ +-hda /dev/HostVG/QEMUGuest1 -net none -serial \ +none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-relabel.xml b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-relabel.xml new file mode 100644 index 0000000000000000000000000000000000000000..cb7423958c7fd38b05ed9d7f66cde033a74b18c0 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-relabel.xml @@ -0,0 +1,28 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 0629e310efc9124926886b52ce51957f620ae2a0..7ff74aa6a66fb8fc3a93c5ca4f04f2bd957ed8d6 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -963,6 +963,7 @@ mymain(void) DO_TEST("seclabel-dynamic-baselabel", QEMU_CAPS_NAME); DO_TEST("seclabel-dynamic-override", QEMU_CAPS_NAME); DO_TEST("seclabel-dynamic-labelskip", QEMU_CAPS_NAME); + DO_TEST("seclabel-dynamic-relabel", QEMU_CAPS_NAME); DO_TEST("seclabel-static", QEMU_CAPS_NAME); DO_TEST("seclabel-static-relabel", QEMU_CAPS_NAME); DO_TEST("seclabel-static-labelskip", QEMU_CAPS_NAME); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index ffff3b556903d8f9dbf9fda26e084e45aec9d14f..ceaaf6a591dde3332ddb9378bc46478e7e06a2a4 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -263,6 +263,7 @@ mymain(void) DO_TEST_FULL("seclabel-dynamic-baselabel", false, WHEN_INACTIVE); DO_TEST_FULL("seclabel-dynamic-override", false, WHEN_INACTIVE); DO_TEST_FULL("seclabel-dynamic-labelskip", true, WHEN_INACTIVE); + DO_TEST_FULL("seclabel-dynamic-relabel", false, WHEN_INACTIVE); DO_TEST("seclabel-static"); DO_TEST_FULL("seclabel-static-labelskip", false, WHEN_ACTIVE); DO_TEST("seclabel-none");