2011-11-11 07:15:53 +00:00
|
|
|
/*
|
|
|
|
* 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) 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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/zfs_vfsops.h>
|
|
|
|
#include <sys/zfs_vnops.h>
|
|
|
|
#include <sys/zfs_znode.h>
|
|
|
|
#include <sys/zfs_ctldir.h>
|
|
|
|
#include <sys/zpl.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common open routine. Disallow any write access.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
zpl_common_open(struct inode *ip, struct file *filp)
|
|
|
|
{
|
|
|
|
if (filp->f_mode & FMODE_WRITE)
|
|
|
|
return (-EACCES);
|
|
|
|
|
|
|
|
return generic_file_open(ip, filp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get root directory contents.
|
|
|
|
*/
|
|
|
|
static int
|
2013-08-07 12:53:45 +00:00
|
|
|
zpl_root_iterate(struct file *filp, struct dir_context *ctx)
|
2011-11-11 07:15:53 +00:00
|
|
|
{
|
2013-08-07 12:53:45 +00:00
|
|
|
zfs_sb_t *zsb = ITOZSB(filp->f_path.dentry->d_inode);
|
2011-11-11 07:15:53 +00:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
if (!dir_emit_dots(filp, ctx))
|
|
|
|
goto out;
|
2011-11-11 07:15:53 +00:00
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
if (ctx->pos == 2) {
|
|
|
|
if (!dir_emit(ctx, ZFS_SNAPDIR_NAME, strlen(ZFS_SNAPDIR_NAME),
|
|
|
|
ZFSCTL_INO_SNAPDIR, DT_DIR))
|
2011-11-11 07:15:53 +00:00
|
|
|
goto out;
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
ctx->pos++;
|
|
|
|
}
|
2011-11-11 07:15:53 +00:00
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
if (ctx->pos == 3) {
|
|
|
|
if (!dir_emit(ctx, ZFS_SHAREDIR_NAME, strlen(ZFS_SHAREDIR_NAME),
|
|
|
|
ZFSCTL_INO_SHARES, DT_DIR))
|
2011-11-11 07:15:53 +00:00
|
|
|
goto out;
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
ctx->pos++;
|
2011-11-11 07:15:53 +00:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
#if !defined(HAVE_VFS_ITERATE)
|
|
|
|
static int
|
|
|
|
zpl_root_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
|
|
|
{
|
|
|
|
struct dir_context ctx = DIR_CONTEXT_INIT(dirent, filldir, filp->f_pos);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = zpl_root_iterate(filp, &ctx);
|
|
|
|
filp->f_pos = ctx.pos;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_VFS_ITERATE */
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
/*
|
|
|
|
* Get root directory attributes.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
zpl_root_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
|
|
|
struct kstat *stat)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = simple_getattr(mnt, dentry, stat);
|
|
|
|
stat->atime = CURRENT_TIME;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *
|
2012-10-12 14:41:06 +00:00
|
|
|
#ifdef HAVE_LOOKUP_NAMEIDATA
|
2011-11-11 07:15:53 +00:00
|
|
|
zpl_root_lookup(struct inode *dip, struct dentry *dentry, struct nameidata *nd)
|
2012-10-12 14:41:06 +00:00
|
|
|
#else
|
|
|
|
zpl_root_lookup(struct inode *dip, struct dentry *dentry, unsigned int flags)
|
|
|
|
#endif
|
2011-11-11 07:15:53 +00:00
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
|
|
|
struct inode *ip;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
crhold(cr);
|
|
|
|
error = -zfsctl_root_lookup(dip, dname(dentry), &ip, 0, cr, NULL, NULL);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
crfree(cr);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
if (error == -ENOENT)
|
|
|
|
return d_splice_alias(NULL, dentry);
|
|
|
|
else
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return d_splice_alias(ip, dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The '.zfs' control directory file and inode operations.
|
|
|
|
*/
|
|
|
|
const struct file_operations zpl_fops_root = {
|
|
|
|
.open = zpl_common_open,
|
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read = generic_read_dir,
|
2013-08-07 12:53:45 +00:00
|
|
|
#ifdef HAVE_VFS_ITERATE
|
|
|
|
.iterate = zpl_root_iterate,
|
|
|
|
#else
|
2011-11-11 07:15:53 +00:00
|
|
|
.readdir = zpl_root_readdir,
|
2013-08-07 12:53:45 +00:00
|
|
|
#endif
|
2011-11-11 07:15:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct inode_operations zpl_ops_root = {
|
|
|
|
.lookup = zpl_root_lookup,
|
|
|
|
.getattr = zpl_root_getattr,
|
|
|
|
};
|
|
|
|
|
2013-01-14 21:59:14 +00:00
|
|
|
#ifdef HAVE_AUTOMOUNT
|
|
|
|
static struct vfsmount *
|
|
|
|
zpl_snapdir_automount(struct path *path)
|
|
|
|
{
|
|
|
|
struct dentry *dentry = path->dentry;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must briefly disable automounts for this dentry because the
|
|
|
|
* user space mount utility will trigger another lookup on this
|
|
|
|
* directory. That will result in zpl_snapdir_automount() being
|
|
|
|
* called repeatedly. The DCACHE_NEED_AUTOMOUNT flag can be
|
|
|
|
* safely reset once the mount completes.
|
|
|
|
*/
|
|
|
|
dentry->d_flags &= ~DCACHE_NEED_AUTOMOUNT;
|
|
|
|
error = -zfsctl_mount_snapshot(path, 0);
|
|
|
|
dentry->d_flags |= DCACHE_NEED_AUTOMOUNT;
|
|
|
|
if (error)
|
|
|
|
return ERR_PTR(error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rather than returning the new vfsmount for the snapshot we must
|
|
|
|
* return NULL to indicate a mount collision. This is done because
|
|
|
|
* the user space mount calls do_add_mount() which adds the vfsmount
|
|
|
|
* to the name space. If we returned the new mount here it would be
|
|
|
|
* added again to the vfsmount list resulting in list corruption.
|
|
|
|
*/
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_AUTOMOUNT */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Revalidate any dentry in the snapshot directory on lookup, since a snapshot
|
|
|
|
* having the same name have been created or destroyed since it was cached.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
#ifdef HAVE_D_REVALIDATE_NAMEIDATA
|
|
|
|
zpl_snapdir_revalidate(struct dentry *dentry, struct nameidata *i)
|
|
|
|
#else
|
|
|
|
zpl_snapdir_revalidate(struct dentry *dentry, unsigned int flags)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dentry_operations_t zpl_dops_snapdirs = {
|
|
|
|
/*
|
|
|
|
* Auto mounting of snapshots is only supported for 2.6.37 and
|
|
|
|
* newer kernels. Prior to this kernel the ops->follow_link()
|
|
|
|
* callback was used as a hack to trigger the mount. The
|
|
|
|
* resulting vfsmount was then explicitly grafted in to the
|
|
|
|
* name space. While it might be possible to add compatibility
|
|
|
|
* code to accomplish this it would require considerable care.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_AUTOMOUNT
|
|
|
|
.d_automount = zpl_snapdir_automount,
|
|
|
|
#endif /* HAVE_AUTOMOUNT */
|
|
|
|
.d_revalidate = zpl_snapdir_revalidate,
|
|
|
|
};
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
static struct dentry *
|
2012-10-12 14:41:06 +00:00
|
|
|
#ifdef HAVE_LOOKUP_NAMEIDATA
|
2011-11-11 07:15:53 +00:00
|
|
|
zpl_snapdir_lookup(struct inode *dip, struct dentry *dentry,
|
|
|
|
struct nameidata *nd)
|
2012-10-12 14:41:06 +00:00
|
|
|
#else
|
|
|
|
zpl_snapdir_lookup(struct inode *dip, struct dentry *dentry,
|
|
|
|
unsigned int flags)
|
|
|
|
#endif
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
2013-01-14 21:59:14 +00:00
|
|
|
struct inode *ip = NULL;
|
2011-11-11 07:15:53 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
crhold(cr);
|
|
|
|
error = -zfsctl_snapdir_lookup(dip, dname(dentry), &ip,
|
|
|
|
0, cr, NULL, NULL);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
crfree(cr);
|
|
|
|
|
2013-01-14 21:59:14 +00:00
|
|
|
if (error && error != -ENOENT)
|
|
|
|
return ERR_PTR(error);
|
2011-11-11 07:15:53 +00:00
|
|
|
|
2013-01-14 21:59:14 +00:00
|
|
|
ASSERT(error == 0 || ip == NULL);
|
2013-01-23 00:14:43 +00:00
|
|
|
d_clear_d_op(dentry);
|
2013-01-14 21:59:14 +00:00
|
|
|
d_set_d_op(dentry, &zpl_dops_snapdirs);
|
2011-11-11 07:15:53 +00:00
|
|
|
|
|
|
|
return d_splice_alias(ip, dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-08-07 12:53:45 +00:00
|
|
|
zpl_snapdir_iterate(struct file *filp, struct dir_context *ctx)
|
2011-11-11 07:15:53 +00:00
|
|
|
{
|
2013-08-07 12:53:45 +00:00
|
|
|
zfs_sb_t *zsb = ITOZSB(filp->f_path.dentry->d_inode);
|
2011-11-11 07:15:53 +00:00
|
|
|
char snapname[MAXNAMELEN];
|
|
|
|
boolean_t case_conflict;
|
2013-08-07 12:53:45 +00:00
|
|
|
uint64_t id;
|
2011-11-11 07:15:53 +00:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
if (!dir_emit_dots(filp, ctx))
|
|
|
|
goto out;
|
2011-11-11 07:15:53 +00:00
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
while (error == 0) {
|
2013-10-12 22:33:28 +00:00
|
|
|
dsl_pool_config_enter(dmu_objset_pool(zsb->z_os), FTAG);
|
2013-08-07 12:53:45 +00:00
|
|
|
error = -dmu_snapshot_list_next(zsb->z_os, MAXNAMELEN,
|
2013-10-12 22:33:28 +00:00
|
|
|
snapname, &id, &ctx->pos, &case_conflict);
|
|
|
|
dsl_pool_config_exit(dmu_objset_pool(zsb->z_os), FTAG);
|
2011-11-11 07:15:53 +00:00
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
if (!dir_emit(ctx, snapname, strlen(snapname),
|
|
|
|
ZFSCTL_INO_SHARES - id, DT_DIR))
|
|
|
|
goto out;
|
2011-11-11 07:15:53 +00:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
|
|
|
|
if (error == -ENOENT)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
#if !defined(HAVE_VFS_ITERATE)
|
|
|
|
static int
|
|
|
|
zpl_snapdir_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
|
|
|
{
|
|
|
|
struct dir_context ctx = DIR_CONTEXT_INIT(dirent, filldir, filp->f_pos);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = zpl_snapdir_iterate(filp, &ctx);
|
|
|
|
filp->f_pos = ctx.pos;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_VFS_ITERATE */
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
int
|
|
|
|
zpl_snapdir_rename(struct inode *sdip, struct dentry *sdentry,
|
|
|
|
struct inode *tdip, struct dentry *tdentry)
|
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
|
|
|
int error;
|
|
|
|
|
|
|
|
crhold(cr);
|
|
|
|
error = -zfsctl_snapdir_rename(sdip, dname(sdentry),
|
|
|
|
tdip, dname(tdentry), cr, 0);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
crfree(cr);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zpl_snapdir_rmdir(struct inode *dip, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
|
|
|
int error;
|
|
|
|
|
|
|
|
crhold(cr);
|
|
|
|
error = -zfsctl_snapdir_remove(dip, dname(dentry), cr, 0);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
crfree(cr);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-04-30 19:01:49 +00:00
|
|
|
zpl_snapdir_mkdir(struct inode *dip, struct dentry *dentry, zpl_umode_t mode)
|
2011-11-11 07:15:53 +00:00
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
|
|
|
vattr_t *vap;
|
|
|
|
struct inode *ip;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
crhold(cr);
|
|
|
|
vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
|
2013-01-16 00:41:09 +00:00
|
|
|
zpl_vap_init(vap, dip, mode | S_IFDIR, cr);
|
2011-11-11 07:15:53 +00:00
|
|
|
|
|
|
|
error = -zfsctl_snapdir_mkdir(dip, dname(dentry), vap, &ip, cr, 0);
|
|
|
|
if (error == 0) {
|
2013-01-23 00:14:43 +00:00
|
|
|
d_clear_d_op(dentry);
|
2013-01-14 21:59:14 +00:00
|
|
|
d_set_d_op(dentry, &zpl_dops_snapdirs);
|
2011-11-11 07:15:53 +00:00
|
|
|
d_instantiate(dentry, ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
kmem_free(vap, sizeof(vattr_t));
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
crfree(cr);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get snapshot directory attributes.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
zpl_snapdir_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
|
|
|
struct kstat *stat)
|
|
|
|
{
|
|
|
|
zfs_sb_t *zsb = ITOZSB(dentry->d_inode);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
error = simple_getattr(mnt, dentry, stat);
|
|
|
|
stat->nlink = stat->size = avl_numnodes(&zsb->z_ctldir_snaps) + 2;
|
|
|
|
stat->ctime = stat->mtime = dmu_objset_snap_cmtime(zsb->z_os);
|
|
|
|
stat->atime = CURRENT_TIME;
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The '.zfs/snapshot' directory file operations. These mainly control
|
|
|
|
* generating the list of available snapshots when doing an 'ls' in the
|
|
|
|
* directory. See zpl_snapdir_readdir().
|
|
|
|
*/
|
|
|
|
const struct file_operations zpl_fops_snapdir = {
|
|
|
|
.open = zpl_common_open,
|
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read = generic_read_dir,
|
2013-08-07 12:53:45 +00:00
|
|
|
#ifdef HAVE_VFS_ITERATE
|
|
|
|
.iterate = zpl_snapdir_iterate,
|
|
|
|
#else
|
2011-11-11 07:15:53 +00:00
|
|
|
.readdir = zpl_snapdir_readdir,
|
2013-08-07 12:53:45 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The '.zfs/snapshot' directory inode operations. These mainly control
|
|
|
|
* creating an inode for a snapshot directory and initializing the needed
|
|
|
|
* infrastructure to automount the snapshot. See zpl_snapdir_lookup().
|
|
|
|
*/
|
|
|
|
const struct inode_operations zpl_ops_snapdir = {
|
|
|
|
.lookup = zpl_snapdir_lookup,
|
|
|
|
.getattr = zpl_snapdir_getattr,
|
|
|
|
.rename = zpl_snapdir_rename,
|
|
|
|
.rmdir = zpl_snapdir_rmdir,
|
|
|
|
.mkdir = zpl_snapdir_mkdir,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct dentry *
|
2012-10-12 14:41:06 +00:00
|
|
|
#ifdef HAVE_LOOKUP_NAMEIDATA
|
2011-11-11 07:15:53 +00:00
|
|
|
zpl_shares_lookup(struct inode *dip, struct dentry *dentry,
|
|
|
|
struct nameidata *nd)
|
2012-10-12 14:41:06 +00:00
|
|
|
#else
|
|
|
|
zpl_shares_lookup(struct inode *dip, struct dentry *dentry,
|
|
|
|
unsigned int flags)
|
|
|
|
#endif
|
2011-11-11 07:15:53 +00:00
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
|
|
|
struct inode *ip = NULL;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
crhold(cr);
|
|
|
|
error = -zfsctl_shares_lookup(dip, dname(dentry), &ip,
|
|
|
|
0, cr, NULL, NULL);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
crfree(cr);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
if (error == -ENOENT)
|
|
|
|
return d_splice_alias(NULL, dentry);
|
|
|
|
else
|
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return d_splice_alias(ip, dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-08-07 12:53:45 +00:00
|
|
|
zpl_shares_iterate(struct file *filp, struct dir_context *ctx)
|
2011-11-11 07:15:53 +00:00
|
|
|
{
|
|
|
|
cred_t *cr = CRED();
|
2013-08-07 12:53:45 +00:00
|
|
|
zfs_sb_t *zsb = ITOZSB(filp->f_path.dentry->d_inode);
|
2011-11-11 07:15:53 +00:00
|
|
|
znode_t *dzp;
|
2013-08-07 12:53:45 +00:00
|
|
|
int error = 0;
|
2011-11-11 07:15:53 +00:00
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
|
|
|
|
if (zsb->z_shares_dir == 0) {
|
2013-08-07 12:53:45 +00:00
|
|
|
dir_emit_dots(filp, ctx);
|
|
|
|
goto out;
|
2011-11-11 07:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error = -zfs_zget(zsb, zsb->z_shares_dir, &dzp);
|
2013-08-07 12:53:45 +00:00
|
|
|
if (error)
|
|
|
|
goto out;
|
2011-11-11 07:15:53 +00:00
|
|
|
|
|
|
|
crhold(cr);
|
2013-08-07 12:53:45 +00:00
|
|
|
error = -zfs_readdir(ZTOI(dzp), ctx, cr);
|
2011-11-11 07:15:53 +00:00
|
|
|
crfree(cr);
|
|
|
|
|
|
|
|
iput(ZTOI(dzp));
|
2013-08-07 12:53:45 +00:00
|
|
|
out:
|
2011-11-11 07:15:53 +00:00
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2013-08-07 12:53:45 +00:00
|
|
|
#if !defined(HAVE_VFS_ITERATE)
|
|
|
|
static int
|
|
|
|
zpl_shares_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
|
|
|
{
|
|
|
|
struct dir_context ctx = DIR_CONTEXT_INIT(dirent, filldir, filp->f_pos);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = zpl_shares_iterate(filp, &ctx);
|
|
|
|
filp->f_pos = ctx.pos;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_VFS_ITERATE */
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
zpl_shares_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
|
|
|
struct kstat *stat)
|
|
|
|
{
|
|
|
|
struct inode *ip = dentry->d_inode;
|
|
|
|
zfs_sb_t *zsb = ITOZSB(ip);
|
|
|
|
znode_t *dzp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ZFS_ENTER(zsb);
|
|
|
|
|
|
|
|
if (zsb->z_shares_dir == 0) {
|
|
|
|
error = simple_getattr(mnt, dentry, stat);
|
|
|
|
stat->nlink = stat->size = 2;
|
|
|
|
stat->atime = CURRENT_TIME;
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = -zfs_zget(zsb, zsb->z_shares_dir, &dzp);
|
2013-12-04 21:50:34 +00:00
|
|
|
if (error == 0) {
|
|
|
|
error = -zfs_getattr_fast(ZTOI(dzp), stat);
|
|
|
|
iput(ZTOI(dzp));
|
|
|
|
}
|
2011-11-11 07:15:53 +00:00
|
|
|
|
|
|
|
ZFS_EXIT(zsb);
|
|
|
|
ASSERT3S(error, <=, 0);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The '.zfs/shares' directory file operations.
|
|
|
|
*/
|
|
|
|
const struct file_operations zpl_fops_shares = {
|
|
|
|
.open = zpl_common_open,
|
|
|
|
.llseek = generic_file_llseek,
|
|
|
|
.read = generic_read_dir,
|
2013-08-07 12:53:45 +00:00
|
|
|
#ifdef HAVE_VFS_ITERATE
|
|
|
|
.iterate = zpl_shares_iterate,
|
|
|
|
#else
|
2011-11-11 07:15:53 +00:00
|
|
|
.readdir = zpl_shares_readdir,
|
2013-08-07 12:53:45 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-11 07:15:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The '.zfs/shares' directory inode operations.
|
|
|
|
*/
|
|
|
|
const struct inode_operations zpl_ops_shares = {
|
|
|
|
.lookup = zpl_shares_lookup,
|
|
|
|
.getattr = zpl_shares_getattr,
|
|
|
|
};
|