]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zap_micro.c
Add zap_prefetch() interface
[mirror_zfs.git] / module / zfs / zap_micro.c
index a065e2533c418e7a55e0bc66bfa75aa939bf1bae..85b465b0528465fd8673fecebafe5367526c55c5 100644 (file)
@@ -21,6 +21,7 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
+ * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
  */
 
 #include <sys/zio.h>
@@ -33,6 +34,7 @@
 #include <sys/zap_leaf.h>
 #include <sys/avl.h>
 #include <sys/arc.h>
+#include <sys/dmu_objset.h>
 
 #ifdef _KERNEL
 #include <sys/sunddi.h>
@@ -386,7 +388,8 @@ mzap_open(objset_t *os, uint64_t obj, dmu_buf_t *db)
         * it, because zap_lockdir() checks zap_ismicro without the lock
         * held.
         */
-       winner = dmu_buf_set_user(db, zap, zap_evict);
+       dmu_buf_init_user(&zap->zap_dbu, zap_evict, &zap->zap_dbuf);
+       winner = dmu_buf_set_user(db, &zap->zap_dbu);
 
        if (winner != NULL) {
                rw_exit(&zap->zap_rwlock);
@@ -481,7 +484,7 @@ zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
                /* it was upgraded, now we only need reader */
                ASSERT(lt == RW_WRITER);
                ASSERT(RW_READER ==
-                   (!zap->zap_ismicro && fatreader) ? RW_READER : lti);
+                   ((!zap->zap_ismicro && fatreader) ? RW_READER : lti));
                rw_downgrade(&zap->zap_rwlock);
                lt = RW_READER;
        }
@@ -652,9 +655,9 @@ zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
        uint64_t obj = dmu_object_alloc(os, ot, 0, bonustype, bonuslen, tx);
 
        ASSERT(leaf_blockshift >= SPA_MINBLOCKSHIFT &&
-           leaf_blockshift <= SPA_MAXBLOCKSHIFT &&
+           leaf_blockshift <= SPA_OLD_MAXBLOCKSHIFT &&
            indirect_blockshift >= SPA_MINBLOCKSHIFT &&
-           indirect_blockshift <= SPA_MAXBLOCKSHIFT);
+           indirect_blockshift <= SPA_OLD_MAXBLOCKSHIFT);
 
        VERIFY(dmu_object_set_blocksize(os, obj,
            1ULL << leaf_blockshift, indirect_blockshift, tx) == 0);
@@ -675,11 +678,10 @@ zap_destroy(objset_t *os, uint64_t zapobj, dmu_tx_t *tx)
        return (dmu_object_free(os, zapobj, tx));
 }
 
-_NOTE(ARGSUSED(0))
 void
-zap_evict(dmu_buf_t *db, void *vzap)
+zap_evict(void *dbu)
 {
-       zap_t *zap = vzap;
+       zap_t *zap = dbu;
 
        rw_destroy(&zap->zap_rwlock);
 
@@ -811,6 +813,28 @@ zap_lookup_norm(objset_t *os, uint64_t zapobj, const char *name,
        return (err);
 }
 
+int
+zap_prefetch(objset_t *os, uint64_t zapobj, const char *name)
+{
+       zap_t *zap;
+       int err;
+       zap_name_t *zn;
+
+       err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, &zap);
+       if (err)
+               return (err);
+       zn = zap_name_alloc(zap, name, MT_EXACT);
+       if (zn == NULL) {
+               zap_unlockdir(zap);
+               return (SET_ERROR(ENOTSUP));
+       }
+
+       fzap_prefetch(zn);
+       zap_name_free(zn);
+       zap_unlockdir(zap);
+       return (err);
+}
+
 int
 zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
     int key_numints)
@@ -1316,46 +1340,6 @@ zap_cursor_advance(zap_cursor_t *zc)
        zc->zc_cd++;
 }
 
-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 (SET_ERROR(ENOTSUP));
-       }
-
-       if (!zc->zc_zap->zap_ismicro) {
-               err = fzap_cursor_move_to_key(zc, zn);
-       } else {
-               mze = mze_find(zn);
-               if (mze == NULL) {
-                       err = SET_ERROR(ENOENT);
-                       goto out;
-               }
-               zc->zc_hash = mze->mze_hash;
-               zc->zc_cd = mze->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)
 {
@@ -1386,7 +1370,6 @@ zap_count_write(objset_t *os, uint64_t zapobj, const char *name, int add,
        zap_t *zap;
        int err = 0;
 
-
        /*
         * Since, we don't have a name, we cannot figure out which blocks will
         * be affected in this operation. So, account for the worst case :
@@ -1399,7 +1382,7 @@ zap_count_write(objset_t *os, uint64_t zapobj, const char *name, int add,
         * large microzap results in a promotion to fatzap.
         */
        if (name == NULL) {
-               *towrite += (3 + (add ? 4 : 0)) * SPA_MAXBLOCKSIZE;
+               *towrite += (3 + (add ? 4 : 0)) * SPA_OLD_MAXBLOCKSIZE;
                return (err);
        }
 
@@ -1423,7 +1406,7 @@ zap_count_write(objset_t *os, uint64_t zapobj, const char *name, int add,
                        /*
                         * We treat this case as similar to (name == NULL)
                         */
-                       *towrite += (3 + (add ? 4 : 0)) * SPA_MAXBLOCKSIZE;
+                       *towrite += (3 + (add ? 4 : 0)) * SPA_OLD_MAXBLOCKSIZE;
                }
        } else {
                /*
@@ -1442,12 +1425,12 @@ zap_count_write(objset_t *os, uint64_t zapobj, const char *name, int add,
                 *                      ptrtbl blocks
                 */
                if (dmu_buf_freeable(zap->zap_dbuf))
-                       *tooverwrite += SPA_MAXBLOCKSIZE;
+                       *tooverwrite += MZAP_MAX_BLKSZ;
                else
-                       *towrite += SPA_MAXBLOCKSIZE;
+                       *towrite += MZAP_MAX_BLKSZ;
 
                if (add) {
-                       *towrite += 4 * SPA_MAXBLOCKSIZE;
+                       *towrite += 4 * MZAP_MAX_BLKSZ;
                }
        }
 
@@ -1466,6 +1449,7 @@ EXPORT_SYMBOL(zap_lookup);
 EXPORT_SYMBOL(zap_lookup_norm);
 EXPORT_SYMBOL(zap_lookup_uint64);
 EXPORT_SYMBOL(zap_contains);
+EXPORT_SYMBOL(zap_prefetch);
 EXPORT_SYMBOL(zap_prefetch_uint64);
 EXPORT_SYMBOL(zap_count_write);
 EXPORT_SYMBOL(zap_add);
@@ -1493,7 +1477,6 @@ EXPORT_SYMBOL(zap_cursor_fini);
 EXPORT_SYMBOL(zap_cursor_retrieve);
 EXPORT_SYMBOL(zap_cursor_advance);
 EXPORT_SYMBOL(zap_cursor_serialize);
-EXPORT_SYMBOL(zap_cursor_move_to_key);
 EXPORT_SYMBOL(zap_cursor_init_serialized);
 EXPORT_SYMBOL(zap_get_stats);
 #endif