Skip to content

Commit bb7d4d8

Browse files
committed
Merge remote-tracking branch 'kwolf/for-anthony' into staging
# By Max Reitz (11) and others # Via Kevin Wolf * kwolf/for-anthony: (26 commits) qemu-iotests: Overlapping cluster allocations qcow2_check: Mark image consistent qcow2-refcount: Repair shared refcount blocks qcow2-refcount: Repair OFLAG_COPIED errors qcow2-refcount: Move OFLAG_COPIED checks qcow2: Employ metadata overlap checks qcow2: Metadata overlap checks qcow2: Add corrupt bit qemu-iotests: Snapshotting zero clusters qcow2-refcount: Snapshot update for zero clusters option: Add assigned flag to QEMUOptionParameter gluster: Abort on AIO completion failure block: Remove old raw driver switch raw block driver from "raw.o" to "raw_bsd.o" raw_bsd: register bdrv_raw raw_bsd: add raw_create_options raw_bsd: introduce "special members" raw_bsd: add raw_create() raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev() add skeleton for BSD licensed "raw" BlockDriver ... Message-id: [email protected] Signed-off-by: Anthony Liguori <[email protected]>
2 parents 5a93d5c + ca0eca9 commit bb7d4d8

27 files changed

+1029
-322
lines changed

block.c

-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
743743
ret = -EINVAL;
744744
goto free_and_fail;
745745
}
746-
assert(file != NULL);
747746
bs->file = file;
748747
ret = drv->bdrv_open(bs, options, open_flags);
749748
}

block/Makefile.objs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
1+
block-obj-y += raw_bsd.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
22
block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
33
block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
44
block-obj-y += qed-check.o

block/blkdebug.c

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static const char *event_names[BLKDBG_EVENT_MAX] = {
168168

169169
[BLKDBG_REFTABLE_LOAD] = "reftable_load",
170170
[BLKDBG_REFTABLE_GROW] = "reftable_grow",
171+
[BLKDBG_REFTABLE_UPDATE] = "reftable_update",
171172

172173
[BLKDBG_REFBLOCK_LOAD] = "refblock_load",
173174
[BLKDBG_REFBLOCK_UPDATE] = "refblock_update",

block/gluster.c

+2-13
Original file line numberDiff line numberDiff line change
@@ -427,20 +427,9 @@ static void gluster_finish_aiocb(struct glfs_fd *fd, ssize_t ret, void *arg)
427427
/*
428428
* Gluster AIO callback thread failed to notify the waiting
429429
* QEMU thread about IO completion.
430-
*
431-
* Complete this IO request and make the disk inaccessible for
432-
* subsequent reads and writes.
433430
*/
434-
error_report("Gluster failed to notify QEMU about IO completion");
435-
436-
qemu_mutex_lock_iothread(); /* We are in gluster thread context */
437-
acb->common.cb(acb->common.opaque, -EIO);
438-
qemu_aio_release(acb);
439-
close(s->fds[GLUSTER_FD_READ]);
440-
close(s->fds[GLUSTER_FD_WRITE]);
441-
qemu_aio_set_fd_handler(s->fds[GLUSTER_FD_READ], NULL, NULL, NULL);
442-
bs->drv = NULL; /* Make the disk inaccessible */
443-
qemu_mutex_unlock_iothread();
431+
error_report("Gluster AIO completion failed: %s", strerror(errno));
432+
abort();
444433
}
445434
}
446435

block/qcow2-cache.c

+17
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
114114
return ret;
115115
}
116116

117+
if (c == s->refcount_block_cache) {
118+
ret = qcow2_pre_write_overlap_check(bs,
119+
QCOW2_OL_DEFAULT & ~QCOW2_OL_REFCOUNT_BLOCK,
120+
c->entries[i].offset, s->cluster_size);
121+
} else if (c == s->l2_table_cache) {
122+
ret = qcow2_pre_write_overlap_check(bs,
123+
QCOW2_OL_DEFAULT & ~QCOW2_OL_ACTIVE_L2,
124+
c->entries[i].offset, s->cluster_size);
125+
} else {
126+
ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
127+
c->entries[i].offset, s->cluster_size);
128+
}
129+
130+
if (ret < 0) {
131+
return ret;
132+
}
133+
117134
if (c == s->refcount_block_cache) {
118135
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_UPDATE_PART);
119136
} else if (c == s->l2_table_cache) {

block/qcow2-cluster.c

+23-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
8080
goto fail;
8181
}
8282

83+
/* the L1 position has not yet been updated, so these clusters must
84+
* indeed be completely free */
85+
ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
86+
new_l1_table_offset, new_l1_size2);
87+
if (ret < 0) {
88+
goto fail;
89+
}
90+
8391
BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE);
8492
for(i = 0; i < s->l1_size; i++)
8593
new_l1_table[i] = cpu_to_be64(new_l1_table[i]);
@@ -137,7 +145,7 @@ static int l2_load(BlockDriverState *bs, uint64_t l2_offset,
137145
* and we really don't want bdrv_pread to perform a read-modify-write)
138146
*/
139147
#define L1_ENTRIES_PER_SECTOR (512 / 8)
140-
static int write_l1_entry(BlockDriverState *bs, int l1_index)
148+
int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index)
141149
{
142150
BDRVQcowState *s = bs->opaque;
143151
uint64_t buf[L1_ENTRIES_PER_SECTOR];
@@ -149,6 +157,13 @@ static int write_l1_entry(BlockDriverState *bs, int l1_index)
149157
buf[i] = cpu_to_be64(s->l1_table[l1_start_index + i]);
150158
}
151159

160+
ret = qcow2_pre_write_overlap_check(bs,
161+
QCOW2_OL_DEFAULT & ~QCOW2_OL_ACTIVE_L1,
162+
s->l1_table_offset + 8 * l1_start_index, sizeof(buf));
163+
if (ret < 0) {
164+
return ret;
165+
}
166+
152167
BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
153168
ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset + 8 * l1_start_index,
154169
buf, sizeof(buf));
@@ -239,7 +254,7 @@ static int l2_allocate(BlockDriverState *bs, int l1_index, uint64_t **table)
239254
/* update the L1 entry */
240255
trace_qcow2_l2_allocate_write_l1(bs, l1_index);
241256
s->l1_table[l1_index] = l2_offset | QCOW_OFLAG_COPIED;
242-
ret = write_l1_entry(bs, l1_index);
257+
ret = qcow2_write_l1_entry(bs, l1_index);
243258
if (ret < 0) {
244259
goto fail;
245260
}
@@ -368,6 +383,12 @@ static int coroutine_fn copy_sectors(BlockDriverState *bs,
368383
&s->aes_encrypt_key);
369384
}
370385

386+
ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
387+
cluster_offset + n_start * BDRV_SECTOR_SIZE, n * BDRV_SECTOR_SIZE);
388+
if (ret < 0) {
389+
goto out;
390+
}
391+
371392
BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);
372393
ret = bdrv_co_writev(bs->file, (cluster_offset >> 9) + n_start, n, &qiov);
373394
if (ret < 0) {

0 commit comments

Comments
 (0)