Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Jun 2017 18:19:27 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r320195 - head/usr.sbin/bhyveload
Message-ID:  <201706211819.v5LIJR2u061684@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Wed Jun 21 18:19:27 2017
New Revision: 320195
URL: https://svnweb.freebsd.org/changeset/base/320195

Log:
  bhyveload: correctly query size of disks
  
  On FreeBSD fstat(2) works fine for querying sizes of plain files,
  but not so much for character devices.
  So, use DIOCGMEDIASIZE to try to get the correct size for disks
  and disk-like devices (e.g. zvols).
  
  PR:		220186
  Reviewed by:	tsoome, grehan
  MFC after:	1 week

Modified:
  head/usr.sbin/bhyveload/bhyveload.c

Modified: head/usr.sbin/bhyveload/bhyveload.c
==============================================================================
--- head/usr.sbin/bhyveload/bhyveload.c	Wed Jun 21 18:17:32 2017	(r320194)
+++ head/usr.sbin/bhyveload/bhyveload.c	Wed Jun 21 18:19:27 2017	(r320195)
@@ -311,10 +311,12 @@ cb_diskioctl(void *arg, int unit, u_long cmd, void *da
 		*(u_int *)data = 512;
 		break;
 	case DIOCGMEDIASIZE:
-		if (fstat(disk_fd[unit], &sb) == 0)
-			*(off_t *)data = sb.st_size;
-		else
+		if (fstat(disk_fd[unit], &sb) != 0)
 			return (ENOTTY);
+		if (S_ISCHR(sb.st_mode) &&
+		    ioctl(disk_fd[unit], DIOCGMEDIASIZE, &sb.st_size) != 0)
+				return (ENOTTY);
+		*(off_t *)data = sb.st_size;
 		break;
 	default:
 		return (ENOTTY);



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