Casting the byte buffer that holds the Reservation Report payload to
the status structures trips -Wcast-align on strict-alignment
architectures, which broke the CI builds there. Put the buffer in a
union with the two status structures instead, so it is properly
aligned and no casts are needed.
Reported by: FreeBSD CI
Fixes: ba75cf0572 ("camcontrol: Support NVMe reservations via the persist subcommand")
Co-authored-by: Claude Fable 5 <[email protected]>
MFC after: 1 week
Sponsored by: Spectra Logic
Add a feature subcommand for the NVMe Get Features and Set Features
commands:
camcontrol feature ndaX -a <get|set> -f feature [-d data]
[-s num] [-U]
There is no transport-specific prefix in the name: SCSI has no
feature command (the closest equivalents are mode pages), and the
ATA SET FEATURES subcommands are already exposed through dedicated
camcontrol subcommands (apm, aam, epc and the power commands), so
the name is unclaimed. The subcommand returns an error for
non-NVMe devices.
Currently, only the hostid feature is fully implemented. The
hostid value for set is specified with -d as a UUID or an integer
in decimal, hex, or octal, and -U outputs the hostid as a UUID on
get.
The -s argument exposes the feature select / save fields from the
NVMe specification. If bit 4 of the Optional NVM Command Support
(ONCS) field of the Identify Controller data is set, each feature
has a default, saved and current value, plus a capabilities mask:
- For get, -s selects which to display: 0 (current),
1 (default), 2 (saved) or 3 (capabilities).
- For set, -s is the save flag; a value of 1 sets the saved
value as well as the current value, so the feature
persists across an NVMe reset. Setting the save flag only
works if the feature's capability mask includes saveable.
sbin/camcontrol/nvfeature.c:
New file, the camcontrol(8) feature subcommand for getting
and setting NVMe features.
sbin/camcontrol/camcontrol.c:
Add the feature subcommand, dispatched only to NVMe devices.
sbin/camcontrol/camcontrol.h:
Add the nvmefeature() prototype.
sbin/camcontrol/Makefile:
Add nvfeature.c to the build.
sbin/camcontrol/camcontrol.8:
Document the feature subcommand.
Co-authored-by: Reid Linnemann <[email protected]>
Co-authored-by: Dave Baukus <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Reviewed by: imp
MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D59536
Support formatting NVMe namespaces through the existing format
subcommand. The format subcommand now dispatches on the device
protocol, in the same way the identify and persist subcommands do,
and issues the NVMe FORMAT NVM command for NVMe devices.
The SCSI syntax and behavior are unchanged. The NVMe-specific
options are -e (secure erase setting), -G (format all namespaces),
-f (LBA format), -l (protection information location), -m (metadata
setting) and -p (protection information type). The -q and -y options
work for both protocols; NVMe formats gain the same confirmation
question that SCSI formats have always had. The -r and -w options
are SCSI only; -r returns an error for NVMe devices and -w has no
effect, since the NVMe format command does not complete until the
format is finished.
The default timeout for NVMe is 30 seconds for a cryptographic erase
and 30 minutes otherwise; the generic -t option overrides it.
sbin/camcontrol/nvformat.c:
New file, the NVMe format backend for the format subcommand.
sbin/camcontrol/camcontrol.c:
Dispatch the format subcommand to scsiformat() or
nvmeformat() based on the device protocol.
sbin/camcontrol/camcontrol.h:
Add the nvmeformat() prototype.
sbin/camcontrol/Makefile:
Add nvformat.c to the build.
sbin/camcontrol/camcontrol.8:
Document NVMe support in the format subcommand section, and
note the differences from SCSI where they occur.
Co-authored-by: Claude Fable 5 <[email protected]>
Reviewed by: imp
MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D59535
The NVMe reservation model is closely patterned after SCSI Persistent
Reservations, so support NVMe devices through the existing persist
subcommand rather than adding a transport-specific subcommand. The
persist subcommand now dispatches on the device protocol, in the same
way the identify subcommand does.
The SCSI syntax is unchanged. For NVMe devices, the -i modes all map
to the Reservation Report command (read_full_status requests the
extended data structure, which contains 128-bit Host Identifiers), and
the -o service actions map to the corresponding NVMe reservation
operations: register, register_ignore, reserve, preempt,
preempt_abort, release and clear, plus two NVMe-only actions,
unregister and replace. The reservation type names for -T are shared
between SCSI and NVMe. A new -c option gives explicit control over
the NVMe Persist Through Power Loss State; -p is equivalent to
-c enable. SCSI-only options return an error for NVMe devices.
Tested against a PASCARI X200 series SSD (reservation capabilities:
WR_EX, PTPL, IEKEY13): register, reserve, release, replace,
unregister, -c enable/disable (Persist Through Power Loss State change
verified in the report output), reservation report, and the error
paths. register_ignore is rejected by drives that implement NVMe 1.3
IEKEY semantics, as expected. SCSI persist against a da(4) device is
unchanged.
sbin/camcontrol/nvres.c:
New file, the NVMe reservation backend for the persist
subcommand.
sbin/camcontrol/camcontrol.c:
Dispatch the persist subcommand to scsipersist() or
nvmepersist() based on the device protocol.
sbin/camcontrol/camcontrol.h:
Add the nvmepersist() prototype.
sbin/camcontrol/Makefile:
Add nvres.c to the build.
sbin/camcontrol/camcontrol.8:
Document NVMe support in the persist subcommand section, and
note the differences from SCSI where they occur.
Co-authored-by: Reid Linnemann <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Reviewed by: imp
MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D59534
Add a -N argument to camcontrol identify. This will fetch and
display namespace Identify data for NVMe drives, using
nvme_print_namespace() from nvmecontrol(8).
This gets the namespace Identify data via XPT_DEV_ADVINFO (i.e.
data cached in the kernel) like the standard NVMe identify command
does, and so works even on NVMe devices that do not support NVMe
Namespace Management.
sbin/camcontrol/camcontrol.c:
Add a -N argument to camcontrol identify.
Rename nvme_get_cdata() to nvme_get_data(), and give it the
ability to fetch controller or namespace Identify data.
While here, improve its error reporting with
cam_error_print(), and only look at the CAM status bits of
the returned CCB.
Change identify(), ataidentify(), and nvmeidentify() to
handle the extra arguments.
Give nvmeidentify() the ability to fetch and print NVMe
namespace data, using nvme_print_namespace() from
nvmecontrol(8).
sbin/camcontrol/camcontrol.h:
Add the nvme_get_data() prototype, for use by future NVMe
subcommands living outside camcontrol.c.
sbin/camcontrol/camcontrol.8:
Document camcontrol identify -N. Make it clear that the
NVMe data is from data cached in the kernel. Add a cross
reference to nvmecontrol(8).
Co-authored-by: Claude Fable 5 <[email protected]>
Reviewed by: imp
MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D59533
Add command (struct nvme_command) building functions for the four
NVMe reservation opcodes (Report, Register, Acquire and Release),
Format NVM, and Get Features / Set Features, along with the
enumerations and data structures that go with them. These are
shared between the kernel and userland, and are the underpinnings
for new camcontrol(8) subcommands (nvres, nvformat, nvfeature) that
will be added separately.
The reservation type names are intentionally similar to the SCSI
names for the same reservation types.
sys/dev/nvme/nvme.h:
Add NVMe command building functions for the four NVMe
reservation opcodes: nvme_ns_resv_report_cmd(),
nvme_ns_resv_register_cmd(), nvme_ns_resv_acquire_cmd() and
nvme_ns_resv_release_cmd().
Add enumerated types for the various NVMe reservation
subcommand actions (acquire, register, release), reservation
types, and Change Persist Through Power Loss State values.
Add struct nvme_resv_acq_data and struct nvme_resv_reg_data,
the data payloads for reservation Acquire and Register.
Add a new NVMe Format NVM command building function,
nvme_admin_format_cmd(), and an enumeration for the Secure
Erase Setting parameter for format.
Add nvme_admin_get_feature_cmd() and
nvme_admin_set_feature_cmd() functions to fill a struct
nvme_command for Get Features / Set Features.
Add macros for bitfields in the ctratt and mic dwords of the
NVMe Identify Controller data structure.
Add a prototype for nvme_hostid_sbuf().
Stop byte swapping the hostid fields in
nvme_resv_status_swapbytes() and
nvme_resv_status_ext_swapbytes(), and document the fields as
little endian. The hostid is an opaque 8 or 16 byte value;
keep it in the byte order the device returns it in instead of
interpreting it at this level.
Widen the nvme_ctrlr_cmd_get_feature() and
nvme_ctrlr_cmd_set_feature() prototypes as described below.
While here, fix the entry count clamp in the reservation status
swapbytes functions to use sizeof(*s) rather than sizeof(s); using
the pointer size made the clamp one entry too permissive.
sys/dev/nvme/nvme_util.c:
Add nvme_hostid_sbuf(), which formats an 8 or 16 byte hostid
(from the Get Features hostid feature, in the little-endian
byte order the device returns it in) into an sbuf as an
integer value in base 16, most significant byte first.
sbin/nvmecontrol/resv.c:
Decode the now little-endian hostid fields explicitly when
printing, and zero pad the printed 64-bit values. Previously
the extended hostid printed in a different byte order on big
and little endian machines, and without zero padding between
the two halves.
sys/dev/nvme/nvme_ctrlr_cmd.c:
Refactor nvme_ctrlr_cmd_get_feature() and
nvme_ctrlr_cmd_set_feature() to use the new command building
functions from nvme.h and accept a namespace ID parameter.
Refactor nvme_ctrlr_cmd_set_feature() to also accept the sv
(save) parameter to persist a feature value across reset.
sys/dev/nvme/nvme_ctrlr.c:
Update the temperature threshold, autonomous power state
transition and host memory buffer callers for the new
nvme_ctrlr_cmd_get_feature() and nvme_ctrlr_cmd_set_feature()
arguments.
Co-authored-by: Reid Linnemann <[email protected]>
Co-authored-by: Dave Baukus <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Reviewed by: imp
MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D59531
Move print_namespace() from identify.c to identify_ext.c and rename
it to nvme_print_namespace(), to match nvme_print_controller().
This allows other consumers (notably camcontrol(8)) to print NVMe
namespace Identify data.
No functional changes intended.
sbin/nvmecontrol/identify.c:
Remove print_namespace(), and call nvme_print_namespace()
instead.
sbin/nvmecontrol/identify_ext.c:
Add nvme_print_namespace(), moved here from identify.c.
sbin/nvmecontrol/nvmecontrol.h:
Remove the print_namespace() prototype.
sbin/nvmecontrol/nvmecontrol_ext.h:
Add the nvme_print_namespace() prototype.
sbin/nvmecontrol/ns.c:
Include nvmecontrol_ext.h, and rename print_namespace() calls
to nvme_print_namespace().
Co-authored-by: Claude Fable 5 <[email protected]>
Reviewed by: imp
MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D59530
The avgfilesize description does not say what the unit is (sectors,
blocks, bytes). Extend the description to mention that this parameter is
in bytes.
PR: 298705
Event: Oslo Hackathon 2026
Differential Revision: https://reviews.freebsd.org/D61047
Add a test case that creates and starts two nodes, has one assume the
primary role and the other the secondary role, writes to the device,
verifies that the data is synced to both nodes, then switches the roles,
and finally shuts both nodes down and compares their backing stores.
Differential Revision: https://reviews.freebsd.org/D59676
Normally, hastd will use the hostname, hostuuid, or hostid as node name.
Allow overriding this with a new -n command-line option. The argument
is treated as a replacement for the hostname, but also disables the
hostuuid and hostid logic. This allows running multiple nodes on the
same system, which is useful for testing.
Differential Revision: https://reviews.freebsd.org/D59675
Make hastd remove its pidfile before exit after catching a signal or a
stop control message, not just on failure to start.
MFC after: 1 week
Reviewed by: ngie
Differential Revision: https://reviews.freebsd.org/D60192
pf's Netlink commands are checked against the credentials of the socket,
so a socket opened by a privileged process keeps its authority across a
privilege drop and exec, as the /dev/pf descriptor passed as -p
/dev/fd/N already does. -l takes the descriptor number of such a socket
and uses it for every request instead of creating a new one.
authpf(8) uses this to run pfctl as the logged-in user.
PR: 291981
Signed-off-by: Avinash Duduskar <[email protected]>
Reviewed by: kp
Pull Request: https://github.com/freebsd/freebsd-src/pull/2508
sector_size is guaranteed to be non-zero here, so cast to
uint32_t to match the comparison.
This fixes the [gcc14 build in CI][0]:
/workspace/src/sbin/nvmecontrol/format.c: In function 'find_lbaf':
/workspace/src/sbin/nvmecontrol/format.c:132:60: error: comparison of integer expressions of different signedness: 'uint32_t' {aka 'unsigned int'} and 'int' [-Werror=sign-compare]
132 | if (NVMEV(NVME_NS_DATA_LBAF_LBADS, format) != lbads ||
| ^~
[0] https://ci.freebsd.org/job/FreeBSD-main-amd64-gcc14_build/5051/
Reviewed by: imp
Fixes: b991e2dd82 ("nvmecontrol: support controller-wide sector sizes")
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Use void, not char, for pointers to opaque data in our send and receive
functions.
Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D60729
pfctl_ina_define() returns an error number instead of setting errno, but
both of its callers print errno. A table that failed to load was
reported as "cannot define table t: No error: 0", or with a stale errno,
both in the main ruleset (process_tabledef()) and in anchors
(pfctl_load_tables()).
Reviewed by: kp
Fixes: 219ce30638 ("pf: convert DIOCRINADEFINE to netlink")
Sponsored by: Rubicon Communications, LLC ("Netgate")
pfctl_flush_fingerprints() returns an error number instead of setting
errno, so a failed flush was reported with whatever errno held: "No
error: 0" on a kernel with ALTQ, ENODEV from the ALTQ probe on one
without. Every "pfctl -f" flushes the fingerprints first, so on a
kernel that predates PFNL_CMD_OSFP_FLUSH every ruleset load fails this
way without saying why.
Reviewed by: kp
Fixes: 75c0a83762 ("pf: convert DIOCOSFPFLUSH DIOCOSFPGET DIOCOSFPADD to netlink")
Sponsored by: Rubicon Communications, LLC ("Netgate")
When we're doing admin-passhtru, we need to use the admin device, not
the namespace device. So when we're passed in ndaX or nvdX, we need to
translate that to nvmeY for this command for the admin-passthru command,
but not the io-passthru command. Note namespace nuance in man page.
Differential Revision: https://reviews.freebsd.org/D59878
Add -n/--dry-run to resolve and print the Format NVM command without
submitting it. This lets users verify namespace selection and format
parameters before making destructive media changes.
Reviewed by: seuros, chuck
Differential Revision: https://reviews.freebsd.org/D59835
Extend sector-size selection to controller-wide formats when every
namespace has one compatible format index and matching effective
metadata and protection settings. Reject ambiguous or inconsistent
layouts so heterogeneous fleets can request a sector size without
risking an unintended controller-wide format.
Reviewed by: seuros, chuck
Differential Revision: https://reviews.freebsd.org/D59834
Add automatic selection of lbaf value based on a single sector size. The
lbas (the data sector size) is selected based on the power of 2 in the
sector size, and the metadata size is selected by the remainder. If an
lbaf matches these values is used, otherwise we exit with an error.
When there's a tie, we prefer the higher performance.
Manual selection of these values remains as well for times when we
select incorrectly.
Reviewed by: seuros, chuck
Differential Revision: https://reviews.freebsd.org/D59833
Add tests for some recently fixed bugs in dhclient. All of these tests
set up two VNET jails connected by an epair. dhclient runs in one jail,
and the test code runs on the other end. It uses scapy to inject
"interesting" packets in response to DHCPDISCOVER messages from
dhclient, then checks the configured interface and lease file.
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D60485
The loop did not verify that the option buffer is large enough before
reading an address.
Reported by: Andrew Griffiths <[email protected]>
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D60484
* ggatel: fix piped output. Flush stdout before daemonizing, so the
output can be read when it's in a command pipeline.
* ggated: bind the port _before_ daemonizing, so an invoking script can
be sure that the port is bound as soon as the command returns.
* tests: allow ggatec or ggatel to automatically allocate a device
number instead of choosing one in a racy way.
With all of these changes I can no run the tests 1000 times without
fail. And in parallel, too.
MFC after: 1 week
Sponsored by: ConnectWise
PR: 298942
Reported by: siva
Reviewed by: ngie
Differential Revision: https://reviews.freebsd.org/D60707
The function went when DIOCRINADEFINE was converted to netlink; pfctl
calls pfctl_ina_define() from libpfctl instead. Name that one in the
error message that pfctl_load_tables() prints when it fails.
Fixes: 219ce30638 ("pf: convert DIOCRINADEFINE to netlink")
Sponsored by: Rubicon Communications, LLC ("Netgate")
Write the URI received in DHCP option 114 to
/var/run/captive-portal.IFACE atomically, with the legacy option 160 as
a fallback, and remove the file on EXPIRE and FAIL.
Reviewed by: bcr (manpage)
Differential Revision: https://reviews.freebsd.org/D60259
Add DHCP options 114 (captive-portal) and 160 (captive-portal-legacy)
to the default Parameter Request List so that servers advertise the
Captive Portal API URI.
Approved by: emaste
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D60257
Rename option 114 from "url" to "captive-portal" (RFC 8910) and retain
"url" as a deprecated alias. Rename option 160 from the generic
"option-160" to "captive-portal-legacy" (RFC 7710).
Reviewed by: emaste, dch
Apprived by: emaste, dch
Differential Revision: https://reviews.freebsd.org/D60256
The majority of lines of code currently in fwdownload.c come from ken@'s
rework in commit 0e358df062 ("Revamp camcontrol(8) fwdownload support
and add the opcodes subcommand."). Add the appropriate copyright.
Approved by: ken
The chunked table address functions (set, add, del, clr_astats) add
each chunk's result to the caller's counter without initialising it.
pfctl reuses nadd for the number of tables created, so a replace that
also creates the table is off by one:
pfctl -t foo -T replace 192.0.2.1
reports "2 addresses added".
Zero the counters first, as pfctl_test_addrs() already does. Remove
the workaround for the add case from pfctl (da64f6e047), which is
no longer needed.
Add a regression test.
Reviewed by: kp
Approved by: kp (mentor)
Fixes: 08ed87a4a2 ("pf: convert DIOCRSETADDRS to netlink")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D60174
c2d03a920e rewrote the action printing in print_rule() from OpenBSD,
which has no natpass, and dropped the "pass" keyword. A ruleset
loaded from "pfctl -sn" output therefore lost its nat-pass semantics.
Add a parser test covering nat, rdr, rdr log and binat with pass.
Reviewed by: kp
Approved by: kp (mentor)
Fixes: c2d03a920e ("pfctl: fix anchortypes bounds test")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D60183
The standard list and status subcommands of every GEOM class emit
through libxo, and so does geom -p, but only geom.8 (list, status) and
gpart.8 (show) mentioned it. Mark the list and status forms with
--libxo in all class manual pages, add the option description, and
cross-reference xo_options(7). Also mark geom -p in geom.8.
Only forms whose output already goes through libxo are marked;
class-specific verbs such as gmirror dump still print directly and are
left alone.
Reviewed by: adrian, bcr, carlavilla, des
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D59574
Bytes 102 through 110 of the I/O Command Set Independent Identify
Controller data structure were reserved padding. Name them: Boot
Partition Capabilities (byte 102), CXL HDM Support Information (byte
103), NVM Subsystem Shutdown Latency (bytes 107:104) and Power Loss
Signaling Information (byte 110). Bytes 109:108 stay reserved.
CXL HDM Support Information was added in NVM Express Base Specification
2.4, Figure 338; the others appear in 2.3, Figure 328.
Report the new fields from nvmecontrol identify.
Reviewed by: imp, adrian
Differential Revision: https://reviews.freebsd.org/D60000
bitmap_ctor() computed the allocation size as
roundup2(bits, LONG_BIT) / (LONG_BIT / 8)
The dividend is a count of bits, so converting it to bytes requires
dividing by 8 (bits per byte), not by LONG_BIT / 8 (bytes per long).
The two divisors happen to coincide on LP64, but on ILP32 platforms
the head bitmap was allocated at twice the required size; for a
FAT32 file system with close to 2^28 clusters, that is 64 MiB instead
of 32 MiB.
The extra half of the allocation was never accessed, so there is no
functional change other than the reduced memory footprint.
MFC after: 3 days
Pull Request: https://github.com/freebsd/freebsd-src/pull/2440