/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012, 2015 by Delphix. All rights reserved.
* Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
*/
/*
* ZFS control directory (a.k.a. ".zfs")
*
* This directory provides a common location for all ZFS meta-objects.
* Currently, this is only the 'snapshot' directory, but this may expand in the
* future. The elements are built using the GFS primitives, as the hierarchy
* does not actually exist on disk.
*
* For 'snapshot', we don't want to have all snapshots always mounted, because
* types of objects:
*
* ctldir ------> snapshotdir -------> snapshot
* |
* |
* V
* mounted fs
*
* The 'snapshot' node contains just enough information to lookup '..' and act
* as a mountpoint for the snapshot. Whenever we lookup a specific snapshot, we
* perform an automount of the underlying filesystem and return the
* corresponding vnode.
*
* All mounts are handled automatically by the kernel, but unmounts are
* (currently) handled from user land. The main reason is that there is no
* reliable way to auto-unmount the filesystem when it's "no longer in use".
* When the user unmounts a filesystem, we call zfsctl_unmount(), which
* unmounts any snapshots within the snapshot directory.
*
* share the same vfs_t as the head filesystem (what '.zfs' lives under).
*
* (ie: snapshots) are ZFS nodes and have their own unique vfs_t.
* However, vnodes within these mounted on file systems have their v_vfsp
* fields set to the head filesystem to make NFS happy (see
* zfsctl_snapdir_lookup()). We VFS_HOLD the head filesystem's vfs_t
* so that it cannot be freed until all snapshots have been unmounted.
*/
#include <sys/zfs_ctldir.h>
#include <sys/zfs_ioctl.h>
#include <sys/zfs_vfsops.h>
#include <sys/vfs_opreg.h>
#include <sys/dsl_destroy.h>
#include <sys/dsl_deleg.h>
#include "zfs_namecheck.h"
typedef struct zfsctl_node {
typedef struct zfsctl_snapdir {
typedef struct {
char *se_name;
static int
snapentry_compare(const void *a, const void *b)
{
if (ret < 0)
return (-1);
else if (ret > 0)
return (1);
else
return (0);
}
{ NULL }
};
/*
* Root directory elements. We only have two entries
* snapshot and shares.
*/
{ NULL }
};
/* include . and .. in the calculation */
sizeof (gfs_dirent_t)) + 1)
/*
* Initialize the various GFS pieces we'll need to create and manipulate .zfs
* directories. This is called from the ZFS init routine, and initializes the
* vnode ops vectors that we'll be using.
*/
void
zfsctl_init(void)
{
}
void
zfsctl_fini(void)
{
/*
* Remove vfsctl vnode ops
*/
if (zfsctl_ops_root)
if (zfsctl_ops_snapdir)
if (zfsctl_ops_snapshot)
if (zfsctl_ops_shares)
}
{
}
/*
* Return the inode number associated with the 'snapshot' or
* 'shares' directory.
*/
/* ARGSUSED */
static ino64_t
{
if (index == 0)
return (ZFSCTL_INO_SNAPDIR);
return (zfsvfs->z_shares_dir);
}
/*
* Create the '.zfs' directory. This directory is cached as part of the VFS
* structure. This results in a hold on the vfs_t. The code in zfs_umount()
* therefore checks against a vfs_count of 2 instead of 1. This reference
* is removed when the ctldir is destroyed in the unmount.
*/
void
{
/*
* We're only faking the fact that we have a root of a filesystem for
* the sake of the GFS interfaces. Undo the flag manipulation it did
* for us.
*/
}
/*
* Destroy the '.zfs' directory. Only called when the filesystem is unmounted.
* There might still be more references if we were force unmounted, but only
* new zfs_inactive() calls can occur and they don't reference .zfs
*/
void
{
}
/*
* Given a root znode, retrieve the associated .zfs directory.
* Add a hold to the vnode and return it.
*/
vnode_t *
{
}
/*
* Common open routine. Disallow any write access.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Common close routine. Nothing to do here.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Common access routine. Disallow writes.
*/
/* ARGSUSED */
static int
{
if (flags & V_ACE_MASK) {
if (mode & ACE_ALL_WRITE_PERMS)
} else {
}
return (0);
}
/*
* Common getattr function. Fill in basic information.
*/
static void
{
/*
* We are a purely virtual object, so we have no
* blocksize or allocated blocks.
*/
vap->va_blksize = 0;
vap->va_nblocks = 0;
/*
* We live in the now (for atime).
*/
gethrestime(&now);
}
/*ARGSUSED*/
static int
{
int i;
}
/* .zfs znodes always have a generation number of 0 */
return (0);
}
/*ARGSUSED*/
static int
{
int error;
if (zfsvfs->z_shares_dir == 0) {
}
}
return (error);
}
/*
* .zfs inode namespace
*
* We need to generate unique inode numbers for all files and directories
* within the .zfs pseudo-filesystem. We use the following scheme:
*
* ENTRY ZFSCTL_INODE
* .zfs 1
*/
/*
* Get root directory attributes.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Special case the handling of "..".
*/
/* ARGSUSED */
int
{
int err;
/*
* No extended attributes allowed under .zfs
*/
if (flags & LOOKUP_XATTR)
} else {
}
return (err);
}
static int
{
/*
* We only care about ACL_ENABLED so that libsec can
* display ACL correctly and not default to POSIX draft.
*/
if (cmd == _PC_ACL_ENABLED) {
*valp = _ACL_ACE_ENABLED;
return (0);
}
}
{ NULL }
};
/*
* Gets the full dataset name that corresponds to the given snapshot name
* Example:
*/
static int
{
return (SET_ERROR(ENAMETOOLONG));
return (0);
}
static int
{
int error;
/* this will be dropped by dounmount() */
return (error);
if (error) {
return (error);
}
/*
* We can't use VN_RELE(), as that will try to invoke
* zfsctl_snapdir_inactive(), which would cause us to destroy
* the sd_lock mutex held by our caller.
*/
return (0);
}
static void
{
char *tail;
/*
* Change the name in the AVL tree.
*/
/*
* Change the current mountpoint info:
* - update the tail of the mntpoint path
* - update the tail of the resource path
*/
}
/*ARGSUSED*/
static int
{
int err;
if (err == 0) {
return (err);
}
}
if (err == 0)
if (err == 0)
if (err != 0)
return (err);
/*
* Cannot move snapshots out of the snapdir.
*/
return (0);
}
if (err == 0)
return (err);
}
/* ARGSUSED */
static int
{
int err;
if (err == 0) {
return (err);
}
}
if (err == 0)
if (err != 0)
return (err);
if (sep) {
if (err != 0)
else
} else {
}
return (err);
}
/*
*/
/* ARGSUSED */
static int
{
int err;
if (err != 0)
return (err);
if (err == 0) {
if (err != 0)
return (err);
}
return (err);
}
/*
* Lookup entry point for the 'snapshot' directory. Try to open the
* snapshot if it exist, creating the pseudo filesystem vnode as necessary.
* Perform a mount of the associated dataset on top of the vnode.
*/
/* ARGSUSED */
static int
{
char *mountpoint;
int err;
/*
* No extended attributes allowed under .zfs
*/
if (flags & LOOKUP_XATTR)
/*
* If we get a recursive call, that means we got called
* from the domount() code while it was trying to look up the
* spec (which looks like a local path for zfs). We need to
* add some flag to domount() to tell it not to do this lookup.
*/
return (0);
}
if (flags & FIGNORECASE) {
if (err == 0) {
return (err);
}
if (realpnp)
if (conflict && direntflags)
}
if (err != 0) {
/*
* The snapshot was unmounted behind our backs,
* try to remount it.
*/
goto domount;
} else {
/*
* VROOT was set during the traverse call. We need
* to clear it since we're pretending to be part
* of our parent's vfs.
*/
}
return (err);
}
/*
* The requested snapshot is not currently mounted, look it up.
*/
if (err != 0) {
/*
* handle "ls *" or "?" in a graceful manner,
* forcing EILSEQ to ENOENT.
* Since shell ultimately passes "*" or "?" as name to lookup
*/
}
}
if (err == 0) {
/*
* Return the mounted root rather than the covered mount point.
* the ZFS vnode mounted on top of the GFS node. This ZFS
* vnode is the root of the newly created vfsp.
*/
}
if (err == 0) {
/*
*
* This is where we lie about our v_vfsp in order to
* without requiring manual mounts of <snapname>.
*/
}
/*
* If we had an error, drop our hold on the vnode and
* zfsctl_snapshot_inactive() will clean up.
*/
if (err != 0) {
}
return (err);
}
/* ARGSUSED */
static int
{
int error;
return (0);
}
if (zfsvfs->z_shares_dir == 0) {
}
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
if (error) {
*eofp = 1;
return (0);
}
return (error);
}
if (flags & V_RDDIR_ENTFLAGS) {
} else {
}
return (0);
}
/* ARGSUSED */
static int
{
int error;
if (zfsvfs->z_shares_dir == 0) {
}
} else {
*eofp = 1;
}
return (error);
}
/*
* pvp is the '.zfs' directory (zfsctl_node_t).
*
*
* when a lookup is performed on .zfs for "snapshot".
*/
vnode_t *
{
return (vp);
}
vnode_t *
{
return (vp);
}
/* ARGSUSED */
static int
{
int error;
if (zfsvfs->z_shares_dir == 0) {
}
}
return (error);
}
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED */
static void
{
void *private;
}
}
{ NULL }
};
{ NULL }
};
/*
*
* snapshot. This newly created GFS node is what we mount snapshot
* vfs_t's ontop of.
*/
static vnode_t *
{
return (vp);
}
static void
{
return;
}
break;
}
}
/*
* Dispose of the vnode for the snapshot mount point.
* This is safe to do because once this entry has been removed
* from the AVL tree, it can't be found again, so cannot become
* "active". If we lookup the same name again we will end up
* creating a new vnode.
*/
}
/*
* These VP's should never see the light of day. They should always
* be covered.
*/
};
int
{
int error;
if (error != 0)
return (error);
break;
}
/*
* Return the mounted root rather than the covered mount point.
* and returns the ZFS vnode mounted on top of the GFS node.
* This ZFS vnode is the root of the vfs for objset 'objsetid'.
*/
if (error == 0) {
else
}
} else {
}
return (error);
}
/*
* Unmount any snapshots for the given filesystem. This is called from
* zfs_umount() - if we have a ctldir, then go through and unmount all the
* snapshots.
*/
int
{
int error;
if (error != 0)
return (error);
/*
* If this snapshot is not mounted, then it must
* have just been unmounted by somebody else, and
* will be cleaned up by zfsctl_snapdir_inactive().
*/
if (error) {
break;
}
}
}
return (error);
}