From owner-svn-src-head@freebsd.org Thu Mar 30 16:31:36 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 42257D26B2F; Thu, 30 Mar 2017 16:31:36 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 1C785C71; Thu, 30 Mar 2017 16:31:36 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2UGVZ2T060583; Thu, 30 Mar 2017 16:31:35 GMT (envelope-from tsoome@FreeBSD.org) Received: (from tsoome@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2UGVZhe060582; Thu, 30 Mar 2017 16:31:35 GMT (envelope-from tsoome@FreeBSD.org) Message-Id: <201703301631.v2UGVZhe060582@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tsoome set sender to tsoome@FreeBSD.org using -f From: Toomas Soome Date: Thu, 30 Mar 2017 16:31:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r316280 - head/sys/boot/efi/loader X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Mar 2017 16:31:36 -0000 Author: tsoome Date: Thu Mar 30 16:31:35 2017 New Revision: 316280 URL: https://svnweb.freebsd.org/changeset/base/316280 Log: loader: simplify efi_zfs_probe and avoid double probing for zfs. The current efi_zfs_probe() is overcomplicated and can be made simpler. Still we need to pick up the device handle for our boot disk first, because the ESP does not have to be the first partition on the disk. Once we do have the handle for boot disk, we probe that disk with pointer for pool GUID. Reviewed by: allanjude Approved by: allanjude (mentor) Differential Revision: https://reviews.freebsd.org/D10198 Modified: head/sys/boot/efi/loader/main.c Modified: head/sys/boot/efi/loader/main.c ============================================================================== --- head/sys/boot/efi/loader/main.c Thu Mar 30 16:23:31 2017 (r316279) +++ head/sys/boot/efi/loader/main.c Thu Mar 30 16:31:35 2017 (r316280) @@ -796,66 +796,45 @@ COMMAND_SET(fdt, "fdt", "flattened devic #ifdef EFI_ZFS_BOOT static void -efipart_probe_img(pdinfo_list_t *hdi) +efi_zfs_probe(void) { + pdinfo_list_t *hdi; + pdinfo_t *hd, *pd = NULL; EFI_GUID imgid = LOADED_IMAGE_PROTOCOL; EFI_LOADED_IMAGE *img; - pdinfo_t *hd, *pd = NULL; + EFI_HANDLE boot_disk = NULL; char devname[SPECNAMELEN + 1]; + uint64_t *guidp = NULL; BS->HandleProtocol(IH, &imgid, (VOID**)&img); - /* - * Search for the booted image device handle from hard disk list. - * Note, this does also include usb sticks, and we assume there is no - * ZFS on floppies nor cd. - * However, we might have booted from floppy (unlikely) or CD, - * so we should not surprised if we can not find the handle. - */ + /* Find the handle for the boot disk. */ + hdi = efiblk_get_pdinfo_list(&efipart_hddev); STAILQ_FOREACH(hd, hdi, pd_link) { - if (hd->pd_handle == img->DeviceHandle) - break; STAILQ_FOREACH(pd, &hd->pd_part, pd_link) { if (pd->pd_handle == img->DeviceHandle) - break; + boot_disk = hd->pd_handle; } - if (pd != NULL) - break; } - if (hd != NULL) { - if (pd != NULL) { - snprintf(devname, sizeof(devname), "%s%dp%d:", - efipart_hddev.dv_name, hd->pd_unit, pd->pd_unit); - } else { - snprintf(devname, sizeof(devname), "%s%d:", - efipart_hddev.dv_name, hd->pd_unit); - } - (void) zfs_probe_dev(devname, &pool_guid); - } -} -static void -efi_zfs_probe(void) -{ - pdinfo_list_t *hdi; - pdinfo_t *hd; - char devname[SPECNAMELEN + 1]; - - hdi = efiblk_get_pdinfo_list(&efipart_hddev); /* - * First probe the boot device (from where loader.efi was read), - * and set pool_guid global variable if we are booting from zfs. - * Since loader is running, we do have an access to the device, - * however, it might not be zfs. + * We provide non-NULL guid pointer if the disk was used for boot, + * and reset after the first found pool. + * Technically this solution is not very correct, we assume the boot + * pool is the first pool on this disk. */ - if (pool_guid == 0) - efipart_probe_img(hdi); - STAILQ_FOREACH(hd, hdi, pd_link) { - snprintf(devname, sizeof(devname), "%s%d:", - efipart_hddev.dv_name, hd->pd_unit); - (void) zfs_probe_dev(devname, NULL); + if (hd->pd_handle == boot_disk) + guidp = &pool_guid; + + STAILQ_FOREACH(pd, &hd->pd_part, pd_link) { + snprintf(devname, sizeof(devname), "%s%dp%d:", + efipart_hddev.dv_name, hd->pd_unit, pd->pd_unit); + (void) zfs_probe_dev(devname, guidp); + if (guidp != NULL && pool_guid != 0) + guidp = NULL; + } } } #endif