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
9  * or https://opensource.org/licenses/CDDL-1.0.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
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 (c) 2013, 2018 by Delphix. All rights reserved.
25  * Copyright (c) 2016, 2017 Intel Corporation.
26  * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
27  */
28 
29 /*
30  * Functions to convert between a list of vdevs and an nvlist representing the
31  * configuration.  Each entry in the list can be one of:
32  *
33  * 	Device vdevs
34  * 		disk=(path=..., devid=...)
35  * 		file=(path=...)
36  *
37  * 	Group vdevs
38  * 		raidz[1|2]=(...)
39  * 		mirror=(...)
40  *
41  * 	Hot spares
42  *
43  * While the underlying implementation supports it, group vdevs cannot contain
44  * other group vdevs.  All userland verification of devices is contained within
45  * this file.  If successful, the nvlist returned can be passed directly to the
46  * kernel; we've done as much verification as possible in userland.
47  *
48  * Hot spares are a special case, and passed down as an array of disk vdevs, at
49  * the same level as the root of the vdev tree.
50  *
51  * The only function exported by this file is 'make_root_vdev'.  The
52  * function performs several passes:
53  *
54  * 	1. Construct the vdev specification.  Performs syntax validation and
55  *         makes sure each device is valid.
56  * 	2. Check for devices in use.  Using libdiskmgt, makes sure that no
57  *         devices are also in use.  Some can be overridden using the 'force'
58  *         flag, others cannot.
59  * 	3. Check for replication errors if the 'force' flag is not specified.
60  *         validates that the replication level is consistent across the
61  *         entire pool.
62  * 	4. Call libzfs to label any whole disks with an EFI label.
63  */
64 
65 #include <assert.h>
66 #include <errno.h>
67 #include <fcntl.h>
68 #include <libintl.h>
69 #include <libnvpair.h>
70 #include <libzutil.h>
71 #include <limits.h>
72 #include <sys/spa.h>
73 #include <stdio.h>
74 #include <string.h>
75 #include <unistd.h>
76 #include <paths.h>
77 #include <sys/stat.h>
78 #include <sys/disk.h>
79 #include <sys/mntent.h>
80 #include <libgeom.h>
81 
82 #include "zpool_util.h"
83 #include <sys/zfs_context.h>
84 
85 int
86 check_device(const char *name, boolean_t force, boolean_t isspare,
87     boolean_t iswholedisk)
88 {
89 	(void) iswholedisk;
90 	char path[MAXPATHLEN];
91 
92 	if (strncmp(name, _PATH_DEV, sizeof (_PATH_DEV) - 1) != 0)
93 		snprintf(path, sizeof (path), "%s%s", _PATH_DEV, name);
94 	else
95 		strlcpy(path, name, sizeof (path));
96 
97 	return (check_file(path, force, isspare));
98 }
99 
100 boolean_t
101 check_sector_size_database(char *path, int *sector_size)
102 {
103 	(void) path, (void) sector_size;
104 	return (0);
105 }
106 
107 void
108 after_zpool_upgrade(zpool_handle_t *zhp)
109 {
110 	char bootfs[ZPOOL_MAXPROPLEN];
111 
112 	if (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs,
113 	    sizeof (bootfs), NULL, B_FALSE) == 0 &&
114 	    strcmp(bootfs, "-") != 0) {
115 		(void) printf(gettext("Pool '%s' has the bootfs "
116 		    "property set, you might need to update\nthe boot "
117 		    "code. See gptzfsboot(8) and loader.efi(8) for "
118 		    "details.\n"), zpool_get_name(zhp));
119 	}
120 }
121 
122 int
123 check_file(const char *file, boolean_t force, boolean_t isspare)
124 {
125 	return (check_file_generic(file, force, isspare));
126 }
127