~ubuntu-branches/ubuntu/vivid/qemu-linaro/vivid

« back to all changes in this revision

Viewing changes to block/qcow2-cache.c

  • Committer: Ricardo Salveti de Araujo
  • Date: 2012-09-20 18:39:31 UTC
  • mfrom: (12922.1.2 qemu-linaro)
  • Revision ID: ricardo.salveti@linaro.org-20120920183931-sp3cg6kpdl8dmwo9
* New upstream release.
  - support emulated systems with more than 2G of memory. (LP: #1030588)
* Drop powerpc-missing-include.patch - merged upstream.
* Update debian/control:
  - drop perl build dependency.
  - add libfdt-dev build dependency.
* Update debian/qemu-keymaps.install file.
* Update debian/rules:
  - update QEMU_CPU for ARM architecture: armv4l -> armv7l.
  - update conf_audio_drv: default to PulseAudio since PA is the default on
    Ubuntu.
  - enable KVM on ARM architecture.
  - enable flat device tree support (--enable-fdt). (LP: #1030594)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "block_int.h"
26
26
#include "qemu-common.h"
27
27
#include "qcow2.h"
 
28
#include "trace.h"
28
29
 
29
30
typedef struct Qcow2CachedTable {
30
31
    void*   table;
39
40
    struct Qcow2Cache*      depends;
40
41
    int                     size;
41
42
    bool                    depends_on_flush;
42
 
    bool                    writethrough;
43
43
};
44
44
 
45
 
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
46
 
    bool writethrough)
 
45
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables)
47
46
{
48
47
    BDRVQcowState *s = bs->opaque;
49
48
    Qcow2Cache *c;
52
51
    c = g_malloc0(sizeof(*c));
53
52
    c->size = num_tables;
54
53
    c->entries = g_malloc0(sizeof(*c->entries) * num_tables);
55
 
    c->writethrough = writethrough;
56
54
 
57
55
    for (i = 0; i < c->size; i++) {
58
56
        c->entries[i].table = qemu_blockalign(bs, s->cluster_size);
100
98
        return 0;
101
99
    }
102
100
 
 
101
    trace_qcow2_cache_entry_flush(qemu_coroutine_self(),
 
102
                                  c == s->l2_table_cache, i);
 
103
 
103
104
    if (c->depends) {
104
105
        ret = qcow2_cache_flush_dependency(bs, c);
105
106
    } else if (c->depends_on_flush) {
132
133
 
133
134
int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
134
135
{
 
136
    BDRVQcowState *s = bs->opaque;
135
137
    int result = 0;
136
138
    int ret;
137
139
    int i;
138
140
 
 
141
    trace_qcow2_cache_flush(qemu_coroutine_self(), c == s->l2_table_cache);
 
142
 
139
143
    for (i = 0; i < c->size; i++) {
140
144
        ret = qcow2_cache_entry_flush(bs, c, i);
141
145
        if (ret < 0 && result != -ENOSPC) {
218
222
    int i;
219
223
    int ret;
220
224
 
 
225
    trace_qcow2_cache_get(qemu_coroutine_self(), c == s->l2_table_cache,
 
226
                          offset, read_from_disk);
 
227
 
221
228
    /* Check if the table is already cached */
222
229
    for (i = 0; i < c->size; i++) {
223
230
        if (c->entries[i].offset == offset) {
227
234
 
228
235
    /* If not, write a table back and replace it */
229
236
    i = qcow2_cache_find_entry_to_replace(c);
 
237
    trace_qcow2_cache_get_replace_entry(qemu_coroutine_self(),
 
238
                                        c == s->l2_table_cache, i);
230
239
    if (i < 0) {
231
240
        return i;
232
241
    }
236
245
        return ret;
237
246
    }
238
247
 
 
248
    trace_qcow2_cache_get_read(qemu_coroutine_self(),
 
249
                               c == s->l2_table_cache, i);
239
250
    c->entries[i].offset = 0;
240
251
    if (read_from_disk) {
241
252
        if (c == s->l2_table_cache) {
258
269
    c->entries[i].cache_hits++;
259
270
    c->entries[i].ref++;
260
271
    *table = c->entries[i].table;
 
272
 
 
273
    trace_qcow2_cache_get_done(qemu_coroutine_self(),
 
274
                               c == s->l2_table_cache, i);
 
275
 
261
276
    return 0;
262
277
}
263
278
 
289
304
    *table = NULL;
290
305
 
291
306
    assert(c->entries[i].ref >= 0);
292
 
 
293
 
    if (c->writethrough) {
294
 
        return qcow2_cache_entry_flush(bs, c, i);
295
 
    } else {
296
 
        return 0;
297
 
    }
 
307
    return 0;
298
308
}
299
309
 
300
310
void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table)
311
321
found:
312
322
    c->entries[i].dirty = true;
313
323
}
314
 
 
315
 
bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c,
316
 
    bool enable)
317
 
{
318
 
    bool old = c->writethrough;
319
 
 
320
 
    if (!old && enable) {
321
 
        qcow2_cache_flush(bs, c);
322
 
    }
323
 
 
324
 
    c->writethrough = enable;
325
 
    return old;
326
 
}