diff options
author | Brian Behlendorf <[email protected]> | 2011-11-11 12:45:53 +0530 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2012-03-22 13:03:47 -0700 |
commit | ebe7e575eae1e03b1faa545a424f008faeac589d (patch) | |
tree | 8699359f0f50019b3c2f49b46f0ff06a874c34e4 /include/sys | |
parent | 49be0ccf1fdc2ce852271d4d2f8b7a9c2c4be6db (diff) |
Add .zfs control directory
Add support for the .zfs control directory. This was accomplished
by leveraging as much of the existing ZFS infrastructure as posible
and updating it for Linux as required. The bulk of the core
functionality is now all there with the following limitations.
*) The .zfs/snapshot directory automount support requires a 2.6.37
or newer kernel. The exception is RHEL6.2 which has backported
the d_automount patches.
*) Creating/destroying/renaming snapshots with mkdir/rmdir/mv
in the .zfs/snapshot directory works as expected. However,
this functionality is only available to root until zfs
delegations are finished.
* mkdir - create a snapshot
* rmdir - destroy a snapshot
* mv - rename a snapshot
The following issues are known defeciences, but we expect them to
be addressed by future commits.
*) Add automount support for kernels older the 2.6.37. This should
be possible using follow_link() which is what Linux did before.
*) Accessing the .zfs/snapshot directory via NFS is not yet possible.
The majority of the ground work for this is complete. However,
finishing this work will require resolving some lingering
integration issues with the Linux NFS kernel server.
*) The .zfs/shares directory exists but no futher smb functionality
has yet been implemented.
Contributions-by: Rohan Puri <[email protected]>
Contributiobs-by: Andrew Barnes <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #173
Diffstat (limited to 'include/sys')
-rw-r--r-- | include/sys/Makefile.am | 1 | ||||
-rw-r--r-- | include/sys/Makefile.in | 4 | ||||
-rw-r--r-- | include/sys/dmu.h | 1 | ||||
-rw-r--r-- | include/sys/fm/Makefile.in | 1 | ||||
-rw-r--r-- | include/sys/fm/fs/Makefile.in | 1 | ||||
-rw-r--r-- | include/sys/fs/Makefile.in | 1 | ||||
-rw-r--r-- | include/sys/zfs_ctldir.h | 113 | ||||
-rw-r--r-- | include/sys/zfs_vfsops.h | 21 | ||||
-rw-r--r-- | include/sys/zfs_znode.h | 1 | ||||
-rw-r--r-- | include/sys/zpl.h | 18 |
10 files changed, 144 insertions, 18 deletions
diff --git a/include/sys/Makefile.am b/include/sys/Makefile.am index 083e1217b..651e68b0c 100644 --- a/include/sys/Makefile.am +++ b/include/sys/Makefile.am @@ -55,6 +55,7 @@ COMMON_H = \ $(top_srcdir)/include/sys/zap_leaf.h \ $(top_srcdir)/include/sys/zfs_acl.h \ $(top_srcdir)/include/sys/zfs_context.h \ + $(top_srcdir)/include/sys/zfs_ctldir.h \ $(top_srcdir)/include/sys/zfs_debug.h \ $(top_srcdir)/include/sys/zfs_dir.h \ $(top_srcdir)/include/sys/zfs_fuid.h \ diff --git a/include/sys/Makefile.in b/include/sys/Makefile.in index a2afe1422..a17957689 100644 --- a/include/sys/Makefile.in +++ b/include/sys/Makefile.in @@ -41,6 +41,7 @@ DIST_COMMON = $(am__kernel_HEADERS_DIST) $(am__libzfs_HEADERS_DIST) \ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/config/always-no-unused-but-set-variable.m4 \ + $(top_srcdir)/config/kernel-automount.m4 \ $(top_srcdir)/config/kernel-bdev-block-device-operations.m4 \ $(top_srcdir)/config/kernel-bdev-logical-size.m4 \ $(top_srcdir)/config/kernel-bdi-setup-and-register.m4 \ @@ -170,6 +171,7 @@ am__kernel_HEADERS_DIST = $(top_srcdir)/include/sys/arc.h \ $(top_srcdir)/include/sys/zap_leaf.h \ $(top_srcdir)/include/sys/zfs_acl.h \ $(top_srcdir)/include/sys/zfs_context.h \ + $(top_srcdir)/include/sys/zfs_ctldir.h \ $(top_srcdir)/include/sys/zfs_debug.h \ $(top_srcdir)/include/sys/zfs_dir.h \ $(top_srcdir)/include/sys/zfs_fuid.h \ @@ -266,6 +268,7 @@ am__libzfs_HEADERS_DIST = $(top_srcdir)/include/sys/arc.h \ $(top_srcdir)/include/sys/zap_leaf.h \ $(top_srcdir)/include/sys/zfs_acl.h \ $(top_srcdir)/include/sys/zfs_context.h \ + $(top_srcdir)/include/sys/zfs_ctldir.h \ $(top_srcdir)/include/sys/zfs_debug.h \ $(top_srcdir)/include/sys/zfs_dir.h \ $(top_srcdir)/include/sys/zfs_fuid.h \ @@ -550,6 +553,7 @@ COMMON_H = \ $(top_srcdir)/include/sys/zap_leaf.h \ $(top_srcdir)/include/sys/zfs_acl.h \ $(top_srcdir)/include/sys/zfs_context.h \ + $(top_srcdir)/include/sys/zfs_ctldir.h \ $(top_srcdir)/include/sys/zfs_debug.h \ $(top_srcdir)/include/sys/zfs_dir.h \ $(top_srcdir)/include/sys/zfs_fuid.h \ diff --git a/include/sys/dmu.h b/include/sys/dmu.h index da1aa30fc..3f9c711b9 100644 --- a/include/sys/dmu.h +++ b/include/sys/dmu.h @@ -643,6 +643,7 @@ extern uint64_t dmu_objset_syncprop(objset_t *os); extern uint64_t dmu_objset_logbias(objset_t *os); extern int dmu_snapshot_list_next(objset_t *os, int namelen, char *name, uint64_t *id, uint64_t *offp, boolean_t *case_conflict); +extern int dmu_snapshot_id(objset_t *os, const char *snapname, uint64_t *idp); extern int dmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen, boolean_t *conflict); extern int dmu_dir_list_next(objset_t *os, int namelen, char *name, diff --git a/include/sys/fm/Makefile.in b/include/sys/fm/Makefile.in index 9fe283acf..5ae85a3a0 100644 --- a/include/sys/fm/Makefile.in +++ b/include/sys/fm/Makefile.in @@ -41,6 +41,7 @@ DIST_COMMON = $(am__kernel_HEADERS_DIST) $(am__libzfs_HEADERS_DIST) \ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/config/always-no-unused-but-set-variable.m4 \ + $(top_srcdir)/config/kernel-automount.m4 \ $(top_srcdir)/config/kernel-bdev-block-device-operations.m4 \ $(top_srcdir)/config/kernel-bdev-logical-size.m4 \ $(top_srcdir)/config/kernel-bdi-setup-and-register.m4 \ diff --git a/include/sys/fm/fs/Makefile.in b/include/sys/fm/fs/Makefile.in index bc2db281f..5976245d7 100644 --- a/include/sys/fm/fs/Makefile.in +++ b/include/sys/fm/fs/Makefile.in @@ -41,6 +41,7 @@ DIST_COMMON = $(am__kernel_HEADERS_DIST) $(am__libzfs_HEADERS_DIST) \ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/config/always-no-unused-but-set-variable.m4 \ + $(top_srcdir)/config/kernel-automount.m4 \ $(top_srcdir)/config/kernel-bdev-block-device-operations.m4 \ $(top_srcdir)/config/kernel-bdev-logical-size.m4 \ $(top_srcdir)/config/kernel-bdi-setup-and-register.m4 \ diff --git a/include/sys/fs/Makefile.in b/include/sys/fs/Makefile.in index 00ed240c6..61f3125f4 100644 --- a/include/sys/fs/Makefile.in +++ b/include/sys/fs/Makefile.in @@ -41,6 +41,7 @@ DIST_COMMON = $(am__kernel_HEADERS_DIST) $(am__libzfs_HEADERS_DIST) \ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = \ $(top_srcdir)/config/always-no-unused-but-set-variable.m4 \ + $(top_srcdir)/config/kernel-automount.m4 \ $(top_srcdir)/config/kernel-bdev-block-device-operations.m4 \ $(top_srcdir)/config/kernel-bdev-logical-size.m4 \ $(top_srcdir)/config/kernel-bdi-setup-and-register.m4 \ diff --git a/include/sys/zfs_ctldir.h b/include/sys/zfs_ctldir.h new file mode 100644 index 000000000..e5985295a --- /dev/null +++ b/include/sys/zfs_ctldir.h @@ -0,0 +1,113 @@ +/* + * 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 + * or http://www.opensolaris.org/os/licensing. + * 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) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (C) 2011 Lawrence Livermore National Security, LLC. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * LLNL-CODE-403049. + * Rewritten for Linux by: + * Rohan Puri <[email protected]> + * Brian Behlendorf <[email protected]> + */ + +#ifndef _ZFS_CTLDIR_H +#define _ZFS_CTLDIR_H + +#include <sys/vnode.h> +#include <sys/zfs_vfsops.h> +#include <sys/zfs_znode.h> + +#define ZFS_CTLDIR_NAME ".zfs" +#define ZFS_SNAPDIR_NAME "snapshot" +#define ZFS_SHAREDIR_NAME "shares" + +#define zfs_has_ctldir(zdp) \ + ((zdp)->z_id == ZTOZSB(zdp)->z_root && \ + (ZTOZSB(zdp)->z_ctldir != NULL)) +#define zfs_show_ctldir(zdp) \ + (zfs_has_ctldir(zdp) && \ + (ZTOZSB(zdp)->z_show_ctldir)) + +typedef struct { + char *se_name; + char *se_path; + struct inode *se_inode; + struct delayed_work se_work; + avl_node_t se_node; +} zfs_snapentry_t; + +/* zfsctl generic functions */ +extern int snapentry_compare(const void *a, const void *b); +extern boolean_t zfsctl_is_node(struct inode *ip); +extern boolean_t zfsctl_is_snapdir(struct inode *ip); +extern void zfsctl_inode_inactive(struct inode *ip); +extern void zfsctl_inode_destroy(struct inode *ip); +extern int zfsctl_create(zfs_sb_t *zsb); +extern void zfsctl_destroy(zfs_sb_t *zsb); +extern struct inode *zfsctl_root(znode_t *zp); +extern int zfsctl_fid(struct inode *ip, fid_t *fidp); + +/* zfsctl '.zfs' functions */ +extern int zfsctl_root_lookup(struct inode *dip, char *name, + struct inode **ipp, int flags, cred_t *cr, int *direntflags, + pathname_t *realpnp); + +/* zfsctl '.zfs/snapshot' functions */ +extern int zfsctl_snapdir_lookup(struct inode *dip, char *name, + struct inode **ipp, int flags, cred_t *cr, int *direntflags, + pathname_t *realpnp); +extern int zfsctl_snapdir_rename(struct inode *sdip, char *sname, + struct inode *tdip, char *tname, cred_t *cr, int flags); +extern int zfsctl_snapdir_remove(struct inode *dip, char *name, cred_t *cr, + int flags); +extern int zfsctl_snapdir_mkdir(struct inode *dip, char *dirname, vattr_t *vap, + struct inode **ipp, cred_t *cr, int flags); +extern void zfsctl_snapdir_inactive(struct inode *ip); +extern int zfsctl_unmount_snapshot(zfs_sb_t *zsb, char *name, int flags); +extern int zfsctl_unmount_snapshots(zfs_sb_t *zsb, int flags, int *count); +extern int zfsctl_mount_snapshot(struct path *path, int flags); +extern int zfsctl_lookup_objset(struct super_block *sb, uint64_t objsetid, + zfs_sb_t **zsb); + +/* zfsctl '.zfs/shares' functions */ +extern int zfsctl_shares_lookup(struct inode *dip, char *name, + struct inode **ipp, int flags, cred_t *cr, int *direntflags, + pathname_t *realpnp); + +/* zfsctl_init/fini functions */ +extern void zfsctl_init(void); +extern void zfsctl_fini(void); + +/* + * These inodes numbers are reserved for the .zfs control directory. + * It is important that they be no larger that 48-bits because only + * 6 bytes are reserved in the NFS file handle for the object number. + * However, they should be as large as possible to avoid conflicts + * with the objects which are assigned monotonically by the dmu. + */ +#define ZFSCTL_INO_ROOT 0x0000FFFFFFFFFFFF +#define ZFSCTL_INO_SHARES 0x0000FFFFFFFFFFFE +#define ZFSCTL_INO_SNAPDIR 0x0000FFFFFFFFFFFD +#define ZFSCTL_INO_SNAPDIRS 0x0000FFFFFFFFFFFC + +#define ZFSCTL_EXPIRE_SNAPSHOT 300 + +#endif /* _ZFS_CTLDIR_H */ diff --git a/include/sys/zfs_vfsops.h b/include/sys/zfs_vfsops.h index 7b70f32ea..33ecf72fb 100644 --- a/include/sys/zfs_vfsops.h +++ b/include/sys/zfs_vfsops.h @@ -71,6 +71,8 @@ typedef struct zfs_sb { uint64_t z_nr_znodes; /* number of znodes in the fs */ kmutex_t z_znodes_lock; /* lock for z_all_znodes */ struct inode *z_ctldir; /* .zfs directory inode */ + avl_tree_t z_ctldir_snaps; /* .zfs/snapshot entries */ + kmutex_t z_ctldir_lock; /* .zfs ctldir lock */ boolean_t z_show_ctldir; /* expose .zfs in the root dir */ boolean_t z_issnap; /* true if this is a snapshot */ boolean_t z_vscan; /* virus scan on/off */ @@ -93,24 +95,6 @@ typedef struct zfs_sb { #define ZSB_XATTR 0x0001 /* Enable user xattrs */ - -/* - * Minimal snapshot helpers, the bulk of the Linux snapshot implementation - * lives in the zpl_snap.c file which is part of the zpl source. - */ -#define ZFS_CTLDIR_NAME ".zfs" - -#define zfs_has_ctldir(zdp) \ - ((zdp)->z_id == ZTOZSB(zdp)->z_root && \ - (ZTOZSB(zdp)->z_ctldir != NULL)) -#define zfs_show_ctldir(zdp) \ - (zfs_has_ctldir(zdp) && \ - (ZTOZSB(zdp)->z_show_ctldir)) - -#define ZFSCTL_INO_ROOT 0x1 -#define ZFSCTL_INO_SNAPDIR 0x2 -#define ZFSCTL_INO_SHARES 0x3 - /* * Allow a maximum number of links. While ZFS does not internally limit * this the inode->i_nlink member is defined as an unsigned int. To be @@ -195,6 +179,7 @@ extern boolean_t zfs_is_readonly(zfs_sb_t *zsb); extern int zfs_register_callbacks(zfs_sb_t *zsb); extern void zfs_unregister_callbacks(zfs_sb_t *zsb); extern int zfs_domount(struct super_block *sb, void *data, int silent); +extern void zfs_preumount(struct super_block *sb); extern int zfs_umount(struct super_block *sb); extern int zfs_remount(struct super_block *sb, int *flags, char *data); extern int zfs_root(zfs_sb_t *zsb, struct inode **ipp); diff --git a/include/sys/zfs_znode.h b/include/sys/zfs_znode.h index 6903ad4cc..8af5798ba 100644 --- a/include/sys/zfs_znode.h +++ b/include/sys/zfs_znode.h @@ -214,6 +214,7 @@ typedef struct znode { boolean_t z_is_sa; /* are we native sa? */ boolean_t z_is_zvol; /* are we used by the zvol */ boolean_t z_is_mapped; /* are we mmap'ed */ + boolean_t z_is_ctldir; /* are we .zfs entry */ struct inode z_inode; /* generic vfs inode */ } znode_t; diff --git a/include/sys/zpl.h b/include/sys/zpl.h index cfc86794e..aa4f41f97 100644 --- a/include/sys/zpl.h +++ b/include/sys/zpl.h @@ -33,6 +33,9 @@ #include <linux/falloc.h> /* zpl_inode.c */ +extern void zpl_vap_init(vattr_t *vap, struct inode *dir, + struct dentry *dentry, mode_t mode, cred_t *cr); + extern const struct inode_operations zpl_inode_operations; extern const struct inode_operations zpl_dir_inode_operations; extern const struct inode_operations zpl_symlink_inode_operations; @@ -69,4 +72,19 @@ extern int zpl_xattr_security_init(struct inode *ip, struct inode *dip, extern xattr_handler_t *zpl_xattr_handlers[]; +/* zpl_ctldir.c */ +extern const struct file_operations zpl_fops_root; +extern const struct inode_operations zpl_ops_root; + +extern const struct file_operations zpl_fops_snapdir; +extern const struct inode_operations zpl_ops_snapdir; +#ifdef HAVE_AUTOMOUNT +extern const struct dentry_operations zpl_dops_snapdirs; +#else +extern const struct inode_operations zpl_ops_snapdirs; +#endif /* HAVE_AUTOMOUNT */ + +extern const struct file_operations zpl_fops_shares; +extern const struct inode_operations zpl_ops_shares; + #endif /* _SYS_ZPL_H */ |