]> git.proxmox.com Git - mirror_zfs.git/commit - module/zfs/spa.c
import: require force when cachefile hostid doesn't match on-disk
authorRob Norris <rob.norris@klarasystems.com>
Sat, 16 Sep 2023 07:02:02 +0000 (17:02 +1000)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 6 Oct 2023 16:24:44 +0000 (09:24 -0700)
commit54b1b1d893cff26417fa8042776d7865d798d765
treebfb6a1a7625530b109abb158bc1a0e0f567a1b94
parent8f5aa8cb00fb591c7dc9a91f0f2ff5b42de5f9c1
import: require force when cachefile hostid doesn't match on-disk

Previously, if a cachefile is passed to zpool import, the cached config
is mostly offered as-is to ZFS_IOC_POOL_TRYIMPORT->spa_tryimport(), and
the results are taken as the canonical pool config and handed back to
ZFS_IOC_POOL_IMPORT.

In the course of its operation, spa_load() will inspect the pool and
build a new config from what it finds on disk. However, it then
regenerates a new config ready to import, and so rightly sets the hostid
and hostname for the local host in the config it returns.

Because of this, the "require force" checks always decide the pool is
exported and last touched by the local host, even if this is not true,
which is possible in a HA environment when MMP is not enabled. The pool
may be imported on another head, but the import checks still pass here,
so the pool ends up imported on both.

(This doesn't happen when a cachefile isn't used, because the pool
config is discovered in userspace in zpool_find_import(), and that does
find the on-disk hostid and hostname correctly).

Since the systemd zfs-import-cache.service unit uses cachefile imports,
this can lead to a system returning after a crash with a "valid"
cachefile on disk and automatically, quietly, importing a pool that has
already been taken up by a secondary head.

This commit causes the on-disk hostid and hostname to be included in the
ZPOOL_CONFIG_LOAD_INFO item in the returned config, and then changes the
"force" checks for zpool import to use them if present.

This method should give no change in behaviour for old userspace on new
kernels (they won't know to look for the new config items) and for new
userspace on old kernels (the won't find the new config items).

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Closes #15290
cmd/zpool/zpool_main.c
module/zfs/spa.c
tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_hostid_changed_cachefile_unclean_export.ksh