1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
50a4e9518Sgw  * Common Development and Distribution License (the "License").
60a4e9518Sgw  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22dcba9f3fSGeorge Wilson  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
264263d13fSGeorge Wilson /*
27094e47e9SGeorge Wilson  * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
28*ac04831dSMike Gerdts  * Copyright 2019 Joyent, Inc.
294263d13fSGeorge Wilson  */
304263d13fSGeorge Wilson 
31fa9e4066Sahrens /*
32fa9e4066Sahrens  * The 'missing' vdev is a special vdev type used only during import.  It
33fa9e4066Sahrens  * signifies a placeholder in the root vdev for some vdev that we know is
34fa9e4066Sahrens  * missing.  We pass it down to the kernel to allow the rest of the
35fa9e4066Sahrens  * configuration to parsed and an attempt made to open all available devices.
36fa9e4066Sahrens  * Because its GUID is always 0, we know that the guid sum will mismatch and we
37fa9e4066Sahrens  * won't be able to open the pool anyway.
38fa9e4066Sahrens  */
39fa9e4066Sahrens 
40fa9e4066Sahrens #include <sys/zfs_context.h>
41fa9e4066Sahrens #include <sys/spa.h>
42fa9e4066Sahrens #include <sys/vdev_impl.h>
43fa9e4066Sahrens #include <sys/fs/zfs.h>
44fa9e4066Sahrens #include <sys/zio.h>
45fa9e4066Sahrens 
46fa9e4066Sahrens /* ARGSUSED */
47fa9e4066Sahrens static int
vdev_missing_open(vdev_t * vd,uint64_t * psize,uint64_t * max_psize,uint64_t * ashift)484263d13fSGeorge Wilson vdev_missing_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
494263d13fSGeorge Wilson     uint64_t *ashift)
50fa9e4066Sahrens {
51fa9e4066Sahrens 	/*
52fa9e4066Sahrens 	 * Really this should just fail.  But then the root vdev will be in the
53fa9e4066Sahrens 	 * faulted state with VDEV_AUX_NO_REPLICAS, when what we really want is
54fa9e4066Sahrens 	 * VDEV_AUX_BAD_GUID_SUM.  So we pretend to succeed, knowing that we
55fa9e4066Sahrens 	 * will fail the GUID sum check before ever trying to open the pool.
56fa9e4066Sahrens 	 */
5788ecc943SGeorge Wilson 	*psize = 0;
584263d13fSGeorge Wilson 	*max_psize = 0;
5988ecc943SGeorge Wilson 	*ashift = 0;
60fa9e4066Sahrens 	return (0);
61fa9e4066Sahrens }
62fa9e4066Sahrens 
63fa9e4066Sahrens /* ARGSUSED */
64fa9e4066Sahrens static void
vdev_missing_close(vdev_t * vd)65fa9e4066Sahrens vdev_missing_close(vdev_t *vd)
66fa9e4066Sahrens {
67fa9e4066Sahrens }
68fa9e4066Sahrens 
69fa9e4066Sahrens /* ARGSUSED */
70738f37bcSGeorge Wilson static void
vdev_missing_io_start(zio_t * zio)71fa9e4066Sahrens vdev_missing_io_start(zio_t *zio)
72fa9e4066Sahrens {
73be6fd75aSMatthew Ahrens 	zio->io_error = SET_ERROR(ENOTSUP);
74738f37bcSGeorge Wilson 	zio_execute(zio);
75fa9e4066Sahrens }
76fa9e4066Sahrens 
77fa9e4066Sahrens /* ARGSUSED */
78e14bb325SJeff Bonwick static void
vdev_missing_io_done(zio_t * zio)79fa9e4066Sahrens vdev_missing_io_done(zio_t *zio)
80fa9e4066Sahrens {
810a4e9518Sgw }
820a4e9518Sgw 
83fa9e4066Sahrens vdev_ops_t vdev_missing_ops = {
84a3874b8bSToomas Soome 	.vdev_op_open = vdev_missing_open,
85a3874b8bSToomas Soome 	.vdev_op_close = vdev_missing_close,
86a3874b8bSToomas Soome 	.vdev_op_asize = vdev_default_asize,
87a3874b8bSToomas Soome 	.vdev_op_io_start = vdev_missing_io_start,
88a3874b8bSToomas Soome 	.vdev_op_io_done = vdev_missing_io_done,
89a3874b8bSToomas Soome 	.vdev_op_state_change = NULL,
90a3874b8bSToomas Soome 	.vdev_op_need_resilver = NULL,
91a3874b8bSToomas Soome 	.vdev_op_hold = NULL,
92a3874b8bSToomas Soome 	.vdev_op_rele = NULL,
93a3874b8bSToomas Soome 	.vdev_op_remap = NULL,
94a3874b8bSToomas Soome 	.vdev_op_xlate = NULL,
95*ac04831dSMike Gerdts 	.vdev_op_dumpio = NULL,
96a3874b8bSToomas Soome 	.vdev_op_type = VDEV_TYPE_MISSING,	/* name of this vdev type */
97a3874b8bSToomas Soome 	.vdev_op_leaf = B_TRUE			/* leaf vdev */
98fa9e4066Sahrens };
9988ecc943SGeorge Wilson 
10088ecc943SGeorge Wilson vdev_ops_t vdev_hole_ops = {
101a3874b8bSToomas Soome 	.vdev_op_open = vdev_missing_open,
102a3874b8bSToomas Soome 	.vdev_op_close = vdev_missing_close,
103a3874b8bSToomas Soome 	.vdev_op_asize = vdev_default_asize,
104a3874b8bSToomas Soome 	.vdev_op_io_start = vdev_missing_io_start,
105a3874b8bSToomas Soome 	.vdev_op_io_done = vdev_missing_io_done,
106a3874b8bSToomas Soome 	.vdev_op_state_change = NULL,
107a3874b8bSToomas Soome 	.vdev_op_need_resilver = NULL,
108a3874b8bSToomas Soome 	.vdev_op_hold = NULL,
109a3874b8bSToomas Soome 	.vdev_op_rele = NULL,
110a3874b8bSToomas Soome 	.vdev_op_remap = NULL,
111a3874b8bSToomas Soome 	.vdev_op_xlate = NULL,
112*ac04831dSMike Gerdts 	.vdev_op_dumpio = NULL,
113a3874b8bSToomas Soome 	.vdev_op_type = VDEV_TYPE_HOLE,		/* name of this vdev type */
114a3874b8bSToomas Soome 	.vdev_op_leaf = B_TRUE			/* leaf vdev */
11588ecc943SGeorge Wilson };
116