From owner-svn-src-all@freebsd.org Thu Jun 25 12:35:21 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CA8FC359F3A; Thu, 25 Jun 2020 12:35:21 +0000 (UTC) (envelope-from kaktus@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49szxj4tn3z42Mr; Thu, 25 Jun 2020 12:35:21 +0000 (UTC) (envelope-from kaktus@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9E94E230FE; Thu, 25 Jun 2020 12:35:21 +0000 (UTC) (envelope-from kaktus@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05PCZLWJ018915; Thu, 25 Jun 2020 12:35:21 GMT (envelope-from kaktus@FreeBSD.org) Received: (from kaktus@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05PCZLTX018913; Thu, 25 Jun 2020 12:35:21 GMT (envelope-from kaktus@FreeBSD.org) Message-Id: <202006251235.05PCZLTX018913@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kaktus set sender to kaktus@FreeBSD.org using -f From: Pawel Biernacki Date: Thu, 25 Jun 2020 12:35:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362612 - head/usr.sbin/bhyve X-SVN-Group: head X-SVN-Commit-Author: kaktus X-SVN-Commit-Paths: head/usr.sbin/bhyve X-SVN-Commit-Revision: 362612 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jun 2020 12:35:21 -0000 Author: kaktus Date: Thu Jun 25 12:35:20 2020 New Revision: 362612 URL: https://svnweb.freebsd.org/changeset/base/362612 Log: bhyve: allow for automatic destruction on power-off Introduce -D flag that allows for the VM to be destroyed on guest initiated power-off by the bhyve(8) process itself. This is quality of life change that allows for simpler deployments without the need for bhyvectl --destroy. Requested by: swills Reviewed by: 0mp (manpages), grehan, kib, swills Approved by: kib (mentor) MFC after: 2 weeks Sponsored by: Mysterious Code Ltd. Differential Revision: https://reviews.freebsd.org/D25414 Modified: head/usr.sbin/bhyve/bhyve.8 head/usr.sbin/bhyve/bhyverun.c Modified: head/usr.sbin/bhyve/bhyve.8 ============================================================================== --- head/usr.sbin/bhyve/bhyve.8 Thu Jun 25 12:31:05 2020 (r362611) +++ head/usr.sbin/bhyve/bhyve.8 Thu Jun 25 12:35:20 2020 (r362612) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 18, 2020 +.Dd Jun 25, 2020 .Dt BHYVE 8 .Os .Sh NAME @@ -32,7 +32,7 @@ .Nd "run a guest operating system inside a virtual machine" .Sh SYNOPSIS .Nm -.Op Fl AabCeHhPSuWwxY +.Op Fl AabCDeHhPSuWwxY .Oo .Sm off .Fl c\~ @@ -131,6 +131,8 @@ If a is specified more than once the last one has precedence. .It Fl C Include guest memory in core file. +.It Fl D +Destroy the VM on guest initiated power-off. .It Fl e Force .Nm Modified: head/usr.sbin/bhyve/bhyverun.c ============================================================================== --- head/usr.sbin/bhyve/bhyverun.c Thu Jun 25 12:31:05 2020 (r362611) +++ head/usr.sbin/bhyve/bhyverun.c Thu Jun 25 12:35:20 2020 (r362612) @@ -197,6 +197,7 @@ static int gdb_port = 0; static int guest_vmexit_on_hlt, guest_vmexit_on_pause; static int virtio_msix = 1; static int x2apic_mode = 0; /* default is xAPIC */ +static int destroy_on_poweroff = 0; static int strictio; static int strictmsr = 1; @@ -236,7 +237,7 @@ usage(int code) { fprintf(stderr, - "Usage: %s [-abehuwxACHPSWY]\n" + "Usage: %s [-abehuwxACDHPSWY]\n" " %*s [-c [[cpus=]numcpus][,sockets=n][,cores=n][,threads=n]]\n" " %*s [-g ] [-l ]\n" " %*s [-m mem] [-p vcpu:hostcpu] [-s ] [-U uuid] \n" @@ -244,6 +245,7 @@ usage(int code) " -A: create ACPI tables\n" " -c: number of cpus and/or topology specification\n" " -C: include guest memory in core file\n" + " -D: destroy on power-off\n" " -e: exit on unhandled I/O access\n" " -g: gdb port\n" " -h: help\n" @@ -815,6 +817,8 @@ vmexit_suspend(struct vmctx *ctx, struct vm_exit *vmex case VM_SUSPEND_RESET: exit(0); case VM_SUSPEND_POWEROFF: + if (destroy_on_poweroff) + vm_destroy(ctx); exit(1); case VM_SUSPEND_HALT: exit(2); @@ -1101,9 +1105,9 @@ main(int argc, char *argv[]) memflags = 0; #ifdef BHYVE_SNAPSHOT - optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:U:r:"; + optstr = "abehuwxACDHIPSWYp:g:G:c:s:m:l:U:r:"; #else - optstr = "abehuwxACHIPSWYp:g:G:c:s:m:l:U:"; + optstr = "abehuwxACDHIPSWYp:g:G:c:s:m:l:U:"; #endif while ((c = getopt(argc, argv, optstr)) != -1) { switch (c) { @@ -1115,6 +1119,9 @@ main(int argc, char *argv[]) break; case 'b': bvmcons = 1; + break; + case 'D': + destroy_on_poweroff = 1; break; case 'p': if (pincpu_parse(optarg) != 0) {