Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Dec 2012 02:37:18 +0000 (UTC)
From:      Peter Grehan <grehan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r244013 - projects/bhyve/usr.sbin/bhyve
Message-ID:  <201212080237.qB82bIuQ042744@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: grehan
Date: Sat Dec  8 02:37:18 2012
New Revision: 244013
URL: http://svnweb.freebsd.org/changeset/base/244013

Log:
  Determine the correct length and sector size for raw devices.
  
  Obtained from:	NetApp
  Tested by:	Michael Dexter with iscsi LUNs

Modified:
  projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c

Modified: projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c
==============================================================================
--- projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c	Sat Dec  8 02:32:35 2012	(r244012)
+++ projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c	Sat Dec  8 02:37:18 2012	(r244013)
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/stat.h>
 #include <sys/uio.h>
 #include <sys/ioctl.h>
+#include <sys/disk.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -331,7 +332,9 @@ pci_vtblk_init(struct vmctx *ctx, struct
 {
 	struct stat sbuf;
 	struct pci_vtblk_softc *sc;
+	off_t size;	
 	int fd;
+	int sectsz;
 
 	if (opts == NULL) {
 		printf("virtio-block: backing device required\n");
@@ -359,7 +362,23 @@ pci_vtblk_init(struct vmctx *ctx, struct
 		close(fd);
 		return (1);
 	}
-	
+
+	/*
+	 * Deal with raw devices
+	 */
+	size = sbuf.st_size;
+	sectsz = DEV_BSIZE;
+	if (S_ISCHR(sbuf.st_mode)) {
+		if (ioctl(fd, DIOCGMEDIASIZE, &size) < 0 ||
+		    ioctl(fd, DIOCGSECTORSIZE, &sectsz)) {
+			perror("Could not fetch dev blk/sector size");
+			close(fd);
+			return (1);
+		}
+		assert(size != 0);
+		assert(sectsz != 0);
+	}
+
 	sc = malloc(sizeof(struct pci_vtblk_softc));
 	memset(sc, 0, sizeof(struct pci_vtblk_softc));
 
@@ -368,9 +387,9 @@ pci_vtblk_init(struct vmctx *ctx, struct
 	sc->vbsc_fd = fd;
 
 	/* setup virtio block config space */
-	sc->vbsc_cfg.vbc_capacity = sbuf.st_size / DEV_BSIZE;
+	sc->vbsc_cfg.vbc_capacity = size / sectsz;
 	sc->vbsc_cfg.vbc_seg_max = VTBLK_MAXSEGS;
-	sc->vbsc_cfg.vbc_blk_size = DEV_BSIZE;
+	sc->vbsc_cfg.vbc_blk_size = sectsz;
 	sc->vbsc_cfg.vbc_size_max = 0;	/* not negotiated */
 	sc->vbsc_cfg.vbc_geom_c = 0;	/* no geometry */
 	sc->vbsc_cfg.vbc_geom_h = 0;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212080237.qB82bIuQ042744>