FreeBSD ZFS
The Zettabyte File System
|
00001 /* 00002 * CDDL HEADER START 00003 * 00004 * The contents of this file are subject to the terms of the 00005 * Common Development and Distribution License (the "License"). 00006 * You may not use this file except in compliance with the License. 00007 * 00008 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 00009 * or http://www.opensolaris.org/os/licensing. 00010 * See the License for the specific language governing permissions 00011 * and limitations under the License. 00012 * 00013 * When distributing Covered Code, include this CDDL HEADER in each 00014 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 00015 * If applicable, add the following below this CDDL HEADER, with the 00016 * fields enclosed by brackets "[]" replaced with your own identifying 00017 * information: Portions Copyright [yyyy] [name of copyright owner] 00018 * 00019 * CDDL HEADER END 00020 */ 00021 /* 00022 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 00023 */ 00024 00025 #ifndef _SYS_FS_ZFS_ZNODE_H 00026 #define _SYS_FS_ZFS_ZNODE_H 00027 00028 #ifdef _KERNEL 00029 #include <sys/list.h> 00030 #include <sys/dmu.h> 00031 #include <sys/sa.h> 00032 #include <sys/zfs_vfsops.h> 00033 #include <sys/rrwlock.h> 00034 #include <sys/zfs_sa.h> 00035 #include <sys/zfs_stat.h> 00036 #endif 00037 #include <sys/zfs_acl.h> 00038 #include <sys/zil.h> 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00049 #define ZFS_READONLY 0x0000000100000000 00050 #define ZFS_HIDDEN 0x0000000200000000 00051 #define ZFS_SYSTEM 0x0000000400000000 00052 #define ZFS_ARCHIVE 0x0000000800000000 00053 #define ZFS_IMMUTABLE 0x0000001000000000 00054 #define ZFS_NOUNLINK 0x0000002000000000 00055 #define ZFS_APPENDONLY 0x0000004000000000 00056 #define ZFS_NODUMP 0x0000008000000000 00057 #define ZFS_OPAQUE 0x0000010000000000 00058 #define ZFS_AV_QUARANTINED 0x0000020000000000 00059 #define ZFS_AV_MODIFIED 0x0000040000000000 00060 #define ZFS_REPARSE 0x0000080000000000 00061 #define ZFS_OFFLINE 0x0000100000000000 00062 #define ZFS_SPARSE 0x0000200000000000 00063 00065 #define ZFS_ATTR_SET(zp, attr, value, pflags, tx) \ 00066 { \ 00067 if (value) \ 00068 pflags |= attr; \ 00069 else \ 00070 pflags &= ~attr; \ 00071 VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_FLAGS(zp->z_zfsvfs), \ 00072 &pflags, sizeof (pflags), tx)); \ 00073 } 00074 00079 #define ZFS_XATTR 0x1 00080 #define ZFS_INHERIT_ACE 0x2 00081 #define ZFS_ACL_TRIVIAL 0x4 00082 #define ZFS_ACL_OBJ_ACE 0x8 00083 #define ZFS_ACL_PROTECTED 0x10 00084 #define ZFS_ACL_DEFAULTED 0x20 00085 #define ZFS_ACL_AUTO_INHERIT 0x40 00086 #define ZFS_BONUS_SCANSTAMP 0x80 00087 #define ZFS_NO_EXECS_DENIED 0x100 00088 /* \} */ 00089 00090 #define SA_ZPL_ATIME(z) z->z_attr_table[ZPL_ATIME] 00091 #define SA_ZPL_MTIME(z) z->z_attr_table[ZPL_MTIME] 00092 #define SA_ZPL_CTIME(z) z->z_attr_table[ZPL_CTIME] 00093 #define SA_ZPL_CRTIME(z) z->z_attr_table[ZPL_CRTIME] 00094 #define SA_ZPL_GEN(z) z->z_attr_table[ZPL_GEN] 00095 #define SA_ZPL_DACL_ACES(z) z->z_attr_table[ZPL_DACL_ACES] 00096 #define SA_ZPL_XATTR(z) z->z_attr_table[ZPL_XATTR] 00097 #define SA_ZPL_SYMLINK(z) z->z_attr_table[ZPL_SYMLINK] 00098 #define SA_ZPL_RDEV(z) z->z_attr_table[ZPL_RDEV] 00099 #define SA_ZPL_SCANSTAMP(z) z->z_attr_table[ZPL_SCANSTAMP] 00100 #define SA_ZPL_UID(z) z->z_attr_table[ZPL_UID] 00101 #define SA_ZPL_GID(z) z->z_attr_table[ZPL_GID] 00102 #define SA_ZPL_PARENT(z) z->z_attr_table[ZPL_PARENT] 00103 #define SA_ZPL_LINKS(z) z->z_attr_table[ZPL_LINKS] 00104 #define SA_ZPL_MODE(z) z->z_attr_table[ZPL_MODE] 00105 #define SA_ZPL_DACL_COUNT(z) z->z_attr_table[ZPL_DACL_COUNT] 00106 #define SA_ZPL_FLAGS(z) z->z_attr_table[ZPL_FLAGS] 00107 #define SA_ZPL_SIZE(z) z->z_attr_table[ZPL_SIZE] 00108 #define SA_ZPL_ZNODE_ACL(z) z->z_attr_table[ZPL_ZNODE_ACL] 00109 #define SA_ZPL_PAD(z) z->z_attr_table[ZPL_PAD] 00110 00114 #define IS_EPHEMERAL(x) (x > MAXUID) 00115 00119 #define USE_FUIDS(version, os) (version >= ZPL_VERSION_FUID && \ 00120 spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID) 00121 #define USE_SA(version, os) (version >= ZPL_VERSION_SA && \ 00122 spa_version(dmu_objset_spa(os)) >= SPA_VERSION_SA) 00123 00124 #define MASTER_NODE_OBJ 1 00125 00132 #define ZFS_FSID "FSID" 00133 #define ZFS_UNLINKED_SET "DELETE_QUEUE" 00134 #define ZFS_ROOT_OBJ "ROOT" 00135 #define ZPL_VERSION_STR "VERSION" 00136 #define ZFS_FUID_TABLES "FUID" 00137 #define ZFS_SHARES_DIR "SHARES" 00138 #define ZFS_SA_ATTRS "SA_ATTRS" 00139 00140 #define ZFS_MAX_BLOCKSIZE (SPA_MAXBLOCKSIZE) 00141 00151 #define ZFS_MAXNAMELEN (MAXNAMELEN - 1) 00152 00157 #ifndef IFTODT 00158 #define IFTODT(mode) (((mode) & S_IFMT) >> 12) 00159 #endif 00160 00169 #define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4) 00170 #define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48) 00171 00173 #ifdef _KERNEL 00174 00181 typedef struct zfs_dirlock { 00182 char *dl_name; 00183 uint32_t dl_sharecnt; 00184 uint8_t dl_namelock; 00185 uint16_t dl_namesize; 00186 kcondvar_t dl_cv; 00187 struct znode *dl_dzp; 00188 struct zfs_dirlock *dl_next; 00189 } zfs_dirlock_t; 00190 00191 typedef struct znode { 00192 struct zfsvfs *z_zfsvfs; 00193 vnode_t *z_vnode; 00194 uint64_t z_id; 00195 kmutex_t z_lock; 00196 krwlock_t z_parent_lock; 00197 krwlock_t z_name_lock; 00198 zfs_dirlock_t *z_dirlocks; 00199 kmutex_t z_range_lock; 00200 avl_tree_t z_range_avl; 00201 uint8_t z_unlinked; 00202 uint8_t z_atime_dirty; 00203 uint8_t z_zn_prefetch; 00204 uint8_t z_moved; 00205 uint_t z_blksz; 00206 uint_t z_seq; 00207 uint64_t z_mapcnt; 00208 uint64_t z_gen; 00209 uint64_t z_size; 00210 uint64_t z_atime[2]; 00211 uint64_t z_links; 00212 uint64_t z_pflags; 00213 uint64_t z_uid; 00214 uint64_t z_gid; 00215 mode_t z_mode; 00216 uint32_t z_sync_cnt; 00217 kmutex_t z_acl_lock; 00218 zfs_acl_t *z_acl_cached; 00219 list_node_t z_link_node; 00220 sa_handle_t *z_sa_hdl; 00221 boolean_t z_is_sa; 00223 struct task z_task; 00224 } znode_t; 00225 00226 00244 /* 00245 * Convert between znode pointers and vnode pointers 00246 */ 00247 #ifdef DEBUG 00248 static __inline vnode_t * 00249 ZTOV(znode_t *zp) 00250 { 00251 vnode_t *vp = zp->z_vnode; 00252 00253 ASSERT(vp == NULL || vp->v_data == NULL || vp->v_data == zp); 00254 return (vp); 00255 } 00256 static __inline znode_t * 00257 VTOZ(vnode_t *vp) 00258 { 00259 znode_t *zp = (znode_t *)vp->v_data; 00260 00261 ASSERT(zp == NULL || zp->z_vnode == NULL || zp->z_vnode == vp); 00262 return (zp); 00263 } 00264 #else 00265 #define ZTOV(ZP) ((ZP)->z_vnode) 00266 #define VTOZ(VP) ((znode_t *)(VP)->v_data) 00267 #endif 00268 00270 #define ZFS_ENTER(zfsvfs) \ 00271 { \ 00272 rrw_enter(&(zfsvfs)->z_teardown_lock, RW_READER, FTAG); \ 00273 if ((zfsvfs)->z_unmounted) { \ 00274 ZFS_EXIT(zfsvfs); \ 00275 return (EIO); \ 00276 } \ 00277 } 00278 00280 #define ZFS_ENTER_NOERROR(zfsvfs) \ 00281 rrw_enter(&(zfsvfs)->z_teardown_lock, RW_READER, FTAG) 00282 00284 #define ZFS_EXIT(zfsvfs) rrw_exit(&(zfsvfs)->z_teardown_lock, FTAG) 00285 00287 #define ZFS_VERIFY_ZP(zp) \ 00288 if ((zp)->z_sa_hdl == NULL) { \ 00289 ZFS_EXIT((zp)->z_zfsvfs); \ 00290 return (EIO); \ 00291 } \ 00292 00293 00297 #define ZFS_OBJ_HASH(obj_num) ((obj_num) & (ZFS_OBJ_MTX_SZ - 1)) 00298 #define ZFS_OBJ_MUTEX(zfsvfs, obj_num) \ 00299 (&(zfsvfs)->z_hold_mtx[ZFS_OBJ_HASH(obj_num)]) 00300 #define ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num) \ 00301 mutex_enter(ZFS_OBJ_MUTEX((zfsvfs), (obj_num))) 00302 #define ZFS_OBJ_HOLD_TRYENTER(zfsvfs, obj_num) \ 00303 mutex_tryenter(ZFS_OBJ_MUTEX((zfsvfs), (obj_num))) 00304 #define ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num) \ 00305 mutex_exit(ZFS_OBJ_MUTEX((zfsvfs), (obj_num))) 00306 00311 #define ZFS_TIME_ENCODE(tp, stmp) \ 00312 { \ 00313 (stmp)[0] = (uint64_t)(tp)->tv_sec; \ 00314 (stmp)[1] = (uint64_t)(tp)->tv_nsec; \ 00315 } 00316 00320 #define ZFS_TIME_DECODE(tp, stmp) \ 00321 { \ 00322 (tp)->tv_sec = (time_t)(stmp)[0]; \ 00323 (tp)->tv_nsec = (long)(stmp)[1]; \ 00324 } 00325 00330 #define ACCESSED (AT_ATIME) 00331 #define STATE_CHANGED (AT_CTIME) 00332 #define CONTENT_MODIFIED (AT_MTIME | AT_CTIME) 00333 00335 #define ZFS_ACCESSTIME_STAMP(zfsvfs, zp) \ 00336 if ((zfsvfs)->z_atime && !((zfsvfs)->z_vfs->vfs_flag & VFS_RDONLY)) \ 00337 zfs_tstamp_update_setup(zp, ACCESSED, NULL, NULL, B_FALSE); 00338 00339 extern int zfs_init_fs(zfsvfs_t *, znode_t **); 00340 extern void zfs_set_dataprop(objset_t *); 00341 extern void zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *, 00342 dmu_tx_t *tx); 00343 extern void zfs_tstamp_update_setup(znode_t *, uint_t, uint64_t [2], 00344 uint64_t [2], boolean_t); 00345 extern void zfs_grow_blocksize(znode_t *, uint64_t, dmu_tx_t *); 00346 extern int zfs_freesp(znode_t *, uint64_t, uint64_t, int, boolean_t); 00347 extern void zfs_znode_init(void); 00348 extern void zfs_znode_fini(void); 00349 extern int zfs_zget(zfsvfs_t *, uint64_t, znode_t **); 00350 extern int zfs_rezget(znode_t *); 00351 extern void zfs_zinactive(znode_t *); 00352 extern void zfs_znode_delete(znode_t *, dmu_tx_t *); 00353 extern void zfs_znode_free(znode_t *); 00354 extern void zfs_remove_op_tables(); 00355 extern int zfs_create_op_tables(); 00356 extern dev_t zfs_cmpldev(uint64_t); 00357 extern int zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value); 00358 extern int zfs_get_stats(objset_t *os, nvlist_t *nv); 00359 extern void zfs_znode_dmu_fini(znode_t *); 00360 00361 extern void zfs_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 00362 znode_t *dzp, znode_t *zp, char *name, vsecattr_t *, zfs_fuid_info_t *, 00363 vattr_t *vap); 00364 extern int zfs_log_create_txtype(zil_create_t, vsecattr_t *vsecp, 00365 vattr_t *vap); 00366 extern void zfs_log_remove(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 00367 znode_t *dzp, char *name, uint64_t foid); 00368 #define ZFS_NO_OBJECT 0 00369 extern void zfs_log_link(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 00370 znode_t *dzp, znode_t *zp, char *name); 00371 extern void zfs_log_symlink(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 00372 znode_t *dzp, znode_t *zp, char *name, char *link); 00373 extern void zfs_log_rename(zilog_t *zilog, dmu_tx_t *tx, uint64_t txtype, 00374 znode_t *sdzp, char *sname, znode_t *tdzp, char *dname, znode_t *szp); 00375 extern void zfs_log_write(zilog_t *zilog, dmu_tx_t *tx, int txtype, 00376 znode_t *zp, offset_t off, ssize_t len, int ioflag); 00377 extern void zfs_log_truncate(zilog_t *zilog, dmu_tx_t *tx, int txtype, 00378 znode_t *zp, uint64_t off, uint64_t len); 00379 extern void zfs_log_setattr(zilog_t *zilog, dmu_tx_t *tx, int txtype, 00380 znode_t *zp, vattr_t *vap, uint_t mask_applied, zfs_fuid_info_t *fuidp); 00381 #ifndef ZFS_NO_ACL 00382 extern void zfs_log_acl(zilog_t *zilog, dmu_tx_t *tx, znode_t *zp, 00383 vsecattr_t *vsecp, zfs_fuid_info_t *fuidp); 00384 #endif 00385 extern void zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx); 00386 extern void zfs_upgrade(zfsvfs_t *zfsvfs, dmu_tx_t *tx); 00387 extern int zfs_create_share_dir(zfsvfs_t *zfsvfs, dmu_tx_t *tx); 00388 00389 extern zil_get_data_t zfs_get_data; 00390 extern zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE]; 00391 extern int zfsfstype; 00392 00393 #endif /* _KERNEL */ 00394 00395 extern int zfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len); 00396 00397 #ifdef __cplusplus 00398 } 00399 #endif 00400 00401 #endif /* _SYS_FS_ZFS_ZNODE_H */