Add the options with-bootdevice, with-kernel, with-initrd, and with-cmdline to 'virsh start'. They allow to temporarily boot from another boot device, to use another kernel, initrd, and cmdline than defined in the persistent domain definition. Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx> Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> --- tools/virsh-domain.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 14 +++++++++ 2 files changed, 98 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7cf8373f05bc..3cb597b90937 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3953,6 +3953,25 @@ static const vshCmdOptDef opts_start[] = { .type = VSH_OT_STRING, .help = N_("pass file descriptors N,M,... to the guest") }, + {.name = "with-bootdevice", + .type = VSH_OT_STRING, + .help = N_("set boot device") + }, + {.name = "with-kernel", + .type = VSH_OT_STRING, + .flags = VSH_OFLAG_EMPTY_OK, + .help = N_("set boot kernel") + }, + {.name = "with-initrd", + .type = VSH_OT_STRING, + .flags = VSH_OFLAG_EMPTY_OK, + .help = N_("set boot initrd") + }, + {.name = "with-cmdline", + .type = VSH_OT_STRING, + .flags = VSH_OFLAG_EMPTY_OK, + .help = N_("set boot cmdline") + }, {.name = NULL} }; @@ -4004,6 +4023,7 @@ cmdStartGetFDs(vshControl *ctl, return -1; } + static bool cmdStart(vshControl *ctl, const vshCmd *cmd) { @@ -4016,6 +4036,10 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) int rc; size_t nfds = 0; int *fds = NULL; + const char *bootDeviceIdentifier = NULL; + const char *kernel = NULL; + const char *initrd = NULL; + const char *cmdline = NULL; if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL, VIRSH_BYNAME | VIRSH_BYUUID))) @@ -4038,9 +4062,68 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "force-boot")) flags |= VIR_DOMAIN_START_FORCE_BOOT; + if (vshCommandOptStringReq(ctl, cmd, "with-bootdevice", + &bootDeviceIdentifier) < 0 || + vshCommandOptStringReq(ctl, cmd, "with-kernel", + &kernel) < 0 || + vshCommandOptStringReq(ctl, cmd, "with-initrd", + &initrd) < 0 || + vshCommandOptStringReq(ctl, cmd, "with-cmdline", + &cmdline) < 0) + goto cleanup; + + if (nfds && (bootDeviceIdentifier || kernel || initrd || cmdline)) { + vshError(ctl, + _("Passing file descriptors together with temporarily changing" + " the boot configuration is currently not supported.")); + goto cleanup; + } + /* Prefer older API unless we have to pass extra parameters */ if (nfds) { rc = virDomainCreateWithFiles(dom, nfds, fds, flags); + } else if (bootDeviceIdentifier || kernel || initrd || cmdline) { + virTypedParameterPtr params = NULL; + int nparams = 0; + int maxparams = 0; + + if (bootDeviceIdentifier) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_DEVICE_IDENTIFIER, + VIR_TYPED_PARAM_STRING, + bootDeviceIdentifier); + + if (kernel) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_KERNEL, + VIR_TYPED_PARAM_STRING, + kernel); + + if (initrd) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_INITRD, + VIR_TYPED_PARAM_STRING, + initrd); + + if (cmdline) + virTypedParamsAddFromString(¶ms, + &nparams, + &maxparams, + VIR_DOMAIN_CREATE_PARM_CMDLINE, + VIR_TYPED_PARAM_STRING, + cmdline); + + rc = virDomainCreateWithParams(dom, + params, + nparams, + flags); + virTypedParamsFree(params, nparams); } else if (flags) { rc = virDomainCreateWithFlags(dom, flags); /* We can emulate force boot, even for older servers that @@ -4091,6 +4174,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) return ret; } + /* * "save" command */ diff --git a/tools/virsh.pod b/tools/virsh.pod index 929958a9533c..54316aa33b97 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2655,6 +2655,8 @@ repeat the command. =item B<start> I<domain-name-or-uuid> [I<--console>] [I<--paused>] [I<--autodestroy>] [I<--bypass-cache>] [I<--force-boot>] [I<--pass-fds N,M,...>] +[I<--with-bootdevice DEVICE-IDENTIFIER>] [I<--with-kernel KERNEL>] +[I<--with-initrd INITRD>] [I<--with-cmdline CMDLINE>] Start a (previously defined) inactive domain, either from the last B<managedsave> state, or via a fresh boot if no managedsave state is @@ -2668,6 +2670,18 @@ the restore will avoid the file system cache, although this may slow down the operation. If I<--force-boot> is specified, then any managedsave state is discarded and a fresh boot occurs. +If the I<--with-bootdevice> option is used and supported by the driver +then the domain will start with the specified device overriding the +persistent defined boot order for this start only. Valid block devices +for this option are displayed using B<domblklist>. To specify a block +device the displayed I<Target> value has to be used. Valid network +devices are displayed using B<domiflist>. To specify a network device +the displayed I<MAC> value has to be used. + +With I<--with-kernel>, I<--with-initrd>, and I<--with-cmdline> you can +specify the kernel, initrd, and cmdline to use for this start if the +used driver supports this. + If I<--pass-fds> is specified, the argument is a comma separated list of open file descriptors which should be pass on into the guest. The file descriptors will be re-numbered in the guest, starting from 3. This -- 2.13.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list