From owner-svn-src-projects@FreeBSD.ORG Wed Oct 3 03:00:38 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7F1481065670; Wed, 3 Oct 2012 03:00:38 +0000 (UTC) (envelope-from grehan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 69C8F8FC08; Wed, 3 Oct 2012 03:00:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9330cbf048025; Wed, 3 Oct 2012 03:00:38 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9330cAx048022; Wed, 3 Oct 2012 03:00:38 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201210030300.q9330cAx048022@svn.freebsd.org> From: Peter Grehan Date: Wed, 3 Oct 2012 03:00:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r241151 - projects/bhyve/sys/boot/userboot/userboot X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Oct 2012 03:00:38 -0000 Author: grehan Date: Wed Oct 3 03:00:37 2012 New Revision: 241151 URL: http://svn.freebsd.org/changeset/base/241151 Log: Rework the GPT/MBR/raw policy so that it actually works, and navigates around disk_open's current handling of falling back from GPT to MBR. As in the previous commit, this should all be fixed in CURRENT. Modified: projects/bhyve/sys/boot/userboot/userboot/main.c Modified: projects/bhyve/sys/boot/userboot/userboot/main.c ============================================================================== --- projects/bhyve/sys/boot/userboot/userboot/main.c Wed Oct 3 02:58:55 2012 (r241150) +++ projects/bhyve/sys/boot/userboot/userboot/main.c Wed Oct 3 03:00:37 2012 (r241151) @@ -129,6 +129,7 @@ static void extract_currdev(void) { struct disk_devdesc dev; + int gpt, rc; //bzero(&dev, sizeof(dev)); @@ -138,12 +139,37 @@ extract_currdev(void) dev.d_unit = 0; dev.d_slice = 0; dev.d_partition = 0; + /* - * Figure out if we are using MBR or GPT - for GPT we - * set the partition to 0 since everything is a GPT slice. + * The priority is GPT, MBR and raw disk. Unfortunately, + * disk_open() doesn't really get this right so first + * probe for MBR, and then GPT. If GPT fails, re-probe + * MBR if it succeeded, else assume raw. */ - if (dev.d_dev->dv_open(NULL, &dev)) - dev.d_partition = 255; + rc = (*dev.d_dev->dv_open)(NULL, &dev); + + dev.d_unit = 0; + dev.d_slice = 0; + dev.d_partition = 255; + gpt = (*dev.d_dev->dv_open)(NULL, &dev); + + if (gpt) { + dev.d_unit = 0; + dev.d_slice = 0; + dev.d_partition = 0; + + if (!rc) { + (void) (*dev.d_dev->dv_open)(NULL, &dev); + } else { + /* + * Force raw disk access + */ + dev.d_slice = -1; + dev.d_partition = -1; + dev.d_offset = 0; + } + } + } else { dev.d_dev = &host_dev; dev.d_type = dev.d_dev->dv_type;