mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: new function virDomainActualNetDefContentsFormat
This function is currently only called from one place, but in a subsequent patch will be called from a 2nd place. The new function exactly replicates the original behavior of the part of virDomainActualNetDefFormat() that it replaces, but takes a virDomainNetDefPtr instead of virDomainActualNetDefPtr, and uses the virDomainNetGetActual*() functions whenever possible, rather than reaching into def->data.network.actual - this is to be sure that we are reporting exactly what is being used internally, just in case there are any discrepancies (there shouldn't be).
This commit is contained in:
parent
65487c0fc5
commit
9da98aa5e1
@ -15427,78 +15427,112 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* virDomainActualNetDefContentsFormat() - format just the subelements
|
||||||
|
* of <interface> that may be overridden by what is in the
|
||||||
|
* virDomainActualNetDef, but inside the current element, rather
|
||||||
|
* than enclosed in an <actual> subelement.
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
virDomainActualNetDefFormat(virBufferPtr buf,
|
virDomainActualNetDefContentsFormat(virBufferPtr buf,
|
||||||
virDomainActualNetDefPtr def,
|
virDomainNetDefPtr def,
|
||||||
unsigned int flags)
|
const char *typeStr,
|
||||||
|
bool inSubelement,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const char *type;
|
|
||||||
const char *mode;
|
const char *mode;
|
||||||
|
|
||||||
if (!def)
|
switch (virDomainNetGetActualType(def)) {
|
||||||
return 0;
|
|
||||||
|
|
||||||
type = virDomainNetTypeToString(def->type);
|
|
||||||
if (!type) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("unexpected net type %d"), def->type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<actual type='%s'", type);
|
|
||||||
if (def->type == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
|
|
||||||
def->data.hostdev.def.managed) {
|
|
||||||
virBufferAddLit(buf, " managed='yes'");
|
|
||||||
}
|
|
||||||
virBufferAddLit(buf, ">\n");
|
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, 2);
|
|
||||||
switch (def->type) {
|
|
||||||
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||||
virBufferEscapeString(buf, "<source bridge='%s'/>\n",
|
virBufferEscapeString(buf, "<source bridge='%s'/>\n",
|
||||||
def->data.bridge.brname);
|
virDomainNetGetActualBridgeName(def));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
||||||
virBufferAddLit(buf, "<source");
|
virBufferAddLit(buf, "<source");
|
||||||
if (def->data.direct.linkdev)
|
virBufferEscapeString(buf, " dev='%s'",
|
||||||
virBufferEscapeString(buf, " dev='%s'",
|
virDomainNetGetActualDirectDev(def));
|
||||||
def->data.direct.linkdev);
|
|
||||||
|
|
||||||
mode = virNetDevMacVLanModeTypeToString(def->data.direct.mode);
|
mode = virNetDevMacVLanModeTypeToString(virDomainNetGetActualDirectMode(def));
|
||||||
if (!mode) {
|
if (!mode) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected source mode %d"),
|
_("unexpected source mode %d"),
|
||||||
def->data.direct.mode);
|
virDomainNetGetActualDirectMode(def));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virBufferAsprintf(buf, " mode='%s'/>\n", mode);
|
virBufferAsprintf(buf, " mode='%s'/>\n", mode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
||||||
if (virDomainHostdevDefFormatSubsys(buf, &def->data.hostdev.def,
|
if (virDomainHostdevDefFormatSubsys(buf, virDomainNetGetActualHostdev(def),
|
||||||
flags, true) < 0) {
|
flags, true) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
||||||
if (def->class_id)
|
if (!inSubelement) {
|
||||||
virBufferAsprintf(buf, "<class id='%u'/>", def->class_id);
|
/* the <source> element isn't included in <actual>
|
||||||
|
* (i.e. when we're putting our output into a subelement
|
||||||
|
* rather than inline) because the main element has the
|
||||||
|
* same info already. If we're outputting inline, though,
|
||||||
|
* we *do* need to output <source>, because the caller
|
||||||
|
* won't have done it.
|
||||||
|
*/
|
||||||
|
virBufferEscapeString(buf, "<source network='%s'/>\n",
|
||||||
|
def->data.network.name);
|
||||||
|
}
|
||||||
|
if (def->data.network.actual && def->data.network.actual->class_id)
|
||||||
|
virBufferAsprintf(buf, "<class id='%u'/>\n",
|
||||||
|
def->data.network.actual->class_id);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected net type %s"), type);
|
_("unexpected actual net type %s"), typeStr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNetDevVlanFormat(&def->vlan, buf) < 0)
|
if (virNetDevVlanFormat(virDomainNetGetActualVlan(def), buf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0)
|
if (virNetDevVPortProfileFormat(virDomainNetGetActualVirtPortProfile(def), buf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
|
if (virNetDevBandwidthFormat(virDomainNetGetActualBandwidth(def), buf) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* virDomainActualNetDefFormat() - format the ActualNetDef
|
||||||
|
* info inside an <actual> element, as required for internal storage
|
||||||
|
* of domain status
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
virDomainActualNetDefFormat(virBufferPtr buf,
|
||||||
|
virDomainNetDefPtr def,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
unsigned int type = virDomainNetGetActualType(def);
|
||||||
|
const char *typeStr = virDomainNetTypeToString(type);
|
||||||
|
|
||||||
|
if (!def)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!typeStr) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("unexpected net type %d"), def->type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
virBufferAsprintf(buf, "<actual type='%s'", typeStr);
|
||||||
|
if (type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
|
||||||
|
virDomainHostdevDefPtr hostdef = virDomainNetGetActualHostdev(def);
|
||||||
|
if (hostdef && hostdef->managed)
|
||||||
|
virBufferAddLit(buf, " managed='yes'");
|
||||||
|
}
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
|
||||||
|
virBufferAdjustIndent(buf, 2);
|
||||||
|
if (virDomainActualNetDefContentsFormat(buf, def, typeStr, true, flags) < 0)
|
||||||
|
return -1;
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</actual>\n");
|
virBufferAddLit(buf, "</actual>\n");
|
||||||
return 0;
|
return 0;
|
||||||
@ -15536,8 +15570,13 @@ virDomainNetDefFormat(virBufferPtr buf,
|
|||||||
virBufferEscapeString(buf, " portgroup='%s'",
|
virBufferEscapeString(buf, " portgroup='%s'",
|
||||||
def->data.network.portgroup);
|
def->data.network.portgroup);
|
||||||
virBufferAddLit(buf, "/>\n");
|
virBufferAddLit(buf, "/>\n");
|
||||||
|
|
||||||
|
/* ONLY for internal status storage - format the ActualNetDef
|
||||||
|
* as a subelement of <interface> so that no persistent config
|
||||||
|
* data is overwritten.
|
||||||
|
*/
|
||||||
if ((flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) &&
|
if ((flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) &&
|
||||||
(virDomainActualNetDefFormat(buf, def->data.network.actual, flags) < 0))
|
(virDomainActualNetDefFormat(buf, def, flags) < 0))
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user