4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "@(#)dmu.c 1.30 07/11/09 SMI"
29 #include <sys/dmu_impl.h>
30 #include <sys/dmu_tx.h>
32 #include <sys/dnode.h>
33 #include <sys/zfs_context.h>
34 #include <sys/dmu_objset.h>
35 #include <sys/dmu_traverse.h>
36 #include <sys/dsl_dataset.h>
37 #include <sys/dsl_dir.h>
38 #include <sys/dsl_pool.h>
39 #include <sys/dsl_synctask.h>
40 #include <sys/dsl_prop.h>
41 #include <sys/dmu_zfetch.h>
42 #include <sys/zfs_ioctl.h>
44 #include <sys/zio_checksum.h>
46 #include <sys/vmsystm.h>
49 const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES] = {
50 { byteswap_uint8_array, TRUE, "unallocated" },
51 { zap_byteswap, TRUE, "object directory" },
52 { byteswap_uint64_array, TRUE, "object array" },
53 { byteswap_uint8_array, TRUE, "packed nvlist" },
54 { byteswap_uint64_array, TRUE, "packed nvlist size" },
55 { byteswap_uint64_array, TRUE, "bplist" },
56 { byteswap_uint64_array, TRUE, "bplist header" },
57 { byteswap_uint64_array, TRUE, "SPA space map header" },
58 { byteswap_uint64_array, TRUE, "SPA space map" },
59 { byteswap_uint64_array, TRUE, "ZIL intent log" },
60 { dnode_buf_byteswap, TRUE, "DMU dnode" },
61 { dmu_objset_byteswap, TRUE, "DMU objset" },
62 { byteswap_uint64_array, TRUE, "DSL directory" },
63 { zap_byteswap, TRUE, "DSL directory child map"},
64 { zap_byteswap, TRUE, "DSL dataset snap map" },
65 { zap_byteswap, TRUE, "DSL props" },
66 { byteswap_uint64_array, TRUE, "DSL dataset" },
67 { zfs_znode_byteswap, TRUE, "ZFS znode" },
68 { zfs_oldacl_byteswap, TRUE, "ZFS V0 ACL" },
69 { byteswap_uint8_array, FALSE, "ZFS plain file" },
70 { zap_byteswap, TRUE, "ZFS directory" },
71 { zap_byteswap, TRUE, "ZFS master node" },
72 { zap_byteswap, TRUE, "ZFS delete queue" },
73 { byteswap_uint8_array, FALSE, "zvol object" },
74 { zap_byteswap, TRUE, "zvol prop" },
75 { byteswap_uint8_array, FALSE, "other uint8[]" },
76 { byteswap_uint64_array, FALSE, "other uint64[]" },
77 { zap_byteswap, TRUE, "other ZAP" },
78 { zap_byteswap, TRUE, "persistent error log" },
79 { byteswap_uint8_array, TRUE, "SPA history" },
80 { byteswap_uint64_array, TRUE, "SPA history offsets" },
81 { zap_byteswap, TRUE, "Pool properties" },
82 { zap_byteswap, TRUE, "DSL permissions" },
83 { zfs_acl_byteswap, TRUE, "ZFS ACL" },
84 { byteswap_uint8_array, TRUE, "ZFS SYSACL" },
85 { byteswap_uint8_array, TRUE, "FUID table" },
86 { byteswap_uint64_array, TRUE, "FUID table size" },
90 dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset,
91 void *tag, dmu_buf_t **dbp)
98 err = dnode_hold(os->os, object, FTAG, &dn);
101 blkid = dbuf_whichblock(dn, offset);
102 rw_enter(&dn->dn_struct_rwlock, RW_READER);
103 db = dbuf_hold(dn, blkid, tag);
104 rw_exit(&dn->dn_struct_rwlock);
108 err = dbuf_read(db, NULL, DB_RF_CANFAIL);
115 dnode_rele(dn, FTAG);
123 return (DN_MAX_BONUSLEN);
127 dmu_set_bonus(dmu_buf_t *db, int newsize, dmu_tx_t *tx)
129 dnode_t *dn = ((dmu_buf_impl_t *)db)->db_dnode;
131 if (dn->dn_bonus != (dmu_buf_impl_t *)db)
133 if (newsize < 0 || newsize > db->db_size)
135 dnode_setbonuslen(dn, newsize, tx);
140 * returns ENOENT, EIO, or 0.
143 dmu_bonus_hold(objset_t *os, uint64_t object, void *tag, dmu_buf_t **dbp)
149 error = dnode_hold(os->os, object, FTAG, &dn);
153 rw_enter(&dn->dn_struct_rwlock, RW_READER);
154 if (dn->dn_bonus == NULL) {
155 rw_exit(&dn->dn_struct_rwlock);
156 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
157 if (dn->dn_bonus == NULL)
158 dbuf_create_bonus(dn);
161 rw_exit(&dn->dn_struct_rwlock);
163 /* as long as the bonus buf is held, the dnode will be held */
164 if (refcount_add(&db->db_holds, tag) == 1)
165 VERIFY(dnode_add_ref(dn, db));
167 dnode_rele(dn, FTAG);
169 VERIFY(0 == dbuf_read(db, NULL, DB_RF_MUST_SUCCEED));
176 * Note: longer-term, we should modify all of the dmu_buf_*() interfaces
177 * to take a held dnode rather than <os, object> -- the lookup is wasteful,
178 * and can induce severe lock contention when writing to several files
179 * whose dnodes are in the same block.
182 dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset,
183 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp)
186 uint64_t blkid, nblks, i;
191 ASSERT(length <= DMU_MAX_ACCESS);
193 flags = DB_RF_CANFAIL | DB_RF_NEVERWAIT;
194 if (length > zfetch_array_rd_sz)
195 flags |= DB_RF_NOPREFETCH;
197 rw_enter(&dn->dn_struct_rwlock, RW_READER);
198 if (dn->dn_datablkshift) {
199 int blkshift = dn->dn_datablkshift;
200 nblks = (P2ROUNDUP(offset+length, 1ULL<<blkshift) -
201 P2ALIGN(offset, 1ULL<<blkshift)) >> blkshift;
203 if (offset + length > dn->dn_datablksz) {
204 zfs_panic_recover("zfs: accessing past end of object "
205 "%llx/%llx (size=%u access=%llu+%llu)",
206 (longlong_t)dn->dn_objset->
207 os_dsl_dataset->ds_object,
208 (longlong_t)dn->dn_object, dn->dn_datablksz,
209 (longlong_t)offset, (longlong_t)length);
214 dbp = kmem_zalloc(sizeof (dmu_buf_t *) * nblks, KM_SLEEP);
216 zio = zio_root(dn->dn_objset->os_spa, NULL, NULL, TRUE);
217 blkid = dbuf_whichblock(dn, offset);
218 for (i = 0; i < nblks; i++) {
219 dmu_buf_impl_t *db = dbuf_hold(dn, blkid+i, tag);
221 rw_exit(&dn->dn_struct_rwlock);
222 dmu_buf_rele_array(dbp, nblks, tag);
226 /* initiate async i/o */
228 rw_exit(&dn->dn_struct_rwlock);
229 (void) dbuf_read(db, zio, flags);
230 rw_enter(&dn->dn_struct_rwlock, RW_READER);
234 rw_exit(&dn->dn_struct_rwlock);
236 /* wait for async i/o */
239 dmu_buf_rele_array(dbp, nblks, tag);
243 /* wait for other io to complete */
245 for (i = 0; i < nblks; i++) {
246 dmu_buf_impl_t *db = (dmu_buf_impl_t *)dbp[i];
247 mutex_enter(&db->db_mtx);
248 while (db->db_state == DB_READ ||
249 db->db_state == DB_FILL)
250 cv_wait(&db->db_changed, &db->db_mtx);
251 if (db->db_state == DB_UNCACHED)
253 mutex_exit(&db->db_mtx);
255 dmu_buf_rele_array(dbp, nblks, tag);
267 dmu_buf_hold_array(objset_t *os, uint64_t object, uint64_t offset,
268 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp)
273 err = dnode_hold(os->os, object, FTAG, &dn);
277 err = dmu_buf_hold_array_by_dnode(dn, offset, length, read, tag,
280 dnode_rele(dn, FTAG);
286 dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset,
287 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp)
289 dnode_t *dn = ((dmu_buf_impl_t *)db)->db_dnode;
292 err = dmu_buf_hold_array_by_dnode(dn, offset, length, read, tag,
299 dmu_buf_rele_array(dmu_buf_t **dbp_fake, int numbufs, void *tag)
302 dmu_buf_impl_t **dbp = (dmu_buf_impl_t **)dbp_fake;
307 for (i = 0; i < numbufs; i++) {
309 dbuf_rele(dbp[i], tag);
312 kmem_free(dbp, sizeof (dmu_buf_t *) * numbufs);
316 dmu_prefetch(objset_t *os, uint64_t object, uint64_t offset, uint64_t len)
322 if (zfs_prefetch_disable)
325 if (len == 0) { /* they're interested in the bonus buffer */
326 dn = os->os->os_meta_dnode;
328 if (object == 0 || object >= DN_MAX_OBJECT)
331 rw_enter(&dn->dn_struct_rwlock, RW_READER);
332 blkid = dbuf_whichblock(dn, object * sizeof (dnode_phys_t));
333 dbuf_prefetch(dn, blkid);
334 rw_exit(&dn->dn_struct_rwlock);
339 * XXX - Note, if the dnode for the requested object is not
340 * already cached, we will do a *synchronous* read in the
341 * dnode_hold() call. The same is true for any indirects.
343 err = dnode_hold(os->os, object, FTAG, &dn);
347 rw_enter(&dn->dn_struct_rwlock, RW_READER);
348 if (dn->dn_datablkshift) {
349 int blkshift = dn->dn_datablkshift;
350 nblks = (P2ROUNDUP(offset+len, 1<<blkshift) -
351 P2ALIGN(offset, 1<<blkshift)) >> blkshift;
353 nblks = (offset < dn->dn_datablksz);
357 blkid = dbuf_whichblock(dn, offset);
358 for (i = 0; i < nblks; i++)
359 dbuf_prefetch(dn, blkid+i);
362 rw_exit(&dn->dn_struct_rwlock);
364 dnode_rele(dn, FTAG);
368 dmu_free_range(objset_t *os, uint64_t object, uint64_t offset,
369 uint64_t size, dmu_tx_t *tx)
372 int err = dnode_hold(os->os, object, FTAG, &dn);
375 ASSERT(offset < UINT64_MAX);
376 ASSERT(size == -1ULL || size <= UINT64_MAX - offset);
377 dnode_free_range(dn, offset, size, tx);
378 dnode_rele(dn, FTAG);
383 dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
390 err = dnode_hold(os->os, object, FTAG, &dn);
395 * Deal with odd block sizes, where there can't be data past the first
396 * block. If we ever do the tail block optimization, we will need to
397 * handle that here as well.
399 if (dn->dn_datablkshift == 0) {
400 int newsz = offset > dn->dn_datablksz ? 0 :
401 MIN(size, dn->dn_datablksz - offset);
402 bzero((char *)buf + newsz, size - newsz);
407 uint64_t mylen = MIN(size, DMU_MAX_ACCESS / 2);
410 * NB: we could do this block-at-a-time, but it's nice
411 * to be reading in parallel.
413 err = dmu_buf_hold_array_by_dnode(dn, offset, mylen,
414 TRUE, FTAG, &numbufs, &dbp);
418 for (i = 0; i < numbufs; i++) {
421 dmu_buf_t *db = dbp[i];
425 bufoff = offset - db->db_offset;
426 tocpy = (int)MIN(db->db_size - bufoff, size);
428 bcopy((char *)db->db_data + bufoff, buf, tocpy);
432 buf = (char *)buf + tocpy;
434 dmu_buf_rele_array(dbp, numbufs, FTAG);
436 dnode_rele(dn, FTAG);
441 dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
442 const void *buf, dmu_tx_t *tx)
450 VERIFY(0 == dmu_buf_hold_array(os, object, offset, size,
451 FALSE, FTAG, &numbufs, &dbp));
453 for (i = 0; i < numbufs; i++) {
456 dmu_buf_t *db = dbp[i];
460 bufoff = offset - db->db_offset;
461 tocpy = (int)MIN(db->db_size - bufoff, size);
463 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size);
465 if (tocpy == db->db_size)
466 dmu_buf_will_fill(db, tx);
468 dmu_buf_will_dirty(db, tx);
470 bcopy(buf, (char *)db->db_data + bufoff, tocpy);
472 if (tocpy == db->db_size)
473 dmu_buf_fill_done(db, tx);
477 buf = (char *)buf + tocpy;
479 dmu_buf_rele_array(dbp, numbufs, FTAG);
484 dmu_read_uio(objset_t *os, uint64_t object, uio_t *uio, uint64_t size)
490 * NB: we could do this block-at-a-time, but it's nice
491 * to be reading in parallel.
493 err = dmu_buf_hold_array(os, object, uio->uio_loffset, size, TRUE, FTAG,
498 for (i = 0; i < numbufs; i++) {
501 dmu_buf_t *db = dbp[i];
505 bufoff = uio->uio_loffset - db->db_offset;
506 tocpy = (int)MIN(db->db_size - bufoff, size);
508 err = uiomove((char *)db->db_data + bufoff, tocpy,
515 dmu_buf_rele_array(dbp, numbufs, FTAG);
521 dmu_write_uio(objset_t *os, uint64_t object, uio_t *uio, uint64_t size,
531 err = dmu_buf_hold_array(os, object, uio->uio_loffset, size,
532 FALSE, FTAG, &numbufs, &dbp);
536 for (i = 0; i < numbufs; i++) {
539 dmu_buf_t *db = dbp[i];
543 bufoff = uio->uio_loffset - db->db_offset;
544 tocpy = (int)MIN(db->db_size - bufoff, size);
546 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size);
548 if (tocpy == db->db_size)
549 dmu_buf_will_fill(db, tx);
551 dmu_buf_will_dirty(db, tx);
554 * XXX uiomove could block forever (eg. nfs-backed
555 * pages). There needs to be a uiolockdown() function
556 * to lock the pages in memory, so that uiomove won't
559 err = uiomove((char *)db->db_data + bufoff, tocpy,
562 if (tocpy == db->db_size)
563 dmu_buf_fill_done(db, tx);
570 dmu_buf_rele_array(dbp, numbufs, FTAG);
575 dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
576 page_t *pp, dmu_tx_t *tx)
585 err = dmu_buf_hold_array(os, object, offset, size,
586 FALSE, FTAG, &numbufs, &dbp);
590 for (i = 0; i < numbufs; i++) {
591 int tocpy, copied, thiscpy;
593 dmu_buf_t *db = dbp[i];
597 ASSERT3U(db->db_size, >=, PAGESIZE);
599 bufoff = offset - db->db_offset;
600 tocpy = (int)MIN(db->db_size - bufoff, size);
602 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size);
604 if (tocpy == db->db_size)
605 dmu_buf_will_fill(db, tx);
607 dmu_buf_will_dirty(db, tx);
609 for (copied = 0; copied < tocpy; copied += PAGESIZE) {
610 ASSERT3U(pp->p_offset, ==, db->db_offset + bufoff);
611 thiscpy = MIN(PAGESIZE, tocpy - copied);
612 va = ppmapin(pp, PROT_READ, (caddr_t)-1);
613 bcopy(va, (char *)db->db_data + bufoff, thiscpy);
619 if (tocpy == db->db_size)
620 dmu_buf_fill_done(db, tx);
628 dmu_buf_rele_array(dbp, numbufs, FTAG);
634 dbuf_dirty_record_t *dr;
641 dmu_sync_done(zio_t *zio, arc_buf_t *buf, void *varg)
643 dmu_sync_arg_t *in = varg;
644 dbuf_dirty_record_t *dr = in->dr;
645 dmu_buf_impl_t *db = dr->dr_dbuf;
646 dmu_sync_cb_t *done = in->done;
648 if (!BP_IS_HOLE(zio->io_bp)) {
649 zio->io_bp->blk_fill = 1;
650 BP_SET_TYPE(zio->io_bp, db->db_dnode->dn_type);
651 BP_SET_LEVEL(zio->io_bp, 0);
654 mutex_enter(&db->db_mtx);
655 ASSERT(dr->dt.dl.dr_override_state == DR_IN_DMU_SYNC);
656 dr->dt.dl.dr_overridden_by = *zio->io_bp; /* structure assignment */
657 dr->dt.dl.dr_override_state = DR_OVERRIDDEN;
658 cv_broadcast(&db->db_changed);
659 mutex_exit(&db->db_mtx);
662 done(&(db->db), in->arg);
664 kmem_free(in, sizeof (dmu_sync_arg_t));
668 * Intent log support: sync the block associated with db to disk.
669 * N.B. and XXX: the caller is responsible for making sure that the
670 * data isn't changing while dmu_sync() is writing it.
674 * EEXIST: this txg has already been synced, so there's nothing to to.
675 * The caller should not log the write.
677 * ENOENT: the block was dbuf_free_range()'d, so there's nothing to do.
678 * The caller should not log the write.
680 * EALREADY: this block is already in the process of being synced.
681 * The caller should track its progress (somehow).
683 * EINPROGRESS: the IO has been initiated.
684 * The caller should log this blkptr in the callback.
686 * 0: completed. Sets *bp to the blkptr just written.
687 * The caller should log this blkptr immediately.
690 dmu_sync(zio_t *pio, dmu_buf_t *db_fake,
691 blkptr_t *bp, uint64_t txg, dmu_sync_cb_t *done, void *arg)
693 dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
694 objset_impl_t *os = db->db_objset;
695 dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool;
696 tx_state_t *tx = &dp->dp_tx;
697 dbuf_dirty_record_t *dr;
704 ASSERT(BP_IS_HOLE(bp));
708 dprintf("dmu_sync txg=%llu, s,o,q %llu %llu %llu\n",
709 txg, tx->tx_synced_txg, tx->tx_open_txg, tx->tx_quiesced_txg);
712 * XXX - would be nice if we could do this without suspending...
717 * If this txg already synced, there's nothing to do.
719 if (txg <= tx->tx_synced_txg) {
722 * If we're running ziltest, we need the blkptr regardless.
724 if (txg > spa_freeze_txg(dp->dp_spa)) {
725 /* if db_blkptr == NULL, this was an empty write */
727 *bp = *db->db_blkptr; /* structure assignment */
733 mutex_enter(&db->db_mtx);
735 if (txg == tx->tx_syncing_txg) {
736 while (db->db_data_pending) {
738 * IO is in-progress. Wait for it to finish.
739 * XXX - would be nice to be able to somehow "attach"
740 * this zio to the parent zio passed in.
742 cv_wait(&db->db_changed, &db->db_mtx);
743 if (!db->db_data_pending &&
744 db->db_blkptr && BP_IS_HOLE(db->db_blkptr)) {
746 * IO was compressed away
748 *bp = *db->db_blkptr; /* structure assignment */
749 mutex_exit(&db->db_mtx);
753 ASSERT(db->db_data_pending ||
754 (db->db_blkptr && db->db_blkptr->blk_birth == txg));
757 if (db->db_blkptr && db->db_blkptr->blk_birth == txg) {
759 * IO is already completed.
761 *bp = *db->db_blkptr; /* structure assignment */
762 mutex_exit(&db->db_mtx);
768 dr = db->db_last_dirty;
769 while (dr && dr->dr_txg > txg)
771 if (dr == NULL || dr->dr_txg < txg) {
773 * This dbuf isn't dirty, must have been free_range'd.
774 * There's no need to log writes to freed blocks, so we're done.
776 mutex_exit(&db->db_mtx);
781 ASSERT(dr->dr_txg == txg);
782 if (dr->dt.dl.dr_override_state == DR_IN_DMU_SYNC) {
784 * We have already issued a sync write for this buffer.
786 mutex_exit(&db->db_mtx);
789 } else if (dr->dt.dl.dr_override_state == DR_OVERRIDDEN) {
791 * This buffer has already been synced. It could not
792 * have been dirtied since, or we would have cleared the state.
794 *bp = dr->dt.dl.dr_overridden_by; /* structure assignment */
795 mutex_exit(&db->db_mtx);
800 dr->dt.dl.dr_override_state = DR_IN_DMU_SYNC;
801 in = kmem_alloc(sizeof (dmu_sync_arg_t), KM_SLEEP);
805 mutex_exit(&db->db_mtx);
808 zb.zb_objset = os->os_dsl_dataset->ds_object;
809 zb.zb_object = db->db.db_object;
810 zb.zb_level = db->db_level;
811 zb.zb_blkid = db->db_blkid;
812 zio_flags = ZIO_FLAG_MUSTSUCCEED;
813 if (dmu_ot[db->db_dnode->dn_type].ot_metadata || zb.zb_level != 0)
814 zio_flags |= ZIO_FLAG_METADATA;
815 zio = arc_write(pio, os->os_spa,
816 zio_checksum_select(db->db_dnode->dn_checksum, os->os_checksum),
817 zio_compress_select(db->db_dnode->dn_compress, os->os_compress),
818 dmu_get_replication_level(os, &zb, db->db_dnode->dn_type),
819 txg, bp, dr->dt.dl.dr_data, NULL, dmu_sync_done, in,
820 ZIO_PRIORITY_SYNC_WRITE, zio_flags, &zb);
833 dmu_object_set_blocksize(objset_t *os, uint64_t object, uint64_t size, int ibs,
839 err = dnode_hold(os->os, object, FTAG, &dn);
842 err = dnode_set_blksz(dn, size, ibs, tx);
843 dnode_rele(dn, FTAG);
848 dmu_object_set_checksum(objset_t *os, uint64_t object, uint8_t checksum,
853 /* XXX assumes dnode_hold will not get an i/o error */
854 (void) dnode_hold(os->os, object, FTAG, &dn);
855 ASSERT(checksum < ZIO_CHECKSUM_FUNCTIONS);
856 dn->dn_checksum = checksum;
857 dnode_setdirty(dn, tx);
858 dnode_rele(dn, FTAG);
862 dmu_object_set_compress(objset_t *os, uint64_t object, uint8_t compress,
867 /* XXX assumes dnode_hold will not get an i/o error */
868 (void) dnode_hold(os->os, object, FTAG, &dn);
869 ASSERT(compress < ZIO_COMPRESS_FUNCTIONS);
870 dn->dn_compress = compress;
871 dnode_setdirty(dn, tx);
872 dnode_rele(dn, FTAG);
876 dmu_get_replication_level(objset_impl_t *os,
877 zbookmark_t *zb, dmu_object_type_t ot)
879 int ncopies = os->os_copies;
881 /* If it's the mos, it should have max copies set. */
882 ASSERT(zb->zb_objset != 0 ||
883 ncopies == spa_max_replication(os->os_spa));
885 if (dmu_ot[ot].ot_metadata || zb->zb_level != 0)
887 return (MIN(ncopies, spa_max_replication(os->os_spa)));
891 dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole, uint64_t *off)
896 err = dnode_hold(os->os, object, FTAG, &dn);
900 * Sync any current changes before
901 * we go trundling through the block pointers.
903 for (i = 0; i < TXG_SIZE; i++) {
904 if (list_link_active(&dn->dn_dirty_link[i]))
908 dnode_rele(dn, FTAG);
909 txg_wait_synced(dmu_objset_pool(os), 0);
910 err = dnode_hold(os->os, object, FTAG, &dn);
915 err = dnode_next_offset(dn, hole, off, 1, 1, 0);
916 dnode_rele(dn, FTAG);
922 dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi)
924 rw_enter(&dn->dn_struct_rwlock, RW_READER);
925 mutex_enter(&dn->dn_mtx);
927 doi->doi_data_block_size = dn->dn_datablksz;
928 doi->doi_metadata_block_size = dn->dn_indblkshift ?
929 1ULL << dn->dn_indblkshift : 0;
930 doi->doi_indirection = dn->dn_nlevels;
931 doi->doi_checksum = dn->dn_checksum;
932 doi->doi_compress = dn->dn_compress;
933 doi->doi_physical_blks = (DN_USED_BYTES(dn->dn_phys) +
934 SPA_MINBLOCKSIZE/2) >> SPA_MINBLOCKSHIFT;
935 doi->doi_max_block_offset = dn->dn_phys->dn_maxblkid;
936 doi->doi_type = dn->dn_type;
937 doi->doi_bonus_size = dn->dn_bonuslen;
938 doi->doi_bonus_type = dn->dn_bonustype;
940 mutex_exit(&dn->dn_mtx);
941 rw_exit(&dn->dn_struct_rwlock);
945 * Get information on a DMU object.
946 * If doi is NULL, just indicates whether the object exists.
949 dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi)
952 int err = dnode_hold(os->os, object, FTAG, &dn);
958 dmu_object_info_from_dnode(dn, doi);
960 dnode_rele(dn, FTAG);
965 * As above, but faster; can be used when you have a held dbuf in hand.
968 dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi)
970 dmu_object_info_from_dnode(((dmu_buf_impl_t *)db)->db_dnode, doi);
974 * Faster still when you only care about the size.
975 * This is specifically optimized for zfs_getattr().
978 dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize, u_longlong_t *nblk512)
980 dnode_t *dn = ((dmu_buf_impl_t *)db)->db_dnode;
982 *blksize = dn->dn_datablksz;
983 /* add 1 for dnode space */
984 *nblk512 = ((DN_USED_BYTES(dn->dn_phys) + SPA_MINBLOCKSIZE/2) >>
985 SPA_MINBLOCKSHIFT) + 1;
989 byteswap_uint64_array(void *vbuf, size_t size)
991 uint64_t *buf = vbuf;
992 size_t count = size >> 3;
995 ASSERT((size & 7) == 0);
997 for (i = 0; i < count; i++)
998 buf[i] = BSWAP_64(buf[i]);
1002 byteswap_uint32_array(void *vbuf, size_t size)
1004 uint32_t *buf = vbuf;
1005 size_t count = size >> 2;
1008 ASSERT((size & 3) == 0);
1010 for (i = 0; i < count; i++)
1011 buf[i] = BSWAP_32(buf[i]);
1015 byteswap_uint16_array(void *vbuf, size_t size)
1017 uint16_t *buf = vbuf;
1018 size_t count = size >> 1;
1021 ASSERT((size & 1) == 0);
1023 for (i = 0; i < count; i++)
1024 buf[i] = BSWAP_16(buf[i]);
1029 byteswap_uint8_array(void *vbuf, size_t size)