1/*- 2 * Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
215}; 216#define sc_name sc_geom->name 217 218u_int g_mirror_ndisks(struct g_mirror_softc *sc, int state); 219#define G_MIRROR_DESTROY_SOFT 0 220#define G_MIRROR_DESTROY_DELAYED 1 221#define G_MIRROR_DESTROY_HARD 2 222int g_mirror_destroy(struct g_mirror_softc *sc, int how); 223int g_mirror_event_send(void *arg, int state, int flags); 224struct g_mirror_metadata; 225int g_mirror_add_disk(struct g_mirror_softc *sc, struct g_provider *pp, 226 struct g_mirror_metadata *md); 227int g_mirror_read_metadata(struct g_consumer *cp, struct g_mirror_metadata *md); 228void g_mirror_fill_metadata(struct g_mirror_softc *sc, 229 struct g_mirror_disk *disk, struct g_mirror_metadata *md); 230void g_mirror_update_metadata(struct g_mirror_disk *disk); 231 232g_ctl_req_t g_mirror_config; 233#endif /* _KERNEL */ 234 235struct g_mirror_metadata { 236 char md_magic[16]; /* Magic value. */ 237 uint32_t md_version; /* Version number. */ 238 char md_name[16]; /* Mirror name. */ 239 uint32_t md_mid; /* Mirror unique ID. */ 240 uint32_t md_did; /* Disk unique ID. */ 241 uint8_t md_all; /* Number of disks in mirror. */ 242 uint32_t md_genid; /* Generation ID. */ 243 uint32_t md_syncid; /* Synchronization ID. */ 244 uint8_t md_priority; /* Disk priority. */ 245 uint32_t md_slice; /* Slice size. */ 246 uint8_t md_balance; /* Balance type. */ 247 uint64_t md_mediasize; /* Size of the smallest 248 disk in mirror. */ 249 uint32_t md_sectorsize; /* Sector size. */ 250 uint64_t md_sync_offset; /* Synchronized offset. */ 251 uint64_t md_mflags; /* Additional mirror flags. */ 252 uint64_t md_dflags; /* Additional disk flags. */ 253 char md_provider[16]; /* Hardcoded provider. */ 254 uint64_t md_provsize; /* Provider's size. */ 255 u_char md_hash[16]; /* MD5 hash. */ 256}; 257static __inline void 258mirror_metadata_encode(struct g_mirror_metadata *md, u_char *data) 259{ 260 MD5_CTX ctx; 261 262 bcopy(md->md_magic, data, 16); 263 le32enc(data + 16, md->md_version); 264 bcopy(md->md_name, data + 20, 16); 265 le32enc(data + 36, md->md_mid); 266 le32enc(data + 40, md->md_did); 267 *(data + 44) = md->md_all; 268 le32enc(data + 45, md->md_genid); 269 le32enc(data + 49, md->md_syncid); 270 *(data + 53) = md->md_priority; 271 le32enc(data + 54, md->md_slice); 272 *(data + 58) = md->md_balance; 273 le64enc(data + 59, md->md_mediasize); 274 le32enc(data + 67, md->md_sectorsize); 275 le64enc(data + 71, md->md_sync_offset); 276 le64enc(data + 79, md->md_mflags); 277 le64enc(data + 87, md->md_dflags); 278 bcopy(md->md_provider, data + 95, 16); 279 le64enc(data + 111, md->md_provsize); 280 MD5Init(&ctx); 281 MD5Update(&ctx, data, 119); 282 MD5Final(md->md_hash, &ctx); 283 bcopy(md->md_hash, data + 119, 16); 284} 285static __inline int 286mirror_metadata_decode_v0v1(const u_char *data, struct g_mirror_metadata *md) 287{ 288 MD5_CTX ctx; 289 290 bcopy(data + 20, md->md_name, 16); 291 md->md_mid = le32dec(data + 36); 292 md->md_did = le32dec(data + 40); 293 md->md_all = *(data + 44); 294 md->md_syncid = le32dec(data + 45); 295 md->md_priority = *(data + 49); 296 md->md_slice = le32dec(data + 50); 297 md->md_balance = *(data + 54); 298 md->md_mediasize = le64dec(data + 55); 299 md->md_sectorsize = le32dec(data + 63); 300 md->md_sync_offset = le64dec(data + 67); 301 md->md_mflags = le64dec(data + 75); 302 md->md_dflags = le64dec(data + 83); 303 bcopy(data + 91, md->md_provider, 16); 304 bcopy(data + 107, md->md_hash, 16); 305 MD5Init(&ctx); 306 MD5Update(&ctx, data, 107); 307 MD5Final(md->md_hash, &ctx); 308 if (bcmp(md->md_hash, data + 107, 16) != 0) 309 return (EINVAL); 310 311 /* New fields. */ 312 md->md_genid = 0; 313 md->md_provsize = 0; 314 315 return (0); 316} 317static __inline int 318mirror_metadata_decode_v2(const u_char *data, struct g_mirror_metadata *md) 319{ 320 MD5_CTX ctx; 321 322 bcopy(data + 20, md->md_name, 16); 323 md->md_mid = le32dec(data + 36); 324 md->md_did = le32dec(data + 40); 325 md->md_all = *(data + 44); 326 md->md_genid = le32dec(data + 45); 327 md->md_syncid = le32dec(data + 49); 328 md->md_priority = *(data + 53); 329 md->md_slice = le32dec(data + 54); 330 md->md_balance = *(data + 58); 331 md->md_mediasize = le64dec(data + 59); 332 md->md_sectorsize = le32dec(data + 67); 333 md->md_sync_offset = le64dec(data + 71); 334 md->md_mflags = le64dec(data + 79); 335 md->md_dflags = le64dec(data + 87); 336 bcopy(data + 95, md->md_provider, 16); 337 bcopy(data + 111, md->md_hash, 16); 338 MD5Init(&ctx); 339 MD5Update(&ctx, data, 111); 340 MD5Final(md->md_hash, &ctx); 341 if (bcmp(md->md_hash, data + 111, 16) != 0) 342 return (EINVAL); 343 344 /* New fields. */ 345 md->md_provsize = 0; 346 347 return (0); 348} 349static __inline int 350mirror_metadata_decode_v3v4(const u_char *data, struct g_mirror_metadata *md) 351{ 352 MD5_CTX ctx; 353 354 bcopy(data + 20, md->md_name, 16); 355 md->md_mid = le32dec(data + 36); 356 md->md_did = le32dec(data + 40); 357 md->md_all = *(data + 44); 358 md->md_genid = le32dec(data + 45); 359 md->md_syncid = le32dec(data + 49); 360 md->md_priority = *(data + 53); 361 md->md_slice = le32dec(data + 54); 362 md->md_balance = *(data + 58); 363 md->md_mediasize = le64dec(data + 59); 364 md->md_sectorsize = le32dec(data + 67); 365 md->md_sync_offset = le64dec(data + 71); 366 md->md_mflags = le64dec(data + 79); 367 md->md_dflags = le64dec(data + 87); 368 bcopy(data + 95, md->md_provider, 16); 369 md->md_provsize = le64dec(data + 111); 370 bcopy(data + 119, md->md_hash, 16); 371 MD5Init(&ctx); 372 MD5Update(&ctx, data, 119); 373 MD5Final(md->md_hash, &ctx); 374 if (bcmp(md->md_hash, data + 119, 16) != 0) 375 return (EINVAL); 376 return (0); 377} 378static __inline int 379mirror_metadata_decode(const u_char *data, struct g_mirror_metadata *md) 380{ 381 int error; 382 383 bcopy(data, md->md_magic, 16); 384 md->md_version = le32dec(data + 16); 385 switch (md->md_version) { 386 case 0: 387 case 1: 388 error = mirror_metadata_decode_v0v1(data, md); 389 break; 390 case 2: 391 error = mirror_metadata_decode_v2(data, md); 392 break; 393 case 3: 394 case 4: 395 error = mirror_metadata_decode_v3v4(data, md); 396 break; 397 default: 398 error = EINVAL; 399 break; 400 } 401 return (error); 402} 403 404static __inline const char * 405balance_name(u_int balance) 406{ 407 static const char *algorithms[] = { 408 [G_MIRROR_BALANCE_NONE] = "none", 409 [G_MIRROR_BALANCE_ROUND_ROBIN] = "round-robin", 410 [G_MIRROR_BALANCE_LOAD] = "load", 411 [G_MIRROR_BALANCE_SPLIT] = "split", 412 [G_MIRROR_BALANCE_PREFER] = "prefer", 413 [G_MIRROR_BALANCE_MAX + 1] = "unknown" 414 }; 415 416 if (balance > G_MIRROR_BALANCE_MAX) 417 balance = G_MIRROR_BALANCE_MAX + 1; 418 419 return (algorithms[balance]); 420} 421 422static __inline int 423balance_id(const char *name) 424{ 425 static const char *algorithms[] = { 426 [G_MIRROR_BALANCE_NONE] = "none", 427 [G_MIRROR_BALANCE_ROUND_ROBIN] = "round-robin", 428 [G_MIRROR_BALANCE_LOAD] = "load", 429 [G_MIRROR_BALANCE_SPLIT] = "split", 430 [G_MIRROR_BALANCE_PREFER] = "prefer" 431 }; 432 int n; 433 434 for (n = G_MIRROR_BALANCE_MIN; n <= G_MIRROR_BALANCE_MAX; n++) { 435 if (strcmp(name, algorithms[n]) == 0) 436 return (n); 437 } 438 return (-1); 439} 440 441static __inline void 442mirror_metadata_dump(const struct g_mirror_metadata *md) 443{ 444 static const char hex[] = "0123456789abcdef"; 445 char hash[16 * 2 + 1]; 446 u_int i; 447 448 printf(" magic: %s\n", md->md_magic); 449 printf(" version: %u\n", (u_int)md->md_version); 450 printf(" name: %s\n", md->md_name); 451 printf(" mid: %u\n", (u_int)md->md_mid); 452 printf(" did: %u\n", (u_int)md->md_did); 453 printf(" all: %u\n", (u_int)md->md_all); 454 printf(" genid: %u\n", (u_int)md->md_genid); 455 printf(" syncid: %u\n", (u_int)md->md_syncid); 456 printf(" priority: %u\n", (u_int)md->md_priority); 457 printf(" slice: %u\n", (u_int)md->md_slice); 458 printf(" balance: %s\n", balance_name((u_int)md->md_balance)); 459 printf(" mediasize: %jd\n", (intmax_t)md->md_mediasize); 460 printf("sectorsize: %u\n", (u_int)md->md_sectorsize); 461 printf("syncoffset: %jd\n", (intmax_t)md->md_sync_offset); 462 printf(" mflags:"); 463 if (md->md_mflags == 0) 464 printf(" NONE"); 465 else { 466 if ((md->md_mflags & G_MIRROR_DEVICE_FLAG_NOFAILSYNC) != 0) 467 printf(" NOFAILSYNC"); 468 if ((md->md_mflags & G_MIRROR_DEVICE_FLAG_NOAUTOSYNC) != 0) 469 printf(" NOAUTOSYNC"); 470 } 471 printf("\n"); 472 printf(" dflags:"); 473 if (md->md_dflags == 0) 474 printf(" NONE"); 475 else { 476 if ((md->md_dflags & G_MIRROR_DISK_FLAG_DIRTY) != 0) 477 printf(" DIRTY"); 478 if ((md->md_dflags & G_MIRROR_DISK_FLAG_SYNCHRONIZING) != 0) 479 printf(" SYNCHRONIZING"); 480 if ((md->md_dflags & G_MIRROR_DISK_FLAG_FORCE_SYNC) != 0) 481 printf(" FORCE_SYNC"); 482 if ((md->md_dflags & G_MIRROR_DISK_FLAG_INACTIVE) != 0) 483 printf(" INACTIVE"); 484 } 485 printf("\n"); 486 printf("hcprovider: %s\n", md->md_provider); 487 printf(" provsize: %ju\n", (uintmax_t)md->md_provsize); 488 bzero(hash, sizeof(hash)); 489 for (i = 0; i < 16; i++) { 490 hash[i * 2] = hex[md->md_hash[i] >> 4]; 491 hash[i * 2 + 1] = hex[md->md_hash[i] & 0x0f]; 492 } 493 printf(" MD5 hash: %s\n", hash); 494} 495#endif /* !_G_MIRROR_H_ */
| 217}; 218#define sc_name sc_geom->name 219 220u_int g_mirror_ndisks(struct g_mirror_softc *sc, int state); 221#define G_MIRROR_DESTROY_SOFT 0 222#define G_MIRROR_DESTROY_DELAYED 1 223#define G_MIRROR_DESTROY_HARD 2 224int g_mirror_destroy(struct g_mirror_softc *sc, int how); 225int g_mirror_event_send(void *arg, int state, int flags); 226struct g_mirror_metadata; 227int g_mirror_add_disk(struct g_mirror_softc *sc, struct g_provider *pp, 228 struct g_mirror_metadata *md); 229int g_mirror_read_metadata(struct g_consumer *cp, struct g_mirror_metadata *md); 230void g_mirror_fill_metadata(struct g_mirror_softc *sc, 231 struct g_mirror_disk *disk, struct g_mirror_metadata *md); 232void g_mirror_update_metadata(struct g_mirror_disk *disk); 233 234g_ctl_req_t g_mirror_config; 235#endif /* _KERNEL */ 236 237struct g_mirror_metadata { 238 char md_magic[16]; /* Magic value. */ 239 uint32_t md_version; /* Version number. */ 240 char md_name[16]; /* Mirror name. */ 241 uint32_t md_mid; /* Mirror unique ID. */ 242 uint32_t md_did; /* Disk unique ID. */ 243 uint8_t md_all; /* Number of disks in mirror. */ 244 uint32_t md_genid; /* Generation ID. */ 245 uint32_t md_syncid; /* Synchronization ID. */ 246 uint8_t md_priority; /* Disk priority. */ 247 uint32_t md_slice; /* Slice size. */ 248 uint8_t md_balance; /* Balance type. */ 249 uint64_t md_mediasize; /* Size of the smallest 250 disk in mirror. */ 251 uint32_t md_sectorsize; /* Sector size. */ 252 uint64_t md_sync_offset; /* Synchronized offset. */ 253 uint64_t md_mflags; /* Additional mirror flags. */ 254 uint64_t md_dflags; /* Additional disk flags. */ 255 char md_provider[16]; /* Hardcoded provider. */ 256 uint64_t md_provsize; /* Provider's size. */ 257 u_char md_hash[16]; /* MD5 hash. */ 258}; 259static __inline void 260mirror_metadata_encode(struct g_mirror_metadata *md, u_char *data) 261{ 262 MD5_CTX ctx; 263 264 bcopy(md->md_magic, data, 16); 265 le32enc(data + 16, md->md_version); 266 bcopy(md->md_name, data + 20, 16); 267 le32enc(data + 36, md->md_mid); 268 le32enc(data + 40, md->md_did); 269 *(data + 44) = md->md_all; 270 le32enc(data + 45, md->md_genid); 271 le32enc(data + 49, md->md_syncid); 272 *(data + 53) = md->md_priority; 273 le32enc(data + 54, md->md_slice); 274 *(data + 58) = md->md_balance; 275 le64enc(data + 59, md->md_mediasize); 276 le32enc(data + 67, md->md_sectorsize); 277 le64enc(data + 71, md->md_sync_offset); 278 le64enc(data + 79, md->md_mflags); 279 le64enc(data + 87, md->md_dflags); 280 bcopy(md->md_provider, data + 95, 16); 281 le64enc(data + 111, md->md_provsize); 282 MD5Init(&ctx); 283 MD5Update(&ctx, data, 119); 284 MD5Final(md->md_hash, &ctx); 285 bcopy(md->md_hash, data + 119, 16); 286} 287static __inline int 288mirror_metadata_decode_v0v1(const u_char *data, struct g_mirror_metadata *md) 289{ 290 MD5_CTX ctx; 291 292 bcopy(data + 20, md->md_name, 16); 293 md->md_mid = le32dec(data + 36); 294 md->md_did = le32dec(data + 40); 295 md->md_all = *(data + 44); 296 md->md_syncid = le32dec(data + 45); 297 md->md_priority = *(data + 49); 298 md->md_slice = le32dec(data + 50); 299 md->md_balance = *(data + 54); 300 md->md_mediasize = le64dec(data + 55); 301 md->md_sectorsize = le32dec(data + 63); 302 md->md_sync_offset = le64dec(data + 67); 303 md->md_mflags = le64dec(data + 75); 304 md->md_dflags = le64dec(data + 83); 305 bcopy(data + 91, md->md_provider, 16); 306 bcopy(data + 107, md->md_hash, 16); 307 MD5Init(&ctx); 308 MD5Update(&ctx, data, 107); 309 MD5Final(md->md_hash, &ctx); 310 if (bcmp(md->md_hash, data + 107, 16) != 0) 311 return (EINVAL); 312 313 /* New fields. */ 314 md->md_genid = 0; 315 md->md_provsize = 0; 316 317 return (0); 318} 319static __inline int 320mirror_metadata_decode_v2(const u_char *data, struct g_mirror_metadata *md) 321{ 322 MD5_CTX ctx; 323 324 bcopy(data + 20, md->md_name, 16); 325 md->md_mid = le32dec(data + 36); 326 md->md_did = le32dec(data + 40); 327 md->md_all = *(data + 44); 328 md->md_genid = le32dec(data + 45); 329 md->md_syncid = le32dec(data + 49); 330 md->md_priority = *(data + 53); 331 md->md_slice = le32dec(data + 54); 332 md->md_balance = *(data + 58); 333 md->md_mediasize = le64dec(data + 59); 334 md->md_sectorsize = le32dec(data + 67); 335 md->md_sync_offset = le64dec(data + 71); 336 md->md_mflags = le64dec(data + 79); 337 md->md_dflags = le64dec(data + 87); 338 bcopy(data + 95, md->md_provider, 16); 339 bcopy(data + 111, md->md_hash, 16); 340 MD5Init(&ctx); 341 MD5Update(&ctx, data, 111); 342 MD5Final(md->md_hash, &ctx); 343 if (bcmp(md->md_hash, data + 111, 16) != 0) 344 return (EINVAL); 345 346 /* New fields. */ 347 md->md_provsize = 0; 348 349 return (0); 350} 351static __inline int 352mirror_metadata_decode_v3v4(const u_char *data, struct g_mirror_metadata *md) 353{ 354 MD5_CTX ctx; 355 356 bcopy(data + 20, md->md_name, 16); 357 md->md_mid = le32dec(data + 36); 358 md->md_did = le32dec(data + 40); 359 md->md_all = *(data + 44); 360 md->md_genid = le32dec(data + 45); 361 md->md_syncid = le32dec(data + 49); 362 md->md_priority = *(data + 53); 363 md->md_slice = le32dec(data + 54); 364 md->md_balance = *(data + 58); 365 md->md_mediasize = le64dec(data + 59); 366 md->md_sectorsize = le32dec(data + 67); 367 md->md_sync_offset = le64dec(data + 71); 368 md->md_mflags = le64dec(data + 79); 369 md->md_dflags = le64dec(data + 87); 370 bcopy(data + 95, md->md_provider, 16); 371 md->md_provsize = le64dec(data + 111); 372 bcopy(data + 119, md->md_hash, 16); 373 MD5Init(&ctx); 374 MD5Update(&ctx, data, 119); 375 MD5Final(md->md_hash, &ctx); 376 if (bcmp(md->md_hash, data + 119, 16) != 0) 377 return (EINVAL); 378 return (0); 379} 380static __inline int 381mirror_metadata_decode(const u_char *data, struct g_mirror_metadata *md) 382{ 383 int error; 384 385 bcopy(data, md->md_magic, 16); 386 md->md_version = le32dec(data + 16); 387 switch (md->md_version) { 388 case 0: 389 case 1: 390 error = mirror_metadata_decode_v0v1(data, md); 391 break; 392 case 2: 393 error = mirror_metadata_decode_v2(data, md); 394 break; 395 case 3: 396 case 4: 397 error = mirror_metadata_decode_v3v4(data, md); 398 break; 399 default: 400 error = EINVAL; 401 break; 402 } 403 return (error); 404} 405 406static __inline const char * 407balance_name(u_int balance) 408{ 409 static const char *algorithms[] = { 410 [G_MIRROR_BALANCE_NONE] = "none", 411 [G_MIRROR_BALANCE_ROUND_ROBIN] = "round-robin", 412 [G_MIRROR_BALANCE_LOAD] = "load", 413 [G_MIRROR_BALANCE_SPLIT] = "split", 414 [G_MIRROR_BALANCE_PREFER] = "prefer", 415 [G_MIRROR_BALANCE_MAX + 1] = "unknown" 416 }; 417 418 if (balance > G_MIRROR_BALANCE_MAX) 419 balance = G_MIRROR_BALANCE_MAX + 1; 420 421 return (algorithms[balance]); 422} 423 424static __inline int 425balance_id(const char *name) 426{ 427 static const char *algorithms[] = { 428 [G_MIRROR_BALANCE_NONE] = "none", 429 [G_MIRROR_BALANCE_ROUND_ROBIN] = "round-robin", 430 [G_MIRROR_BALANCE_LOAD] = "load", 431 [G_MIRROR_BALANCE_SPLIT] = "split", 432 [G_MIRROR_BALANCE_PREFER] = "prefer" 433 }; 434 int n; 435 436 for (n = G_MIRROR_BALANCE_MIN; n <= G_MIRROR_BALANCE_MAX; n++) { 437 if (strcmp(name, algorithms[n]) == 0) 438 return (n); 439 } 440 return (-1); 441} 442 443static __inline void 444mirror_metadata_dump(const struct g_mirror_metadata *md) 445{ 446 static const char hex[] = "0123456789abcdef"; 447 char hash[16 * 2 + 1]; 448 u_int i; 449 450 printf(" magic: %s\n", md->md_magic); 451 printf(" version: %u\n", (u_int)md->md_version); 452 printf(" name: %s\n", md->md_name); 453 printf(" mid: %u\n", (u_int)md->md_mid); 454 printf(" did: %u\n", (u_int)md->md_did); 455 printf(" all: %u\n", (u_int)md->md_all); 456 printf(" genid: %u\n", (u_int)md->md_genid); 457 printf(" syncid: %u\n", (u_int)md->md_syncid); 458 printf(" priority: %u\n", (u_int)md->md_priority); 459 printf(" slice: %u\n", (u_int)md->md_slice); 460 printf(" balance: %s\n", balance_name((u_int)md->md_balance)); 461 printf(" mediasize: %jd\n", (intmax_t)md->md_mediasize); 462 printf("sectorsize: %u\n", (u_int)md->md_sectorsize); 463 printf("syncoffset: %jd\n", (intmax_t)md->md_sync_offset); 464 printf(" mflags:"); 465 if (md->md_mflags == 0) 466 printf(" NONE"); 467 else { 468 if ((md->md_mflags & G_MIRROR_DEVICE_FLAG_NOFAILSYNC) != 0) 469 printf(" NOFAILSYNC"); 470 if ((md->md_mflags & G_MIRROR_DEVICE_FLAG_NOAUTOSYNC) != 0) 471 printf(" NOAUTOSYNC"); 472 } 473 printf("\n"); 474 printf(" dflags:"); 475 if (md->md_dflags == 0) 476 printf(" NONE"); 477 else { 478 if ((md->md_dflags & G_MIRROR_DISK_FLAG_DIRTY) != 0) 479 printf(" DIRTY"); 480 if ((md->md_dflags & G_MIRROR_DISK_FLAG_SYNCHRONIZING) != 0) 481 printf(" SYNCHRONIZING"); 482 if ((md->md_dflags & G_MIRROR_DISK_FLAG_FORCE_SYNC) != 0) 483 printf(" FORCE_SYNC"); 484 if ((md->md_dflags & G_MIRROR_DISK_FLAG_INACTIVE) != 0) 485 printf(" INACTIVE"); 486 } 487 printf("\n"); 488 printf("hcprovider: %s\n", md->md_provider); 489 printf(" provsize: %ju\n", (uintmax_t)md->md_provsize); 490 bzero(hash, sizeof(hash)); 491 for (i = 0; i < 16; i++) { 492 hash[i * 2] = hex[md->md_hash[i] >> 4]; 493 hash[i * 2 + 1] = hex[md->md_hash[i] & 0x0f]; 494 } 495 printf(" MD5 hash: %s\n", hash); 496} 497#endif /* !_G_MIRROR_H_ */
|