Commit 70240ca680aa7e9363ffbb784cf64907060f853e

Authored by aliguori
1 parent fc197934

Revert r6407

This series is broken by design as it requires expensive IO operations at
open time causing very long delays when starting a virtual machine for the
first time.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6813 c046a42c-6fe2-441c-8c8c-71466251a162
block-qcow2.c
... ... @@ -145,7 +145,6 @@ typedef struct BDRVQcowState {
145 145 AES_KEY aes_decrypt_key;
146 146  
147 147 int64_t highest_alloc; /* highest cluester allocated (in clusters) */
148   - int64_t nc_free; /* num of free clusters below highest_alloc */
149 148  
150 149 uint64_t snapshots_offset;
151 150 int snapshots_size;
... ... @@ -174,7 +173,7 @@ static void free_clusters(BlockDriverState *bs,
174 173 #ifdef DEBUG_ALLOC
175 174 static void check_refcounts(BlockDriverState *bs);
176 175 #endif
177   -static void scan_refcount(BlockDriverState *bs, int64_t *high, int64_t *free);
  176 +static void scan_refcount(BlockDriverState *bs, int64_t *high);
178 177  
179 178  
180 179 static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
... ... @@ -276,7 +275,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
276 275 if (refcount_init(bs) < 0)
277 276 goto fail;
278 277  
279   - scan_refcount(bs, &s->highest_alloc, &s->nc_free);
  278 + scan_refcount(bs, &s->highest_alloc);
280 279  
281 280 /* read the backing file name */
282 281 if (header.backing_file_offset != 0) {
... ... @@ -1647,7 +1646,6 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
1647 1646 bdi->vm_state_offset = (int64_t)s->l1_vm_state_index <<
1648 1647 (s->cluster_bits + s->l2_bits);
1649 1648 bdi->highest_alloc = s->highest_alloc << s->cluster_bits;
1650   - bdi->num_free_bytes = s->nc_free << s->cluster_bits;
1651 1649 return 0;
1652 1650 }
1653 1651  
... ... @@ -2166,35 +2164,25 @@ static int load_refcount_block(BlockDriverState *bs,
2166 2164 return 0;
2167 2165 }
2168 2166  
2169   -static void scan_refcount(BlockDriverState *bs, int64_t *high, int64_t *free)
  2167 +static void scan_refcount(BlockDriverState *bs, int64_t *high)
2170 2168 {
2171 2169 BDRVQcowState *s = bs->opaque;
2172   - int64_t refcnt_index, cluster_index, cluster_end, h = 0, f = 0;
2173   - int64_t tail = 0; /* do not count last consecutive free entries */
  2170 + int64_t refcnt_index, cluster_index, cluster_end, h = 0;
2174 2171  
2175 2172 for (refcnt_index=0; refcnt_index < s->refcount_table_size; refcnt_index++){
2176 2173 if (s->refcount_table[refcnt_index] == 0) {
2177   - f += 1 << (s->cluster_bits - REFCOUNT_SHIFT);
2178   - tail += 1 << (s->cluster_bits - REFCOUNT_SHIFT);
2179 2174 continue;
2180 2175 }
2181 2176 cluster_index = refcnt_index << (s->cluster_bits - REFCOUNT_SHIFT);
2182 2177 cluster_end = (refcnt_index + 1) << (s->cluster_bits - REFCOUNT_SHIFT);
2183 2178 for ( ; cluster_index < cluster_end; cluster_index++) {
2184   - if (get_refcount(bs, cluster_index) == 0) {
2185   - f++;
2186   - tail++;
2187   - }
2188   - else {
  2179 + if (get_refcount(bs, cluster_index) == 0)
  2180 + /* do nothing -- reserved for free counting */;
  2181 + else
2189 2182 h = cluster_index;
2190   - tail = 0;
2191   - }
2192 2183 }
2193 2184 }
2194 2185  
2195   - f -= tail;
2196   - if (free)
2197   - *free = f;
2198 2186 if (high)
2199 2187 *high = (h+1);
2200 2188 }
... ... @@ -2240,10 +2228,8 @@ retry:
2240 2228 (s->free_cluster_index - nb_clusters) << s->cluster_bits);
2241 2229 #endif
2242 2230  
2243   - if (s->highest_alloc < s->free_cluster_index) {
2244   - s->nc_free += (s->free_cluster_index - s->highest_alloc);
  2231 + if (s->highest_alloc < s->free_cluster_index)
2245 2232 s->highest_alloc = s->free_cluster_index;
2246   - }
2247 2233  
2248 2234 return (s->free_cluster_index - nb_clusters) << s->cluster_bits;
2249 2235 }
... ... @@ -2418,12 +2404,6 @@ static int update_cluster_refcount(BlockDriverState *bs,
2418 2404 block_index = cluster_index &
2419 2405 ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
2420 2406 refcount = be16_to_cpu(s->refcount_block_cache[block_index]);
2421   -
2422   - if (refcount == 1 && addend == -1)
2423   - s->nc_free += 1;
2424   - else if (refcount == 0 && addend == 1)
2425   - s->nc_free -= 1;
2426   -
2427 2407 refcount += addend;
2428 2408 if (refcount < 0 || refcount > 0xffff)
2429 2409 return -EINVAL;
... ...
... ... @@ -1153,9 +1153,8 @@ void bdrv_info_stats(Monitor *mon)
1153 1153 bs->rd_bytes, bs->wr_bytes,
1154 1154 bs->rd_ops, bs->wr_ops);
1155 1155 if (bdrv_get_info(bs, &bdi) == 0)
1156   - monitor_printf(mon, " high=%" PRId64
1157   - " bytes_free=%" PRId64,
1158   - bdi.highest_alloc, bdi.num_free_bytes);
  1156 + monitor_printf(mon, " high=%" PRId64,
  1157 + bdi.highest_alloc);
1159 1158 monitor_printf(mon, "\n");
1160 1159 }
1161 1160 }
... ...
... ... @@ -27,7 +27,6 @@ typedef struct BlockDriverInfo {
27 27 /* offset at which the VM state can be saved (0 if not possible) */
28 28 int64_t vm_state_offset;
29 29 int64_t highest_alloc; /* highest allocated block offset (in bytes) */
30   - int64_t num_free_bytes; /* below highest_alloc */
31 30 } BlockDriverInfo;
32 31  
33 32 typedef struct QEMUSnapshotInfo {
... ...