xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dmu_objset.h (revision 4de2612967d06c4fdbf524a62556a1e8118a006f)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_DMU_OBJSET_H
28 #define	_SYS_DMU_OBJSET_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/spa.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 	objset_phys_t *os_phys;
65 	dnode_t *os_meta_dnode;
66 	zilog_t *os_zil;
67 	objset_t os;
68 	uint8_t os_checksum;	/* can change, under dsl_dir's locks */
69 	uint8_t os_compress;	/* can change, under dsl_dir's locks */
70 	uint8_t os_md_checksum;
71 	uint8_t os_md_compress;
72 
73 	/* no lock needed: */
74 	struct dmu_tx *os_synctx; /* XXX sketchy */
75 	blkptr_t os_rootbp;
76 
77 	/* Protected by os_obj_lock */
78 	kmutex_t os_obj_lock;
79 	uint64_t os_obj_next;
80 
81 	/* Protected by os_lock */
82 	kmutex_t os_lock;
83 	list_t os_dirty_dnodes[TXG_SIZE];
84 	list_t os_free_dnodes[TXG_SIZE];
85 	list_t os_dnodes;
86 	list_t os_downgraded_dbufs;
87 } objset_impl_t;
88 
89 #define	DMU_PRIVATE_OBJECT		(1ULL << 63)
90 
91 #define	DMU_META_DNODE_OBJECT		(1ULL << 63)
92 
93 /* XXX rename this to DMU_IS_DNODE_OBJECT? */
94 #define	IS_DNODE_DNODE(object) ((object) == DMU_META_DNODE_OBJECT)
95 
96 /* called from zpl */
97 int dmu_objset_open(const char *name, dmu_objset_type_t type, int mode,
98     objset_t **osp);
99 void dmu_objset_close(objset_t *os);
100 int dmu_objset_create(const char *name, dmu_objset_type_t type,
101     objset_t *clone_parent,
102     void (*func)(objset_t *os, void *arg, dmu_tx_t *tx), void *arg);
103 int dmu_objset_destroy(const char *name);
104 int dmu_objset_rollback(const char *name);
105 void dmu_objset_stats(objset_t *os, dmu_objset_stats_t *dds);
106 void dmu_objset_find(char *name, void func(char *, void *), void *arg,
107     int flags);
108 void dmu_objset_byteswap(void *buf, size_t size);
109 
110 /* called from dsl */
111 void dmu_objset_sync(objset_impl_t *os, dmu_tx_t *tx);
112 objset_impl_t *dmu_objset_create_impl(spa_t *spa, struct dsl_dataset *ds,
113     dmu_objset_type_t type, dmu_tx_t *tx);
114 objset_impl_t *dmu_objset_open_impl(spa_t *spa, struct dsl_dataset *ds,
115     blkptr_t *bp);
116 void dmu_objset_evict(struct dsl_dataset *ds, void *arg);
117 
118 #ifdef	__cplusplus
119 }
120 #endif
121 
122 #endif /* _SYS_DMU_OBJSET_H */
123