Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
53f3739a
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
53f3739a
编写于
7月 11, 2013
作者:
J
Jiri Denemark
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
qemu: Separate host device removal into a standalone function
上级
ac68a785
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
142 addition
and
98 deletion
+142
-98
src/qemu/qemu_hotplug.c
src/qemu/qemu_hotplug.c
+142
-98
未找到文件。
src/qemu/qemu_hotplug.c
浏览文件 @
53f3739a
...
...
@@ -2345,6 +2345,136 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
}
static
void
qemuDomainRemovePCIHostDevice
(
virQEMUDriverPtr
driver
,
virDomainObjPtr
vm
,
virDomainHostdevDefPtr
hostdev
)
{
virQEMUDriverConfigPtr
cfg
=
virQEMUDriverGetConfig
(
driver
);
virDomainHostdevSubsysPtr
subsys
=
&
hostdev
->
source
.
subsys
;
virPCIDevicePtr
pci
;
virPCIDevicePtr
activePci
;
/*
* For SRIOV net host devices, unset mac and port profile before
* reset and reattach device
*/
if
(
hostdev
->
parent
.
data
.
net
)
qemuDomainHostdevNetConfigRestore
(
hostdev
,
cfg
->
stateDir
);
virObjectLock
(
driver
->
activePciHostdevs
);
virObjectLock
(
driver
->
inactivePciHostdevs
);
pci
=
virPCIDeviceNew
(
subsys
->
u
.
pci
.
addr
.
domain
,
subsys
->
u
.
pci
.
addr
.
bus
,
subsys
->
u
.
pci
.
addr
.
slot
,
subsys
->
u
.
pci
.
addr
.
function
);
if
(
pci
)
{
activePci
=
virPCIDeviceListSteal
(
driver
->
activePciHostdevs
,
pci
);
if
(
activePci
&&
virPCIDeviceReset
(
activePci
,
driver
->
activePciHostdevs
,
driver
->
inactivePciHostdevs
)
==
0
)
{
qemuReattachPciDevice
(
activePci
,
driver
);
}
else
{
/* reset of the device failed, treat it as if it was returned */
virPCIDeviceFree
(
activePci
);
}
virPCIDeviceFree
(
pci
);
}
virObjectUnlock
(
driver
->
activePciHostdevs
);
virObjectUnlock
(
driver
->
inactivePciHostdevs
);
qemuDomainReleaseDeviceAddress
(
vm
,
hostdev
->
info
,
NULL
);
virObjectUnref
(
cfg
);
}
static
void
qemuDomainRemoveUSBHostDevice
(
virQEMUDriverPtr
driver
,
virDomainObjPtr
vm
ATTRIBUTE_UNUSED
,
virDomainHostdevDefPtr
hostdev
)
{
virDomainHostdevSubsysPtr
subsys
=
&
hostdev
->
source
.
subsys
;
virUSBDevicePtr
usb
;
usb
=
virUSBDeviceNew
(
subsys
->
u
.
usb
.
bus
,
subsys
->
u
.
usb
.
device
,
NULL
);
if
(
usb
)
{
virObjectLock
(
driver
->
activeUsbHostdevs
);
virUSBDeviceListDel
(
driver
->
activeUsbHostdevs
,
usb
);
virObjectUnlock
(
driver
->
activeUsbHostdevs
);
virUSBDeviceFree
(
usb
);
}
else
{
VIR_WARN
(
"Unable to find device %03d.%03d in list of used USB devices"
,
subsys
->
u
.
usb
.
bus
,
subsys
->
u
.
usb
.
device
);
}
}
static
void
qemuDomainRemoveSCSIHostDevice
(
virQEMUDriverPtr
driver
,
virDomainObjPtr
vm
,
virDomainHostdevDefPtr
hostdev
)
{
qemuDomainReAttachHostScsiDevices
(
driver
,
vm
->
def
->
name
,
&
hostdev
,
1
);
}
static
void
qemuDomainRemoveHostDevice
(
virQEMUDriverPtr
driver
,
virDomainObjPtr
vm
,
virDomainHostdevDefPtr
hostdev
)
{
virDomainNetDefPtr
net
=
NULL
;
size_t
i
;
VIR_DEBUG
(
"Removing host device %s from domain %p %s"
,
hostdev
->
info
->
alias
,
vm
,
vm
->
def
->
name
);
if
(
hostdev
->
parent
.
type
==
VIR_DOMAIN_DEVICE_NET
)
{
net
=
hostdev
->
parent
.
data
.
net
;
for
(
i
=
0
;
i
<
vm
->
def
->
nnets
;
i
++
)
{
if
(
vm
->
def
->
nets
[
i
]
==
net
)
{
virDomainNetRemove
(
vm
->
def
,
i
);
break
;
}
}
}
for
(
i
=
0
;
i
<
vm
->
def
->
nhostdevs
;
i
++
)
{
if
(
vm
->
def
->
hostdevs
[
i
]
==
hostdev
)
{
virDomainHostdevRemove
(
vm
->
def
,
i
);
break
;
}
}
virDomainAuditHostdev
(
vm
,
hostdev
,
"detach"
,
true
);
switch
((
enum
virDomainHostdevSubsysType
)
hostdev
->
source
.
subsys
.
type
)
{
case
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI
:
qemuDomainRemovePCIHostDevice
(
driver
,
vm
,
hostdev
);
break
;
case
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB
:
qemuDomainRemoveUSBHostDevice
(
driver
,
vm
,
hostdev
);
break
;
case
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI
:
qemuDomainRemoveSCSIHostDevice
(
driver
,
vm
,
hostdev
);
break
;
case
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST
:
break
;
}
if
(
qemuTeardownHostdevCgroup
(
vm
,
hostdev
)
<
0
)
VIR_WARN
(
"Failed to remove host device cgroup ACL"
);
if
(
virSecurityManagerRestoreHostdevLabel
(
driver
->
securityManager
,
vm
->
def
,
hostdev
,
NULL
)
<
0
)
{
VIR_WARN
(
"Failed to restore host device labelling"
);
}
virDomainHostdevDefFree
(
hostdev
);
if
(
net
)
{
networkReleaseActualDevice
(
net
);
virDomainNetDefFree
(
net
);
}
}
int
qemuDomainDetachVirtioDiskDevice
(
virQEMUDriverPtr
driver
,
virDomainObjPtr
vm
,
virDomainDiskDefPtr
detach
)
...
...
@@ -2585,68 +2715,31 @@ qemuDomainDetachHostPciDevice(virQEMUDriverPtr driver,
{
qemuDomainObjPrivatePtr
priv
=
vm
->
privateData
;
virDomainHostdevSubsysPtr
subsys
=
&
detach
->
source
.
subsys
;
int
ret
=
-
1
,
rv
;
virPCIDevicePtr
pci
;
virPCIDevicePtr
activePci
;
virQEMUDriverConfigPtr
cfg
=
virQEMUDriverGetConfig
(
driver
);
int
ret
;
if
(
qemuIsMultiFunctionDevice
(
vm
->
def
,
detach
->
info
))
{
virReportError
(
VIR_ERR_OPERATION_FAILED
,
_
(
"cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"
),
subsys
->
u
.
pci
.
addr
.
domain
,
subsys
->
u
.
pci
.
addr
.
bus
,
subsys
->
u
.
pci
.
addr
.
slot
,
subsys
->
u
.
pci
.
addr
.
function
);
goto
cleanup
;
return
-
1
;
}
if
(
!
virDomainDeviceAddressIsValid
(
detach
->
info
,
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI
))
{
virReportError
(
VIR_ERR_OPERATION_FAILED
,
"%s"
,
_
(
"device cannot be detached without a PCI address"
));
goto
cleanup
;
return
-
1
;
}
qemuDomainObjEnterMonitor
(
driver
,
vm
);
if
(
virQEMUCapsGet
(
priv
->
qemuCaps
,
QEMU_CAPS_DEVICE
))
{
r
v
=
qemuMonitorDelDevice
(
priv
->
mon
,
detach
->
info
->
alias
);
r
et
=
qemuMonitorDelDevice
(
priv
->
mon
,
detach
->
info
->
alias
);
}
else
{
r
v
=
qemuMonitorRemovePCIDevice
(
priv
->
mon
,
&
detach
->
info
->
addr
.
pci
);
r
et
=
qemuMonitorRemovePCIDevice
(
priv
->
mon
,
&
detach
->
info
->
addr
.
pci
);
}
qemuDomainObjExitMonitor
(
driver
,
vm
);
virDomainAuditHostdev
(
vm
,
detach
,
"detach"
,
rv
==
0
);
if
(
rv
<
0
)
goto
cleanup
;
/*
* For SRIOV net host devices, unset mac and port profile before
* reset and reattach device
*/
if
(
detach
->
parent
.
data
.
net
)
qemuDomainHostdevNetConfigRestore
(
detach
,
cfg
->
stateDir
);
virObjectLock
(
driver
->
activePciHostdevs
);
virObjectLock
(
driver
->
inactivePciHostdevs
);
pci
=
virPCIDeviceNew
(
subsys
->
u
.
pci
.
addr
.
domain
,
subsys
->
u
.
pci
.
addr
.
bus
,
subsys
->
u
.
pci
.
addr
.
slot
,
subsys
->
u
.
pci
.
addr
.
function
);
if
(
pci
)
{
activePci
=
virPCIDeviceListSteal
(
driver
->
activePciHostdevs
,
pci
);
if
(
activePci
&&
virPCIDeviceReset
(
activePci
,
driver
->
activePciHostdevs
,
driver
->
inactivePciHostdevs
)
==
0
)
{
qemuReattachPciDevice
(
activePci
,
driver
);
ret
=
0
;
}
else
{
/* reset of the device failed, treat it as if it was returned */
virPCIDeviceFree
(
activePci
);
}
virPCIDeviceFree
(
pci
);
}
virObjectUnlock
(
driver
->
activePciHostdevs
);
virObjectUnlock
(
driver
->
inactivePciHostdevs
);
qemuDomainReleaseDeviceAddress
(
vm
,
detach
->
info
,
NULL
);
cleanup:
virObjectUnref
(
cfg
);
return
ret
;
}
...
...
@@ -2656,8 +2749,6 @@ qemuDomainDetachHostUsbDevice(virQEMUDriverPtr driver,
virDomainHostdevDefPtr
detach
)
{
qemuDomainObjPrivatePtr
priv
=
vm
->
privateData
;
virDomainHostdevSubsysPtr
subsys
=
&
detach
->
source
.
subsys
;
virUSBDevicePtr
usb
;
int
ret
;
if
(
!
detach
->
info
->
alias
)
{
...
...
@@ -2675,20 +2766,7 @@ qemuDomainDetachHostUsbDevice(virQEMUDriverPtr driver,
qemuDomainObjEnterMonitor
(
driver
,
vm
);
ret
=
qemuMonitorDelDevice
(
priv
->
mon
,
detach
->
info
->
alias
);
qemuDomainObjExitMonitor
(
driver
,
vm
);
virDomainAuditHostdev
(
vm
,
detach
,
"detach"
,
ret
==
0
);
if
(
ret
<
0
)
return
-
1
;
usb
=
virUSBDeviceNew
(
subsys
->
u
.
usb
.
bus
,
subsys
->
u
.
usb
.
device
,
NULL
);
if
(
usb
)
{
virObjectLock
(
driver
->
activeUsbHostdevs
);
virUSBDeviceListDel
(
driver
->
activeUsbHostdevs
,
usb
);
virObjectUnlock
(
driver
->
activeUsbHostdevs
);
virUSBDeviceFree
(
usb
);
}
else
{
VIR_WARN
(
"Unable to find device %03d.%03d in list of used USB devices"
,
subsys
->
u
.
usb
.
bus
,
subsys
->
u
.
usb
.
device
);
}
return
ret
;
}
...
...
@@ -2736,11 +2814,6 @@ qemuDomainDetachHostScsiDevice(virQEMUDriverPtr driver,
}
qemuDomainObjExitMonitor
(
driver
,
vm
);
virDomainAuditHostdev
(
vm
,
detach
,
"detach"
,
ret
==
0
);
if
(
ret
==
0
)
qemuDomainReAttachHostScsiDevices
(
driver
,
vm
->
def
->
name
,
&
detach
,
1
);
cleanup:
VIR_FREE
(
drvstr
);
VIR_FREE
(
devstr
);
...
...
@@ -2750,27 +2823,10 @@ cleanup:
static
int
qemuDomainDetachThisHostDevice
(
virQEMUDriverPtr
driver
,
virDomainObjPtr
vm
,
virDomainHostdevDefPtr
detach
,
int
idx
)
virDomainHostdevDefPtr
detach
)
{
int
ret
=
-
1
;
if
(
idx
<
0
)
{
/* caller didn't know index of hostdev in hostdevs list, so we
* need to find it.
*/
for
(
idx
=
0
;
idx
<
vm
->
def
->
nhostdevs
;
idx
++
)
{
if
(
vm
->
def
->
hostdevs
[
idx
]
==
detach
)
break
;
}
if
(
idx
>=
vm
->
def
->
nhostdevs
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"device not found in hostdevs list (%zu entries)"
),
vm
->
def
->
nhostdevs
);
return
ret
;
}
}
switch
(
detach
->
source
.
subsys
.
type
)
{
case
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI
:
ret
=
qemuDomainDetachHostPciDevice
(
driver
,
vm
,
detach
);
...
...
@@ -2788,17 +2844,11 @@ qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver,
return
-
1
;
}
if
(
!
ret
)
{
if
(
qemuTeardownHostdevCgroup
(
vm
,
detach
)
<
0
)
VIR_WARN
(
"Failed to remove host device cgroup ACL"
);
if
(
ret
<
0
)
virDomainAuditHostdev
(
vm
,
detach
,
"detach"
,
false
);
else
qemuDomainRemoveHostDevice
(
driver
,
vm
,
detach
);
if
(
virSecurityManagerRestoreHostdevLabel
(
driver
->
securityManager
,
vm
->
def
,
detach
,
NULL
)
<
0
)
{
VIR_WARN
(
"Failed to restore host device labelling"
);
}
virDomainHostdevRemove
(
vm
->
def
,
idx
);
virDomainHostdevDefFree
(
detach
);
}
return
ret
;
}
...
...
@@ -2860,7 +2910,7 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
if
(
detach
->
parent
.
type
==
VIR_DOMAIN_DEVICE_NET
)
return
qemuDomainDetachNetDevice
(
driver
,
vm
,
&
detach
->
parent
);
else
return
qemuDomainDetachThisHostDevice
(
driver
,
vm
,
detach
,
idx
);
return
qemuDomainDetachThisHostDevice
(
driver
,
vm
,
detach
);
}
int
...
...
@@ -2893,13 +2943,7 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
if
(
virDomainNetGetActualType
(
detach
)
==
VIR_DOMAIN_NET_TYPE_HOSTDEV
)
{
/* coverity[negative_returns] */
ret
=
qemuDomainDetachThisHostDevice
(
driver
,
vm
,
virDomainNetGetActualHostdev
(
detach
),
-
1
);
if
(
!
ret
)
{
networkReleaseActualDevice
(
detach
);
virDomainNetRemove
(
vm
->
def
,
detachidx
);
virDomainNetDefFree
(
detach
);
}
virDomainNetGetActualHostdev
(
detach
));
goto
cleanup
;
}
if
(
STREQLEN
(
vm
->
def
->
os
.
machine
,
"s390-ccw"
,
8
)
&&
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录