snapshot.c (84a5a8014801a83d1b8d15fa7f0fde03db081530) | snapshot.c (7c8eece45b10fc9b716850345118ed6fa8d17887) |
---|---|
1/* 2 * Block layer snapshot related functions 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 359 unchanged lines hidden (view full) --- 368 369/* Group operations. All block drivers are involved. 370 * These functions will properly handle dataplane (take aio_context_acquire 371 * when appropriate for appropriate block drivers) */ 372 373bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs) 374{ 375 bool ok = true; | 1/* 2 * Block layer snapshot related functions 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 359 unchanged lines hidden (view full) --- 368 369/* Group operations. All block drivers are involved. 370 * These functions will properly handle dataplane (take aio_context_acquire 371 * when appropriate for appropriate block drivers) */ 372 373bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs) 374{ 375 bool ok = true; |
376 BlockDriverState *bs = NULL; | 376 BlockDriverState *bs; 377 BdrvNextIterator *it = NULL; |
377 | 378 |
378 while (ok && (bs = bdrv_next(bs))) { | 379 while (ok && (it = bdrv_next(it, &bs))) { |
379 AioContext *ctx = bdrv_get_aio_context(bs); 380 381 aio_context_acquire(ctx); 382 if (bdrv_is_inserted(bs) && !bdrv_is_read_only(bs)) { 383 ok = bdrv_can_snapshot(bs); 384 } 385 aio_context_release(ctx); 386 } 387 388 *first_bad_bs = bs; 389 return ok; 390} 391 392int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs, 393 Error **err) 394{ 395 int ret = 0; | 380 AioContext *ctx = bdrv_get_aio_context(bs); 381 382 aio_context_acquire(ctx); 383 if (bdrv_is_inserted(bs) && !bdrv_is_read_only(bs)) { 384 ok = bdrv_can_snapshot(bs); 385 } 386 aio_context_release(ctx); 387 } 388 389 *first_bad_bs = bs; 390 return ok; 391} 392 393int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs, 394 Error **err) 395{ 396 int ret = 0; |
396 BlockDriverState *bs = NULL; | 397 BlockDriverState *bs; 398 BdrvNextIterator *it = NULL; |
397 QEMUSnapshotInfo sn1, *snapshot = &sn1; 398 | 399 QEMUSnapshotInfo sn1, *snapshot = &sn1; 400 |
399 while (ret == 0 && (bs = bdrv_next(bs))) { | 401 while (ret == 0 && (it = bdrv_next(it, &bs))) { |
400 AioContext *ctx = bdrv_get_aio_context(bs); 401 402 aio_context_acquire(ctx); 403 if (bdrv_can_snapshot(bs) && 404 bdrv_snapshot_find(bs, snapshot, name) >= 0) { 405 ret = bdrv_snapshot_delete_by_id_or_name(bs, name, err); 406 } 407 aio_context_release(ctx); 408 } 409 410 *first_bad_bs = bs; 411 return ret; 412} 413 414 415int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs) 416{ 417 int err = 0; | 402 AioContext *ctx = bdrv_get_aio_context(bs); 403 404 aio_context_acquire(ctx); 405 if (bdrv_can_snapshot(bs) && 406 bdrv_snapshot_find(bs, snapshot, name) >= 0) { 407 ret = bdrv_snapshot_delete_by_id_or_name(bs, name, err); 408 } 409 aio_context_release(ctx); 410 } 411 412 *first_bad_bs = bs; 413 return ret; 414} 415 416 417int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs) 418{ 419 int err = 0; |
418 BlockDriverState *bs = NULL; | 420 BlockDriverState *bs; 421 BdrvNextIterator *it = NULL; |
419 | 422 |
420 while (err == 0 && (bs = bdrv_next(bs))) { | 423 while (err == 0 && (it = bdrv_next(it, &bs))) { |
421 AioContext *ctx = bdrv_get_aio_context(bs); 422 423 aio_context_acquire(ctx); 424 if (bdrv_can_snapshot(bs)) { 425 err = bdrv_snapshot_goto(bs, name); 426 } 427 aio_context_release(ctx); 428 } 429 430 *first_bad_bs = bs; 431 return err; 432} 433 434int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs) 435{ 436 QEMUSnapshotInfo sn; 437 int err = 0; | 424 AioContext *ctx = bdrv_get_aio_context(bs); 425 426 aio_context_acquire(ctx); 427 if (bdrv_can_snapshot(bs)) { 428 err = bdrv_snapshot_goto(bs, name); 429 } 430 aio_context_release(ctx); 431 } 432 433 *first_bad_bs = bs; 434 return err; 435} 436 437int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs) 438{ 439 QEMUSnapshotInfo sn; 440 int err = 0; |
438 BlockDriverState *bs = NULL; | 441 BlockDriverState *bs; 442 BdrvNextIterator *it = NULL; |
439 | 443 |
440 while (err == 0 && (bs = bdrv_next(bs))) { | 444 while (err == 0 && (it = bdrv_next(it, &bs))) { |
441 AioContext *ctx = bdrv_get_aio_context(bs); 442 443 aio_context_acquire(ctx); 444 if (bdrv_can_snapshot(bs)) { 445 err = bdrv_snapshot_find(bs, &sn, name); 446 } 447 aio_context_release(ctx); 448 } 449 450 *first_bad_bs = bs; 451 return err; 452} 453 454int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, 455 BlockDriverState *vm_state_bs, 456 uint64_t vm_state_size, 457 BlockDriverState **first_bad_bs) 458{ 459 int err = 0; | 445 AioContext *ctx = bdrv_get_aio_context(bs); 446 447 aio_context_acquire(ctx); 448 if (bdrv_can_snapshot(bs)) { 449 err = bdrv_snapshot_find(bs, &sn, name); 450 } 451 aio_context_release(ctx); 452 } 453 454 *first_bad_bs = bs; 455 return err; 456} 457 458int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, 459 BlockDriverState *vm_state_bs, 460 uint64_t vm_state_size, 461 BlockDriverState **first_bad_bs) 462{ 463 int err = 0; |
460 BlockDriverState *bs = NULL; | 464 BlockDriverState *bs; 465 BdrvNextIterator *it = NULL; |
461 | 466 |
462 while (err == 0 && (bs = bdrv_next(bs))) { | 467 while (err == 0 && (it = bdrv_next(it, &bs))) { |
463 AioContext *ctx = bdrv_get_aio_context(bs); 464 465 aio_context_acquire(ctx); 466 if (bs == vm_state_bs) { 467 sn->vm_state_size = vm_state_size; 468 err = bdrv_snapshot_create(bs, sn); 469 } else if (bdrv_can_snapshot(bs)) { 470 sn->vm_state_size = 0; --- 4 unchanged lines hidden (view full) --- 475 476 *first_bad_bs = bs; 477 return err; 478} 479 480BlockDriverState *bdrv_all_find_vmstate_bs(void) 481{ 482 bool not_found = true; | 468 AioContext *ctx = bdrv_get_aio_context(bs); 469 470 aio_context_acquire(ctx); 471 if (bs == vm_state_bs) { 472 sn->vm_state_size = vm_state_size; 473 err = bdrv_snapshot_create(bs, sn); 474 } else if (bdrv_can_snapshot(bs)) { 475 sn->vm_state_size = 0; --- 4 unchanged lines hidden (view full) --- 480 481 *first_bad_bs = bs; 482 return err; 483} 484 485BlockDriverState *bdrv_all_find_vmstate_bs(void) 486{ 487 bool not_found = true; |
483 BlockDriverState *bs = NULL; | 488 BlockDriverState *bs; 489 BdrvNextIterator *it = NULL; |
484 | 490 |
485 while (not_found && (bs = bdrv_next(bs))) { | 491 while (not_found && (it = bdrv_next(it, &bs))) { |
486 AioContext *ctx = bdrv_get_aio_context(bs); 487 488 aio_context_acquire(ctx); 489 not_found = !bdrv_can_snapshot(bs); 490 aio_context_release(ctx); 491 } 492 return bs; 493} | 492 AioContext *ctx = bdrv_get_aio_context(bs); 493 494 aio_context_acquire(ctx); 495 not_found = !bdrv_can_snapshot(bs); 496 aio_context_release(ctx); 497 } 498 return bs; 499} |