From nobody Tue Nov 23 23:12:44 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D2AE918A1260; Tue, 23 Nov 2021 23:12:45 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzKg033Qrz3vSP; Tue, 23 Nov 2021 23:12:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1F63A1F722; Tue, 23 Nov 2021 23:12:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ANNCi14037458; Tue, 23 Nov 2021 23:12:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ANNCikt037457; Tue, 23 Nov 2021 23:12:44 GMT (envelope-from git) Date: Tue, 23 Nov 2021 23:12:44 GMT Message-Id: <202111232312.1ANNCikt037457@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 5f6c2bd03bc3 - stable/13 - bhyve: Support setting the disk serial number for VirtIO block devices. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5f6c2bd03bc35d8ffae3bd7a0ffe38822441b0c8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637709164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sG+2cZI9pcpf3ThyW8zWD9CWXZsebkj6Yx8itNvVQMA=; b=b+mDrJPRrYaEeEipDJWkemeP0lbYBL44NC46PBFnQ19cvuZHtZbcFWaihXUyyKJlt8hO8U E+w+Opg9o2Blp6lU5/ysG4NsZcpwbzTfUXQb5fgvm6z6PIedfBF9eR0FsHSgQ/8iCX6Tv2 Tbgow/19q5ym420ZI5DbR8vBc1M3ZYJzsqc6cMghiI0aKQcj48Frh+Zy41+GZe7zggDmj/ XNQR7s5T0p/hOvsF2q98ZDcraaLtZBmuZB3FlLxfZIUBwSzuFinjvcwpCri1KCi1qgQVNZ tORj/3LHd6soaYneDoQtpMGMzzpxsWEecyWw1/gjwxi8gETtD65PqIKaYpnHdQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637709164; a=rsa-sha256; cv=none; b=a6geY7YnZWmRRCBTf4jv8ElVpf/MS1L0Sh0rvZEeNnMgeqwB3a0v6r8/CbDjpXXMNPGJB3 Nty/z3U6kF4LuSF9ehDutU3N86yp5Hvr1w+uVtWQ6Kq32/2ZYl/RN5MojxjkN2sLWhNKKv f7hkEGflqWV1BmCcdsrT6e+noPjOWx2YYRAXemy3XefiF+NohJEXSigRT0FIoCbvZTAHl7 3XMGE17bvFOYHmHezMyqh2EKZtme9ntPObKV3/ZyxG6L21sAFNItZl8dnt2kr12LpriT9x 9VSksOrwOBKqaaP8E7iHbx7CMtADidq4XUbrfB+JuOndmqSO6rxpoPI6ZY9hWw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=5f6c2bd03bc35d8ffae3bd7a0ffe38822441b0c8 commit 5f6c2bd03bc35d8ffae3bd7a0ffe38822441b0c8 Author: John Baldwin AuthorDate: 2021-09-17 16:55:06 +0000 Commit: John Baldwin CommitDate: 2021-11-23 23:11:43 +0000 bhyve: Support setting the disk serial number for VirtIO block devices. Reviewed by: allanjude Obtained from: illumos Differential Revision: https://reviews.freebsd.org/D31983 (cherry picked from commit c6efcb1281f3518a92fdc579d2c3c3c74eb6070c) --- usr.sbin/bhyve/bhyve_config.5 | 12 +++++++++++- usr.sbin/bhyve/pci_virtio_block.c | 27 +++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5 index 1a77b1bbacb4..a9cea3849c01 100644 --- a/usr.sbin/bhyve/bhyve_config.5 +++ b/usr.sbin/bhyve/bhyve_config.5 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 20, 2021 +.Dd September 17, 2021 .Dt BHYVE_CONFIG 5 .Os .Sh NAME @@ -512,6 +512,16 @@ The path of a directory on the host to export to the guest. .It Va ro Ta bool Ta false Ta If true, the guest filesystem is read-only. .El +.Ss VirtIO Block Device Settings +In addition to the block device settings described above, each +VirtIO block device supports the following settings: +.Bl -column "model" "integer" "generated" +.It Sy Name Ta Sy Format Ta Sy Default Ta Sy Description +.It Va ser Ta string Ta generated Ta +Serial number of up to twenty characters. +A default serial number is generated using a hash of the backing +store's pathname. +.El .Ss VirtIO Console Device Settings Each VirtIO Console device contains one or more console ports. Each port stores its settings in a node named diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 3718b2d7eff0..385b812be84c 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -453,7 +453,7 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) { char bident[sizeof("XX:X:X")]; struct blockif_ctxt *bctxt; - const char *path; + const char *path, *serial; MD5_CTX mdctx; u_char digest[16]; struct pci_vtblk_softc *sc; @@ -498,16 +498,23 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) /* sc->vbsc_vq.vq_notify = we have no per-queue notify */ /* - * Create an identifier for the backing file. Use parts of the - * md5 sum of the filename + * If an explicit identifier is not given, create an + * identifier using parts of the md5 sum of the filename. */ - path = get_config_value_node(nvl, "path"); - MD5Init(&mdctx); - MD5Update(&mdctx, path, strlen(path)); - MD5Final(digest, &mdctx); - snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES, - "BHYVE-%02X%02X-%02X%02X-%02X%02X", - digest[0], digest[1], digest[2], digest[3], digest[4], digest[5]); + bzero(sc->vbsc_ident, VTBLK_BLK_ID_BYTES); + if ((serial = get_config_value_node(nvl, "serial")) != NULL || + (serial = get_config_value_node(nvl, "ser")) != NULL) { + strlcpy(sc->vbsc_ident, serial, VTBLK_BLK_ID_BYTES); + } else { + path = get_config_value_node(nvl, "path"); + MD5Init(&mdctx); + MD5Update(&mdctx, path, strlen(path)); + MD5Final(digest, &mdctx); + snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES, + "BHYVE-%02X%02X-%02X%02X-%02X%02X", + digest[0], digest[1], digest[2], digest[3], digest[4], + digest[5]); + } /* setup virtio block config space */ sc->vbsc_cfg.vbc_capacity = size / VTBLK_BSIZE; /* 512-byte units */