author | gw25295 |
Mon, 29 Oct 2007 17:24:59 -0700 | |
changeset 5369 | 27c1235ef9a4 |
parent 5367 | c40abbe796be |
child 5642 | 504c84876fda |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 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 |
/* |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
22 |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
27 |
||
28 |
#include <sys/dsl_pool.h> |
|
29 |
#include <sys/dsl_dataset.h> |
|
30 |
#include <sys/dsl_dir.h> |
|
2199 | 31 |
#include <sys/dsl_synctask.h> |
789 | 32 |
#include <sys/dmu_tx.h> |
33 |
#include <sys/dmu_objset.h> |
|
34 |
#include <sys/arc.h> |
|
35 |
#include <sys/zap.h> |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
36 |
#include <sys/zio.h> |
789 | 37 |
#include <sys/zfs_context.h> |
38 |
#include <sys/fs/zfs.h> |
|
39 |
||
1544 | 40 |
static int |
41 |
dsl_pool_open_mos_dir(dsl_pool_t *dp, dsl_dir_t **ddp) |
|
789 | 42 |
{ |
43 |
uint64_t obj; |
|
44 |
int err; |
|
45 |
||
46 |
err = zap_lookup(dp->dp_meta_objset, |
|
47 |
dp->dp_root_dir->dd_phys->dd_child_dir_zapobj, |
|
48 |
MOS_DIR_NAME, sizeof (obj), 1, &obj); |
|
1544 | 49 |
if (err) |
50 |
return (err); |
|
789 | 51 |
|
1544 | 52 |
return (dsl_dir_open_obj(dp, obj, MOS_DIR_NAME, dp, ddp)); |
789 | 53 |
} |
54 |
||
55 |
static dsl_pool_t * |
|
56 |
dsl_pool_open_impl(spa_t *spa, uint64_t txg) |
|
57 |
{ |
|
58 |
dsl_pool_t *dp; |
|
59 |
blkptr_t *bp = spa_get_rootblkptr(spa); |
|
60 |
||
61 |
dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP); |
|
62 |
dp->dp_spa = spa; |
|
63 |
dp->dp_meta_rootbp = *bp; |
|
2856 | 64 |
rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL); |
789 | 65 |
txg_init(dp, txg); |
66 |
||
67 |
txg_list_create(&dp->dp_dirty_datasets, |
|
68 |
offsetof(dsl_dataset_t, ds_dirty_link)); |
|
69 |
txg_list_create(&dp->dp_dirty_dirs, |
|
70 |
offsetof(dsl_dir_t, dd_dirty_link)); |
|
2199 | 71 |
txg_list_create(&dp->dp_sync_tasks, |
72 |
offsetof(dsl_sync_task_group_t, dstg_node)); |
|
5367 | 73 |
list_create(&dp->dp_synced_datasets, sizeof (dsl_dataset_t), |
789 | 74 |
offsetof(dsl_dataset_t, ds_synced_link)); |
75 |
||
76 |
return (dp); |
|
77 |
} |
|
78 |
||
1544 | 79 |
int |
80 |
dsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp) |
|
789 | 81 |
{ |
82 |
int err; |
|
83 |
dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); |
|
1544 | 84 |
objset_impl_t *osi; |
789 | 85 |
|
86 |
rw_enter(&dp->dp_config_rwlock, RW_READER); |
|
1544 | 87 |
err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp, &osi); |
88 |
if (err) |
|
89 |
goto out; |
|
90 |
dp->dp_meta_objset = &osi->os; |
|
91 |
||
789 | 92 |
err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, |
93 |
DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1, |
|
94 |
&dp->dp_root_dir_obj); |
|
1544 | 95 |
if (err) |
96 |
goto out; |
|
97 |
||
98 |
err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj, |
|
99 |
NULL, dp, &dp->dp_root_dir); |
|
100 |
if (err) |
|
101 |
goto out; |
|
789 | 102 |
|
1544 | 103 |
err = dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir); |
104 |
if (err) |
|
105 |
goto out; |
|
106 |
||
107 |
out: |
|
789 | 108 |
rw_exit(&dp->dp_config_rwlock); |
1544 | 109 |
if (err) |
110 |
dsl_pool_close(dp); |
|
111 |
else |
|
112 |
*dpp = dp; |
|
789 | 113 |
|
1544 | 114 |
return (err); |
789 | 115 |
} |
116 |
||
117 |
void |
|
118 |
dsl_pool_close(dsl_pool_t *dp) |
|
119 |
{ |
|
120 |
/* drop our reference from dsl_pool_open() */ |
|
1544 | 121 |
if (dp->dp_mos_dir) |
122 |
dsl_dir_close(dp->dp_mos_dir, dp); |
|
123 |
if (dp->dp_root_dir) |
|
124 |
dsl_dir_close(dp->dp_root_dir, dp); |
|
789 | 125 |
|
126 |
/* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */ |
|
1544 | 127 |
if (dp->dp_meta_objset) |
128 |
dmu_objset_evict(NULL, dp->dp_meta_objset->os); |
|
789 | 129 |
|
130 |
txg_list_destroy(&dp->dp_dirty_datasets); |
|
131 |
txg_list_destroy(&dp->dp_dirty_dirs); |
|
5367 | 132 |
list_destroy(&dp->dp_synced_datasets); |
789 | 133 |
|
134 |
arc_flush(); |
|
135 |
txg_fini(dp); |
|
2856 | 136 |
rw_destroy(&dp->dp_config_rwlock); |
789 | 137 |
kmem_free(dp, sizeof (dsl_pool_t)); |
138 |
} |
|
139 |
||
140 |
dsl_pool_t * |
|
141 |
dsl_pool_create(spa_t *spa, uint64_t txg) |
|
142 |
{ |
|
143 |
int err; |
|
144 |
dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); |
|
145 |
dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg); |
|
146 |
dp->dp_meta_objset = &dmu_objset_create_impl(spa, |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
147 |
NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx)->os; |
789 | 148 |
|
149 |
/* create the pool directory */ |
|
150 |
err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, |
|
151 |
DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx); |
|
152 |
ASSERT3U(err, ==, 0); |
|
153 |
||
154 |
/* create and open the root dir */ |
|
155 |
dsl_dataset_create_root(dp, &dp->dp_root_dir_obj, tx); |
|
1544 | 156 |
VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj, |
157 |
NULL, dp, &dp->dp_root_dir)); |
|
789 | 158 |
|
159 |
/* create and open the meta-objset dir */ |
|
2199 | 160 |
(void) dsl_dir_create_sync(dp->dp_root_dir, MOS_DIR_NAME, tx); |
1544 | 161 |
VERIFY(0 == dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir)); |
789 | 162 |
|
163 |
dmu_tx_commit(tx); |
|
164 |
||
165 |
return (dp); |
|
166 |
} |
|
167 |
||
168 |
void |
|
169 |
dsl_pool_sync(dsl_pool_t *dp, uint64_t txg) |
|
170 |
{ |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
171 |
zio_t *zio; |
789 | 172 |
dmu_tx_t *tx; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
173 |
dsl_dir_t *dd; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
174 |
dsl_dataset_t *ds; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
175 |
dsl_sync_task_group_t *dstg; |
789 | 176 |
objset_impl_t *mosi = dp->dp_meta_objset->os; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
177 |
int err; |
789 | 178 |
|
179 |
tx = dmu_tx_create_assigned(dp, txg); |
|
180 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
181 |
zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
182 |
while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
183 |
if (!list_link_active(&ds->ds_synced_link)) |
5367 | 184 |
list_insert_tail(&dp->dp_synced_datasets, ds); |
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3547
diff
changeset
|
185 |
else |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3547
diff
changeset
|
186 |
dmu_buf_rele(ds->ds_dbuf, ds); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
187 |
dsl_dataset_sync(ds, zio, tx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
188 |
} |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
189 |
err = zio_wait(zio); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
190 |
ASSERT(err == 0); |
789 | 191 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
192 |
while (dstg = txg_list_remove(&dp->dp_sync_tasks, txg)) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
193 |
dsl_sync_task_group_sync(dstg, tx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
194 |
while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg)) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
195 |
dsl_dir_sync(dd, tx); |
789 | 196 |
|
197 |
if (list_head(&mosi->os_dirty_dnodes[txg & TXG_MASK]) != NULL || |
|
198 |
list_head(&mosi->os_free_dnodes[txg & TXG_MASK]) != NULL) { |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
199 |
zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
200 |
dmu_objset_sync(mosi, zio, tx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
201 |
err = zio_wait(zio); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
202 |
ASSERT(err == 0); |
789 | 203 |
dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", ""); |
204 |
spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp); |
|
205 |
} |
|
206 |
||
207 |
dmu_tx_commit(tx); |
|
208 |
} |
|
209 |
||
210 |
void |
|
211 |
dsl_pool_zil_clean(dsl_pool_t *dp) |
|
212 |
{ |
|
213 |
dsl_dataset_t *ds; |
|
214 |
||
5367 | 215 |
while (ds = list_head(&dp->dp_synced_datasets)) { |
216 |
list_remove(&dp->dp_synced_datasets, ds); |
|
789 | 217 |
ASSERT(ds->ds_user_ptr != NULL); |
218 |
zil_clean(((objset_impl_t *)ds->ds_user_ptr)->os_zil); |
|
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3547
diff
changeset
|
219 |
dmu_buf_rele(ds->ds_dbuf, ds); |
789 | 220 |
} |
221 |
} |
|
222 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
223 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
224 |
* TRUE if the current thread is the tx_sync_thread or if we |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
225 |
* are being called from SPA context during pool initialization. |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
226 |
*/ |
789 | 227 |
int |
228 |
dsl_pool_sync_context(dsl_pool_t *dp) |
|
229 |
{ |
|
230 |
return (curthread == dp->dp_tx.tx_sync_thread || |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
2856
diff
changeset
|
231 |
spa_get_dsl(dp->dp_spa) == NULL); |
789 | 232 |
} |
233 |
||
234 |
uint64_t |
|
235 |
dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree) |
|
236 |
{ |
|
237 |
uint64_t space, resv; |
|
238 |
||
239 |
/* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1544
diff
changeset
|
240 |
* Reserve about 1.6% (1/64), or at least 32MB, for allocation |
789 | 241 |
* efficiency. |
242 |
* XXX The intent log is not accounted for, so it must fit |
|
243 |
* within this slop. |
|
244 |
* |
|
245 |
* If we're trying to assess whether it's OK to do a free, |
|
246 |
* cut the reservation in half to allow forward progress |
|
247 |
* (e.g. make it possible to rm(1) files from a full pool). |
|
248 |
*/ |
|
2082 | 249 |
space = spa_get_dspace(dp->dp_spa); |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1544
diff
changeset
|
250 |
resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1); |
789 | 251 |
if (netfree) |
252 |
resv >>= 1; |
|
253 |
||
254 |
return (space - resv); |
|
255 |
} |