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 --- 145 unchanged lines hidden (view full) --- 154 } 155 geom_deletetree(&mesh); 156 return (rv); 157} 158 159static boolean_t 160is_provider(const char *name) 161{ |
162 int fd; 163 |
164 fd = g_open(name, 0); 165 if (fd >= 0) { 166 g_close(fd); 167 return (B_TRUE); |
168 } |
169 return (B_FALSE); |
170 171} 172/* 173 * Create a leaf vdev. Determine if this is a GEOM provider. 174 * Valid forms for a leaf vdev are: 175 * 176 * /dev/xxx Complete path to a GEOM provider 177 * xxx Shorthand for /dev/xxx 178 */ 179nvlist_t * 180make_leaf_vdev(const char *arg) 181{ |
182 char ident[DISK_IDENT_SIZE], path[MAXPATHLEN]; 183 struct stat64 statbuf; |
184 nvlist_t *vdev = NULL; 185 char *type = NULL; |
186 boolean_t wholedisk = B_FALSE; |
187 188 if (strncmp(arg, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) 189 strlcpy(path, arg, sizeof (path)); 190 else 191 snprintf(path, sizeof (path), "%s%s", _PATH_DEV, arg); 192 193 if (is_provider(path)) 194 type = VDEV_TYPE_DISK; --- 10 unchanged lines hidden (view full) --- 205 */ 206 verify(nvlist_alloc(&vdev, NV_UNIQUE_NAME, 0) == 0); 207 verify(nvlist_add_string(vdev, ZPOOL_CONFIG_PATH, path) == 0); 208 verify(nvlist_add_string(vdev, ZPOOL_CONFIG_TYPE, type) == 0); 209 if (strcmp(type, VDEV_TYPE_DISK) == 0) 210 verify(nvlist_add_uint64(vdev, ZPOOL_CONFIG_WHOLE_DISK, 211 (uint64_t)B_FALSE) == 0); 212 |
213 /* 214 * For a whole disk, defer getting its devid until after labeling it. 215 */ 216 if (1 || (S_ISBLK(statbuf.st_mode) && !wholedisk)) { 217 /* 218 * Get the devid for the device. 219 */ 220 int fd; 221 ddi_devid_t devid; 222 char *minor = NULL, *devid_str = NULL; 223 224 if ((fd = open(path, O_RDONLY)) < 0) { 225 (void) fprintf(stderr, gettext("cannot open '%s': " 226 "%s\n"), path, strerror(errno)); 227 nvlist_free(vdev); 228 return (NULL); 229 } 230 231 if (devid_get(fd, &devid) == 0) { 232 if (devid_get_minor_name(fd, &minor) == 0 && 233 (devid_str = devid_str_encode(devid, minor)) != 234 NULL) { 235 verify(nvlist_add_string(vdev, 236 ZPOOL_CONFIG_DEVID, devid_str) == 0); 237 } 238 if (devid_str != NULL) 239 devid_str_free(devid_str); 240 if (minor != NULL) 241 devid_str_free(minor); 242 devid_free(devid); 243 } 244 245 (void) close(fd); 246 } 247 |
248 return (vdev); 249} 250 251/* 252 * Go through and verify the replication level of the pool is consistent. 253 * Performs the following checks: 254 * 255 * For the new spec, verifies that devices in mirrors and raidz are the --- 628 unchanged lines hidden --- |