1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5f65e61c0Sahrens * Common Development and Distribution License (the "License"). 6f65e61c0Sahrens * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 22f65e61c0Sahrens * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _SYS_ZAP_IMPL_H 27fa9e4066Sahrens #define _SYS_ZAP_IMPL_H 28fa9e4066Sahrens 29fa9e4066Sahrens #pragma ident "%Z%%M% %I% %E% SMI" 30fa9e4066Sahrens 31fa9e4066Sahrens #include <sys/zap.h> 32fa9e4066Sahrens #include <sys/zfs_context.h> 33fa9e4066Sahrens #include <sys/avl.h> 34fa9e4066Sahrens 35fa9e4066Sahrens #ifdef __cplusplus 36fa9e4066Sahrens extern "C" { 37fa9e4066Sahrens #endif 38fa9e4066Sahrens 39f65e61c0Sahrens extern int fzap_default_block_shift; 40f65e61c0Sahrens 41*5ad82045Snd #define ZAP_MAGIC 0x2F52AB2ABULL 42fa9e4066Sahrens 43f65e61c0Sahrens #define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_f.zap_block_shift) 44fa9e4066Sahrens 45fa9e4066Sahrens #define ZAP_MAXCD (uint32_t)(-1) 46fa9e4066Sahrens #define ZAP_HASHBITS 28 47fa9e4066Sahrens #define MZAP_ENT_LEN 64 48fa9e4066Sahrens #define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2) 49f65e61c0Sahrens #define MZAP_MAX_BLKSHIFT SPA_MAXBLOCKSHIFT 50fa9e4066Sahrens #define MZAP_MAX_BLKSZ (1 << MZAP_MAX_BLKSHIFT) 51fa9e4066Sahrens 52fa9e4066Sahrens typedef struct mzap_ent_phys { 53fa9e4066Sahrens uint64_t mze_value; 54fa9e4066Sahrens uint32_t mze_cd; 55fa9e4066Sahrens uint16_t mze_pad; /* in case we want to chain them someday */ 56fa9e4066Sahrens char mze_name[MZAP_NAME_LEN]; 57fa9e4066Sahrens } mzap_ent_phys_t; 58fa9e4066Sahrens 59fa9e4066Sahrens typedef struct mzap_phys { 60fa9e4066Sahrens uint64_t mz_block_type; /* ZBT_MICRO */ 61fa9e4066Sahrens uint64_t mz_salt; 62fa9e4066Sahrens uint64_t mz_pad[6]; 63fa9e4066Sahrens mzap_ent_phys_t mz_chunk[1]; 64fa9e4066Sahrens /* actually variable size depending on block size */ 65fa9e4066Sahrens } mzap_phys_t; 66fa9e4066Sahrens 67fa9e4066Sahrens typedef struct mzap_ent { 68fa9e4066Sahrens avl_node_t mze_node; 69fa9e4066Sahrens int mze_chunkid; 70fa9e4066Sahrens uint64_t mze_hash; 71fa9e4066Sahrens mzap_ent_phys_t mze_phys; 72fa9e4066Sahrens } mzap_ent_t; 73fa9e4066Sahrens 74fa9e4066Sahrens 75fa9e4066Sahrens /* 76fa9e4066Sahrens * The (fat) zap is stored in one object. It is an array of 77f65e61c0Sahrens * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of: 78fa9e4066Sahrens * 79fa9e4066Sahrens * ptrtbl fits in first block: 80fa9e4066Sahrens * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ... 81fa9e4066Sahrens * 82fa9e4066Sahrens * ptrtbl too big for first block: 83fa9e4066Sahrens * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ... 84fa9e4066Sahrens * 85fa9e4066Sahrens */ 86fa9e4066Sahrens 87fa9e4066Sahrens struct dmu_buf; 88fa9e4066Sahrens struct zap_leaf; 89fa9e4066Sahrens 90fa9e4066Sahrens #define ZBT_LEAF ((1ULL << 63) + 0) 91fa9e4066Sahrens #define ZBT_HEADER ((1ULL << 63) + 1) 92fa9e4066Sahrens #define ZBT_MICRO ((1ULL << 63) + 3) 93fa9e4066Sahrens /* any other values are ptrtbl blocks */ 94fa9e4066Sahrens 95f65e61c0Sahrens /* 96f65e61c0Sahrens * the embedded pointer table takes up half a block: 97f65e61c0Sahrens * block size / entry size (2^3) / 2 98f65e61c0Sahrens */ 99f65e61c0Sahrens #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1) 100f65e61c0Sahrens 101f65e61c0Sahrens /* 102f65e61c0Sahrens * The embedded pointer table starts half-way through the block. Since 103f65e61c0Sahrens * the pointer table itself is half the block, it starts at (64-bit) 104f65e61c0Sahrens * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)). 105f65e61c0Sahrens */ 106f65e61c0Sahrens #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \ 107f65e61c0Sahrens ((uint64_t *)(zap)->zap_f.zap_phys) \ 108f65e61c0Sahrens [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))] 109fa9e4066Sahrens 110fa9e4066Sahrens /* 111fa9e4066Sahrens * TAKE NOTE: 112fa9e4066Sahrens * If zap_phys_t is modified, zap_byteswap() must be modified. 113fa9e4066Sahrens */ 114fa9e4066Sahrens typedef struct zap_phys { 115fa9e4066Sahrens uint64_t zap_block_type; /* ZBT_HEADER */ 116fa9e4066Sahrens uint64_t zap_magic; /* ZAP_MAGIC */ 117fa9e4066Sahrens 118fa9e4066Sahrens struct zap_table_phys { 119fa9e4066Sahrens uint64_t zt_blk; /* starting block number */ 120fa9e4066Sahrens uint64_t zt_numblks; /* number of blocks */ 121fa9e4066Sahrens uint64_t zt_shift; /* bits to index it */ 122fa9e4066Sahrens uint64_t zt_nextblk; /* next (larger) copy start block */ 123fa9e4066Sahrens uint64_t zt_blks_copied; /* number source blocks copied */ 124fa9e4066Sahrens } zap_ptrtbl; 125fa9e4066Sahrens 126fa9e4066Sahrens uint64_t zap_freeblk; /* the next free block */ 127fa9e4066Sahrens uint64_t zap_num_leafs; /* number of leafs */ 128fa9e4066Sahrens uint64_t zap_num_entries; /* number of entries */ 129fa9e4066Sahrens uint64_t zap_salt; /* salt to stir into hash function */ 130f65e61c0Sahrens /* 131f65e61c0Sahrens * This structure is followed by padding, and then the embedded 132f65e61c0Sahrens * pointer table. The embedded pointer table takes up second 133f65e61c0Sahrens * half of the block. It is accessed using the 134f65e61c0Sahrens * ZAP_EMBEDDED_PTRTBL_ENT() macro. 135f65e61c0Sahrens */ 136fa9e4066Sahrens } zap_phys_t; 137fa9e4066Sahrens 138fa9e4066Sahrens typedef struct zap_table_phys zap_table_phys_t; 139fa9e4066Sahrens 140fa9e4066Sahrens typedef struct zap { 141fa9e4066Sahrens objset_t *zap_objset; 142fa9e4066Sahrens uint64_t zap_object; 143fa9e4066Sahrens struct dmu_buf *zap_dbuf; 144fa9e4066Sahrens krwlock_t zap_rwlock; 145fa9e4066Sahrens int zap_ismicro; 146fa9e4066Sahrens uint64_t zap_salt; 147fa9e4066Sahrens union { 148fa9e4066Sahrens struct { 149fa9e4066Sahrens zap_phys_t *zap_phys; 150fa9e4066Sahrens 151fa9e4066Sahrens /* 152fa9e4066Sahrens * zap_num_entries_mtx protects 153fa9e4066Sahrens * zap_num_entries 154fa9e4066Sahrens */ 155fa9e4066Sahrens kmutex_t zap_num_entries_mtx; 156f65e61c0Sahrens int zap_block_shift; 157fa9e4066Sahrens } zap_fat; 158fa9e4066Sahrens struct { 159fa9e4066Sahrens mzap_phys_t *zap_phys; 160fa9e4066Sahrens int16_t zap_num_entries; 161fa9e4066Sahrens int16_t zap_num_chunks; 162fa9e4066Sahrens int16_t zap_alloc_next; 163fa9e4066Sahrens avl_tree_t zap_avl; 164fa9e4066Sahrens } zap_micro; 165fa9e4066Sahrens } zap_u; 166fa9e4066Sahrens } zap_t; 167fa9e4066Sahrens 168fa9e4066Sahrens #define zap_f zap_u.zap_fat 169fa9e4066Sahrens #define zap_m zap_u.zap_micro 170fa9e4066Sahrens 171fa9e4066Sahrens uint64_t zap_hash(zap_t *zap, const char *name); 172fa9e4066Sahrens int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx, 173fa9e4066Sahrens krw_t lti, int fatreader, zap_t **zapp); 174fa9e4066Sahrens void zap_unlockdir(zap_t *zap); 175455d5089Sahrens void zap_evict(dmu_buf_t *db, void *vmzap); 176fa9e4066Sahrens 177fa9e4066Sahrens #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n)))) 178fa9e4066Sahrens 179fa9e4066Sahrens void fzap_byteswap(void *buf, size_t size); 180fa9e4066Sahrens int fzap_count(zap_t *zap, uint64_t *count); 181fa9e4066Sahrens int fzap_lookup(zap_t *zap, const char *name, 182fa9e4066Sahrens uint64_t integer_size, uint64_t num_integers, void *buf); 183fa9e4066Sahrens int fzap_add(zap_t *zap, const char *name, 184fa9e4066Sahrens uint64_t integer_size, uint64_t num_integers, 185fa9e4066Sahrens const void *val, dmu_tx_t *tx); 186fa9e4066Sahrens int fzap_update(zap_t *zap, const char *name, 187fa9e4066Sahrens int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx); 188fa9e4066Sahrens int fzap_length(zap_t *zap, const char *name, 189fa9e4066Sahrens uint64_t *integer_size, uint64_t *num_integers); 190fa9e4066Sahrens int fzap_remove(zap_t *zap, const char *name, dmu_tx_t *tx); 191fa9e4066Sahrens int fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za); 192fa9e4066Sahrens void fzap_get_stats(zap_t *zap, zap_stats_t *zs); 19387e5029aSahrens void zap_put_leaf(struct zap_leaf *l); 194fa9e4066Sahrens 195fa9e4066Sahrens int fzap_add_cd(zap_t *zap, const char *name, 196fa9e4066Sahrens uint64_t integer_size, uint64_t num_integers, 197ea8dc4b6Seschrock const void *val, uint32_t cd, dmu_tx_t *tx); 198fa9e4066Sahrens void fzap_upgrade(zap_t *zap, dmu_tx_t *tx); 199fa9e4066Sahrens 200fa9e4066Sahrens #ifdef __cplusplus 201fa9e4066Sahrens } 202fa9e4066Sahrens #endif 203fa9e4066Sahrens 204fa9e4066Sahrens #endif /* _SYS_ZAP_IMPL_H */ 205