From 71bbe6fb709dcfbe36877fa53c928e2e6d881843 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 16 Dec 2022 16:19:51 -0700 Subject: [PATCH] stand/zfs: Add a third argument to zfs_probe_dev: part_too Pass in 'true' if you'd like to search this device's partitions or 'false' if you should just search the device. EFI and (in the future) kboot have discrete partitions that aren't accessed via the full disk device. Weird things happen if you try to search in these cases. Sponsored by: Netflix --- stand/efi/libefi/efizfs.c | 2 +- stand/i386/loader/main.c | 2 +- stand/i386/zfsboot/zfsboot.c | 4 ++-- stand/libsa/zfs/libzfs.h | 2 +- stand/libsa/zfs/zfs.c | 4 +++- stand/userboot/userboot/main.c | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/stand/efi/libefi/efizfs.c b/stand/efi/libefi/efizfs.c index 7f3986d47140..4fa336df1d59 100644 --- a/stand/efi/libefi/efizfs.c +++ b/stand/efi/libefi/efizfs.c @@ -115,7 +115,7 @@ efi_zfs_probe(void) snprintf(devname, sizeof(devname), "%s%dp%d:", efipart_hddev.dv_name, hd->pd_unit, pd->pd_unit); guid = 0; - if (zfs_probe_dev(devname, &guid) == 0) { + if (zfs_probe_dev(devname, &guid, false) == 0) { insert_zfs(pd->pd_handle, guid); if (pd->pd_handle == boot_img->DeviceHandle) pool_guid = guid; diff --git a/stand/i386/loader/main.c b/stand/i386/loader/main.c index f3e1d4ff434d..e5cc766f5781 100644 --- a/stand/i386/loader/main.c +++ b/stand/i386/loader/main.c @@ -453,7 +453,7 @@ i386_zfs_probe(void) for (dev.dd.d_unit = 0; bd_unit2bios(&dev) >= 0; dev.dd.d_unit++) { snprintf(devname, sizeof(devname), "%s%d:", bioshd.dv_name, dev.dd.d_unit); - zfs_probe_dev(devname, NULL); + zfs_probe_dev(devname, NULL, true); } } #endif diff --git a/stand/i386/zfsboot/zfsboot.c b/stand/i386/zfsboot/zfsboot.c index c6305b41493e..da91fc3a5d20 100644 --- a/stand/i386/zfsboot/zfsboot.c +++ b/stand/i386/zfsboot/zfsboot.c @@ -706,9 +706,9 @@ i386_zfs_probe(void) dev.dd.d_unit); /* If this is not boot disk, use generic probe. */ if (dev.dd.d_unit != boot_unit) - zfs_probe_dev(devname, NULL); + zfs_probe_dev(devname, NULL, true); else - zfs_probe_dev(devname, &pool_guid); + zfs_probe_dev(devname, &pool_guid, true); if (pool_guid != 0 && bdev == NULL) { bdev = malloc(sizeof (struct i386_devdesc)); diff --git a/stand/libsa/zfs/libzfs.h b/stand/libsa/zfs/libzfs.h index b6b6cd78f073..d9758f49ab78 100644 --- a/stand/libsa/zfs/libzfs.h +++ b/stand/libsa/zfs/libzfs.h @@ -49,7 +49,7 @@ struct zfs_devdesc { }; char *zfs_fmtdev(struct devdesc *); -int zfs_probe_dev(const char *devname, uint64_t *pool_guid); +int zfs_probe_dev(const char *devname, uint64_t *pool_guid, bool part_too); int zfs_list(const char *name); int zfs_get_bootonce(void *, const char *, char *, size_t); int zfs_get_bootenv(void *, nvlist_t **); diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c index d7aecc71ab5c..57fecf2f4d68 100644 --- a/stand/libsa/zfs/zfs.c +++ b/stand/libsa/zfs/zfs.c @@ -1492,7 +1492,7 @@ zfs_attach_nvstore(void *vdev) } int -zfs_probe_dev(const char *devname, uint64_t *pool_guid) +zfs_probe_dev(const char *devname, uint64_t *pool_guid, bool parts_too) { struct ptable *table; struct zfs_probe_args pa; @@ -1508,6 +1508,8 @@ zfs_probe_dev(const char *devname, uint64_t *pool_guid) ret = zfs_probe(pa.fd, pool_guid); if (ret == 0) return (0); + if (!parts_too) + return (ENXIO); /* Probe each partition */ ret = ioctl(pa.fd, DIOCGMEDIASIZE, &mediasz); diff --git a/stand/userboot/userboot/main.c b/stand/userboot/userboot/main.c index 6ec5c5ddbbb6..b403d9b48f56 100644 --- a/stand/userboot/userboot/main.c +++ b/stand/userboot/userboot/main.c @@ -313,7 +313,7 @@ userboot_zfs_probe(void) for (unit = 0; unit < userboot_disk_maxunit; unit++) { sprintf(devname, "disk%d:", unit); pool_guid = 0; - zfs_probe_dev(devname, &pool_guid); + zfs_probe_dev(devname, &pool_guid, true); if (pool_guid != 0) userboot_zfs_found = 1; }