3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 /*
26 * This file contains the top half of the zfs directory structure
27 * implementation. The bottom half is in zap_leaf.c.
28 *
29 * The zdir is an extendable hash data structure. There is a table of
30 * pointers to buckets (zap_t->zd_data->zd_leafs). The buckets are
31 * each a constant size and hold a variable number of directory entries.
32 * The buckets (aka "leaf nodes") are implemented in zap_leaf.c.
33 *
34 * The pointer table holds a power of 2 number of pointers.
35 * (1<<zap_t->zd_data->zd_phys->zd_prefix_len). The bucket pointed to
36 * by the pointer at index i in the table holds entries whose hash value
37 * has a zd_prefix_len - bit prefix
38 */
39
40 #include <sys/spa.h>
41 #include <sys/dmu.h>
42 #include <sys/zfs_context.h>
929
930 void
931 fzap_prefetch(zap_name_t *zn)
932 {
933 uint64_t idx, blk;
934 zap_t *zap = zn->zn_zap;
935 int bs;
936
937 idx = ZAP_HASH_IDX(zn->zn_hash,
938 zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
939 if (zap_idx_to_blk(zap, idx, &blk) != 0)
940 return;
941 bs = FZAP_BLOCK_SHIFT(zap);
942 dmu_prefetch(zap->zap_objset, zap->zap_object, blk << bs, 1 << bs);
943 }
944
945 /*
946 * Helper functions for consumers.
947 */
948
949 int
950 zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
951 char *name)
952 {
953 zap_cursor_t zc;
954 zap_attribute_t *za;
955 int err;
956
957 if (mask == 0)
958 mask = -1ULL;
959
960 za = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
961 for (zap_cursor_init(&zc, os, zapobj);
962 (err = zap_cursor_retrieve(&zc, za)) == 0;
963 zap_cursor_advance(&zc)) {
964 if ((za->za_first_integer & mask) == (value & mask)) {
965 (void) strcpy(name, za->za_name);
966 break;
967 }
968 }
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 */
25
26 /*
27 * This file contains the top half of the zfs directory structure
28 * implementation. The bottom half is in zap_leaf.c.
29 *
30 * The zdir is an extendable hash data structure. There is a table of
31 * pointers to buckets (zap_t->zd_data->zd_leafs). The buckets are
32 * each a constant size and hold a variable number of directory entries.
33 * The buckets (aka "leaf nodes") are implemented in zap_leaf.c.
34 *
35 * The pointer table holds a power of 2 number of pointers.
36 * (1<<zap_t->zd_data->zd_phys->zd_prefix_len). The bucket pointed to
37 * by the pointer at index i in the table holds entries whose hash value
38 * has a zd_prefix_len - bit prefix
39 */
40
41 #include <sys/spa.h>
42 #include <sys/dmu.h>
43 #include <sys/zfs_context.h>
930
931 void
932 fzap_prefetch(zap_name_t *zn)
933 {
934 uint64_t idx, blk;
935 zap_t *zap = zn->zn_zap;
936 int bs;
937
938 idx = ZAP_HASH_IDX(zn->zn_hash,
939 zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
940 if (zap_idx_to_blk(zap, idx, &blk) != 0)
941 return;
942 bs = FZAP_BLOCK_SHIFT(zap);
943 dmu_prefetch(zap->zap_objset, zap->zap_object, blk << bs, 1 << bs);
944 }
945
946 /*
947 * Helper functions for consumers.
948 */
949
950 uint64_t
951 zap_create_link(objset_t *os, dmu_object_type_t ot, uint64_t parent_obj,
952 const char *name, dmu_tx_t *tx)
953 {
954 uint64_t new_obj;
955
956 VERIFY((new_obj = zap_create(os, ot, DMU_OT_NONE, 0, tx)) > 0);
957 VERIFY(zap_add(os, parent_obj, name, sizeof (uint64_t), 1, &new_obj,
958 tx) == 0);
959
960 return (new_obj);
961 }
962
963 int
964 zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
965 char *name)
966 {
967 zap_cursor_t zc;
968 zap_attribute_t *za;
969 int err;
970
971 if (mask == 0)
972 mask = -1ULL;
973
974 za = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
975 for (zap_cursor_init(&zc, os, zapobj);
976 (err = zap_cursor_retrieve(&zc, za)) == 0;
977 zap_cursor_advance(&zc)) {
978 if ((za->za_first_integer & mask) == (value & mask)) {
979 (void) strcpy(name, za->za_name);
980 break;
981 }
982 }
|