Set MNT_SHRINKABLE on snapshot mount

We could set MNT_SHRINKABLE when mouting snapshot mount instead of using
occasional post mount getattr.

Signed-off-by: Andrey Vesnovaty <andrey.vesnovaty@gmail.com>
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
Fix invalid fileid for snapshot root dentry

Prevents NFS client from detection of different fileids of snapshot root dentry
before & after snapshot mount.

Signed-off-by: Andrey Vesnovaty <andrey.vesnovaty@gmail.com>
Fix readdir for .zfs/snapshot directory

dmu_snapshot_list_next stores the index of the next snapshot entry to the offp
argument, which zpl_snapdir_iterate then uses for the dir_emit. This
result in an off-by-one error. Therefore a temporary variable should be
used.

This was a regression introduced in commit zfsonlinux/zfs@0f37d0c.

Signed-off-by: Andrey Vesnovaty <andrey.vesnovaty@gmail.com>
zfsctl: No need to sync ctldir inodes

There's no metadata to write to disk for ctldir inodes. So we check if
a inode belongs to the ctldir in zpl_commit_metadata, and returns
immediately if it is.

Signed-off-by: Andrey Vesnovaty <andrey.vesnovaty@gmail.com>
Save snapshot root dentry on snapshot mount

When it's need to decode snapshot file handly it hard to get snapshot sb.
On the contrary on snapshot mount it's easy to get snapshot sb because
mount path available in the context of snapshot mount.

Signed-off-by: Andrey Vesnovaty <andrey.vesnovaty@gmail.com>
Don't encode short fh for snapshot inodes

Signed-off-by: Andrey Vesnovaty <andrey.vesnovaty@gmail.com>
Add helper function to get mount path of a dataset

This will be used in later commit which add support for decoding
snapshot fh. This is needed because in case the snapshot is not mounted
when decoding its fh, we have to trigger an automount. And to trigger a
snapshot automount, we have to know its path.

In this commit we add a helper function which get the mount path from
zpool and dataset properties (namely altroot and mountpoint
properties). This is practically the same method used by the userspace
zfs commandline tool. This method won't work for dataset with 'legacy'
mountpoint, but we have to do it this way because newer Linux
kernel hides the mount point information from file systems.

Theoretically the proper solution of the problem is to eliminate the
need to mount a snapshot, and just generate all snapshot related information
on access. However this will require a lot more work and probably
significant changes to how zfs handle snapshots. So I think we better
leave this for later.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
Add encode and decode support for snapshot fh

The snapshot file handle should provide enough info in order to get the right
objsetid and right object in the objset defined by objsetid. Therefore
we encode the snapshot fh as objsetid + inode.

The objsetid should be encoded for every snapshot dentry including root dentry;
for snapshot root dentry zf_gen should be 0.

To decode a snapshot fh, we simply extract the objsetid and the inode,
then we try to retrive the super block stored in the snapentry. Zero matching
snapentry means the snapshot is not mounted. In this case we try to
trigger a automount of the snapshot by doing a path lookup on the full
snapshot path, and then try again.

If zf_gen is 0, we return the snapshot root dentry.

Also added a configure check for kern_path, since it is not available
in earlier kernels.

Signed-off-by: Andrey Vesnovaty <andrey.vesnovaty@gmail.com>
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>