libzfs_import.c (332550) | libzfs_import.c (339130) |
---|---|
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 --- 19 unchanged lines hidden (view full) --- 28 29/* 30 * Pool import support functions. 31 * 32 * To import a pool, we rely on reading the configuration information from the 33 * ZFS label of each device. If we successfully read the label, then we 34 * organize the configuration information in the following hierarchy: 35 * | 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 --- 19 unchanged lines hidden (view full) --- 28 29/* 30 * Pool import support functions. 31 * 32 * To import a pool, we rely on reading the configuration information from the 33 * ZFS label of each device. If we successfully read the label, then we 34 * organize the configuration information in the following hierarchy: 35 * |
36 * pool guid -> toplevel vdev guid -> label txg | 36 * pool guid -> toplevel vdev guid -> label txg |
37 * 38 * Duplicate entries matching this same tuple will be discarded. Once we have 39 * examined every device, we pick the best label txg config for each toplevel 40 * vdev. We then arrange these toplevel vdevs into a complete pool config, and 41 * update any paths that have changed. Finally, we attempt to import the pool 42 * using our derived config, and record the results. 43 */ 44 --- 195 unchanged lines hidden (view full) --- 240 free(ne); 241 return (-1); 242 } 243 244 ne->ne_guid = vdev_guid; 245 ne->ne_next = pl->names; 246 pl->names = ne; 247 | 37 * 38 * Duplicate entries matching this same tuple will be discarded. Once we have 39 * examined every device, we pick the best label txg config for each toplevel 40 * vdev. We then arrange these toplevel vdevs into a complete pool config, and 41 * update any paths that have changed. Finally, we attempt to import the pool 42 * using our derived config, and record the results. 43 */ 44 --- 195 unchanged lines hidden (view full) --- 240 free(ne); 241 return (-1); 242 } 243 244 ne->ne_guid = vdev_guid; 245 ne->ne_next = pl->names; 246 pl->names = ne; 247 |
248 nvlist_free(config); | |
249 return (0); 250 } 251 252 /* 253 * If we have a valid config but cannot read any of these fields, then 254 * it means we have a half-initialized label. In vdev_label_init() 255 * we write a label with txg == 0 so that we can identify the device 256 * in case the user refers to the same disk later on. If we fail to 257 * create the pool, we'll be left with a label in this state 258 * which should not be considered part of a valid pool. 259 */ 260 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, 261 &pool_guid) != 0 || 262 nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID, 263 &vdev_guid) != 0 || 264 nvlist_lookup_uint64(config, ZPOOL_CONFIG_TOP_GUID, 265 &top_guid) != 0 || 266 nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, 267 &txg) != 0 || txg == 0) { | 248 return (0); 249 } 250 251 /* 252 * If we have a valid config but cannot read any of these fields, then 253 * it means we have a half-initialized label. In vdev_label_init() 254 * we write a label with txg == 0 so that we can identify the device 255 * in case the user refers to the same disk later on. If we fail to 256 * create the pool, we'll be left with a label in this state 257 * which should not be considered part of a valid pool. 258 */ 259 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, 260 &pool_guid) != 0 || 261 nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID, 262 &vdev_guid) != 0 || 263 nvlist_lookup_uint64(config, ZPOOL_CONFIG_TOP_GUID, 264 &top_guid) != 0 || 265 nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, 266 &txg) != 0 || txg == 0) { |
268 nvlist_free(config); | |
269 return (0); 270 } 271 272 /* 273 * First, see if we know about this pool. If not, then add it to the 274 * list of known pools. 275 */ 276 for (pe = pl->pools; pe != NULL; pe = pe->pe_next) { 277 if (pe->pe_guid == pool_guid) 278 break; 279 } 280 281 if (pe == NULL) { 282 if ((pe = zfs_alloc(hdl, sizeof (pool_entry_t))) == NULL) { | 267 return (0); 268 } 269 270 /* 271 * First, see if we know about this pool. If not, then add it to the 272 * list of known pools. 273 */ 274 for (pe = pl->pools; pe != NULL; pe = pe->pe_next) { 275 if (pe->pe_guid == pool_guid) 276 break; 277 } 278 279 if (pe == NULL) { 280 if ((pe = zfs_alloc(hdl, sizeof (pool_entry_t))) == NULL) { |
283 nvlist_free(config); | |
284 return (-1); 285 } 286 pe->pe_guid = pool_guid; 287 pe->pe_next = pl->pools; 288 pl->pools = pe; 289 } 290 291 /* 292 * Second, see if we know about this toplevel vdev. Add it if its 293 * missing. 294 */ 295 for (ve = pe->pe_vdevs; ve != NULL; ve = ve->ve_next) { 296 if (ve->ve_guid == top_guid) 297 break; 298 } 299 300 if (ve == NULL) { 301 if ((ve = zfs_alloc(hdl, sizeof (vdev_entry_t))) == NULL) { | 281 return (-1); 282 } 283 pe->pe_guid = pool_guid; 284 pe->pe_next = pl->pools; 285 pl->pools = pe; 286 } 287 288 /* 289 * Second, see if we know about this toplevel vdev. Add it if its 290 * missing. 291 */ 292 for (ve = pe->pe_vdevs; ve != NULL; ve = ve->ve_next) { 293 if (ve->ve_guid == top_guid) 294 break; 295 } 296 297 if (ve == NULL) { 298 if ((ve = zfs_alloc(hdl, sizeof (vdev_entry_t))) == NULL) { |
302 nvlist_free(config); | |
303 return (-1); 304 } 305 ve->ve_guid = top_guid; 306 ve->ve_next = pe->pe_vdevs; 307 pe->pe_vdevs = ve; 308 } 309 310 /* 311 * Third, see if we have a config with a matching transaction group. If 312 * so, then we do nothing. Otherwise, add it to the list of known 313 * configs. 314 */ 315 for (ce = ve->ve_configs; ce != NULL; ce = ce->ce_next) { 316 if (ce->ce_txg == txg) 317 break; 318 } 319 320 if (ce == NULL) { 321 if ((ce = zfs_alloc(hdl, sizeof (config_entry_t))) == NULL) { | 299 return (-1); 300 } 301 ve->ve_guid = top_guid; 302 ve->ve_next = pe->pe_vdevs; 303 pe->pe_vdevs = ve; 304 } 305 306 /* 307 * Third, see if we have a config with a matching transaction group. If 308 * so, then we do nothing. Otherwise, add it to the list of known 309 * configs. 310 */ 311 for (ce = ve->ve_configs; ce != NULL; ce = ce->ce_next) { 312 if (ce->ce_txg == txg) 313 break; 314 } 315 316 if (ce == NULL) { 317 if ((ce = zfs_alloc(hdl, sizeof (config_entry_t))) == NULL) { |
322 nvlist_free(config); | |
323 return (-1); 324 } 325 ce->ce_txg = txg; | 318 return (-1); 319 } 320 ce->ce_txg = txg; |
326 ce->ce_config = config; | 321 ce->ce_config = fnvlist_dup(config); |
327 ce->ce_next = ve->ve_configs; 328 ve->ve_configs = ce; | 322 ce->ce_next = ve->ve_configs; 323 ve->ve_configs = ce; |
329 } else { 330 nvlist_free(config); | |
331 } 332 333 /* 334 * At this point we've successfully added our config to the list of 335 * known configs. The last thing to do is add the vdev guid -> path 336 * mappings so that we can fix up the configuration as necessary before 337 * doing the import. 338 */ --- 1052 unchanged lines hidden (view full) --- 1391 } else if (iarg->guid != 0) { 1392 uint64_t this_guid; 1393 1394 matched = nvlist_lookup_uint64(config, 1395 ZPOOL_CONFIG_POOL_GUID, 1396 &this_guid) == 0 && 1397 iarg->guid == this_guid; 1398 } | 324 } 325 326 /* 327 * At this point we've successfully added our config to the list of 328 * known configs. The last thing to do is add the vdev guid -> path 329 * mappings so that we can fix up the configuration as necessary before 330 * doing the import. 331 */ --- 1052 unchanged lines hidden (view full) --- 1384 } else if (iarg->guid != 0) { 1385 uint64_t this_guid; 1386 1387 matched = nvlist_lookup_uint64(config, 1388 ZPOOL_CONFIG_POOL_GUID, 1389 &this_guid) == 0 && 1390 iarg->guid == this_guid; 1391 } |
1399 if (!matched) { 1400 nvlist_free(config); 1401 } else { | 1392 if (matched) { |
1402 /* 1403 * use the non-raw path for the config 1404 */ 1405 (void) strlcpy(end, slice->rn_name, 1406 pathleft); 1407 if (add_config(hdl, &pools, path, 1408 config) != 0) 1409 config_failed = B_TRUE; 1410 } | 1393 /* 1394 * use the non-raw path for the config 1395 */ 1396 (void) strlcpy(end, slice->rn_name, 1397 pathleft); 1398 if (add_config(hdl, &pools, path, 1399 config) != 0) 1400 config_failed = B_TRUE; 1401 } |
1402 nvlist_free(config); |
|
1411 } 1412 free(slice->rn_name); 1413 free(slice); 1414 } 1415 avl_destroy(&slice_cache); 1416 1417 (void) closedir(dirp); 1418 --- 436 unchanged lines hidden --- | 1403 } 1404 free(slice->rn_name); 1405 free(slice); 1406 } 1407 avl_destroy(&slice_cache); 1408 1409 (void) closedir(dirp); 1410 --- 436 unchanged lines hidden --- |