zfs_ctldir.c revision cdf5b4ca0fa5ca7622b06bcb271be9e8a8245fec
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* 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.
*/
#include <sys/zfs_ctldir.h>
#include <sys/zfs_ioctl.h>
#include <sys/zfs_vfsops.h>
#include <sys/vfs_opreg.h>
typedef struct {
char *se_name;
static int
snapentry_compare(const void *a, const void *b)
{
const zfs_snapentry_t *sa = a;
const zfs_snapentry_t *sb = b;
if (ret < 0)
return (-1);
else if (ret > 0)
return (1);
else
return (0);
}
static const fs_operation_def_t zfsctl_tops_root[];
static const fs_operation_def_t zfsctl_tops_snapdir[];
static const fs_operation_def_t zfsctl_tops_snapshot[];
static gfs_opsvec_t zfsctl_opsvec[] = {
{ NULL }
};
typedef struct zfsctl_node {
typedef struct zfsctl_snapdir {
/*
* Root directory elements. We have only a single static entry, 'snapshot'.
*/
static gfs_dirent_t zfsctl_root_entries[] = {
{ NULL }
};
/* include . and .. in the calculation */
#define NROOT_ENTRIES ((sizeof (zfsctl_root_entries) / \
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)
}
/*
* Return the inode number associated with the 'snapshot' directory.
*/
/* ARGSUSED */
static ino64_t
{
return (ZFSCTL_INO_SNAPDIR);
}
/*
* 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 (EACCES);
return (0);
}
/*
* Common close routine. Nothing to do here.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* Common access routine. Disallow writes.
*/
/* ARGSUSED */
static int
{
return (EACCES);
return (0);
}
/*
* Common getattr function. Fill in basic information.
*/
static void
{
/*
* We are a purly 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);
}
static int
{
int i;
return (ENOSPC);
}
/* .zfs znodes always have a generation number of 0 */
return (0);
}
/*
* .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;
} else {
}
return (err);
}
static const fs_operation_def_t zfsctl_tops_root[] = {
{ NULL }
};
static int
{
return (ENAMETOOLONG);
return (0);
}
static int
{
int err;
return (ENOENT);
/* this will be dropped by dounmount() */
return (err);
if (err) {
return (err);
}
return (0);
}
static void
{
char newpath[MAXNAMELEN];
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
*/
}
static int
{
int err;
if (err)
return (err);
if (err)
return (err);
/*
* Cannot move snapshots out of the snapdir.
*/
return (EINVAL);
return (0);
if (err)
return (err);
return (ENOENT);
}
if (err == 0)
return (err);
}
/* ARGSUSED */
static int
{
char snapname[MAXNAMELEN];
int err;
if (err)
return (err);
if (err)
return (err);
if (err) {
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 snapname[MAXNAMELEN];
char *mountpoint;
int err;
return (0);
/*
* 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 (ENOENT);
if (err) {
/*
* The snapshot was unmounted behind our backs,
* try to remount it.
*/
goto domount;
}
return (err);
}
/*
* The requested snapshot is not currently mounted, look it up.
*/
if (err) {
return (err);
}
return (ENOENT);
}
if (err == 0) {
/*
* Return the mounted root rather than the covered mount point.
*/
}
if (err == 0) {
/*
* Fix up the root vnode.
*/
}
/*
* If we had an error, drop our hold on the vnode and
* zfsctl_snapshot_inactive() will clean up.
*/
if (err) {
}
return (err);
}
/* ARGSUSED */
static int
{
char snapname[MAXNAMELEN];
*eofp = 1;
return (0);
}
return (0);
}
vnode_t *
{
return (vp);
}
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED */
static void
{
void *private;
}
}
static const fs_operation_def_t zfsctl_tops_snapdir[] = {
{ NULL }
};
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.
*/
static const fs_operation_def_t zfsctl_tops_snapshot[] = {
};
int
{
int error;
if (error != 0)
return (error);
break;
}
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 (vn_ismntpt(svp)) {
goto out;
if (error) {
goto out;
}
/*
* We can't use VN_RELE(), as that will try to
* invoke zfsctl_snapdir_inactive(), and that
* would lead to an attempt to re-grab the sd_lock.
*/
}
}
out:
return (error);
}