xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dmu_objset.h (revision 3baa08fc5b6bea08a475b0cfe3ad161d74c5864b)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DMU_OBJSET_H
27 #define	_SYS_DMU_OBJSET_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/spa.h>
32 #include <sys/arc.h>
33 #include <sys/txg.h>
34 #include <sys/zfs_context.h>
35 #include <sys/dnode.h>
36 #include <sys/zio.h>
37 #include <sys/zil.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 struct dsl_dataset;
44 struct dmu_tx;
45 struct objset_impl;
46 
47 typedef struct objset_phys {
48 	dnode_phys_t os_meta_dnode;
49 	zil_header_t os_zil_header;
50 	uint64_t os_type;
51 	char os_pad[1024 - sizeof (dnode_phys_t) - sizeof (zil_header_t) -
52 	    sizeof (uint64_t)];
53 } objset_phys_t;
54 
55 struct objset {
56 	struct objset_impl *os;
57 	int os_mode;
58 };
59 
60 typedef struct objset_impl {
61 	/* Immutable: */
62 	struct dsl_dataset *os_dsl_dataset;
63 	spa_t *os_spa;
64 	arc_buf_t *os_phys_buf;
65 	objset_phys_t *os_phys;
66 	dnode_t *os_meta_dnode;
67 	zilog_t *os_zil;
68 	objset_t os;
69 	uint8_t os_checksum;	/* can change, under dsl_dir's locks */
70 	uint8_t os_compress;	/* can change, under dsl_dir's locks */
71 	uint8_t os_copies;	/* can change, under dsl_dir's locks */
72 	uint8_t os_primary_cache;	/* can change, under dsl_dir's locks */
73 	uint8_t os_secondary_cache;	/* can change, under dsl_dir's locks */
74 
75 	/* no lock needed: */
76 	struct dmu_tx *os_synctx; /* XXX sketchy */
77 	blkptr_t *os_rootbp;
78 	zil_header_t os_zil_header;
79 
80 	/* Protected by os_obj_lock */
81 	kmutex_t os_obj_lock;
82 	uint64_t os_obj_next;
83 
84 	/* Protected by os_lock */
85 	kmutex_t os_lock;
86 	list_t os_dirty_dnodes[TXG_SIZE];
87 	list_t os_free_dnodes[TXG_SIZE];
88 	list_t os_dnodes;
89 	list_t os_downgraded_dbufs;
90 
91 	/* stuff we store for the user */
92 	kmutex_t os_user_ptr_lock;
93 	void *os_user_ptr;
94 } objset_impl_t;
95 
96 #define	DMU_META_DNODE_OBJECT	0
97 
98 #define	DMU_OS_IS_L2CACHEABLE(os)				\
99 	((os)->os_secondary_cache == ZFS_CACHE_ALL ||		\
100 	(os)->os_secondary_cache == ZFS_CACHE_METADATA)
101 
102 /* called from zpl */
103 int dmu_objset_open(const char *name, dmu_objset_type_t type, int mode,
104     objset_t **osp);
105 void dmu_objset_close(objset_t *os);
106 int dmu_objset_create(const char *name, dmu_objset_type_t type,
107     objset_t *clone_parent, uint64_t flags,
108     void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg);
109 int dmu_objset_destroy(const char *name);
110 int dmu_objset_rollback(objset_t *os);
111 int dmu_objset_snapshot(char *fsname, char *snapname, boolean_t recursive);
112 void dmu_objset_stats(objset_t *os, nvlist_t *nv);
113 void dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat);
114 void dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
115     uint64_t *usedobjsp, uint64_t *availobjsp);
116 uint64_t dmu_objset_fsid_guid(objset_t *os);
117 int dmu_objset_find(char *name, int func(char *, void *), void *arg,
118     int flags);
119 int dmu_objset_find_spa(spa_t *spa, const char *name,
120     int func(spa_t *, uint64_t, const char *, void *), void *arg, int flags);
121 void dmu_objset_byteswap(void *buf, size_t size);
122 int dmu_objset_evict_dbufs(objset_t *os);
123 
124 /* called from dsl */
125 void dmu_objset_sync(objset_impl_t *os, zio_t *zio, dmu_tx_t *tx);
126 objset_impl_t *dmu_objset_create_impl(spa_t *spa, struct dsl_dataset *ds,
127     blkptr_t *bp, dmu_objset_type_t type, dmu_tx_t *tx);
128 int dmu_objset_open_impl(spa_t *spa, struct dsl_dataset *ds, blkptr_t *bp,
129     objset_impl_t **osip);
130 void dmu_objset_evict(struct dsl_dataset *ds, void *arg);
131 
132 #ifdef	__cplusplus
133 }
134 #endif
135 
136 #endif /* _SYS_DMU_OBJSET_H */
137