From 97f0b79796f9edda8d0f21136d0a8a1c179baedc Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Thu, 20 Nov 2008 12:11:21 -0800 Subject: [PATCH 1/2] Add feature-zap-cursor-to-key branch --- .topdeps | 1 + .topmsg | 6 ++++ zfs/lib/libzcommon/include/sys/zap.h | 5 +++ zfs/lib/libzcommon/include/sys/zap_impl.h | 1 + zfs/lib/libzpool/zap.c | 24 ++++++++++++++ zfs/lib/libzpool/zap_micro.c | 39 +++++++++++++++++++++++ 6 files changed, 76 insertions(+) create mode 100644 .topdeps create mode 100644 .topmsg diff --git a/.topdeps b/.topdeps new file mode 100644 index 0000000000..1f7391f92b --- /dev/null +++ b/.topdeps @@ -0,0 +1 @@ +master diff --git a/.topmsg b/.topmsg new file mode 100644 index 0000000000..7727ce8d3f --- /dev/null +++ b/.topmsg @@ -0,0 +1,6 @@ +From: Brian Behlendorf +Subject: [PATCH] feature zap cursor to key + +Add a ZAP API to move a ZAP cursor to a given key + +Signed-off-by: Brian Behlendorf diff --git a/zfs/lib/libzcommon/include/sys/zap.h b/zfs/lib/libzcommon/include/sys/zap.h index df1ef8c9d2..62403d451c 100644 --- a/zfs/lib/libzcommon/include/sys/zap.h +++ b/zfs/lib/libzcommon/include/sys/zap.h @@ -301,6 +301,11 @@ void zap_cursor_advance(zap_cursor_t *zc); */ uint64_t zap_cursor_serialize(zap_cursor_t *zc); +/* + * Advance the cursor to the attribute having the key. + */ +int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt); + /* * Initialize a zap cursor pointing to the position recorded by * zap_cursor_serialize (in the "serialized" argument). You can also diff --git a/zfs/lib/libzcommon/include/sys/zap_impl.h b/zfs/lib/libzcommon/include/sys/zap_impl.h index 8517471984..7b9c8a2b77 100644 --- a/zfs/lib/libzcommon/include/sys/zap_impl.h +++ b/zfs/lib/libzcommon/include/sys/zap_impl.h @@ -210,6 +210,7 @@ int fzap_add_cd(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers, const void *val, uint32_t cd, dmu_tx_t *tx); void fzap_upgrade(zap_t *zap, dmu_tx_t *tx); +int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn); #ifdef __cplusplus } diff --git a/zfs/lib/libzpool/zap.c b/zfs/lib/libzpool/zap.c index f4f456ce8b..0484a29ab5 100644 --- a/zfs/lib/libzpool/zap.c +++ b/zfs/lib/libzpool/zap.c @@ -1029,6 +1029,30 @@ zap_stats_ptrtbl(zap_t *zap, uint64_t *tbl, int len, zap_stats_t *zs) } } +int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn) +{ + int err; + zap_leaf_t *l; + zap_entry_handle_t zeh; + uint64_t hash; + + if (zn->zn_name_orij && strlen(zn->zn_name_orij) > ZAP_MAXNAMELEN) + return (E2BIG); + + err = zap_deref_leaf(zc->zc_zap, zn->zn_hash, NULL, RW_READER, &l); + if (err != 0) + return (err); + + err = zap_leaf_lookup(l, zn, &zeh); + if (err != 0) + return (err); + + zc->zc_leaf = l; + zc->zc_hash = zeh.zeh_hash; + zc->zc_cd = zeh.zeh_cd; + return 0; +} + void fzap_get_stats(zap_t *zap, zap_stats_t *zs) { diff --git a/zfs/lib/libzpool/zap_micro.c b/zfs/lib/libzpool/zap_micro.c index 7aea76b311..c633be4035 100644 --- a/zfs/lib/libzpool/zap_micro.c +++ b/zfs/lib/libzpool/zap_micro.c @@ -1045,6 +1045,45 @@ zap_cursor_advance(zap_cursor_t *zc) } } +int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt) +{ + int err = 0; + mzap_ent_t *mze; + zap_name_t *zn; + + if (zc->zc_zap == NULL) { + err = zap_lockdir(zc->zc_objset, zc->zc_zapobj, NULL, + RW_READER, TRUE, FALSE, &zc->zc_zap); + if (err) + return (err); + } else { + rw_enter(&zc->zc_zap->zap_rwlock, RW_READER); + } + + zn = zap_name_alloc(zc->zc_zap, name, mt); + if (zn == NULL) { + rw_exit(&zc->zc_zap->zap_rwlock); + return (ENOTSUP); + } + + if (!zc->zc_zap->zap_ismicro) { + err = fzap_cursor_move_to_key(zc, zn); + } else { + mze = mze_find(zn); + if (mze == NULL) { + err = (ENOENT); + goto out; + } + zc->zc_hash = mze->mze_hash; + zc->zc_cd = mze->mze_phys.mze_cd; + } + +out: + zap_name_free(zn); + rw_exit(&zc->zc_zap->zap_rwlock); + return (err); +} + int zap_get_stats(objset_t *os, uint64_t zapobj, zap_stats_t *zs) { From 578cd5b14fef912972d2d768b949fca9818b101a Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 24 Nov 2008 14:52:12 -0800 Subject: [PATCH 2/2] Remove unused variable hash --- zfs/lib/libzpool/zap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/zfs/lib/libzpool/zap.c b/zfs/lib/libzpool/zap.c index 0484a29ab5..da8f312617 100644 --- a/zfs/lib/libzpool/zap.c +++ b/zfs/lib/libzpool/zap.c @@ -1034,7 +1034,6 @@ int fzap_cursor_move_to_key(zap_cursor_t *zc, zap_name_t *zn) int err; zap_leaf_t *l; zap_entry_handle_t zeh; - uint64_t hash; if (zn->zn_name_orij && strlen(zn->zn_name_orij) > ZAP_MAXNAMELEN) return (E2BIG);