1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or https://opensource.org/licenses/CDDL-1.0. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 /* 24 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 25 * Copyright (c) 2011, 2018 by Delphix. All rights reserved. 26 * Copyright (c) 2014 Integros [integros.com] 27 * Copyright 2017 Joyent, Inc. 28 */ 29 30 #include <sys/spa.h> 31 #include <sys/spa_impl.h> 32 #include <sys/zap.h> 33 #include <sys/dsl_synctask.h> 34 #include <sys/dmu_tx.h> 35 #include <sys/dmu_objset.h> 36 #include <sys/dsl_dataset.h> 37 #include <sys/dsl_dir.h> 38 #include <sys/cmn_err.h> 39 #include <sys/sunddi.h> 40 #include <sys/cred.h> 41 #include "zfs_comutil.h" 42 #include "zfs_gitrev.h" 43 #ifdef _KERNEL 44 #include <sys/zone.h> 45 #endif 46 47 /* 48 * Routines to manage the on-disk history log. 49 * 50 * The history log is stored as a dmu object containing 51 * <packed record length, record nvlist> tuples. 52 * 53 * Where "record nvlist" is an nvlist containing uint64_ts and strings, and 54 * "packed record length" is the packed length of the "record nvlist" stored 55 * as a little endian uint64_t. 56 * 57 * The log is implemented as a ring buffer, though the original creation 58 * of the pool ('zpool create') is never overwritten. 59 * 60 * The history log is tracked as object 'spa_t::spa_history'. The bonus buffer 61 * of 'spa_history' stores the offsets for logging/retrieving history as 62 * 'spa_history_phys_t'. 'sh_pool_create_len' is the ending offset in bytes of 63 * where the 'zpool create' record is stored. This allows us to never 64 * overwrite the original creation of the pool. 'sh_phys_max_off' is the 65 * physical ending offset in bytes of the log. This tells you the length of 66 * the buffer. 'sh_eof' is the logical EOF (in bytes). Whenever a record 67 * is added, 'sh_eof' is incremented by the size of the record. 68 * 'sh_eof' is never decremented. 'sh_bof' is the logical BOF (in bytes). 69 * This is where the consumer should start reading from after reading in 70 * the 'zpool create' portion of the log. 71 * 72 * 'sh_records_lost' keeps track of how many records have been overwritten 73 * and permanently lost. 74 */ 75 76 /* convert a logical offset to physical */ 77 static uint64_t 78 spa_history_log_to_phys(uint64_t log_off, spa_history_phys_t *shpp) 79 { 80 uint64_t phys_len; 81 82 phys_len = shpp->sh_phys_max_off - shpp->sh_pool_create_len; 83 return ((log_off - shpp->sh_pool_create_len) % phys_len 84 + shpp->sh_pool_create_len); 85 } 86 87 void 88 spa_history_create_obj(spa_t *spa, dmu_tx_t *tx) 89 { 90 dmu_buf_t *dbp; 91 spa_history_phys_t *shpp; 92 objset_t *mos = spa->spa_meta_objset; 93 94 ASSERT0(spa->spa_history); 95 spa->spa_history = dmu_object_alloc(mos, DMU_OT_SPA_HISTORY, 96 SPA_OLD_MAXBLOCKSIZE, DMU_OT_SPA_HISTORY_OFFSETS, 97 sizeof (spa_history_phys_t), tx); 98 99 VERIFY0(zap_add(mos, DMU_POOL_DIRECTORY_OBJECT, 100 DMU_POOL_HISTORY, sizeof (uint64_t), 1, 101 &spa->spa_history, tx)); 102 103 VERIFY0(dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp)); 104 ASSERT3U(dbp->db_size, >=, sizeof (spa_history_phys_t)); 105 106 shpp = dbp->db_data; 107 dmu_buf_will_dirty(dbp, tx); 108 109 /* 110 * Figure out maximum size of history log. We set it at 111 * 0.1% of pool size, with a max of 1G and min of 128KB. 112 */ 113 shpp->sh_phys_max_off = 114 metaslab_class_get_dspace(spa_normal_class(spa)) / 1000; 115 shpp->sh_phys_max_off = MIN(shpp->sh_phys_max_off, 1<<30); 116 shpp->sh_phys_max_off = MAX(shpp->sh_phys_max_off, 128<<10); 117 118 dmu_buf_rele(dbp, FTAG); 119 } 120 121 /* 122 * Change 'sh_bof' to the beginning of the next record. 123 */ 124 static int 125 spa_history_advance_bof(spa_t *spa, spa_history_phys_t *shpp) 126 { 127 objset_t *mos = spa->spa_meta_objset; 128 uint64_t firstread, reclen, phys_bof; 129 char buf[sizeof (reclen)]; 130 int err; 131 132 phys_bof = spa_history_log_to_phys(shpp->sh_bof, shpp); 133 firstread = MIN(sizeof (reclen), shpp->sh_phys_max_off - phys_bof); 134 135 if ((err = dmu_read(mos, spa->spa_history, phys_bof, firstread, 136 buf, DMU_READ_PREFETCH)) != 0) 137 return (err); 138 if (firstread != sizeof (reclen)) { 139 if ((err = dmu_read(mos, spa->spa_history, 140 shpp->sh_pool_create_len, sizeof (reclen) - firstread, 141 buf + firstread, DMU_READ_PREFETCH)) != 0) 142 return (err); 143 } 144 145 reclen = LE_64(*((uint64_t *)buf)); 146 shpp->sh_bof += reclen + sizeof (reclen); 147 shpp->sh_records_lost++; 148 return (0); 149 } 150 151 static int 152 spa_history_write(spa_t *spa, void *buf, uint64_t len, spa_history_phys_t *shpp, 153 dmu_tx_t *tx) 154 { 155 uint64_t firstwrite, phys_eof; 156 objset_t *mos = spa->spa_meta_objset; 157 int err; 158 159 ASSERT(MUTEX_HELD(&spa->spa_history_lock)); 160 161 /* see if we need to reset logical BOF */ 162 while (shpp->sh_phys_max_off - shpp->sh_pool_create_len - 163 (shpp->sh_eof - shpp->sh_bof) <= len) { 164 if ((err = spa_history_advance_bof(spa, shpp)) != 0) { 165 return (err); 166 } 167 } 168 169 phys_eof = spa_history_log_to_phys(shpp->sh_eof, shpp); 170 firstwrite = MIN(len, shpp->sh_phys_max_off - phys_eof); 171 shpp->sh_eof += len; 172 dmu_write(mos, spa->spa_history, phys_eof, firstwrite, buf, tx); 173 174 len -= firstwrite; 175 if (len > 0) { 176 /* write out the rest at the beginning of physical file */ 177 dmu_write(mos, spa->spa_history, shpp->sh_pool_create_len, 178 len, (char *)buf + firstwrite, tx); 179 } 180 181 return (0); 182 } 183 184 /* 185 * Post a history sysevent. 186 * 187 * The nvlist_t* passed into this function will be transformed into a new 188 * nvlist where: 189 * 190 * 1. Nested nvlists will be flattened to a single level 191 * 2. Keys will have their names normalized (to remove any problematic 192 * characters, such as whitespace) 193 * 194 * The nvlist_t passed into this function will duplicated and should be freed 195 * by caller. 196 * 197 */ 198 static void 199 spa_history_log_notify(spa_t *spa, nvlist_t *nvl) 200 { 201 nvlist_t *hist_nvl = fnvlist_alloc(); 202 uint64_t uint64; 203 const char *string; 204 205 if (nvlist_lookup_string(nvl, ZPOOL_HIST_CMD, &string) == 0) 206 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_CMD, string); 207 208 if (nvlist_lookup_string(nvl, ZPOOL_HIST_INT_NAME, &string) == 0) 209 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_INT_NAME, string); 210 211 if (nvlist_lookup_string(nvl, ZPOOL_HIST_ZONE, &string) == 0) 212 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_ZONE, string); 213 214 if (nvlist_lookup_string(nvl, ZPOOL_HIST_HOST, &string) == 0) 215 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_HOST, string); 216 217 if (nvlist_lookup_string(nvl, ZPOOL_HIST_DSNAME, &string) == 0) 218 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_DSNAME, string); 219 220 if (nvlist_lookup_string(nvl, ZPOOL_HIST_INT_STR, &string) == 0) 221 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_INT_STR, string); 222 223 if (nvlist_lookup_string(nvl, ZPOOL_HIST_IOCTL, &string) == 0) 224 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_IOCTL, string); 225 226 if (nvlist_lookup_string(nvl, ZPOOL_HIST_INT_NAME, &string) == 0) 227 fnvlist_add_string(hist_nvl, ZFS_EV_HIST_INT_NAME, string); 228 229 if (nvlist_lookup_uint64(nvl, ZPOOL_HIST_DSID, &uint64) == 0) 230 fnvlist_add_uint64(hist_nvl, ZFS_EV_HIST_DSID, uint64); 231 232 if (nvlist_lookup_uint64(nvl, ZPOOL_HIST_TXG, &uint64) == 0) 233 fnvlist_add_uint64(hist_nvl, ZFS_EV_HIST_TXG, uint64); 234 235 if (nvlist_lookup_uint64(nvl, ZPOOL_HIST_TIME, &uint64) == 0) 236 fnvlist_add_uint64(hist_nvl, ZFS_EV_HIST_TIME, uint64); 237 238 if (nvlist_lookup_uint64(nvl, ZPOOL_HIST_WHO, &uint64) == 0) 239 fnvlist_add_uint64(hist_nvl, ZFS_EV_HIST_WHO, uint64); 240 241 if (nvlist_lookup_uint64(nvl, ZPOOL_HIST_INT_EVENT, &uint64) == 0) 242 fnvlist_add_uint64(hist_nvl, ZFS_EV_HIST_INT_EVENT, uint64); 243 244 spa_event_notify(spa, NULL, hist_nvl, ESC_ZFS_HISTORY_EVENT); 245 246 nvlist_free(hist_nvl); 247 } 248 249 /* 250 * Write out a history event. 251 */ 252 static void 253 spa_history_log_sync(void *arg, dmu_tx_t *tx) 254 { 255 nvlist_t *nvl = arg; 256 spa_t *spa = dmu_tx_pool(tx)->dp_spa; 257 objset_t *mos = spa->spa_meta_objset; 258 dmu_buf_t *dbp; 259 spa_history_phys_t *shpp; 260 size_t reclen; 261 uint64_t le_len; 262 char *record_packed = NULL; 263 int ret; 264 265 /* 266 * If we have an older pool that doesn't have a command 267 * history object, create it now. 268 */ 269 mutex_enter(&spa->spa_history_lock); 270 if (!spa->spa_history) 271 spa_history_create_obj(spa, tx); 272 mutex_exit(&spa->spa_history_lock); 273 274 /* 275 * Get the offset of where we need to write via the bonus buffer. 276 * Update the offset when the write completes. 277 */ 278 VERIFY0(dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp)); 279 shpp = dbp->db_data; 280 281 dmu_buf_will_dirty(dbp, tx); 282 283 #ifdef ZFS_DEBUG 284 { 285 dmu_object_info_t doi; 286 dmu_object_info_from_db(dbp, &doi); 287 ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_SPA_HISTORY_OFFSETS); 288 } 289 #endif 290 291 fnvlist_add_string(nvl, ZPOOL_HIST_HOST, utsname()->nodename); 292 293 if (nvlist_exists(nvl, ZPOOL_HIST_CMD)) { 294 zfs_dbgmsg("command: %s", 295 fnvlist_lookup_string(nvl, ZPOOL_HIST_CMD)); 296 } else if (nvlist_exists(nvl, ZPOOL_HIST_INT_NAME)) { 297 if (nvlist_exists(nvl, ZPOOL_HIST_DSNAME)) { 298 zfs_dbgmsg("txg %lld %s %s (id %llu) %s", 299 (longlong_t)fnvlist_lookup_uint64(nvl, 300 ZPOOL_HIST_TXG), 301 fnvlist_lookup_string(nvl, ZPOOL_HIST_INT_NAME), 302 fnvlist_lookup_string(nvl, ZPOOL_HIST_DSNAME), 303 (u_longlong_t)fnvlist_lookup_uint64(nvl, 304 ZPOOL_HIST_DSID), 305 fnvlist_lookup_string(nvl, ZPOOL_HIST_INT_STR)); 306 } else { 307 zfs_dbgmsg("txg %lld %s %s", 308 (longlong_t)fnvlist_lookup_uint64(nvl, 309 ZPOOL_HIST_TXG), 310 fnvlist_lookup_string(nvl, ZPOOL_HIST_INT_NAME), 311 fnvlist_lookup_string(nvl, ZPOOL_HIST_INT_STR)); 312 } 313 /* 314 * The history sysevent is posted only for internal history 315 * messages to show what has happened, not how it happened. For 316 * example, the following command: 317 * 318 * # zfs destroy -r tank/foo 319 * 320 * will result in one sysevent posted per dataset that is 321 * destroyed as a result of the command - which could be more 322 * than one event in total. By contrast, if the sysevent was 323 * posted as a result of the ZPOOL_HIST_CMD key being present 324 * it would result in only one sysevent being posted with the 325 * full command line arguments, requiring the consumer to know 326 * how to parse and understand zfs(8) command invocations. 327 */ 328 spa_history_log_notify(spa, nvl); 329 } else if (nvlist_exists(nvl, ZPOOL_HIST_IOCTL)) { 330 zfs_dbgmsg("ioctl %s", 331 fnvlist_lookup_string(nvl, ZPOOL_HIST_IOCTL)); 332 } 333 334 VERIFY3U(nvlist_pack(nvl, &record_packed, &reclen, NV_ENCODE_NATIVE, 335 KM_SLEEP), ==, 0); 336 337 mutex_enter(&spa->spa_history_lock); 338 339 /* write out the packed length as little endian */ 340 le_len = LE_64((uint64_t)reclen); 341 ret = spa_history_write(spa, &le_len, sizeof (le_len), shpp, tx); 342 if (!ret) 343 ret = spa_history_write(spa, record_packed, reclen, shpp, tx); 344 345 /* The first command is the create, which we keep forever */ 346 if (ret == 0 && shpp->sh_pool_create_len == 0 && 347 nvlist_exists(nvl, ZPOOL_HIST_CMD)) { 348 shpp->sh_pool_create_len = shpp->sh_bof = shpp->sh_eof; 349 } 350 351 mutex_exit(&spa->spa_history_lock); 352 fnvlist_pack_free(record_packed, reclen); 353 dmu_buf_rele(dbp, FTAG); 354 fnvlist_free(nvl); 355 } 356 357 /* 358 * Write out a history event. 359 */ 360 int 361 spa_history_log(spa_t *spa, const char *msg) 362 { 363 int err; 364 nvlist_t *nvl = fnvlist_alloc(); 365 366 fnvlist_add_string(nvl, ZPOOL_HIST_CMD, msg); 367 err = spa_history_log_nvl(spa, nvl); 368 fnvlist_free(nvl); 369 return (err); 370 } 371 372 int 373 spa_history_log_nvl(spa_t *spa, nvlist_t *nvl) 374 { 375 int err = 0; 376 dmu_tx_t *tx; 377 nvlist_t *nvarg, *in_nvl = NULL; 378 379 if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY || !spa_writeable(spa)) 380 return (SET_ERROR(EINVAL)); 381 382 err = nvlist_lookup_nvlist(nvl, ZPOOL_HIST_INPUT_NVL, &in_nvl); 383 if (err == 0) { 384 (void) nvlist_remove_all(in_nvl, ZPOOL_HIDDEN_ARGS); 385 } 386 387 tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir); 388 err = dmu_tx_assign(tx, DMU_TX_WAIT); 389 if (err) { 390 dmu_tx_abort(tx); 391 return (err); 392 } 393 394 ASSERT3UF(tx->tx_txg, <=, spa_final_dirty_txg(spa), 395 "Logged %s after final txg was set!", "nvlist"); 396 397 VERIFY0(nvlist_dup(nvl, &nvarg, KM_SLEEP)); 398 if (spa_history_zone() != NULL) { 399 fnvlist_add_string(nvarg, ZPOOL_HIST_ZONE, 400 spa_history_zone()); 401 } 402 fnvlist_add_uint64(nvarg, ZPOOL_HIST_WHO, crgetruid(CRED())); 403 404 /* 405 * Since the history is recorded asynchronously, the effective time is 406 * now, which may be considerably before the change is made on disk. 407 */ 408 fnvlist_add_uint64(nvarg, ZPOOL_HIST_TIME, gethrestime_sec()); 409 410 /* Kick this off asynchronously; errors are ignored. */ 411 dsl_sync_task_nowait(spa_get_dsl(spa), spa_history_log_sync, nvarg, tx); 412 dmu_tx_commit(tx); 413 414 /* spa_history_log_sync will free nvl */ 415 return (err); 416 } 417 418 /* 419 * Read out the command history. 420 */ 421 int 422 spa_history_get(spa_t *spa, uint64_t *offp, uint64_t *len, char *buf) 423 { 424 objset_t *mos = spa->spa_meta_objset; 425 dmu_buf_t *dbp; 426 uint64_t read_len, phys_read_off, phys_eof; 427 uint64_t leftover = 0; 428 spa_history_phys_t *shpp; 429 int err; 430 431 /* 432 * If the command history doesn't exist (older pool), 433 * that's ok, just return ENOENT. 434 */ 435 if (!spa->spa_history) 436 return (SET_ERROR(ENOENT)); 437 438 /* 439 * The history is logged asynchronously, so when they request 440 * the first chunk of history, make sure everything has been 441 * synced to disk so that we get it. 442 */ 443 if (*offp == 0 && spa_writeable(spa)) 444 txg_wait_synced(spa_get_dsl(spa), 0); 445 446 if ((err = dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp)) != 0) 447 return (err); 448 shpp = dbp->db_data; 449 450 #ifdef ZFS_DEBUG 451 { 452 dmu_object_info_t doi; 453 dmu_object_info_from_db(dbp, &doi); 454 ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_SPA_HISTORY_OFFSETS); 455 } 456 #endif 457 458 mutex_enter(&spa->spa_history_lock); 459 phys_eof = spa_history_log_to_phys(shpp->sh_eof, shpp); 460 461 if (*offp < shpp->sh_pool_create_len) { 462 /* read in just the zpool create history */ 463 phys_read_off = *offp; 464 read_len = MIN(*len, shpp->sh_pool_create_len - 465 phys_read_off); 466 } else { 467 /* 468 * Need to reset passed in offset to BOF if the passed in 469 * offset has since been overwritten. 470 */ 471 *offp = MAX(*offp, shpp->sh_bof); 472 phys_read_off = spa_history_log_to_phys(*offp, shpp); 473 474 /* 475 * Read up to the minimum of what the user passed down or 476 * the EOF (physical or logical). If we hit physical EOF, 477 * use 'leftover' to read from the physical BOF. 478 */ 479 if (phys_read_off <= phys_eof) { 480 read_len = MIN(*len, phys_eof - phys_read_off); 481 } else { 482 read_len = MIN(*len, 483 shpp->sh_phys_max_off - phys_read_off); 484 if (phys_read_off + *len > shpp->sh_phys_max_off) { 485 leftover = MIN(*len - read_len, 486 phys_eof - shpp->sh_pool_create_len); 487 } 488 } 489 } 490 491 /* offset for consumer to use next */ 492 *offp += read_len + leftover; 493 494 /* tell the consumer how much you actually read */ 495 *len = read_len + leftover; 496 497 if (read_len == 0) { 498 mutex_exit(&spa->spa_history_lock); 499 dmu_buf_rele(dbp, FTAG); 500 return (0); 501 } 502 503 err = dmu_read(mos, spa->spa_history, phys_read_off, read_len, buf, 504 DMU_READ_PREFETCH); 505 if (leftover && err == 0) { 506 err = dmu_read(mos, spa->spa_history, shpp->sh_pool_create_len, 507 leftover, buf + read_len, DMU_READ_PREFETCH); 508 } 509 mutex_exit(&spa->spa_history_lock); 510 511 dmu_buf_rele(dbp, FTAG); 512 return (err); 513 } 514 515 /* 516 * The nvlist will be consumed by this call. 517 */ 518 static void 519 log_internal(nvlist_t *nvl, const char *operation, spa_t *spa, 520 dmu_tx_t *tx, const char *fmt, va_list adx) 521 { 522 char *msg; 523 524 /* 525 * If this is part of creating a pool, not everything is 526 * initialized yet, so don't bother logging the internal events. 527 * Likewise if the pool is not writeable. 528 */ 529 if (spa_is_initializing(spa) || !spa_writeable(spa)) { 530 fnvlist_free(nvl); 531 return; 532 } 533 534 ASSERT3UF(tx->tx_txg, <=, spa_final_dirty_txg(spa), 535 "Logged after final txg was set: %s %s", operation, fmt); 536 537 msg = kmem_vasprintf(fmt, adx); 538 fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg); 539 kmem_strfree(msg); 540 541 fnvlist_add_string(nvl, ZPOOL_HIST_INT_NAME, operation); 542 fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg); 543 fnvlist_add_uint64(nvl, ZPOOL_HIST_TIME, gethrestime_sec()); 544 545 if (dmu_tx_is_syncing(tx)) { 546 spa_history_log_sync(nvl, tx); 547 } else { 548 dsl_sync_task_nowait(spa_get_dsl(spa), 549 spa_history_log_sync, nvl, tx); 550 } 551 /* spa_history_log_sync() will free nvl */ 552 } 553 554 void 555 spa_history_log_internal(spa_t *spa, const char *operation, 556 dmu_tx_t *tx, const char *fmt, ...) 557 { 558 dmu_tx_t *htx = tx; 559 va_list adx; 560 561 /* create a tx if we didn't get one */ 562 if (tx == NULL) { 563 htx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir); 564 if (dmu_tx_assign(htx, DMU_TX_WAIT) != 0) { 565 dmu_tx_abort(htx); 566 return; 567 } 568 } 569 570 va_start(adx, fmt); 571 log_internal(fnvlist_alloc(), operation, spa, htx, fmt, adx); 572 va_end(adx); 573 574 /* if we didn't get a tx from the caller, commit the one we made */ 575 if (tx == NULL) 576 dmu_tx_commit(htx); 577 } 578 579 void 580 spa_history_log_internal_ds(dsl_dataset_t *ds, const char *operation, 581 dmu_tx_t *tx, const char *fmt, ...) 582 { 583 va_list adx; 584 char namebuf[ZFS_MAX_DATASET_NAME_LEN]; 585 nvlist_t *nvl = fnvlist_alloc(); 586 587 ASSERT(tx != NULL); 588 589 dsl_dataset_name(ds, namebuf); 590 fnvlist_add_string(nvl, ZPOOL_HIST_DSNAME, namebuf); 591 fnvlist_add_uint64(nvl, ZPOOL_HIST_DSID, ds->ds_object); 592 593 va_start(adx, fmt); 594 log_internal(nvl, operation, dsl_dataset_get_spa(ds), tx, fmt, adx); 595 va_end(adx); 596 } 597 598 void 599 spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation, 600 dmu_tx_t *tx, const char *fmt, ...) 601 { 602 va_list adx; 603 char namebuf[ZFS_MAX_DATASET_NAME_LEN]; 604 nvlist_t *nvl = fnvlist_alloc(); 605 606 ASSERT(tx != NULL); 607 608 dsl_dir_name(dd, namebuf); 609 fnvlist_add_string(nvl, ZPOOL_HIST_DSNAME, namebuf); 610 fnvlist_add_uint64(nvl, ZPOOL_HIST_DSID, 611 dsl_dir_phys(dd)->dd_head_dataset_obj); 612 613 va_start(adx, fmt); 614 log_internal(nvl, operation, dd->dd_pool->dp_spa, tx, fmt, adx); 615 va_end(adx); 616 } 617 618 void 619 spa_history_log_version(spa_t *spa, const char *operation, dmu_tx_t *tx) 620 { 621 utsname_t *u = utsname(); 622 623 spa_history_log_internal(spa, operation, tx, 624 "pool version %llu; software version %s; uts %s %s %s %s", 625 (u_longlong_t)spa_version(spa), ZFS_META_GITREV, 626 u->nodename, u->release, u->version, u->machine); 627 } 628 629 #ifndef _KERNEL 630 const char * 631 spa_history_zone(void) 632 { 633 return (NULL); 634 } 635 #endif 636 637 #if defined(_KERNEL) 638 EXPORT_SYMBOL(spa_history_create_obj); 639 EXPORT_SYMBOL(spa_history_get); 640 EXPORT_SYMBOL(spa_history_log); 641 EXPORT_SYMBOL(spa_history_log_internal); 642 EXPORT_SYMBOL(spa_history_log_version); 643 #endif 644