1 Add a ZAP API to move a ZAP cursor to a given key.
3 Index: zfs+chaos4/lib/libzfscommon/include/sys/zap.h
4 ===================================================================
5 --- zfs+chaos4.orig/lib/libzfscommon/include/sys/zap.h
6 +++ zfs+chaos4/lib/libzfscommon/include/sys/zap.h
7 @@ -302,6 +302,11 @@ void zap_cursor_advance(zap_cursor_t *zc
8 uint64_t zap_cursor_serialize(zap_cursor_t *zc);
11 + * Advance the cursor to the attribute having the key.
13 +int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt);
16 * Initialize a zap cursor pointing to the position recorded by
17 * zap_cursor_serialize (in the "serialized" argument). You can also
18 * use a "serialized" argument of 0 to start at the beginning of the
19 Index: zfs+chaos4/lib/libzfscommon/include/sys/zap_impl.h
20 ===================================================================
21 --- zfs+chaos4.orig/lib/libzfscommon/include/sys/zap_impl.h
22 +++ zfs+chaos4/lib/libzfscommon/include/sys/zap_impl.h
23 @@ -210,6 +210,7 @@ int fzap_add_cd(zap_name_t *zn,
24 uint64_t integer_size, uint64_t num_integers,
25 const void *val, uint32_t cd, dmu_tx_t *tx);
26 void fzap_upgrade(zap_t *zap, dmu_tx_t *tx);
27 +int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn);
31 Index: zfs+chaos4/lib/libzpool/zap.c
32 ===================================================================
33 --- zfs+chaos4.orig/lib/libzpool/zap.c
34 +++ zfs+chaos4/lib/libzpool/zap.c
35 @@ -1029,6 +1029,30 @@ zap_stats_ptrtbl(zap_t *zap, uint64_t *t
39 +int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn)
43 + zap_entry_handle_t zeh;
46 + if (zn->zn_name_orij && strlen(zn->zn_name_orij) > ZAP_MAXNAMELEN)
49 + err = zap_deref_leaf(zc->zc_zap, zn->zn_hash, NULL, RW_READER, &l);
53 + err = zap_leaf_lookup(l, zn, &zeh);
58 + zc->zc_hash = zeh.zeh_hash;
59 + zc->zc_cd = zeh.zeh_cd;
64 fzap_get_stats(zap_t *zap, zap_stats_t *zs)
66 Index: zfs+chaos4/lib/libzpool/zap_micro.c
67 ===================================================================
68 --- zfs+chaos4.orig/lib/libzpool/zap_micro.c
69 +++ zfs+chaos4/lib/libzpool/zap_micro.c
70 @@ -1045,6 +1045,45 @@ zap_cursor_advance(zap_cursor_t *zc)
74 +int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt)
80 + if (zc->zc_zap == NULL) {
81 + err = zap_lockdir(zc->zc_objset, zc->zc_zapobj, NULL,
82 + RW_READER, TRUE, FALSE, &zc->zc_zap);
86 + rw_enter(&zc->zc_zap->zap_rwlock, RW_READER);
89 + zn = zap_name_alloc(zc->zc_zap, name, mt);
91 + rw_exit(&zc->zc_zap->zap_rwlock);
95 + if (!zc->zc_zap->zap_ismicro) {
96 + err = fzap_cursor_move_to_key(zc, zn);
103 + zc->zc_hash = mze->mze_hash;
104 + zc->zc_cd = mze->mze_phys.mze_cd;
109 + rw_exit(&zc->zc_zap->zap_rwlock);
114 zap_get_stats(objset_t *os, uint64_t zapobj, zap_stats_t *zs)