From nobody Tue Jan 24 22:14:33 2023 X-Original-To: dev-commits-src-branches@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 4P1h8p4hr9z3bgrL; Tue, 24 Jan 2023 22:14:34 +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 4P1h8p1DFcz3M56; Tue, 24 Jan 2023 22:14:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598474; 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=kYhNgoaileKUqnAV7k/4XoTimzcKNCU0gR1nGijMAzA=; b=SI8O15lsrLdPMtUBlxu0DZdfu1EOnmxDexdVxFeHpGaXU/R97GBEidVlga1ReiqE/eeiEt 64ggO5SX/f0p2PKC+TMJnxIxIJ5hATsRLZt7sTPU39m6DgkWotqnPtNqFS/ggZJq3bGFJO SciX76lKqO6YvOX1fqknEwajPbRTQQrEZD87uyx4PdiL1QJWz9D7wVa8+XcU2nTVBiGRCu FXXS4NlqGviqgxsYGRkNjktcRmj3Dj4343KgIAu5Gzs8wsBC3LpRYFYm0VqShynUh9/QtY 1/WfROFLbrcTEmFnvogo/QRaErZYkiRGSYg5a4SM/UtLFmIWSZl9pYjUVzwn0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598474; 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=kYhNgoaileKUqnAV7k/4XoTimzcKNCU0gR1nGijMAzA=; b=D1HJQz5PDr/QGS//sf2P4juEMEcd/IofSBO+qJ5mPp3jJbNrbQky/+wbKl2eAoqLNACVCI JNpFIFKJwQJ8TTH0+0imByLsOMvxrkieCctrnrFD9tmSJEZc0HLeP1oq3jBXAcVd0Q2imN u9u0sVpGpqOLTCW7bqAqBWwOVnz8Dq91cs+BubE8BpUtB7PN1Ef5nVTA2LyXmtZAkWMLMx +sskioHMIEvMU6snYxzxvI2MMHzB3jGoXz2WDEGgZBbpw4Rom+KwNstzOrnOTcpOc0myG8 SYIykagrE2usEGWQhJTA2wtzG5C0QcJPmRrwIaRLySC3aUnu5ta4vqg7/DnpkQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598474; a=rsa-sha256; cv=none; b=nMdocdcFbjbMJq6RixaIm/ssGPrBie4SIgAYsu23lCu/a3egeCPOJ3cwpY3RHclTgFm9Wo aB1bQnbWyV1N4xptfLRl8VT0MC0OUrmXbac4E4+Pqydsaq7SdBmV38GIBHNBXjVhiXLsUp zoV4TzGiyCBFmN8M1APscAQsWB7P9c6K5eYNotqHFUNEGr/LU6+UlTt5MhklRytSuaPziu js8gmxZtXyKo0QNN4V/2lcdxUC+xkbNKsBHQAyKDzcKiAP90wAeFQ/5VLFRmC9lVP0s8HS UGywyhrDdUbgmnnVvNrcbv9r6yrCM57oQj4a/guJPQDYs2+x3r3w94twFePUmA== 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 4P1h8p0KHGzQhQ; Tue, 24 Jan 2023 22:14:34 +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 30OMEXkB089993; Tue, 24 Jan 2023 22:14:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMEXpU089992; Tue, 24 Jan 2023 22:14:33 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:14:33 GMT Message-Id: <202301242214.30OMEXpU089992@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 0b569fe6717a - stable/13 - kboot: Add hostdisk override List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 0b569fe6717a155c6f46e63d9de75ab009fcf5d1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=0b569fe6717a155c6f46e63d9de75ab009fcf5d1 commit 0b569fe6717a155c6f46e63d9de75ab009fcf5d1 Author: Warner Losh AuthorDate: 2023-01-13 21:21:07 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:47 +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 (cherry picked from commit b7ecfa195f46da4a08a0cb5b399c8bc69bff225a) --- 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