From owner-svn-src-stable@FreeBSD.ORG Thu Mar 19 09:54:50 2015 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1ED40A20; Thu, 19 Mar 2015 09:54:50 +0000 (UTC) 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)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 092336AE; Thu, 19 Mar 2015 09:54:50 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t2J9snkj050203; Thu, 19 Mar 2015 09:54:49 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t2J9snJw050199; Thu, 19 Mar 2015 09:54:49 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201503190954.t2J9snJw050199@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 19 Mar 2015 09:54:49 +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: r280244 - 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-stable@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2015 09:54:50 -0000 Author: mav Date: Thu Mar 19 09:54:48 2015 New Revision: 280244 URL: https://svnweb.freebsd.org/changeset/base/280244 Log: MFC r279654: Report logical/physical sector sizes for virtual SATA disk. Modified: stable/10/usr.sbin/bhyve/block_if.c stable/10/usr.sbin/bhyve/block_if.h stable/10/usr.sbin/bhyve/pci_ahci.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/bhyve/block_if.c ============================================================================== --- stable/10/usr.sbin/bhyve/block_if.c Thu Mar 19 09:53:00 2015 (r280243) +++ stable/10/usr.sbin/bhyve/block_if.c Thu Mar 19 09:54:48 2015 (r280244) @@ -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 c 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 c */ 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, §sz)) { @@ -332,7 +335,10 @@ blockif_open(const char *optstr, const c } 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 c 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) { Modified: stable/10/usr.sbin/bhyve/block_if.h ============================================================================== --- stable/10/usr.sbin/bhyve/block_if.h Thu Mar 19 09:53:00 2015 (r280243) +++ stable/10/usr.sbin/bhyve/block_if.h Thu Mar 19 09:54:48 2015 (r280244) @@ -55,6 +55,7 @@ off_t blockif_size(struct blockif_ctxt * void blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h, uint8_t *s); int blockif_sectsz(struct blockif_ctxt *bc); +void blockif_psectsz(struct blockif_ctxt *bc, int *size, int *off); int blockif_queuesz(struct blockif_ctxt *bc); int blockif_is_ro(struct blockif_ctxt *bc); int blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq); Modified: stable/10/usr.sbin/bhyve/pci_ahci.c ============================================================================== --- stable/10/usr.sbin/bhyve/pci_ahci.c Thu Mar 19 09:53:00 2015 (r280243) +++ stable/10/usr.sbin/bhyve/pci_ahci.c Thu Mar 19 09:54:48 2015 (r280244) @@ -684,11 +684,14 @@ handle_identify(struct ahci_port *p, int } else { uint16_t buf[256]; uint64_t sectors; + int sectsz, psectsz, psectoff; uint16_t cyl; uint8_t sech, heads; - sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx); + sectsz = blockif_sectsz(p->bctx); + sectors = blockif_size(p->bctx) / sectsz; blockif_chs(p->bctx, &cyl, &heads, &sech); + blockif_psectsz(p->bctx, &psectsz, &psectoff); memset(buf, 0, sizeof(buf)); buf[0] = 0x0040; buf[1] = cyl; @@ -733,6 +736,18 @@ handle_identify(struct ahci_port *p, int buf[101] = (sectors >> 16); buf[102] = (sectors >> 32); buf[103] = (sectors >> 48); + buf[106] = 0x4000; + buf[209] = 0x4000; + if (psectsz > sectsz) { + buf[106] |= 0x2000; + buf[106] |= ffsl(psectsz / sectsz) - 1; + buf[209] |= (psectoff / sectsz); + } + if (sectsz > 512) { + buf[106] |= 0x1000; + buf[117] = sectsz / 2; + buf[118] = ((sectsz / 2) >> 16); + } ahci_write_fis_piosetup(p); write_prdt(p, slot, cfis, (void *)buf, sizeof(buf)); p->tfd = ATA_S_DSC | ATA_S_READY;