From owner-svn-src-all@FreeBSD.ORG Sat Oct 12 19:41:36 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7688FF0A; Sat, 12 Oct 2013 19:41:36 +0000 (UTC) (envelope-from grehan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 61F752DBE; Sat, 12 Oct 2013 19:41:36 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9CJfanL019671; Sat, 12 Oct 2013 19:41:36 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9CJfaCk019670; Sat, 12 Oct 2013 19:41:36 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201310121941.r9CJfaCk019670@svn.freebsd.org> From: Peter Grehan Date: Sat, 12 Oct 2013 19:41:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r256390 - stable/10/usr.sbin/bhyve X-SVN-Group: stable-10 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.14 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: Sat, 12 Oct 2013 19:41:36 -0000 Author: grehan Date: Sat Oct 12 19:41:35 2013 New Revision: 256390 URL: http://svnweb.freebsd.org/changeset/base/256390 Log: MFC r256389 Implement the virtio block 'get-ident' operation. This eliminates the annoying verbose boot error of the form g_handleattr: vtbd0 bio_length 24 len 28 -> EFAULT The ident returned by bhyve is a text string 'BHYVE-XXXX-XXXX', where the X's are the first bytes of the md5 hash of the backing filename. Approved by: re (gjb) Modified: stable/10/usr.sbin/bhyve/pci_virtio_block.c Directory Properties: stable/10/usr.sbin/bhyve/ (props changed) Modified: stable/10/usr.sbin/bhyve/pci_virtio_block.c ============================================================================== --- stable/10/usr.sbin/bhyve/pci_virtio_block.c Sat Oct 12 19:31:19 2013 (r256389) +++ stable/10/usr.sbin/bhyve/pci_virtio_block.c Sat Oct 12 19:41:35 2013 (r256390) @@ -46,17 +46,25 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "bhyverun.h" #include "pci_emul.h" #include "virtio.h" +#ifndef min +#define min(a, b) ((a) < (b) ? (a) : (b)) +#endif + #define VTBLK_RINGSZ 64 #define VTBLK_MAXSEGS 32 #define VTBLK_S_OK 0 #define VTBLK_S_IOERR 1 +#define VTBLK_S_UNSUPP 2 + +#define VTBLK_BLK_ID_BYTES 20 /* * Host capabilities @@ -85,6 +93,7 @@ struct vtblk_config { struct virtio_blk_hdr { #define VBH_OP_READ 0 #define VBH_OP_WRITE 1 +#define VBH_OP_IDENT 8 #define VBH_FLAG_BARRIER 0x80000000 /* OR'ed into vbh_type */ uint32_t vbh_type; uint32_t vbh_ioprio; @@ -106,6 +115,7 @@ struct pci_vtblk_softc { struct vqueue_info vbsc_vq; int vbsc_fd; struct vtblk_config vbsc_cfg; + char vbsc_ident[VTBLK_BLK_ID_BYTES]; }; static void pci_vtblk_reset(void *); @@ -180,7 +190,7 @@ pci_vtblk_proc(struct pci_vtblk_softc *s for (i = 1; i < n; i++) { /* * - write op implies read-only descriptor, - * - read op implies write-only descriptor, + * - read/ident op implies write-only descriptor, * therefore test the inverse of the descriptor bit * to the op. */ @@ -189,14 +199,34 @@ pci_vtblk_proc(struct pci_vtblk_softc *s } DPRINTF(("virtio-block: %s op, %d bytes, %d segs, offset %ld\n\r", - writeop ? "write" : "read", iolen, i - 1, offset)); + writeop ? "write" : "read/ident", iolen, i - 1, offset)); - if (writeop) + switch (type) { + case VBH_OP_WRITE: err = pwritev(sc->vbsc_fd, iov + 1, i - 1, offset); - else + break; + case VBH_OP_READ: err = preadv(sc->vbsc_fd, iov + 1, i - 1, offset); + break; + case VBH_OP_IDENT: + /* Assume a single buffer */ + strlcpy(iov[1].iov_base, sc->vbsc_ident, + min(iov[1].iov_len, sizeof(sc->vbsc_ident))); + err = 0; + break; + default: + err = -ENOSYS; + break; + } - *status = err < 0 ? VTBLK_S_IOERR : VTBLK_S_OK; + /* convert errno into a virtio block error return */ + if (err < 0) { + if (err == -ENOSYS) + *status = VTBLK_S_UNSUPP; + else + *status = VTBLK_S_IOERR; + } else + *status = VTBLK_S_OK; /* * Return the descriptor back to the host. @@ -220,6 +250,8 @@ static int pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) { struct stat sbuf; + MD5_CTX mdctx; + u_char digest[16]; struct pci_vtblk_softc *sc; off_t size; int fd; @@ -274,6 +306,16 @@ pci_vtblk_init(struct vmctx *ctx, struct sc->vbsc_vq.vq_qsize = VTBLK_RINGSZ; /* 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 + */ + MD5Init(&mdctx); + MD5Update(&mdctx, opts, strlen(opts)); + MD5Final(digest, &mdctx); + sprintf(sc->vbsc_ident, "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 / sectsz; sc->vbsc_cfg.vbc_seg_max = VTBLK_MAXSEGS;