提交 0778fc1a 编写于 作者: M Matthieu Coudron 提交者: Michal Privoznik

qemu_driver: Introduce <filesystem/> support in device attach/detach

This commit allows to attach/detach a <filesystem> device in qemu. For
this purpose I'm introducing two new functions: virDomainFSInsert() and
virDomainFSRemove() and adding necessary code in the qemu driver.  It
compares filesystems based on their "destination" folder. So if two
filesystems share the same destination, they are considered equal and
the qemu driver would reject the insertion.
Signed-off-by: NMatthieu Coudron <mattator@gmail.com>
上级 8fc98ac8
......@@ -17919,6 +17919,22 @@ virDiskNameToBusDeviceIndex(virDomainDiskDefPtr disk,
return 0;
}
int
virDomainFSInsert(virDomainDefPtr def, virDomainFSDefPtr fs)
{
return VIR_APPEND_ELEMENT(def->fss, def->nfss, fs);
}
virDomainFSDefPtr
virDomainFSRemove(virDomainDefPtr def, size_t i)
{
virDomainFSDefPtr fs = def->fss[i];
VIR_DELETE_ELEMENT(def->fss, i, def->nfss);
return fs;
}
virDomainFSDefPtr
virDomainGetRootFilesystem(virDomainDefPtr def)
{
......
......@@ -2555,7 +2555,10 @@ int virDiskNameToBusDeviceIndex(virDomainDiskDefPtr disk,
int *devIdx);
virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def);
int virDomainFSInsert(virDomainDefPtr def, virDomainFSDefPtr fs);
int virDomainFSIndexByName(virDomainDefPtr def, const char *name);
virDomainFSDefPtr virDomainFSRemove(virDomainDefPtr def, size_t i);
int virDomainVideoDefaultType(const virDomainDef *def);
int virDomainVideoDefaultRAM(const virDomainDef *def, int type);
......
......@@ -221,6 +221,8 @@ virDomainFeatureStateTypeFromString;
virDomainFeatureStateTypeToString;
virDomainFSDefFree;
virDomainFSIndexByName;
virDomainFSInsert;
virDomainFSRemove;
virDomainFSTypeFromString;
virDomainFSTypeToString;
virDomainFSWrpolicyTypeFromString;
......
......@@ -6606,6 +6606,7 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
virDomainHostdevDefPtr hostdev;
virDomainLeaseDefPtr lease;
virDomainControllerDefPtr controller;
virDomainFSDefPtr fs;
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
......@@ -6687,6 +6688,19 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
dev->data.chr = NULL;
break;
case VIR_DOMAIN_DEVICE_FS:
fs = dev->data.fs;
if (virDomainFSIndexByName(vmdef, fs->dst) >= 0) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("Target already exists"));
return -1;
}
if (virDomainFSInsert(vmdef, fs) < 0)
return -1;
dev->data.fs = NULL;
break;
default:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("persistent attach of device '%s' is not supported"),
......@@ -6707,6 +6721,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
virDomainLeaseDefPtr lease, det_lease;
virDomainControllerDefPtr cont, det_cont;
virDomainChrDefPtr chr;
virDomainFSDefPtr fs;
int idx;
char mac[VIR_MAC_STRING_BUFLEN];
......@@ -6783,6 +6798,19 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
dev->data.chr = NULL;
break;
case VIR_DOMAIN_DEVICE_FS:
fs = dev->data.fs;
idx = virDomainFSIndexByName(vmdef, fs->dst);
if (idx < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("no matching filesystem device was found"));
return -1;
}
fs = virDomainFSRemove(vmdef, idx);
virDomainFSDefFree(fs);
break;
default:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("persistent detach of device '%s' is not supported"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册