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