usr/src/uts/common/fs/zfs/dmu.c
changeset 13700 2889e2596bd6
parent 12684 397e44ebb8a9
child 13776 cd512c80fd75
equal deleted inserted replaced
13699:733714f4dc24 13700:2889e2596bd6
    18  *
    18  *
    19  * CDDL HEADER END
    19  * CDDL HEADER END
    20  */
    20  */
    21 /*
    21 /*
    22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
    22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
       
    23  * Copyright (c) 2012 by Delphix. All rights reserved.
    23  */
    24  */
    24 
    25 
    25 #include <sys/dmu.h>
    26 #include <sys/dmu.h>
    26 #include <sys/dmu_impl.h>
    27 #include <sys/dmu_impl.h>
    27 #include <sys/dmu_tx.h>
    28 #include <sys/dmu_tx.h>
    44 #include <sys/vmsystm.h>
    45 #include <sys/vmsystm.h>
    45 #include <sys/zfs_znode.h>
    46 #include <sys/zfs_znode.h>
    46 #endif
    47 #endif
    47 
    48 
    48 const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES] = {
    49 const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES] = {
    49 	{	byteswap_uint8_array,	TRUE,	"unallocated"		},
    50 	{	DMU_BSWAP_UINT8,	TRUE,	"unallocated"		},
    50 	{	zap_byteswap,		TRUE,	"object directory"	},
    51 	{	DMU_BSWAP_ZAP,		TRUE,	"object directory"	},
    51 	{	byteswap_uint64_array,	TRUE,	"object array"		},
    52 	{	DMU_BSWAP_UINT64,	TRUE,	"object array"		},
    52 	{	byteswap_uint8_array,	TRUE,	"packed nvlist"		},
    53 	{	DMU_BSWAP_UINT8,	TRUE,	"packed nvlist"		},
    53 	{	byteswap_uint64_array,	TRUE,	"packed nvlist size"	},
    54 	{	DMU_BSWAP_UINT64,	TRUE,	"packed nvlist size"	},
    54 	{	byteswap_uint64_array,	TRUE,	"bpobj"			},
    55 	{	DMU_BSWAP_UINT64,	TRUE,	"bpobj"			},
    55 	{	byteswap_uint64_array,	TRUE,	"bpobj header"		},
    56 	{	DMU_BSWAP_UINT64,	TRUE,	"bpobj header"		},
    56 	{	byteswap_uint64_array,	TRUE,	"SPA space map header"	},
    57 	{	DMU_BSWAP_UINT64,	TRUE,	"SPA space map header"	},
    57 	{	byteswap_uint64_array,	TRUE,	"SPA space map"		},
    58 	{	DMU_BSWAP_UINT64,	TRUE,	"SPA space map"		},
    58 	{	byteswap_uint64_array,	TRUE,	"ZIL intent log"	},
    59 	{	DMU_BSWAP_UINT64,	TRUE,	"ZIL intent log"	},
    59 	{	dnode_buf_byteswap,	TRUE,	"DMU dnode"		},
    60 	{	DMU_BSWAP_DNODE,	TRUE,	"DMU dnode"		},
    60 	{	dmu_objset_byteswap,	TRUE,	"DMU objset"		},
    61 	{	DMU_BSWAP_OBJSET,	TRUE,	"DMU objset"		},
    61 	{	byteswap_uint64_array,	TRUE,	"DSL directory"		},
    62 	{	DMU_BSWAP_UINT64,	TRUE,	"DSL directory"		},
    62 	{	zap_byteswap,		TRUE,	"DSL directory child map"},
    63 	{	DMU_BSWAP_ZAP,		TRUE,	"DSL directory child map"},
    63 	{	zap_byteswap,		TRUE,	"DSL dataset snap map"	},
    64 	{	DMU_BSWAP_ZAP,		TRUE,	"DSL dataset snap map"	},
    64 	{	zap_byteswap,		TRUE,	"DSL props"		},
    65 	{	DMU_BSWAP_ZAP,		TRUE,	"DSL props"		},
    65 	{	byteswap_uint64_array,	TRUE,	"DSL dataset"		},
    66 	{	DMU_BSWAP_UINT64,	TRUE,	"DSL dataset"		},
    66 	{	zfs_znode_byteswap,	TRUE,	"ZFS znode"		},
    67 	{	DMU_BSWAP_ZNODE,	TRUE,	"ZFS znode"		},
    67 	{	zfs_oldacl_byteswap,	TRUE,	"ZFS V0 ACL"		},
    68 	{	DMU_BSWAP_OLDACL,	TRUE,	"ZFS V0 ACL"		},
    68 	{	byteswap_uint8_array,	FALSE,	"ZFS plain file"	},
    69 	{	DMU_BSWAP_UINT8,	FALSE,	"ZFS plain file"	},
    69 	{	zap_byteswap,		TRUE,	"ZFS directory"		},
    70 	{	DMU_BSWAP_ZAP,		TRUE,	"ZFS directory"		},
    70 	{	zap_byteswap,		TRUE,	"ZFS master node"	},
    71 	{	DMU_BSWAP_ZAP,		TRUE,	"ZFS master node"	},
    71 	{	zap_byteswap,		TRUE,	"ZFS delete queue"	},
    72 	{	DMU_BSWAP_ZAP,		TRUE,	"ZFS delete queue"	},
    72 	{	byteswap_uint8_array,	FALSE,	"zvol object"		},
    73 	{	DMU_BSWAP_UINT8,	FALSE,	"zvol object"		},
    73 	{	zap_byteswap,		TRUE,	"zvol prop"		},
    74 	{	DMU_BSWAP_ZAP,		TRUE,	"zvol prop"		},
    74 	{	byteswap_uint8_array,	FALSE,	"other uint8[]"		},
    75 	{	DMU_BSWAP_UINT8,	FALSE,	"other uint8[]"		},
    75 	{	byteswap_uint64_array,	FALSE,	"other uint64[]"	},
    76 	{	DMU_BSWAP_UINT64,	FALSE,	"other uint64[]"	},
    76 	{	zap_byteswap,		TRUE,	"other ZAP"		},
    77 	{	DMU_BSWAP_ZAP,		TRUE,	"other ZAP"		},
    77 	{	zap_byteswap,		TRUE,	"persistent error log"	},
    78 	{	DMU_BSWAP_ZAP,		TRUE,	"persistent error log"	},
    78 	{	byteswap_uint8_array,	TRUE,	"SPA history"		},
    79 	{	DMU_BSWAP_UINT8,	TRUE,	"SPA history"		},
    79 	{	byteswap_uint64_array,	TRUE,	"SPA history offsets"	},
    80 	{	DMU_BSWAP_UINT64,	TRUE,	"SPA history offsets"	},
    80 	{	zap_byteswap,		TRUE,	"Pool properties"	},
    81 	{	DMU_BSWAP_ZAP,		TRUE,	"Pool properties"	},
    81 	{	zap_byteswap,		TRUE,	"DSL permissions"	},
    82 	{	DMU_BSWAP_ZAP,		TRUE,	"DSL permissions"	},
    82 	{	zfs_acl_byteswap,	TRUE,	"ZFS ACL"		},
    83 	{	DMU_BSWAP_ACL,		TRUE,	"ZFS ACL"		},
    83 	{	byteswap_uint8_array,	TRUE,	"ZFS SYSACL"		},
    84 	{	DMU_BSWAP_UINT8,	TRUE,	"ZFS SYSACL"		},
    84 	{	byteswap_uint8_array,	TRUE,	"FUID table"		},
    85 	{	DMU_BSWAP_UINT8,	TRUE,	"FUID table"		},
    85 	{	byteswap_uint64_array,	TRUE,	"FUID table size"	},
    86 	{	DMU_BSWAP_UINT64,	TRUE,	"FUID table size"	},
    86 	{	zap_byteswap,		TRUE,	"DSL dataset next clones"},
    87 	{	DMU_BSWAP_ZAP,		TRUE,	"DSL dataset next clones"},
    87 	{	zap_byteswap,		TRUE,	"scan work queue"	},
    88 	{	DMU_BSWAP_ZAP,		TRUE,	"scan work queue"	},
    88 	{	zap_byteswap,		TRUE,	"ZFS user/group used"	},
    89 	{	DMU_BSWAP_ZAP,		TRUE,	"ZFS user/group used"	},
    89 	{	zap_byteswap,		TRUE,	"ZFS user/group quota"	},
    90 	{	DMU_BSWAP_ZAP,		TRUE,	"ZFS user/group quota"	},
    90 	{	zap_byteswap,		TRUE,	"snapshot refcount tags"},
    91 	{	DMU_BSWAP_ZAP,		TRUE,	"snapshot refcount tags"},
    91 	{	zap_byteswap,		TRUE,	"DDT ZAP algorithm"	},
    92 	{	DMU_BSWAP_ZAP,		TRUE,	"DDT ZAP algorithm"	},
    92 	{	zap_byteswap,		TRUE,	"DDT statistics"	},
    93 	{	DMU_BSWAP_ZAP,		TRUE,	"DDT statistics"	},
    93 	{	byteswap_uint8_array,	TRUE,	"System attributes"	},
    94 	{	DMU_BSWAP_UINT8,	TRUE,	"System attributes"	},
    94 	{	zap_byteswap,		TRUE,	"SA master node"	},
    95 	{	DMU_BSWAP_ZAP,		TRUE,	"SA master node"	},
    95 	{	zap_byteswap,		TRUE,	"SA attr registration"	},
    96 	{	DMU_BSWAP_ZAP,		TRUE,	"SA attr registration"	},
    96 	{	zap_byteswap,		TRUE,	"SA attr layouts"	},
    97 	{	DMU_BSWAP_ZAP,		TRUE,	"SA attr layouts"	},
    97 	{	zap_byteswap,		TRUE,	"scan translations"	},
    98 	{	DMU_BSWAP_ZAP,		TRUE,	"scan translations"	},
    98 	{	byteswap_uint8_array,	FALSE,	"deduplicated block"	},
    99 	{	DMU_BSWAP_UINT8,	FALSE,	"deduplicated block"	},
    99 	{	zap_byteswap,		TRUE,	"DSL deadlist map"	},
   100 	{	DMU_BSWAP_ZAP,		TRUE,	"DSL deadlist map"	},
   100 	{	byteswap_uint64_array,	TRUE,	"DSL deadlist map hdr"	},
   101 	{	DMU_BSWAP_UINT64,	TRUE,	"DSL deadlist map hdr"	},
   101 	{	zap_byteswap,		TRUE,	"DSL dir clones"	},
   102 	{	DMU_BSWAP_ZAP,		TRUE,	"DSL dir clones"	},
   102 	{	byteswap_uint64_array,	TRUE,	"bpobj subobj"		},
   103 	{	DMU_BSWAP_UINT64,	TRUE,	"bpobj subobj"		}
       
   104 };
       
   105 
       
   106 const dmu_object_byteswap_info_t dmu_ot_byteswap[DMU_BSWAP_NUMFUNCS] = {
       
   107 	{	byteswap_uint8_array,	"uint8"		},
       
   108 	{	byteswap_uint16_array,	"uint16"	},
       
   109 	{	byteswap_uint32_array,	"uint32"	},
       
   110 	{	byteswap_uint64_array,	"uint64"	},
       
   111 	{	zap_byteswap,		"zap"		},
       
   112 	{	dnode_buf_byteswap,	"dnode"		},
       
   113 	{	dmu_objset_byteswap,	"objset"	},
       
   114 	{	zfs_znode_byteswap,	"znode"		},
       
   115 	{	zfs_oldacl_byteswap,	"oldacl"	},
       
   116 	{	zfs_acl_byteswap,	"acl"		}
   103 };
   117 };
   104 
   118 
   105 int
   119 int
   106 dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset,
   120 dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset,
   107     void *tag, dmu_buf_t **dbp, int flags)
   121     void *tag, dmu_buf_t **dbp, int flags)
   174 	int error;
   188 	int error;
   175 
   189 
   176 	DB_DNODE_ENTER(db);
   190 	DB_DNODE_ENTER(db);
   177 	dn = DB_DNODE(db);
   191 	dn = DB_DNODE(db);
   178 
   192 
   179 	if (type > DMU_OT_NUMTYPES) {
   193 	if (!DMU_OT_IS_VALID(type)) {
   180 		error = EINVAL;
   194 		error = EINVAL;
   181 	} else if (dn->dn_bonus != db) {
   195 	} else if (dn->dn_bonus != db) {
   182 		error = EINVAL;
   196 		error = EINVAL;
   183 	} else {
   197 	} else {
   184 		dnode_setbonus_type(dn, type, tx);
   198 		dnode_setbonus_type(dn, type, tx);
  1501 
  1515 
  1502 void
  1516 void
  1503 dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp)
  1517 dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp)
  1504 {
  1518 {
  1505 	dmu_object_type_t type = dn ? dn->dn_type : DMU_OT_OBJSET;
  1519 	dmu_object_type_t type = dn ? dn->dn_type : DMU_OT_OBJSET;
  1506 	boolean_t ismd = (level > 0 || dmu_ot[type].ot_metadata ||
  1520 	boolean_t ismd = (level > 0 || DMU_OT_IS_METADATA(type) ||
  1507 	    (wp & WP_SPILL));
  1521 	    (wp & WP_SPILL));
  1508 	enum zio_checksum checksum = os->os_checksum;
  1522 	enum zio_checksum checksum = os->os_checksum;
  1509 	enum zio_compress compress = os->os_compress;
  1523 	enum zio_compress compress = os->os_compress;
  1510 	enum zio_checksum dedup_checksum = os->os_dedup_checksum;
  1524 	enum zio_checksum dedup_checksum = os->os_dedup_checksum;
  1511 	boolean_t dedup;
  1525 	boolean_t dedup;