Revision 6af4e9ea block/qcow2-cache.c
b/block/qcow2-cache.c | ||
---|---|---|
40 | 40 |
struct Qcow2Cache* depends; |
41 | 41 |
int size; |
42 | 42 |
bool depends_on_flush; |
43 |
bool writethrough; |
|
44 | 43 |
}; |
45 | 44 |
|
46 |
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables, |
|
47 |
bool writethrough) |
|
45 |
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables) |
|
48 | 46 |
{ |
49 | 47 |
BDRVQcowState *s = bs->opaque; |
50 | 48 |
Qcow2Cache *c; |
... | ... | |
53 | 51 |
c = g_malloc0(sizeof(*c)); |
54 | 52 |
c->size = num_tables; |
55 | 53 |
c->entries = g_malloc0(sizeof(*c->entries) * num_tables); |
56 |
c->writethrough = writethrough; |
|
57 | 54 |
|
58 | 55 |
for (i = 0; i < c->size; i++) { |
59 | 56 |
c->entries[i].table = qemu_blockalign(bs, s->cluster_size); |
... | ... | |
307 | 304 |
*table = NULL; |
308 | 305 |
|
309 | 306 |
assert(c->entries[i].ref >= 0); |
310 |
|
|
311 |
if (c->writethrough) { |
|
312 |
return qcow2_cache_entry_flush(bs, c, i); |
|
313 |
} else { |
|
314 |
return 0; |
|
315 |
} |
|
307 |
return 0; |
|
316 | 308 |
} |
317 | 309 |
|
318 | 310 |
void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table) |
... | ... | |
329 | 321 |
found: |
330 | 322 |
c->entries[i].dirty = true; |
331 | 323 |
} |
332 |
|
|
333 |
bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c, |
|
334 |
bool enable) |
|
335 |
{ |
|
336 |
bool old = c->writethrough; |
|
337 |
|
|
338 |
if (!old && enable) { |
|
339 |
qcow2_cache_flush(bs, c); |
|
340 |
} |
|
341 |
|
|
342 |
c->writethrough = enable; |
|
343 |
return old; |
|
344 |
} |
Also available in: Unified diff