Skip to content

Commit 91d9a5c

Browse files
asomersjsai20
authored andcommitted
Speed up "zpool import" in the presence of many zvols
By default, FreeBSD does not allow zpools to be backed by zvols (that can be changed with the "vfs.zfs.vol.recursive" sysctl). When that sysctl is set to 0, the kernel does not attempt to read zvols when looking for vdevs. But the zpool command still does. This change brings the zpool command into line with the kernel's behavior. It speeds "zpool import" when an already imported pool has many zvols, or a zvol with many snapshots. https://svnweb.freebsd.org/base?view=revision&revision=357235 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241083 https://reviews.freebsd.org/D22077 Obtained from: FreeBSD Reported by: Martin Birgmeier <[email protected]> Sponsored by: Axcient Reviewed-by: Ryan Moeller <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Alan Somers <[email protected]> Closes openzfs#11502
1 parent d29ea56 commit 91d9a5c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/libzutil/os/freebsd/zutil_import_os.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
* using our derived config, and record the results.
4343
*/
4444

45+
#include <sys/types.h>
46+
#include <sys/disk.h>
47+
#include <sys/ioctl.h>
48+
#include <sys/stat.h>
49+
#include <sys/sysctl.h>
50+
4551
#include <aio.h>
4652
#include <ctype.h>
4753
#include <dirent.h>
@@ -51,9 +57,6 @@
5157
#include <stddef.h>
5258
#include <stdlib.h>
5359
#include <string.h>
54-
#include <sys/disk.h>
55-
#include <sys/ioctl.h>
56-
#include <sys/stat.h>
5760
#include <unistd.h>
5861
#include <fcntl.h>
5962

@@ -181,15 +184,17 @@ int
181184
zpool_find_import_blkid(libpc_handle_t *hdl, pthread_mutex_t *lock,
182185
avl_tree_t **slice_cache)
183186
{
187+
const char *oid = "vfs.zfs.vol.recursive";
184188
char *end, path[MAXPATHLEN];
185189
rdsk_node_t *slice;
186190
struct gmesh mesh;
187191
struct gclass *mp;
188192
struct ggeom *gp;
189193
struct gprovider *pp;
190194
avl_index_t where;
191-
size_t pathleft;
192-
int error;
195+
int error, value;
196+
size_t pathleft, size = sizeof (value);
197+
boolean_t skip_zvols = B_FALSE;
193198

194199
end = stpcpy(path, "/dev/");
195200
pathleft = &path[sizeof (path)] - end;
@@ -198,11 +203,16 @@ zpool_find_import_blkid(libpc_handle_t *hdl, pthread_mutex_t *lock,
198203
if (error != 0)
199204
return (error);
200205

206+
if (sysctlbyname(oid, &value, &size, NULL, 0) == 0 && value == 0)
207+
skip_zvols = B_TRUE;
208+
201209
*slice_cache = zutil_alloc(hdl, sizeof (avl_tree_t));
202210
avl_create(*slice_cache, slice_cache_compare, sizeof (rdsk_node_t),
203211
offsetof(rdsk_node_t, rn_node));
204212

205213
LIST_FOREACH(mp, &mesh.lg_class, lg_class) {
214+
if (skip_zvols && strcmp(mp->lg_name, "ZFS::ZVOL") == 0)
215+
continue;
206216
LIST_FOREACH(gp, &mp->lg_geom, lg_geom) {
207217
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
208218
strlcpy(end, pp->lg_name, pathleft);

0 commit comments

Comments
 (0)