usr/src/uts/common/fs/zfs/spa_history.c
author Matthew Ahrens <matt@delphix.com>
Sat, 05 Nov 2011 17:34:13 -0700
changeset 13509 04570f5cbeca
parent 12296 7cf402a7f374
child 13512 060607df0c9d
permissions -rw-r--r--
1644 add ZFS "clones" property 1645 add ZFS "written" and "written@..." properties 1646 "zfs send" should estimate size of stream 1647 "zfs destroy" should determine space reclaimed by destroying multiple snapshots 1708 adjust size of zpool history data Reviewed by: Richard Lowe <[email protected]> Reviewed by: George Wilson <[email protected]> Approved by: Gordon Ross <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     1
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     2
 * CDDL HEADER START
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     3
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     7
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    11
 * and limitations under the License.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    12
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    18
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    19
 * CDDL HEADER END
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    20
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    21
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    22
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
    23
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
13509
04570f5cbeca 1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents: 12296
diff changeset
    24
 * Copyright (c) 2011 by Delphix. All rights reserved.
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    25
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    26
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    27
#include <sys/spa.h>
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    28
#include <sys/spa_impl.h>
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    29
#include <sys/zap.h>
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    30
#include <sys/dsl_synctask.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    31
#include <sys/dmu_tx.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    32
#include <sys/dmu_objset.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    33
#include <sys/utsname.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    34
#include <sys/cmn_err.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    35
#include <sys/sunddi.h>
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
    36
#include "zfs_comutil.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    37
#ifdef _KERNEL
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    38
#include <sys/zone.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
    39
#endif
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    40
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    41
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    42
 * Routines to manage the on-disk history log.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    43
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    44
 * The history log is stored as a dmu object containing
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    45
 * <packed record length, record nvlist> tuples.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    46
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    47
 * Where "record nvlist" is a nvlist containing uint64_ts and strings, and
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    48
 * "packed record length" is the packed length of the "record nvlist" stored
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    49
 * as a little endian uint64_t.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    50
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    51
 * The log is implemented as a ring buffer, though the original creation
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    52
 * of the pool ('zpool create') is never overwritten.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    53
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    54
 * The history log is tracked as object 'spa_t::spa_history'.  The bonus buffer
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    55
 * of 'spa_history' stores the offsets for logging/retrieving history as
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    56
 * 'spa_history_phys_t'.  'sh_pool_create_len' is the ending offset in bytes of
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    57
 * where the 'zpool create' record is stored.  This allows us to never
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    58
 * overwrite the original creation of the pool.  'sh_phys_max_off' is the
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    59
 * physical ending offset in bytes of the log.  This tells you the length of
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    60
 * the buffer. 'sh_eof' is the logical EOF (in bytes).  Whenever a record
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    61
 * is added, 'sh_eof' is incremented by the the size of the record.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    62
 * 'sh_eof' is never decremented.  'sh_bof' is the logical BOF (in bytes).
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    63
 * This is where the consumer should start reading from after reading in
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    64
 * the 'zpool create' portion of the log.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    65
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    66
 * 'sh_records_lost' keeps track of how many records have been overwritten
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    67
 * and permanently lost.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    68
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    69
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    70
/* convert a logical offset to physical */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    71
static uint64_t
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    72
spa_history_log_to_phys(uint64_t log_off, spa_history_phys_t *shpp)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    73
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    74
	uint64_t phys_len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    75
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    76
	phys_len = shpp->sh_phys_max_off - shpp->sh_pool_create_len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    77
	return ((log_off - shpp->sh_pool_create_len) % phys_len
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    78
	    + shpp->sh_pool_create_len);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    79
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    80
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    81
void
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    82
spa_history_create_obj(spa_t *spa, dmu_tx_t *tx)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    83
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    84
	dmu_buf_t *dbp;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    85
	spa_history_phys_t *shpp;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    86
	objset_t *mos = spa->spa_meta_objset;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    87
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    88
	ASSERT(spa->spa_history == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    89
	spa->spa_history = dmu_object_alloc(mos, DMU_OT_SPA_HISTORY,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    90
	    SPA_MAXBLOCKSIZE, DMU_OT_SPA_HISTORY_OFFSETS,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    91
	    sizeof (spa_history_phys_t), tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    92
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    93
	VERIFY(zap_add(mos, DMU_POOL_DIRECTORY_OBJECT,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    94
	    DMU_POOL_HISTORY, sizeof (uint64_t), 1,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    95
	    &spa->spa_history, tx) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    96
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    97
	VERIFY(0 == dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    98
	ASSERT(dbp->db_size >= sizeof (spa_history_phys_t));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
    99
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   100
	shpp = dbp->db_data;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   101
	dmu_buf_will_dirty(dbp, tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   102
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   103
	/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   104
	 * Figure out maximum size of history log.  We set it at
13509
04570f5cbeca 1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents: 12296
diff changeset
   105
	 * 0.1% of pool size, with a max of 1G and min of 128KB.
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   106
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 9946
diff changeset
   107
	shpp->sh_phys_max_off =
13509
04570f5cbeca 1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents: 12296
diff changeset
   108
	    metaslab_class_get_dspace(spa_normal_class(spa)) / 1000;
04570f5cbeca 1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents: 12296
diff changeset
   109
	shpp->sh_phys_max_off = MIN(shpp->sh_phys_max_off, 1<<30);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   110
	shpp->sh_phys_max_off = MAX(shpp->sh_phys_max_off, 128<<10);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   111
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   112
	dmu_buf_rele(dbp, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   113
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   114
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   115
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   116
 * Change 'sh_bof' to the beginning of the next record.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   117
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   118
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   119
spa_history_advance_bof(spa_t *spa, spa_history_phys_t *shpp)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   120
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   121
	objset_t *mos = spa->spa_meta_objset;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   122
	uint64_t firstread, reclen, phys_bof;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   123
	char buf[sizeof (reclen)];
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   124
	int err;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   125
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   126
	phys_bof = spa_history_log_to_phys(shpp->sh_bof, shpp);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   127
	firstread = MIN(sizeof (reclen), shpp->sh_phys_max_off - phys_bof);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   128
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   129
	if ((err = dmu_read(mos, spa->spa_history, phys_bof, firstread,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7046
diff changeset
   130
	    buf, DMU_READ_PREFETCH)) != 0)
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   131
		return (err);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   132
	if (firstread != sizeof (reclen)) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   133
		if ((err = dmu_read(mos, spa->spa_history,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   134
		    shpp->sh_pool_create_len, sizeof (reclen) - firstread,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7046
diff changeset
   135
		    buf + firstread, DMU_READ_PREFETCH)) != 0)
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   136
			return (err);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   137
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   138
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   139
	reclen = LE_64(*((uint64_t *)buf));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   140
	shpp->sh_bof += reclen + sizeof (reclen);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   141
	shpp->sh_records_lost++;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   142
	return (0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   143
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   144
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   145
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   146
spa_history_write(spa_t *spa, void *buf, uint64_t len, spa_history_phys_t *shpp,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   147
    dmu_tx_t *tx)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   148
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   149
	uint64_t firstwrite, phys_eof;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   150
	objset_t *mos = spa->spa_meta_objset;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   151
	int err;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   152
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   153
	ASSERT(MUTEX_HELD(&spa->spa_history_lock));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   154
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   155
	/* see if we need to reset logical BOF */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   156
	while (shpp->sh_phys_max_off - shpp->sh_pool_create_len -
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   157
	    (shpp->sh_eof - shpp->sh_bof) <= len) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   158
		if ((err = spa_history_advance_bof(spa, shpp)) != 0) {
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   159
			return (err);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   160
		}
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   161
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   162
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   163
	phys_eof = spa_history_log_to_phys(shpp->sh_eof, shpp);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   164
	firstwrite = MIN(len, shpp->sh_phys_max_off - phys_eof);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   165
	shpp->sh_eof += len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   166
	dmu_write(mos, spa->spa_history, phys_eof, firstwrite, buf, tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   167
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   168
	len -= firstwrite;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   169
	if (len > 0) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   170
		/* write out the rest at the beginning of physical file */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   171
		dmu_write(mos, spa->spa_history, shpp->sh_pool_create_len,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   172
		    len, (char *)buf + firstwrite, tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   173
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   174
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   175
	return (0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   176
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   177
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   178
static char *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   179
spa_history_zone()
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   180
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   181
#ifdef _KERNEL
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   182
	return (curproc->p_zone->zone_name);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   183
#else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   184
	return ("global");
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   185
#endif
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   186
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   187
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   188
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   189
 * Write out a history event.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   190
 */
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   191
/*ARGSUSED*/
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   192
static void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   193
spa_history_log_sync(void *arg1, void *arg2, dmu_tx_t *tx)
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   194
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   195
	spa_t		*spa = arg1;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   196
	history_arg_t	*hap = arg2;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   197
	const char	*history_str = hap->ha_history_str;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   198
	objset_t	*mos = spa->spa_meta_objset;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   199
	dmu_buf_t	*dbp;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   200
	spa_history_phys_t *shpp;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   201
	size_t		reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   202
	uint64_t	le_len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   203
	nvlist_t	*nvrecord;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   204
	char		*record_packed = NULL;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   205
	int		ret;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   206
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   207
	/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   208
	 * If we have an older pool that doesn't have a command
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   209
	 * history object, create it now.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   210
	 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   211
	mutex_enter(&spa->spa_history_lock);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   212
	if (!spa->spa_history)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   213
		spa_history_create_obj(spa, tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   214
	mutex_exit(&spa->spa_history_lock);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   215
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   216
	/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   217
	 * Get the offset of where we need to write via the bonus buffer.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   218
	 * Update the offset when the write completes.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   219
	 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   220
	VERIFY(0 == dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   221
	shpp = dbp->db_data;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   222
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   223
	dmu_buf_will_dirty(dbp, tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   224
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   225
#ifdef ZFS_DEBUG
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   226
	{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   227
		dmu_object_info_t doi;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   228
		dmu_object_info_from_db(dbp, &doi);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   229
		ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_SPA_HISTORY_OFFSETS);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   230
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   231
#endif
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   232
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   233
	VERIFY(nvlist_alloc(&nvrecord, NV_UNIQUE_NAME, KM_SLEEP) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   234
	VERIFY(nvlist_add_uint64(nvrecord, ZPOOL_HIST_TIME,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   235
	    gethrestime_sec()) == 0);
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   236
	VERIFY(nvlist_add_uint64(nvrecord, ZPOOL_HIST_WHO, hap->ha_uid) == 0);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   237
	if (hap->ha_zone != NULL)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   238
		VERIFY(nvlist_add_string(nvrecord, ZPOOL_HIST_ZONE,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   239
		    hap->ha_zone) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   240
#ifdef _KERNEL
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   241
	VERIFY(nvlist_add_string(nvrecord, ZPOOL_HIST_HOST,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   242
	    utsname.nodename) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   243
#endif
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   244
	if (hap->ha_log_type == LOG_CMD_POOL_CREATE ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   245
	    hap->ha_log_type == LOG_CMD_NORMAL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   246
		VERIFY(nvlist_add_string(nvrecord, ZPOOL_HIST_CMD,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   247
		    history_str) == 0);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   248
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   249
		zfs_dbgmsg("command: %s", history_str);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   250
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   251
		VERIFY(nvlist_add_uint64(nvrecord, ZPOOL_HIST_INT_EVENT,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   252
		    hap->ha_event) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   253
		VERIFY(nvlist_add_uint64(nvrecord, ZPOOL_HIST_TXG,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   254
		    tx->tx_txg) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   255
		VERIFY(nvlist_add_string(nvrecord, ZPOOL_HIST_INT_STR,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   256
		    history_str) == 0);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   257
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   258
		zfs_dbgmsg("internal %s pool:%s txg:%llu %s",
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   259
		    zfs_history_event_names[hap->ha_event], spa_name(spa),
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   260
		    (longlong_t)tx->tx_txg, history_str);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   261
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   262
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   263
4611
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4577
diff changeset
   264
	VERIFY(nvlist_size(nvrecord, &reclen, NV_ENCODE_XDR) == 0);
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4577
diff changeset
   265
	record_packed = kmem_alloc(reclen, KM_SLEEP);
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4577
diff changeset
   266
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   267
	VERIFY(nvlist_pack(nvrecord, &record_packed, &reclen,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   268
	    NV_ENCODE_XDR, KM_SLEEP) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   269
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   270
	mutex_enter(&spa->spa_history_lock);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   271
	if (hap->ha_log_type == LOG_CMD_POOL_CREATE)
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   272
		VERIFY(shpp->sh_eof == shpp->sh_pool_create_len);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   273
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   274
	/* write out the packed length as little endian */
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 2926
diff changeset
   275
	le_len = LE_64((uint64_t)reclen);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   276
	ret = spa_history_write(spa, &le_len, sizeof (le_len), shpp, tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   277
	if (!ret)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   278
		ret = spa_history_write(spa, record_packed, reclen, shpp, tx);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   279
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   280
	if (!ret && hap->ha_log_type == LOG_CMD_POOL_CREATE) {
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   281
		shpp->sh_pool_create_len += sizeof (le_len) + reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   282
		shpp->sh_bof = shpp->sh_pool_create_len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   283
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   284
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   285
	mutex_exit(&spa->spa_history_lock);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   286
	nvlist_free(nvrecord);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   287
	kmem_free(record_packed, reclen);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   288
	dmu_buf_rele(dbp, FTAG);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   289
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   290
	strfree(hap->ha_history_str);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   291
	if (hap->ha_zone != NULL)
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   292
		strfree(hap->ha_zone);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   293
	kmem_free(hap, sizeof (history_arg_t));
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   294
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   295
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   296
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   297
 * Write out a history event.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   298
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   299
int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   300
spa_history_log(spa_t *spa, const char *history_str, history_log_type_t what)
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   301
{
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   302
	history_arg_t *ha;
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   303
	int err = 0;
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   304
	dmu_tx_t *tx;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   305
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   306
	ASSERT(what != LOG_INTERNAL);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   307
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   308
	tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   309
	err = dmu_tx_assign(tx, TXG_WAIT);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   310
	if (err) {
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   311
		dmu_tx_abort(tx);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   312
		return (err);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   313
	}
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   314
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   315
	ha = kmem_alloc(sizeof (history_arg_t), KM_SLEEP);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   316
	ha->ha_history_str = strdup(history_str);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   317
	ha->ha_zone = strdup(spa_history_zone());
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   318
	ha->ha_log_type = what;
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   319
	ha->ha_uid = crgetuid(CRED());
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   320
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   321
	/* Kick this off asynchronously; errors are ignored. */
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   322
	dsl_sync_task_do_nowait(spa_get_dsl(spa), NULL,
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   323
	    spa_history_log_sync, spa, ha, 0, tx);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   324
	dmu_tx_commit(tx);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   325
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   326
	/* spa_history_log_sync will free ha and strings */
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   327
	return (err);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   328
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   329
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   330
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   331
 * Read out the command history.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   332
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   333
int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   334
spa_history_get(spa_t *spa, uint64_t *offp, uint64_t *len, char *buf)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   335
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   336
	objset_t *mos = spa->spa_meta_objset;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   337
	dmu_buf_t *dbp;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   338
	uint64_t read_len, phys_read_off, phys_eof;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   339
	uint64_t leftover = 0;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   340
	spa_history_phys_t *shpp;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   341
	int err;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   342
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   343
	/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   344
	 * If the command history  doesn't exist (older pool),
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   345
	 * that's ok, just return ENOENT.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   346
	 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   347
	if (!spa->spa_history)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   348
		return (ENOENT);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   349
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   350
	/*
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   351
	 * The history is logged asynchronously, so when they request
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   352
	 * the first chunk of history, make sure everything has been
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   353
	 * synced to disk so that we get it.
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   354
	 */
11937
ee1b786b1783 6932590 zdb -vvv causes core dump
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11816
diff changeset
   355
	if (*offp == 0 && spa_writeable(spa))
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   356
		txg_wait_synced(spa_get_dsl(spa), 0);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   357
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   358
	if ((err = dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   359
		return (err);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   360
	shpp = dbp->db_data;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   361
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   362
#ifdef ZFS_DEBUG
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   363
	{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   364
		dmu_object_info_t doi;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   365
		dmu_object_info_from_db(dbp, &doi);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   366
		ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_SPA_HISTORY_OFFSETS);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   367
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   368
#endif
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   369
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   370
	mutex_enter(&spa->spa_history_lock);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   371
	phys_eof = spa_history_log_to_phys(shpp->sh_eof, shpp);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   372
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   373
	if (*offp < shpp->sh_pool_create_len) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   374
		/* read in just the zpool create history */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   375
		phys_read_off = *offp;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   376
		read_len = MIN(*len, shpp->sh_pool_create_len -
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   377
		    phys_read_off);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   378
	} else {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   379
		/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   380
		 * Need to reset passed in offset to BOF if the passed in
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   381
		 * offset has since been overwritten.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   382
		 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   383
		*offp = MAX(*offp, shpp->sh_bof);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   384
		phys_read_off = spa_history_log_to_phys(*offp, shpp);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   385
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   386
		/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   387
		 * Read up to the minimum of what the user passed down or
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   388
		 * the EOF (physical or logical).  If we hit physical EOF,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   389
		 * use 'leftover' to read from the physical BOF.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   390
		 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   391
		if (phys_read_off <= phys_eof) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   392
			read_len = MIN(*len, phys_eof - phys_read_off);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   393
		} else {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   394
			read_len = MIN(*len,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   395
			    shpp->sh_phys_max_off - phys_read_off);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   396
			if (phys_read_off + *len > shpp->sh_phys_max_off) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   397
				leftover = MIN(*len - read_len,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   398
				    phys_eof - shpp->sh_pool_create_len);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   399
			}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   400
		}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   401
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   402
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   403
	/* offset for consumer to use next */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   404
	*offp += read_len + leftover;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   405
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   406
	/* tell the consumer how much you actually read */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   407
	*len = read_len + leftover;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   408
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   409
	if (read_len == 0) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   410
		mutex_exit(&spa->spa_history_lock);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   411
		dmu_buf_rele(dbp, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   412
		return (0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   413
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   414
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7046
diff changeset
   415
	err = dmu_read(mos, spa->spa_history, phys_read_off, read_len, buf,
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7046
diff changeset
   416
	    DMU_READ_PREFETCH);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   417
	if (leftover && err == 0) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   418
		err = dmu_read(mos, spa->spa_history, shpp->sh_pool_create_len,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7046
diff changeset
   419
		    leftover, buf + read_len, DMU_READ_PREFETCH);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   420
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   421
	mutex_exit(&spa->spa_history_lock);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   422
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   423
	dmu_buf_rele(dbp, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   424
	return (err);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents:
diff changeset
   425
}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   426
9946
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   427
static void
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   428
log_internal(history_internal_events_t event, spa_t *spa,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   429
    dmu_tx_t *tx, const char *fmt, va_list adx)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   430
{
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   431
	history_arg_t *ha;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   432
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 4611
diff changeset
   433
	/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 4611
diff changeset
   434
	 * If this is part of creating a pool, not everything is
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 4611
diff changeset
   435
	 * initialized yet, so don't bother logging the internal events.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 4611
diff changeset
   436
	 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 4611
diff changeset
   437
	if (tx->tx_txg == TXG_INITIAL)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 4611
diff changeset
   438
		return;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 4611
diff changeset
   439
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   440
	ha = kmem_alloc(sizeof (history_arg_t), KM_SLEEP);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   441
	ha->ha_history_str = kmem_alloc(vsnprintf(NULL, 0, fmt, adx) + 1,
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   442
	    KM_SLEEP);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   443
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   444
	(void) vsprintf(ha->ha_history_str, fmt, adx);
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   445
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   446
	ha->ha_log_type = LOG_INTERNAL;
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   447
	ha->ha_event = event;
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   448
	ha->ha_zone = NULL;
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   449
	ha->ha_uid = 0;
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   450
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   451
	if (dmu_tx_is_syncing(tx)) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   452
		spa_history_log_sync(spa, ha, tx);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   453
	} else {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   454
		dsl_sync_task_do_nowait(spa_get_dsl(spa), NULL,
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   455
		    spa_history_log_sync, spa, ha, 0, tx);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   456
	}
11816
a30797f77200 6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10922
diff changeset
   457
	/* spa_history_log_sync() will free ha and strings */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3444
diff changeset
   458
}
9946
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   459
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   460
void
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   461
spa_history_log_internal(history_internal_events_t event, spa_t *spa,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   462
    dmu_tx_t *tx, const char *fmt, ...)
9946
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   463
{
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   464
	dmu_tx_t *htx = tx;
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   465
	va_list adx;
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   466
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   467
	/* create a tx if we didn't get one */
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   468
	if (tx == NULL) {
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   469
		htx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   470
		if (dmu_tx_assign(htx, TXG_WAIT) != 0) {
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   471
			dmu_tx_abort(htx);
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   472
			return;
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   473
		}
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   474
	}
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   475
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   476
	va_start(adx, fmt);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   477
	log_internal(event, spa, htx, fmt, adx);
9946
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   478
	va_end(adx);
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   479
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   480
	/* if we didn't get a tx from the caller, commit the one we made */
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   481
	if (tx == NULL)
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   482
		dmu_tx_commit(htx);
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   483
}
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   484
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   485
void
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   486
spa_history_log_version(spa_t *spa, history_internal_events_t event)
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   487
{
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   488
#ifdef _KERNEL
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   489
	uint64_t current_vers = spa_version(spa);
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   490
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   491
	if (current_vers >= SPA_VERSION_ZPOOL_HISTORY) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11937
diff changeset
   492
		spa_history_log_internal(event, spa, NULL,
9946
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   493
		    "pool spa %llu; zfs spa %llu; zpl %d; uts %s %s %s %s",
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   494
		    (u_longlong_t)current_vers, SPA_VERSION, ZPL_VERSION,
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   495
		    utsname.nodename, utsname.release, utsname.version,
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   496
		    utsname.machine);
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   497
	}
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   498
	cmn_err(CE_CONT, "!%s version %llu pool %s using %llu",
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   499
	    event == LOG_POOL_IMPORT ? "imported" :
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   500
	    event == LOG_POOL_CREATE ? "created" : "accessed",
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   501
	    (u_longlong_t)current_vers, spa_name(spa), SPA_VERSION);
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   502
#endif
86a051e72232 6842809 zfs history needs to record system info on import/create
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9512
diff changeset
   503
}