qcow2: Try to aggregate free clusters and freed clusters (Laurent Vivier)
In alloc_cluster_offset(), try to aggregate free clusters and freed clusters. Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5008 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
		
							parent
							
								
									768706a52f
								
							
						
					
					
						commit
						bc352085d2
					
				| 
						 | 
					@ -870,7 +870,7 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs,
 | 
				
			||||||
    BDRVQcowState *s = bs->opaque;
 | 
					    BDRVQcowState *s = bs->opaque;
 | 
				
			||||||
    int l2_index, ret;
 | 
					    int l2_index, ret;
 | 
				
			||||||
    uint64_t l2_offset, *l2_table, cluster_offset;
 | 
					    uint64_t l2_offset, *l2_table, cluster_offset;
 | 
				
			||||||
    int nb_available, nb_clusters, i;
 | 
					    int nb_available, nb_clusters, i, j;
 | 
				
			||||||
    uint64_t start_sect, current;
 | 
					    uint64_t start_sect, current;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index);
 | 
					    ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index);
 | 
				
			||||||
| 
						 | 
					@ -909,33 +909,51 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs,
 | 
				
			||||||
    if (cluster_offset & QCOW_OFLAG_COMPRESSED)
 | 
					    if (cluster_offset & QCOW_OFLAG_COMPRESSED)
 | 
				
			||||||
        nb_clusters = 1;
 | 
					        nb_clusters = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* how many empty or how many to free ? */
 | 
					    /* how many available clusters ? */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    i = 0;
 | 
				
			||||||
 | 
					    while (i < nb_clusters) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        i++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!cluster_offset) {
 | 
					        if (!cluster_offset) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* how many free clusters ? */
 | 
					            /* how many free clusters ? */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        i = 1;
 | 
					            while (i < nb_clusters) {
 | 
				
			||||||
        while (i < nb_clusters &&
 | 
					                cluster_offset = l2_table[l2_index + i];
 | 
				
			||||||
               l2_table[l2_index + i] == 0) {
 | 
					                if (cluster_offset != 0)
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
                i++;
 | 
					                i++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        nb_clusters = i;
 | 
					
 | 
				
			||||||
 | 
					            if ((cluster_offset & QCOW_OFLAG_COPIED) ||
 | 
				
			||||||
 | 
					                (cluster_offset & QCOW_OFLAG_COMPRESSED))
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* how many contiguous clusters ? */
 | 
					            /* how many contiguous clusters ? */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 1; i < nb_clusters; i++) {
 | 
					            j = 1;
 | 
				
			||||||
 | 
					            current = 0;
 | 
				
			||||||
 | 
					            while (i < nb_clusters) {
 | 
				
			||||||
                current = be64_to_cpu(l2_table[l2_index + i]);
 | 
					                current = be64_to_cpu(l2_table[l2_index + i]);
 | 
				
			||||||
            if (cluster_offset + (i << s->cluster_bits) != current)
 | 
					                if (cluster_offset + (j << s->cluster_bits) != current)
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                i++;
 | 
				
			||||||
 | 
					                j++;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            free_any_clusters(bs, cluster_offset, j);
 | 
				
			||||||
 | 
					            if (current)
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            cluster_offset = current;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    nb_clusters = i;
 | 
					    nb_clusters = i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        free_any_clusters(bs, cluster_offset, i);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* allocate a new cluster */
 | 
					    /* allocate a new cluster */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cluster_offset = alloc_clusters(bs, nb_clusters * s->cluster_size);
 | 
					    cluster_offset = alloc_clusters(bs, nb_clusters * s->cluster_size);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue