]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zap_micro.c
Illumos 4171, 4172
[mirror_zfs.git] / module / zfs / zap_micro.c
index 178ab02719a5b0edde1ebbf4670ab499289f1e8a..73d84b55431ff62b5a63756beed9dead74a8b36b 100644 (file)
@@ -20,7 +20,7 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011 by Delphix. All rights reserved.
+ * Copyright (c) 2013 by Delphix. All rights reserved.
  */
 
 #include <sys/zio.h>
@@ -202,7 +202,7 @@ zap_name_alloc(zap_t *zap, const char *key, matchtype_t mt)
 zap_name_t *
 zap_name_alloc_uint64(zap_t *zap, const uint64_t *key, int numints)
 {
-       zap_name_t *zn = kmem_alloc(sizeof (zap_name_t), KM_SLEEP);
+       zap_name_t *zn = kmem_alloc(sizeof (zap_name_t), KM_PUSHPAGE);
 
        ASSERT(zap->zap_normflags == 0);
        zn->zn_zap = zap;
@@ -461,7 +461,7 @@ zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
        {
                dmu_object_info_t doi;
                dmu_object_info_from_db(db, &doi);
-               ASSERT(dmu_ot[doi.doi_type].ot_byteswap == zap_byteswap);
+               ASSERT3U(DMU_OT_BYTESWAP(doi.doi_type), ==, DMU_BSWAP_ZAP);
        }
 #endif
 
@@ -506,7 +506,7 @@ zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
                        return (mzap_upgrade(zapp, tx, 0));
                }
                err = dmu_object_set_blocksize(os, obj, newsz, 0, tx);
-               ASSERT3U(err, ==, 0);
+               ASSERT0(err);
                zap->zap_m.zap_num_chunks =
                    db->db_size / MZAP_ENT_LEN - 1;
        }
@@ -572,7 +572,7 @@ mzap_upgrade(zap_t **zapp, dmu_tx_t *tx, zap_flags_t flags)
        return (err);
 }
 
-static void
+void
 mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
     dmu_tx_t *tx)
 {
@@ -585,7 +585,7 @@ mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
        {
                dmu_object_info_t doi;
                dmu_object_info_from_db(db, &doi);
-               ASSERT(dmu_ot[doi.doi_type].ot_byteswap == zap_byteswap);
+               ASSERT3U(DMU_OT_BYTESWAP(doi.doi_type), ==, DMU_BSWAP_ZAP);
        }
 #endif
 
@@ -780,7 +780,7 @@ zap_lookup_norm(objset_t *os, uint64_t zapobj, const char *name,
        zn = zap_name_alloc(zap, name, mt);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
 
        if (!zap->zap_ismicro) {
@@ -789,12 +789,12 @@ zap_lookup_norm(objset_t *os, uint64_t zapobj, const char *name,
        } else {
                mze = mze_find(zn);
                if (mze == NULL) {
-                       err = ENOENT;
+                       err = SET_ERROR(ENOENT);
                } else {
                        if (num_integers < 1) {
-                               err = EOVERFLOW;
+                               err = SET_ERROR(EOVERFLOW);
                        } else if (integer_size != 8) {
-                               err = EINVAL;
+                               err = SET_ERROR(EINVAL);
                        } else {
                                *(uint64_t *)buf =
                                    MZE_PHYS(zap, mze)->mze_value;
@@ -826,7 +826,7 @@ zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
        zn = zap_name_alloc_uint64(zap, key, key_numints);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
 
        fzap_prefetch(zn);
@@ -849,7 +849,7 @@ zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
        zn = zap_name_alloc_uint64(zap, key, key_numints);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
 
        err = fzap_lookup(zn, integer_size, num_integers, buf,
@@ -862,8 +862,8 @@ zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
 int
 zap_contains(objset_t *os, uint64_t zapobj, const char *name)
 {
-       int err = (zap_lookup_norm(os, zapobj, name, 0,
-           0, NULL, MT_EXACT, NULL, 0, NULL));
+       int err = zap_lookup_norm(os, zapobj, name, 0,
+           0, NULL, MT_EXACT, NULL, 0, NULL);
        if (err == EOVERFLOW || err == EINVAL)
                err = 0; /* found, but skipped reading the value */
        return (err);
@@ -884,14 +884,14 @@ zap_length(objset_t *os, uint64_t zapobj, const char *name,
        zn = zap_name_alloc(zap, name, MT_EXACT);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        if (!zap->zap_ismicro) {
                err = fzap_length(zn, integer_size, num_integers);
        } else {
                mze = mze_find(zn);
                if (mze == NULL) {
-                       err = ENOENT;
+                       err = SET_ERROR(ENOENT);
                } else {
                        if (integer_size)
                                *integer_size = 8;
@@ -918,7 +918,7 @@ zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
        zn = zap_name_alloc_uint64(zap, key, key_numints);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        err = fzap_length(zn, integer_size, num_integers);
        zap_name_free(zn);
@@ -938,7 +938,8 @@ mzap_addent(zap_name_t *zn, uint64_t value)
 
 #ifdef ZFS_DEBUG
        for (i = 0; i < zap->zap_m.zap_num_chunks; i++) {
-               ASSERTV(mzap_ent_phys_t *mze=&zap->zap_m.zap_phys->mz_chunk[i]);
+               ASSERTV(mzap_ent_phys_t *mze);
+               ASSERT(mze = &zap->zap_m.zap_phys->mz_chunk[i]);
                ASSERT(strcmp(zn->zn_key_orig, mze->mze_name) != 0);
        }
 #endif
@@ -987,7 +988,7 @@ zap_add(objset_t *os, uint64_t zapobj, const char *key,
        zn = zap_name_alloc(zap, key, MT_EXACT);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        if (!zap->zap_ismicro) {
                err = fzap_add(zn, integer_size, num_integers, val, tx);
@@ -1001,7 +1002,7 @@ zap_add(objset_t *os, uint64_t zapobj, const char *key,
        } else {
                mze = mze_find(zn);
                if (mze != NULL) {
-                       err = EEXIST;
+                       err = SET_ERROR(EEXIST);
                } else {
                        mzap_addent(zn, *intval);
                }
@@ -1028,7 +1029,7 @@ zap_add_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
        zn = zap_name_alloc_uint64(zap, key, key_numints);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        err = fzap_add(zn, integer_size, num_integers, val, tx);
        zap = zn->zn_zap;       /* fzap_add() may change zap */
@@ -1065,7 +1066,7 @@ zap_update(objset_t *os, uint64_t zapobj, const char *name,
        zn = zap_name_alloc(zap, name, MT_EXACT);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        if (!zap->zap_ismicro) {
                err = fzap_update(zn, integer_size, num_integers, val, tx);
@@ -1110,7 +1111,7 @@ zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
        zn = zap_name_alloc_uint64(zap, key, key_numints);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        err = fzap_update(zn, integer_size, num_integers, val, tx);
        zap = zn->zn_zap;       /* fzap_update() may change zap */
@@ -1141,14 +1142,14 @@ zap_remove_norm(objset_t *os, uint64_t zapobj, const char *name,
        zn = zap_name_alloc(zap, name, mt);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        if (!zap->zap_ismicro) {
                err = fzap_remove(zn, tx);
        } else {
                mze = mze_find(zn);
                if (mze == NULL) {
-                       err = ENOENT;
+                       err = SET_ERROR(ENOENT);
                } else {
                        zap->zap_m.zap_num_entries--;
                        bzero(&zap->zap_m.zap_phys->mz_chunk[mze->mze_chunkid],
@@ -1175,7 +1176,7 @@ zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
        zn = zap_name_alloc_uint64(zap, key, key_numints);
        if (zn == NULL) {
                zap_unlockdir(zap);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
        err = fzap_remove(zn, tx);
        zap_name_free(zn);
@@ -1253,7 +1254,7 @@ zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
        mzap_ent_t *mze;
 
        if (zc->zc_hash == -1ULL)
-               return (ENOENT);
+               return (SET_ERROR(ENOENT));
 
        if (zc->zc_zap == NULL) {
                int hb;
@@ -1279,8 +1280,6 @@ zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
        if (!zc->zc_zap->zap_ismicro) {
                err = fzap_cursor_retrieve(zc->zc_zap, zc, za);
        } else {
-               err = ENOENT;
-
                mze_tofind.mze_hash = zc->zc_hash;
                mze_tofind.mze_cd = zc->zc_cd;
 
@@ -1303,6 +1302,7 @@ zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
                        err = 0;
                } else {
                        zc->zc_hash = -1ULL;
+                       err = SET_ERROR(ENOENT);
                }
        }
        rw_exit(&zc->zc_zap->zap_rwlock);
@@ -1336,7 +1336,7 @@ zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt)
        zn = zap_name_alloc(zc->zc_zap, name, mt);
        if (zn == NULL) {
                rw_exit(&zc->zc_zap->zap_rwlock);
-               return (ENOTSUP);
+               return (SET_ERROR(ENOTSUP));
        }
 
        if (!zc->zc_zap->zap_ismicro) {
@@ -1344,7 +1344,7 @@ zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt)
        } else {
                mze = mze_find(zn);
                if (mze == NULL) {
-                       err = ENOENT;
+                       err = SET_ERROR(ENOENT);
                        goto out;
                }
                zc->zc_hash = mze->mze_hash;