Revision 8b81a7b6 block/qcow2-refcount.c

b/block/qcow2-refcount.c
861 861
            }
862 862

  
863 863
            for(j = 0; j < s->l2_size; j++) {
864
                uint64_t cluster_index;
865

  
864 866
                offset = be64_to_cpu(l2_table[j]);
865
                if (offset != 0) {
866
                    old_offset = offset;
867
                    offset &= ~QCOW_OFLAG_COPIED;
868
                    if (offset & QCOW_OFLAG_COMPRESSED) {
867
                old_offset = offset;
868
                offset &= ~QCOW_OFLAG_COPIED;
869

  
870
                switch (qcow2_get_cluster_type(offset)) {
871
                    case QCOW2_CLUSTER_COMPRESSED:
869 872
                        nb_csectors = ((offset >> s->csize_shift) &
870 873
                                       s->csize_mask) + 1;
871 874
                        if (addend != 0) {
......
880 883
                        }
881 884
                        /* compressed clusters are never modified */
882 885
                        refcount = 2;
883
                    } else {
884
                        uint64_t cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
886
                        break;
887

  
888
                    case QCOW2_CLUSTER_NORMAL:
889
                    case QCOW2_CLUSTER_ZERO:
890
                        cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
891
                        if (!cluster_index) {
892
                            /* unallocated */
893
                            refcount = 0;
894
                            break;
895
                        }
885 896
                        if (addend != 0) {
886 897
                            refcount = update_cluster_refcount(bs, cluster_index, addend,
887 898
                                                               QCOW2_DISCARD_SNAPSHOT);
......
893 904
                            ret = refcount;
894 905
                            goto fail;
895 906
                        }
896
                    }
907
                        break;
897 908

  
898
                    if (refcount == 1) {
899
                        offset |= QCOW_OFLAG_COPIED;
900
                    }
901
                    if (offset != old_offset) {
902
                        if (addend > 0) {
903
                            qcow2_cache_set_dependency(bs, s->l2_table_cache,
904
                                s->refcount_block_cache);
905
                        }
906
                        l2_table[j] = cpu_to_be64(offset);
907
                        qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
909
                    case QCOW2_CLUSTER_UNALLOCATED:
910
                        refcount = 0;
911
                        break;
912

  
913
                    default:
914
                        abort();
915
                }
916

  
917
                if (refcount == 1) {
918
                    offset |= QCOW_OFLAG_COPIED;
919
                }
920
                if (offset != old_offset) {
921
                    if (addend > 0) {
922
                        qcow2_cache_set_dependency(bs, s->l2_table_cache,
923
                            s->refcount_block_cache);
908 924
                    }
925
                    l2_table[j] = cpu_to_be64(offset);
926
                    qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
909 927
                }
910 928
            }
911 929

  

Also available in: Unified diff