zil.c (209962) | zil.c (213197) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 11 unchanged lines hidden (view full) --- 20 */ 21/* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26#include <sys/zfs_context.h> 27#include <sys/spa.h> | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 11 unchanged lines hidden (view full) --- 20 */ 21/* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26#include <sys/zfs_context.h> 27#include <sys/spa.h> |
28#include <sys/spa_impl.h> |
|
28#include <sys/dmu.h> 29#include <sys/zap.h> 30#include <sys/arc.h> 31#include <sys/stat.h> 32#include <sys/resource.h> 33#include <sys/zil.h> 34#include <sys/zil_impl.h> 35#include <sys/dsl_dataset.h> --- 474 unchanged lines hidden (view full) --- 510 if (error) { 511 cmn_err(CE_WARN, "can't open objset for %s", osname); 512 return (0); 513 } 514 515 zilog = dmu_objset_zil(os); 516 zh = zil_header_in_syncing_context(zilog); 517 | 29#include <sys/dmu.h> 30#include <sys/zap.h> 31#include <sys/arc.h> 32#include <sys/stat.h> 33#include <sys/resource.h> 34#include <sys/zil.h> 35#include <sys/zil_impl.h> 36#include <sys/dsl_dataset.h> --- 474 unchanged lines hidden (view full) --- 511 if (error) { 512 cmn_err(CE_WARN, "can't open objset for %s", osname); 513 return (0); 514 } 515 516 zilog = dmu_objset_zil(os); 517 zh = zil_header_in_syncing_context(zilog); 518 |
519 if (zilog->zl_spa->spa_log_state == SPA_LOG_CLEAR) { 520 if (!BP_IS_HOLE(&zh->zh_log)) 521 zio_free_blk(zilog->zl_spa, &zh->zh_log, first_txg); 522 BP_ZERO(&zh->zh_log); 523 dsl_dataset_dirty(dmu_objset_ds(os), tx); 524 } 525 |
|
518 /* 519 * Record here whether the zil has any records to replay. 520 * If the header block pointer is null or the block points 521 * to the stubby then we know there are no valid log records. 522 * We use the header to store this state as the the zilog gets 523 * freed later in dmu_objset_close(). 524 * The flags (and the rest of the header fields) are cleared in 525 * zil_sync() as a result of a zil_destroy(), after replaying the log. 526 * 527 * Note, the intent log can be empty but still need the 528 * stubby to be claimed. 529 */ | 526 /* 527 * Record here whether the zil has any records to replay. 528 * If the header block pointer is null or the block points 529 * to the stubby then we know there are no valid log records. 530 * We use the header to store this state as the the zilog gets 531 * freed later in dmu_objset_close(). 532 * The flags (and the rest of the header fields) are cleared in 533 * zil_sync() as a result of a zil_destroy(), after replaying the log. 534 * 535 * Note, the intent log can be empty but still need the 536 * stubby to be claimed. 537 */ |
530 if (!zil_empty(zilog)) | 538 if (!zil_empty(zilog)) { |
531 zh->zh_flags |= ZIL_REPLAY_NEEDED; | 539 zh->zh_flags |= ZIL_REPLAY_NEEDED; |
540 dsl_dataset_dirty(dmu_objset_ds(os), tx); 541 } |
|
532 533 /* 534 * Claim all log blocks if we haven't already done so, and remember 535 * the highest claimed sequence number. This ensures that if we can 536 * read only part of the log now (e.g. due to a missing device), 537 * but we can read the entire log later, we will not try to replay 538 * or destroy beyond the last block we successfully claimed. 539 */ --- 52 unchanged lines hidden (view full) --- 592 VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1); 593 } 594 dmu_objset_close(os); 595 if (error == ECKSUM) 596 return (0); /* normal end of chain */ 597 return (error); 598} 599 | 542 543 /* 544 * Claim all log blocks if we haven't already done so, and remember 545 * the highest claimed sequence number. This ensures that if we can 546 * read only part of the log now (e.g. due to a missing device), 547 * but we can read the entire log later, we will not try to replay 548 * or destroy beyond the last block we successfully claimed. 549 */ --- 52 unchanged lines hidden (view full) --- 602 VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1); 603 } 604 dmu_objset_close(os); 605 if (error == ECKSUM) 606 return (0); /* normal end of chain */ 607 return (error); 608} 609 |
600/* 601 * Clear a log chain 602 */ 603/* ARGSUSED */ 604int 605zil_clear_log_chain(char *osname, void *txarg) 606{ 607 zilog_t *zilog; 608 zil_header_t *zh; 609 objset_t *os; 610 dmu_tx_t *tx; 611 int error; 612 613 error = dmu_objset_open(osname, DMU_OST_ANY, DS_MODE_USER, &os); 614 if (error) { 615 cmn_err(CE_WARN, "can't open objset for %s", osname); 616 return (0); 617 } 618 619 zilog = dmu_objset_zil(os); 620 tx = dmu_tx_create(zilog->zl_os); 621 (void) dmu_tx_assign(tx, TXG_WAIT); 622 zh = zil_header_in_syncing_context(zilog); 623 BP_ZERO(&zh->zh_log); 624 dsl_dataset_dirty(dmu_objset_ds(os), tx); 625 dmu_tx_commit(tx); 626 dmu_objset_close(os); 627 return (0); 628} 629 | |
630static int 631zil_vdev_compare(const void *x1, const void *x2) 632{ 633 uint64_t v1 = ((zil_vdev_node_t *)x1)->zv_vdev; 634 uint64_t v2 = ((zil_vdev_node_t *)x2)->zv_vdev; 635 636 if (v1 < v2) 637 return (-1); --- 128 unchanged lines hidden (view full) --- 766 zb.zb_blkid = lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_SEQ]; 767 768 if (zilog->zl_root_zio == NULL) { 769 zilog->zl_root_zio = zio_root(zilog->zl_spa, NULL, NULL, 770 ZIO_FLAG_CANFAIL); 771 } 772 if (lwb->lwb_zio == NULL) { 773 lwb->lwb_zio = zio_rewrite(zilog->zl_root_zio, zilog->zl_spa, | 610static int 611zil_vdev_compare(const void *x1, const void *x2) 612{ 613 uint64_t v1 = ((zil_vdev_node_t *)x1)->zv_vdev; 614 uint64_t v2 = ((zil_vdev_node_t *)x2)->zv_vdev; 615 616 if (v1 < v2) 617 return (-1); --- 128 unchanged lines hidden (view full) --- 746 zb.zb_blkid = lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_SEQ]; 747 748 if (zilog->zl_root_zio == NULL) { 749 zilog->zl_root_zio = zio_root(zilog->zl_spa, NULL, NULL, 750 ZIO_FLAG_CANFAIL); 751 } 752 if (lwb->lwb_zio == NULL) { 753 lwb->lwb_zio = zio_rewrite(zilog->zl_root_zio, zilog->zl_spa, |
774 0, &lwb->lwb_blk, lwb->lwb_buf, 775 lwb->lwb_sz, zil_lwb_write_done, lwb, 776 ZIO_PRIORITY_LOG_WRITE, ZIO_FLAG_CANFAIL, &zb); | 754 0, &lwb->lwb_blk, lwb->lwb_buf, lwb->lwb_sz, 755 zil_lwb_write_done, lwb, ZIO_PRIORITY_LOG_WRITE, 756 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE, &zb); |
777 } 778} 779 780/* 781 * Start a log block write and advance to the next log block. 782 * Calls are serialized. 783 */ 784static lwb_t * --- 480 unchanged lines hidden (view full) --- 1265 * To guard against this, assign a new GUID to the new 1266 * log chain so it doesn't matter what blk points to. 1267 */ 1268 zil_init_log_chain(zilog, &blk); 1269 zh->zh_log = blk; 1270 } 1271 } 1272 | 757 } 758} 759 760/* 761 * Start a log block write and advance to the next log block. 762 * Calls are serialized. 763 */ 764static lwb_t * --- 480 unchanged lines hidden (view full) --- 1245 * To guard against this, assign a new GUID to the new 1246 * log chain so it doesn't matter what blk points to. 1247 */ 1248 zil_init_log_chain(zilog, &blk); 1249 zh->zh_log = blk; 1250 } 1251 } 1252 |
1273 for (;;) { 1274 lwb = list_head(&zilog->zl_lwb_list); 1275 if (lwb == NULL) { 1276 mutex_exit(&zilog->zl_lock); 1277 return; 1278 } | 1253 while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) { |
1279 zh->zh_log = lwb->lwb_blk; 1280 if (lwb->lwb_buf != NULL || lwb->lwb_max_txg > txg) 1281 break; 1282 list_remove(&zilog->zl_lwb_list, lwb); 1283 zio_free_blk(spa, &lwb->lwb_blk, txg); 1284 kmem_cache_free(zil_lwb_cache, lwb); 1285 1286 /* --- 400 unchanged lines hidden (view full) --- 1687 1688 ASSERT(zil_empty(zilog)); 1689 ret = B_TRUE; 1690out: 1691 cv_broadcast(&zilog->zl_cv_writer); 1692 mutex_exit(&zilog->zl_lock); 1693 return (ret); 1694} | 1254 zh->zh_log = lwb->lwb_blk; 1255 if (lwb->lwb_buf != NULL || lwb->lwb_max_txg > txg) 1256 break; 1257 list_remove(&zilog->zl_lwb_list, lwb); 1258 zio_free_blk(spa, &lwb->lwb_blk, txg); 1259 kmem_cache_free(zil_lwb_cache, lwb); 1260 1261 /* --- 400 unchanged lines hidden (view full) --- 1662 1663 ASSERT(zil_empty(zilog)); 1664 ret = B_TRUE; 1665out: 1666 cv_broadcast(&zilog->zl_cv_writer); 1667 mutex_exit(&zilog->zl_lock); 1668 return (ret); 1669} |
1670 1671/* ARGSUSED */ 1672int 1673zil_vdev_offline(char *osname, void *arg) 1674{ 1675 objset_t *os; 1676 zilog_t *zilog; 1677 int error; 1678 1679 error = dmu_objset_open(osname, DMU_OST_ANY, DS_MODE_USER, &os); 1680 if (error) 1681 return (error); 1682 1683 zilog = dmu_objset_zil(os); 1684 if (zil_suspend(zilog) != 0) 1685 error = EEXIST; 1686 else 1687 zil_resume(zilog); 1688 dmu_objset_close(os); 1689 return (error); 1690} |
|