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