bhyvectl: don't permit using --suspend and --checkpoint at same time

When using the --suspend and --checkpoint parameter, bhyvectl will
produce two checkpoint images and the exits. This is slightly ambiguous.
So, permit only one of theses parameters at the same time.

Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38887
This commit is contained in:
Vitaliy Gusev 2023-03-06 13:42:15 +01:00 committed by Corvin Köhne
parent 9a9a248964
commit 062f2818c1
No known key found for this signature in database
GPG Key ID: D854DA56315E026A

View File

@ -86,8 +86,7 @@ usage(bool cpu_intel)
" [--create]\n"
" [--destroy]\n"
#ifdef BHYVE_SNAPSHOT
" [--checkpoint=<filename>]\n"
" [--suspend=<filename>]\n"
" [--checkpoint=<filename> | --suspend=<filename>]\n"
#endif
" [--get-all]\n"
" [--get-stats]\n"
@ -299,7 +298,6 @@ static int unassign_pptdev, bus, slot, func;
static int run;
static int get_cpu_topology;
#ifdef BHYVE_SNAPSHOT
static int vm_checkpoint_opt;
static int vm_suspend_opt;
#endif
@ -1743,7 +1741,7 @@ main(int argc, char *argv[])
struct tm tm;
struct option *opts;
#ifdef BHYVE_SNAPSHOT
char *checkpoint_file, *suspend_file;
char *checkpoint_file = NULL;
#endif
cpu_intel = cpu_vendor_intel();
@ -1905,12 +1903,12 @@ main(int argc, char *argv[])
break;
#ifdef BHYVE_SNAPSHOT
case SET_CHECKPOINT_FILE:
vm_checkpoint_opt = 1;
checkpoint_file = optarg;
break;
case SET_SUSPEND_FILE:
vm_suspend_opt = 1;
suspend_file = optarg;
if (checkpoint_file != NULL)
usage(cpu_intel);
checkpoint_file = optarg;
vm_suspend_opt = (ch == SET_SUSPEND_FILE);
break;
#endif
default:
@ -2385,11 +2383,8 @@ main(int argc, char *argv[])
vm_destroy(ctx);
#ifdef BHYVE_SNAPSHOT
if (!error && vm_checkpoint_opt)
error = snapshot_request(vmname, checkpoint_file, false);
if (!error && vm_suspend_opt)
error = snapshot_request(vmname, suspend_file, true);
if (!error && checkpoint_file)
error = snapshot_request(vmname, checkpoint_file, vm_suspend_opt);
#endif
free (opts);