FreeBSD ZFS
The Zettabyte File System
|
00001 /* 00002 * CDDL HEADER START 00003 * 00004 * The contents of this file are subject to the terms of the 00005 * Common Development and Distribution License (the "License"). 00006 * You may not use this file except in compliance with the License. 00007 * 00008 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 00009 * or http://www.opensolaris.org/os/licensing. 00010 * See the License for the specific language governing permissions 00011 * and limitations under the License. 00012 * 00013 * When distributing Covered Code, include this CDDL HEADER in each 00014 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 00015 * If applicable, add the following below this CDDL HEADER, with the 00016 * fields enclosed by brackets "[]" replaced with your own identifying 00017 * information: Portions Copyright [yyyy] [name of copyright owner] 00018 * 00019 * CDDL HEADER END 00020 */ 00021 /* 00022 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 00023 * Use is subject to license terms. 00024 */ 00025 00026 /* 00027 * Copyright (c) 2012 by Delphix. All rights reserved. 00028 */ 00029 00030 #include <sys/zfs_context.h> 00031 #include <sys/spa.h> 00032 #include <sys/vdev_impl.h> 00033 #include <sys/zio.h> 00034 #include <sys/fs/zfs.h> 00035 00050 static int 00051 too_many_errors(vdev_t *vd, int numerrors) 00052 { 00053 ASSERT3U(numerrors, <=, vd->vdev_children); 00054 return (numerrors > 0); 00055 } 00056 00057 static int 00058 vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *max_asize, 00059 uint64_t *ashift) 00060 { 00061 int lasterror = 0; 00062 int numerrors = 0; 00063 00064 if (vd->vdev_children == 0) { 00065 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; 00066 return (EINVAL); 00067 } 00068 00069 vdev_open_children(vd); 00070 00071 for (int c = 0; c < vd->vdev_children; c++) { 00072 vdev_t *cvd = vd->vdev_child[c]; 00073 00074 if (cvd->vdev_open_error && !cvd->vdev_islog) { 00075 lasterror = cvd->vdev_open_error; 00076 numerrors++; 00077 } 00078 } 00079 00080 if (too_many_errors(vd, numerrors)) { 00081 vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS; 00082 return (lasterror); 00083 } 00084 00085 *asize = 0; 00086 *max_asize = 0; 00087 *ashift = 0; 00088 00089 return (0); 00090 } 00091 00092 static void 00093 vdev_root_close(vdev_t *vd) 00094 { 00095 for (int c = 0; c < vd->vdev_children; c++) 00096 vdev_close(vd->vdev_child[c]); 00097 } 00098 00099 static void 00100 vdev_root_state_change(vdev_t *vd, int faulted, int degraded) 00101 { 00102 if (too_many_errors(vd, faulted)) { 00103 vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN, 00104 VDEV_AUX_NO_REPLICAS); 00105 } else if (degraded) { 00106 vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE); 00107 } else { 00108 vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE); 00109 } 00110 } 00111 00112 vdev_ops_t vdev_root_ops = { 00113 vdev_root_open, 00114 vdev_root_close, 00115 vdev_default_asize, 00116 NULL, /* io_start - not applicable to the root */ 00117 NULL, /* io_done - not applicable to the root */ 00118 vdev_root_state_change, 00119 NULL, 00120 NULL, 00121 VDEV_TYPE_ROOT, /* name of this vdev type */ 00122 B_FALSE /* not a leaf vdev */ 00123 };