475 Commits
Author SHA1 Message Date
Warner Losh 262fa4695d stand: Implement zfs_dnode_readlink in terms of zfs_dnode_sa_lookup
Get the link offset using the zfs_dnode_sa_lookup helper now.

Recently, the symbolic links we rely on in the boot loader have stopped
working.

Prior to OpenZFS commit e90badec11 ("Inherit the project ID for every
object type", Matt Turner, 2026-08-14), symbolic link information was
written at a fixed offset in the SA data. Since that commit, the
inherited PROJIDs mean that all pools with quota enabled have started
writing symbolic links with a new, non-fixed offset. Old symbolic links
remained unchanged, but new ones were written with a different
offset. At work, we have all these things: rewritten BEs, quotas, and a
dependence on symbolic links in our boot path.

This came in on 2026-08-24 OpenZFS merge (22649d4dba). This was 12
hours after stab week for August, so we didn't hit this until the
September stab week. Since the new kernel has to write links at the new
offset, the initial tests worked, but the second ones didn't.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60268
2026-10-03 11:32:08 -06:00
Warner Losh f382ef1dc8 stand: update zfs_dnode_stat to use zfs_dnode_sa_lookup
Find the SA values with the zfs_dnode_sa_lookup and read out the
relevant bits for the stat buffer.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60267
2026-10-03 11:32:08 -06:00
Warner Losh 8bc06ba211 stand: Lookup specific SA value in a dnode
zfs_dnode_sa_lookup will look in the bonus part of the dnode for the
requested SA values, and fall back to the spill as if it's not there.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60266
2026-10-03 11:32:08 -06:00
Warner Losh 4175fa107f stand: Lookup the offsets for this SA bundle
Compute the offset for the data for this bundle and the requested data
type.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60265
2026-10-03 11:32:08 -06:00
Warner Losh 32fcc66dd3 stand: Load dynamic system attribute offsets
zfs_sa_load looks up all the system attribute offsets and stores them in
the mountpoint.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60264
2026-10-03 11:32:08 -06:00
Warner Losh 16cf795d3e stand: zfs_dnode_readlink move from spa to mount argument
For the dynamic system attributes, we'll need the mount argument. Adjust
zfs_dnode_readlink to take that argument.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60262
2026-10-03 11:32:07 -06:00
Warner Losh ecd41c0df3 stand: zfs_dnode_stat move from spa to mount argument
When reading dynamic system attributes, we'll need the mount argument
since we can no longer hard-code the offsets. Adjust zfs_dnode_stat to
take it.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60261
2026-10-03 11:32:07 -06:00
Warner Losh acbcb68c9f stand: Remove const from zfs_lookup's zfsmount argument
Dynamic system attribute layout can require modifications to the mount
structure on lookup. Drop the const to allow that.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D60260
2026-10-03 11:32:07 -06:00
Krzysztof Galazka c4640126f1 loader.efi: Apply command-line DHCP overrides earlier
Ability to override DHCP options with command-line arguments
was affected by intoduction of initmd support. Initmd discovery
configures the network before loader arguments
were parsed, so a dhcp.root-path override was unavailable
during the first network configuration. Move parsing
arguments earlier and apply dhcp.root-path even if DHCP response
does not contain option 17. This allows providing a dynamic NFS
root e.g. by chain loading loader.efi from iPXE.

Signed-off-by: Krzysztof Galazka <[email protected]>

Reviewed by:	imp
Assisted by:    Github Copilot (GPT-5.6 Sol)
Sponsored by:   Intel Corporation
Differential Revision:	https://reviews.freebsd.org/D59998
2026-09-29 21:55:17 +02:00
Warner Losh a098fd021e loader: request DHCP initmd option
Request FreeBSD RFC 3925 PEM 2238 DHCP 125 option. Use suboption 1 to
specify a ramdisk image to load and use to load the kernel and as the
root file system.

Differential Revision:	https://reviews.freebsd.org/D59428
Sponsored by:		Netflix
2026-09-10 22:15:28 -06:00
Warner Losh 7208b3b845 libsa: Add a generic URI-syntax devspec parser
Add parse_uri(), a helper for devices whose devspec can take a
"[N]://host[:port][/path]" form in addition to the traditional "N:path"
form. It returns EINVAL when devspec doesn't match that pattern, so a
caller's own dv_parsedev can fall back to the traditional form.

Un-static default_parsedev() so it can serve as that fallback.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D59422
2026-09-10 22:15:28 -06:00
Faraz Vahedi 8d29d24296 libc: Restore prior C23 include guards
To avoid any sort of POLA violation, this commit restores old
guards and defines the C23 feature test macros in addition to
them.  This is to close off whole class of possible breakage,
rather than patching it case by case.

Reported by:	dim
Reviewed by:	dim, dteske, fuz
Approved by:	dim, dteske (mentor), fuz (mentor)
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D58911
2026-08-19 13:51:21 +03:30
Etienne Bonnand b567434a59 stand: set st_dev/st_ino in the loader's ZFS stat for veriexec
The loader's ZFS implementation never set st_dev or st_ino in
zfs_dnode_stat(). With an uninitialized struct stat, veriexec's device
comparison in lib/libsecureboot/veopen.c read stack garbage and skipped
the matching manifest entry, failing with a spurious "no entry" on ZFS
root under UEFI Secure Boot.

Rather than zeroing the device (which would break veriexec's ability to
tell apart the same path on different datasets), populate st_dev and
st_ino with the same intrinsic identifiers the kernel uses:

- st_dev = the dataset's ds_fsid_guid (as the kernel does via
  dmu_objset_fsid_guid()/dsl_dataset_fsid_guid()), already read in
  zfs_mount_dataset() and now propagated through struct zfsmount.
- st_ino = the object number resolved in zfs_lookup(), propagated
  through struct file (the loader's equivalent of the kernel's z_id).

dev_t and ino_t are 64-bit on FreeBSD, so both are assigned directly
with no hashing. A memset() at the top of zfs_dnode_stat() zeroes the
remaining fields so they no longer hold stack garbage.

Tested on 16.0-CURRENT (amd64), ZFS-on-GELI root: rebuilt and re-signed
the EFI loader; the system boots under UEFI Secure Boot with
mac_veriexec active.

(boot1 segment was modified by kevans)

PR:		295935
Sponsored by:	Defenso

Reviewed-by: kevans
Pull-Request: https://github.com/freebsd/freebsd-src/pull/2271
2026-08-18 10:47:12 -05:00
Faraz Vahedi cd0727ec70 libc: Add <stdio.h> C23 feature test macro
Define the __STDC_VERSION_STDIO_H__ feature test macro now that
the header fully conforms to C23.

Reviewed by:	fuz
Approved by:	fuz (mentor)
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D58842
2026-08-14 23:01:54 +03:30
Alexander Motin 495826f69d stand: add ARCH and MSZ into DHCP requests
It should give DHCP servers more information for proper responses.
2026-08-03 22:23:55 -04:00
Alexander Motin f70e4664a6 stand: consume UEFI PXE Base Code cache to seed DHCP
Populate stand/libsa/bootp.c's bootp_response global from the UEFI PXE
Base Code Protocol's cached DhcpAck, so bootp() can enter RFC 2131
INIT-REBOOT and skip DISCOVER/OFFER instead of running a fresh DHCP
transaction after the firmware has already done one.
2026-08-03 21:04:18 -04:00
Alexander Motin f4860c31b6 stand: Bump DHCP xid between transactions
Transaction ID should persist only between OFFER and the following
REQUEST.  In all other cases it should change.
2026-07-30 21:35:29 -04:00
Alexander Motin 8822954480 stand: Cleanup use of cached DHCP response packet
- When cached response is available, actually use xid from one
instead of using its byte-swapped value for BIOS and 1 for UEFI.
 - If cached response is not available, generate pseudo-random xid,
since use of a constant may cause conflicts if two systems are
booting same time, and server sends responses as broadcast.
 - When cached response is available, skip DHCP DISCOVER/OFFER
and just send REQUEST to the DHCP server from the cached response.
We could skip this phase too and just use the cached response, but
we don't know whether firmware requested all of DHCP options we'd
like to get.

Tested on amd64 Supermicro X11DPI-NT for both BIOS and EFI, with
and without cached response packet.
2026-07-29 22:26:46 -04:00
Warner Losh df9d6403ca loader: Add forgotten xz.c and zstdfs.c
These were overlooked when I added compression support.

Fixes: 86d719ae68 ("loader: Add xzfs, like gzipfs but with xz.")
Fixes: c61ee49cd0 ("loader: zstd based filesystem, zstdfs like gzipfs")
Sponsored by:		Netflix
2026-07-11 21:53:29 -06:00
Warner Losh c61ee49cd0 loader: zstd based filesystem, zstdfs like gzipfs
Off by default.

Sponsored by:		Netflix
2026-07-11 13:28:47 -06:00
Warner Losh 86d719ae68 loader: Add xzfs, like gzipfs but with xz.
This is just like gzipfs or bzipfs, except done with the newer xz
program. This is off by default for the moment.

Sponsored by:		Netflix
2026-07-11 13:28:47 -06:00
Warner Losh dc6c193bb4 loader.efi: Add xz decompression
We can now decompress .xz compressed memory disks, like
FreeBSD-15.1-RELEASE-amd64-disc1.iso.xz

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D58073
2026-07-11 13:28:47 -06:00
Warner Losh 53811ed623 loader: Add defines for ZLIB_CFLAGS, BZIP2_CFLAGS and ZSTD_CFLAGS
These are scattered in several places, so centralize the setting of
these flags.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57861
2026-06-26 08:54:35 -06:00
Warner Losh 01ef8f4555 loader: Don't need add these flags to ZSTD_SRC
These are zfs-only flags, don't add them when we're building ZSTD.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D57860
2026-06-26 08:54:35 -06:00
Martin Cracauer d2c21935e8 pxeboot: warn and abort on TCP-only NFS server, which doesn't work for pxeboot
When pxeboot gets a 0 as a port number from portmapper (indicating an
error), it currently happily sends NFS packets to the server's port 0
in an endless loop. Change this to instead bail out with a useful
message.

This happens, for example, with recent Linux NFS servers as many
distributions switched to TCP only NFS serving by default. FreeBSD's
pxeboot must have UDP. In this situation pxeboot asks the server's
portmapper for the UDP NFS port and since there is none gets 0.

Also add a hint to the manpage explaining this and how to fix it.

Reviewed by: ziaee, kevans, imp
2026-05-24 11:43:00 -04:00
Ryan Libby 944a4eb089 stand/libsa/zfs: disable ZSTD_TRACE and DYNAMIC_BMI2 code paths
Enabling ZSTD_TRACE leaves behind undefined weak symbols, which causes a
problem for gcc builds.  The bfd linker emits an obscure error about
overlapping FDEs.  We don't need ZSTD_TRACE for libsa, so just disable
it.

Also disable BMI2 instruction optimizations.  The addition of the
optional BMI2 code paths caused the boot loader binaries to grow larger
(28 KiB for clang, 32 KiB for gcc).  The boot loader binaries are size
constrained, and this pushed the gcc-generated lua_loader.bin over the
500000 byte limit, and the clang one to within 4k of the limit.

Fixes:	8a62a2a565 ("zfs: merge openzfs/zfs@f8e5af53e")
Reviewed by:	delphij, imp, mm
Differential Revision:	https://reviews.freebsd.org/D56866
2026-05-07 10:30:05 -07:00
Simon J. Gerraty a371b008d1 Add boot_setenv
Move is_restricted_var() to libsa/environment.c so it can be leveraged
by boot_setenv called from subr_boot with not truted input.

Also, allow for local tuning via ENV_IS_RESTRICTED_ALLOWED_LIST and
ENV_IS_RESTRICTED_LIST

Sponsored by:	Hewlett Packard Enterprise Development LP.

Reviewed by:	kevans, imp
Differential Revision:	https://reviews.freebsd.org/D56287
2026-04-07 09:29:07 -07:00
Martin Matuska 80aae8a3f8 zfs: merge openzfs/zfs@3ee08abd2
Notable upstream pull request merges:
 #17000 -multiple cmd/zfs: support creating parents with canmount=no
 #17926 b481a8bbb Make zpool status dedup table support raw bytes -p output
 #18238 -multiple Report space metrics per allocation class
 #18240 5dad9459d Add --no-preserve-encryption flag
 #18257 1eace5906 libzfs: use mount_setattr for selective remount including
                  legacy mounts
 #18259 1e2c94a04 More consistent use of TREE_* macros in AVL comparators
 #18262 c58b8b7dc Fix check for .cfi_negate_ra_state on aarch64
 #18264 f109c7bb9 Add the --file-layout (-f) option to zdb(8)
 #18268 304de7f19 libzfs: handle EDOM error in zpool_create
 #18275 753f1e1e2 zstream: add a drop_record subcommand
 #18276 0f90a797d Fix vdev_rebuild_range() tx commit
 #18277 1e1d64d66 Fix log vdev removal issues
 #18278 06b0abfe6 Fix the send --exclude option to work with encryption
 #18281 e73ada771 libzpool: lift zfs_file ops out to separate source file
 #18284 d97945776 zstream: consolidate shared code
 #18285 -multiple Separate SIMD compile checks for userspace and kernel
 #18288 c5905b2cb Implement lzc_send_progress
 #18289 -multiple L2ARC: Add depth cap and write budget fairness for
                  persistent markers
 #18290 d45c8d648 FreeBSD: Improve dmesg kernel message prefix
 #18294 b403040c4 draid: fix data corruption after disk clear
 #18296 -multiple libzfs: mnttab cleanup
 #18300 d35951b18 zpool clear: remove undocumented rewind flags
 #18301 ae7fcd5f9 fix libzfs diff mem leak in an error path
 #18303 65165df12 zilstat: add man page
 #18314 7f65e04ab libzfs: scrub: only include start and end nv pairs if
                  needed for scrub
 #18315 -multiple Sync ZVOLs block cloning conditions with file systems
 #18330 f80338fac zarcsummary: add man page
 #18337 f259a47c7 zpool-iostat.8: clarify first report shows per-second
                  averages

Obtained from:	OpenZFS
OpenZFS commit:	3ee08abd2f
2026-03-19 21:25:34 +01:00
Martin Matuska 8a62a2a565 zfs: merge openzfs/zfs@f8e5af53e
Notable upstream pull request merges:
 #17358 4975430cf Add vdev property to disable vdev scheduler
 #18031 c77f17b75 Add snapshots_changed_nsecs dataset property
 #18080 dbb3f247e cmd/zfs: clone: accept `-u` to not mount newly created
                  datasets
 #18089 -multiple Zstd: Update bundled library to version 1.5.7
 #18091 2301755df Fix zfs_open() to skip zil_async_to_sync() for the
                  snapshot
 #18093 -multiple L2ARC: Rework write throttling with DWPD rate limiting
                  and parallel writes
 #18095 2dbd6af5e Rename several printf attributes declarations to
                  __printf__
 #18096 8605bdfdd FreeBSD: unbreak compilation on i386
 #18105 794f1587d When receiving a stream with the large block flag,
                  activate feature
 #18115 765929cb4 DDT: Add locking for table ZAP destruction
 #18118 09e4e01e9 Fix history logging for `zpool create -t`
 #18119 2f1f25217 icp: emit .note.GNU-stack section for all ELF targets
 #18131 3fffe4e70 Fix --enable-invariants on FreeBSD
 #18133 d2f5cb3a5 Move range_tree, btree, highbit64 to common code
 #18136 54b141fab FreeBSD: Remove references to DEBUG_VFS_LOCKS
 #18138 cdf89f413 Flush RRD only when TXGs contain data
 #18139 a157ef62a Make sure we can still write data to txg
 #18140 cd895f0e5 remove thread unsafe debug code causing FreeBSD double
                  free panic
 #18144 4f180e095 Fix activating large_microzap on receive
 #18146 35b2d3970 Lock db_mtx around arc_release() in couple places
 #18154 b36472052 nvpair: chase FreeBSD xdrproc_t definition
 #18160 21bbe7cb6 Improve caching for dbuf prefetches
 #18177 -multiple Multihost Improvements
 #18179 2646bd558 Allow rewrite skip cloned and snapshotted blocks
 #18180 aa29455dd Restrict cloning with different properties
 #18184 040ba7a7c libzfs: improve error message for zpool create with
                  ENXIO
 #18188 1412bdc6c zfs_vnops_os.c: Move a vput() to after
                  zfs_setattr_dir()
 #18198 cc184fe98 Fix `send:raw` permission for send `-w -I`
 #18208 ba970eb20 Cleanup allocation class selection
 #18212 0f9564e85 Simplify dnode_level_is_l2cacheable()
 #18214 370570890 Remove parent ZIO from dbuf_prefetch()
 #18218 bfb276e55 freebsd: Fix TIMESPEC_OVERFLOW for PowerPC
 #18222 d06a1d9ac Fix available space accounting for special/dedup
 #18225 d48967728 ICP: AES-GCM VAES-AVX2: fix typos and document
                  source files
 #18226 c8a72a27e ICP: AES-GCM assembly: remove unused Gmul functions
 #18230 -multiple Fix zdb --key crash for unencrypted datasets, and
                  teach tests to understand this better
 #18233 -multiple icp: add SHA-512 implementation using Intel SHA512
                  extension
 #18245 991fc56fa Introduce dedupused/dedupsaved pool properties
 #18251 6a717f31e Improve misleading error messages for
                 ZPOOL_STATUS_CORRUPT_POOL
 #18254 7744f0496 SIMD: libspl: test the correct CPUID bit for AVX512VL
 #18255 6495dafd5 range_tree: use zfs_panic_recover() for
                  partial-overlap remov
 #18256 3408332d7 zhack: Fix importing large allocation profiles on
                  small pools
 #18258 f8457fbdc Fix deadlock on dmu_tx_assign() from vdev_rebuild()
 #18263 f8e5af53e Fix redundant declaration of dsl_pool_t

Obtained from:	OpenZFS
OpenZFS commit:	f8e5af53e9
2026-03-14 13:14:56 +01:00
Gordon Bergling fa567fe7c5 libsa/geli: Fix a typo in an error message
- s/crypo/crypto/

MFC after:	5 days
2026-02-07 06:20:16 +01:00
Warner Losh fe8105de14 stand: Minor style tweaks
re-wrap the function calls in a couple of ifs in get_zfs_root so they
are more readable. They really didn't need to be wrapped like this in
the first place.

Sponsored by:		Netflix
2026-02-04 10:29:11 -07:00
John Baldwin fe45651224 stand: Add compiler builtins needed by GCC for RISC-V
Reviewed by:	mhorne
Differential Revision:	https://reviews.freebsd.org/D54963
2026-01-31 12:10:36 -05:00
Toomas Soome ab5f29ae9e stand/zfs: fix path setup in zfs_mount()
Need to check argument 'path', not just allocated struct member.
2026-01-28 10:32:13 +02:00
Warner Losh 3c857567c1 stand: Rename ZFSSRC to SAZFSSRC to avoid confusion
ZFSSRC is abiguous on its surface and too clos to ZFSTOP, so rename it
to SAZFSSRC.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D53901
2025-11-24 17:50:26 -07:00
Warner Losh 05346243df stand: Move from OZFS to ZFSTOP
Use ZFSTOP instead of OZFS. They are the saame thing.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D53900
2025-11-24 17:35:46 -07:00
Mark Johnston 4d6801a6b5 stand: Teach the zfs loader about dynamic gang headers
There is a pool feature, dynamic_gang_header, that is enabled by default
in new pools.  When this feature is active, gang headers may be larger
than 512 bytes.  The loader needs to be taught to cope with that.

Try using the vdev ashift to pick the gang block header size.  If the
checksum fails, fall back to the old gang block header size.

This is based on a patch by Paul Dagnelie, with testing, bug-fixing and
some simplifications from me.

PR:		289690
Co-authored by:	Paul Dagnelie <[email protected]>
Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D53578
2025-11-06 16:02:33 +00:00
Robert Clausecker 90fa789cfa sys/crypto: import md5c.c C rewrite
The reimplementation is a bit cleaner than the original code,
although it is also slightly slower. This shouldn't matter too
much as we will have asm code for the major platforms.

The code is unrolled when built in the kernel or user space, but
not when in libsa, as to reduce the code size.

Differential Revision:	https://reviews.freebsd.org/D45670
Reviewed by:	jrtc27, imp
Approved by:	markj (mentor)
MFC after:	1 month
2025-10-24 12:16:58 +02:00
Robert Clausecker 73a9b273d3 sys: move sys/kern/md[45].c to sys/crypto
Both files are used by kernel and userspace.
Move them to sys/crypto where they belong.

No functional changes intended.

In preparation of D45670.

Reviewed by:	markj
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D52909
2025-10-24 12:16:46 +02:00
Olivier Certner d3bfcd6640 libsa: smbios: Detect less-than-64-bit platforms via __SIZEOF_SIZE_T__
What we really want here is to know if pointers can refer to 64-bit
addresses, regardless of whether they also hold other information (such
as capabilities in CHERI).  __SIZEOF_SIZE_T__ is probably the closest
indication to that piece of information, so let's use it.  __ILP32__
wasn't wrong in practice though, as we don't support 32-bit CHERI
hardware (and likely never will).

Consistently with this change, test whether we can actually address the
64-bit SMBIOS's structure table by converting the end address to
'size_t' and checking whether its value is preserved.

Suggested by:   jhb (for the __ILP32__ => __SIZEOF_SIZE_T__ part)
Reviewed by:    jhb, imp
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D49318
2025-10-07 10:14:41 +02:00
Warner Losh dd747d7bcb Revert "stand: Use calloc instead of malloc for initialization of filesystem devsw"
This reverts commit dfafdbdfc3. There's no
author, and also problems with it. I'll redo it.

Sponsored by:		Netflix
2025-09-02 09:23:02 -06:00
null dfafdbdfc3 stand: Use calloc instead of malloc for initialization of filesystem devsw
This change is required for https://reviews.freebsd.org/D49355, so that
we can check if d_dev is uninitialized by checking if it's NULL.

Reviewed by:		imp
Differential Revision:	https://reviews.freebsd.org/D49705
2025-09-01 15:57:14 -06:00
Kirk McKusick 690ae8a202 Bail out of corrupt directory entries during boot
A directory with a zero-valued d_reclen causes boot to hang, This
patch checks for directory entries with value zero and bails out
rather than spin forever. The hope is that the user has other options.

Sadly this was reported on Jun 16 2015 and is just now attended to
as part of a sweep of old unclosed phabricator reports.

Reported-by:  Daniel O'Connor darius-dons.net.au
Differential  Revision: https://reviews.freebsd.org/D2844
MFC-after:    1 week
Sponsored-by: Netflix
2025-08-21 22:33:48 -07:00
Kyle Evans 510e473ff3 stand: add a mechanism to avoid env var propagation to kenv
Our only user of this at the moment is teken.{fg,bg}_color.  These are
special because teken is a library common to both the kernel and the
loader, and we want to avoid having special vars to control the loader
vs. the kernel.  Ideally, if a user wants a different set of console
colors, then they set the appropriate teken variable and it
Just Works(TM) everywhere.  We can't just avoid setting the env vars,
because we specifically want to install a hook to adjust how loader is
drawn.

This allows us to avoid breaking a kernel config(5) that has some
default teken colors set with our defaults.  That's a valid
configuration, even if it might seem weird that they don't want to set
colors in both loader and the kernel -- they may not anticipate spending
any time in loader, and thus prefer to just let it do its default
behavior.

NOKENV is expected to be unset if the value is overwritten, rather than
acting as a persistent marker that we do not want the value to persist
under any circumstance.  We can always add another flag bit later for
persistence if we find a use for that, but most variables are fine to
carry over.  This is mostly needed for environment variables that we
really just want to set a hook for.

Future work could expand this to break it out to the scripted
interfaces.  We have discussed some options like a new built-in command,
or adding a flag to the existing `set` command, but haven't really come
up with a concrete plan to avoid confusion.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D50888
2025-08-21 22:48:29 -05:00
Simon J. Gerraty 5bfb3045d2 Allow secure-netboot
When doing file verification, tftp needs to be able to handle multiple
open files concurrently.
We also need tftp_stat() to provide useful values for st_dev and st_ino.

Allow an architecture to define NETPROTO_DEFAULT.
The default is NET_NFS for backwards compatability.

In net_parse_rootpath() fix parsing of
<scheme>://<ip>[:<port]/<path>
and ensure we return INADDR_NONE unless we successfully
parsed an addr, so we don't end up clobbering rootip obtained
from bootp().

Sponsored by:   Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D51187
2025-08-20 15:49:53 -07:00
Simon J. Gerraty b44cc1b479 loader: do not try to open directories with TFTP
Attempting to mount or even open / with some tftp servers
causes a several minute delay in boot.

Since opening a directory via TFTP does not make sense, we
avoid it.  We don't know if using TFTP until after net_open()
has been called.

Add an is_tftp() accessor to avoid everyone having to include
all the net* headers.

Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D51447
2025-08-20 15:45:54 -07:00
Simon J. Gerraty aaf65a13c0 stand: add fs_ops.fs_flag
To avoid a layering violation in open() allow fs_ops to
indicate that devopen() should be skipped.

This is only true for pkgfs.

Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D51684
2025-08-20 15:42:35 -07:00
Gleb Smirnoff fe2418f26e libsa/zfs: inline vdev_init_from_label() into vdev_probe()
This function is used only once and also pulls three variables from the
nvlist that the only caller have already pulled out.

Reviewed by:		mav, imp
Differential Revision:	https://reviews.freebsd.org/D52031
2025-08-20 07:53:20 -07:00
Gleb Smirnoff a1572e202a libsa/zfs: further improve handling of stale labels
Fix two problems with 6dd0803ffd.  First problem is that situation when
newer label was read before stale one, was handled differently to reverse
order case.  Second problem is that vdev_free() would free the fully
initialized leaf vdev that carried stale label.  In a case when vdev
carries a stale label, but is still referenced by a different label with
new a configuration, we don't want to free it, but rather insert it into
the new configuration.

o Provide a helper function nvlist_find_vdev_guid() that checks presence
  of certain GUID in a label.
o In top level vdev store the GUID of vdev used to instantiate top vdev.
o Cover all possible cases in the block in vdev_probe() where we encounter
  a known configuration.  Make the diagnostic print more informative and
  looking same regardless of probe order.  Make this whole block easier to
  read reducing one level of indentation for a price of a single comparison
  at runtime.

Reviewed by:		mav, imp
Differential Revision:	https://reviews.freebsd.org/D51913
Fixes:			6dd0803ffd
2025-08-20 07:52:20 -07:00
Gleb Smirnoff 9dbd8ee116 libsa/zfs: refactor vdev tree for better resiliency against stale disks
Before this change in vdev_insert() we would avoid inserting a duplicate
vdev to the list of children, however this duplicate being unlinked from
the parent is still stored on the global list with initialized v_guid.
Such leaked duplicate can later be returned by vdev_find().  After
6dd0803ffd such leaked vdev may be freed or pointing to a freed parent,
which leads to a loader crash.  Note that the leak problem was there
before 6dd0803ffd.

First, in vdev_insert() free conflicting vdev and return the existing one.
Update callers accordingly.  There is only one caller that actually may
encounter this condition.

Second, eliminate global list of vdevs and make vdev_find() to work
recursively on the tree that a caller must provide.  Of course, a chance
of GUID collision between members of different pools is extremely low. The
main motivation here is just to increase code robustness and fully isolate
the data structures of different pools being tasted by the loader, and
make easier debugging of bugs like the one being fixed.

Reviewed by:		mav, imp
Differential Revision:	https://reviews.freebsd.org/D51912
Fixes:			6dd0803ffd
2025-08-20 07:51:21 -07:00
Gleb Smirnoff 8ef5016f73 libsa/zfs: simplify vdev_find_previous()
An empty list case is properly covered by the cycle.
Don't pass pointer to vdev being looked up, pass just id.

Reviewed by:		mav, imp
Differential Revision:	https://reviews.freebsd.org/D51911
2025-08-20 07:51:14 -07:00