FreeBSD ZFS
The Zettabyte File System

sys/zap_impl.h

Go to the documentation of this file.
00001 /*
00002  * CDDL HEADER START
00003  *
00004  * The contents of this file are subject to the terms of the
00005  * Common Development and Distribution License (the "License").
00006  * You may not use this file except in compliance with the License.
00007  *
00008  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
00009  * or http://www.opensolaris.org/os/licensing.
00010  * See the License for the specific language governing permissions
00011  * and limitations under the License.
00012  *
00013  * When distributing Covered Code, include this CDDL HEADER in each
00014  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
00015  * If applicable, add the following below this CDDL HEADER, with the
00016  * fields enclosed by brackets "[]" replaced with your own identifying
00017  * information: Portions Copyright [yyyy] [name of copyright owner]
00018  *
00019  * CDDL HEADER END
00020  */
00021 /*
00022  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
00023  */
00024 
00025 #ifndef _SYS_ZAP_IMPL_H
00026 #define _SYS_ZAP_IMPL_H
00027 
00028 #include <sys/zap.h>
00029 #include <sys/zfs_context.h>
00030 #include <sys/avl.h>
00031 
00032 #ifdef  __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 extern int fzap_default_block_shift;
00037 
00038 #define ZAP_MAGIC 0x2F52AB2ABULL
00039 
00040 #define FZAP_BLOCK_SHIFT(zap)   ((zap)->zap_f.zap_block_shift)
00041 
00042 #define MZAP_ENT_LEN            64
00043 #define MZAP_NAME_LEN           (MZAP_ENT_LEN - 8 - 4 - 2)
00044 #define MZAP_MAX_BLKSHIFT       SPA_MAXBLOCKSHIFT
00045 #define MZAP_MAX_BLKSZ          (1 << MZAP_MAX_BLKSHIFT)
00046 
00047 #define ZAP_NEED_CD             (-1U)
00048 
00049 typedef struct mzap_ent_phys {
00050         uint64_t mze_value;
00051         uint32_t mze_cd;
00052         uint16_t mze_pad;       
00053         char mze_name[MZAP_NAME_LEN];
00054 } mzap_ent_phys_t;
00055 
00056 typedef struct mzap_phys {
00057         uint64_t mz_block_type; 
00058         uint64_t mz_salt;
00059         uint64_t mz_normflags;
00060         uint64_t mz_pad[5];
00062         mzap_ent_phys_t mz_chunk[1];
00063 } mzap_phys_t;
00064 
00065 typedef struct mzap_ent {
00066         avl_node_t mze_node;
00067         int mze_chunkid;
00068         uint64_t mze_hash;
00069         uint32_t mze_cd; 
00070 } mzap_ent_t;
00071 
00072 #define MZE_PHYS(zap, mze) \
00073         (&(zap)->zap_m.zap_phys->mz_chunk[(mze)->mze_chunkid])
00074 
00075 /*
00076  * The (fat) zap is stored in one object. It is an array of
00077  * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
00078  *
00079  * ptrtbl fits in first block:
00080  *      [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
00081  *
00082  * ptrtbl too big for first block:
00083  *      [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
00084  *
00085  */
00086 
00087 struct dmu_buf;
00088 struct zap_leaf;
00089 
00090 #define ZBT_LEAF                ((1ULL << 63) + 0)
00091 #define ZBT_HEADER              ((1ULL << 63) + 1)
00092 #define ZBT_MICRO               ((1ULL << 63) + 3)
00093 /* any other values are ptrtbl blocks */
00094 
00099 #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
00100 
00106 #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
00107         ((uint64_t *)(zap)->zap_f.zap_phys) \
00108         [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
00109 
00118 typedef struct zap_phys {
00119         uint64_t zap_block_type;        
00120         uint64_t zap_magic;             
00122         struct zap_table_phys {
00123                 uint64_t zt_blk;        
00124                 uint64_t zt_numblks;    
00125                 uint64_t zt_shift;      
00126                 uint64_t zt_nextblk;    
00127                 uint64_t zt_blks_copied; 
00128         } zap_ptrtbl;
00129 
00130         uint64_t zap_freeblk;           
00131         uint64_t zap_num_leafs;         
00132         uint64_t zap_num_entries;       
00133         uint64_t zap_salt;              
00134         uint64_t zap_normflags;         
00135         uint64_t zap_flags;             
00136 } zap_phys_t;
00137 
00138 typedef struct zap_table_phys zap_table_phys_t;
00139 
00140 typedef struct zap {
00141         objset_t *zap_objset;
00142         uint64_t zap_object;
00143         struct dmu_buf *zap_dbuf;
00144         krwlock_t zap_rwlock;
00145         boolean_t zap_ismicro;
00146         int zap_normflags;
00147         uint64_t zap_salt;
00148         union {
00149                 struct {
00150                         zap_phys_t *zap_phys;
00151 
00153                         kmutex_t zap_num_entries_mtx;
00154                         int zap_block_shift;
00155                 } zap_fat;
00156                 struct {
00157                         mzap_phys_t *zap_phys;
00158                         int16_t zap_num_entries;
00159                         int16_t zap_num_chunks;
00160                         int16_t zap_alloc_next;
00161                         avl_tree_t zap_avl;
00162                 } zap_micro;
00163         } zap_u;
00164 } zap_t;
00165 
00166 typedef struct zap_name {
00167         zap_t *zn_zap;
00168         int zn_key_intlen;
00169         const void *zn_key_orig;
00170         int zn_key_orig_numints;
00171         const void *zn_key_norm;
00172         int zn_key_norm_numints;
00173         uint64_t zn_hash;
00174         matchtype_t zn_matchtype;
00175         char zn_normbuf[ZAP_MAXNAMELEN];
00176 } zap_name_t;
00177 
00178 #define zap_f   zap_u.zap_fat
00179 #define zap_m   zap_u.zap_micro
00180 
00181 boolean_t zap_match(zap_name_t *zn, const char *matchname);
00182 int zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
00183     krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp);
00184 void zap_unlockdir(zap_t *zap);
00185 void zap_evict(dmu_buf_t *db, void *vmzap);
00186 zap_name_t *zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt);
00187 void zap_name_free(zap_name_t *zn);
00188 int zap_hashbits(zap_t *zap);
00189 uint32_t zap_maxcd(zap_t *zap);
00190 uint64_t zap_getflags(zap_t *zap);
00191 
00192 #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n))))
00193 
00194 void fzap_byteswap(void *buf, size_t size);
00195 int fzap_count(zap_t *zap, uint64_t *count);
00196 int fzap_lookup(zap_name_t *zn,
00197     uint64_t integer_size, uint64_t num_integers, void *buf,
00198     char *realname, int rn_len, boolean_t *normalization_conflictp);
00199 void fzap_prefetch(zap_name_t *zn);
00200 int fzap_count_write(zap_name_t *zn, int add, uint64_t *towrite,
00201     uint64_t *tooverwrite);
00202 int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
00203     const void *val, dmu_tx_t *tx);
00204 int fzap_update(zap_name_t *zn,
00205     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
00206 int fzap_length(zap_name_t *zn,
00207     uint64_t *integer_size, uint64_t *num_integers);
00208 int fzap_remove(zap_name_t *zn, dmu_tx_t *tx);
00209 int fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za);
00210 void fzap_get_stats(zap_t *zap, zap_stats_t *zs);
00211 void zap_put_leaf(struct zap_leaf *l);
00212 
00213 int fzap_add_cd(zap_name_t *zn,
00214     uint64_t integer_size, uint64_t num_integers,
00215     const void *val, uint32_t cd, dmu_tx_t *tx);
00216 void fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags);
00217 int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn);
00218 
00219 #ifdef  __cplusplus
00220 }
00221 #endif
00222 
00223 #endif /* _SYS_ZAP_IMPL_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines