Use actual file size when resizing FILE namespaces
save_file decided whether a filesize change was an expansion by comparing
against the stored filesize. That value is None for a namespace created
from an existing file without a filesize, which made a later resize fail
with a TypeError. It can also be stale: if it was smaller than the real
file, a requested "expansion" would truncate the file and lose data.
Compare against the file's actual size instead, and record that size when
an existing file is used without a filesize being supplied.
Require FILE namespace sizes to be a multiple of 512 bytes
SPDK's bdev_aio_create rejects a file whose size is not a multiple of
the block size, so such a namespace failed to attach. Reject these at
create/update time for both targets: check the size of an existing file
when it is first used, and any new or changed filesize.
Add NVMET_FILE_BLOCK_SIZE and use it for the SPDK bdev_aio_create
default block size as well.
Isolate per-item failures in kernel nvmet render
The kernel nvmet render steps are nested context managers, so an
OSError from any configfs write propagates through all of them. For
example, a namespace whose device_path cannot be opened makes the write
to enable fail. When that happens:
- remaining namespaces, and any subsystems after the failing one, are
not processed
- directories created by mkdir earlier in the same pass are left with
no attributes
- every post-yield delete phase (rmdir/unlink of stale hosts, ports,
referrals, links and namespaces) is skipped
Because the bad namespace directory remains, every later render takes
the update path, fails again and aborts in the same way. Until the
backing device is fixed or the namespace is removed, any NVMe-oF config
change applies its additions but never its deletions.
[13 lines not shown]
Isolate per-item failures in SPDK nvmet render
A single bad config item could abort the entire SPDK nvmet render. For
example, a FILE namespace whose size is not a multiple of the block size
makes bdev_aio_create fail with -EINVAL. Because the render steps are
nested context managers, the exception propagated through all of them:
- remaining bdevs were only partially created, in set-iteration order
- no namespaces were attached at all, even for healthy bdevs
- every post-yield delete phase was skipped, leaving stale state
- on HA, the transition of ANA state to optimized was skipped
The failure also recurred on every later render until the bad item was
fixed or removed, and was only visible in middlewared.log.
NvmetConfig.render now runs each add, update and delete through
_apply(). It logs the failing item and records it, and the render
continues. Once all steps have completed, write_config() raises a single
RuntimeError listing every failure, so etc.generate still reports the
[4 lines not shown]
Ignore the BACKUP from vrrp_backup's own keepalived restart
vrrp_backup pauses failover event processing, then stops keepalived
to move the VIPs off this node. Stopping keepalived removes its
fifo, so VrrpFifoThread loses its connection and starts retrying.
Near the end, vrrp_backup starts keepalived again, which reports
BACKUP (init), and then unpauses event processing.
Normally VrrpFifoThread reconnects before the unpause, and that
BACKUP is discarded because events are still paused. But the first
time the reader loses the fifo, it sleeps for 2 seconds before
retrying. If vrrp_backup gets from stopping keepalived to unpausing
in less than that, the reader is still asleep at the unpause. It
reconnects afterwards, reads the BACKUP as a new event, and
vrrp_backup runs a second time.
validate() already ignores a BACKUP while vrrp_backup is running.
Also ignore one after vrrp_backup has completed successfully, using
LAST_EVENT_TYPE. Because vrrp_backup sets LAST_EVENT_TYPE before
[4 lines not shown]
NAS-144162 / 28.0.0-BETA.1 / Harden NTP (#19907)
Basically, this commit is adding support for a newer secure way of
updating time. It's a preliminary
step for some WORM-related work in S3 land where we want to basically
ensure that buckets fall
back to being RO if time de-synced or not from secure source.
- Add `nts` to system.ntpserver, rendered as chrony's `nts` option
- Without `force`, probe NTS-KE (TLS 1.3, ALPN ntske/1) and the
negotiated NTP server on save
- Cap `maxpoll` at 21 for NTS servers
- Render `authselectmode prefer` in chrony.conf
- Add system.security `require_nts` (default off), rendered as
`authselectmode require`
- With `require_nts`: refuse enabling without an NTS server, saving
servers without NTS and deleting the last NTS server
- Restart chronyd on both controllers when `require_nts` changes
- Migration: add `ntp_nts` and `require_nts`
[24 lines not shown]
NAS-145046 / 27.1.0 / Make all string fields single-line by default (by themylogin) (#20209)
`str` now accepts only single-line string by default.
If we need a multiline string, it must be `Multiline[str]` or
`Multiline[NonEmptyString]` or etc.
Original PR: https://github.com/truenas/middleware/pull/20179
---------
Co-authored-by: themylogin <themylogin at gmail.com>
NAS-145038 / 28.0.0-BETA.1 / Add webui.dataset.details and move pool.dataset.details onto zfs.resource (#20102)
## Context
This adds the machinery the WebUI needs to move off
`pool.dataset.details` without breaking today's contract.
`pool.dataset.details` keeps returning exactly what it returns now, so
the current UI keeps working unchanged, and the new
`webui.dataset.details` is there for the Datasets page to switch to when
it's ready.
- **pool.dataset.details** now gets its data from zfs.resource instead
of the legacy query engine, as part of retiring the pool.dataset
namespace. Its output is unchanged.
- **webui.dataset.details** lives in the webui namespace rather than
zfs.resource. It exists to give the Datasets page everything it shows in
one cheap call: every dataset, plus the shares, VMs, containers, apps
and data protection tasks that use it. That is a join across most of the
plugins that consume storage, and zfs.resource shouldn't depend on its
own consumers.
[7 lines not shown]
Skip the BACKUP from vrrp_backup's own keepalived restart
vrrp_backup pauses failover events, stops keepalived to move the
VIPs off this node, and starts it again before unpausing. The
restarted keepalived reports BACKUP (init). If VrrpFifoThread
reconnects to the fifo after the unpause, which happens when the
time from keepalived stopping to the unpause is less than the
reader's 2 second retry sleep, that BACKUP is processed as a new
event and the whole BACKUP sequence runs a second time.
Drop a BACKUP event when the last failover event was a successful
vrrp_backup. VrrpEventThread already did this for events arriving
in rapid succession, using LAST_EVENT_TYPE; now it does it for every
BACKUP. Set LAST_EVENT_TYPE to MASTER when vrrp_master starts
rather than when it succeeds, so that a BACKUP following a MASTER
attempt that failed or was ignored is still processed.
NAS-145201 / 27.0.0 / Keep scst disabled at boot after config upload on HA (by bmeagherix) (#20213)
## Problem
On HA, SCST must not start at boot; middleware starts it from
`vrrp_master` /
`vrrp_backup`. `etc_files/systemd.py` enforced this, but two other paths
could
still leave `scst` enabled at boot:
- **Sync to Peer:** the `config.on_upload` hook re-enabled `scst` on the
STANDBY
just before it rebooted. SCST then started at boot with a stale config,
failed,
and raced middleware's own start, leaving SCST unloaded and
`standby_after_start` retrying forever.
- **Upgrade:** `/data/user-services.json` recorded `scst` as enabled, so
the
installer enabled it in the new boot environment.
[31 lines not shown]
NAS-145201 / 27.1.0 / Keep scst disabled at boot after config upload on HA (by bmeagherix) (#20214)
## Problem
On HA, SCST must not start at boot; middleware starts it from
`vrrp_master` /
`vrrp_backup`. `etc_files/systemd.py` enforced this, but two other paths
could
still leave `scst` enabled at boot:
- **Sync to Peer:** the `config.on_upload` hook re-enabled `scst` on the
STANDBY
just before it rebooted. SCST then started at boot with a stale config,
failed,
and raced middleware's own start, leaving SCST unloaded and
`standby_after_start` retrying forever.
- **Upgrade:** `/data/user-services.json` recorded `scst` as enabled, so
the
installer enabled it in the new boot environment.
[31 lines not shown]
NAS-145201 / 27.1.0 / Keep scst disabled at boot after config upload on HA (#20185)
On HA, SCST must not start at boot; middleware starts it from
vrrp_master / vrrp_backup. etc_files/systemd.py enforced this, but
two other paths could still leave `scst` enabled at boot:
- Sync to Peer: the config.on_upload hook re-enabled scst on the
STANDBY just before it rebooted. SCST then started at boot with a
stale config, failed, and raced middleware's own start, leaving
SCST unloaded and standby_after_start retrying forever.
- Upgrade: /data/user-services.json recorded scst as enabled, so the
installer enabled it in the new boot environment.
LIO mode has the same issue to a lesser degree: scst should never be
enabled at boot there.
- Add systemd_enabled_units() to services, defaulting to all of a
service's units, with an iSCSI override that returns none on HA or
in LIO mode. Unit state set by etc_files/systemd.py, the
[14 lines not shown]
NAS-145201 / 27.0.0 / Keep scst disabled at boot after config upload on HA (#20185)
On HA, SCST must not start at boot; middleware starts it from
vrrp_master / vrrp_backup. etc_files/systemd.py enforced this, but
two other paths could still leave `scst` enabled at boot:
- Sync to Peer: the config.on_upload hook re-enabled scst on the
STANDBY just before it rebooted. SCST then started at boot with a
stale config, failed, and raced middleware's own start, leaving
SCST unloaded and standby_after_start retrying forever.
- Upgrade: /data/user-services.json recorded scst as enabled, so the
installer enabled it in the new boot environment.
LIO mode has the same issue to a lesser degree: scst should never be
enabled at boot there.
- Add systemd_enabled_units() to services, defaulting to all of a
service's units, with an iSCSI override that returns none on HA or
in LIO mode. Unit state set by etc_files/systemd.py, the
[14 lines not shown]
NAS-145201 / 28.0.0-BETA.1 / Keep scst disabled at boot after config upload on HA (#20185)
On HA, SCST must not start at boot; middleware starts it from vrrp_master / vrrp_backup. etc_files/systemd.py enforced this, but two other paths could still leave `scst` enabled at boot:
- Sync to Peer: the config.on_upload hook re-enabled scst on the STANDBY just before it rebooted. SCST then started at boot with a stale config, failed, and raced middleware's own start, leaving SCST unloaded and standby_after_start retrying forever.
- Upgrade: /data/user-services.json recorded scst as enabled, so the installer enabled it in the new boot environment.
LIO mode has the same issue to a lesser degree: scst should never be enabled at boot there.
- Add systemd_enabled_units() to services, defaulting to all of a
service's units, with an iSCSI override that returns none on HA or in LIO mode.
Unit state set by etc_files/systemd.py, the user-services.json it writes,
and on_config_upload now all come from this one place. on_config_upload
takes the iSCSI mode from the uploaded database rather than the live config.
- Add truenas-scst-boot.py, which the installer runs in the new boot environment on upgrade. It covers upgrades from versions whose user-services.json still says scst is enabled. Neither middleware nor the license daemon runs there, so it cannot check the license; it disables scst in LIO mode, or when ALUA is enabled on an HA hardware platform.
- Log a periodic warning from standby_after_start when the SCST kernel modules are not loaded, since retrying cannot succeed in that state.
Add truenas-scst-boot.py to keep scst disabled after upgrade
On upgrade the installer enables every unit marked enabled in the
old boot environment's /data/user-services.json. Middleware without
the previous commit recorded scst there as enabled even on HA and in
LIO mode, so the first boot of the new environment could start SCST
before middleware disabled it again.
Add a script for the installer to run chrooted in the new boot
environment, after the database migration and with /proc, /sys and
/dev mounted, as it already does for truenas-hw-license.py. It
disables scst if the iSCSI mode is LIO, or if ALUA is enabled and the
hardware is an HA platform. If the check fails, the script exits
non-zero and leaves scst unchanged.
Keep scst disabled at boot on HA and in LIO mode
On HA, scst must not start at boot; middleware starts it from
vrrp_master / vrrp_backup. It is also unused in LIO mode.
etc_files/systemd.py enforced this when setting unit state, but
two other paths did not:
- The config.on_upload hook (run on the STANDBY by sync_to_peer)
enabled scst just before the STANDBY rebooted.
- /data/user-services.json recorded scst as enabled, so the
installer enabled it in the new boot environment on upgrade.
Add systemd_enabled_units(), which defaults to the service's systemd
units, and override it for iscsitarget to return none on HA or in LIO
mode. Use it in both etc_files/systemd.py (including the JSON it
writes) and on_config_upload. on_config_upload passes the uploaded
database so the iSCSI mode is taken from it, not from the live config.
Warn when SCST is not loaded during standby_after_start
Diagnostic only: retrying to surface cluster_mode cannot succeed if the
SCST kernel modules are not loaded, so log a rate-limited warning.
NAS-145046 / 27.1.0 / Let a generated SSH key pair keep its line breaks
`keychaincredential.generate_ssh_key_pair` returns a PEM private key and
an OpenSSH public key. Both carry line breaks, so the result model needs
`Multiline`. #20179 missed it, and master has the same gap in
`v25_10_0` through `v25_10_5`, `v27_0_0` and `v28_0_0`.
Production only logs the failure, because `serialize_result` falls back
to `remove_secrets`. The integration suite turns that fallback off in
`tests/conftest.py`, so six `tests/api2` files that call the method fail
instead.
NAS-145046 / 27.1.0 / Mark the multiline fields of the older API versions
Master no longer carries `v24_10` or `v25_04_0` through `v25_04_2`, so
#20179 left them alone. This branch still serves all four. A client
pinned to one of them would now get "Line breaks are not allowed" for a
value it has always been allowed to send. A result built from a stored
multiline value would fail the same way.
Every field here takes the marker its `v25_10_0` counterpart takes. A
class these versions lack stays unmarked, and so does a field master
left unmarked.
NAS-145046 / 27.1.0 / Make all string fields single-line by default
`str` now accepts only single-line string by default.
If we need a multiline string, it must be `Multiline[str]` or
`Multiline[NonEmptyString]` or etc.
This branch differs from master, so the backport also does this:
- `v27_1_0` is `v27_0_0` without the `to_previous` and `from_previous`
adapters, so it is regenerated from the changed `v27_0_0`.
- `v25_10_3` and `v25_10_4` are copies of `v25_10_5`, which master drops.
- Both migrations go to a new `versions/27.1`, registered in
`alembic.ini`, under revision ids of their own. `hosts_json` chains
onto `6d08137a3def`.
- `FullAdmin`, the sorted imports and `docs/source/api/field_markers.rst`
only exist on master. Every import block keeps its own order, and the
unit test drops the `FullAdmin` assertion.
- The private models live in `plugins/acme_protocol.py`,
[6 lines not shown]
NAS-144162 / 28.0.0-BETA.1 / Harden NTP (#19907)
Basically, this commit is adding support for a newer secure way of
updating time. It's a preliminary
step for some WORM-related work in S3 land where we want to basically
ensure that buckets fall
back to being RO if time de-synced or not from secure source.
- Add `nts` to system.ntpserver, rendered as chrony's `nts` option
- Without `force`, probe NTS-KE (TLS 1.3, ALPN ntske/1) and the
negotiated NTP server on save
- Cap `maxpoll` at 21 for NTS servers
- Render `authselectmode prefer` in chrony.conf
- Add system.security `require_nts` (default off), rendered as
`authselectmode require`
- With `require_nts`: refuse enabling without an NTS server, saving
servers without NTS and deleting the last NTS server
- Restart chronyd on both controllers when `require_nts` changes
- Migration: add `ntp_nts` and `require_nts`
[8 lines not shown]