xref: /freebsd/sys/contrib/openzfs/module/zfs/vdev_missing.c (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
29  */
30 
31 /*
32  * The 'missing' vdev is a special vdev type used only during import.  It
33  * signifies a placeholder in the root vdev for some vdev that we know is
34  * missing.  We pass it down to the kernel to allow the rest of the
35  * configuration to parsed and an attempt made to open all available devices.
36  * Because its GUID is always 0, we know that the guid sum will mismatch and we
37  * won't be able to open the pool anyway.
38  */
39 
40 #include <sys/zfs_context.h>
41 #include <sys/spa.h>
42 #include <sys/vdev_impl.h>
43 #include <sys/fs/zfs.h>
44 #include <sys/zio.h>
45 
46 static int
vdev_missing_open(vdev_t * vd,uint64_t * psize,uint64_t * max_psize,uint64_t * ashift,uint64_t * pshift)47 vdev_missing_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
48     uint64_t *ashift, uint64_t *pshift)
49 {
50 	/*
51 	 * Really this should just fail.  But then the root vdev will be in the
52 	 * faulted state with VDEV_AUX_NO_REPLICAS, when what we really want is
53 	 * VDEV_AUX_BAD_GUID_SUM.  So we pretend to succeed, knowing that we
54 	 * will fail the GUID sum check before ever trying to open the pool.
55 	 */
56 	(void) vd;
57 	*psize = 0;
58 	*max_psize = 0;
59 	*ashift = 0;
60 	*pshift = 0;
61 	return (0);
62 }
63 
64 static void
vdev_missing_close(vdev_t * vd)65 vdev_missing_close(vdev_t *vd)
66 {
67 	(void) vd;
68 }
69 
70 static void
vdev_missing_io_start(zio_t * zio)71 vdev_missing_io_start(zio_t *zio)
72 {
73 	zio->io_error = SET_ERROR(ENOTSUP);
74 	zio_execute(zio);
75 }
76 
77 static void
vdev_missing_io_done(zio_t * zio)78 vdev_missing_io_done(zio_t *zio)
79 {
80 	(void) zio;
81 }
82 
83 vdev_ops_t vdev_missing_ops = {
84 	.vdev_op_init = NULL,
85 	.vdev_op_fini = NULL,
86 	.vdev_op_open = vdev_missing_open,
87 	.vdev_op_close = vdev_missing_close,
88 	.vdev_op_asize = vdev_default_asize,
89 	.vdev_op_min_asize = vdev_default_min_asize,
90 	.vdev_op_min_alloc = NULL,
91 	.vdev_op_io_start = vdev_missing_io_start,
92 	.vdev_op_io_done = vdev_missing_io_done,
93 	.vdev_op_state_change = NULL,
94 	.vdev_op_need_resilver = NULL,
95 	.vdev_op_hold = NULL,
96 	.vdev_op_rele = NULL,
97 	.vdev_op_remap = NULL,
98 	.vdev_op_xlate = NULL,
99 	.vdev_op_rebuild_asize = NULL,
100 	.vdev_op_metaslab_init = NULL,
101 	.vdev_op_config_generate = NULL,
102 	.vdev_op_nparity = NULL,
103 	.vdev_op_ndisks = NULL,
104 	.vdev_op_type = VDEV_TYPE_MISSING,	/* name of this vdev type */
105 	.vdev_op_leaf = B_TRUE			/* leaf vdev */
106 };
107 
108 vdev_ops_t vdev_hole_ops = {
109 	.vdev_op_init = NULL,
110 	.vdev_op_fini = NULL,
111 	.vdev_op_open = vdev_missing_open,
112 	.vdev_op_close = vdev_missing_close,
113 	.vdev_op_asize = vdev_default_asize,
114 	.vdev_op_min_asize = vdev_default_min_asize,
115 	.vdev_op_min_alloc = NULL,
116 	.vdev_op_io_start = vdev_missing_io_start,
117 	.vdev_op_io_done = vdev_missing_io_done,
118 	.vdev_op_state_change = NULL,
119 	.vdev_op_need_resilver = NULL,
120 	.vdev_op_hold = NULL,
121 	.vdev_op_rele = NULL,
122 	.vdev_op_remap = NULL,
123 	.vdev_op_xlate = NULL,
124 	.vdev_op_rebuild_asize = NULL,
125 	.vdev_op_metaslab_init = NULL,
126 	.vdev_op_config_generate = NULL,
127 	.vdev_op_nparity = NULL,
128 	.vdev_op_ndisks = NULL,
129 	.vdev_op_type = VDEV_TYPE_HOLE,		/* name of this vdev type */
130 	.vdev_op_leaf = B_TRUE			/* leaf vdev */
131 };
132