diff options
Diffstat (limited to 'drivers/md/dm-snap-persistent.c')
-rw-r--r-- | drivers/md/dm-snap-persistent.c | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c index e4ecadf0548a..39becbec4dfe 100644 --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c | |||
@@ -58,25 +58,30 @@ | |||
58 | #define NUM_SNAPSHOT_HDR_CHUNKS 1 | 58 | #define NUM_SNAPSHOT_HDR_CHUNKS 1 |
59 | 59 | ||
60 | struct disk_header { | 60 | struct disk_header { |
61 | uint32_t magic; | 61 | __le32 magic; |
62 | 62 | ||
63 | /* | 63 | /* |
64 | * Is this snapshot valid. There is no way of recovering | 64 | * Is this snapshot valid. There is no way of recovering |
65 | * an invalid snapshot. | 65 | * an invalid snapshot. |
66 | */ | 66 | */ |
67 | uint32_t valid; | 67 | __le32 valid; |
68 | 68 | ||
69 | /* | 69 | /* |
70 | * Simple, incrementing version. no backward | 70 | * Simple, incrementing version. no backward |
71 | * compatibility. | 71 | * compatibility. |
72 | */ | 72 | */ |
73 | uint32_t version; | 73 | __le32 version; |
74 | 74 | ||
75 | /* In sectors */ | 75 | /* In sectors */ |
76 | uint32_t chunk_size; | 76 | __le32 chunk_size; |
77 | }; | 77 | } __packed; |
78 | 78 | ||
79 | struct disk_exception { | 79 | struct disk_exception { |
80 | __le64 old_chunk; | ||
81 | __le64 new_chunk; | ||
82 | } __packed; | ||
83 | |||
84 | struct core_exception { | ||
80 | uint64_t old_chunk; | 85 | uint64_t old_chunk; |
81 | uint64_t new_chunk; | 86 | uint64_t new_chunk; |
82 | }; | 87 | }; |
@@ -396,32 +401,32 @@ static struct disk_exception *get_exception(struct pstore *ps, uint32_t index) | |||
396 | } | 401 | } |
397 | 402 | ||
398 | static void read_exception(struct pstore *ps, | 403 | static void read_exception(struct pstore *ps, |
399 | uint32_t index, struct disk_exception *result) | 404 | uint32_t index, struct core_exception *result) |
400 | { | 405 | { |
401 | struct disk_exception *e = get_exception(ps, index); | 406 | struct disk_exception *de = get_exception(ps, index); |
402 | 407 | ||
403 | /* copy it */ | 408 | /* copy it */ |
404 | result->old_chunk = le64_to_cpu(e->old_chunk); | 409 | result->old_chunk = le64_to_cpu(de->old_chunk); |
405 | result->new_chunk = le64_to_cpu(e->new_chunk); | 410 | result->new_chunk = le64_to_cpu(de->new_chunk); |
406 | } | 411 | } |
407 | 412 | ||
408 | static void write_exception(struct pstore *ps, | 413 | static void write_exception(struct pstore *ps, |
409 | uint32_t index, struct disk_exception *de) | 414 | uint32_t index, struct core_exception *e) |
410 | { | 415 | { |
411 | struct disk_exception *e = get_exception(ps, index); | 416 | struct disk_exception *de = get_exception(ps, index); |
412 | 417 | ||
413 | /* copy it */ | 418 | /* copy it */ |
414 | e->old_chunk = cpu_to_le64(de->old_chunk); | 419 | de->old_chunk = cpu_to_le64(e->old_chunk); |
415 | e->new_chunk = cpu_to_le64(de->new_chunk); | 420 | de->new_chunk = cpu_to_le64(e->new_chunk); |
416 | } | 421 | } |
417 | 422 | ||
418 | static void clear_exception(struct pstore *ps, uint32_t index) | 423 | static void clear_exception(struct pstore *ps, uint32_t index) |
419 | { | 424 | { |
420 | struct disk_exception *e = get_exception(ps, index); | 425 | struct disk_exception *de = get_exception(ps, index); |
421 | 426 | ||
422 | /* clear it */ | 427 | /* clear it */ |
423 | e->old_chunk = 0; | 428 | de->old_chunk = 0; |
424 | e->new_chunk = 0; | 429 | de->new_chunk = 0; |
425 | } | 430 | } |
426 | 431 | ||
427 | /* | 432 | /* |
@@ -437,13 +442,13 @@ static int insert_exceptions(struct pstore *ps, | |||
437 | { | 442 | { |
438 | int r; | 443 | int r; |
439 | unsigned int i; | 444 | unsigned int i; |
440 | struct disk_exception de; | 445 | struct core_exception e; |
441 | 446 | ||
442 | /* presume the area is full */ | 447 | /* presume the area is full */ |
443 | *full = 1; | 448 | *full = 1; |
444 | 449 | ||
445 | for (i = 0; i < ps->exceptions_per_area; i++) { | 450 | for (i = 0; i < ps->exceptions_per_area; i++) { |
446 | read_exception(ps, i, &de); | 451 | read_exception(ps, i, &e); |
447 | 452 | ||
448 | /* | 453 | /* |
449 | * If the new_chunk is pointing at the start of | 454 | * If the new_chunk is pointing at the start of |
@@ -451,7 +456,7 @@ static int insert_exceptions(struct pstore *ps, | |||
451 | * is we know that we've hit the end of the | 456 | * is we know that we've hit the end of the |
452 | * exceptions. Therefore the area is not full. | 457 | * exceptions. Therefore the area is not full. |
453 | */ | 458 | */ |
454 | if (de.new_chunk == 0LL) { | 459 | if (e.new_chunk == 0LL) { |
455 | ps->current_committed = i; | 460 | ps->current_committed = i; |
456 | *full = 0; | 461 | *full = 0; |
457 | break; | 462 | break; |
@@ -460,13 +465,13 @@ static int insert_exceptions(struct pstore *ps, | |||
460 | /* | 465 | /* |
461 | * Keep track of the start of the free chunks. | 466 | * Keep track of the start of the free chunks. |
462 | */ | 467 | */ |
463 | if (ps->next_free <= de.new_chunk) | 468 | if (ps->next_free <= e.new_chunk) |
464 | ps->next_free = de.new_chunk + 1; | 469 | ps->next_free = e.new_chunk + 1; |
465 | 470 | ||
466 | /* | 471 | /* |
467 | * Otherwise we add the exception to the snapshot. | 472 | * Otherwise we add the exception to the snapshot. |
468 | */ | 473 | */ |
469 | r = callback(callback_context, de.old_chunk, de.new_chunk); | 474 | r = callback(callback_context, e.old_chunk, e.new_chunk); |
470 | if (r) | 475 | if (r) |
471 | return r; | 476 | return r; |
472 | } | 477 | } |
@@ -641,12 +646,12 @@ static void persistent_commit_exception(struct dm_exception_store *store, | |||
641 | { | 646 | { |
642 | unsigned int i; | 647 | unsigned int i; |
643 | struct pstore *ps = get_info(store); | 648 | struct pstore *ps = get_info(store); |
644 | struct disk_exception de; | 649 | struct core_exception ce; |
645 | struct commit_callback *cb; | 650 | struct commit_callback *cb; |
646 | 651 | ||
647 | de.old_chunk = e->old_chunk; | 652 | ce.old_chunk = e->old_chunk; |
648 | de.new_chunk = e->new_chunk; | 653 | ce.new_chunk = e->new_chunk; |
649 | write_exception(ps, ps->current_committed++, &de); | 654 | write_exception(ps, ps->current_committed++, &ce); |
650 | 655 | ||
651 | /* | 656 | /* |
652 | * Add the callback to the back of the array. This code | 657 | * Add the callback to the back of the array. This code |
@@ -701,7 +706,7 @@ static int persistent_prepare_merge(struct dm_exception_store *store, | |||
701 | chunk_t *last_new_chunk) | 706 | chunk_t *last_new_chunk) |
702 | { | 707 | { |
703 | struct pstore *ps = get_info(store); | 708 | struct pstore *ps = get_info(store); |
704 | struct disk_exception de; | 709 | struct core_exception ce; |
705 | int nr_consecutive; | 710 | int nr_consecutive; |
706 | int r; | 711 | int r; |
707 | 712 | ||
@@ -722,9 +727,9 @@ static int persistent_prepare_merge(struct dm_exception_store *store, | |||
722 | ps->current_committed = ps->exceptions_per_area; | 727 | ps->current_committed = ps->exceptions_per_area; |
723 | } | 728 | } |
724 | 729 | ||
725 | read_exception(ps, ps->current_committed - 1, &de); | 730 | read_exception(ps, ps->current_committed - 1, &ce); |
726 | *last_old_chunk = de.old_chunk; | 731 | *last_old_chunk = ce.old_chunk; |
727 | *last_new_chunk = de.new_chunk; | 732 | *last_new_chunk = ce.new_chunk; |
728 | 733 | ||
729 | /* | 734 | /* |
730 | * Find number of consecutive chunks within the current area, | 735 | * Find number of consecutive chunks within the current area, |
@@ -733,9 +738,9 @@ static int persistent_prepare_merge(struct dm_exception_store *store, | |||
733 | for (nr_consecutive = 1; nr_consecutive < ps->current_committed; | 738 | for (nr_consecutive = 1; nr_consecutive < ps->current_committed; |
734 | nr_consecutive++) { | 739 | nr_consecutive++) { |
735 | read_exception(ps, ps->current_committed - 1 - nr_consecutive, | 740 | read_exception(ps, ps->current_committed - 1 - nr_consecutive, |
736 | &de); | 741 | &ce); |
737 | if (de.old_chunk != *last_old_chunk - nr_consecutive || | 742 | if (ce.old_chunk != *last_old_chunk - nr_consecutive || |
738 | de.new_chunk != *last_new_chunk - nr_consecutive) | 743 | ce.new_chunk != *last_new_chunk - nr_consecutive) |
739 | break; | 744 | break; |
740 | } | 745 | } |
741 | 746 | ||