Skip to content

Commit 5061f95

Browse files
authored
Retire zfs_autoimport_disable kmod option
Back in 2014 the zfs_autoimport_disable module option was added to control whether the kmods should load the pool configs from the cache file on module load. The default value since that time has been for the kernel to not process the cache file. Detecting and importing pools during boot is now controlled outside of the kmod on both Linux and FreeBSD. By all accounts this has been working well and we can remove this dormant code on the kernel side. The spa_config_load() function is has been moved to userspace, it is now only used by libzpool. Additionally, the spa_boot_init() hook which was used by FreeBSD now looks to be used and was removed. Reviewed-by: Rob Norris <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #17618
1 parent d151432 commit 5061f95

File tree

6 files changed

+85
-126
lines changed

6 files changed

+85
-126
lines changed

include/sys/spa.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,6 @@ extern kcondvar_t spa_namespace_cv;
880880
#define SPA_CONFIG_UPDATE_VDEVS 1
881881

882882
extern void spa_write_cachefile(spa_t *, boolean_t, boolean_t, boolean_t);
883-
extern void spa_config_load(void);
884883
extern int spa_all_configs(uint64_t *generation, nvlist_t **pools);
885884
extern void spa_config_set(spa_t *spa, nvlist_t *config);
886885
extern nvlist_t *spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg,
@@ -1244,7 +1243,6 @@ extern void vdev_mirror_stat_fini(void);
12441243
/* Initialization and termination */
12451244
extern void spa_init(spa_mode_t mode);
12461245
extern void spa_fini(void);
1247-
extern void spa_boot_init(void *);
12481246

12491247
/* properties */
12501248
extern int spa_prop_set(spa_t *spa, nvlist_t *nvp);

lib/libzpool/kernel.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <sys/processor.h>
3939
#include <sys/rrwlock.h>
4040
#include <sys/spa.h>
41+
#include <sys/spa_impl.h>
4142
#include <sys/stat.h>
4243
#include <sys/systeminfo.h>
4344
#include <sys/time.h>
@@ -811,6 +812,79 @@ umem_out_of_memory(void)
811812
return (0);
812813
}
813814

815+
static void
816+
spa_config_load(void)
817+
{
818+
void *buf = NULL;
819+
nvlist_t *nvlist, *child;
820+
nvpair_t *nvpair;
821+
char *pathname;
822+
zfs_file_t *fp;
823+
zfs_file_attr_t zfa;
824+
uint64_t fsize;
825+
int err;
826+
827+
/*
828+
* Open the configuration file.
829+
*/
830+
pathname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
831+
832+
(void) snprintf(pathname, MAXPATHLEN, "%s", spa_config_path);
833+
834+
err = zfs_file_open(pathname, O_RDONLY, 0, &fp);
835+
if (err)
836+
err = zfs_file_open(ZPOOL_CACHE_BOOT, O_RDONLY, 0, &fp);
837+
838+
kmem_free(pathname, MAXPATHLEN);
839+
840+
if (err)
841+
return;
842+
843+
if (zfs_file_getattr(fp, &zfa))
844+
goto out;
845+
846+
fsize = zfa.zfa_size;
847+
buf = kmem_alloc(fsize, KM_SLEEP);
848+
849+
/*
850+
* Read the nvlist from the file.
851+
*/
852+
if (zfs_file_read(fp, buf, fsize, NULL) < 0)
853+
goto out;
854+
855+
/*
856+
* Unpack the nvlist.
857+
*/
858+
if (nvlist_unpack(buf, fsize, &nvlist, KM_SLEEP) != 0)
859+
goto out;
860+
861+
/*
862+
* Iterate over all elements in the nvlist, creating a new spa_t for
863+
* each one with the specified configuration.
864+
*/
865+
mutex_enter(&spa_namespace_lock);
866+
nvpair = NULL;
867+
while ((nvpair = nvlist_next_nvpair(nvlist, nvpair)) != NULL) {
868+
if (nvpair_type(nvpair) != DATA_TYPE_NVLIST)
869+
continue;
870+
871+
child = fnvpair_value_nvlist(nvpair);
872+
873+
if (spa_lookup(nvpair_name(nvpair)) != NULL)
874+
continue;
875+
(void) spa_add(nvpair_name(nvpair), child, NULL);
876+
}
877+
mutex_exit(&spa_namespace_lock);
878+
879+
nvlist_free(nvlist);
880+
881+
out:
882+
if (buf != NULL)
883+
kmem_free(buf, fsize);
884+
885+
zfs_file_close(fp);
886+
}
887+
814888
void
815889
kernel_init(int mode)
816890
{
@@ -835,6 +909,7 @@ kernel_init(int mode)
835909
zstd_init();
836910

837911
spa_init((spa_mode_t)mode);
912+
spa_config_load();
838913

839914
fletcher_4_init();
840915

man/man4/zfs.4

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,6 @@ The target number of bytes the ARC should leave as free memory on the system.
941941
If zero, equivalent to the bigger of
942942
.Sy 512 KiB No and Sy all_system_memory/64 .
943943
.
944-
.It Sy zfs_autoimport_disable Ns = Ns Sy 1 Ns | Ns 0 Pq int
945-
Disable pool import at module load by ignoring the cache file
946-
.Pq Sy spa_config_path .
947-
.
948944
.It Sy zfs_checksum_events_per_second Ns = Ns Sy 20 Ns /s Pq uint
949945
Rate limit checksum events to this many per second.
950946
Note that this should not be set below the ZED thresholds

module/os/freebsd/zfs/kmod_core.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ static int zfs__fini(void);
112112
static void zfs_shutdown(void *, int);
113113

114114
static eventhandler_tag zfs_shutdown_event_tag;
115-
static eventhandler_tag zfs_mountroot_event_tag;
116115

117116
#define ZFS_MIN_KSTACK_PAGES 4
118117

@@ -311,9 +310,6 @@ zfs_modevent(module_t mod, int type, void *unused __unused)
311310
zfs_shutdown_event_tag = EVENTHANDLER_REGISTER(
312311
shutdown_post_sync, zfs_shutdown, NULL,
313312
SHUTDOWN_PRI_FIRST);
314-
zfs_mountroot_event_tag = EVENTHANDLER_REGISTER(
315-
mountroot, spa_boot_init, NULL,
316-
SI_ORDER_ANY);
317313
}
318314
return (err);
319315
case MOD_UNLOAD:
@@ -322,9 +318,6 @@ zfs_modevent(module_t mod, int type, void *unused __unused)
322318
if (zfs_shutdown_event_tag != NULL)
323319
EVENTHANDLER_DEREGISTER(shutdown_post_sync,
324320
zfs_shutdown_event_tag);
325-
if (zfs_mountroot_event_tag != NULL)
326-
EVENTHANDLER_DEREGISTER(mountroot,
327-
zfs_mountroot_event_tag);
328321
}
329322
return (err);
330323
case MOD_SHUTDOWN:

module/zfs/spa_config.c

Lines changed: 10 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@
4848
/*
4949
* Pool configuration repository.
5050
*
51-
* Pool configuration is stored as a packed nvlist on the filesystem. By
52-
* default, all pools are stored in /etc/zfs/zpool.cache and loaded on boot
53-
* (when the ZFS module is loaded). Pools can also have the 'cachefile'
54-
* property set that allows them to be stored in an alternate location until
55-
* the control of external software.
51+
* Pool configuration is stored as a packed nvlist on the filesystem. When
52+
* pools are imported they are added to the /etc/zfs/zpool.cache file and
53+
* removed from it when exported. For each cache file, we have a single nvlist
54+
* which holds all the configuration information. Pools can also have the
55+
* 'cachefile' property set which allows this config to be stored in an
56+
* alternate location under the control of external software.
5657
*
57-
* For each cache file, we have a single nvlist which holds all the
58-
* configuration information. When the module loads, we read this information
59-
* from /etc/zfs/zpool.cache and populate the SPA namespace. This namespace is
60-
* maintained independently in spa.c. Whenever the namespace is modified, or
61-
* the configuration of a pool is changed, we call spa_write_cachefile(), which
62-
* walks through all the active pools and writes the configuration to disk.
58+
* The kernel independantly maintains an AVL tree of imported pools. See the
59+
* "SPA locking" comment in spa.c. Whenever a pool configuration is modified
60+
* we call spa_write_cachefile() which walks through all the active pools and
61+
* writes the updated configuration to to /etc/zfs/zpool.cache file.
6362
*/
6463

6564
static uint64_t spa_config_generation = 1;
@@ -69,94 +68,6 @@ static uint64_t spa_config_generation = 1;
6968
* userland pools when doing testing.
7069
*/
7170
char *spa_config_path = (char *)ZPOOL_CACHE;
72-
#ifdef _KERNEL
73-
static int zfs_autoimport_disable = B_TRUE;
74-
#endif
75-
76-
/*
77-
* Called when the module is first loaded, this routine loads the configuration
78-
* file into the SPA namespace. It does not actually open or load the pools; it
79-
* only populates the namespace.
80-
*/
81-
void
82-
spa_config_load(void)
83-
{
84-
void *buf = NULL;
85-
nvlist_t *nvlist, *child;
86-
nvpair_t *nvpair;
87-
char *pathname;
88-
zfs_file_t *fp;
89-
zfs_file_attr_t zfa;
90-
uint64_t fsize;
91-
int err;
92-
93-
#ifdef _KERNEL
94-
if (zfs_autoimport_disable)
95-
return;
96-
#endif
97-
98-
/*
99-
* Open the configuration file.
100-
*/
101-
pathname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
102-
103-
(void) snprintf(pathname, MAXPATHLEN, "%s", spa_config_path);
104-
105-
err = zfs_file_open(pathname, O_RDONLY, 0, &fp);
106-
107-
#ifdef __FreeBSD__
108-
if (err)
109-
err = zfs_file_open(ZPOOL_CACHE_BOOT, O_RDONLY, 0, &fp);
110-
#endif
111-
kmem_free(pathname, MAXPATHLEN);
112-
113-
if (err)
114-
return;
115-
116-
if (zfs_file_getattr(fp, &zfa))
117-
goto out;
118-
119-
fsize = zfa.zfa_size;
120-
buf = kmem_alloc(fsize, KM_SLEEP);
121-
122-
/*
123-
* Read the nvlist from the file.
124-
*/
125-
if (zfs_file_read(fp, buf, fsize, NULL) < 0)
126-
goto out;
127-
128-
/*
129-
* Unpack the nvlist.
130-
*/
131-
if (nvlist_unpack(buf, fsize, &nvlist, KM_SLEEP) != 0)
132-
goto out;
133-
134-
/*
135-
* Iterate over all elements in the nvlist, creating a new spa_t for
136-
* each one with the specified configuration.
137-
*/
138-
mutex_enter(&spa_namespace_lock);
139-
nvpair = NULL;
140-
while ((nvpair = nvlist_next_nvpair(nvlist, nvpair)) != NULL) {
141-
if (nvpair_type(nvpair) != DATA_TYPE_NVLIST)
142-
continue;
143-
144-
child = fnvpair_value_nvlist(nvpair);
145-
146-
if (spa_lookup(nvpair_name(nvpair)) != NULL)
147-
continue;
148-
(void) spa_add(nvpair_name(nvpair), child, NULL);
149-
}
150-
mutex_exit(&spa_namespace_lock);
151-
152-
nvlist_free(nvlist);
153-
154-
out:
155-
if (buf != NULL)
156-
kmem_free(buf, fsize);
157-
158-
zfs_file_close(fp);
159-
}
16071

16172
static int
16273
spa_config_remove(spa_config_dirent_t *dp)
@@ -623,7 +534,6 @@ spa_config_update(spa_t *spa, int what)
623534
spa_config_update(spa, SPA_CONFIG_UPDATE_VDEVS);
624535
}
625536

626-
EXPORT_SYMBOL(spa_config_load);
627537
EXPORT_SYMBOL(spa_all_configs);
628538
EXPORT_SYMBOL(spa_config_set);
629539
EXPORT_SYMBOL(spa_config_generate);
@@ -634,8 +544,3 @@ EXPORT_SYMBOL(spa_config_update);
634544
ZFS_MODULE_PARAM(zfs_spa, spa_, config_path, STRING, ZMOD_RD,
635545
"SPA config file (/etc/zfs/zpool.cache)");
636546
#endif
637-
638-
#ifdef _KERNEL
639-
ZFS_MODULE_PARAM(zfs, zfs_, autoimport_disable, INT, ZMOD_RW,
640-
"Disable pool import at module load");
641-
#endif

module/zfs/spa_misc.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,13 +2547,6 @@ spa_name_compare(const void *a1, const void *a2)
25472547
return (TREE_ISIGN(s));
25482548
}
25492549

2550-
void
2551-
spa_boot_init(void *unused)
2552-
{
2553-
(void) unused;
2554-
spa_config_load();
2555-
}
2556-
25572550
void
25582551
spa_init(spa_mode_t mode)
25592552
{
@@ -2607,7 +2600,6 @@ spa_init(spa_mode_t mode)
26072600
chksum_init();
26082601
zpool_prop_init();
26092602
zpool_feature_init();
2610-
spa_config_load();
26112603
vdev_prop_init();
26122604
l2arc_start();
26132605
scan_init();

0 commit comments

Comments
 (0)