xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/dmu_objset.h (revision 13043:8c712bbb18ea)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51544Seschrock  * Common Development and Distribution License (the "License").
61544Seschrock  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
21789Sahrens /*
2212178SMark.Shellenbaum@Sun.COM  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23789Sahrens  */
24789Sahrens 
2512294SMark.Musante@Sun.COM /* Portions Copyright 2010 Robert Milkowski */
2612294SMark.Musante@Sun.COM 
27789Sahrens #ifndef	_SYS_DMU_OBJSET_H
28789Sahrens #define	_SYS_DMU_OBJSET_H
29789Sahrens 
30789Sahrens #include <sys/spa.h>
313547Smaybee #include <sys/arc.h>
32789Sahrens #include <sys/txg.h>
33789Sahrens #include <sys/zfs_context.h>
34789Sahrens #include <sys/dnode.h>
35789Sahrens #include <sys/zio.h>
36789Sahrens #include <sys/zil.h>
3711935SMark.Shellenbaum@Sun.COM #include <sys/sa.h>
38789Sahrens 
39789Sahrens #ifdef	__cplusplus
40789Sahrens extern "C" {
41789Sahrens #endif
42789Sahrens 
4312684STom.Erickson@Sun.COM extern krwlock_t os_lock;
4412684STom.Erickson@Sun.COM 
45789Sahrens struct dsl_dataset;
46789Sahrens struct dmu_tx;
47789Sahrens 
489396SMatthew.Ahrens@Sun.COM #define	OBJSET_PHYS_SIZE 2048
499396SMatthew.Ahrens@Sun.COM #define	OBJSET_OLD_PHYS_SIZE 1024
509396SMatthew.Ahrens@Sun.COM 
5112296SLin.Ling@Sun.COM #define	OBJSET_BUF_HAS_USERUSED(buf) \
5212296SLin.Ling@Sun.COM 	(arc_buf_size(buf) > OBJSET_OLD_PHYS_SIZE)
5312296SLin.Ling@Sun.COM 
549396SMatthew.Ahrens@Sun.COM #define	OBJSET_FLAG_USERACCOUNTING_COMPLETE	(1ULL<<0)
559396SMatthew.Ahrens@Sun.COM 
56789Sahrens typedef struct objset_phys {
57789Sahrens 	dnode_phys_t os_meta_dnode;
58789Sahrens 	zil_header_t os_zil_header;
59789Sahrens 	uint64_t os_type;
609396SMatthew.Ahrens@Sun.COM 	uint64_t os_flags;
619396SMatthew.Ahrens@Sun.COM 	char os_pad[OBJSET_PHYS_SIZE - sizeof (dnode_phys_t)*3 -
629396SMatthew.Ahrens@Sun.COM 	    sizeof (zil_header_t) - sizeof (uint64_t)*2];
639396SMatthew.Ahrens@Sun.COM 	dnode_phys_t os_userused_dnode;
649396SMatthew.Ahrens@Sun.COM 	dnode_phys_t os_groupused_dnode;
65789Sahrens } objset_phys_t;
66789Sahrens 
67789Sahrens struct objset {
68789Sahrens 	/* Immutable: */
69789Sahrens 	struct dsl_dataset *os_dsl_dataset;
70789Sahrens 	spa_t *os_spa;
713547Smaybee 	arc_buf_t *os_phys_buf;
72789Sahrens 	objset_phys_t *os_phys;
7312684STom.Erickson@Sun.COM 	/*
7412684STom.Erickson@Sun.COM 	 * The following "special" dnodes have no parent and are exempt from
7512684STom.Erickson@Sun.COM 	 * dnode_move(), but they root their descendents in this objset using
7612684STom.Erickson@Sun.COM 	 * handles anyway, so that all access to dnodes from dbufs consistently
7712684STom.Erickson@Sun.COM 	 * uses handles.
7812684STom.Erickson@Sun.COM 	 */
7912684STom.Erickson@Sun.COM 	dnode_handle_t os_meta_dnode;
8012684STom.Erickson@Sun.COM 	dnode_handle_t os_userused_dnode;
8112684STom.Erickson@Sun.COM 	dnode_handle_t os_groupused_dnode;
82789Sahrens 	zilog_t *os_zil;
8310922SJeff.Bonwick@Sun.COM 
8410922SJeff.Bonwick@Sun.COM 	/* can change, under dsl_dir's locks: */
8510922SJeff.Bonwick@Sun.COM 	uint8_t os_checksum;
8610922SJeff.Bonwick@Sun.COM 	uint8_t os_compress;
8710922SJeff.Bonwick@Sun.COM 	uint8_t os_copies;
8810922SJeff.Bonwick@Sun.COM 	uint8_t os_dedup_checksum;
8910922SJeff.Bonwick@Sun.COM 	uint8_t os_dedup_verify;
9010922SJeff.Bonwick@Sun.COM 	uint8_t os_logbias;
9110922SJeff.Bonwick@Sun.COM 	uint8_t os_primary_cache;
9210922SJeff.Bonwick@Sun.COM 	uint8_t os_secondary_cache;
9312294SMark.Musante@Sun.COM 	uint8_t os_sync;
94789Sahrens 
95789Sahrens 	/* no lock needed: */
96789Sahrens 	struct dmu_tx *os_synctx; /* XXX sketchy */
973547Smaybee 	blkptr_t *os_rootbp;
987046Sahrens 	zil_header_t os_zil_header;
999396SMatthew.Ahrens@Sun.COM 	list_t os_synced_dnodes;
1009396SMatthew.Ahrens@Sun.COM 	uint64_t os_flags;
101789Sahrens 
102789Sahrens 	/* Protected by os_obj_lock */
103789Sahrens 	kmutex_t os_obj_lock;
104789Sahrens 	uint64_t os_obj_next;
105789Sahrens 
106789Sahrens 	/* Protected by os_lock */
107789Sahrens 	kmutex_t os_lock;
108789Sahrens 	list_t os_dirty_dnodes[TXG_SIZE];
109789Sahrens 	list_t os_free_dnodes[TXG_SIZE];
110789Sahrens 	list_t os_dnodes;
111789Sahrens 	list_t os_downgraded_dbufs;
1125326Sek110237 
1135326Sek110237 	/* stuff we store for the user */
1145326Sek110237 	kmutex_t os_user_ptr_lock;
1155326Sek110237 	void *os_user_ptr;
11611935SMark.Shellenbaum@Sun.COM 
11711935SMark.Shellenbaum@Sun.COM 	/* SA layout/attribute registration */
11811935SMark.Shellenbaum@Sun.COM 	sa_os_t *os_sa;
11910298SMatthew.Ahrens@Sun.COM };
120789Sahrens 
12110922SJeff.Bonwick@Sun.COM #define	DMU_META_OBJSET		0
1221544Seschrock #define	DMU_META_DNODE_OBJECT	0
1239396SMatthew.Ahrens@Sun.COM #define	DMU_OBJECT_IS_SPECIAL(obj) ((int64_t)(obj) <= 0)
12412684STom.Erickson@Sun.COM #define	DMU_META_DNODE(os)	((os)->os_meta_dnode.dnh_dnode)
12512684STom.Erickson@Sun.COM #define	DMU_USERUSED_DNODE(os)	((os)->os_userused_dnode.dnh_dnode)
12612684STom.Erickson@Sun.COM #define	DMU_GROUPUSED_DNODE(os)	((os)->os_groupused_dnode.dnh_dnode)
127789Sahrens 
1287237Sek110237 #define	DMU_OS_IS_L2CACHEABLE(os)				\
1297237Sek110237 	((os)->os_secondary_cache == ZFS_CACHE_ALL ||		\
1307237Sek110237 	(os)->os_secondary_cache == ZFS_CACHE_METADATA)
1317237Sek110237 
132789Sahrens /* called from zpl */
13310298SMatthew.Ahrens@Sun.COM int dmu_objset_hold(const char *name, void *tag, objset_t **osp);
13410298SMatthew.Ahrens@Sun.COM int dmu_objset_own(const char *name, dmu_objset_type_t type,
13510298SMatthew.Ahrens@Sun.COM     boolean_t readonly, void *tag, objset_t **osp);
13610298SMatthew.Ahrens@Sun.COM void dmu_objset_rele(objset_t *os, void *tag);
13710298SMatthew.Ahrens@Sun.COM void dmu_objset_disown(objset_t *os, void *tag);
13810298SMatthew.Ahrens@Sun.COM int dmu_objset_from_ds(struct dsl_dataset *ds, objset_t **osp);
13910298SMatthew.Ahrens@Sun.COM 
14010272SMatthew.Ahrens@Sun.COM int dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
1414543Smarks     void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg);
14210272SMatthew.Ahrens@Sun.COM int dmu_objset_clone(const char *name, struct dsl_dataset *clone_origin,
14310272SMatthew.Ahrens@Sun.COM     uint64_t flags);
14410242Schris.kirby@sun.com int dmu_objset_destroy(const char *name, boolean_t defer);
145*13043STim.Haley@Sun.COM int dmu_objset_snapshot(char *fsname, char *snapname, char *tag,
146*13043STim.Haley@Sun.COM     struct nvlist *props, boolean_t recursive, boolean_t temporary, int fd);
1472885Sahrens void dmu_objset_stats(objset_t *os, nvlist_t *nv);
1482885Sahrens void dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat);
1492885Sahrens void dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
1502885Sahrens     uint64_t *usedobjsp, uint64_t *availobjsp);
1512885Sahrens uint64_t dmu_objset_fsid_guid(objset_t *os);
15211209SMatthew.Ahrens@Sun.COM int dmu_objset_find(char *name, int func(const char *, void *), void *arg,
153789Sahrens     int flags);
1547046Sahrens int dmu_objset_find_spa(spa_t *spa, const char *name,
1557046Sahrens     int func(spa_t *, uint64_t, const char *, void *), void *arg, int flags);
15611209SMatthew.Ahrens@Sun.COM int dmu_objset_prefetch(const char *name, void *arg);
157789Sahrens void dmu_objset_byteswap(void *buf, size_t size);
1584944Smaybee int dmu_objset_evict_dbufs(objset_t *os);
15910373Schris.kirby@sun.com timestruc_t dmu_objset_snap_cmtime(objset_t *os);
160789Sahrens 
161789Sahrens /* called from dsl */
16210298SMatthew.Ahrens@Sun.COM void dmu_objset_sync(objset_t *os, zio_t *zio, dmu_tx_t *tx);
16310922SJeff.Bonwick@Sun.COM boolean_t dmu_objset_is_dirty(objset_t *os, uint64_t txg);
16412722SSanjeev.Bagewadi@Sun.COM boolean_t dmu_objset_is_dirty_anywhere(objset_t *os);
16510298SMatthew.Ahrens@Sun.COM objset_t *dmu_objset_create_impl(spa_t *spa, struct dsl_dataset *ds,
1663547Smaybee     blkptr_t *bp, dmu_objset_type_t type, dmu_tx_t *tx);
1671544Seschrock int dmu_objset_open_impl(spa_t *spa, struct dsl_dataset *ds, blkptr_t *bp,
16810298SMatthew.Ahrens@Sun.COM     objset_t **osp);
16910298SMatthew.Ahrens@Sun.COM void dmu_objset_evict(objset_t *os);
17011935SMark.Shellenbaum@Sun.COM void dmu_objset_do_userquota_updates(objset_t *os, dmu_tx_t *tx);
17112178SMark.Shellenbaum@Sun.COM void dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx);
17210298SMatthew.Ahrens@Sun.COM boolean_t dmu_objset_userused_enabled(objset_t *os);
1739396SMatthew.Ahrens@Sun.COM int dmu_objset_userspace_upgrade(objset_t *os);
1749396SMatthew.Ahrens@Sun.COM boolean_t dmu_objset_userspace_present(objset_t *os);
175789Sahrens 
17612684STom.Erickson@Sun.COM void dmu_objset_init(void);
17712684STom.Erickson@Sun.COM void dmu_objset_fini(void);
17812684STom.Erickson@Sun.COM 
179789Sahrens #ifdef	__cplusplus
180789Sahrens }
181789Sahrens #endif
182789Sahrens 
183789Sahrens #endif /* _SYS_DMU_OBJSET_H */
184