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