Automatically Detecting Zpool Connection/Auto-Mount ZFS

All your general support questions for OpenZFS on OS X.

Automatically Detecting Zpool Connection/Auto-Mount ZFS

Postby Haravikk » Sun May 01, 2016 11:34 pm

So I have a zpool in a direct attached storage enclosure that I use as an additional backup, but since it's quite slow I only run this once a month or so when I have time to just leave it running, by turning it on, importing, running the backup then exporting again, periodically running a scrub as well to check that everything's okay.

However, I currently do this manually, whereas what I'd really like to be able to do is just flick the switch to turn the enclosure on and have it be imported then scrub/backup and export, all automatically.

I know all the commands I'd need to put into a script, but what I don't know is how to trigger it; since the volume(s) on the pool don't mount automatically I can't use launchd's OnMount option, so what are the alternatives? I'd like to avoid polling the zpool command looking for the pool to be found, though I don't mind doing that if I can at least trigger the polling to begin roughly around when the enclosure is switched on (rather than running all the time).

Does anyone know of a way to detect when a zpool becomes available (as it becomes available) to import and/or have it import automatically such that I can then run my script?
Haravikk
 
Posts: 81
Joined: Tue Mar 17, 2015 4:52 am

Re: Automatically Detecting Zpool Connection/Auto-Mount ZFS

Postby lundman » Mon May 02, 2016 12:50 am

The issue 116 branch is indeed working on this, by using the fs.bundle APPLE has for identifying filesystems and automounting them. This is not quite ready for general use though. But you could certainly cobble together something similar.

Or go with something simpler maybe, run from cron that checks diskutil list for that certain disk to appear? Maybe there are even more clever ways :)
User avatar
lundman
 
Posts: 1337
Joined: Thu Mar 06, 2014 2:05 pm
Location: Tokyo, Japan

Re: Automatically Detecting Zpool Connection/Auto-Mount ZFS

Postby Haravikk » Mon May 02, 2016 2:12 am

Sounds like a great feature!

I'm hoping to avoid polling if I can, so no cron checks if I can avoid it; I know there's an IO registry that detects and identifies connected devices, but I'm not sure if there's a way to do this programmatically to launch a script when a specific device connects. I know there's an API for it, so I could possibly write a small program to do the listening and auto-mounting for me, but it seems like overkill as it means learning how all of that works, testing it etc., so I thought I'd ask in case there's some other mechanism I'm missing.

Of course, having OS X recognise zpool volumes and try to mount them will be sweet when it's ready!
Haravikk
 
Posts: 81
Joined: Tue Mar 17, 2015 4:52 am

Re: Automatically Detecting Zpool Connection/Auto-Mount ZFS

Postby JohnP » Fri May 06, 2016 5:29 pm

Just some ideas:
A launchd item that runs a script every so often just to check diskutil for changes isn't very onerous on the system.

However, since you want to avoid polling, Control Plane http://www.controlplaneapp.com/feature-list/gives you an interface to that IO registry when a device is plugged in. It is a bit of overkill really, but you could use it to trigger your script to do the import etc.
JohnP
 
Posts: 5
Joined: Tue Sep 16, 2014 5:25 pm


Return to General Help

Who is online

Users browsing this forum: No registered users and 8 guests