]> granicus.if.org Git - zfs/commitdiff
Illumos 5045 - use atomic_{inc,dec}_* instead of atomic_add_*
authorJosef 'Jeff' Sipek <josef.sipek@nexenta.com>
Thu, 14 Jan 2016 00:37:41 +0000 (16:37 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 15 Jan 2016 23:38:36 +0000 (15:38 -0800)
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Approved by: Robert Mustacchi <rm@joyent.com>

References:
  https://www.illumos.org/issues/5045
  https://github.com/illumos/illumos-gate/commit/1a5e258

Porting notes:
- All changes to non-ZFS files dropped.
- Changes to zfs_vfsops.c dropped because they were Illumos specific.

Ported-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4220

include/sys/refcount.h
module/zfs/dbuf.c
module/zfs/fm.c
module/zfs/spa.c
module/zfs/vdev_cache.c
module/zfs/vdev_label.c
module/zfs/zio_inject.c

index b69c46cf72a314c8df662d1c70406ccf97eea993..d3f90fdc6277b85e6205daf5d73726103a774d93 100644 (file)
@@ -86,8 +86,8 @@ typedef struct refcount {
 #define        refcount_destroy_many(rc, number) ((rc)->rc_count = 0)
 #define        refcount_is_zero(rc) ((rc)->rc_count == 0)
 #define        refcount_count(rc) ((rc)->rc_count)
-#define        refcount_add(rc, holder) atomic_add_64_nv(&(rc)->rc_count, 1)
-#define        refcount_remove(rc, holder) atomic_add_64_nv(&(rc)->rc_count, -1)
+#define        refcount_add(rc, holder) atomic_inc_64_nv(&(rc)->rc_count)
+#define        refcount_remove(rc, holder) atomic_dec_64_nv(&(rc)->rc_count)
 #define        refcount_add_many(rc, number, holder) \
        atomic_add_64_nv(&(rc)->rc_count, number)
 #define        refcount_remove_many(rc, number, holder) \
index e65f573e280ee49331f3c42ba1034ea158aea5a2..3d3b7696368f1572accae520488c84659f98b7a7 100644 (file)
@@ -230,7 +230,7 @@ dbuf_hash_insert(dmu_buf_impl_t *db)
        db->db_hash_next = h->hash_table[idx];
        h->hash_table[idx] = db;
        mutex_exit(DBUF_HASH_MUTEX(h, idx));
-       atomic_add_64(&dbuf_hash_count, 1);
+       atomic_inc_64(&dbuf_hash_count);
 
        return (NULL);
 }
@@ -266,7 +266,7 @@ dbuf_hash_remove(dmu_buf_impl_t *db)
        *dbp = db->db_hash_next;
        db->db_hash_next = NULL;
        mutex_exit(DBUF_HASH_MUTEX(h, idx));
-       atomic_add_64(&dbuf_hash_count, -1);
+       atomic_dec_64(&dbuf_hash_count);
 }
 
 static arc_evict_func_t dbuf_do_evict;
index 999bd8adc5187efff9a2747129296dffe3e2aaf6..4de901ed09c75b33d4ebe2917a4a895c8b9a814c 100644 (file)
@@ -523,25 +523,25 @@ zfs_zevent_post(nvlist_t *nvl, nvlist_t *detector, zevent_cb_t *cb)
 
        error = nvlist_add_int64_array(nvl, FM_EREPORT_TIME, tv_array, 2);
        if (error) {
-               atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
                goto out;
        }
 
        eid = atomic_inc_64_nv(&zevent_eid);
        error = nvlist_add_uint64(nvl, FM_EREPORT_EID, eid);
        if (error) {
-               atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
                goto out;
        }
 
        error = nvlist_size(nvl, &nvl_size, NV_ENCODE_NATIVE);
        if (error) {
-               atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64);
                goto out;
        }
 
        if (nvl_size > ERPT_DATA_SZ || nvl_size == 0) {
-               atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64);
                error = EOVERFLOW;
                goto out;
        }
@@ -551,7 +551,7 @@ zfs_zevent_post(nvlist_t *nvl, nvlist_t *detector, zevent_cb_t *cb)
 
        ev = zfs_zevent_alloc();
        if (ev == NULL) {
-               atomic_add_64(&erpt_kstat_data.erpt_dropped.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64);
                error = ENOMEM;
                goto out;
        }
@@ -1025,8 +1025,7 @@ fm_payload_set(nvlist_t *payload, ...)
        va_end(ap);
 
        if (ret)
-               atomic_add_64(
-                   &erpt_kstat_data.payload_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.payload_set_failed.value.ui64);
 }
 
 /*
@@ -1059,24 +1058,24 @@ fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class,
        int ret;
 
        if (version != FM_EREPORT_VERS0) {
-               atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
                return;
        }
 
        (void) snprintf(ereport_class, FM_MAX_CLASS, "%s.%s",
            FM_EREPORT_CLASS, erpt_class);
        if (nvlist_add_string(ereport, FM_CLASS, ereport_class) != 0) {
-               atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
                return;
        }
 
        if (nvlist_add_uint64(ereport, FM_EREPORT_ENA, ena)) {
-               atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
        }
 
        if (nvlist_add_nvlist(ereport, FM_EREPORT_DETECTOR,
            (nvlist_t *)detector) != 0) {
-               atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
        }
 
        va_start(ap, detector);
@@ -1085,7 +1084,7 @@ fm_ereport_set(nvlist_t *ereport, int version, const char *erpt_class,
        va_end(ap);
 
        if (ret)
-               atomic_add_64(&erpt_kstat_data.erpt_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.erpt_set_failed.value.ui64);
 }
 
 /*
@@ -1108,19 +1107,19 @@ static int
 fm_fmri_hc_set_common(nvlist_t *fmri, int version, const nvlist_t *auth)
 {
        if (version != FM_HC_SCHEME_VERSION) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return (0);
        }
 
        if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0 ||
            nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return (0);
        }
 
        if (auth != NULL && nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY,
            (nvlist_t *)auth) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return (0);
        }
 
@@ -1152,22 +1151,22 @@ fm_fmri_hc_set(nvlist_t *fmri, int version, const nvlist_t *auth,
                pairs[i] = fm_nvlist_create(nva);
                if (nvlist_add_string(pairs[i], FM_FMRI_HC_NAME, name) != 0 ||
                    nvlist_add_string(pairs[i], FM_FMRI_HC_ID, idstr) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                }
        }
        va_end(ap);
 
        if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs) != 0)
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
 
        for (i = 0; i < npairs; i++)
                fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN);
 
        if (snvl != NULL) {
                if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                }
        }
 }
@@ -1192,20 +1191,20 @@ fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth,
         */
        if (nvlist_lookup_nvlist_array(bboard, FM_FMRI_HC_LIST, &hcl, &n)
            != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        for (i = 0; i < n; i++) {
                if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME,
                    &hcname) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                        return;
                }
                if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &hcid) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                        return;
                }
 
@@ -1217,8 +1216,8 @@ fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth,
                                        fm_nvlist_destroy(pairs[j],
                                            FM_NVA_RETAIN);
                        }
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                        return;
                }
        }
@@ -1242,8 +1241,8 @@ fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth,
                                        fm_nvlist_destroy(pairs[j],
                                            FM_NVA_RETAIN);
                        }
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                        return;
                }
        }
@@ -1254,7 +1253,7 @@ fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth,
         */
        if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs,
            npairs + n) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
@@ -1264,8 +1263,8 @@ fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth,
 
        if (snvl != NULL) {
                if (nvlist_add_nvlist(fmri, FM_FMRI_HC_SPECIFIC, snvl) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                        return;
                }
        }
@@ -1291,7 +1290,7 @@ fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth,
        int err = 0;
 
        if (version != DEV_SCHEME_VERSION0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
@@ -1312,7 +1311,7 @@ fm_fmri_dev_set(nvlist_t *fmri_dev, int version, const nvlist_t *auth,
                err |= nvlist_add_string(fmri_dev, FM_FMRI_DEV_TGTPTLUN0, tpl0);
 
        if (err)
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
 
 }
 
@@ -1337,35 +1336,35 @@ fm_fmri_cpu_set(nvlist_t *fmri_cpu, int version, const nvlist_t *auth,
        uint64_t *failedp = &erpt_kstat_data.fmri_set_failed.value.ui64;
 
        if (version < CPU_SCHEME_VERSION1) {
-               atomic_add_64(failedp, 1);
+               atomic_inc_64(failedp);
                return;
        }
 
        if (nvlist_add_uint8(fmri_cpu, FM_VERSION, version) != 0) {
-               atomic_add_64(failedp, 1);
+               atomic_inc_64(failedp);
                return;
        }
 
        if (nvlist_add_string(fmri_cpu, FM_FMRI_SCHEME,
            FM_FMRI_SCHEME_CPU) != 0) {
-               atomic_add_64(failedp, 1);
+               atomic_inc_64(failedp);
                return;
        }
 
        if (auth != NULL && nvlist_add_nvlist(fmri_cpu, FM_FMRI_AUTHORITY,
            (nvlist_t *)auth) != 0)
-               atomic_add_64(failedp, 1);
+               atomic_inc_64(failedp);
 
        if (nvlist_add_uint32(fmri_cpu, FM_FMRI_CPU_ID, cpu_id) != 0)
-               atomic_add_64(failedp, 1);
+               atomic_inc_64(failedp);
 
        if (cpu_maskp != NULL && nvlist_add_uint8(fmri_cpu, FM_FMRI_CPU_MASK,
            *cpu_maskp) != 0)
-               atomic_add_64(failedp, 1);
+               atomic_inc_64(failedp);
 
        if (serial_idp == NULL || nvlist_add_string(fmri_cpu,
            FM_FMRI_CPU_SERIAL_ID, (char *)serial_idp) != 0)
-                       atomic_add_64(failedp, 1);
+                       atomic_inc_64(failedp);
 }
 
 /*
@@ -1386,49 +1385,47 @@ fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth,
     const char *unum, const char *serial, uint64_t offset)
 {
        if (version != MEM_SCHEME_VERSION0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        if (!serial && (offset != (uint64_t)-1)) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_MEM) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        if (auth != NULL) {
                if (nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY,
                    (nvlist_t *)auth) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                }
        }
 
        if (nvlist_add_string(fmri, FM_FMRI_MEM_UNUM, unum) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
        }
 
        if (serial != NULL) {
                if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID,
                    (char **)&serial, 1) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                }
-               if (offset != (uint64_t)-1) {
-                       if (nvlist_add_uint64(fmri, FM_FMRI_MEM_OFFSET,
-                           offset) != 0) {
-                               atomic_add_64(&erpt_kstat_data.
-                                   fmri_set_failed.value.ui64, 1);
-                       }
+               if (offset != (uint64_t)-1 && nvlist_add_uint64(fmri,
+                   FM_FMRI_MEM_OFFSET, offset) != 0) {
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                }
        }
 }
@@ -1438,28 +1435,28 @@ fm_fmri_zfs_set(nvlist_t *fmri, int version, uint64_t pool_guid,
     uint64_t vdev_guid)
 {
        if (version != ZFS_SCHEME_VERSION0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        if (nvlist_add_uint8(fmri, FM_VERSION, version) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        if (nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_ZFS) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
                return;
        }
 
        if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_POOL, pool_guid) != 0) {
-               atomic_add_64(&erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+               atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
        }
 
        if (vdev_guid != 0) {
                if (nvlist_add_uint64(fmri, FM_FMRI_ZFS_VDEV, vdev_guid) != 0) {
-                       atomic_add_64(
-                           &erpt_kstat_data.fmri_set_failed.value.ui64, 1);
+                       atomic_inc_64(
+                           &erpt_kstat_data.fmri_set_failed.value.ui64);
                }
        }
 }
index ffefbd3458104d272fab7b8ac370a9b57549ac16..787b03d2991ef1db59fc8d03824681533235a9c7 100644 (file)
@@ -1898,9 +1898,9 @@ spa_load_verify_done(zio_t *zio)
        if (error) {
                if ((BP_GET_LEVEL(bp) != 0 || DMU_OT_IS_METADATA(type)) &&
                    type != DMU_OT_INTENT_LOG)
-                       atomic_add_64(&sle->sle_meta_count, 1);
+                       atomic_inc_64(&sle->sle_meta_count);
                else
-                       atomic_add_64(&sle->sle_data_count, 1);
+                       atomic_inc_64(&sle->sle_data_count);
        }
        zio_data_buf_free(zio->io_data, zio->io_size);
 
index 389fa6fd9d0706e7e33a24cce9468b26ea76b901..e802240c12bdef39ac3edc58e82affad427a3272 100644 (file)
@@ -102,7 +102,7 @@ static vdc_stats_t vdc_stats = {
        { "misses",             KSTAT_DATA_UINT64 }
 };
 
-#define        VDCSTAT_BUMP(stat)      atomic_add_64(&vdc_stats.stat.value.ui64, 1);
+#define        VDCSTAT_BUMP(stat)      atomic_inc_64(&vdc_stats.stat.value.ui64);
 
 static int
 vdev_cache_offset_compare(const void *a1, const void *a2)
index 7f588ed6b0b5611905cea0ce53d8ccfca64204b7..419cbc1a0ebe8412986dc79823e19813603e357d 100644 (file)
@@ -984,7 +984,7 @@ vdev_uberblock_sync_done(zio_t *zio)
        uint64_t *good_writes = zio->io_private;
 
        if (zio->io_error == 0 && zio->io_vd->vdev_top->vdev_ms_array != 0)
-               atomic_add_64(good_writes, 1);
+               atomic_inc_64(good_writes);
 }
 
 /*
@@ -1060,7 +1060,7 @@ vdev_label_sync_done(zio_t *zio)
        uint64_t *good_writes = zio->io_private;
 
        if (zio->io_error == 0)
-               atomic_add_64(good_writes, 1);
+               atomic_inc_64(good_writes);
 }
 
 /*
index 40b507a0b6d83f3803c2cc07dfafd943312ad1e5..69836dff3cb90f4afaddcea9ef22b4fe43c1b852 100644 (file)
@@ -427,7 +427,7 @@ zio_inject_fault(char *name, int flags, int *id, zinject_record_t *record)
                handler->zi_spa = spa;
                handler->zi_record = *record;
                list_insert_tail(&inject_handlers, handler);
-               atomic_add_32(&zio_injection_enabled, 1);
+               atomic_inc_32(&zio_injection_enabled);
 
                rw_exit(&inject_lock);
        }
@@ -508,7 +508,7 @@ zio_clear_fault(int id)
 
        spa_inject_delref(handler->zi_spa);
        kmem_free(handler, sizeof (inject_handler_t));
-       atomic_add_32(&zio_injection_enabled, -1);
+       atomic_dec_32(&zio_injection_enabled);
 
        return (0);
 }