conf: Support disk source formatting without needing a virDomainDiskDefPtr

The <source> element formatting function was expecting a
virDomainDiskDefPtr to store the data. As snapshots are not using this
data structure to hold the data, we need to add an internal function
which splits out individual fields separately.
This commit is contained in:
Peter Krempa 2013-11-07 15:41:30 +01:00
parent 436fa772fb
commit d6b4c2cca9

View File

@ -14353,28 +14353,38 @@ virDomainDiskBlockIoDefFormat(virBufferPtr buf,
} }
static int static int
virDomainDiskSourceDefFormat(virBufferPtr buf, virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
virDomainDiskDefPtr def, int type,
const char *src,
int policy,
int protocol,
size_t nhosts,
virDomainDiskHostDefPtr hosts,
size_t nseclabels,
virSecurityDeviceLabelDefPtr *seclabels,
virDomainDiskSourcePoolDefPtr srcpool,
unsigned int flags) unsigned int flags)
{ {
int n; size_t n;
const char *startupPolicy = virDomainStartupPolicyTypeToString(def->startupPolicy); const char *startupPolicy = NULL;
if (def->src || def->nhosts > 0 || def->srcpool || if (policy)
def->startupPolicy) { startupPolicy = virDomainStartupPolicyTypeToString(policy);
switch (def->type) {
if (src || nhosts > 0 || srcpool || startupPolicy) {
switch (type) {
case VIR_DOMAIN_DISK_TYPE_FILE: case VIR_DOMAIN_DISK_TYPE_FILE:
virBufferAddLit(buf, " <source"); virBufferAddLit(buf, " <source");
if (def->src) if (src)
virBufferEscapeString(buf, " file='%s'", def->src); virBufferEscapeString(buf, " file='%s'", src);
if (def->startupPolicy) if (startupPolicy)
virBufferEscapeString(buf, " startupPolicy='%s'", virBufferEscapeString(buf, " startupPolicy='%s'",
startupPolicy); startupPolicy);
if (def->nseclabels) { if (nseclabels) {
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 8); virBufferAdjustIndent(buf, 8);
for (n = 0; n < def->nseclabels; n++) for (n = 0; n < nseclabels; n++)
virSecurityDeviceLabelDefFormat(buf, def->seclabels[n], virSecurityDeviceLabelDefFormat(buf, seclabels[n],
flags); flags);
virBufferAdjustIndent(buf, -8); virBufferAdjustIndent(buf, -8);
virBufferAddLit(buf, " </source>\n"); virBufferAddLit(buf, " </source>\n");
@ -14384,15 +14394,15 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
break; break;
case VIR_DOMAIN_DISK_TYPE_BLOCK: case VIR_DOMAIN_DISK_TYPE_BLOCK:
virBufferAddLit(buf, " <source"); virBufferAddLit(buf, " <source");
virBufferEscapeString(buf, " dev='%s'", def->src); virBufferEscapeString(buf, " dev='%s'", src);
if (def->startupPolicy) if (startupPolicy)
virBufferEscapeString(buf, " startupPolicy='%s'", virBufferEscapeString(buf, " startupPolicy='%s'",
startupPolicy); startupPolicy);
if (def->nseclabels) { if (nseclabels) {
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 8); virBufferAdjustIndent(buf, 8);
for (n = 0; n < def->nseclabels; n++) for (n = 0; n < nseclabels; n++)
virSecurityDeviceLabelDefFormat(buf, def->seclabels[n], virSecurityDeviceLabelDefFormat(buf, seclabels[n],
flags); flags);
virBufferAdjustIndent(buf, -8); virBufferAdjustIndent(buf, -8);
virBufferAddLit(buf, " </source>\n"); virBufferAddLit(buf, " </source>\n");
@ -14401,41 +14411,38 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
} }
break; break;
case VIR_DOMAIN_DISK_TYPE_DIR: case VIR_DOMAIN_DISK_TYPE_DIR:
virBufferEscapeString(buf, " <source dir='%s'", virBufferEscapeString(buf, " <source dir='%s'", src);
def->src); if (startupPolicy)
if (def->startupPolicy)
virBufferEscapeString(buf, " startupPolicy='%s'", virBufferEscapeString(buf, " startupPolicy='%s'",
startupPolicy); startupPolicy);
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
break; break;
case VIR_DOMAIN_DISK_TYPE_NETWORK: case VIR_DOMAIN_DISK_TYPE_NETWORK:
virBufferAsprintf(buf, " <source protocol='%s'", virBufferAsprintf(buf, " <source protocol='%s'",
virDomainDiskProtocolTypeToString(def->protocol)); virDomainDiskProtocolTypeToString(protocol));
if (def->src) { if (src)
virBufferEscapeString(buf, " name='%s'", def->src); virBufferEscapeString(buf, " name='%s'", src);
}
if (def->nhosts == 0) { if (nhosts == 0) {
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} else { } else {
size_t i;
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
for (i = 0; i < def->nhosts; i++) { for (n = 0; n < nhosts; n++) {
virBufferAddLit(buf, " <host"); virBufferAddLit(buf, " <host");
if (def->hosts[i].name) { if (hosts[n].name)
virBufferEscapeString(buf, " name='%s'", def->hosts[i].name); virBufferEscapeString(buf, " name='%s'", hosts[n].name);
}
if (def->hosts[i].port) { if (hosts[n].port)
virBufferEscapeString(buf, " port='%s'", virBufferEscapeString(buf, " port='%s'",
def->hosts[i].port); hosts[n].port);
}
if (def->hosts[i].transport) { if (hosts[n].transport)
virBufferAsprintf(buf, " transport='%s'", virBufferAsprintf(buf, " transport='%s'",
virDomainDiskProtocolTransportTypeToString(def->hosts[i].transport)); virDomainDiskProtocolTransportTypeToString(hosts[n].transport));
}
if (def->hosts[i].socket) { if (hosts[n].socket)
virBufferEscapeString(buf, " socket='%s'", def->hosts[i].socket); virBufferEscapeString(buf, " socket='%s'", hosts[n].socket);
}
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
virBufferAddLit(buf, " </source>\n"); virBufferAddLit(buf, " </source>\n");
@ -14444,21 +14451,21 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
case VIR_DOMAIN_DISK_TYPE_VOLUME: case VIR_DOMAIN_DISK_TYPE_VOLUME:
virBufferAddLit(buf, " <source"); virBufferAddLit(buf, " <source");
if (def->srcpool) { if (srcpool) {
virBufferAsprintf(buf, " pool='%s' volume='%s'", virBufferAsprintf(buf, " pool='%s' volume='%s'",
def->srcpool->pool, def->srcpool->volume); srcpool->pool, srcpool->volume);
if (def->srcpool->mode) if (srcpool->mode)
virBufferAsprintf(buf, " mode='%s'", virBufferAsprintf(buf, " mode='%s'",
virDomainDiskSourcePoolModeTypeToString(def->srcpool->mode)); virDomainDiskSourcePoolModeTypeToString(srcpool->mode));
} }
if (def->startupPolicy) if (startupPolicy)
virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
if (def->nseclabels) { if (nseclabels) {
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 8); virBufferAdjustIndent(buf, 8);
for (n = 0; n < def->nseclabels; n++) for (n = 0; n < nseclabels; n++)
virSecurityDeviceLabelDefFormat(buf, def->seclabels[n], virSecurityDeviceLabelDefFormat(buf, seclabels[n],
flags); flags);
virBufferAdjustIndent(buf, -8); virBufferAdjustIndent(buf, -8);
virBufferAddLit(buf, " </source>\n"); virBufferAddLit(buf, " </source>\n");
@ -14469,7 +14476,7 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected disk type %s"), _("unexpected disk type %s"),
virDomainDiskTypeToString(def->type)); virDomainDiskTypeToString(type));
return -1; return -1;
} }
} }
@ -14477,6 +14484,26 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
return 0; return 0;
} }
static int
virDomainDiskSourceDefFormat(virBufferPtr buf,
virDomainDiskDefPtr def,
unsigned int flags)
{
return virDomainDiskSourceDefFormatInternal(buf,
def->type,
def->src,
def->startupPolicy,
def->protocol,
def->nhosts,
def->hosts,
def->nseclabels,
def->seclabels,
def->srcpool,
flags);
}
static int static int
virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefFormat(virBufferPtr buf,
virDomainDiskDefPtr def, virDomainDiskDefPtr def,