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 /*
23eda14cbcSMatt Macy * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24eda14cbcSMatt Macy * Copyright (c) 2013, 2018 by Delphix. All rights reserved.
25eda14cbcSMatt Macy * Copyright (c) 2016, 2017 Intel Corporation.
26eda14cbcSMatt Macy * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
27eda14cbcSMatt Macy */
28eda14cbcSMatt Macy
29eda14cbcSMatt Macy /*
30eda14cbcSMatt Macy * Functions to convert between a list of vdevs and an nvlist representing the
31eda14cbcSMatt Macy * configuration. Each entry in the list can be one of:
32eda14cbcSMatt Macy *
33eda14cbcSMatt Macy * Device vdevs
34eda14cbcSMatt Macy * disk=(path=..., devid=...)
35eda14cbcSMatt Macy * file=(path=...)
36eda14cbcSMatt Macy *
37eda14cbcSMatt Macy * Group vdevs
38eda14cbcSMatt Macy * raidz[1|2]=(...)
39eda14cbcSMatt Macy * mirror=(...)
40eda14cbcSMatt Macy *
41eda14cbcSMatt Macy * Hot spares
42eda14cbcSMatt Macy *
43eda14cbcSMatt Macy * While the underlying implementation supports it, group vdevs cannot contain
44eda14cbcSMatt Macy * other group vdevs. All userland verification of devices is contained within
45eda14cbcSMatt Macy * this file. If successful, the nvlist returned can be passed directly to the
46eda14cbcSMatt Macy * kernel; we've done as much verification as possible in userland.
47eda14cbcSMatt Macy *
48eda14cbcSMatt Macy * Hot spares are a special case, and passed down as an array of disk vdevs, at
49eda14cbcSMatt Macy * the same level as the root of the vdev tree.
50eda14cbcSMatt Macy *
51eda14cbcSMatt Macy * The only function exported by this file is 'make_root_vdev'. The
52eda14cbcSMatt Macy * function performs several passes:
53eda14cbcSMatt Macy *
54eda14cbcSMatt Macy * 1. Construct the vdev specification. Performs syntax validation and
55eda14cbcSMatt Macy * makes sure each device is valid.
56eda14cbcSMatt Macy * 2. Check for devices in use. Using libdiskmgt, makes sure that no
57eda14cbcSMatt Macy * devices are also in use. Some can be overridden using the 'force'
58eda14cbcSMatt Macy * flag, others cannot.
59eda14cbcSMatt Macy * 3. Check for replication errors if the 'force' flag is not specified.
60eda14cbcSMatt Macy * validates that the replication level is consistent across the
61eda14cbcSMatt Macy * entire pool.
62eda14cbcSMatt Macy * 4. Call libzfs to label any whole disks with an EFI label.
63eda14cbcSMatt Macy */
64eda14cbcSMatt Macy
65eda14cbcSMatt Macy #include <assert.h>
66eda14cbcSMatt Macy #include <errno.h>
67eda14cbcSMatt Macy #include <fcntl.h>
68eda14cbcSMatt Macy #include <libintl.h>
69eda14cbcSMatt Macy #include <libnvpair.h>
70eda14cbcSMatt Macy #include <libzutil.h>
71eda14cbcSMatt Macy #include <limits.h>
72eda14cbcSMatt Macy #include <sys/spa.h>
73eda14cbcSMatt Macy #include <stdio.h>
74eda14cbcSMatt Macy #include <string.h>
75eda14cbcSMatt Macy #include <unistd.h>
76eda14cbcSMatt Macy #include <paths.h>
77eda14cbcSMatt Macy #include <sys/stat.h>
78eda14cbcSMatt Macy #include <sys/disk.h>
79eda14cbcSMatt Macy #include <sys/mntent.h>
80eda14cbcSMatt Macy #include <libgeom.h>
81eda14cbcSMatt Macy
82eda14cbcSMatt Macy #include "zpool_util.h"
83eda14cbcSMatt Macy #include <sys/zfs_context.h>
84eda14cbcSMatt Macy
85eda14cbcSMatt Macy int
check_device(const char * name,boolean_t force,boolean_t isspare,boolean_t iswholedisk)86eda14cbcSMatt Macy check_device(const char *name, boolean_t force, boolean_t isspare,
87eda14cbcSMatt Macy boolean_t iswholedisk)
88eda14cbcSMatt Macy {
89e92ffd9bSMartin Matuska (void) iswholedisk;
90eda14cbcSMatt Macy char path[MAXPATHLEN];
91eda14cbcSMatt Macy
92eda14cbcSMatt Macy if (strncmp(name, _PATH_DEV, sizeof (_PATH_DEV) - 1) != 0)
93eda14cbcSMatt Macy snprintf(path, sizeof (path), "%s%s", _PATH_DEV, name);
94eda14cbcSMatt Macy else
95eda14cbcSMatt Macy strlcpy(path, name, sizeof (path));
96eda14cbcSMatt Macy
97eda14cbcSMatt Macy return (check_file(path, force, isspare));
98eda14cbcSMatt Macy }
99eda14cbcSMatt Macy
100eda14cbcSMatt Macy boolean_t
check_sector_size_database(char * path,int * sector_size)101eda14cbcSMatt Macy check_sector_size_database(char *path, int *sector_size)
102eda14cbcSMatt Macy {
103e92ffd9bSMartin Matuska (void) path, (void) sector_size;
104eda14cbcSMatt Macy return (0);
105eda14cbcSMatt Macy }
10616038816SMartin Matuska
10716038816SMartin Matuska void
after_zpool_upgrade(zpool_handle_t * zhp)10816038816SMartin Matuska after_zpool_upgrade(zpool_handle_t *zhp)
10916038816SMartin Matuska {
11016038816SMartin Matuska char bootfs[ZPOOL_MAXPROPLEN];
11116038816SMartin Matuska
11216038816SMartin Matuska if (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs,
11316038816SMartin Matuska sizeof (bootfs), NULL, B_FALSE) == 0 &&
11416038816SMartin Matuska strcmp(bootfs, "-") != 0) {
11516038816SMartin Matuska (void) printf(gettext("Pool '%s' has the bootfs "
11616038816SMartin Matuska "property set, you might need to update\nthe boot "
11716038816SMartin Matuska "code. See gptzfsboot(8) and loader.efi(8) for "
11816038816SMartin Matuska "details.\n"), zpool_get_name(zhp));
11916038816SMartin Matuska }
12016038816SMartin Matuska }
1211f88aa09SMartin Matuska
1221f88aa09SMartin Matuska int
check_file(const char * file,boolean_t force,boolean_t isspare)1231f88aa09SMartin Matuska check_file(const char *file, boolean_t force, boolean_t isspare)
1241f88aa09SMartin Matuska {
1251f88aa09SMartin Matuska return (check_file_generic(file, force, isspare));
1261f88aa09SMartin Matuska }
127*b356da80SMartin Matuska
128*b356da80SMartin Matuska int
zpool_power_current_state(zpool_handle_t * zhp,char * vdev)129*b356da80SMartin Matuska zpool_power_current_state(zpool_handle_t *zhp, char *vdev)
130*b356da80SMartin Matuska {
131*b356da80SMartin Matuska
132*b356da80SMartin Matuska (void) zhp;
133*b356da80SMartin Matuska (void) vdev;
134*b356da80SMartin Matuska /* Enclosure slot power not supported on FreeBSD yet */
135*b356da80SMartin Matuska return (-1);
136*b356da80SMartin Matuska }
137*b356da80SMartin Matuska
138*b356da80SMartin Matuska int
zpool_power(zpool_handle_t * zhp,char * vdev,boolean_t turn_on)139*b356da80SMartin Matuska zpool_power(zpool_handle_t *zhp, char *vdev, boolean_t turn_on)
140*b356da80SMartin Matuska {
141*b356da80SMartin Matuska
142*b356da80SMartin Matuska (void) zhp;
143*b356da80SMartin Matuska (void) vdev;
144*b356da80SMartin Matuska (void) turn_on;
145*b356da80SMartin Matuska /* Enclosure slot power not supported on FreeBSD yet */
146*b356da80SMartin Matuska return (ENOTSUP);
147*b356da80SMartin Matuska }
148