diff --git a/ChangeLog b/ChangeLog index 1d82eac76cad360e549f5ccc3055510c751fe98f..b36aea1e68519aeaf6ed493453f37dfd462e5af6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Mar 2 17:26:48 CET 2009 Daniel Veillard + + * src/virsh.c: add 3 new commands for node device detach, + reattach and reset, patch by Mark McLoughlin. + Mon Mar 2 17:19:23 CET 2009 Daniel Veillard * include/libvirt/libvirt.h include/libvirt/libvirt.h.in @@ -5,7 +10,8 @@ Mon Mar 2 17:19:23 CET 2009 Daniel Veillard src/lxc_driver.c src/openvz_driver.c src/qemu_driver.c src/test.c src/uml_driver.c: add the public APIs for virNodeDeviceDettach virNodeDeviceReAttach and virNodeDeviceReset - and extends the driver structure accordingly. + and extends the driver structure accordingly, patch by Mark + McLoughlin. Mon Mar 2 17:07:44 CET 2009 Daniel Veillard diff --git a/src/virsh.c b/src/virsh.c index 298dde0c749b8b79f5c702469f6cbd2259ae86a9..8ae79c50d2cf233cf4d2fc76e806aebce6939f03 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -4432,6 +4432,129 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd) return TRUE; } +/* + * "nodedev-dettach" command + */ +static const vshCmdInfo info_node_device_dettach[] = { + {"help", gettext_noop("dettach node device its device driver")}, + {"desc", gettext_noop("Dettach node device its device driver before assigning to a domain.")}, + {NULL, NULL} +}; + + +static const vshCmdOptDef opts_node_device_dettach[] = { + {"device", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("device key")}, + {NULL, 0, 0, NULL} +}; + +static int +cmdNodeDeviceDettach (vshControl *ctl, const vshCmd *cmd) +{ + const char *name; + virNodeDevicePtr device; + int ret = TRUE; + + if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) + return FALSE; + if (!(name = vshCommandOptString(cmd, "device", NULL))) + return FALSE; + if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { + vshError(ctl, FALSE, "%s '%s'", _("Could not find matching device"), name); + return FALSE; + } + + if (virNodeDeviceDettach(device) == 0) { + vshPrint(ctl, _("Device %s dettached\n"), name); + } else { + vshError(ctl, FALSE, _("Failed to dettach device %s"), name); + ret = FALSE; + } + virNodeDeviceFree(device); + return ret; +} + +/* + * "nodedev-reattach" command + */ +static const vshCmdInfo info_node_device_reattach[] = { + {"help", gettext_noop("reattach node device its device driver")}, + {"desc", gettext_noop("Dettach node device its device driver before assigning to a domain.")}, + {NULL, NULL} +}; + + +static const vshCmdOptDef opts_node_device_reattach[] = { + {"device", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("device key")}, + {NULL, 0, 0, NULL} +}; + +static int +cmdNodeDeviceReAttach (vshControl *ctl, const vshCmd *cmd) +{ + const char *name; + virNodeDevicePtr device; + int ret = TRUE; + + if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) + return FALSE; + if (!(name = vshCommandOptString(cmd, "device", NULL))) + return FALSE; + if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { + vshError(ctl, FALSE, "%s '%s'", _("Could not find matching device"), name); + return FALSE; + } + + if (virNodeDeviceReAttach(device) == 0) { + vshPrint(ctl, _("Device %s re-attached\n"), name); + } else { + vshError(ctl, FALSE, _("Failed to re-attach device %s"), name); + ret = FALSE; + } + virNodeDeviceFree(device); + return ret; +} + +/* + * "nodedev-reset" command + */ +static const vshCmdInfo info_node_device_reset[] = { + {"help", gettext_noop("reset node device")}, + {"desc", gettext_noop("Reset node device before or after assigning to a domain.")}, + {NULL, NULL} +}; + + +static const vshCmdOptDef opts_node_device_reset[] = { + {"device", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("device key")}, + {NULL, 0, 0, NULL} +}; + +static int +cmdNodeDeviceReset (vshControl *ctl, const vshCmd *cmd) +{ + const char *name; + virNodeDevicePtr device; + int ret = TRUE; + + if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) + return FALSE; + if (!(name = vshCommandOptString(cmd, "device", NULL))) + return FALSE; + if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) { + vshError(ctl, FALSE, "%s '%s'", _("Could not find matching device"), name); + return FALSE; + } + + if (virNodeDeviceReset(device) == 0) { + vshPrint(ctl, _("Device %s reset\n"), name); + } else { + vshError(ctl, FALSE, _("Failed to reset device %s"), name); + ret = FALSE; + } + virNodeDeviceFree(device); + return ret; +} + /* * "hostkey" command */ @@ -5576,6 +5699,9 @@ static const vshCmdDef commands[] = { {"nodedev-list", cmdNodeListDevices, opts_node_list_devices, info_node_list_devices}, {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml, info_node_device_dumpxml}, + {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach, info_node_device_dettach}, + {"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach, info_node_device_reattach}, + {"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset, info_node_device_reset}, {"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart}, {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build},