Deleted Added
full compact
vdev.c (230514) vdev.c (236155)
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

--- 8 unchanged lines hidden (view full) ---

17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
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

--- 8 unchanged lines hidden (view full) ---

17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2011 by Delphix. All rights reserved.
25 * Copyright (c) 2012 by Delphix. All rights reserved.
26 */
27
28#include <sys/zfs_context.h>
29#include <sys/fm/fs/zfs.h>
30#include <sys/spa.h>
31#include <sys/spa_impl.h>
32#include <sys/dmu.h>
33#include <sys/dmu_tx.h>

--- 80 unchanged lines hidden (view full) ---

114 * can still satisfy the same number of allocations.
115 */
116uint64_t
117vdev_get_min_asize(vdev_t *vd)
118{
119 vdev_t *pvd = vd->vdev_parent;
120
121 /*
26 */
27
28#include <sys/zfs_context.h>
29#include <sys/fm/fs/zfs.h>
30#include <sys/spa.h>
31#include <sys/spa_impl.h>
32#include <sys/dmu.h>
33#include <sys/dmu_tx.h>

--- 80 unchanged lines hidden (view full) ---

114 * can still satisfy the same number of allocations.
115 */
116uint64_t
117vdev_get_min_asize(vdev_t *vd)
118{
119 vdev_t *pvd = vd->vdev_parent;
120
121 /*
122 * The our parent is NULL (inactive spare or cache) or is the root,
122 * If our parent is NULL (inactive spare or cache) or is the root,
123 * just return our own asize.
124 */
125 if (pvd == NULL)
126 return (vd->vdev_asize);
127
128 /*
129 * The top-level vdev just returns the allocatable size rounded
130 * to the nearest metaslab.

--- 612 unchanged lines hidden (view full) ---

743 vdev_t *mvd;
744
745 ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
746
747 mvd = vdev_alloc_common(spa, cvd->vdev_id, 0, ops);
748
749 mvd->vdev_asize = cvd->vdev_asize;
750 mvd->vdev_min_asize = cvd->vdev_min_asize;
123 * just return our own asize.
124 */
125 if (pvd == NULL)
126 return (vd->vdev_asize);
127
128 /*
129 * The top-level vdev just returns the allocatable size rounded
130 * to the nearest metaslab.

--- 612 unchanged lines hidden (view full) ---

743 vdev_t *mvd;
744
745 ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
746
747 mvd = vdev_alloc_common(spa, cvd->vdev_id, 0, ops);
748
749 mvd->vdev_asize = cvd->vdev_asize;
750 mvd->vdev_min_asize = cvd->vdev_min_asize;
751 mvd->vdev_max_asize = cvd->vdev_max_asize;
751 mvd->vdev_ashift = cvd->vdev_ashift;
752 mvd->vdev_state = cvd->vdev_state;
753 mvd->vdev_crtxg = cvd->vdev_crtxg;
754
755 vdev_remove_child(pvd, cvd);
756 vdev_add_child(pvd, mvd);
757 cvd->vdev_id = mvd->vdev_children;
758 vdev_add_child(mvd, cvd);

--- 355 unchanged lines hidden (view full) ---

1114 * Prepare a virtual device for access.
1115 */
1116int
1117vdev_open(vdev_t *vd)
1118{
1119 spa_t *spa = vd->vdev_spa;
1120 int error;
1121 uint64_t osize = 0;
752 mvd->vdev_ashift = cvd->vdev_ashift;
753 mvd->vdev_state = cvd->vdev_state;
754 mvd->vdev_crtxg = cvd->vdev_crtxg;
755
756 vdev_remove_child(pvd, cvd);
757 vdev_add_child(pvd, mvd);
758 cvd->vdev_id = mvd->vdev_children;
759 vdev_add_child(mvd, cvd);

--- 355 unchanged lines hidden (view full) ---

1115 * Prepare a virtual device for access.
1116 */
1117int
1118vdev_open(vdev_t *vd)
1119{
1120 spa_t *spa = vd->vdev_spa;
1121 int error;
1122 uint64_t osize = 0;
1122 uint64_t asize, psize;
1123 uint64_t max_osize = 0;
1124 uint64_t asize, max_asize, psize;
1123 uint64_t ashift = 0;
1124
1125 ASSERT(vd->vdev_open_thread == curthread ||
1126 spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
1127 ASSERT(vd->vdev_state == VDEV_STATE_CLOSED ||
1128 vd->vdev_state == VDEV_STATE_CANT_OPEN ||
1129 vd->vdev_state == VDEV_STATE_OFFLINE);
1130

--- 14 unchanged lines hidden (view full) ---

1145 vd->vdev_label_aux);
1146 return (ENXIO);
1147 } else if (vd->vdev_offline) {
1148 ASSERT(vd->vdev_children == 0);
1149 vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE, VDEV_AUX_NONE);
1150 return (ENXIO);
1151 }
1152
1125 uint64_t ashift = 0;
1126
1127 ASSERT(vd->vdev_open_thread == curthread ||
1128 spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
1129 ASSERT(vd->vdev_state == VDEV_STATE_CLOSED ||
1130 vd->vdev_state == VDEV_STATE_CANT_OPEN ||
1131 vd->vdev_state == VDEV_STATE_OFFLINE);
1132

--- 14 unchanged lines hidden (view full) ---

1147 vd->vdev_label_aux);
1148 return (ENXIO);
1149 } else if (vd->vdev_offline) {
1150 ASSERT(vd->vdev_children == 0);
1151 vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE, VDEV_AUX_NONE);
1152 return (ENXIO);
1153 }
1154
1153 error = vd->vdev_ops->vdev_op_open(vd, &osize, &ashift);
1155 error = vd->vdev_ops->vdev_op_open(vd, &osize, &max_osize, &ashift);
1154
1155 /*
1156 * Reset the vdev_reopening flag so that we actually close
1157 * the vdev on error.
1158 */
1159 vd->vdev_reopening = B_FALSE;
1160 if (zio_injection_enabled && error == 0)
1161 error = zio_handle_device_injection(vd, NULL, ENXIO);

--- 41 unchanged lines hidden (view full) ---

1203 if (vd->vdev_child[c]->vdev_state != VDEV_STATE_HEALTHY) {
1204 vdev_set_state(vd, B_TRUE, VDEV_STATE_DEGRADED,
1205 VDEV_AUX_NONE);
1206 break;
1207 }
1208 }
1209
1210 osize = P2ALIGN(osize, (uint64_t)sizeof (vdev_label_t));
1156
1157 /*
1158 * Reset the vdev_reopening flag so that we actually close
1159 * the vdev on error.
1160 */
1161 vd->vdev_reopening = B_FALSE;
1162 if (zio_injection_enabled && error == 0)
1163 error = zio_handle_device_injection(vd, NULL, ENXIO);

--- 41 unchanged lines hidden (view full) ---

1205 if (vd->vdev_child[c]->vdev_state != VDEV_STATE_HEALTHY) {
1206 vdev_set_state(vd, B_TRUE, VDEV_STATE_DEGRADED,
1207 VDEV_AUX_NONE);
1208 break;
1209 }
1210 }
1211
1212 osize = P2ALIGN(osize, (uint64_t)sizeof (vdev_label_t));
1213 max_osize = P2ALIGN(max_osize, (uint64_t)sizeof (vdev_label_t));
1211
1212 if (vd->vdev_children == 0) {
1213 if (osize < SPA_MINDEVSIZE) {
1214 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1215 VDEV_AUX_TOO_SMALL);
1216 return (EOVERFLOW);
1217 }
1218 psize = osize;
1219 asize = osize - (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE);
1214
1215 if (vd->vdev_children == 0) {
1216 if (osize < SPA_MINDEVSIZE) {
1217 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1218 VDEV_AUX_TOO_SMALL);
1219 return (EOVERFLOW);
1220 }
1221 psize = osize;
1222 asize = osize - (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE);
1223 max_asize = max_osize - (VDEV_LABEL_START_SIZE +
1224 VDEV_LABEL_END_SIZE);
1220 } else {
1221 if (vd->vdev_parent != NULL && osize < SPA_MINDEVSIZE -
1222 (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE)) {
1223 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1224 VDEV_AUX_TOO_SMALL);
1225 return (EOVERFLOW);
1226 }
1227 psize = 0;
1228 asize = osize;
1225 } else {
1226 if (vd->vdev_parent != NULL && osize < SPA_MINDEVSIZE -
1227 (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE)) {
1228 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1229 VDEV_AUX_TOO_SMALL);
1230 return (EOVERFLOW);
1231 }
1232 psize = 0;
1233 asize = osize;
1234 max_asize = max_osize;
1229 }
1230
1231 vd->vdev_psize = psize;
1232
1233 /*
1234 * Make sure the allocatable size hasn't shrunk.
1235 */
1236 if (asize < vd->vdev_min_asize) {
1237 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1238 VDEV_AUX_BAD_LABEL);
1239 return (EINVAL);
1240 }
1241
1242 if (vd->vdev_asize == 0) {
1243 /*
1244 * This is the first-ever open, so use the computed values.
1245 * For testing purposes, a higher ashift can be requested.
1246 */
1247 vd->vdev_asize = asize;
1235 }
1236
1237 vd->vdev_psize = psize;
1238
1239 /*
1240 * Make sure the allocatable size hasn't shrunk.
1241 */
1242 if (asize < vd->vdev_min_asize) {
1243 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1244 VDEV_AUX_BAD_LABEL);
1245 return (EINVAL);
1246 }
1247
1248 if (vd->vdev_asize == 0) {
1249 /*
1250 * This is the first-ever open, so use the computed values.
1251 * For testing purposes, a higher ashift can be requested.
1252 */
1253 vd->vdev_asize = asize;
1254 vd->vdev_max_asize = max_asize;
1248 vd->vdev_ashift = MAX(ashift, vd->vdev_ashift);
1249 } else {
1250 /*
1251 * Make sure the alignment requirement hasn't increased.
1252 */
1253 if (ashift > vd->vdev_top->vdev_ashift) {
1254 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1255 VDEV_AUX_BAD_LABEL);
1256 return (EINVAL);
1257 }
1255 vd->vdev_ashift = MAX(ashift, vd->vdev_ashift);
1256 } else {
1257 /*
1258 * Make sure the alignment requirement hasn't increased.
1259 */
1260 if (ashift > vd->vdev_top->vdev_ashift) {
1261 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1262 VDEV_AUX_BAD_LABEL);
1263 return (EINVAL);
1264 }
1265 vd->vdev_max_asize = max_asize;
1258 }
1259
1260 /*
1261 * If all children are healthy and the asize has increased,
1262 * then we've experienced dynamic LUN growth. If automatic
1263 * expansion is enabled then use the additional space.
1264 */
1265 if (vd->vdev_state == VDEV_STATE_HEALTHY && asize > vd->vdev_asize &&

--- 1207 unchanged lines hidden (view full) ---

2473
2474 mutex_enter(&vd->vdev_stat_lock);
2475 bcopy(&vd->vdev_stat, vs, sizeof (*vs));
2476 vs->vs_timestamp = gethrtime() - vs->vs_timestamp;
2477 vs->vs_state = vd->vdev_state;
2478 vs->vs_rsize = vdev_get_min_asize(vd);
2479 if (vd->vdev_ops->vdev_op_leaf)
2480 vs->vs_rsize += VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE;
1266 }
1267
1268 /*
1269 * If all children are healthy and the asize has increased,
1270 * then we've experienced dynamic LUN growth. If automatic
1271 * expansion is enabled then use the additional space.
1272 */
1273 if (vd->vdev_state == VDEV_STATE_HEALTHY && asize > vd->vdev_asize &&

--- 1207 unchanged lines hidden (view full) ---

2481
2482 mutex_enter(&vd->vdev_stat_lock);
2483 bcopy(&vd->vdev_stat, vs, sizeof (*vs));
2484 vs->vs_timestamp = gethrtime() - vs->vs_timestamp;
2485 vs->vs_state = vd->vdev_state;
2486 vs->vs_rsize = vdev_get_min_asize(vd);
2487 if (vd->vdev_ops->vdev_op_leaf)
2488 vs->vs_rsize += VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE;
2489 vs->vs_esize = vd->vdev_max_asize - vd->vdev_asize;
2481 mutex_exit(&vd->vdev_stat_lock);
2482
2483 /*
2484 * If we're getting stats on the root vdev, aggregate the I/O counts
2485 * over all top-level vdevs (i.e. the direct children of the root).
2486 */
2487 if (vd == rvd) {
2488 for (int c = 0; c < rvd->vdev_children; c++) {

--- 673 unchanged lines hidden ---
2490 mutex_exit(&vd->vdev_stat_lock);
2491
2492 /*
2493 * If we're getting stats on the root vdev, aggregate the I/O counts
2494 * over all top-level vdevs (i.e. the direct children of the root).
2495 */
2496 if (vd == rvd) {
2497 for (int c = 0; c < rvd->vdev_children; c++) {

--- 673 unchanged lines hidden ---