1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 
  26 #ifndef _SYS_FS_ZFS_VFSOPS_H
  27 #define _SYS_FS_ZFS_VFSOPS_H
  28 
  29 #include <sys/isa_defs.h>
  30 #include <sys/types32.h>
  31 #include <sys/list.h>
  32 #include <sys/vfs.h>
  33 #include <sys/zil.h>
  34 #include <sys/sa.h>
  35 #include <sys/rrwlock.h>
  36 #include <sys/zfs_ioctl.h>
  37 
  38 #ifdef  __cplusplus
  39 extern "C" {
  40 #endif
  41 
  42 typedef struct zfsvfs zfsvfs_t;
  43 struct znode;
  44 
  45 /*
  46  * ZFS Quality of Service (QoS) I/O throttling state,
  47  * per file system.  Limits the I/O rate in this FS.
  48  * See "Token Bucket" on Wikipedia
  49  */
  50 typedef struct zfs_rate_state {
  51         uint64_t rate_cap;              /* zero means no cap */
  52         int64_t rate_token_bucket;      /* bytes I/O allowed without waiting */
  53         hrtime_t rate_last_update;
  54         kmutex_t rate_lock;
  55         kcondvar_t rate_wait_cv;
  56         int rate_waiters;
  57 } zfs_rate_state_t;
  58 
  59 /*
  60  * Status of the zfs_unlinked_drain thread.
  61  */
  62 typedef enum drain_state {
  63         ZFS_DRAIN_SHUTDOWN = 0,
  64         ZFS_DRAIN_RUNNING,
  65         ZFS_DRAIN_SHUTDOWN_REQ
  66 } drain_state_t;
  67 
  68 struct zfsvfs {
  69         vfs_t           *z_vfs;         /* generic fs struct */
  70         zfsvfs_t        *z_parent;      /* parent fs */
  71         objset_t        *z_os;          /* objset reference */
  72         uint64_t        z_root;         /* id of root znode */
  73         uint64_t        z_unlinkedobj;  /* id of unlinked zapobj */
  74         uint64_t        z_max_blksz;    /* maximum block size for files */
  75         uint64_t        z_fuid_obj;     /* fuid table object number */
  76         uint64_t        z_fuid_size;    /* fuid table size */
  77         avl_tree_t      z_fuid_idx;     /* fuid tree keyed by index */
  78         avl_tree_t      z_fuid_domain;  /* fuid tree keyed by domain */
  79         krwlock_t       z_fuid_lock;    /* fuid lock */
  80         boolean_t       z_fuid_loaded;  /* fuid tables are loaded */
  81         boolean_t       z_fuid_dirty;   /* need to sync fuid table ? */
  82         struct zfs_fuid_info    *z_fuid_replay; /* fuid info for replay */
  83         zilog_t         *z_log;         /* intent log pointer */
  84         uint_t          z_acl_mode;     /* acl chmod/mode behavior */
  85         uint_t          z_acl_inherit;  /* acl inheritance behavior */
  86         zfs_case_t      z_case;         /* case-sense */
  87         boolean_t       z_utf8;         /* utf8-only */
  88         int             z_norm;         /* normalization flags */
  89         boolean_t       z_atime;        /* enable atimes mount option */
  90         boolean_t       z_unmounted;    /* unmounted */
  91         rrmlock_t       z_teardown_lock;
  92         krwlock_t       z_teardown_inactive_lock;
  93         list_t          z_all_znodes;   /* all vnodes in the fs */
  94         kmutex_t        z_znodes_lock;  /* lock for z_all_znodes */
  95         uint_t          z_znodes_freeing_cnt; /* number of znodes to be freed */
  96         vnode_t         *z_ctldir;      /* .zfs directory pointer */
  97         boolean_t       z_show_ctldir;  /* expose .zfs in the root dir */
  98         boolean_t       z_issnap;       /* true if this is a snapshot */
  99         boolean_t       z_vscan;        /* virus scan on/off */
 100         boolean_t       z_use_fuids;    /* version allows fuids */
 101         boolean_t       z_replay;       /* set during ZIL replay */
 102         boolean_t       z_use_sa;       /* version allow system attributes */
 103         uint64_t        z_version;      /* ZPL version */
 104         uint64_t        z_shares_dir;   /* hidden shares dir */
 105         kmutex_t        z_lock;
 106         uint64_t        z_userquota_obj;
 107         uint64_t        z_groupquota_obj;
 108         uint64_t        z_replay_eof;   /* New end of file - replay only */
 109         sa_attr_type_t  *z_attr_table;  /* SA attr mapping->id */
 110         boolean_t       z_isworm;       /* true if this is a WORM FS */
 111         /* true if suspend-resume cycle is in progress */
 112         boolean_t       z_busy;
 113         int     z_hold_mtx_sz; /* the size of z_hold_mtx array */
 114         kmutex_t        *z_hold_mtx;    /* znode hold locks */
 115         /* for controlling async zfs_unlinked_drain */
 116         kmutex_t        z_drain_lock;
 117         kcondvar_t      z_drain_cv;
 118         drain_state_t   z_drain_state;
 119         zfs_rate_state_t z_rate;
 120 };
 121 
 122 /*
 123  * Normal filesystems (those not under .zfs/snapshot) have a total
 124  * file ID size limited to 12 bytes (including the length field) due to
 125  * NFSv2 protocol's limitation of 32 bytes for a filehandle.  For historical
 126  * reasons, this same limit is being imposed by the Solaris NFSv3 implementation
 127  * (although the NFSv3 protocol actually permits a maximum of 64 bytes).  It
 128  * is not possible to expand beyond 12 bytes without abandoning support
 129  * of NFSv2.
 130  *
 131  * For normal filesystems, we partition up the available space as follows:
 132  *      2 bytes         fid length (required)
 133  *      6 bytes         object number (48 bits)
 134  *      4 bytes         generation number (32 bits)
 135  *
 136  * We reserve only 48 bits for the object number, as this is the limit
 137  * currently defined and imposed by the DMU.
 138  */
 139 typedef struct zfid_short {
 140         uint16_t        zf_len;
 141         uint8_t         zf_object[6];           /* obj[i] = obj >> (8 * i) */
 142         uint8_t         zf_gen[4];              /* gen[i] = gen >> (8 * i) */
 143 } zfid_short_t;
 144 
 145 /*
 146  * Filesystems under .zfs/snapshot have a total file ID size of 22 bytes
 147  * (including the length field).  This makes files under .zfs/snapshot
 148  * accessible by NFSv3 and NFSv4, but not NFSv2.
 149  *
 150  * For files under .zfs/snapshot, we partition up the available space
 151  * as follows:
 152  *      2 bytes         fid length (required)
 153  *      6 bytes         object number (48 bits)
 154  *      4 bytes         generation number (32 bits)
 155  *      6 bytes         objset id (48 bits)
 156  *      4 bytes         currently just zero (32 bits)
 157  *
 158  * We reserve only 48 bits for the object number and objset id, as these are
 159  * the limits currently defined and imposed by the DMU.
 160  */
 161 typedef struct zfid_long {
 162         zfid_short_t    z_fid;
 163         uint8_t         zf_setid[6];            /* obj[i] = obj >> (8 * i) */
 164         uint8_t         zf_setgen[4];           /* gen[i] = gen >> (8 * i) */
 165 } zfid_long_t;
 166 
 167 #define SHORT_FID_LEN   (sizeof (zfid_short_t) - sizeof (uint16_t))
 168 #define LONG_FID_LEN    (sizeof (zfid_long_t) - sizeof (uint16_t))
 169 
 170 extern uint_t zfs_fsyncer_key;
 171 
 172 extern int zfs_suspend_fs(zfsvfs_t *zfsvfs);
 173 extern int zfs_resume_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds);
 174 extern int zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
 175     const char *domain, uint64_t rid, uint64_t *valuep);
 176 extern int zfs_userspace_many(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
 177     uint64_t *cookiep, void *vbuf, uint64_t *bufsizep);
 178 extern int zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type,
 179     const char *domain, uint64_t rid, uint64_t quota);
 180 extern boolean_t zfs_owner_overquota(zfsvfs_t *zfsvfs, struct znode *,
 181     boolean_t isgroup);
 182 extern boolean_t zfs_fuid_overquota(zfsvfs_t *zfsvfs, boolean_t isgroup,
 183     uint64_t fuid);
 184 extern int zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers);
 185 extern int zfsvfs_create(const char *name, zfsvfs_t **zfvp);
 186 extern int zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os);
 187 extern void zfsvfs_free(zfsvfs_t *zfsvfs);
 188 extern int zfs_check_global_label(const char *dsname, const char *hexsl);
 189 
 190 #ifdef  __cplusplus
 191 }
 192 #endif
 193 
 194 #endif  /* _SYS_FS_ZFS_VFSOPS_H */