ZFS and NFS

Dear @ll,

I guess I have not yet understood how ZFS and NFS interact with each other. Maybe someone here can help me.

What I did:

Code:
#> zpool create pool raidz <disk1> <disk2> <disk3>

#> zfs create pool/home
#> zfs create pool/home/<user>
#> zfs create pool/home/<user>/Documents
#> zfs set sharenfs=on pool/home

#> zfs create pool/data
#> zfs set sharenfs=on pool/data

The intention is to write the blocks of all files inside the Documents directory twice, as this directory holds business critical stuff.

I mount these directories from a Linux machine:
Code:
#> mount -t nfs 192.168.123.456:/home /home
#> mount -t nfs 192.168.123.456:/data /data

User and group permissions are set correctly, so that the server is accessed with normal user rights (no root user).

I can access all subdirectories inside /data without any problems. But when I try to access /home/<user> the directory cannot be found. What I want to know is if this is the to expected behaviour of the system? Is there a posibility to share the /home/<users> directories via the /home NFS share without any additional mounts on the client machine?

What is the difference between exporting via zfs set sharenfs=on and old fashioned /etc/exports?

Unfortunally I was not able to find a suitable documentation or forum post that answered this questions.

Best Regards
/dev/null
 
Every ZFS filesystem you want to access has to be shared separately. You can't cross ZFS filesystems via NFS.

IOW, you can't export pool/home/ and access the completely separate filesystem pool/home/<user>/ nor the completely separate filesystem pool/home/<user>/Documents/. At least, not on FreeBSD.

I believe Rick was working on a way to do this, but don't know if that's been committed yet or not. There were some threads about ZFS and NFS on -stable? over the summer.
 
Nulldevice said:
What is the difference between exporting via zfs set sharenfs=on and old fashioned /etc/exports?
Nothing really. The sharenfs option is a bit of a hack on FreeBSD. It simply adds the filesystem in question to /etc/zfs/exports.
 
First thank you for your answers.

@SirDice
If I understood you right, that will also mean that I cannot export nested filesystems at all. An it makes no difference if I put them manually into /etc/exports or if I use the sharefs facilities in zfs. Is that correct?

Does this also apply if I use NFSv4?

When using NFSv4, usually a base directory (e.g. /nfs_exports) is created and all other directories are mounted below this base directory.
On Linux this is usually done this way:


#> mount -bind /home /nfs_exports/home
#> mount -bind /data /nfs_exports/data


In this case I have some kind of nested mounts. Therefore, I guess NFSv4 should be able to export also nested ZFS filesystems.

Do you think that this could work?

Best Regards
/dev/null
 
I got it work as desired:

/etc/exports
Code:
/usr/home                  -alldirs -network 192.168.123.0 -mask 255.255.255.0
/usr/home/<user>           -alldirs -network 192.168.123.0 -mask 255.255.255.0
/usr/home/<user>/Documents -alldirs -network 192.168.123.0 -mask 255.255.255.0
V4: /usr/home                       -network 192.168.123.0 -mask 255.255.255.0

And I mounted it on the Linux box by typing [CMD=]mount -t nfs4 192.168.123.456:/ /home[/CMD].

However, thanks for the support.

Best Regards
/dev/null
 
Nulldevice said:
An it makes no difference if I put them manually into /etc/exports or if I use the sharefs facilities in zfs. Is that correct?
That is correct.
 
Nulldevice said:
I got it work as desired:

/etc/exports
Code:
/usr/home                  -alldirs -network 192.168.123.0 -mask 255.255.255.0
/usr/home/<user>           -alldirs -network 192.168.123.0 -mask 255.255.255.0
/usr/home/<user>/Documents -alldirs -network 192.168.123.0 -mask 255.255.255.0
V4: /usr/home                       -network 192.168.123.0 -mask 255.255.255.0

And I mounted it on the Linux box by typing [CMD=]mount -t nfs4 192.168.123.456:/ /home[/CMD].

However, thanks for the support.

Best Regards
/dev/null

Very interesting. How did you get NSF v4 to work? Did you just add the following line to /etc/exports?
Code:
V4: /usr/home
 
As other people have said, the sharenfs property doesn't do anything special. It just creates an entry in /etc/zfs/exports which is read by mountd. I *think* it also tells mountd to reload the exports when you change anything but I'm not 100% certain.

You should be able to do the following:

Code:
zfs set sharenfs="-alldirs -network 192.168.123.0/24" pool/home

A quick test on my own machine shows that this property is inherited by all the sub datasets so you end up with all of them added to /etc/zfs/exports automatically. It's a bit slicker than doing it all manually, ties in with the 'zfs way' of doing things and lets you change the sharenfs settings once to update all the exports. On top of that it will automatically share any new sub datasets you create (if you add one for a new user for instance).

Not sure if there's any way of creating v4 exports through the sharenfs property though. You'll probably end up putting the V4 export in /etc/exports and letting ZFS handle the contents of /etc/zfs/exports.
 
Back
Top