vdev_label.c (225736) | vdev_label.c (243674) |
---|---|
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 --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ | 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 --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ |
21 |
|
21/* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. | 22/* 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
24 * Copyright (c) 2012 by Delphix. All rights reserved. |
|
23 */ 24 25/* 26 * Virtual Device Labels 27 * --------------------- 28 * 29 * The vdev label serves several distinct purposes: 30 * --- 85 unchanged lines hidden (view full) --- 116 * The nvlist describing the pool and vdev contains the following elements: 117 * 118 * version ZFS on-disk version 119 * name Pool name 120 * state Pool state 121 * txg Transaction group in which this label was written 122 * pool_guid Unique identifier for this pool 123 * vdev_tree An nvlist describing vdev tree. | 25 */ 26 27/* 28 * Virtual Device Labels 29 * --------------------- 30 * 31 * The vdev label serves several distinct purposes: 32 * --- 85 unchanged lines hidden (view full) --- 118 * The nvlist describing the pool and vdev contains the following elements: 119 * 120 * version ZFS on-disk version 121 * name Pool name 122 * state Pool state 123 * txg Transaction group in which this label was written 124 * pool_guid Unique identifier for this pool 125 * vdev_tree An nvlist describing vdev tree. |
126 * features_for_read 127 * An nvlist of the features necessary for reading the MOS. |
|
124 * 125 * Each leaf device label also contains the following: 126 * 127 * top_guid Unique ID for top-level vdev in which this is contained 128 * guid Unique ID for the leaf vdev 129 * 130 * The 'vs' configuration follows the format described in 'spa_config.c'. 131 */ --- 291 unchanged lines hidden (view full) --- 423 } 424 425 VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_VDEV_CHILDREN, 426 rvd->vdev_children) == 0); 427 428 kmem_free(array, rvd->vdev_children * sizeof (uint64_t)); 429} 430 | 128 * 129 * Each leaf device label also contains the following: 130 * 131 * top_guid Unique ID for top-level vdev in which this is contained 132 * guid Unique ID for the leaf vdev 133 * 134 * The 'vs' configuration follows the format described in 'spa_config.c'. 135 */ --- 291 unchanged lines hidden (view full) --- 427 } 428 429 VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_VDEV_CHILDREN, 430 rvd->vdev_children) == 0); 431 432 kmem_free(array, rvd->vdev_children * sizeof (uint64_t)); 433} 434 |
435/* 436 * Returns the configuration from the label of the given vdev. For vdevs 437 * which don't have a txg value stored on their label (i.e. spares/cache) 438 * or have not been completely initialized (txg = 0) just return 439 * the configuration from the first valid label we find. Otherwise, 440 * find the most up-to-date label that does not exceed the specified 441 * 'txg' value. 442 */ |
|
431nvlist_t * | 443nvlist_t * |
432vdev_label_read_config(vdev_t *vd) | 444vdev_label_read_config(vdev_t *vd, uint64_t txg) |
433{ 434 spa_t *spa = vd->vdev_spa; 435 nvlist_t *config = NULL; 436 vdev_phys_t *vp; 437 zio_t *zio; | 445{ 446 spa_t *spa = vd->vdev_spa; 447 nvlist_t *config = NULL; 448 vdev_phys_t *vp; 449 zio_t *zio; |
450 uint64_t best_txg = 0; 451 int error = 0; |
|
438 int flags = ZIO_FLAG_CONFIG_WRITER | ZIO_FLAG_CANFAIL | 439 ZIO_FLAG_SPECULATIVE; 440 441 ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL); 442 443 if (!vdev_readable(vd)) 444 return (NULL); 445 446 vp = zio_buf_alloc(sizeof (vdev_phys_t)); 447 448retry: 449 for (int l = 0; l < VDEV_LABELS; l++) { | 452 int flags = ZIO_FLAG_CONFIG_WRITER | ZIO_FLAG_CANFAIL | 453 ZIO_FLAG_SPECULATIVE; 454 455 ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL); 456 457 if (!vdev_readable(vd)) 458 return (NULL); 459 460 vp = zio_buf_alloc(sizeof (vdev_phys_t)); 461 462retry: 463 for (int l = 0; l < VDEV_LABELS; l++) { |
464 nvlist_t *label = NULL; |
|
450 451 zio = zio_root(spa, NULL, NULL, flags); 452 453 vdev_label_read(zio, vd, l, vp, 454 offsetof(vdev_label_t, vl_vdev_phys), 455 sizeof (vdev_phys_t), NULL, NULL, flags); 456 457 if (zio_wait(zio) == 0 && 458 nvlist_unpack(vp->vp_nvlist, sizeof (vp->vp_nvlist), | 465 466 zio = zio_root(spa, NULL, NULL, flags); 467 468 vdev_label_read(zio, vd, l, vp, 469 offsetof(vdev_label_t, vl_vdev_phys), 470 sizeof (vdev_phys_t), NULL, NULL, flags); 471 472 if (zio_wait(zio) == 0 && 473 nvlist_unpack(vp->vp_nvlist, sizeof (vp->vp_nvlist), |
459 &config, 0) == 0) 460 break; | 474 &label, 0) == 0) { 475 uint64_t label_txg = 0; |
461 | 476 |
462 if (config != NULL) { 463 nvlist_free(config); 464 config = NULL; | 477 /* 478 * Auxiliary vdevs won't have txg values in their 479 * labels and newly added vdevs may not have been 480 * completely initialized so just return the 481 * configuration from the first valid label we 482 * encounter. 483 */ 484 error = nvlist_lookup_uint64(label, 485 ZPOOL_CONFIG_POOL_TXG, &label_txg); 486 if ((error || label_txg == 0) && !config) { 487 config = label; 488 break; 489 } else if (label_txg <= txg && label_txg > best_txg) { 490 best_txg = label_txg; 491 nvlist_free(config); 492 config = fnvlist_dup(label); 493 } |
465 } | 494 } |
495 496 if (label != NULL) { 497 nvlist_free(label); 498 label = NULL; 499 } |
|
466 } 467 468 if (config == NULL && !(flags & ZIO_FLAG_TRYHARD)) { 469 flags |= ZIO_FLAG_TRYHARD; 470 goto retry; 471 } 472 473 zio_buf_free(vp, sizeof (vdev_phys_t)); --- 17 unchanged lines hidden (view full) --- 491 if (spare_guid) 492 *spare_guid = 0ULL; 493 if (l2cache_guid) 494 *l2cache_guid = 0ULL; 495 496 /* 497 * Read the label, if any, and perform some basic sanity checks. 498 */ | 500 } 501 502 if (config == NULL && !(flags & ZIO_FLAG_TRYHARD)) { 503 flags |= ZIO_FLAG_TRYHARD; 504 goto retry; 505 } 506 507 zio_buf_free(vp, sizeof (vdev_phys_t)); --- 17 unchanged lines hidden (view full) --- 525 if (spare_guid) 526 *spare_guid = 0ULL; 527 if (l2cache_guid) 528 *l2cache_guid = 0ULL; 529 530 /* 531 * Read the label, if any, and perform some basic sanity checks. 532 */ |
499 if ((label = vdev_label_read_config(vd)) == NULL) | 533 if ((label = vdev_label_read_config(vd, -1ULL)) == NULL) |
500 return (B_FALSE); 501 502 (void) nvlist_lookup_uint64(label, ZPOOL_CONFIG_CREATE_TXG, 503 &vdtxg); 504 505 if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, 506 &state) != 0 || 507 nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, --- 320 unchanged lines hidden (view full) --- 828 */ 829 830/* 831 * Consider the following situation: txg is safely synced to disk. We've 832 * written the first uberblock for txg + 1, and then we lose power. When we 833 * come back up, we fail to see the uberblock for txg + 1 because, say, 834 * it was on a mirrored device and the replica to which we wrote txg + 1 835 * is now offline. If we then make some changes and sync txg + 1, and then | 534 return (B_FALSE); 535 536 (void) nvlist_lookup_uint64(label, ZPOOL_CONFIG_CREATE_TXG, 537 &vdtxg); 538 539 if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, 540 &state) != 0 || 541 nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, --- 320 unchanged lines hidden (view full) --- 862 */ 863 864/* 865 * Consider the following situation: txg is safely synced to disk. We've 866 * written the first uberblock for txg + 1, and then we lose power. When we 867 * come back up, we fail to see the uberblock for txg + 1 because, say, 868 * it was on a mirrored device and the replica to which we wrote txg + 1 869 * is now offline. If we then make some changes and sync txg + 1, and then |
836 * the missing replica comes back, then for a new seconds we'll have two | 870 * the missing replica comes back, then for a few seconds we'll have two |
837 * conflicting uberblocks on disk with the same txg. The solution is simple: 838 * among uberblocks with equal txg, choose the one with the latest timestamp. 839 */ 840static int 841vdev_uberblock_compare(uberblock_t *ub1, uberblock_t *ub2) 842{ 843 if (ub1->ub_txg < ub2->ub_txg) 844 return (-1); 845 if (ub1->ub_txg > ub2->ub_txg) 846 return (1); 847 848 if (ub1->ub_timestamp < ub2->ub_timestamp) 849 return (-1); 850 if (ub1->ub_timestamp > ub2->ub_timestamp) 851 return (1); 852 853 return (0); 854} 855 | 871 * conflicting uberblocks on disk with the same txg. The solution is simple: 872 * among uberblocks with equal txg, choose the one with the latest timestamp. 873 */ 874static int 875vdev_uberblock_compare(uberblock_t *ub1, uberblock_t *ub2) 876{ 877 if (ub1->ub_txg < ub2->ub_txg) 878 return (-1); 879 if (ub1->ub_txg > ub2->ub_txg) 880 return (1); 881 882 if (ub1->ub_timestamp < ub2->ub_timestamp) 883 return (-1); 884 if (ub1->ub_timestamp > ub2->ub_timestamp) 885 return (1); 886 887 return (0); 888} 889 |
890struct ubl_cbdata { 891 uberblock_t *ubl_ubbest; /* Best uberblock */ 892 vdev_t *ubl_vd; /* vdev associated with the above */ 893}; 894 |
|
856static void 857vdev_uberblock_load_done(zio_t *zio) 858{ | 895static void 896vdev_uberblock_load_done(zio_t *zio) 897{ |
898 vdev_t *vd = zio->io_vd; |
|
859 spa_t *spa = zio->io_spa; 860 zio_t *rio = zio->io_private; 861 uberblock_t *ub = zio->io_data; | 899 spa_t *spa = zio->io_spa; 900 zio_t *rio = zio->io_private; 901 uberblock_t *ub = zio->io_data; |
862 uberblock_t *ubbest = rio->io_private; | 902 struct ubl_cbdata *cbp = rio->io_private; |
863 | 903 |
864 ASSERT3U(zio->io_size, ==, VDEV_UBERBLOCK_SIZE(zio->io_vd)); | 904 ASSERT3U(zio->io_size, ==, VDEV_UBERBLOCK_SIZE(vd)); |
865 866 if (zio->io_error == 0 && uberblock_verify(ub) == 0) { 867 mutex_enter(&rio->io_lock); 868 if (ub->ub_txg <= spa->spa_load_max_txg && | 905 906 if (zio->io_error == 0 && uberblock_verify(ub) == 0) { 907 mutex_enter(&rio->io_lock); 908 if (ub->ub_txg <= spa->spa_load_max_txg && |
869 vdev_uberblock_compare(ub, ubbest) > 0) 870 *ubbest = *ub; | 909 vdev_uberblock_compare(ub, cbp->ubl_ubbest) > 0) { 910 /* 911 * Keep track of the vdev in which this uberblock 912 * was found. We will use this information later 913 * to obtain the config nvlist associated with 914 * this uberblock. 915 */ 916 *cbp->ubl_ubbest = *ub; 917 cbp->ubl_vd = vd; 918 } |
871 mutex_exit(&rio->io_lock); 872 } 873 874 zio_buf_free(zio->io_data, zio->io_size); 875} 876 | 919 mutex_exit(&rio->io_lock); 920 } 921 922 zio_buf_free(zio->io_data, zio->io_size); 923} 924 |
877void 878vdev_uberblock_load(zio_t *zio, vdev_t *vd, uberblock_t *ubbest) | 925static void 926vdev_uberblock_load_impl(zio_t *zio, vdev_t *vd, int flags, 927 struct ubl_cbdata *cbp) |
879{ | 928{ |
880 spa_t *spa = vd->vdev_spa; 881 vdev_t *rvd = spa->spa_root_vdev; 882 int flags = ZIO_FLAG_CONFIG_WRITER | ZIO_FLAG_CANFAIL | 883 ZIO_FLAG_SPECULATIVE | ZIO_FLAG_TRYHARD; 884 885 if (vd == rvd) { 886 ASSERT(zio == NULL); 887 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 888 zio = zio_root(spa, NULL, ubbest, flags); 889 bzero(ubbest, sizeof (uberblock_t)); 890 } 891 892 ASSERT(zio != NULL); 893 | |
894 for (int c = 0; c < vd->vdev_children; c++) | 929 for (int c = 0; c < vd->vdev_children; c++) |
895 vdev_uberblock_load(zio, vd->vdev_child[c], ubbest); | 930 vdev_uberblock_load_impl(zio, vd->vdev_child[c], flags, cbp); |
896 897 if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) { 898 for (int l = 0; l < VDEV_LABELS; l++) { 899 for (int n = 0; n < VDEV_UBERBLOCK_COUNT(vd); n++) { 900 vdev_label_read(zio, vd, l, 901 zio_buf_alloc(VDEV_UBERBLOCK_SIZE(vd)), 902 VDEV_UBERBLOCK_OFFSET(vd, n), 903 VDEV_UBERBLOCK_SIZE(vd), 904 vdev_uberblock_load_done, zio, flags); 905 } 906 } 907 } | 931 932 if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) { 933 for (int l = 0; l < VDEV_LABELS; l++) { 934 for (int n = 0; n < VDEV_UBERBLOCK_COUNT(vd); n++) { 935 vdev_label_read(zio, vd, l, 936 zio_buf_alloc(VDEV_UBERBLOCK_SIZE(vd)), 937 VDEV_UBERBLOCK_OFFSET(vd, n), 938 VDEV_UBERBLOCK_SIZE(vd), 939 vdev_uberblock_load_done, zio, flags); 940 } 941 } 942 } |
943} |
|
908 | 944 |
909 if (vd == rvd) { 910 (void) zio_wait(zio); 911 spa_config_exit(spa, SCL_ALL, FTAG); 912 } | 945/* 946 * Reads the 'best' uberblock from disk along with its associated 947 * configuration. First, we read the uberblock array of each label of each 948 * vdev, keeping track of the uberblock with the highest txg in each array. 949 * Then, we read the configuration from the same vdev as the best uberblock. 950 */ 951void 952vdev_uberblock_load(vdev_t *rvd, uberblock_t *ub, nvlist_t **config) 953{ 954 zio_t *zio; 955 spa_t *spa = rvd->vdev_spa; 956 struct ubl_cbdata cb; 957 int flags = ZIO_FLAG_CONFIG_WRITER | ZIO_FLAG_CANFAIL | 958 ZIO_FLAG_SPECULATIVE | ZIO_FLAG_TRYHARD; 959 960 ASSERT(ub); 961 ASSERT(config); 962 963 bzero(ub, sizeof (uberblock_t)); 964 *config = NULL; 965 966 cb.ubl_ubbest = ub; 967 cb.ubl_vd = NULL; 968 969 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER); 970 zio = zio_root(spa, NULL, &cb, flags); 971 vdev_uberblock_load_impl(zio, rvd, flags, &cb); 972 (void) zio_wait(zio); 973 974 /* 975 * It's possible that the best uberblock was discovered on a label 976 * that has a configuration which was written in a future txg. 977 * Search all labels on this vdev to find the configuration that 978 * matches the txg for our uberblock. 979 */ 980 if (cb.ubl_vd != NULL) 981 *config = vdev_label_read_config(cb.ubl_vd, ub->ub_txg); 982 spa_config_exit(spa, SCL_ALL, FTAG); |
913} 914 915/* 916 * On success, increment root zio's count of good writes. 917 * We only get credit for writes to known-visible vdevs; see spa_vdev_add(). 918 */ 919static void 920vdev_uberblock_sync_done(zio_t *zio) --- 296 unchanged lines hidden --- | 983} 984 985/* 986 * On success, increment root zio's count of good writes. 987 * We only get credit for writes to known-visible vdevs; see spa_vdev_add(). 988 */ 989static void 990vdev_uberblock_sync_done(zio_t *zio) --- 296 unchanged lines hidden --- |