- ip = dentry->d_inode;
- cr = (cred_t *)get_current_cred();
- vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
-
- error = -zfs_getattr(ip, vap, 0, cr);
- if (error)
- goto out;
-
- stat->ino = ip->i_ino;
- stat->dev = 0;
- stat->mode = vap->va_mode;
- stat->nlink = vap->va_nlink;
- stat->uid = vap->va_uid;
- stat->gid = vap->va_gid;
- stat->rdev = vap->va_rdev;
- stat->size = vap->va_size;
- stat->atime = vap->va_atime;
- stat->mtime = vap->va_mtime;
- stat->ctime = vap->va_ctime;
- stat->blksize = vap->va_blksize;
- stat->blocks = vap->va_nblocks;
-out:
- kmem_free(vap, sizeof(vattr_t));
- put_cred(cr);
+ /*
+ * Ensure MNT_SHRINKABLE is set on snapshots to ensure they are
+ * unmounted automatically with the parent file system. This
+ * is done on the first getattr because it's not easy to get the
+ * vfsmount structure at mount time. This call path is explicitly
+ * marked unlikely to avoid any performance impact. FWIW, ext4
+ * resorts to a similar trick for sysadmin convenience.
+ */
+ if (unlikely(issnap && !(mnt->mnt_flags & MNT_SHRINKABLE)))
+ mnt->mnt_flags |= MNT_SHRINKABLE;
+
+ error = -zfs_getattr_fast(dentry->d_inode, stat);