121 #define USE_SA(version, os) (version >= ZPL_VERSION_SA && \
122 spa_version(dmu_objset_spa(os)) >= SPA_VERSION_SA)
123
124 #define MASTER_NODE_OBJ 1
125
126 /*
127 * Special attributes for master node.
128 * "userquota@" and "groupquota@" are also valid (from
129 * zfs_userquota_prop_prefixes[]).
130 */
131 #define ZFS_FSID "FSID"
132 #define ZFS_UNLINKED_SET "DELETE_QUEUE"
133 #define ZFS_ROOT_OBJ "ROOT"
134 #define ZPL_VERSION_STR "VERSION"
135 #define ZFS_FUID_TABLES "FUID"
136 #define ZFS_SHARES_DIR "SHARES"
137 #define ZFS_SA_ATTRS "SA_ATTRS"
138
139 #define ZFS_MAX_BLOCKSIZE (SPA_MAXBLOCKSIZE)
140
141 /* Path component length */
142 /*
143 * The generic fs code uses MAXNAMELEN to represent
144 * what the largest component length is. Unfortunately,
145 * this length includes the terminating NULL. ZFS needs
146 * to tell the users via pathconf() and statvfs() what the
147 * true maximum length of a component is, excluding the NULL.
148 */
149 #define ZFS_MAXNAMELEN (MAXNAMELEN - 1)
150
151 /*
152 * Convert mode bits (zp_mode) to BSD-style DT_* values for storing in
153 * the directory entries.
154 */
155 #define IFTODT(mode) (((mode) & S_IFMT) >> 12)
156
157 /*
158 * The directory entry has the type (currently unused on Solaris) in the
159 * top 4 bits, and the object number in the low 48 bits. The "middle"
160 * 12 bits are unused.
161 */
162 #define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4)
217 * --------------------
218 * 1. When truncating a file (zfs_create, zfs_setattr, zfs_space) the whole
219 * file range needs to be locked as RL_WRITER. Only then can the pages be
220 * freed etc and zp_size reset. zp_size must be set within range lock.
221 * 2. For writes and punching holes (zfs_write & zfs_space) just the range
222 * being written or freed needs to be locked as RL_WRITER.
223 * Multiple writes at the end of the file must coordinate zp_size updates
224 * to ensure data isn't lost. A compare and swap loop is currently used
225 * to ensure the file size is at least the offset last written.
226 * 3. For reads (zfs_read, zfs_get_data & zfs_putapage) just the range being
227 * read needs to be locked as RL_READER. A check against zp_size can then
228 * be made for reading beyond end of file.
229 */
230
231 /*
232 * Convert between znode pointers and vnode pointers
233 */
234 #define ZTOV(ZP) ((ZP)->z_vnode)
235 #define VTOZ(VP) ((znode_t *)(VP)->v_data)
236
237 /*
238 * ZFS_ENTER() is called on entry to each ZFS vnode and vfs operation.
239 * ZFS_EXIT() must be called before exitting the vop.
240 * ZFS_VERIFY_ZP() verifies the znode is valid.
241 */
242 #define ZFS_ENTER(zfsvfs) \
243 { \
244 rrw_enter_read(&(zfsvfs)->z_teardown_lock, FTAG); \
245 if ((zfsvfs)->z_unmounted) { \
246 ZFS_EXIT(zfsvfs); \
247 return (EIO); \
248 } \
249 }
250
251 #define ZFS_EXIT(zfsvfs) rrw_exit(&(zfsvfs)->z_teardown_lock, FTAG)
252
253 #define ZFS_VERIFY_ZP(zp) \
254 if ((zp)->z_sa_hdl == NULL) { \
255 ZFS_EXIT((zp)->z_zfsvfs); \
256 return (EIO); \
257 } \
258
259 /*
260 * Macros for dealing with dmu_buf_hold
261 */
262 #define ZFS_OBJ_HASH(obj_num) ((obj_num) & (ZFS_OBJ_MTX_SZ - 1))
263 #define ZFS_OBJ_MUTEX(zfsvfs, obj_num) \
264 (&(zfsvfs)->z_hold_mtx[ZFS_OBJ_HASH(obj_num)])
265 #define ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num) \
266 mutex_enter(ZFS_OBJ_MUTEX((zfsvfs), (obj_num)))
267 #define ZFS_OBJ_HOLD_TRYENTER(zfsvfs, obj_num) \
268 mutex_tryenter(ZFS_OBJ_MUTEX((zfsvfs), (obj_num)))
269 #define ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num) \
270 mutex_exit(ZFS_OBJ_MUTEX((zfsvfs), (obj_num)))
271
272 /*
273 * Macros to encode/decode ZFS stored time values from/to struct timespec
274 */
275 #define ZFS_TIME_ENCODE(tp, stmp) \
276 { \
277 (stmp)[0] = (uint64_t)(tp)->tv_sec; \
278 (stmp)[1] = (uint64_t)(tp)->tv_nsec; \
279 }
280
281 #define ZFS_TIME_DECODE(tp, stmp) \
282 { \
283 (tp)->tv_sec = (time_t)(stmp)[0]; \
284 (tp)->tv_nsec = (long)(stmp)[1]; \
285 }
286
287 /*
288 * Timestamp defines
289 */
290 #define ACCESSED (AT_ATIME)
291 #define STATE_CHANGED (AT_CTIME)
292 #define CONTENT_MODIFIED (AT_MTIME | AT_CTIME)
293
294 #define ZFS_ACCESSTIME_STAMP(zfsvfs, zp) \
295 if ((zfsvfs)->z_atime && !((zfsvfs)->z_vfs->vfs_flag & VFS_RDONLY)) \
296 zfs_tstamp_update_setup(zp, ACCESSED, NULL, NULL, B_FALSE);
297
298 extern int zfs_init_fs(zfsvfs_t *, znode_t **);
299 extern void zfs_set_dataprop(objset_t *);
300 extern void zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *,
|
121 #define USE_SA(version, os) (version >= ZPL_VERSION_SA && \
122 spa_version(dmu_objset_spa(os)) >= SPA_VERSION_SA)
123
124 #define MASTER_NODE_OBJ 1
125
126 /*
127 * Special attributes for master node.
128 * "userquota@" and "groupquota@" are also valid (from
129 * zfs_userquota_prop_prefixes[]).
130 */
131 #define ZFS_FSID "FSID"
132 #define ZFS_UNLINKED_SET "DELETE_QUEUE"
133 #define ZFS_ROOT_OBJ "ROOT"
134 #define ZPL_VERSION_STR "VERSION"
135 #define ZFS_FUID_TABLES "FUID"
136 #define ZFS_SHARES_DIR "SHARES"
137 #define ZFS_SA_ATTRS "SA_ATTRS"
138
139 #define ZFS_MAX_BLOCKSIZE (SPA_MAXBLOCKSIZE)
140
141 /*
142 * Path component length
143 *
144 * The generic fs code uses MAXNAMELEN to represent
145 * what the largest component length is. Unfortunately,
146 * this length includes the terminating NULL. ZFS needs
147 * to tell the users via pathconf() and statvfs() what the
148 * true maximum length of a component is, excluding the NULL.
149 */
150 #define ZFS_MAXNAMELEN (MAXNAMELEN - 1)
151
152 /*
153 * Convert mode bits (zp_mode) to BSD-style DT_* values for storing in
154 * the directory entries.
155 */
156 #define IFTODT(mode) (((mode) & S_IFMT) >> 12)
157
158 /*
159 * The directory entry has the type (currently unused on Solaris) in the
160 * top 4 bits, and the object number in the low 48 bits. The "middle"
161 * 12 bits are unused.
162 */
163 #define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4)
218 * --------------------
219 * 1. When truncating a file (zfs_create, zfs_setattr, zfs_space) the whole
220 * file range needs to be locked as RL_WRITER. Only then can the pages be
221 * freed etc and zp_size reset. zp_size must be set within range lock.
222 * 2. For writes and punching holes (zfs_write & zfs_space) just the range
223 * being written or freed needs to be locked as RL_WRITER.
224 * Multiple writes at the end of the file must coordinate zp_size updates
225 * to ensure data isn't lost. A compare and swap loop is currently used
226 * to ensure the file size is at least the offset last written.
227 * 3. For reads (zfs_read, zfs_get_data & zfs_putapage) just the range being
228 * read needs to be locked as RL_READER. A check against zp_size can then
229 * be made for reading beyond end of file.
230 */
231
232 /*
233 * Convert between znode pointers and vnode pointers
234 */
235 #define ZTOV(ZP) ((ZP)->z_vnode)
236 #define VTOZ(VP) ((znode_t *)(VP)->v_data)
237
238 /* Called on entry to each ZFS vnode and vfs operation */
239 #define ZFS_ENTER(zfsvfs) \
240 { \
241 rrw_enter_read(&(zfsvfs)->z_teardown_lock, FTAG); \
242 if ((zfsvfs)->z_unmounted) { \
243 ZFS_EXIT(zfsvfs); \
244 return (EIO); \
245 } \
246 }
247
248 /* Must be called before exiting the vop */
249 #define ZFS_EXIT(zfsvfs) rrw_exit(&(zfsvfs)->z_teardown_lock, FTAG)
250
251 /* Verifies the znode is valid */
252 #define ZFS_VERIFY_ZP(zp) \
253 if ((zp)->z_sa_hdl == NULL) { \
254 ZFS_EXIT((zp)->z_zfsvfs); \
255 return (EIO); \
256 } \
257
258 /*
259 * Macros for dealing with dmu_buf_hold
260 */
261 #define ZFS_OBJ_HASH(obj_num) ((obj_num) & (ZFS_OBJ_MTX_SZ - 1))
262 #define ZFS_OBJ_MUTEX(zfsvfs, obj_num) \
263 (&(zfsvfs)->z_hold_mtx[ZFS_OBJ_HASH(obj_num)])
264 #define ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num) \
265 mutex_enter(ZFS_OBJ_MUTEX((zfsvfs), (obj_num)))
266 #define ZFS_OBJ_HOLD_TRYENTER(zfsvfs, obj_num) \
267 mutex_tryenter(ZFS_OBJ_MUTEX((zfsvfs), (obj_num)))
268 #define ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num) \
269 mutex_exit(ZFS_OBJ_MUTEX((zfsvfs), (obj_num)))
270
271 /* Encode ZFS stored time values from a struct timespec */
272 #define ZFS_TIME_ENCODE(tp, stmp) \
273 { \
274 (stmp)[0] = (uint64_t)(tp)->tv_sec; \
275 (stmp)[1] = (uint64_t)(tp)->tv_nsec; \
276 }
277
278 /* Decode ZFS stored time values to a struct timespec */
279 #define ZFS_TIME_DECODE(tp, stmp) \
280 { \
281 (tp)->tv_sec = (time_t)(stmp)[0]; \
282 (tp)->tv_nsec = (long)(stmp)[1]; \
283 }
284
285 /*
286 * Timestamp defines
287 */
288 #define ACCESSED (AT_ATIME)
289 #define STATE_CHANGED (AT_CTIME)
290 #define CONTENT_MODIFIED (AT_MTIME | AT_CTIME)
291
292 #define ZFS_ACCESSTIME_STAMP(zfsvfs, zp) \
293 if ((zfsvfs)->z_atime && !((zfsvfs)->z_vfs->vfs_flag & VFS_RDONLY)) \
294 zfs_tstamp_update_setup(zp, ACCESSED, NULL, NULL, B_FALSE);
295
296 extern int zfs_init_fs(zfsvfs_t *, znode_t **);
297 extern void zfs_set_dataprop(objset_t *);
298 extern void zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *,
|