mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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 <rohan.puri15@gmail.com>
Contributiobs-by: Andrew Barnes <barnes333@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #173
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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 <rohan.puri15@gmail.com>
|
||||
* Brian Behlendorf <behlendorf1@llnl.gov>
|
||||
*/
|
||||
|
||||
#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 */
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user