提交 81dc248e 编写于 作者: J Jonathon Jongsma 提交者: Erik Skultety

nodedev: refactor nodeDeviceFindNewDevice()

In preparation for creating mediated devices in libvirt, we will need to
wait for new mediated devices to be created as well. Refactor
nodeDeviceFindNewDevice() so that we can re-use the main logic from this
function to wait for different device types by passing a different
'find' function.
Signed-off-by: NJonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 c952d9cc
...@@ -447,6 +447,10 @@ nodeDeviceGetTime(time_t *t) ...@@ -447,6 +447,10 @@ nodeDeviceGetTime(time_t *t)
} }
typedef virNodeDevicePtr (*nodeDeviceFindNewDeviceFunc)(virConnectPtr conn,
const void* opaque);
/* When large numbers of devices are present on the host, it's /* When large numbers of devices are present on the host, it's
* possible for udev not to realize that it has work to do before we * possible for udev not to realize that it has work to do before we
* get here. We thus keep trying to find the new device we just * get here. We thus keep trying to find the new device we just
...@@ -462,8 +466,8 @@ nodeDeviceGetTime(time_t *t) ...@@ -462,8 +466,8 @@ nodeDeviceGetTime(time_t *t)
*/ */
static virNodeDevicePtr static virNodeDevicePtr
nodeDeviceFindNewDevice(virConnectPtr conn, nodeDeviceFindNewDevice(virConnectPtr conn,
const char *wwnn, nodeDeviceFindNewDeviceFunc func,
const char *wwpn) const void *opaque)
{ {
virNodeDevicePtr device = NULL; virNodeDevicePtr device = NULL;
time_t start = 0, now = 0; time_t start = 0, now = 0;
...@@ -474,7 +478,7 @@ nodeDeviceFindNewDevice(virConnectPtr conn, ...@@ -474,7 +478,7 @@ nodeDeviceFindNewDevice(virConnectPtr conn,
virWaitForDevices(); virWaitForDevices();
device = nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, 0); device = func(conn, opaque);
if (device != NULL) if (device != NULL)
break; break;
...@@ -488,6 +492,35 @@ nodeDeviceFindNewDevice(virConnectPtr conn, ...@@ -488,6 +492,35 @@ nodeDeviceFindNewDevice(virConnectPtr conn,
} }
typedef struct _NewSCSIHostFuncData NewSCSIHostFuncData;
struct _NewSCSIHostFuncData
{
const char *wwnn;
const char *wwpn;
};
static virNodeDevicePtr
nodeDeviceFindNewSCSIHostFunc(virConnectPtr conn,
const void *opaque)
{
const NewSCSIHostFuncData *data = opaque;
return nodeDeviceLookupSCSIHostByWWN(conn, data->wwnn, data->wwpn, 0);
}
static virNodeDevicePtr
nodeDeviceFindNewSCSIHost(virConnectPtr conn,
const char *wwnn,
const char *wwpn)
{
NewSCSIHostFuncData data = { .wwnn = wwnn, .wwpn = wwpn};
return nodeDeviceFindNewDevice(conn, nodeDeviceFindNewSCSIHostFunc, &data);
}
static bool static bool
nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNodeDevCapType type) nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNodeDevCapType type)
{ {
...@@ -538,7 +571,7 @@ nodeDeviceCreateXML(virConnectPtr conn, ...@@ -538,7 +571,7 @@ nodeDeviceCreateXML(virConnectPtr conn,
if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0)
return NULL; return NULL;
device = nodeDeviceFindNewDevice(conn, wwnn, wwpn); device = nodeDeviceFindNewSCSIHost(conn, wwnn, wwpn);
/* We don't check the return value, because one way or another, /* We don't check the return value, because one way or another,
* we're returning what we get... */ * we're returning what we get... */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册