Deleted Added
sdiff udiff text old ( 225736 ) new ( 243674 )
full compact
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/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. 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.
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
431nvlist_t *
432vdev_label_read_config(vdev_t *vd)
433{
434 spa_t *spa = vd->vdev_spa;
435 nvlist_t *config = NULL;
436 vdev_phys_t *vp;
437 zio_t *zio;
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++) {
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),
459 &config, 0) == 0)
460 break;
461
462 if (config != NULL) {
463 nvlist_free(config);
464 config = NULL;
465 }
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 */
499 if ((label = vdev_label_read_config(vd)) == 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
836 * the missing replica comes back, then for a new 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
856static void
857vdev_uberblock_load_done(zio_t *zio)
858{
859 spa_t *spa = zio->io_spa;
860 zio_t *rio = zio->io_private;
861 uberblock_t *ub = zio->io_data;
862 uberblock_t *ubbest = rio->io_private;
863
864 ASSERT3U(zio->io_size, ==, VDEV_UBERBLOCK_SIZE(zio->io_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 &&
869 vdev_uberblock_compare(ub, ubbest) > 0)
870 *ubbest = *ub;
871 mutex_exit(&rio->io_lock);
872 }
873
874 zio_buf_free(zio->io_data, zio->io_size);
875}
876
877void
878vdev_uberblock_load(zio_t *zio, vdev_t *vd, uberblock_t *ubbest)
879{
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++)
895 vdev_uberblock_load(zio, vd->vdev_child[c], ubbest);
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 }
908
909 if (vd == rvd) {
910 (void) zio_wait(zio);
911 spa_config_exit(spa, SCL_ALL, FTAG);
912 }
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 ---