FreeBSD ZFS
The Zettabyte File System

sys/zap.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  * Copyright (c) 2012 by Delphix. All rights reserved.
00024  */
00025 
00026 #ifndef _SYS_ZAP_H
00027 #define _SYS_ZAP_H
00028 
00075 /*
00076  * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C
00077  * strings) for the names of attributes, rather than a byte string
00078  * bounded by an explicit length.  If some day we want to support names
00079  * in character sets which have embedded zeros (eg. UTF-16, UTF-32),
00080  * we'll have to add routines for using length-bounded strings.
00081  */
00082 
00083 #include <sys/dmu.h>
00084 
00085 #ifdef  __cplusplus
00086 extern "C" {
00087 #endif
00088 
00092 typedef enum matchtype
00093 {
00095         MT_EXACT,
00100         MT_BEST,
00106         MT_FIRST
00107 } matchtype_t;
00108 
00109 typedef enum zap_flags {
00113         ZAP_FLAG_HASH64 = 1 << 0,
00115         ZAP_FLAG_UINT64_KEY = 1 << 1,
00120         ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
00121 } zap_flags_t;
00122 
00136 uint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
00137     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
00138 uint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
00139     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
00140 uint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
00141     dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
00142     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
00143 uint64_t zap_create_link(objset_t *os, dmu_object_type_t ot,
00144     uint64_t parent_obj, const char *name, dmu_tx_t *tx);
00145 
00150 int zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
00151     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
00152 int zap_create_claim_norm(objset_t *ds, uint64_t obj,
00153     int normflags, dmu_object_type_t ot,
00154     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
00155 
00156 /*
00157  * The zapobj passed in must be a valid ZAP object for all of the
00158  * following routines.
00159  */
00160 
00166 int zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
00167 
00168 /*
00169  * Manipulate attributes.
00170  *
00171  * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
00172  */
00173 
00191 int zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
00192     uint64_t integer_size, uint64_t num_integers, void *buf);
00193 
00201 int zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
00202     uint64_t integer_size, uint64_t num_integers, void *buf,
00203     matchtype_t mt, char *realname, int rn_len,
00204     boolean_t *ncp);
00205 int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
00206     int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
00207 int zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
00208 int zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
00209     int key_numints);
00210 
00211 int zap_count_write(objset_t *os, uint64_t zapobj, const char *name,
00212     int add, uint64_t *towrite, uint64_t *tooverwrite);
00213 
00219 int zap_add(objset_t *ds, uint64_t zapobj, const char *key,
00220     int integer_size, uint64_t num_integers,
00221     const void *val, dmu_tx_t *tx);
00222 int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
00223     int key_numints, int integer_size, uint64_t num_integers,
00224     const void *val, dmu_tx_t *tx);
00225 
00234 int zap_update(objset_t *ds, uint64_t zapobj, const char *name,
00235     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
00236 int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
00237     int key_numints,
00238     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
00239 
00246 int zap_length(objset_t *ds, uint64_t zapobj, const char *name,
00247     uint64_t *integer_size, uint64_t *num_integers);
00248 int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
00249     int key_numints, uint64_t *integer_size, uint64_t *num_integers);
00250 
00256 int zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
00257 int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
00258     matchtype_t mt, dmu_tx_t *tx);
00259 int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
00260     int key_numints, dmu_tx_t *tx);
00261 
00267 int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
00268 
00280 int zap_value_search(objset_t *os, uint64_t zapobj,
00281     uint64_t value, uint64_t mask, char *name);
00282 
00288 int zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
00289 
00293 int zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
00294     uint64_t value, dmu_tx_t *tx);
00295 
00299 int zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
00300     dmu_tx_t *tx);
00301 
00306 int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
00307 int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
00308 int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
00309 int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
00310     dmu_tx_t *tx);
00311 
00315 int zap_add_int_key(objset_t *os, uint64_t obj,
00316     uint64_t key, uint64_t value, dmu_tx_t *tx);
00317 int zap_update_int_key(objset_t *os, uint64_t obj,
00318     uint64_t key, uint64_t value, dmu_tx_t *tx);
00319 int zap_lookup_int_key(objset_t *os, uint64_t obj,
00320     uint64_t key, uint64_t *valuep);
00321 
00322 int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
00323     dmu_tx_t *tx);
00324 
00325 struct zap;
00326 struct zap_leaf;
00327 typedef struct zap_cursor {
00328         /* This structure is opaque! */
00329         objset_t *zc_objset;
00330         struct zap *zc_zap;
00331         struct zap_leaf *zc_leaf;
00332         uint64_t zc_zapobj;
00333         uint64_t zc_serialized;
00334         uint64_t zc_hash;
00335         uint32_t zc_cd;
00336 } zap_cursor_t;
00337 
00338 typedef struct {
00339         int za_integer_length;
00344         boolean_t za_normalization_conflict;
00345         uint64_t za_num_integers;
00346         uint64_t za_first_integer;
00347         char za_name[MAXNAMELEN];
00348 } zap_attribute_t;
00349 
00350 /*
00351  * The interface for listing all the attributes of a zapobj can be
00352  * thought of as cursor moving down a list of the attributes one by
00353  * one.  The cookie returned by the zap_cursor_serialize routine is
00354  * persistent across system calls (and across reboot, even).
00355  */
00356 
00361 void zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
00362 void zap_cursor_fini(zap_cursor_t *zc);
00363 
00369 int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
00370 
00374 void zap_cursor_advance(zap_cursor_t *zc);
00375 
00383 uint64_t zap_cursor_serialize(zap_cursor_t *zc);
00384 
00385 /*
00386  * Advance the cursor to the attribute having the given key.
00387  */
00388 int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt);
00389 
00390 /*
00391  * Initialize a zap cursor pointing to the position recorded by
00392  * zap_cursor_serialize (in the "serialized" argument).  You can also
00393  * use a "serialized" argument of 0 to start at the beginning of the
00394  * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
00395  * zap_cursor_init(...).)
00396  */
00397 void zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
00398     uint64_t zapobj, uint64_t serialized);
00399 
00400 
00401 #define ZAP_HISTOGRAM_SIZE 10
00402 
00403 typedef struct zap_stats {
00409         uint64_t zs_ptrtbl_len;
00410 
00411         uint64_t zs_blocksize;          
00419         uint64_t zs_num_blocks;
00420 
00425         uint64_t zs_ptrtbl_nextblk;       
00426         uint64_t zs_ptrtbl_blks_copied;   
00427         uint64_t zs_ptrtbl_zt_blk;        
00428         uint64_t zs_ptrtbl_zt_numblks;    
00429         uint64_t zs_ptrtbl_zt_shift;      
00436         uint64_t zs_block_type;         
00437         uint64_t zs_magic;              
00438         uint64_t zs_num_leafs;          
00439         uint64_t zs_num_entries;        
00440         uint64_t zs_salt;               
00457         uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
00458 
00466         uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
00467 
00472         uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
00473 
00479         uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
00480 
00487         uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
00489 } zap_stats_t;
00490 
00498 int zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
00499 
00500 #ifdef  __cplusplus
00501 }
00502 #endif
00503 
00504 #endif  /* _SYS_ZAP_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines