annotate usr/src/uts/common/fs/zfs/dmu.c @ 2743:632c24f376ff

6461438 zfs send/recv code should live in its own file
author ahrens
date Fri, 15 Sep 2006 11:21:46 -0700
parents 12e2ad22b970
children c0259887ebbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
3 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
4 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
5 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
6 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
7 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
9 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
10 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
11 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
12 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
13 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
15 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
16 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
17 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
18 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
19 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
20 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
21 /*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
23 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
24 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
26 #pragma ident "%Z%%M% %I% %E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
28 #include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
29 #include <sys/dmu_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
30 #include <sys/dmu_tx.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
31 #include <sys/dbuf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
32 #include <sys/dnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
33 #include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
34 #include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
35 #include <sys/dmu_traverse.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
36 #include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
37 #include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
38 #include <sys/dsl_pool.h>
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
39 #include <sys/dsl_synctask.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
40 #include <sys/dmu_zfetch.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
41 #include <sys/zfs_ioctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
42 #include <sys/zap.h>
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
43 #include <sys/zio_checksum.h>
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
44 #ifdef _KERNEL
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
45 #include <sys/vmsystm.h>
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
46 #endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
47
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
48 const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
49 { byteswap_uint8_array, TRUE, "unallocated" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
50 { zap_byteswap, TRUE, "object directory" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
51 { byteswap_uint64_array, TRUE, "object array" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
52 { byteswap_uint8_array, TRUE, "packed nvlist" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
53 { byteswap_uint64_array, TRUE, "packed nvlist size" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
54 { byteswap_uint64_array, TRUE, "bplist" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
55 { byteswap_uint64_array, TRUE, "bplist header" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
56 { byteswap_uint64_array, TRUE, "SPA space map header" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
57 { byteswap_uint64_array, TRUE, "SPA space map" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
58 { byteswap_uint64_array, TRUE, "ZIL intent log" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
59 { dnode_buf_byteswap, TRUE, "DMU dnode" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
60 { dmu_objset_byteswap, TRUE, "DMU objset" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
61 { byteswap_uint64_array, TRUE, "DSL directory" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
62 { zap_byteswap, TRUE, "DSL directory child map"},
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
63 { zap_byteswap, TRUE, "DSL dataset snap map" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
64 { zap_byteswap, TRUE, "DSL props" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
65 { byteswap_uint64_array, TRUE, "DSL dataset" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
66 { zfs_znode_byteswap, TRUE, "ZFS znode" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
67 { zfs_acl_byteswap, TRUE, "ZFS ACL" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
68 { byteswap_uint8_array, FALSE, "ZFS plain file" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
69 { zap_byteswap, TRUE, "ZFS directory" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
70 { zap_byteswap, TRUE, "ZFS master node" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
71 { zap_byteswap, TRUE, "ZFS delete queue" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
72 { byteswap_uint8_array, FALSE, "zvol object" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
73 { zap_byteswap, TRUE, "zvol prop" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
74 { byteswap_uint8_array, FALSE, "other uint8[]" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
75 { byteswap_uint64_array, FALSE, "other uint64[]" },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
76 { zap_byteswap, TRUE, "other ZAP" },
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
77 { zap_byteswap, TRUE, "persistent error log" },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
78 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
80 int
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
81 dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
82 void *tag, dmu_buf_t **dbp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
83 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
84 dnode_t *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
85 uint64_t blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
86 dmu_buf_impl_t *db;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
87 int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
88
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
89 err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
90 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
91 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
92 blkid = dbuf_whichblock(dn, offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
93 rw_enter(&dn->dn_struct_rwlock, RW_READER);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
94 db = dbuf_hold(dn, blkid, tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
95 rw_exit(&dn->dn_struct_rwlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
96 if (db == NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
97 err = EIO;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
98 } else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
99 err = dbuf_read(db, NULL, DB_RF_CANFAIL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
100 if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
101 dbuf_rele(db, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
102 db = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
103 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
104 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
105
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
106 dnode_rele(dn, FTAG);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
107 *dbp = &db->db;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
108 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
109 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
110
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
111 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
112 dmu_bonus_max(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
113 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
114 return (DN_MAX_BONUSLEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
115 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
117 /*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
118 * returns ENOENT, EIO, or 0.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
119 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
120 int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
121 dmu_bonus_hold(objset_t *os, uint64_t object, void *tag, dmu_buf_t **dbp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
122 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
123 dnode_t *dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
124 int err, count;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
125 dmu_buf_impl_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
126
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
127 err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
128 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
129 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
130
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
131 rw_enter(&dn->dn_struct_rwlock, RW_READER);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
132 if (dn->dn_bonus == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
133 rw_exit(&dn->dn_struct_rwlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
134 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
135 if (dn->dn_bonus == NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
136 dn->dn_bonus = dbuf_create_bonus(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
137 }
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
138 db = dn->dn_bonus;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
139 rw_exit(&dn->dn_struct_rwlock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
140 mutex_enter(&db->db_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
141 count = refcount_add(&db->db_holds, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
142 mutex_exit(&db->db_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
143 if (count == 1)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
144 dnode_add_ref(dn, db);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
145 dnode_rele(dn, FTAG);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
146
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
147 VERIFY(0 == dbuf_read(db, NULL, DB_RF_MUST_SUCCEED));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
148
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
149 *dbp = &db->db;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
150 return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
151 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
152
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
153 /*
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
154 * Note: longer-term, we should modify all of the dmu_buf_*() interfaces
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
155 * to take a held dnode rather than <os, object> -- the lookup is wasteful,
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
156 * and can induce severe lock contention when writing to several files
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
157 * whose dnodes are in the same block.
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
158 */
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
159 static int
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
160 dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
161 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
162 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
163 dmu_buf_t **dbp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
164 uint64_t blkid, nblks, i;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
165 uint32_t flags;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
166 int err;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
167 zio_t *zio;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
168
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
169 ASSERT(length <= DMU_MAX_ACCESS);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
170
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
171 flags = DB_RF_CANFAIL | DB_RF_NEVERWAIT;
1731
1efa8b3d1296 6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents: 1630
diff changeset
172 if (length > zfetch_array_rd_sz)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
173 flags |= DB_RF_NOPREFETCH;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
174
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
175 rw_enter(&dn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
176 if (dn->dn_datablkshift) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
177 int blkshift = dn->dn_datablkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
178 nblks = (P2ROUNDUP(offset+length, 1ULL<<blkshift) -
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
179 P2ALIGN(offset, 1ULL<<blkshift)) >> blkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
180 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
181 ASSERT3U(offset + length, <=, dn->dn_datablksz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
182 nblks = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
183 }
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
184 dbp = kmem_zalloc(sizeof (dmu_buf_t *) * nblks, KM_SLEEP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
185
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
186 zio = zio_root(dn->dn_objset->os_spa, NULL, NULL, TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
187 blkid = dbuf_whichblock(dn, offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
188 for (i = 0; i < nblks; i++) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
189 dmu_buf_impl_t *db = dbuf_hold(dn, blkid+i, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
190 if (db == NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
191 rw_exit(&dn->dn_struct_rwlock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
192 dmu_buf_rele_array(dbp, nblks, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
193 zio_nowait(zio);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
194 return (EIO);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
195 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
196 /* initiate async i/o */
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
197 if (read) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
198 rw_exit(&dn->dn_struct_rwlock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
199 (void) dbuf_read(db, zio, flags);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
200 rw_enter(&dn->dn_struct_rwlock, RW_READER);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
201 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
202 dbp[i] = &db->db;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
203 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
204 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
205
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
206 /* wait for async i/o */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
207 err = zio_wait(zio);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
208 if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
209 dmu_buf_rele_array(dbp, nblks, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
210 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
211 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
212
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
213 /* wait for other io to complete */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
214 if (read) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
215 for (i = 0; i < nblks; i++) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
216 dmu_buf_impl_t *db = (dmu_buf_impl_t *)dbp[i];
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
217 mutex_enter(&db->db_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
218 while (db->db_state == DB_READ ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
219 db->db_state == DB_FILL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
220 cv_wait(&db->db_changed, &db->db_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
221 if (db->db_state == DB_UNCACHED)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
222 err = EIO;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
223 mutex_exit(&db->db_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
224 if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
225 dmu_buf_rele_array(dbp, nblks, tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
226 return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
227 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
228 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
229 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
230
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
231 *numbufsp = nblks;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
232 *dbpp = dbp;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
233 return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
234 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
235
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
236 int
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
237 dmu_buf_hold_array(objset_t *os, uint64_t object, uint64_t offset,
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
238 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
239 {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
240 dnode_t *dn;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
241 int err;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
242
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
243 err = dnode_hold(os->os, object, FTAG, &dn);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
244 if (err)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
245 return (err);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
246
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
247 err = dmu_buf_hold_array_by_dnode(dn, offset, length, read, tag,
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
248 numbufsp, dbpp);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
249
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
250 dnode_rele(dn, FTAG);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
251
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
252 return (err);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
253 }
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
254
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
255 int
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
256 dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset,
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
257 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
258 {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
259 dnode_t *dn = ((dmu_buf_impl_t *)db)->db_dnode;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
260 int err;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
261
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
262 err = dmu_buf_hold_array_by_dnode(dn, offset, length, read, tag,
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
263 numbufsp, dbpp);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
264
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
265 return (err);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
266 }
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
267
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
268 void
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
269 dmu_buf_rele_array(dmu_buf_t **dbp_fake, int numbufs, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
270 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
271 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
272 dmu_buf_impl_t **dbp = (dmu_buf_impl_t **)dbp_fake;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
273
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
274 if (numbufs == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
275 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
276
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
277 for (i = 0; i < numbufs; i++) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
278 if (dbp[i])
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
279 dbuf_rele(dbp[i], tag);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
280 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
281
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
282 kmem_free(dbp, sizeof (dmu_buf_t *) * numbufs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
283 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
284
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
285 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
286 dmu_prefetch(objset_t *os, uint64_t object, uint64_t offset, uint64_t len)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
287 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
288 dnode_t *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
289 uint64_t blkid;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
290 int nblks, i, err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
291
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
292 if (len == 0) { /* they're interested in the bonus buffer */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
293 dn = os->os->os_meta_dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
295 if (object == 0 || object >= DN_MAX_OBJECT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
296 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
297
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
298 rw_enter(&dn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
299 blkid = dbuf_whichblock(dn, object * sizeof (dnode_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
300 dbuf_prefetch(dn, blkid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
301 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
302 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
303 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
304
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
305 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
306 * XXX - Note, if the dnode for the requested object is not
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
307 * already cached, we will do a *synchronous* read in the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
308 * dnode_hold() call. The same is true for any indirects.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
309 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
310 err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
311 if (err != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
312 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
313
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
314 rw_enter(&dn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
315 if (dn->dn_datablkshift) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
316 int blkshift = dn->dn_datablkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
317 nblks = (P2ROUNDUP(offset+len, 1<<blkshift) -
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
318 P2ALIGN(offset, 1<<blkshift)) >> blkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
319 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
320 nblks = (offset < dn->dn_datablksz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
321 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
322
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
323 if (nblks != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
324 blkid = dbuf_whichblock(dn, offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
325 for (i = 0; i < nblks; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
326 dbuf_prefetch(dn, blkid+i);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
327 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
328
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
329 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
330
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
331 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
332 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
333
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
334 int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
335 dmu_free_range(objset_t *os, uint64_t object, uint64_t offset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
336 uint64_t size, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
337 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
338 dnode_t *dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
339 int err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
340 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
341 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
342 ASSERT(offset < UINT64_MAX);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
343 ASSERT(size == -1ULL || size <= UINT64_MAX - offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
344 dnode_free_range(dn, offset, size, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
345 dnode_rele(dn, FTAG);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
346 return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
347 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
348
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
349 int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
350 dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
351 void *buf)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
352 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
353 dnode_t *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
354 dmu_buf_t **dbp;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
355 int numbufs, i, err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
356
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
357 /*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
358 * Deal with odd block sizes, where there can't be data past the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
359 * first block.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
360 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
361 err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
362 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
363 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
364 if (dn->dn_datablkshift == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
365 int newsz = offset > dn->dn_datablksz ? 0 :
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
366 MIN(size, dn->dn_datablksz - offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
367 bzero((char *)buf + newsz, size - newsz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
368 size = newsz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
369 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
370 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
371
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
372 while (size > 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
373 uint64_t mylen = MIN(size, DMU_MAX_ACCESS / 2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
374 int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
375
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
376 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
377 * NB: we could do this block-at-a-time, but it's nice
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
378 * to be reading in parallel.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
379 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
380 err = dmu_buf_hold_array(os, object, offset, mylen,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
381 TRUE, FTAG, &numbufs, &dbp);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
382 if (err)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
383 return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
384
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
385 for (i = 0; i < numbufs; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
386 int tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
387 int bufoff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
388 dmu_buf_t *db = dbp[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
389
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
390 ASSERT(size > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
391
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
392 bufoff = offset - db->db_offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
393 tocpy = (int)MIN(db->db_size - bufoff, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
394
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
395 bcopy((char *)db->db_data + bufoff, buf, tocpy);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
396
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
397 offset += tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
398 size -= tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
399 buf = (char *)buf + tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
400 }
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
401 dmu_buf_rele_array(dbp, numbufs, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
402 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
403 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
404 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
405
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
406 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
407 dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
408 const void *buf, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
409 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
410 dmu_buf_t **dbp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
411 int numbufs, i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
412
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
413 if (size == 0)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
414 return;
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
415
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
416 VERIFY(0 == dmu_buf_hold_array(os, object, offset, size,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
417 FALSE, FTAG, &numbufs, &dbp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
418
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
419 for (i = 0; i < numbufs; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
420 int tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
421 int bufoff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
422 dmu_buf_t *db = dbp[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
423
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
424 ASSERT(size > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
425
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
426 bufoff = offset - db->db_offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
427 tocpy = (int)MIN(db->db_size - bufoff, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
428
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
429 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
430
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
431 if (tocpy == db->db_size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
432 dmu_buf_will_fill(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
433 else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
434 dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
436 bcopy(buf, (char *)db->db_data + bufoff, tocpy);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
437
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
438 if (tocpy == db->db_size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
439 dmu_buf_fill_done(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
440
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
441 offset += tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
442 size -= tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
443 buf = (char *)buf + tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
444 }
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
445 dmu_buf_rele_array(dbp, numbufs, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
446 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
447
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
448 #ifdef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
449 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
450 dmu_write_uio(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
451 uio_t *uio, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
452 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
453 dmu_buf_t **dbp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
454 int numbufs, i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
455 int err = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
456
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
457 if (size == 0)
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
458 return (0);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
459
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
460 err = dmu_buf_hold_array(os, object, offset, size,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
461 FALSE, FTAG, &numbufs, &dbp);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
462 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
463 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
464
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
465 for (i = 0; i < numbufs; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
466 int tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
467 int bufoff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
468 dmu_buf_t *db = dbp[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
469
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
470 ASSERT(size > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
471
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
472 bufoff = offset - db->db_offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
473 tocpy = (int)MIN(db->db_size - bufoff, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
474
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
475 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
476
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
477 if (tocpy == db->db_size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
478 dmu_buf_will_fill(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
479 else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
480 dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
481
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
482 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
483 * XXX uiomove could block forever (eg. nfs-backed
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
484 * pages). There needs to be a uiolockdown() function
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
485 * to lock the pages in memory, so that uiomove won't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
486 * block.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
487 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
488 err = uiomove((char *)db->db_data + bufoff, tocpy,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
489 UIO_WRITE, uio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
490
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
491 if (tocpy == db->db_size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
492 dmu_buf_fill_done(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
494 if (err)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
495 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
496
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
497 offset += tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
498 size -= tocpy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
499 }
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
500 dmu_buf_rele_array(dbp, numbufs, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
501 return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
502 }
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
503
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
504 int
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
505 dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
506 page_t *pp, dmu_tx_t *tx)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
507 {
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
508 dmu_buf_t **dbp;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
509 int numbufs, i;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
510 int err;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
511
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
512 if (size == 0)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
513 return (0);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
514
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
515 err = dmu_buf_hold_array(os, object, offset, size,
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
516 FALSE, FTAG, &numbufs, &dbp);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
517 if (err)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
518 return (err);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
519
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
520 for (i = 0; i < numbufs; i++) {
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
521 int tocpy, copied, thiscpy;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
522 int bufoff;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
523 dmu_buf_t *db = dbp[i];
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
524 caddr_t va;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
525
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
526 ASSERT(size > 0);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
527 ASSERT3U(db->db_size, >=, PAGESIZE);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
528
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
529 bufoff = offset - db->db_offset;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
530 tocpy = (int)MIN(db->db_size - bufoff, size);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
531
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
532 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
533
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
534 if (tocpy == db->db_size)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
535 dmu_buf_will_fill(db, tx);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
536 else
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
537 dmu_buf_will_dirty(db, tx);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
538
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
539 for (copied = 0; copied < tocpy; copied += PAGESIZE) {
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
540 ASSERT3U(pp->p_offset, ==, db->db_offset + bufoff);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
541 thiscpy = MIN(PAGESIZE, tocpy - copied);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
542 va = ppmapin(pp, PROT_READ, (caddr_t)-1);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
543 bcopy(va, (char *)db->db_data + bufoff, thiscpy);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
544 ppmapout(va);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
545 pp = pp->p_next;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
546 bufoff += PAGESIZE;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
547 }
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
548
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
549 if (tocpy == db->db_size)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
550 dmu_buf_fill_done(db, tx);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
551
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
552 if (err)
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
553 break;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
554
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
555 offset += tocpy;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
556 size -= tocpy;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
557 }
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
558 dmu_buf_rele_array(dbp, numbufs, FTAG);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
559 return (err);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2676
diff changeset
560 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
561 #endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
562
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
563 typedef struct {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
564 uint64_t txg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
565 dmu_buf_impl_t *db;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
566 dmu_sync_cb_t *done;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
567 void *arg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
568 } dmu_sync_cbin_t;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
569
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
570 typedef union {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
571 dmu_sync_cbin_t data;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
572 blkptr_t blk;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
573 } dmu_sync_cbarg_t;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
574
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
575 /* ARGSUSED */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
576 static void
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
577 dmu_sync_done(zio_t *zio, arc_buf_t *buf, void *varg)
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
578 {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
579 dmu_sync_cbin_t *in = (dmu_sync_cbin_t *)varg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
580 dmu_buf_impl_t *db = in->db;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
581 uint64_t txg = in->txg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
582 dmu_sync_cb_t *done = in->done;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
583 void *arg = in->arg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
584 blkptr_t *blk = (blkptr_t *)varg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
585
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
586 if (!BP_IS_HOLE(zio->io_bp)) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
587 zio->io_bp->blk_fill = 1;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
588 BP_SET_TYPE(zio->io_bp, db->db_dnode->dn_type);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
589 BP_SET_LEVEL(zio->io_bp, 0);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
590 }
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
591
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
592 *blk = *zio->io_bp; /* structure assignment */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
593
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
594 mutex_enter(&db->db_mtx);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
595 ASSERT(db->db_d.db_overridden_by[txg&TXG_MASK] == IN_DMU_SYNC);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
596 db->db_d.db_overridden_by[txg&TXG_MASK] = blk;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
597 cv_broadcast(&db->db_changed);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
598 mutex_exit(&db->db_mtx);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
599
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
600 if (done)
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
601 done(&(db->db), arg);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
602 }
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
603
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
604 /*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
605 * Intent log support: sync the block associated with db to disk.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
606 * N.B. and XXX: the caller is responsible for making sure that the
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
607 * data isn't changing while dmu_sync() is writing it.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
608 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
609 * Return values:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
610 *
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
611 * EEXIST: this txg has already been synced, so there's nothing to to.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
612 * The caller should not log the write.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
613 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
614 * ENOENT: the block was dbuf_free_range()'d, so there's nothing to do.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
615 * The caller should not log the write.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
616 *
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
617 * EALREADY: this block is already in the process of being synced.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
618 * The caller should track its progress (somehow).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
619 *
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
620 * EINPROGRESS: the IO has been initiated.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
621 * The caller should log this blkptr in the callback.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
622 *
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
623 * 0: completed. Sets *bp to the blkptr just written.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
624 * The caller should log this blkptr immediately.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
625 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
626 int
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
627 dmu_sync(zio_t *pio, dmu_buf_t *db_fake,
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
628 blkptr_t *bp, uint64_t txg, dmu_sync_cb_t *done, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
629 {
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
630 dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
631 objset_impl_t *os = db->db_objset;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
632 dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
633 tx_state_t *tx = &dp->dp_tx;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
634 dmu_sync_cbin_t *in;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
635 blkptr_t *blk;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
636 zbookmark_t zb;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
637 uint32_t arc_flag;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
638 int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
639
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
640 ASSERT(BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
641 ASSERT(txg != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
642
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
643
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
644 dprintf("dmu_sync txg=%llu, s,o,q %llu %llu %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
645 txg, tx->tx_synced_txg, tx->tx_open_txg, tx->tx_quiesced_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
646
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
647 /*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
648 * XXX - would be nice if we could do this without suspending...
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
649 */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
650 txg_suspend(dp);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
651
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
652 /*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
653 * If this txg already synced, there's nothing to do.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
654 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
655 if (txg <= tx->tx_synced_txg) {
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
656 txg_resume(dp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
657 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
658 * If we're running ziltest, we need the blkptr regardless.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
659 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
660 if (txg > spa_freeze_txg(dp->dp_spa)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
661 /* if db_blkptr == NULL, this was an empty write */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
662 if (db->db_blkptr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
663 *bp = *db->db_blkptr; /* structure assignment */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
664 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
665 }
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
666 return (EEXIST);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
667 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
669 mutex_enter(&db->db_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
670
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
671 blk = db->db_d.db_overridden_by[txg&TXG_MASK];
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
672 if (blk == IN_DMU_SYNC) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
673 /*
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
674 * We have already issued a sync write for this buffer.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
675 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
676 mutex_exit(&db->db_mtx);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
677 txg_resume(dp);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
678 return (EALREADY);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
679 } else if (blk != NULL) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
680 /*
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
681 * This buffer had already been synced. It could not
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
682 * have been dirtied since, or we would have cleared blk.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
683 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
684 *bp = *blk; /* structure assignment */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
685 mutex_exit(&db->db_mtx);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
686 txg_resume(dp);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
687 return (0);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
688 }
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
689
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
690 if (txg == tx->tx_syncing_txg) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
691 while (db->db_data_pending) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
692 /*
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
693 * IO is in-progress. Wait for it to finish.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
694 * XXX - would be nice to be able to somehow "attach"
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
695 * this zio to the parent zio passed in.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
696 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
697 cv_wait(&db->db_changed, &db->db_mtx);
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
698 if (!db->db_data_pending &&
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
699 db->db_blkptr && BP_IS_HOLE(db->db_blkptr)) {
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
700 /*
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
701 * IO was compressed away
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
702 */
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
703 *bp = *db->db_blkptr; /* structure assignment */
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
704 mutex_exit(&db->db_mtx);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
705 txg_resume(dp);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
706 return (0);
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
707 }
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
708 ASSERT(db->db_data_pending ||
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
709 (db->db_blkptr && db->db_blkptr->blk_birth == txg));
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
710 }
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
711
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
712 if (db->db_blkptr && db->db_blkptr->blk_birth == txg) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
713 /*
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
714 * IO is already completed.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
715 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
716 *bp = *db->db_blkptr; /* structure assignment */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
717 mutex_exit(&db->db_mtx);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
718 txg_resume(dp);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
719 return (0);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
720 }
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
721 }
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
722
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
723 if (db->db_d.db_data_old[txg&TXG_MASK] == NULL) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
724 /*
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
725 * This dbuf isn't dirty, must have been free_range'd.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
726 * There's no need to log writes to freed blocks, so we're done.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
727 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
728 mutex_exit(&db->db_mtx);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
729 txg_resume(dp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
730 return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
731 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
732
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
733 ASSERT(db->db_d.db_overridden_by[txg&TXG_MASK] == NULL);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
734 db->db_d.db_overridden_by[txg&TXG_MASK] = IN_DMU_SYNC;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
735 /*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
736 * XXX - a little ugly to stash the blkptr in the callback
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
737 * buffer. We always need to make sure the following is true:
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
738 * ASSERT(sizeof(blkptr_t) >= sizeof(dmu_sync_cbin_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
739 */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
740 in = kmem_alloc(sizeof (blkptr_t), KM_SLEEP);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
741 in->db = db;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
742 in->txg = txg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
743 in->done = done;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
744 in->arg = arg;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
745 mutex_exit(&db->db_mtx);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
746 txg_resume(dp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
747
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
748 arc_flag = pio == NULL ? ARC_WAIT : ARC_NOWAIT;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
749 zb.zb_objset = os->os_dsl_dataset->ds_object;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
750 zb.zb_object = db->db.db_object;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
751 zb.zb_level = db->db_level;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
752 zb.zb_blkid = db->db_blkid;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
753 err = arc_write(pio, os->os_spa,
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
754 zio_checksum_select(db->db_dnode->dn_checksum, os->os_checksum),
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
755 zio_compress_select(db->db_dnode->dn_compress, os->os_compress),
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
756 dmu_get_replication_level(os->os_spa, &zb, db->db_dnode->dn_type),
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
757 txg, bp, db->db_d.db_data_old[txg&TXG_MASK], dmu_sync_done, in,
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
758 ZIO_PRIORITY_SYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, arc_flag, &zb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
759 ASSERT(err == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
760
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
761 return (arc_flag == ARC_NOWAIT ? EINPROGRESS : 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
762 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
764 uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
765 dmu_object_max_nonzero_offset(objset_t *os, uint64_t object)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
766 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
767 dnode_t *dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
768
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
769 /* XXX assumes dnode_hold will not get an i/o error */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
770 (void) dnode_hold(os->os, object, FTAG, &dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
771 uint64_t rv = dnode_max_nonzero_offset(dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
772 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
773 return (rv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
774 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
775
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
776 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
777 dmu_object_set_blocksize(objset_t *os, uint64_t object, uint64_t size, int ibs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
778 dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
779 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
780 dnode_t *dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
781 int err;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
782
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
783 err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
784 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
785 return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
786 err = dnode_set_blksz(dn, size, ibs, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
787 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
788 return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
789 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
790
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
791 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
792 dmu_object_set_checksum(objset_t *os, uint64_t object, uint8_t checksum,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
793 dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
794 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
795 dnode_t *dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
796
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
797 /* XXX assumes dnode_hold will not get an i/o error */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
798 (void) dnode_hold(os->os, object, FTAG, &dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
799 ASSERT(checksum < ZIO_CHECKSUM_FUNCTIONS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
800 dn->dn_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
801 dnode_setdirty(dn, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
802 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
803 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
804
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
805 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
806 dmu_object_set_compress(objset_t *os, uint64_t object, uint8_t compress,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
807 dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
808 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
809 dnode_t *dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
810
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
811 /* XXX assumes dnode_hold will not get an i/o error */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
812 (void) dnode_hold(os->os, object, FTAG, &dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
813 ASSERT(compress < ZIO_COMPRESS_FUNCTIONS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
814 dn->dn_compress = compress;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
815 dnode_setdirty(dn, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
816 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
817 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
818
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
819 /*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
820 * XXX - eventually, this should take into account per-dataset (or
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
821 * even per-object?) user requests for higher levels of replication.
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
822 */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
823 int
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
824 dmu_get_replication_level(spa_t *spa, zbookmark_t *zb, dmu_object_type_t ot)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
825 {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
826 int ncopies = 1;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
827
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
828 if (dmu_ot[ot].ot_metadata)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
829 ncopies++;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
830 if (zb->zb_level != 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
831 ncopies++;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
832 if (zb->zb_objset == 0 && zb->zb_object == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
833 ncopies++;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
834 return (MIN(ncopies, spa_max_replication(spa)));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
835 }
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1731
diff changeset
836
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
837 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
838 dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole, uint64_t *off)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
839 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
840 dnode_t *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
841 int i, err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
842
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
843 err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
844 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
845 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
846 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
847 * Sync any current changes before
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
848 * we go trundling through the block pointers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
849 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
850 for (i = 0; i < TXG_SIZE; i++) {
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
851 if (list_link_active(&dn->dn_dirty_link[i]))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
852 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
853 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
854 if (i != TXG_SIZE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
855 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
856 txg_wait_synced(dmu_objset_pool(os), 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
857 err = dnode_hold(os->os, object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
858 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
859 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
860 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
861
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
862 err = dnode_next_offset(dn, hole, off, 1, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
863 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
864
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
865 return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
866 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
867
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
868 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
869 dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
870 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
871 rw_enter(&dn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
872 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
873
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
874 doi->doi_data_block_size = dn->dn_datablksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
875 doi->doi_metadata_block_size = dn->dn_indblkshift ?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
876 1ULL << dn->dn_indblkshift : 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
877 doi->doi_indirection = dn->dn_nlevels;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
878 doi->doi_checksum = dn->dn_checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
879 doi->doi_compress = dn->dn_compress;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
880 doi->doi_physical_blks = (DN_USED_BYTES(dn->dn_phys) +
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
881 SPA_MINBLOCKSIZE/2) >> SPA_MINBLOCKSHIFT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
882 doi->doi_max_block_offset = dn->dn_phys->dn_maxblkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
883 doi->doi_type = dn->dn_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
884 doi->doi_bonus_size = dn->dn_bonuslen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
885 doi->doi_bonus_type = dn->dn_bonustype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
886
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
887 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
888 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
889 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
890
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
891 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
892 * Get information on a DMU object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
893 * If doi is NULL, just indicates whether the object exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
894 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
895 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
896 dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
897 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
898 dnode_t *dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
899 int err = dnode_hold(os->os, object, FTAG, &dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
900
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
901 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
902 return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
903
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
904 if (doi != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
905 dmu_object_info_from_dnode(dn, doi);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
906
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
907 dnode_rele(dn, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
908 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
909 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
910
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
911 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
912 * As above, but faster; can be used when you have a held dbuf in hand.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
913 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
914 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
915 dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
916 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
917 dmu_object_info_from_dnode(((dmu_buf_impl_t *)db)->db_dnode, doi);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
918 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
919
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
920 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
921 * Faster still when you only care about the size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
922 * This is specifically optimized for zfs_getattr().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
923 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
924 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
925 dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize, u_longlong_t *nblk512)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
926 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
927 dnode_t *dn = ((dmu_buf_impl_t *)db)->db_dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
928
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
929 *blksize = dn->dn_datablksz;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
930 /* add 1 for dnode space */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
931 *nblk512 = ((DN_USED_BYTES(dn->dn_phys) + SPA_MINBLOCKSIZE/2) >>
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
932 SPA_MINBLOCKSHIFT) + 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
933 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
934
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
935 /*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
936 * Given a bookmark, return the name of the dataset, object, and range in
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
937 * human-readable format.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
938 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
939 int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
940 spa_bookmark_name(spa_t *spa, zbookmark_t *zb, nvlist_t *nvl)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
941 {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
942 dsl_pool_t *dp;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
943 dsl_dataset_t *ds = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
944 objset_t *os = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
945 dnode_t *dn = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
946 int err, shift;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
947 char dsname[MAXNAMELEN];
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
948 char objname[32];
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
949 char range[64];
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
950
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
951 dp = spa_get_dsl(spa);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
952 if (zb->zb_objset != 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
953 rw_enter(&dp->dp_config_rwlock, RW_READER);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
954 err = dsl_dataset_open_obj(dp, zb->zb_objset,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
955 NULL, DS_MODE_NONE, FTAG, &ds);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
956 if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
957 rw_exit(&dp->dp_config_rwlock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
958 return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
959 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
960 dsl_dataset_name(ds, dsname);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
961 dsl_dataset_close(ds, DS_MODE_NONE, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
962 rw_exit(&dp->dp_config_rwlock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
963
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
964 err = dmu_objset_open(dsname, DMU_OST_ANY, DS_MODE_NONE, &os);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
965 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
966 goto out;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
967
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
968 } else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
969 dsl_dataset_name(NULL, dsname);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
970 os = dp->dp_meta_objset;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
971 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
972
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
973
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
974 if (zb->zb_object == DMU_META_DNODE_OBJECT) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
975 (void) strncpy(objname, "mdn", sizeof (objname));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
976 } else {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
977 (void) snprintf(objname, sizeof (objname), "%lld",
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
978 (longlong_t)zb->zb_object);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
979 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
980
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
981 err = dnode_hold(os->os, zb->zb_object, FTAG, &dn);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
982 if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
983 goto out;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
984
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
985 shift = (dn->dn_datablkshift?dn->dn_datablkshift:SPA_MAXBLOCKSHIFT) +
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
986 zb->zb_level * (dn->dn_indblkshift - SPA_BLKPTRSHIFT);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
987 (void) snprintf(range, sizeof (range), "%llu-%llu",
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
988 (u_longlong_t)(zb->zb_blkid << shift),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
989 (u_longlong_t)((zb->zb_blkid+1) << shift));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
990
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
991 if ((err = nvlist_add_string(nvl, ZPOOL_ERR_DATASET, dsname)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
992 (err = nvlist_add_string(nvl, ZPOOL_ERR_OBJECT, objname)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
993 (err = nvlist_add_string(nvl, ZPOOL_ERR_RANGE, range)) != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
994 goto out;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
995
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
996 out:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
997 if (dn)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
998 dnode_rele(dn, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
999 if (os && os != dp->dp_meta_objset)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
1000 dmu_objset_close(os);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
1001 return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
1002 }
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
1003
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1004 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1005 byteswap_uint64_array(void *vbuf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1006 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1007 uint64_t *buf = vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1008 size_t count = size >> 3;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1009 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1011 ASSERT((size & 7) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1012
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1013 for (i = 0; i < count; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1014 buf[i] = BSWAP_64(buf[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1015 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1016
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1017 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1018 byteswap_uint32_array(void *vbuf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1019 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1020 uint32_t *buf = vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1021 size_t count = size >> 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1022 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1023
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1024 ASSERT((size & 3) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1025
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1026 for (i = 0; i < count; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1027 buf[i] = BSWAP_32(buf[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1028 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1029
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1030 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1031 byteswap_uint16_array(void *vbuf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1032 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1033 uint16_t *buf = vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1034 size_t count = size >> 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1035 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1036
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1037 ASSERT((size & 1) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1038
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1039 for (i = 0; i < count; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1040 buf[i] = BSWAP_16(buf[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1041 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1042
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1043 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1044 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1045 byteswap_uint8_array(void *vbuf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1046 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1047 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1048
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1049 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1050 dmu_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1051 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1052 dbuf_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1053 dnode_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1054 arc_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1055 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1056
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1057 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1058 dmu_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1059 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1060 arc_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1061 dnode_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1062 dbuf_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1063 }