cachefile management
rottegift opened this issue · comments
Sean Doran commented
Cache management could really use work.
Sketch follows. Notes in square brackets:
mkdir /etc/zfs/caches
zpool create a …
zpool create b …
zpool create c …
for i in b c; do zpool set cachefile=/etc/zfs/caches/$b.cache; done
launchctl reboot
zpool import -c /etc/zfs/zpool.cache
[shows details for a b and c] [1]
zpool import -c /etc/zfs/zpool.cache a
zpool import -c /etc/zfs/zpool.cache
[no pools available to import] [2]
zpool import -c /etc/zfs/caches/b.cache b
zpool import -c /etc/zfs/caches/c.cache c
for i in b c; do zpool set cachefile=/etc/zfs/caches/$b.cache; done
launchctl reboot
[repeat ad infinitum]
Setting cachefile property creates files like /etc/zfs/b.cache.tmp that zed doesn’t rename. [3]
For [1]: when we set a pool’s cachefile property, we should clean out the previous cachefile.
For [2]: we do clean out everything from a cachefile on import, even pools other than the one we just imported.
For [3] I do the following localization:
diff --git a/cmd/zed/zed.d/config.sync.sh b/cmd/zed/zed.d/config.sync.sh
index 9716fe79f1..36e70db725 100755
--- a/cmd/zed/zed.d/config.sync.sh
+++ b/cmd/zed/zed.d/config.sync.sh
@@ -13,6 +13,41 @@ logger -t "${ZED_SYSLOG_TAG:=zed}" \
eid="${ZEVENT_EID}" class="${ZEVENT_SUBCLASS}" \
"${ZEVENT_POOL:+pool=$ZEVENT_POOL} ${CACHEFILE}"
-notify "{$CACHEFILE} file has been renamed" "config.sync"
+if [ -d /etc/zfs ]; then
+ if [ -f /etc/zfs/zpool.cache.tmp ]; then
+
+ rm -f /etc/zfs/zpool.cache
+ mv /etc/zfs/zpool.cache.tmp /etc/zfs/zpool.cache
+
+ logger -t "${ZED_SYSLOG_TAG:=zed}" -p "${ZED_SYSLOG_PRIORITY:=daemon.notice}" \
+ eid="${ZEVENT_EID}" class="${ZEVENT_SUBCLASS}" \
+ "${ZEVENT_POOL:+pool=$ZEVENT_POOL}"
+
+ notify "zpool.cache file has been renamed" "config.sync"
+
+ fi
+else
+ mkdir -p /etc/zfs
+fi
+
+if [ -d /etc/zfs/caches ]; then
+ for p in homepool Dual ssdpool Trinity Safety Quarto
+ do
+ if [ -f /etc/zfs/caches/${p}.cache.tmp ]
+ then
+ rm -f /etc/zfs/caches/${p}.cache
+ mv /etc/zfs/caches/${p}.cache.tmp /etc/zfs/caches/${p}.cache
+
+ logger -t "${ZED_SYSLOG_TAG:=zed}" -p "${ZED_SYSLOG_PRIORITY:=daemon.notice}" \
+ eid="${ZEVENT_EID}" class="${ZEVENT_SUBCLASS}" \
+ "${ZEVENT_POOL:+pool=$ZEVENT_POOL}"
+
+ notify "${i} file has been renamed" "config.sync"
+
+ fi
+ done
+else
+ mkdir -p /etc/zfs/caches
+fi
echo 0
Related: #203 #349 (generalizing above patch from just /etc/zfs/caches above would fix the latter)