Page MenuHomeFreeBSD

D61844.1795298354.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61844.1795298354.diff

diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c
--- a/stand/libsa/zfs/zfs.c
+++ b/stand/libsa/zfs/zfs.c
@@ -1,6 +1,10 @@
/*-
* Copyright (c) 2007 Doug Rabson
* All rights reserved.
+ * Copyright (c) 2026 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Klara, Inc. under sponsorship
+ * from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -881,6 +885,22 @@
return (rv);
}
+/*
+ * Whether something else in the loader owns the named variable, i.e., gave it
+ * hooks of its own. We leave those alone, since we'd otherwise have to either
+ * bypass their hooks or risk leaving them half-changed if we can't store them.
+ */
+static bool
+zfs_nvstore_foreign(const char *name)
+{
+ struct env_var *ev;
+
+ if ((ev = env_getenv(name)) == NULL ||
+ ev->ev_sethook == zfs_nvstore_sethook)
+ return (false);
+ return (ev->ev_sethook != NULL || ev->ev_unsethook != NULL);
+}
+
static int
zfs_nvstore_getter(void *vdev, const char *name, void **data)
{
@@ -925,6 +945,9 @@
int rv;
bool env_set = true;
+ if (zfs_nvstore_foreign(name))
+ return (EPERM);
+
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
return (ENOTSUP);
@@ -1240,6 +1263,9 @@
nvlist_t *nv;
int rv;
+ if (zfs_nvstore_foreign(name))
+ return (EPERM);
+
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
return (ENOTSUP);
@@ -1392,6 +1418,27 @@
return (rv);
}
+/*
+ * Import a variable from the nvstore when we attach it. As when setting one,
+ * we leave alone any variable that something else in the loader owns.
+ */
+static int
+zfs_nvstore_import(void *vdev, void *ptr)
+{
+ nvp_header_t *nvh = ptr;
+ char *name;
+ bool skip;
+
+ if ((name = nvstring_get((nv_string_t *)(nvh + 1))) == NULL)
+ return (ENOMEM);
+ skip = zfs_nvstore_foreign(name);
+ free(name);
+
+ if (skip)
+ return (0);
+ return (zfs_nvstore_setenv(vdev, ptr));
+}
+
static int
zfs_nvstore_iterate(void *vdev, int (*cb)(void *, void *))
{
@@ -1463,7 +1510,7 @@
if (rv != 0)
free(dev);
else
- rv = zfs_nvstore_iterate(dev, zfs_nvstore_setenv);
+ rv = zfs_nvstore_iterate(dev, zfs_nvstore_import);
return (rv);
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 21, 9:59 PM (19 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41895565
Default Alt Text
D61844.1795298354.diff (2 KB)

Event Timeline