]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cmd/zpool/os/freebsd/zpool_vdev_os.c
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / cmd / zpool / os / freebsd / zpool_vdev_os.c
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 http://www.opensolaris.org/os/licensing.
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         char path[MAXPATHLEN];
90
91         if (strncmp(name, _PATH_DEV, sizeof (_PATH_DEV) - 1) != 0)
92                 snprintf(path, sizeof (path), "%s%s", _PATH_DEV, name);
93         else
94                 strlcpy(path, name, sizeof (path));
95
96         return (check_file(path, force, isspare));
97 }
98
99 boolean_t
100 check_sector_size_database(char *path, int *sector_size)
101 {
102         return (0);
103 }