]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/spa_history.c
Illumos 5314 - Remove "dbuf phys" db->db_data pointer aliases in ZFS
[mirror_zfs.git] / module / zfs / spa_history.c
index 79d48620c9e1815f880c109d9711f664a5b6f1d1..8e0033d949da9fc84154449c4924b3e29344093b 100644 (file)
@@ -21,7 +21,7 @@
 
 /*
  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013 by Delphix. All rights reserved.
  */
 
 #include <sys/spa.h>
@@ -32,7 +32,6 @@
 #include <sys/dmu_objset.h>
 #include <sys/dsl_dataset.h>
 #include <sys/dsl_dir.h>
-#include <sys/utsname.h>
 #include <sys/cmn_err.h>
 #include <sys/sunddi.h>
 #include <sys/cred.h>
@@ -197,10 +196,10 @@ spa_history_zone(void)
  */
 /*ARGSUSED*/
 static void
-spa_history_log_sync(void *arg1, void *arg2, dmu_tx_t *tx)
+spa_history_log_sync(void *arg, dmu_tx_t *tx)
 {
-       spa_t           *spa = arg1;
-       nvlist_t        *nvl = arg2;
+       nvlist_t        *nvl = arg;
+       spa_t           *spa = dmu_tx_pool(tx)->dp_spa;
        objset_t        *mos = spa->spa_meta_objset;
        dmu_buf_t       *dbp;
        spa_history_phys_t *shpp;
@@ -222,7 +221,7 @@ spa_history_log_sync(void *arg1, void *arg2, dmu_tx_t *tx)
         * Get the offset of where we need to write via the bonus buffer.
         * Update the offset when the write completes.
         */
-       VERIFY(0 == dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp));
+       VERIFY0(dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp));
        shpp = dbp->db_data;
 
        dmu_buf_will_dirty(dbp, tx);
@@ -236,9 +235,8 @@ spa_history_log_sync(void *arg1, void *arg2, dmu_tx_t *tx)
 #endif
 
        fnvlist_add_uint64(nvl, ZPOOL_HIST_TIME, gethrestime_sec());
-#ifdef _KERNEL
-       fnvlist_add_string(nvl, ZPOOL_HIST_HOST, utsname.nodename);
-#endif
+       fnvlist_add_string(nvl, ZPOOL_HIST_HOST, utsname()->nodename);
+
        if (nvlist_exists(nvl, ZPOOL_HIST_CMD)) {
                zfs_dbgmsg("command: %s",
                    fnvlist_lookup_string(nvl, ZPOOL_HIST_CMD));
@@ -262,7 +260,7 @@ spa_history_log_sync(void *arg1, void *arg2, dmu_tx_t *tx)
        }
 
        VERIFY3U(nvlist_pack(nvl, &record_packed, &reclen, NV_ENCODE_NATIVE,
-           KM_PUSHPAGE), ==, 0);
+           KM_SLEEP), ==, 0);
 
        mutex_enter(&spa->spa_history_lock);
 
@@ -291,9 +289,7 @@ int
 spa_history_log(spa_t *spa, const char *msg)
 {
        int err;
-       nvlist_t *nvl;
-
-        VERIFY0(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_PUSHPAGE));
+       nvlist_t *nvl = fnvlist_alloc();
 
        fnvlist_add_string(nvl, ZPOOL_HIST_CMD, msg);
        err = spa_history_log_nvl(spa, nvl);
@@ -309,7 +305,7 @@ spa_history_log_nvl(spa_t *spa, nvlist_t *nvl)
        nvlist_t *nvarg;
 
        if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY || !spa_writeable(spa))
-               return (EINVAL);
+               return (SET_ERROR(EINVAL));
 
        tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
        err = dmu_tx_assign(tx, TXG_WAIT);
@@ -318,7 +314,7 @@ spa_history_log_nvl(spa_t *spa, nvlist_t *nvl)
                return (err);
        }
 
-       VERIFY0(nvlist_dup(nvl, &nvarg, KM_PUSHPAGE));
+       VERIFY0(nvlist_dup(nvl, &nvarg, KM_SLEEP));
        if (spa_history_zone() != NULL) {
                fnvlist_add_string(nvarg, ZPOOL_HIST_ZONE,
                    spa_history_zone());
@@ -326,8 +322,8 @@ spa_history_log_nvl(spa_t *spa, nvlist_t *nvl)
        fnvlist_add_uint64(nvarg, ZPOOL_HIST_WHO, crgetruid(CRED()));
 
        /* Kick this off asynchronously; errors are ignored. */
-       dsl_sync_task_do_nowait(spa_get_dsl(spa), NULL,
-           spa_history_log_sync, spa, nvarg, 0, tx);
+       dsl_sync_task_nowait(spa_get_dsl(spa), spa_history_log_sync,
+           nvarg, 0, tx);
        dmu_tx_commit(tx);
 
        /* spa_history_log_sync will free nvl */
@@ -353,7 +349,7 @@ spa_history_get(spa_t *spa, uint64_t *offp, uint64_t *len, char *buf)
         * that's ok, just return ENOENT.
         */
        if (!spa->spa_history)
-               return (ENOENT);
+               return (SET_ERROR(ENOENT));
 
        /*
         * The history is logged asynchronously, so when they request
@@ -440,7 +436,6 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa,
     dmu_tx_t *tx, const char *fmt, va_list adx)
 {
        char *msg;
-       va_list adx1;
 
        /*
         * If this is part of creating a pool, not everything is
@@ -452,12 +447,7 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa,
                return;
        }
 
-       va_copy(adx1, adx);
-       msg = kmem_alloc(vsnprintf(NULL, 0, fmt, adx1) + 1, KM_PUSHPAGE);
-       va_end(adx1);
-       va_copy(adx1, adx);
-       (void) vsprintf(msg, fmt, adx1);
-       va_end(adx1);
+       msg = kmem_vasprintf(fmt, adx);
        fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg);
        strfree(msg);
 
@@ -465,10 +455,10 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa,
        fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg);
 
        if (dmu_tx_is_syncing(tx)) {
-               spa_history_log_sync(spa, nvl, tx);
+               spa_history_log_sync(nvl, tx);
        } else {
-               dsl_sync_task_do_nowait(spa_get_dsl(spa), NULL,
-                   spa_history_log_sync, spa, nvl, 0, tx);
+               dsl_sync_task_nowait(spa_get_dsl(spa),
+                   spa_history_log_sync, nvl, 0, tx);
        }
        /* spa_history_log_sync() will free nvl */
 }
@@ -479,7 +469,6 @@ spa_history_log_internal(spa_t *spa, const char *operation,
 {
        dmu_tx_t *htx = tx;
        va_list adx;
-       nvlist_t *nvl;
 
        /* create a tx if we didn't get one */
        if (tx == NULL) {
@@ -491,8 +480,7 @@ spa_history_log_internal(spa_t *spa, const char *operation,
        }
 
        va_start(adx, fmt);
-       VERIFY0(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_PUSHPAGE));
-       log_internal(nvl, operation, spa, htx, fmt, adx);
+       log_internal(fnvlist_alloc(), operation, spa, htx, fmt, adx);
        va_end(adx);
 
        /* if we didn't get a tx from the caller, commit the one we made */
@@ -506,12 +494,11 @@ spa_history_log_internal_ds(dsl_dataset_t *ds, const char *operation,
 {
        va_list adx;
        char namebuf[MAXNAMELEN];
-       nvlist_t *nvl;
+       nvlist_t *nvl = fnvlist_alloc();
 
        ASSERT(tx != NULL);
 
        dsl_dataset_name(ds, namebuf);
-       VERIFY0(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_PUSHPAGE));
        fnvlist_add_string(nvl, ZPOOL_HIST_DSNAME, namebuf);
        fnvlist_add_uint64(nvl, ZPOOL_HIST_DSID, ds->ds_object);
 
@@ -526,15 +513,14 @@ spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
 {
        va_list adx;
        char namebuf[MAXNAMELEN];
-       nvlist_t *nvl;
+       nvlist_t *nvl = fnvlist_alloc();
 
        ASSERT(tx != NULL);
 
        dsl_dir_name(dd, namebuf);
-       VERIFY0(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_PUSHPAGE));
        fnvlist_add_string(nvl, ZPOOL_HIST_DSNAME, namebuf);
        fnvlist_add_uint64(nvl, ZPOOL_HIST_DSID,
-           dd->dd_phys->dd_head_dataset_obj);
+           dsl_dir_phys(dd)->dd_head_dataset_obj);
 
        va_start(adx, fmt);
        log_internal(nvl, operation, dd->dd_pool->dp_spa, tx, fmt, adx);
@@ -544,17 +530,12 @@ spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
 void
 spa_history_log_version(spa_t *spa, const char *operation)
 {
-#ifdef _KERNEL
-       uint64_t current_vers = spa_version(spa);
+       utsname_t *u = utsname();
 
        spa_history_log_internal(spa, operation, NULL,
            "pool version %llu; software version %llu/%d; uts %s %s %s %s",
-           (u_longlong_t)current_vers, SPA_VERSION, ZPL_VERSION,
-           utsname.nodename, utsname.release, utsname.version,
-           utsname.machine);
-       cmn_err(CE_CONT, "!%s version %llu pool %s using %llu", operation,
-           (u_longlong_t)current_vers, spa_name(spa), SPA_VERSION);
-#endif
+           (u_longlong_t)spa_version(spa), SPA_VERSION, ZPL_VERSION,
+           u->nodename, u->release, u->version, u->machine);
 }
 
 #if defined(_KERNEL) && defined(HAVE_SPL)