summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bhyve/block_if.c
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2015-03-19 09:54:48 +0000
committermav <mav@FreeBSD.org>2015-03-19 09:54:48 +0000
commit207f5e4d982a38a26b05f47f9af3d5bea8778fc9 (patch)
treea43d4c7d01c1f9e6213b1cb8e41760dff54e8bca /usr.sbin/bhyve/block_if.c
parenta4ce980fefb8ebb6cc3d77b44a8757e7812314f8 (diff)
downloadFreeBSD-src-207f5e4d982a38a26b05f47f9af3d5bea8778fc9.zip
FreeBSD-src-207f5e4d982a38a26b05f47f9af3d5bea8778fc9.tar.gz
MFC r279654: Report logical/physical sector sizes for virtual SATA disk.
Diffstat (limited to 'usr.sbin/bhyve/block_if.c')
-rw-r--r--usr.sbin/bhyve/block_if.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c
index 8687e9a..5934006 100644
--- a/usr.sbin/bhyve/block_if.c
+++ b/usr.sbin/bhyve/block_if.c
@@ -83,6 +83,8 @@ struct blockif_ctxt {
int bc_rdonly;
off_t bc_size;
int bc_sectsz;
+ int bc_psectsz;
+ int bc_psectoff;
pthread_t bc_btid;
pthread_mutex_t bc_mtx;
pthread_cond_t bc_cond;
@@ -268,7 +270,7 @@ blockif_open(const char *optstr, const char *ident)
char *nopt, *xopts;
struct blockif_ctxt *bc;
struct stat sbuf;
- off_t size;
+ off_t size, psectsz, psectoff;
int extra, fd, i, sectsz;
int nocache, sync, ro;
@@ -323,6 +325,7 @@ blockif_open(const char *optstr, const char *ident)
*/
size = sbuf.st_size;
sectsz = DEV_BSIZE;
+ psectsz = psectoff = 0;
if (S_ISCHR(sbuf.st_mode)) {
if (ioctl(fd, DIOCGMEDIASIZE, &size) < 0 ||
ioctl(fd, DIOCGSECTORSIZE, &sectsz)) {
@@ -332,7 +335,10 @@ blockif_open(const char *optstr, const char *ident)
}
assert(size != 0);
assert(sectsz != 0);
- }
+ if (ioctl(fd, DIOCGSTRIPESIZE, &psectsz) == 0 && psectsz > 0)
+ ioctl(fd, DIOCGSTRIPEOFFSET, &psectoff);
+ } else
+ psectsz = sbuf.st_blksize;
bc = calloc(1, sizeof(struct blockif_ctxt));
if (bc == NULL) {
@@ -345,6 +351,8 @@ blockif_open(const char *optstr, const char *ident)
bc->bc_rdonly = ro;
bc->bc_size = size;
bc->bc_sectsz = sectsz;
+ bc->bc_psectsz = psectsz;
+ bc->bc_psectoff = psectoff;
pthread_mutex_init(&bc->bc_mtx, NULL);
pthread_cond_init(&bc->bc_cond, NULL);
TAILQ_INIT(&bc->bc_freeq);
@@ -595,6 +603,15 @@ blockif_sectsz(struct blockif_ctxt *bc)
return (bc->bc_sectsz);
}
+void
+blockif_psectsz(struct blockif_ctxt *bc, int *size, int *off)
+{
+
+ assert(bc->bc_magic == BLOCKIF_SIG);
+ *size = bc->bc_psectsz;
+ *off = bc->bc_psectoff;
+}
+
int
blockif_queuesz(struct blockif_ctxt *bc)
{
OpenPOWER on IntegriCloud