From nobody Fri Jan 13 21:24:53 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NtvZZ1T4Bz2qklG; Fri, 13 Jan 2023 21:24:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NtvZZ0WsZz40yK; Fri, 13 Jan 2023 21:24:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645094; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I4lao0EKE9lskDB6RiXWqDf7Lk1WvIuJa0/vADFK9Oo=; b=Bfjfjh03/TIpymIEknyWkadCtOKpIuLpaOaPV7ZjV2XqOEGWCVs6kAzRBvQMg68xUjdf1y v+65Ca8tGFLJW/inwcN9/zD2qHwV7EDd0vhMy46oX39VZQTi3t9Z2L1yEkmXK4Su2VzdxY 2QZyr3oisyCxYzwwq2EUHq7gMlkL8lGP3uL5Efv3gRNWcp6TPw91YysRSozpuqXzPncbGw 7I4EEqc9av7HfSRa4VjeZTJTDUaVSlaBSVdwUcfTO2Kz1F4JlDdLJQytZtkB2VVHPw4zhw 8Dk56sfjzo+msvCyKBoeP6ns7qutQTFlkK0bbal14a6q+tr4YxnaMoeBFpQKvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645094; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I4lao0EKE9lskDB6RiXWqDf7Lk1WvIuJa0/vADFK9Oo=; b=OFaLjlrUXE1Xv+M+NMgvo2RIhfCuU63iRvVpSM/jDFLZugNf1hwJt3LP4U1pjFOC8bJ0Dd toziUcJ45yVc63AncJ8be0i8Y0NUanxo920P2dAUGqVpueGQbdKZGrEfCEm0zdY/gx2HeI zZw9aWO+4+i4u6eYsYuUUJbspVvFtnxKcWw/MuXkKjoF0/fclh9vE5cOxmepmlYf6spWPM Vydc8Ji5Mahj7wKP1xP+QPGYmsJhibq6PD567+if2Nuc3eTY8g5pY8RZ2toidUqjRi2yuJ AKp7kJem/SfkCjpSeckrYknWB+iGuV/y9hmGX9X5NNpC9F/MLPBYjdCt4pKx6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645094; a=rsa-sha256; cv=none; b=vNOd3gLiul4Pb0HCPZ9RpFb0cFkKYBxdgsT6bjCeoc7L1Q3DyB2Q85YNzE0d3J3ub7q+tc B7RxhYgtMFLeHs9t/q/8y6+cU0Xy5sDhREGPmW8HDTXYYSZhxgJGLTw3iE+Ypl6iA45PaS 8yPD5TyWCAm3e7fxsgRTDAuyyn3rBQ5GBRC6XvmM8aPY1XBZzmc/Mt4IcDYou/O/Du45Xd E7XgZdVgcrLzgroCFW7bTs8wwm6Cb6WTomoLRC3eFAwtcyEtusBuMm7A84k0GICI5zuYI2 B2Blgx0Ozc/1l51GTbBJ7rlaWxmkxpUynKAQE5iW5z+KOzf5HXDa7YJenzCD0w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NtvZY62tNzN2F; Fri, 13 Jan 2023 21:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30DLOrFU040979; Fri, 13 Jan 2023 21:24:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLOrtF040978; Fri, 13 Jan 2023 21:24:53 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:24:53 GMT Message-Id: <202301132124.30DLOrtF040978@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: b7ecfa195f46 - main - kboot: Add hostdisk override List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b7ecfa195f46da4a08a0cb5b399c8bc69bff225a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b7ecfa195f46da4a08a0cb5b399c8bc69bff225a commit b7ecfa195f46da4a08a0cb5b399c8bc69bff225a Author: Warner Losh AuthorDate: 2023-01-13 21:21:07 +0000 Commit: Warner Losh CommitDate: 2023-01-13 21:22:39 +0000 kboot: Add hostdisk override When hostdisk_override is set, all the /dev devices are hidden, and only the files in that directory are used. This will allow filesystem testing on FreeBSD without root, for example. Adjust the parse routine to not require devices start with /dev (plus fix a leak for an error condition). Add a match routine to allow the device name to be something like "/home/user/testing/zfsfoo:" instead of strictly in /dev. Note: since we need to look at all the devices in the system to probe for ZFS zpools, you can't generally use a full path to get a 'virtual disk' at this time. Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D38011 --- stand/kboot/hostdisk.c | 79 ++++++++++++++++++++++++++++++++++++++++++++------ stand/kboot/main.c | 7 +++-- 2 files changed, 75 insertions(+), 11 deletions(-) diff --git a/stand/kboot/hostdisk.c b/stand/kboot/hostdisk.c index a96c38c21182..fab4ee04bb6b 100644 --- a/stand/kboot/hostdisk.c +++ b/stand/kboot/hostdisk.c @@ -47,6 +47,7 @@ static int hostdisk_close(struct open_file *f); static int hostdisk_ioctl(struct open_file *f, u_long cmd, void *data); static int hostdisk_print(int verbose); static char *hostdisk_fmtdev(struct devdesc *vdev); +static bool hostdisk_match(struct devsw *devsw, const char *devspec); static int hostdisk_parsedev(struct devdesc **idev, const char *devspec, const char **path); struct devsw hostdisk = { @@ -60,6 +61,7 @@ struct devsw hostdisk = { .dv_print = hostdisk_print, .dv_cleanup = nullsys, .dv_fmtdev = hostdisk_fmtdev, + .dv_match = hostdisk_match, .dv_parsedev = hostdisk_parsedev, }; @@ -247,15 +249,59 @@ hostdisk_one_disk(struct host_dirent64 *dent, void *argp __unused) return (true); } -static void -hostdisk_find_block_devices(void) +static bool +hostdisk_fake_one_disk(struct host_dirent64 *dent, void *argp) { + char *override_dir = argp; + char *fn = NULL; + hdinfo_t *hd = NULL; + struct host_kstat sb; + /* - * Start here XXX open SYSBLK, walk through all directories, keep the - * ones that return a size and a 'block' device when we 'stat' it. Try - * to avoid partitions and only do raw devices. + * We only do regular files. Each one is treated as a disk image + * accessible via /dev/${dent->d_name}. */ - foreach_file(SYSBLK, hostdisk_one_disk, NULL, 0); + if (dent->d_type != HOST_DT_REG && dent->d_type != HOST_DT_LNK) + return (true); + if (asprintf(&fn, "%s/%s", override_dir, dent->d_name) == -1) + return (true); + if (host_stat(fn, &sb) != 0) + goto err; + if (!HOST_S_ISREG(sb.st_mode)) + return (true); + if (sb.st_size == 0) + goto err; + if ((hd = calloc(1, sizeof(*hd))) == NULL) + goto err; + hd->hd_dev = fn; + hd->hd_size = sb.st_size; + hd->hd_sectorsize = 512; /* XXX configurable? */ + hd->hd_sectors = hd->hd_size / hd->hd_sectorsize; + if (hd->hd_size < HOSTDISK_MIN_SIZE) + goto err; + hd->hd_flags = 0; + STAILQ_INIT(&hd->hd_children); + printf("%s: %ju %ju %ju\n", + hd->hd_dev, hd->hd_size, hd->hd_sectors, hd->hd_sectorsize); + STAILQ_INSERT_TAIL(&hdinfo, hd, hd_link); + /* XXX no partiions? -- is that OK? */ + return (true); +err: + free(hd); + free(fn); + return (true); +} + +static void +hostdisk_find_block_devices(void) +{ + char *override; + + override=getenv("hostdisk_override"); + if (override != NULL) + foreach_file(override, hostdisk_fake_one_disk, override, 0); + else + foreach_file(SYSBLK, hostdisk_one_disk, NULL, 0); } static int @@ -387,6 +433,23 @@ hostdisk_fmtdev(struct devdesc *vdev) return ((char *)hd_name(dev2hd(vdev))); } +static bool +hostdisk_match(struct devsw *devsw, const char *devspec) +{ + hdinfo_t *hd; + const char *colon; + char *cp; + + colon = strchr(devspec, ':'); + if (colon == NULL) + return false; + cp = strdup(devspec); + cp[colon - devspec] = '\0'; + hd = hostdisk_find(cp); + free(cp); + return (hd != NULL); +} + static int hostdisk_parsedev(struct devdesc **idev, const char *devspec, const char **path) { @@ -396,9 +459,6 @@ hostdisk_parsedev(struct devdesc **idev, const char *devspec, const char **path) int len; char *fn; - /* Must start with /dev */ - if (strncmp(devspec, "/dev", 4) != 0) - return (EINVAL); /* Must have a : in it */ cp = strchr(devspec, ':'); if (cp == NULL) @@ -412,6 +472,7 @@ hostdisk_parsedev(struct devdesc **idev, const char *devspec, const char **path) hd = hostdisk_find(fn); if (hd == NULL) { printf("Can't find hdinfo for %s\n", fn); + free(fn); return (EINVAL); } free(fn); diff --git a/stand/kboot/main.c b/stand/kboot/main.c index 9a0f8b8baf69..91bc4c06e452 100644 --- a/stand/kboot/main.c +++ b/stand/kboot/main.c @@ -192,9 +192,12 @@ main(int argc, const char **argv) #if defined(LOADER_ZFS_SUPPORT) if (strcmp(bootdev, "zfs:") == 0) { /* - * Pseudo device that says go find the right ZFS pool. + * Pseudo device that says go find the right ZFS pool. This will be + * the first pool that we find that passes the sanity checks (eg looks + * like it might be vbootable) and sets currdev to the right thing based + * on active BEs, etc */ - printf("WARNING: bare 'zfs:' for boot device not yet implemented\n"); + hostdisk_zfs_find_default(); } #endif