mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
virsh: use new virNodeDeviceDetachFlags
The virsh nodedev-detach command has a new --driver option. If it's given virsh will attempt to use the new virNodeDeviceDetachFlags API instead of virNodeDeviceDettach. Validation of the driver name string is left to the hypervisor (qemu accepts "kvm" or "vfio". The only other hypervisor that implements these functions is xen, and it only accepts NULL).
This commit is contained in:
parent
cad14a52ca
commit
d923f6c882
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virsh-nodedev.c: Commands in node device group
|
* virsh-nodedev.c: Commands in node device group
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005, 2007-2012 Red Hat, Inc.
|
* Copyright (C) 2005, 2007-2013 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -600,6 +600,10 @@ static const vshCmdOptDef opts_node_device_detach[] = {
|
|||||||
.flags = VSH_OFLAG_REQ,
|
.flags = VSH_OFLAG_REQ,
|
||||||
.help = N_("device key")
|
.help = N_("device key")
|
||||||
},
|
},
|
||||||
|
{.name = "driver",
|
||||||
|
.type = VSH_OT_STRING,
|
||||||
|
.help = N_("pci device assignment backend driver (e.g. 'vfio' or 'kvm'")
|
||||||
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -607,26 +611,36 @@ static bool
|
|||||||
cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
|
cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
|
const char *driverName = NULL;
|
||||||
virNodeDevicePtr device;
|
virNodeDevicePtr device;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
ignore_value(vshCommandOptString(cmd, "driver", &driverName));
|
||||||
|
|
||||||
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
|
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
|
||||||
vshError(ctl, _("Could not find matching device '%s'"), name);
|
vshError(ctl, _("Could not find matching device '%s'"), name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Yes, our public API is misspelled. At least virsh can accept
|
if (driverName) {
|
||||||
* either spelling. */
|
/* we must use the newer API that accepts a driverName */
|
||||||
if (virNodeDeviceDettach(device) == 0) {
|
if (virNodeDeviceDetachFlags(device, driverName, 0) < 0)
|
||||||
vshPrint(ctl, _("Device %s detached\n"), name);
|
ret = false;
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, _("Failed to detach device %s"), name);
|
/* Yes, our (old) public API is misspelled. At least virsh
|
||||||
ret = false;
|
* can accept either spelling. */
|
||||||
|
if (virNodeDeviceDettach(device) < 0)
|
||||||
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
vshPrint(ctl, _("Device %s detached\n"), name);
|
||||||
|
else
|
||||||
|
vshError(ctl, _("Failed to detach device %s"), name);
|
||||||
|
|
||||||
virNodeDeviceFree(device);
|
virNodeDeviceFree(device);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user