Compare commits
167 Commits
v1.7.0
...
pull-audio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d58ce68a45 | ||
|
|
7f0ba7bb43 | ||
|
|
0e8ae611bd | ||
|
|
40a814b0b1 | ||
|
|
a1d22a367d | ||
|
|
d2aa90cda8 | ||
|
|
93531372f0 | ||
|
|
0c0cb6a237 | ||
|
|
3c88da3c24 | ||
|
|
2a576ee6e3 | ||
|
|
0a0ee0b93b | ||
|
|
9ed5dacbfa | ||
|
|
cdac7a7184 | ||
|
|
a55d121f4a | ||
|
|
e679f05248 | ||
|
|
783eb67e7a | ||
|
|
6fedcaa1c5 | ||
|
|
3e40ba0faf | ||
|
|
b3ebc10c37 | ||
|
|
96eeeba0db | ||
|
|
5b49ab188f | ||
|
|
bf63839ffa | ||
|
|
ac9524dc55 | ||
|
|
d3fa923044 | ||
|
|
0b06ef3bdd | ||
|
|
ac95acdb8e | ||
|
|
405889820b | ||
|
|
24f833cd43 | ||
|
|
bcf2b7d2af | ||
|
|
6eefccc0bb | ||
|
|
385724e788 | ||
|
|
07403a5a03 | ||
|
|
94e68caaa0 | ||
|
|
11938d7863 | ||
|
|
33f373d7c5 | ||
|
|
f2521c9023 | ||
|
|
7572ddc8db | ||
|
|
7337acaf21 | ||
|
|
1c0704a556 | ||
|
|
049b09825f | ||
|
|
13c28af87a | ||
|
|
4323fdcf94 | ||
|
|
f33d287393 | ||
|
|
ef80654d0d | ||
|
|
9c468a013f | ||
|
|
8c116b0e41 | ||
|
|
7b4c4781e3 | ||
|
|
34602dd642 | ||
|
|
236c796432 | ||
|
|
e14fb91312 | ||
|
|
f210a83c1f | ||
|
|
58cc2ae1e3 | ||
|
|
3baa84491a | ||
|
|
f8413b3c23 | ||
|
|
66f6b8143b | ||
|
|
84f94a9a82 | ||
|
|
823bd7391c | ||
|
|
c5fd1fb038 | ||
|
|
e18d90c15b | ||
|
|
97a2ae3453 | ||
|
|
d0b4503ed2 | ||
|
|
260a82e524 | ||
|
|
fa6252b056 | ||
|
|
2af8a1a704 | ||
|
|
4b52498e62 | ||
|
|
cffb1ec600 | ||
|
|
95de6d7078 | ||
|
|
97b00e2851 | ||
|
|
b8d71c09f3 | ||
|
|
7ce21016b6 | ||
|
|
d5ef94d43d | ||
|
|
94d6ff21f4 | ||
|
|
d20d9b7c67 | ||
|
|
d51e9fe505 | ||
|
|
e9eecb5bf8 | ||
|
|
af057fe740 | ||
|
|
a6b6d08a3b | ||
|
|
4282c82770 | ||
|
|
efbc42e584 | ||
|
|
754e72e195 | ||
|
|
cb77e35815 | ||
|
|
1246b259f8 | ||
|
|
47908a0f66 | ||
|
|
867d898ccf | ||
|
|
b2e2395f13 | ||
|
|
ef0dd982cb | ||
|
|
5d28b0e960 | ||
|
|
1226961622 | ||
|
|
ac86048bcd | ||
|
|
7b6b145dbc | ||
|
|
f287c41381 | ||
|
|
1442d3e691 | ||
|
|
aeca6e8d8b | ||
|
|
539891a85d | ||
|
|
d18e173a07 | ||
|
|
0b959cf5e4 | ||
|
|
664d2c4458 | ||
|
|
c9baa30f42 | ||
|
|
41d9ea80ac | ||
|
|
cd629de1cf | ||
|
|
b6a3e690b4 | ||
|
|
981cbf59b5 | ||
|
|
509d39aa22 | ||
|
|
c34b8012e8 | ||
|
|
0d83c98bf1 | ||
|
|
c9fbb99d41 | ||
|
|
f32f988c77 | ||
|
|
9fd3171af9 | ||
|
|
b59b3d5773 | ||
|
|
3cf53c7714 | ||
|
|
4cc70e9337 | ||
|
|
5b43dbb699 | ||
|
|
b3af018f3b | ||
|
|
c31d482f29 | ||
|
|
4d5977eaec | ||
|
|
6273d1136a | ||
|
|
dce32b6c2b | ||
|
|
091b1108ca | ||
|
|
14b98fdaf3 | ||
|
|
21b5683508 | ||
|
|
e4654d2d94 | ||
|
|
a29267846a | ||
|
|
55a2b1631f | ||
|
|
9721cf2cd6 | ||
|
|
f4f1e10a58 | ||
|
|
905bba13ca | ||
|
|
0b1fa34e1d | ||
|
|
2b81ba5388 | ||
|
|
904c063039 | ||
|
|
690af06aeb | ||
|
|
e489df40ca | ||
|
|
f4a193e717 | ||
|
|
8582972227 | ||
|
|
f8d1daea6f | ||
|
|
b276d24994 | ||
|
|
5a37b60a61 | ||
|
|
11b6699af5 | ||
|
|
c3d8688470 | ||
|
|
d75cbb5e68 | ||
|
|
d4cd961507 | ||
|
|
01a6a238a3 | ||
|
|
ba6c59191f | ||
|
|
6f14da5247 | ||
|
|
c31cb70728 | ||
|
|
04f19e4d2d | ||
|
|
fe81c2cca6 | ||
|
|
186d4f2b1d | ||
|
|
4ce786914b | ||
|
|
e1a5c4bed4 | ||
|
|
d32f35cbc5 | ||
|
|
aa7bfbfff7 | ||
|
|
6faac15fa8 | ||
|
|
7dc65c02fe | ||
|
|
72391da506 | ||
|
|
3b444eadf7 | ||
|
|
04b300f85f | ||
|
|
5007c940a9 | ||
|
|
49cfa2fdc9 | ||
|
|
3453f9a0df | ||
|
|
0478661ec5 | ||
|
|
5eb6d9e3ef | ||
|
|
d4bfc7b9f3 | ||
|
|
9ec557bd53 | ||
|
|
f1f8bc218a | ||
|
|
de9de157fb | ||
|
|
ef36fa1492 | ||
|
|
fb541ca59c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@ config-all-devices.*
|
||||
config-all-disas.*
|
||||
config-host.*
|
||||
config-target.*
|
||||
config.status
|
||||
trace/generated-tracers.h
|
||||
trace/generated-tracers.c
|
||||
trace/generated-tracers-dtrace.h
|
||||
|
||||
@@ -879,6 +879,7 @@ F: block/rbd.c
|
||||
Sheepdog
|
||||
M: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
|
||||
M: Liu Yuan <namei.unix@gmail.com>
|
||||
L: sheepdog@lists.wpkg.org
|
||||
S: Supported
|
||||
F: block/sheepdog.c
|
||||
|
||||
|
||||
@@ -217,11 +217,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
|
||||
ctx->walking_handlers--;
|
||||
|
||||
/* early return if we only have the aio_notify() fd */
|
||||
if (ctx->pollfds->len == 1) {
|
||||
return progress;
|
||||
}
|
||||
|
||||
/* wait until next event */
|
||||
ret = qemu_poll_ns((GPollFD *)ctx->pollfds->data,
|
||||
ctx->pollfds->len,
|
||||
|
||||
@@ -161,11 +161,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
|
||||
|
||||
ctx->walking_handlers--;
|
||||
|
||||
/* early return if we only have the aio_notify() fd */
|
||||
if (count == 1) {
|
||||
return progress;
|
||||
}
|
||||
|
||||
/* wait until next event */
|
||||
while (count > 0) {
|
||||
int ret;
|
||||
|
||||
@@ -95,7 +95,7 @@ static struct {
|
||||
}
|
||||
},
|
||||
|
||||
.period = { .hertz = 250 },
|
||||
.period = { .hertz = 100 },
|
||||
.plive = 0,
|
||||
.log_to_monitor = 0,
|
||||
.try_poll_in = 1,
|
||||
|
||||
@@ -547,11 +547,11 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as)
|
||||
ss.rate = as->freq;
|
||||
|
||||
/*
|
||||
* qemu audio tick runs at 250 Hz (by default), so processing
|
||||
* data chunks worth 4 ms of sound should be a good fit.
|
||||
* qemu audio tick runs at 100 Hz (by default), so processing
|
||||
* data chunks worth 10 ms of sound should be a good fit.
|
||||
*/
|
||||
ba.tlength = pa_usec_to_bytes (4 * 1000, &ss);
|
||||
ba.minreq = pa_usec_to_bytes (2 * 1000, &ss);
|
||||
ba.tlength = pa_usec_to_bytes (10 * 1000, &ss);
|
||||
ba.minreq = pa_usec_to_bytes (5 * 1000, &ss);
|
||||
ba.maxlength = -1;
|
||||
ba.prebuf = -1;
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ typedef struct BlkMigDevState {
|
||||
/* Protected by block migration lock. */
|
||||
unsigned long *aio_bitmap;
|
||||
int64_t completed_sectors;
|
||||
BdrvDirtyBitmap *dirty_bitmap;
|
||||
} BlkMigDevState;
|
||||
|
||||
typedef struct BlkMigBlock {
|
||||
@@ -309,12 +310,21 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
|
||||
|
||||
/* Called with iothread lock taken. */
|
||||
|
||||
static void set_dirty_tracking(int enable)
|
||||
static void set_dirty_tracking(void)
|
||||
{
|
||||
BlkMigDevState *bmds;
|
||||
|
||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
||||
bdrv_set_dirty_tracking(bmds->bs, enable ? BLOCK_SIZE : 0);
|
||||
bmds->dirty_bitmap = bdrv_create_dirty_bitmap(bmds->bs, BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static void unset_dirty_tracking(void)
|
||||
{
|
||||
BlkMigDevState *bmds;
|
||||
|
||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
||||
bdrv_release_dirty_bitmap(bmds->bs, bmds->dirty_bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,7 +442,7 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
|
||||
} else {
|
||||
blk_mig_unlock();
|
||||
}
|
||||
if (bdrv_get_dirty(bmds->bs, sector)) {
|
||||
if (bdrv_get_dirty(bmds->bs, bmds->dirty_bitmap, sector)) {
|
||||
|
||||
if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
|
||||
nr_sectors = total_sectors - sector;
|
||||
@@ -554,7 +564,7 @@ static int64_t get_remaining_dirty(void)
|
||||
int64_t dirty = 0;
|
||||
|
||||
QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) {
|
||||
dirty += bdrv_get_dirty_count(bmds->bs);
|
||||
dirty += bdrv_get_dirty_count(bmds->bs, bmds->dirty_bitmap);
|
||||
}
|
||||
|
||||
return dirty << BDRV_SECTOR_BITS;
|
||||
@@ -569,7 +579,7 @@ static void blk_mig_cleanup(void)
|
||||
|
||||
bdrv_drain_all();
|
||||
|
||||
set_dirty_tracking(0);
|
||||
unset_dirty_tracking();
|
||||
|
||||
blk_mig_lock();
|
||||
while ((bmds = QSIMPLEQ_FIRST(&block_mig_state.bmds_list)) != NULL) {
|
||||
@@ -604,7 +614,7 @@ static int block_save_setup(QEMUFile *f, void *opaque)
|
||||
init_blk_migration(f);
|
||||
|
||||
/* start track dirty blocks */
|
||||
set_dirty_tracking(1);
|
||||
set_dirty_tracking();
|
||||
qemu_mutex_unlock_iothread();
|
||||
|
||||
ret = flush_blks(f);
|
||||
@@ -780,7 +790,8 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
|
||||
}
|
||||
|
||||
if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
|
||||
ret = bdrv_write_zeroes(bs, addr, nr_sectors);
|
||||
ret = bdrv_write_zeroes(bs, addr, nr_sectors,
|
||||
BDRV_REQ_MAY_UNMAP);
|
||||
} else {
|
||||
buf = g_malloc(BLOCK_SIZE);
|
||||
qemu_get_buffer(f, buf, BLOCK_SIZE);
|
||||
|
||||
466
block.c
466
block.c
@@ -49,12 +49,12 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */
|
||||
struct BdrvDirtyBitmap {
|
||||
HBitmap *bitmap;
|
||||
QLIST_ENTRY(BdrvDirtyBitmap) list;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
BDRV_REQ_COPY_ON_READ = 0x1,
|
||||
BDRV_REQ_ZERO_WRITE = 0x2,
|
||||
} BdrvRequestFlags;
|
||||
#define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */
|
||||
|
||||
static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
|
||||
static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
|
||||
@@ -79,12 +79,13 @@ static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
QEMUIOVector *qiov,
|
||||
int nb_sectors,
|
||||
BdrvRequestFlags flags,
|
||||
BlockDriverCompletionFunc *cb,
|
||||
void *opaque,
|
||||
bool is_write);
|
||||
static void coroutine_fn bdrv_co_do_rw(void *opaque);
|
||||
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors);
|
||||
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags);
|
||||
|
||||
static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
|
||||
QTAILQ_HEAD_INITIALIZER(bdrv_states);
|
||||
@@ -323,6 +324,7 @@ BlockDriverState *bdrv_new(const char *device_name)
|
||||
BlockDriverState *bs;
|
||||
|
||||
bs = g_malloc0(sizeof(BlockDriverState));
|
||||
QLIST_INIT(&bs->dirty_bitmaps);
|
||||
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
|
||||
if (device_name[0] != '\0') {
|
||||
QTAILQ_INSERT_TAIL(&bdrv_states, bs, list);
|
||||
@@ -1052,21 +1054,16 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
||||
int64_t total_size;
|
||||
BlockDriver *bdrv_qcow2;
|
||||
QEMUOptionParameter *create_options;
|
||||
char backing_filename[PATH_MAX];
|
||||
|
||||
if (qdict_size(options) != 0) {
|
||||
error_setg(errp, "Can't use snapshot=on with driver-specific options");
|
||||
ret = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
assert(filename != NULL);
|
||||
QDict *snapshot_options;
|
||||
|
||||
/* if snapshot, we create a temporary backing file and open it
|
||||
instead of opening 'filename' directly */
|
||||
|
||||
/* if there is a backing file, use it */
|
||||
/* Get the required size from the image */
|
||||
bs1 = bdrv_new("");
|
||||
ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
|
||||
QINCREF(options);
|
||||
ret = bdrv_open(bs1, filename, options, BDRV_O_NO_BACKING,
|
||||
drv, &local_err);
|
||||
if (ret < 0) {
|
||||
bdrv_unref(bs1);
|
||||
goto fail;
|
||||
@@ -1075,33 +1072,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
||||
|
||||
bdrv_unref(bs1);
|
||||
|
||||
/* Create the temporary image */
|
||||
ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename));
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Could not get temporary filename");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Real path is meaningless for protocols */
|
||||
if (path_has_protocol(filename)) {
|
||||
snprintf(backing_filename, sizeof(backing_filename),
|
||||
"%s", filename);
|
||||
} else if (!realpath(filename, backing_filename)) {
|
||||
ret = -errno;
|
||||
error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bdrv_qcow2 = bdrv_find_format("qcow2");
|
||||
create_options = parse_option_parameters("", bdrv_qcow2->create_options,
|
||||
NULL);
|
||||
|
||||
set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
|
||||
set_option_parameter(create_options, BLOCK_OPT_BACKING_FILE,
|
||||
backing_filename);
|
||||
if (drv) {
|
||||
set_option_parameter(create_options, BLOCK_OPT_BACKING_FMT,
|
||||
drv->format_name);
|
||||
}
|
||||
|
||||
ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
|
||||
free_option_parameters(create_options);
|
||||
@@ -1114,6 +1096,22 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Prepare a new options QDict for the temporary file, where user
|
||||
* options refer to the backing file */
|
||||
if (filename) {
|
||||
qdict_put(options, "file.filename", qstring_from_str(filename));
|
||||
}
|
||||
if (drv) {
|
||||
qdict_put(options, "driver", qstring_from_str(drv->format_name));
|
||||
}
|
||||
|
||||
snapshot_options = qdict_new();
|
||||
qdict_put(snapshot_options, "backing", options);
|
||||
qdict_flatten(snapshot_options);
|
||||
|
||||
bs->options = snapshot_options;
|
||||
options = qdict_clone_shallow(bs->options);
|
||||
|
||||
filename = tmp_filename;
|
||||
drv = bdrv_qcow2;
|
||||
bs->is_temporary = 1;
|
||||
@@ -1559,13 +1557,8 @@ void bdrv_drain_all(void)
|
||||
BlockDriverState *bs;
|
||||
|
||||
while (busy) {
|
||||
/* FIXME: We do not have timer support here, so this is effectively
|
||||
* a busy wait.
|
||||
*/
|
||||
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
||||
if (bdrv_start_throttled_reqs(bs)) {
|
||||
busy = true;
|
||||
}
|
||||
bdrv_start_throttled_reqs(bs);
|
||||
}
|
||||
|
||||
busy = bdrv_requests_pending_all();
|
||||
@@ -1622,7 +1615,7 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
|
||||
bs_dest->iostatus = bs_src->iostatus;
|
||||
|
||||
/* dirty bitmap */
|
||||
bs_dest->dirty_bitmap = bs_src->dirty_bitmap;
|
||||
bs_dest->dirty_bitmaps = bs_src->dirty_bitmaps;
|
||||
|
||||
/* reference count */
|
||||
bs_dest->refcnt = bs_src->refcnt;
|
||||
@@ -1655,7 +1648,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
|
||||
|
||||
/* bs_new must be anonymous and shouldn't have anything fancy enabled */
|
||||
assert(bs_new->device_name[0] == '\0');
|
||||
assert(bs_new->dirty_bitmap == NULL);
|
||||
assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));
|
||||
assert(bs_new->job == NULL);
|
||||
assert(bs_new->dev == NULL);
|
||||
assert(bs_new->in_use == 0);
|
||||
@@ -1716,6 +1709,7 @@ static void bdrv_delete(BlockDriverState *bs)
|
||||
assert(!bs->job);
|
||||
assert(!bs->in_use);
|
||||
assert(!bs->refcnt);
|
||||
assert(QLIST_EMPTY(&bs->dirty_bitmaps));
|
||||
|
||||
bdrv_close(bs);
|
||||
|
||||
@@ -2397,10 +2391,48 @@ int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov)
|
||||
return bdrv_rwv_co(bs, sector_num, qiov, true, 0);
|
||||
}
|
||||
|
||||
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
|
||||
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, BdrvRequestFlags flags)
|
||||
{
|
||||
return bdrv_rw_co(bs, sector_num, NULL, nb_sectors, true,
|
||||
BDRV_REQ_ZERO_WRITE);
|
||||
BDRV_REQ_ZERO_WRITE | flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* Completely zero out a block device with the help of bdrv_write_zeroes.
|
||||
* The operation is sped up by checking the block status and only writing
|
||||
* zeroes to the device if they currently do not return zeroes. Optional
|
||||
* flags are passed through to bdrv_write_zeroes (e.g. BDRV_REQ_MAY_UNMAP).
|
||||
*
|
||||
* Returns < 0 on error, 0 on success. For error codes see bdrv_write().
|
||||
*/
|
||||
int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags)
|
||||
{
|
||||
int64_t target_size = bdrv_getlength(bs) / BDRV_SECTOR_SIZE;
|
||||
int64_t ret, nb_sectors, sector_num = 0;
|
||||
int n;
|
||||
|
||||
for (;;) {
|
||||
nb_sectors = target_size - sector_num;
|
||||
if (nb_sectors <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (nb_sectors > INT_MAX) {
|
||||
nb_sectors = INT_MAX;
|
||||
}
|
||||
ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &n);
|
||||
if (ret & BDRV_BLOCK_ZERO) {
|
||||
sector_num += n;
|
||||
continue;
|
||||
}
|
||||
ret = bdrv_write_zeroes(bs, sector_num, n, flags);
|
||||
if (ret < 0) {
|
||||
error_report("error writing zeroes at sector %" PRId64 ": %s",
|
||||
sector_num, strerror(-ret));
|
||||
return ret;
|
||||
}
|
||||
sector_num += n;
|
||||
}
|
||||
}
|
||||
|
||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||
@@ -2582,7 +2614,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs,
|
||||
if (drv->bdrv_co_write_zeroes &&
|
||||
buffer_is_zero(bounce_buffer, iov.iov_len)) {
|
||||
ret = bdrv_co_do_write_zeroes(bs, cluster_sector_num,
|
||||
cluster_nb_sectors);
|
||||
cluster_nb_sectors, 0);
|
||||
} else {
|
||||
/* This does not change the data on the disk, it is not necessary
|
||||
* to flush even in cache=writethrough mode.
|
||||
@@ -2715,33 +2747,77 @@ int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
|
||||
BDRV_REQ_COPY_ON_READ);
|
||||
}
|
||||
|
||||
/* if no limit is specified in the BlockLimits use a default
|
||||
* of 32768 512-byte sectors (16 MiB) per request.
|
||||
*/
|
||||
#define MAX_WRITE_ZEROES_DEFAULT 32768
|
||||
|
||||
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors)
|
||||
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
QEMUIOVector qiov;
|
||||
struct iovec iov;
|
||||
int ret;
|
||||
struct iovec iov = {0};
|
||||
int ret = 0;
|
||||
|
||||
/* TODO Emulate only part of misaligned requests instead of letting block
|
||||
* drivers return -ENOTSUP and emulate everything */
|
||||
int max_write_zeroes = bs->bl.max_write_zeroes ?
|
||||
bs->bl.max_write_zeroes : MAX_WRITE_ZEROES_DEFAULT;
|
||||
|
||||
/* First try the efficient write zeroes operation */
|
||||
if (drv->bdrv_co_write_zeroes) {
|
||||
ret = drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
|
||||
if (ret != -ENOTSUP) {
|
||||
return ret;
|
||||
while (nb_sectors > 0 && !ret) {
|
||||
int num = nb_sectors;
|
||||
|
||||
/* Align request. Block drivers can expect the "bulk" of the request
|
||||
* to be aligned.
|
||||
*/
|
||||
if (bs->bl.write_zeroes_alignment
|
||||
&& num > bs->bl.write_zeroes_alignment) {
|
||||
if (sector_num % bs->bl.write_zeroes_alignment != 0) {
|
||||
/* Make a small request up to the first aligned sector. */
|
||||
num = bs->bl.write_zeroes_alignment;
|
||||
num -= sector_num % bs->bl.write_zeroes_alignment;
|
||||
} else if ((sector_num + num) % bs->bl.write_zeroes_alignment != 0) {
|
||||
/* Shorten the request to the last aligned sector. num cannot
|
||||
* underflow because num > bs->bl.write_zeroes_alignment.
|
||||
*/
|
||||
num -= (sector_num + num) % bs->bl.write_zeroes_alignment;
|
||||
}
|
||||
}
|
||||
|
||||
/* limit request size */
|
||||
if (num > max_write_zeroes) {
|
||||
num = max_write_zeroes;
|
||||
}
|
||||
|
||||
ret = -ENOTSUP;
|
||||
/* First try the efficient write zeroes operation */
|
||||
if (drv->bdrv_co_write_zeroes) {
|
||||
ret = drv->bdrv_co_write_zeroes(bs, sector_num, num, flags);
|
||||
}
|
||||
|
||||
if (ret == -ENOTSUP) {
|
||||
/* Fall back to bounce buffer if write zeroes is unsupported */
|
||||
iov.iov_len = num * BDRV_SECTOR_SIZE;
|
||||
if (iov.iov_base == NULL) {
|
||||
iov.iov_base = qemu_blockalign(bs, num * BDRV_SECTOR_SIZE);
|
||||
memset(iov.iov_base, 0, num * BDRV_SECTOR_SIZE);
|
||||
}
|
||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
||||
|
||||
ret = drv->bdrv_co_writev(bs, sector_num, num, &qiov);
|
||||
|
||||
/* Keep bounce buffer around if it is big enough for all
|
||||
* all future requests.
|
||||
*/
|
||||
if (num < max_write_zeroes) {
|
||||
qemu_vfree(iov.iov_base);
|
||||
iov.iov_base = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
sector_num += num;
|
||||
nb_sectors -= num;
|
||||
}
|
||||
|
||||
/* Fall back to bounce buffer if write zeroes is unsupported */
|
||||
iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
|
||||
iov.iov_base = qemu_blockalign(bs, iov.iov_len);
|
||||
memset(iov.iov_base, 0, iov.iov_len);
|
||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
||||
|
||||
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, &qiov);
|
||||
|
||||
qemu_vfree(iov.iov_base);
|
||||
return ret;
|
||||
}
|
||||
@@ -2783,7 +2859,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
|
||||
if (ret < 0) {
|
||||
/* Do nothing, write notifier decided to fail this request */
|
||||
} else if (flags & BDRV_REQ_ZERO_WRITE) {
|
||||
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors);
|
||||
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors, flags);
|
||||
} else {
|
||||
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
|
||||
}
|
||||
@@ -2792,9 +2868,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
|
||||
ret = bdrv_co_flush(bs);
|
||||
}
|
||||
|
||||
if (bs->dirty_bitmap) {
|
||||
bdrv_set_dirty(bs, sector_num, nb_sectors);
|
||||
}
|
||||
bdrv_set_dirty(bs, sector_num, nb_sectors);
|
||||
|
||||
if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
|
||||
bs->wr_highest_sector = sector_num + nb_sectors - 1;
|
||||
@@ -2817,12 +2891,17 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
|
||||
int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors)
|
||||
int64_t sector_num, int nb_sectors,
|
||||
BdrvRequestFlags flags)
|
||||
{
|
||||
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
|
||||
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags);
|
||||
|
||||
if (!(bs->open_flags & BDRV_O_UNMAP)) {
|
||||
flags &= ~BDRV_REQ_MAY_UNMAP;
|
||||
}
|
||||
|
||||
return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
|
||||
BDRV_REQ_ZERO_WRITE);
|
||||
BDRV_REQ_ZERO_WRITE | flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3102,6 +3181,36 @@ int bdrv_has_zero_init(BlockDriverState *bs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs)
|
||||
{
|
||||
BlockDriverInfo bdi;
|
||||
|
||||
if (bs->backing_hd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bdrv_get_info(bs, &bdi) == 0) {
|
||||
return bdi.unallocated_blocks_are_zero;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs)
|
||||
{
|
||||
BlockDriverInfo bdi;
|
||||
|
||||
if (bs->backing_hd || !(bs->open_flags & BDRV_O_UNMAP)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bdrv_get_info(bs, &bdi) == 0) {
|
||||
return bdi.can_write_zeroes_with_unmap;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef struct BdrvCoGetBlockStatusData {
|
||||
BlockDriverState *bs;
|
||||
BlockDriverState *base;
|
||||
@@ -3171,8 +3280,8 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
|
||||
*pnum, pnum);
|
||||
}
|
||||
|
||||
if (!(ret & BDRV_BLOCK_DATA)) {
|
||||
if (bdrv_has_zero_init(bs)) {
|
||||
if (!(ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO)) {
|
||||
if (bdrv_unallocated_blocks_are_zero(bs)) {
|
||||
ret |= BDRV_BLOCK_ZERO;
|
||||
} else if (bs->backing_hd) {
|
||||
BlockDriverState *bs2 = bs->backing_hd;
|
||||
@@ -3330,7 +3439,7 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
if (bdrv_check_request(bs, sector_num, nb_sectors))
|
||||
return -EIO;
|
||||
|
||||
assert(!bs->dirty_bitmap);
|
||||
assert(QLIST_EMPTY(&bs->dirty_bitmaps));
|
||||
|
||||
return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
|
||||
}
|
||||
@@ -3419,6 +3528,19 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag)
|
||||
{
|
||||
while (bs && bs->drv && !bs->drv->bdrv_debug_remove_breakpoint) {
|
||||
bs = bs->file;
|
||||
}
|
||||
|
||||
if (bs && bs->drv && bs->drv->bdrv_debug_remove_breakpoint) {
|
||||
return bs->drv->bdrv_debug_remove_breakpoint(bs, tag);
|
||||
}
|
||||
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
int bdrv_debug_resume(BlockDriverState *bs, const char *tag)
|
||||
{
|
||||
while (bs && bs->drv && !bs->drv->bdrv_debug_resume) {
|
||||
@@ -3554,7 +3676,7 @@ BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
|
||||
{
|
||||
trace_bdrv_aio_readv(bs, sector_num, nb_sectors, opaque);
|
||||
|
||||
return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors,
|
||||
return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors, 0,
|
||||
cb, opaque, false);
|
||||
}
|
||||
|
||||
@@ -3564,7 +3686,18 @@ BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
{
|
||||
trace_bdrv_aio_writev(bs, sector_num, nb_sectors, opaque);
|
||||
|
||||
return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors,
|
||||
return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors, 0,
|
||||
cb, opaque, true);
|
||||
}
|
||||
|
||||
BlockDriverAIOCB *bdrv_aio_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags,
|
||||
BlockDriverCompletionFunc *cb, void *opaque)
|
||||
{
|
||||
trace_bdrv_aio_write_zeroes(bs, sector_num, nb_sectors, flags, opaque);
|
||||
|
||||
return bdrv_co_aio_rw_vector(bs, sector_num, NULL, nb_sectors,
|
||||
BDRV_REQ_ZERO_WRITE | flags,
|
||||
cb, opaque, true);
|
||||
}
|
||||
|
||||
@@ -3736,8 +3869,10 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)
|
||||
/* Run the aio requests. */
|
||||
mcb->num_requests = num_reqs;
|
||||
for (i = 0; i < num_reqs; i++) {
|
||||
bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov,
|
||||
reqs[i].nb_sectors, multiwrite_cb, mcb);
|
||||
bdrv_co_aio_rw_vector(bs, reqs[i].sector, reqs[i].qiov,
|
||||
reqs[i].nb_sectors, reqs[i].flags,
|
||||
multiwrite_cb, mcb,
|
||||
true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -3879,10 +4014,10 @@ static void coroutine_fn bdrv_co_do_rw(void *opaque)
|
||||
|
||||
if (!acb->is_write) {
|
||||
acb->req.error = bdrv_co_do_readv(bs, acb->req.sector,
|
||||
acb->req.nb_sectors, acb->req.qiov, 0);
|
||||
acb->req.nb_sectors, acb->req.qiov, acb->req.flags);
|
||||
} else {
|
||||
acb->req.error = bdrv_co_do_writev(bs, acb->req.sector,
|
||||
acb->req.nb_sectors, acb->req.qiov, 0);
|
||||
acb->req.nb_sectors, acb->req.qiov, acb->req.flags);
|
||||
}
|
||||
|
||||
acb->bh = qemu_bh_new(bdrv_co_em_bh, acb);
|
||||
@@ -3893,6 +4028,7 @@ static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
QEMUIOVector *qiov,
|
||||
int nb_sectors,
|
||||
BdrvRequestFlags flags,
|
||||
BlockDriverCompletionFunc *cb,
|
||||
void *opaque,
|
||||
bool is_write)
|
||||
@@ -3904,6 +4040,7 @@ static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
|
||||
acb->req.sector = sector_num;
|
||||
acb->req.nb_sectors = nb_sectors;
|
||||
acb->req.qiov = qiov;
|
||||
acb->req.flags = flags;
|
||||
acb->is_write = is_write;
|
||||
acb->done = NULL;
|
||||
|
||||
@@ -4179,9 +4316,16 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque)
|
||||
rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
|
||||
}
|
||||
|
||||
/* if no limit is specified in the BlockLimits use a default
|
||||
* of 32768 512-byte sectors (16 MiB) per request.
|
||||
*/
|
||||
#define MAX_DISCARD_DEFAULT 32768
|
||||
|
||||
int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors)
|
||||
{
|
||||
int max_discard;
|
||||
|
||||
if (!bs->drv) {
|
||||
return -ENOMEDIUM;
|
||||
} else if (bdrv_check_request(bs, sector_num, nb_sectors)) {
|
||||
@@ -4190,34 +4334,62 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
|
||||
return -EROFS;
|
||||
}
|
||||
|
||||
if (bs->dirty_bitmap) {
|
||||
bdrv_reset_dirty(bs, sector_num, nb_sectors);
|
||||
}
|
||||
bdrv_reset_dirty(bs, sector_num, nb_sectors);
|
||||
|
||||
/* Do nothing if disabled. */
|
||||
if (!(bs->open_flags & BDRV_O_UNMAP)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bs->drv->bdrv_co_discard) {
|
||||
return bs->drv->bdrv_co_discard(bs, sector_num, nb_sectors);
|
||||
} else if (bs->drv->bdrv_aio_discard) {
|
||||
BlockDriverAIOCB *acb;
|
||||
CoroutineIOCompletion co = {
|
||||
.coroutine = qemu_coroutine_self(),
|
||||
};
|
||||
|
||||
acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
|
||||
bdrv_co_io_em_complete, &co);
|
||||
if (acb == NULL) {
|
||||
return -EIO;
|
||||
} else {
|
||||
qemu_coroutine_yield();
|
||||
return co.ret;
|
||||
}
|
||||
} else {
|
||||
if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
max_discard = bs->bl.max_discard ? bs->bl.max_discard : MAX_DISCARD_DEFAULT;
|
||||
while (nb_sectors > 0) {
|
||||
int ret;
|
||||
int num = nb_sectors;
|
||||
|
||||
/* align request */
|
||||
if (bs->bl.discard_alignment &&
|
||||
num >= bs->bl.discard_alignment &&
|
||||
sector_num % bs->bl.discard_alignment) {
|
||||
if (num > bs->bl.discard_alignment) {
|
||||
num = bs->bl.discard_alignment;
|
||||
}
|
||||
num -= sector_num % bs->bl.discard_alignment;
|
||||
}
|
||||
|
||||
/* limit request size */
|
||||
if (num > max_discard) {
|
||||
num = max_discard;
|
||||
}
|
||||
|
||||
if (bs->drv->bdrv_co_discard) {
|
||||
ret = bs->drv->bdrv_co_discard(bs, sector_num, num);
|
||||
} else {
|
||||
BlockDriverAIOCB *acb;
|
||||
CoroutineIOCompletion co = {
|
||||
.coroutine = qemu_coroutine_self(),
|
||||
};
|
||||
|
||||
acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
|
||||
bdrv_co_io_em_complete, &co);
|
||||
if (acb == NULL) {
|
||||
return -EIO;
|
||||
} else {
|
||||
qemu_coroutine_yield();
|
||||
ret = co.ret;
|
||||
}
|
||||
}
|
||||
if (ret && ret != -ENOTSUP) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
sector_num += num;
|
||||
nb_sectors -= num;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
|
||||
@@ -4354,60 +4526,92 @@ bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov)
|
||||
return true;
|
||||
}
|
||||
|
||||
void bdrv_set_dirty_tracking(BlockDriverState *bs, int granularity)
|
||||
BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, int granularity)
|
||||
{
|
||||
int64_t bitmap_size;
|
||||
BdrvDirtyBitmap *bitmap;
|
||||
|
||||
assert((granularity & (granularity - 1)) == 0);
|
||||
|
||||
if (granularity) {
|
||||
granularity >>= BDRV_SECTOR_BITS;
|
||||
assert(!bs->dirty_bitmap);
|
||||
bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS);
|
||||
bs->dirty_bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
|
||||
} else {
|
||||
if (bs->dirty_bitmap) {
|
||||
hbitmap_free(bs->dirty_bitmap);
|
||||
bs->dirty_bitmap = NULL;
|
||||
granularity >>= BDRV_SECTOR_BITS;
|
||||
assert(granularity);
|
||||
bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS);
|
||||
bitmap = g_malloc0(sizeof(BdrvDirtyBitmap));
|
||||
bitmap->bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
|
||||
QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
|
||||
{
|
||||
BdrvDirtyBitmap *bm, *next;
|
||||
QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
|
||||
if (bm == bitmap) {
|
||||
QLIST_REMOVE(bitmap, list);
|
||||
hbitmap_free(bitmap->bitmap);
|
||||
g_free(bitmap);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int bdrv_get_dirty(BlockDriverState *bs, int64_t sector)
|
||||
BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)
|
||||
{
|
||||
if (bs->dirty_bitmap) {
|
||||
return hbitmap_get(bs->dirty_bitmap, sector);
|
||||
BdrvDirtyBitmap *bm;
|
||||
BlockDirtyInfoList *list = NULL;
|
||||
BlockDirtyInfoList **plist = &list;
|
||||
|
||||
QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) {
|
||||
BlockDirtyInfo *info = g_malloc0(sizeof(BlockDirtyInfo));
|
||||
BlockDirtyInfoList *entry = g_malloc0(sizeof(BlockDirtyInfoList));
|
||||
info->count = bdrv_get_dirty_count(bs, bm);
|
||||
info->granularity =
|
||||
((int64_t) BDRV_SECTOR_SIZE << hbitmap_granularity(bm->bitmap));
|
||||
entry->value = info;
|
||||
*plist = entry;
|
||||
plist = &entry->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector)
|
||||
{
|
||||
if (bitmap) {
|
||||
return hbitmap_get(bitmap->bitmap, sector);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void bdrv_dirty_iter_init(BlockDriverState *bs, HBitmapIter *hbi)
|
||||
void bdrv_dirty_iter_init(BlockDriverState *bs,
|
||||
BdrvDirtyBitmap *bitmap, HBitmapIter *hbi)
|
||||
{
|
||||
hbitmap_iter_init(hbi, bs->dirty_bitmap, 0);
|
||||
hbitmap_iter_init(hbi, bitmap->bitmap, 0);
|
||||
}
|
||||
|
||||
void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector,
|
||||
int nr_sectors)
|
||||
{
|
||||
hbitmap_set(bs->dirty_bitmap, cur_sector, nr_sectors);
|
||||
}
|
||||
|
||||
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
|
||||
int nr_sectors)
|
||||
{
|
||||
hbitmap_reset(bs->dirty_bitmap, cur_sector, nr_sectors);
|
||||
}
|
||||
|
||||
int64_t bdrv_get_dirty_count(BlockDriverState *bs)
|
||||
{
|
||||
if (bs->dirty_bitmap) {
|
||||
return hbitmap_count(bs->dirty_bitmap);
|
||||
} else {
|
||||
return 0;
|
||||
BdrvDirtyBitmap *bitmap;
|
||||
QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
|
||||
hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors);
|
||||
}
|
||||
}
|
||||
|
||||
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors)
|
||||
{
|
||||
BdrvDirtyBitmap *bitmap;
|
||||
QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
|
||||
hbitmap_reset(bitmap->bitmap, cur_sector, nr_sectors);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t bdrv_get_dirty_count(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
|
||||
{
|
||||
return hbitmap_count(bitmap->bitmap);
|
||||
}
|
||||
|
||||
/* Get a reference to bs */
|
||||
void bdrv_ref(BlockDriverState *bs)
|
||||
{
|
||||
@@ -4504,7 +4708,6 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
{
|
||||
QEMUOptionParameter *param = NULL, *create_options = NULL;
|
||||
QEMUOptionParameter *backing_fmt, *backing_file, *size;
|
||||
BlockDriverState *bs = NULL;
|
||||
BlockDriver *drv, *proto_drv;
|
||||
BlockDriver *backing_drv = NULL;
|
||||
Error *local_err = NULL;
|
||||
@@ -4583,6 +4786,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
size = get_option_parameter(param, BLOCK_OPT_SIZE);
|
||||
if (size && size->value.n == -1) {
|
||||
if (backing_file && backing_file->value.s) {
|
||||
BlockDriverState *bs;
|
||||
uint64_t size;
|
||||
char buf[32];
|
||||
int back_flags;
|
||||
@@ -4601,6 +4805,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
error_get_pretty(local_err));
|
||||
error_free(local_err);
|
||||
local_err = NULL;
|
||||
bdrv_unref(bs);
|
||||
goto out;
|
||||
}
|
||||
bdrv_get_geometry(bs, &size);
|
||||
@@ -4608,6 +4813,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
|
||||
snprintf(buf, sizeof(buf), "%" PRId64, size);
|
||||
set_option_parameter(param, BLOCK_OPT_SIZE, buf);
|
||||
|
||||
bdrv_unref(bs);
|
||||
} else {
|
||||
error_setg(errp, "Image creation needs a size parameter");
|
||||
goto out;
|
||||
@@ -4638,9 +4845,6 @@ out:
|
||||
free_option_parameters(create_options);
|
||||
free_option_parameters(param);
|
||||
|
||||
if (bs) {
|
||||
bdrv_unref(bs);
|
||||
}
|
||||
if (error_is_set(&local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,8 @@ static int coroutine_fn backup_do_cow(BlockDriverState *bs,
|
||||
|
||||
if (buffer_is_zero(iov.iov_base, iov.iov_len)) {
|
||||
ret = bdrv_co_write_zeroes(job->target,
|
||||
start * BACKUP_SECTORS_PER_CLUSTER, n);
|
||||
start * BACKUP_SECTORS_PER_CLUSTER,
|
||||
n, BDRV_REQ_MAY_UNMAP);
|
||||
} else {
|
||||
ret = bdrv_co_writev(job->target,
|
||||
start * BACKUP_SECTORS_PER_CLUSTER, n,
|
||||
|
||||
@@ -605,6 +605,31 @@ static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag)
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs,
|
||||
const char *tag)
|
||||
{
|
||||
BDRVBlkdebugState *s = bs->opaque;
|
||||
BlkdebugSuspendedReq *r;
|
||||
BlkdebugRule *rule, *next;
|
||||
int i, ret = -ENOENT;
|
||||
|
||||
for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
|
||||
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
|
||||
if (rule->action == ACTION_SUSPEND &&
|
||||
!strcmp(rule->options.suspend.tag, tag)) {
|
||||
remove_rule(rule);
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
QLIST_FOREACH(r, &s->suspended_reqs, next) {
|
||||
if (!strcmp(r->tag, tag)) {
|
||||
qemu_coroutine_enter(r->co, NULL);
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)
|
||||
{
|
||||
@@ -639,6 +664,8 @@ static BlockDriver bdrv_blkdebug = {
|
||||
|
||||
.bdrv_debug_event = blkdebug_debug_event,
|
||||
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
|
||||
.bdrv_debug_remove_breakpoint
|
||||
= blkdebug_debug_remove_breakpoint,
|
||||
.bdrv_debug_resume = blkdebug_debug_resume,
|
||||
.bdrv_debug_is_suspended = blkdebug_debug_is_suspended,
|
||||
};
|
||||
|
||||
124
block/cow.c
124
block/cow.c
@@ -103,40 +103,18 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX(hch): right now these functions are extremely inefficient.
|
||||
* We should just read the whole bitmap we'll need in one go instead.
|
||||
*/
|
||||
static inline int cow_set_bit(BlockDriverState *bs, int64_t bitnum, bool *first)
|
||||
static inline void cow_set_bits(uint8_t *bitmap, int start, int64_t nb_sectors)
|
||||
{
|
||||
uint64_t offset = sizeof(struct cow_header_v2) + bitnum / 8;
|
||||
uint8_t bitmap;
|
||||
int ret;
|
||||
|
||||
ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (bitmap & (1 << (bitnum % 8))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*first) {
|
||||
ret = bdrv_flush(bs->file);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
int64_t bitnum = start, last = start + nb_sectors;
|
||||
while (bitnum < last) {
|
||||
if ((bitnum & 7) == 0 && bitnum + 8 <= last) {
|
||||
bitmap[bitnum / 8] = 0xFF;
|
||||
bitnum += 8;
|
||||
continue;
|
||||
}
|
||||
*first = false;
|
||||
bitmap[bitnum/8] |= (1 << (bitnum % 8));
|
||||
bitnum++;
|
||||
}
|
||||
|
||||
bitmap |= (1 << (bitnum % 8));
|
||||
|
||||
ret = bdrv_pwrite(bs->file, offset, &bitmap, sizeof(bitmap));
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BITS_PER_BITMAP_SECTOR (512 * 8)
|
||||
@@ -174,18 +152,34 @@ static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs,
|
||||
{
|
||||
int64_t bitnum = sector_num + sizeof(struct cow_header_v2) * 8;
|
||||
uint64_t offset = (bitnum / 8) & -BDRV_SECTOR_SIZE;
|
||||
uint8_t bitmap[BDRV_SECTOR_SIZE];
|
||||
int ret;
|
||||
int changed;
|
||||
bool first = true;
|
||||
int changed = 0, same = 0;
|
||||
|
||||
ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
do {
|
||||
int ret;
|
||||
uint8_t bitmap[BDRV_SECTOR_SIZE];
|
||||
|
||||
bitnum &= BITS_PER_BITMAP_SECTOR - 1;
|
||||
changed = cow_test_bit(bitnum, bitmap);
|
||||
*num_same = cow_find_streak(bitmap, changed, bitnum, nb_sectors);
|
||||
bitnum &= BITS_PER_BITMAP_SECTOR - 1;
|
||||
int sector_bits = MIN(nb_sectors, BITS_PER_BITMAP_SECTOR - bitnum);
|
||||
|
||||
ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (first) {
|
||||
changed = cow_test_bit(bitnum, bitmap);
|
||||
first = false;
|
||||
}
|
||||
|
||||
same += cow_find_streak(bitmap, changed, bitnum, nb_sectors);
|
||||
|
||||
bitnum += sector_bits;
|
||||
nb_sectors -= sector_bits;
|
||||
offset += BDRV_SECTOR_SIZE;
|
||||
} while (nb_sectors);
|
||||
|
||||
*num_same = same;
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -204,18 +198,52 @@ static int64_t coroutine_fn cow_co_get_block_status(BlockDriverState *bs,
|
||||
static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors)
|
||||
{
|
||||
int error = 0;
|
||||
int i;
|
||||
int64_t bitnum = sector_num + sizeof(struct cow_header_v2) * 8;
|
||||
uint64_t offset = (bitnum / 8) & -BDRV_SECTOR_SIZE;
|
||||
bool first = true;
|
||||
int sector_bits;
|
||||
|
||||
for (i = 0; i < nb_sectors; i++) {
|
||||
error = cow_set_bit(bs, sector_num + i, &first);
|
||||
if (error) {
|
||||
break;
|
||||
for ( ; nb_sectors;
|
||||
bitnum += sector_bits,
|
||||
nb_sectors -= sector_bits,
|
||||
offset += BDRV_SECTOR_SIZE) {
|
||||
int ret, set;
|
||||
uint8_t bitmap[BDRV_SECTOR_SIZE];
|
||||
|
||||
bitnum &= BITS_PER_BITMAP_SECTOR - 1;
|
||||
sector_bits = MIN(nb_sectors, BITS_PER_BITMAP_SECTOR - bitnum);
|
||||
|
||||
ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Skip over any already set bits */
|
||||
set = cow_find_streak(bitmap, 1, bitnum, sector_bits);
|
||||
bitnum += set;
|
||||
sector_bits -= set;
|
||||
nb_sectors -= set;
|
||||
if (!sector_bits) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (first) {
|
||||
ret = bdrv_flush(bs->file);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
||||
cow_set_bits(bitmap, bitnum, sector_bits);
|
||||
|
||||
ret = bdrv_pwrite(bs->file, offset, &bitmap, sizeof(bitmap));
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
|
||||
187
block/iscsi.c
187
block/iscsi.c
@@ -2,6 +2,7 @@
|
||||
* QEMU Block driver for iSCSI images
|
||||
*
|
||||
* Copyright (c) 2010-2011 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
* Copyright (c) 2012-2013 Peter Lieven <pl@kamp.de>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -54,8 +55,10 @@ typedef struct IscsiLun {
|
||||
QEMUTimer *nop_timer;
|
||||
uint8_t lbpme;
|
||||
uint8_t lbprz;
|
||||
uint8_t has_write_same;
|
||||
struct scsi_inquiry_logical_block_provisioning lbp;
|
||||
struct scsi_inquiry_block_limits bl;
|
||||
unsigned char *zeroblock;
|
||||
} IscsiLun;
|
||||
|
||||
typedef struct IscsiTask {
|
||||
@@ -87,7 +90,6 @@ typedef struct IscsiAIOCB {
|
||||
#define NOP_INTERVAL 5000
|
||||
#define MAX_NOP_FAILURES 3
|
||||
#define ISCSI_CMD_RETRIES 5
|
||||
#define ISCSI_MAX_UNMAP 131072
|
||||
|
||||
static void
|
||||
iscsi_bh_cb(void *p)
|
||||
@@ -912,8 +914,6 @@ coroutine_fn iscsi_co_discard(BlockDriverState *bs, int64_t sector_num,
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
struct IscsiTask iTask;
|
||||
struct unmap_list list;
|
||||
uint32_t nb_blocks;
|
||||
uint32_t max_unmap;
|
||||
|
||||
if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
|
||||
return -EINVAL;
|
||||
@@ -925,57 +925,115 @@ coroutine_fn iscsi_co_discard(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
|
||||
list.lba = sector_qemu2lun(sector_num, iscsilun);
|
||||
nb_blocks = sector_qemu2lun(nb_sectors, iscsilun);
|
||||
list.num = sector_qemu2lun(nb_sectors, iscsilun);
|
||||
|
||||
max_unmap = iscsilun->bl.max_unmap;
|
||||
if (max_unmap == 0xffffffff) {
|
||||
max_unmap = ISCSI_MAX_UNMAP;
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
retry:
|
||||
if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1,
|
||||
iscsi_co_generic_cb, &iTask) == NULL) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
while (nb_blocks > 0) {
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
list.num = nb_blocks;
|
||||
if (list.num > max_unmap) {
|
||||
list.num = max_unmap;
|
||||
}
|
||||
retry:
|
||||
if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1,
|
||||
iscsi_co_generic_cb, &iTask) == NULL) {
|
||||
return -EIO;
|
||||
}
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
if (iTask.task != NULL) {
|
||||
scsi_free_scsi_task(iTask.task);
|
||||
iTask.task = NULL;
|
||||
}
|
||||
|
||||
if (iTask.task != NULL) {
|
||||
scsi_free_scsi_task(iTask.task);
|
||||
iTask.task = NULL;
|
||||
}
|
||||
if (iTask.do_retry) {
|
||||
goto retry;
|
||||
}
|
||||
|
||||
if (iTask.do_retry) {
|
||||
goto retry;
|
||||
}
|
||||
if (iTask.status == SCSI_STATUS_CHECK_CONDITION) {
|
||||
/* the target might fail with a check condition if it
|
||||
is not happy with the alignment of the UNMAP request
|
||||
we silently fail in this case */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (iTask.status == SCSI_STATUS_CHECK_CONDITION) {
|
||||
/* the target might fail with a check condition if it
|
||||
is not happy with the alignment of the UNMAP request
|
||||
we silently fail in this case */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
list.lba += list.num;
|
||||
nb_blocks -= list.num;
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED)
|
||||
|
||||
static int
|
||||
coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, BdrvRequestFlags flags)
|
||||
{
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
struct IscsiTask iTask;
|
||||
uint64_t lba;
|
||||
uint32_t nb_blocks;
|
||||
|
||||
if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!(flags & BDRV_REQ_MAY_UNMAP) && !iscsilun->has_write_same) {
|
||||
/* WRITE SAME without UNMAP is not supported by the target */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if ((flags & BDRV_REQ_MAY_UNMAP) && !iscsilun->lbp.lbpws) {
|
||||
/* WRITE SAME with UNMAP is not supported by the target */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
lba = sector_qemu2lun(sector_num, iscsilun);
|
||||
nb_blocks = sector_qemu2lun(nb_sectors, iscsilun);
|
||||
|
||||
if (iscsilun->zeroblock == NULL) {
|
||||
iscsilun->zeroblock = g_malloc0(iscsilun->block_size);
|
||||
}
|
||||
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
retry:
|
||||
if (iscsi_writesame16_task(iscsilun->iscsi, iscsilun->lun, lba,
|
||||
iscsilun->zeroblock, iscsilun->block_size,
|
||||
nb_blocks, 0, !!(flags & BDRV_REQ_MAY_UNMAP),
|
||||
0, 0, iscsi_co_generic_cb, &iTask) == NULL) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
while (!iTask.complete) {
|
||||
iscsi_set_events(iscsilun);
|
||||
qemu_coroutine_yield();
|
||||
}
|
||||
|
||||
if (iTask.task != NULL) {
|
||||
scsi_free_scsi_task(iTask.task);
|
||||
iTask.task = NULL;
|
||||
}
|
||||
|
||||
if (iTask.do_retry) {
|
||||
goto retry;
|
||||
}
|
||||
|
||||
if (iTask.status != SCSI_STATUS_GOOD) {
|
||||
if (iTask.status == SCSI_STATUS_CHECK_CONDITION &&
|
||||
iTask.task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST &&
|
||||
iTask.task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
/* WRITE SAME is not supported by the target */
|
||||
iscsilun->has_write_same = false;
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED */
|
||||
|
||||
static int parse_chap(struct iscsi_context *iscsi, const char *target)
|
||||
{
|
||||
QemuOptsList *list;
|
||||
@@ -1331,6 +1389,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
|
||||
iscsilun->type = inq->periperal_device_type;
|
||||
iscsilun->has_write_same = true;
|
||||
|
||||
if ((ret = iscsi_readcapacity_sync(iscsilun)) != 0) {
|
||||
goto out;
|
||||
@@ -1384,6 +1443,23 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
sizeof(struct scsi_inquiry_block_limits));
|
||||
scsi_free_scsi_task(task);
|
||||
task = NULL;
|
||||
|
||||
if (iscsilun->bl.max_unmap < 0xffffffff) {
|
||||
bs->bl.max_discard = sector_lun2qemu(iscsilun->bl.max_unmap,
|
||||
iscsilun);
|
||||
}
|
||||
bs->bl.discard_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran,
|
||||
iscsilun);
|
||||
|
||||
if (iscsilun->bl.max_ws_len < 0xffffffff) {
|
||||
bs->bl.max_write_zeroes = sector_lun2qemu(iscsilun->bl.max_ws_len,
|
||||
iscsilun);
|
||||
}
|
||||
bs->bl.write_zeroes_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran,
|
||||
iscsilun);
|
||||
|
||||
bs->bl.opt_transfer_length = sector_lun2qemu(iscsilun->bl.opt_xfer_len,
|
||||
iscsilun);
|
||||
}
|
||||
|
||||
#if defined(LIBISCSI_FEATURE_NOP_COUNTER)
|
||||
@@ -1424,6 +1500,7 @@ static void iscsi_close(BlockDriverState *bs)
|
||||
}
|
||||
qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), NULL, NULL, NULL);
|
||||
iscsi_destroy_context(iscsi);
|
||||
g_free(iscsilun->zeroblock);
|
||||
memset(iscsilun, 0, sizeof(IscsiLun));
|
||||
}
|
||||
|
||||
@@ -1447,11 +1524,6 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iscsi_has_zero_init(BlockDriverState *bs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iscsi_create(const char *filename, QEMUOptionParameter *options,
|
||||
Error **errp)
|
||||
{
|
||||
@@ -1506,6 +1578,21 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
{
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
bdi->unallocated_blocks_are_zero = !!iscsilun->lbprz;
|
||||
bdi->can_write_zeroes_with_unmap = iscsilun->lbprz && iscsilun->lbp.lbpws;
|
||||
/* Guess the internal cluster (page) size of the iscsi target by the means
|
||||
* of opt_unmap_gran. Transfer the unmap granularity only if it has a
|
||||
* reasonable size for bdi->cluster_size */
|
||||
if (iscsilun->bl.opt_unmap_gran * iscsilun->block_size >= 64 * 1024 &&
|
||||
iscsilun->bl.opt_unmap_gran * iscsilun->block_size <= 16 * 1024 * 1024) {
|
||||
bdi->cluster_size = iscsilun->bl.opt_unmap_gran * iscsilun->block_size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QEMUOptionParameter iscsi_create_options[] = {
|
||||
{
|
||||
.name = BLOCK_OPT_SIZE,
|
||||
@@ -1527,19 +1614,21 @@ static BlockDriver bdrv_iscsi = {
|
||||
.create_options = iscsi_create_options,
|
||||
|
||||
.bdrv_getlength = iscsi_getlength,
|
||||
.bdrv_get_info = iscsi_get_info,
|
||||
.bdrv_truncate = iscsi_truncate,
|
||||
|
||||
#if defined(LIBISCSI_FEATURE_IOVECTOR)
|
||||
.bdrv_co_get_block_status = iscsi_co_get_block_status,
|
||||
#endif
|
||||
.bdrv_co_discard = iscsi_co_discard,
|
||||
#if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED)
|
||||
.bdrv_co_write_zeroes = iscsi_co_write_zeroes,
|
||||
#endif
|
||||
|
||||
.bdrv_aio_readv = iscsi_aio_readv,
|
||||
.bdrv_aio_writev = iscsi_aio_writev,
|
||||
.bdrv_aio_flush = iscsi_aio_flush,
|
||||
|
||||
.bdrv_has_zero_init = iscsi_has_zero_init,
|
||||
|
||||
#ifdef __linux__
|
||||
.bdrv_ioctl = iscsi_ioctl,
|
||||
.bdrv_aio_ioctl = iscsi_aio_ioctl,
|
||||
|
||||
@@ -39,6 +39,7 @@ typedef struct MirrorBlockJob {
|
||||
int64_t granularity;
|
||||
size_t buf_size;
|
||||
unsigned long *cow_bitmap;
|
||||
BdrvDirtyBitmap *dirty_bitmap;
|
||||
HBitmapIter hbi;
|
||||
uint8_t *buf;
|
||||
QSIMPLEQ_HEAD(, MirrorBuffer) buf_free;
|
||||
@@ -145,9 +146,10 @@ static void coroutine_fn mirror_iteration(MirrorBlockJob *s)
|
||||
|
||||
s->sector_num = hbitmap_iter_next(&s->hbi);
|
||||
if (s->sector_num < 0) {
|
||||
bdrv_dirty_iter_init(source, &s->hbi);
|
||||
bdrv_dirty_iter_init(source, s->dirty_bitmap, &s->hbi);
|
||||
s->sector_num = hbitmap_iter_next(&s->hbi);
|
||||
trace_mirror_restart_iter(s, bdrv_get_dirty_count(source));
|
||||
trace_mirror_restart_iter(s,
|
||||
bdrv_get_dirty_count(source, s->dirty_bitmap));
|
||||
assert(s->sector_num >= 0);
|
||||
}
|
||||
|
||||
@@ -183,7 +185,7 @@ static void coroutine_fn mirror_iteration(MirrorBlockJob *s)
|
||||
do {
|
||||
int added_sectors, added_chunks;
|
||||
|
||||
if (!bdrv_get_dirty(source, next_sector) ||
|
||||
if (!bdrv_get_dirty(source, s->dirty_bitmap, next_sector) ||
|
||||
test_bit(next_chunk, s->in_flight_bitmap)) {
|
||||
assert(nb_sectors > 0);
|
||||
break;
|
||||
@@ -249,7 +251,8 @@ static void coroutine_fn mirror_iteration(MirrorBlockJob *s)
|
||||
/* Advance the HBitmapIter in parallel, so that we do not examine
|
||||
* the same sector twice.
|
||||
*/
|
||||
if (next_sector > hbitmap_next_sector && bdrv_get_dirty(source, next_sector)) {
|
||||
if (next_sector > hbitmap_next_sector
|
||||
&& bdrv_get_dirty(source, s->dirty_bitmap, next_sector)) {
|
||||
hbitmap_next_sector = hbitmap_iter_next(&s->hbi);
|
||||
}
|
||||
|
||||
@@ -355,7 +358,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
}
|
||||
}
|
||||
|
||||
bdrv_dirty_iter_init(bs, &s->hbi);
|
||||
bdrv_dirty_iter_init(bs, s->dirty_bitmap, &s->hbi);
|
||||
last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
||||
for (;;) {
|
||||
uint64_t delay_ns;
|
||||
@@ -367,7 +370,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
goto immediate_exit;
|
||||
}
|
||||
|
||||
cnt = bdrv_get_dirty_count(bs);
|
||||
cnt = bdrv_get_dirty_count(bs, s->dirty_bitmap);
|
||||
|
||||
/* Note that even when no rate limit is applied we need to yield
|
||||
* periodically with no pending I/O so that qemu_aio_flush() returns.
|
||||
@@ -409,7 +412,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
|
||||
should_complete = s->should_complete ||
|
||||
block_job_is_cancelled(&s->common);
|
||||
cnt = bdrv_get_dirty_count(bs);
|
||||
cnt = bdrv_get_dirty_count(bs, s->dirty_bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,7 +427,7 @@ static void coroutine_fn mirror_run(void *opaque)
|
||||
*/
|
||||
trace_mirror_before_drain(s, cnt);
|
||||
bdrv_drain_all();
|
||||
cnt = bdrv_get_dirty_count(bs);
|
||||
cnt = bdrv_get_dirty_count(bs, s->dirty_bitmap);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
@@ -471,7 +474,7 @@ immediate_exit:
|
||||
qemu_vfree(s->buf);
|
||||
g_free(s->cow_bitmap);
|
||||
g_free(s->in_flight_bitmap);
|
||||
bdrv_set_dirty_tracking(bs, 0);
|
||||
bdrv_release_dirty_bitmap(bs, s->dirty_bitmap);
|
||||
bdrv_iostatus_disable(s->target);
|
||||
if (s->should_complete && ret == 0) {
|
||||
if (bdrv_get_flags(s->target) != bdrv_get_flags(s->common.bs)) {
|
||||
@@ -575,7 +578,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
||||
s->granularity = granularity;
|
||||
s->buf_size = MAX(buf_size, granularity);
|
||||
|
||||
bdrv_set_dirty_tracking(bs, granularity);
|
||||
s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity);
|
||||
bdrv_set_enable_write_cache(s->target, true);
|
||||
bdrv_set_on_error(s->target, on_target_error, on_target_error);
|
||||
bdrv_iostatus_enable(s->target);
|
||||
|
||||
@@ -204,12 +204,9 @@ void bdrv_query_info(BlockDriverState *bs,
|
||||
info->io_status = bs->iostatus;
|
||||
}
|
||||
|
||||
if (bs->dirty_bitmap) {
|
||||
info->has_dirty = true;
|
||||
info->dirty = g_malloc0(sizeof(*info->dirty));
|
||||
info->dirty->count = bdrv_get_dirty_count(bs) * BDRV_SECTOR_SIZE;
|
||||
info->dirty->granularity =
|
||||
((int64_t) BDRV_SECTOR_SIZE << hbitmap_granularity(bs->dirty_bitmap));
|
||||
if (!QLIST_EMPTY(&bs->dirty_bitmaps)) {
|
||||
info->has_dirty_bitmaps = true;
|
||||
info->dirty_bitmaps = bdrv_query_dirty_bitmaps(bs);
|
||||
}
|
||||
|
||||
if (bs->drv) {
|
||||
|
||||
@@ -1401,7 +1401,7 @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
|
||||
|
||||
/* Round start up and end down */
|
||||
offset = align_offset(offset, s->cluster_size);
|
||||
end_offset &= ~(s->cluster_size - 1);
|
||||
end_offset = start_of_cluster(s, end_offset);
|
||||
|
||||
if (offset > end_offset) {
|
||||
return 0;
|
||||
@@ -1613,7 +1613,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
|
||||
}
|
||||
|
||||
ret = bdrv_write_zeroes(bs->file, offset / BDRV_SECTOR_SIZE,
|
||||
s->cluster_sectors);
|
||||
s->cluster_sectors, 0);
|
||||
if (ret < 0) {
|
||||
if (!preallocated) {
|
||||
qcow2_free_clusters(bs, offset, s->cluster_size,
|
||||
|
||||
@@ -515,8 +515,8 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
|
||||
s->l2_table_cache);
|
||||
}
|
||||
|
||||
start = offset & ~(s->cluster_size - 1);
|
||||
last = (offset + length - 1) & ~(s->cluster_size - 1);
|
||||
start = start_of_cluster(s, offset);
|
||||
last = start_of_cluster(s, offset + length - 1);
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
cluster_offset += s->cluster_size)
|
||||
{
|
||||
@@ -724,7 +724,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
|
||||
}
|
||||
redo:
|
||||
free_in_cluster = s->cluster_size -
|
||||
(s->free_byte_offset & (s->cluster_size - 1));
|
||||
offset_into_cluster(s, s->free_byte_offset);
|
||||
if (size <= free_in_cluster) {
|
||||
/* enough space in current cluster */
|
||||
offset = s->free_byte_offset;
|
||||
@@ -732,7 +732,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
|
||||
free_in_cluster -= size;
|
||||
if (free_in_cluster == 0)
|
||||
s->free_byte_offset = 0;
|
||||
if ((offset & (s->cluster_size - 1)) != 0)
|
||||
if (offset_into_cluster(s, offset) != 0)
|
||||
qcow2_update_cluster_refcount(bs, offset >> s->cluster_bits, 1,
|
||||
QCOW2_DISCARD_NEVER);
|
||||
} else {
|
||||
@@ -740,7 +740,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
|
||||
if (offset < 0) {
|
||||
return offset;
|
||||
}
|
||||
cluster_offset = s->free_byte_offset & ~(s->cluster_size - 1);
|
||||
cluster_offset = start_of_cluster(s, s->free_byte_offset);
|
||||
if ((cluster_offset + s->cluster_size) == offset) {
|
||||
/* we are lucky: contiguous data */
|
||||
offset = s->free_byte_offset;
|
||||
@@ -1010,8 +1010,8 @@ static void inc_refcounts(BlockDriverState *bs,
|
||||
if (size <= 0)
|
||||
return;
|
||||
|
||||
start = offset & ~(s->cluster_size - 1);
|
||||
last = (offset + size - 1) & ~(s->cluster_size - 1);
|
||||
start = start_of_cluster(s, offset);
|
||||
last = start_of_cluster(s, offset + size - 1);
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
cluster_offset += s->cluster_size) {
|
||||
k = cluster_offset >> s->cluster_bits;
|
||||
@@ -1122,7 +1122,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
offset, s->cluster_size);
|
||||
|
||||
/* Correct offsets are cluster aligned */
|
||||
if (offset & (s->cluster_size - 1)) {
|
||||
if (offset_into_cluster(s, offset)) {
|
||||
fprintf(stderr, "ERROR offset=%" PRIx64 ": Cluster is not "
|
||||
"properly aligned; L2 entry corrupted.\n", offset);
|
||||
res->corruptions++;
|
||||
@@ -1194,7 +1194,7 @@ static int check_refcounts_l1(BlockDriverState *bs,
|
||||
l2_offset, s->cluster_size);
|
||||
|
||||
/* L2 tables are cluster aligned */
|
||||
if (l2_offset & (s->cluster_size - 1)) {
|
||||
if (offset_into_cluster(s, l2_offset)) {
|
||||
fprintf(stderr, "ERROR l2_offset=%" PRIx64 ": Table is not "
|
||||
"cluster aligned; L1 entry corrupted\n", l2_offset);
|
||||
res->corruptions++;
|
||||
@@ -1423,7 +1423,7 @@ static int64_t realloc_refcount_block(BlockDriverState *bs, int reftable_index,
|
||||
}
|
||||
|
||||
/* update refcount table */
|
||||
assert(!(new_offset & (s->cluster_size - 1)));
|
||||
assert(!offset_into_cluster(s, new_offset));
|
||||
s->refcount_table[reftable_index] = new_offset;
|
||||
ret = write_reftable_entry(bs, reftable_index);
|
||||
if (ret < 0) {
|
||||
@@ -1507,7 +1507,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
cluster = offset >> s->cluster_bits;
|
||||
|
||||
/* Refcount blocks are cluster aligned */
|
||||
if (offset & (s->cluster_size - 1)) {
|
||||
if (offset_into_cluster(s, offset)) {
|
||||
fprintf(stderr, "ERROR refcount block %" PRId64 " is not "
|
||||
"cluster aligned; refcount table entry corrupted\n", i);
|
||||
res->corruptions++;
|
||||
|
||||
@@ -675,7 +675,10 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
|
||||
return s->nb_snapshots;
|
||||
}
|
||||
|
||||
int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name)
|
||||
int qcow2_snapshot_load_tmp(BlockDriverState *bs,
|
||||
const char *snapshot_id,
|
||||
const char *name,
|
||||
Error **errp)
|
||||
{
|
||||
int i, snapshot_index;
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@@ -687,8 +690,10 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name)
|
||||
assert(bs->read_only);
|
||||
|
||||
/* Search the snapshot */
|
||||
snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_name);
|
||||
snapshot_index = find_snapshot_by_id_and_name(bs, snapshot_id, name);
|
||||
if (snapshot_index < 0) {
|
||||
error_setg(errp,
|
||||
"Can't find snapshot");
|
||||
return -ENOENT;
|
||||
}
|
||||
sn = &s->snapshots[snapshot_index];
|
||||
@@ -699,6 +704,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name)
|
||||
|
||||
ret = bdrv_pread(bs->file, sn->l1_table_offset, new_l1_table, new_l1_bytes);
|
||||
if (ret < 0) {
|
||||
error_setg(errp, "Failed to read l1 table for snapshot");
|
||||
g_free(new_l1_table);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -718,6 +718,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
|
||||
qemu_opts_del(opts);
|
||||
bs->bl.write_zeroes_alignment = s->cluster_sectors;
|
||||
|
||||
if (s->use_lazy_refcounts && s->qcow_version < 3) {
|
||||
error_setg(errp, "Lazy refcounts require a qcow2 image with at least "
|
||||
@@ -1471,7 +1472,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
* size for any qcow2 image.
|
||||
*/
|
||||
BlockDriverState* bs;
|
||||
QCowHeader header;
|
||||
QCowHeader *header;
|
||||
uint8_t* refcount_table;
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
@@ -1489,30 +1490,34 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
}
|
||||
|
||||
/* Write the header */
|
||||
memset(&header, 0, sizeof(header));
|
||||
header.magic = cpu_to_be32(QCOW_MAGIC);
|
||||
header.version = cpu_to_be32(version);
|
||||
header.cluster_bits = cpu_to_be32(cluster_bits);
|
||||
header.size = cpu_to_be64(0);
|
||||
header.l1_table_offset = cpu_to_be64(0);
|
||||
header.l1_size = cpu_to_be32(0);
|
||||
header.refcount_table_offset = cpu_to_be64(cluster_size);
|
||||
header.refcount_table_clusters = cpu_to_be32(1);
|
||||
header.refcount_order = cpu_to_be32(3 + REFCOUNT_SHIFT);
|
||||
header.header_length = cpu_to_be32(sizeof(header));
|
||||
QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
|
||||
header = g_malloc0(cluster_size);
|
||||
*header = (QCowHeader) {
|
||||
.magic = cpu_to_be32(QCOW_MAGIC),
|
||||
.version = cpu_to_be32(version),
|
||||
.cluster_bits = cpu_to_be32(cluster_bits),
|
||||
.size = cpu_to_be64(0),
|
||||
.l1_table_offset = cpu_to_be64(0),
|
||||
.l1_size = cpu_to_be32(0),
|
||||
.refcount_table_offset = cpu_to_be64(cluster_size),
|
||||
.refcount_table_clusters = cpu_to_be32(1),
|
||||
.refcount_order = cpu_to_be32(3 + REFCOUNT_SHIFT),
|
||||
.header_length = cpu_to_be32(sizeof(*header)),
|
||||
};
|
||||
|
||||
if (flags & BLOCK_FLAG_ENCRYPT) {
|
||||
header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);
|
||||
header->crypt_method = cpu_to_be32(QCOW_CRYPT_AES);
|
||||
} else {
|
||||
header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
|
||||
header->crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
|
||||
}
|
||||
|
||||
if (flags & BLOCK_FLAG_LAZY_REFCOUNTS) {
|
||||
header.compatible_features |=
|
||||
header->compatible_features |=
|
||||
cpu_to_be64(QCOW2_COMPAT_LAZY_REFCOUNTS);
|
||||
}
|
||||
|
||||
ret = bdrv_pwrite(bs, 0, &header, sizeof(header));
|
||||
ret = bdrv_pwrite(bs, 0, header, cluster_size);
|
||||
g_free(header);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Could not write qcow2 header");
|
||||
goto out;
|
||||
@@ -1588,7 +1593,8 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
|
||||
/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
|
||||
ret = bdrv_open(bs, filename, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err);
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
|
||||
drv, &local_err);
|
||||
if (error_is_set(&local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
goto out;
|
||||
@@ -1696,7 +1702,7 @@ static int qcow2_make_empty(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors)
|
||||
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
|
||||
{
|
||||
int ret;
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@@ -1892,6 +1898,8 @@ static coroutine_fn int qcow2_co_flush_to_os(BlockDriverState *bs)
|
||||
static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
bdi->unallocated_blocks_are_zero = true;
|
||||
bdi->can_write_zeroes_with_unmap = (s->qcow_version >= 3);
|
||||
bdi->cluster_size = s->cluster_size;
|
||||
bdi->vm_state_offset = qcow2_vm_state_offset(s);
|
||||
return 0;
|
||||
|
||||
@@ -488,7 +488,10 @@ int qcow2_snapshot_delete(BlockDriverState *bs,
|
||||
const char *name,
|
||||
Error **errp);
|
||||
int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
|
||||
int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name);
|
||||
int qcow2_snapshot_load_tmp(BlockDriverState *bs,
|
||||
const char *snapshot_id,
|
||||
const char *name,
|
||||
Error **errp);
|
||||
|
||||
void qcow2_free_snapshots(BlockDriverState *bs);
|
||||
int qcow2_read_snapshots(BlockDriverState *bs);
|
||||
|
||||
@@ -495,6 +495,7 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
}
|
||||
|
||||
bs->bl.write_zeroes_alignment = s->header.cluster_size >> BDRV_SECTOR_BITS;
|
||||
s->need_check_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
|
||||
qed_need_check_timer_cb, s);
|
||||
|
||||
@@ -1397,7 +1398,8 @@ static void coroutine_fn qed_co_write_zeroes_cb(void *opaque, int ret)
|
||||
|
||||
static int coroutine_fn bdrv_qed_co_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
int nb_sectors)
|
||||
int nb_sectors,
|
||||
BdrvRequestFlags flags)
|
||||
{
|
||||
BlockDriverAIOCB *blockacb;
|
||||
BDRVQEDState *s = bs->opaque;
|
||||
@@ -1474,6 +1476,8 @@ static int bdrv_qed_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
memset(bdi, 0, sizeof(*bdi));
|
||||
bdi->cluster_size = s->header.cluster_size;
|
||||
bdi->is_dirty = s->header.features & QED_F_NEED_CHECK;
|
||||
bdi->unallocated_blocks_are_zero = true;
|
||||
bdi->can_write_zeroes_with_unmap = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
#define QEMU_AIO_IOCTL 0x0004
|
||||
#define QEMU_AIO_FLUSH 0x0008
|
||||
#define QEMU_AIO_DISCARD 0x0010
|
||||
#define QEMU_AIO_WRITE_ZEROES 0x0020
|
||||
#define QEMU_AIO_TYPE_MASK \
|
||||
(QEMU_AIO_READ|QEMU_AIO_WRITE|QEMU_AIO_IOCTL|QEMU_AIO_FLUSH| \
|
||||
QEMU_AIO_DISCARD)
|
||||
QEMU_AIO_DISCARD|QEMU_AIO_WRITE_ZEROES)
|
||||
|
||||
/* AIO flags */
|
||||
#define QEMU_AIO_MISALIGNED 0x1000
|
||||
|
||||
@@ -139,9 +139,11 @@ typedef struct BDRVRawState {
|
||||
void *aio_ctx;
|
||||
#endif
|
||||
#ifdef CONFIG_XFS
|
||||
bool is_xfs : 1;
|
||||
bool is_xfs:1;
|
||||
#endif
|
||||
bool has_discard : 1;
|
||||
bool has_discard:1;
|
||||
bool has_write_zeroes:1;
|
||||
bool discard_zeroes:1;
|
||||
} BDRVRawState;
|
||||
|
||||
typedef struct BDRVRawReopenState {
|
||||
@@ -283,6 +285,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
||||
Error *local_err = NULL;
|
||||
const char *filename;
|
||||
int fd, ret;
|
||||
struct stat st;
|
||||
|
||||
opts = qemu_opts_create_nofail(&raw_runtime_opts);
|
||||
qemu_opts_absorb_qdict(opts, options, &local_err);
|
||||
@@ -323,10 +326,38 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
||||
}
|
||||
#endif
|
||||
|
||||
s->has_discard = 1;
|
||||
s->has_discard = true;
|
||||
s->has_write_zeroes = true;
|
||||
|
||||
if (fstat(s->fd, &st) < 0) {
|
||||
error_setg_errno(errp, errno, "Could not stat file");
|
||||
goto fail;
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
s->discard_zeroes = true;
|
||||
}
|
||||
if (S_ISBLK(st.st_mode)) {
|
||||
#ifdef BLKDISCARDZEROES
|
||||
unsigned int arg;
|
||||
if (ioctl(s->fd, BLKDISCARDZEROES, &arg) == 0 && arg) {
|
||||
s->discard_zeroes = true;
|
||||
}
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
/* On Linux 3.10, BLKDISCARD leaves stale data in the page cache. Do
|
||||
* not rely on the contents of discarded blocks unless using O_DIRECT.
|
||||
* Same for BLKZEROOUT.
|
||||
*/
|
||||
if (!(bs->open_flags & BDRV_O_NOCACHE)) {
|
||||
s->discard_zeroes = false;
|
||||
s->has_write_zeroes = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_XFS
|
||||
if (platform_test_xfs_fd(s->fd)) {
|
||||
s->is_xfs = 1;
|
||||
s->is_xfs = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -675,6 +706,23 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_XFS
|
||||
static int xfs_write_zeroes(BDRVRawState *s, int64_t offset, uint64_t bytes)
|
||||
{
|
||||
struct xfs_flock64 fl;
|
||||
|
||||
memset(&fl, 0, sizeof(fl));
|
||||
fl.l_whence = SEEK_SET;
|
||||
fl.l_start = offset;
|
||||
fl.l_len = bytes;
|
||||
|
||||
if (xfsctl(NULL, s->fd, XFS_IOC_ZERO_RANGE, &fl) < 0) {
|
||||
DEBUG_BLOCK_PRINT("cannot write zero range (%s)\n", strerror(errno));
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xfs_discard(BDRVRawState *s, int64_t offset, uint64_t bytes)
|
||||
{
|
||||
struct xfs_flock64 fl;
|
||||
@@ -693,13 +741,49 @@ static int xfs_discard(BDRVRawState *s, int64_t offset, uint64_t bytes)
|
||||
}
|
||||
#endif
|
||||
|
||||
static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb)
|
||||
{
|
||||
int ret = -EOPNOTSUPP;
|
||||
BDRVRawState *s = aiocb->bs->opaque;
|
||||
|
||||
if (s->has_write_zeroes == 0) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
|
||||
#ifdef BLKZEROOUT
|
||||
do {
|
||||
uint64_t range[2] = { aiocb->aio_offset, aiocb->aio_nbytes };
|
||||
if (ioctl(aiocb->aio_fildes, BLKZEROOUT, range) == 0) {
|
||||
return 0;
|
||||
}
|
||||
} while (errno == EINTR);
|
||||
|
||||
ret = -errno;
|
||||
#endif
|
||||
} else {
|
||||
#ifdef CONFIG_XFS
|
||||
if (s->is_xfs) {
|
||||
return xfs_write_zeroes(s, aiocb->aio_offset, aiocb->aio_nbytes);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ret == -ENODEV || ret == -ENOSYS || ret == -EOPNOTSUPP ||
|
||||
ret == -ENOTTY) {
|
||||
s->has_write_zeroes = false;
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb)
|
||||
{
|
||||
int ret = -EOPNOTSUPP;
|
||||
BDRVRawState *s = aiocb->bs->opaque;
|
||||
|
||||
if (s->has_discard == 0) {
|
||||
return 0;
|
||||
if (!s->has_discard) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (aiocb->aio_type & QEMU_AIO_BLKDEV) {
|
||||
@@ -734,8 +818,8 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb)
|
||||
|
||||
if (ret == -ENODEV || ret == -ENOSYS || ret == -EOPNOTSUPP ||
|
||||
ret == -ENOTTY) {
|
||||
s->has_discard = 0;
|
||||
ret = 0;
|
||||
s->has_discard = false;
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -777,6 +861,9 @@ static int aio_worker(void *arg)
|
||||
case QEMU_AIO_DISCARD:
|
||||
ret = handle_aiocb_discard(aiocb);
|
||||
break;
|
||||
case QEMU_AIO_WRITE_ZEROES:
|
||||
ret = handle_aiocb_write_zeroes(aiocb);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type);
|
||||
ret = -EINVAL;
|
||||
@@ -787,6 +874,29 @@ static int aio_worker(void *arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int paio_submit_co(BlockDriverState *bs, int fd,
|
||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
||||
int type)
|
||||
{
|
||||
RawPosixAIOData *acb = g_slice_new(RawPosixAIOData);
|
||||
ThreadPool *pool;
|
||||
|
||||
acb->bs = bs;
|
||||
acb->aio_type = type;
|
||||
acb->aio_fildes = fd;
|
||||
|
||||
if (qiov) {
|
||||
acb->aio_iov = qiov->iov;
|
||||
acb->aio_niov = qiov->niov;
|
||||
}
|
||||
acb->aio_nbytes = nb_sectors * 512;
|
||||
acb->aio_offset = sector_num * 512;
|
||||
|
||||
trace_paio_submit_co(sector_num, nb_sectors, type);
|
||||
pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
|
||||
return thread_pool_submit_co(pool, aio_worker, acb);
|
||||
}
|
||||
|
||||
static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
|
||||
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
||||
BlockDriverCompletionFunc *cb, void *opaque, int type)
|
||||
@@ -1199,6 +1309,31 @@ static coroutine_fn BlockDriverAIOCB *raw_aio_discard(BlockDriverState *bs,
|
||||
cb, opaque, QEMU_AIO_DISCARD);
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_write_zeroes(
|
||||
BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, BdrvRequestFlags flags)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
|
||||
if (!(flags & BDRV_REQ_MAY_UNMAP)) {
|
||||
return paio_submit_co(bs, s->fd, sector_num, NULL, nb_sectors,
|
||||
QEMU_AIO_WRITE_ZEROES);
|
||||
} else if (s->discard_zeroes) {
|
||||
return paio_submit_co(bs, s->fd, sector_num, NULL, nb_sectors,
|
||||
QEMU_AIO_DISCARD);
|
||||
}
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
|
||||
bdi->unallocated_blocks_are_zero = s->discard_zeroes;
|
||||
bdi->can_write_zeroes_with_unmap = s->discard_zeroes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QEMUOptionParameter raw_create_options[] = {
|
||||
{
|
||||
.name = BLOCK_OPT_SIZE,
|
||||
@@ -1222,6 +1357,7 @@ static BlockDriver bdrv_file = {
|
||||
.bdrv_create = raw_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_co_get_block_status = raw_co_get_block_status,
|
||||
.bdrv_co_write_zeroes = raw_co_write_zeroes,
|
||||
|
||||
.bdrv_aio_readv = raw_aio_readv,
|
||||
.bdrv_aio_writev = raw_aio_writev,
|
||||
@@ -1230,6 +1366,7 @@ static BlockDriver bdrv_file = {
|
||||
|
||||
.bdrv_truncate = raw_truncate,
|
||||
.bdrv_getlength = raw_getlength,
|
||||
.bdrv_get_info = raw_get_info,
|
||||
.bdrv_get_allocated_file_size
|
||||
= raw_get_allocated_file_size,
|
||||
|
||||
@@ -1525,6 +1662,26 @@ static coroutine_fn BlockDriverAIOCB *hdev_aio_discard(BlockDriverState *bs,
|
||||
cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
|
||||
}
|
||||
|
||||
static coroutine_fn int hdev_co_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
int rc;
|
||||
|
||||
rc = fd_open(bs);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
if (!(flags & BDRV_REQ_MAY_UNMAP)) {
|
||||
return paio_submit_co(bs, s->fd, sector_num, NULL, nb_sectors,
|
||||
QEMU_AIO_WRITE_ZEROES|QEMU_AIO_BLKDEV);
|
||||
} else if (s->discard_zeroes) {
|
||||
return paio_submit_co(bs, s->fd, sector_num, NULL, nb_sectors,
|
||||
QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
|
||||
}
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int hdev_create(const char *filename, QEMUOptionParameter *options,
|
||||
Error **errp)
|
||||
{
|
||||
@@ -1577,6 +1734,7 @@ static BlockDriver bdrv_host_device = {
|
||||
.bdrv_reopen_abort = raw_reopen_abort,
|
||||
.bdrv_create = hdev_create,
|
||||
.create_options = raw_create_options,
|
||||
.bdrv_co_write_zeroes = hdev_co_write_zeroes,
|
||||
|
||||
.bdrv_aio_readv = raw_aio_readv,
|
||||
.bdrv_aio_writev = raw_aio_writev,
|
||||
@@ -1585,6 +1743,7 @@ static BlockDriver bdrv_host_device = {
|
||||
|
||||
.bdrv_truncate = raw_truncate,
|
||||
.bdrv_getlength = raw_getlength,
|
||||
.bdrv_get_info = raw_get_info,
|
||||
.bdrv_get_allocated_file_size
|
||||
= raw_get_allocated_file_size,
|
||||
|
||||
|
||||
@@ -68,9 +68,10 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors)
|
||||
int64_t sector_num, int nb_sectors,
|
||||
BdrvRequestFlags flags)
|
||||
{
|
||||
return bdrv_co_write_zeroes(bs->file, sector_num, nb_sectors);
|
||||
return bdrv_co_write_zeroes(bs->file, sector_num, nb_sectors, flags);
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_discard(BlockDriverState *bs,
|
||||
@@ -149,6 +150,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
bs->sg = bs->file->sg;
|
||||
bs->bl = bs->file->bl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
130
block/sheepdog.c
130
block/sheepdog.c
@@ -91,6 +91,14 @@
|
||||
#define SD_NR_VDIS (1U << 24)
|
||||
#define SD_DATA_OBJ_SIZE (UINT64_C(1) << 22)
|
||||
#define SD_MAX_VDI_SIZE (SD_DATA_OBJ_SIZE * MAX_DATA_OBJS)
|
||||
/*
|
||||
* For erasure coding, we use at most SD_EC_MAX_STRIP for data strips and
|
||||
* (SD_EC_MAX_STRIP - 1) for parity strips
|
||||
*
|
||||
* SD_MAX_COPIES is sum of number of data strips and parity strips.
|
||||
*/
|
||||
#define SD_EC_MAX_STRIP 16
|
||||
#define SD_MAX_COPIES (SD_EC_MAX_STRIP * 2 - 1)
|
||||
|
||||
#define SD_INODE_SIZE (sizeof(SheepdogInode))
|
||||
#define CURRENT_VDI_ID 0
|
||||
@@ -1464,9 +1472,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size,
|
||||
uint32_t base_vid, uint32_t *vdi_id, int snapshot,
|
||||
uint8_t copy_policy)
|
||||
static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot)
|
||||
{
|
||||
SheepdogVdiReq hdr;
|
||||
SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
|
||||
@@ -1483,11 +1489,11 @@ static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size,
|
||||
* does not fit in buf? For now, just truncate and avoid buffer overrun.
|
||||
*/
|
||||
memset(buf, 0, sizeof(buf));
|
||||
pstrcpy(buf, sizeof(buf), filename);
|
||||
pstrcpy(buf, sizeof(buf), s->name);
|
||||
|
||||
memset(&hdr, 0, sizeof(hdr));
|
||||
hdr.opcode = SD_OP_NEW_VDI;
|
||||
hdr.vdi_id = base_vid;
|
||||
hdr.vdi_id = s->inode.vdi_id;
|
||||
|
||||
wlen = SD_MAX_VDI_LEN;
|
||||
|
||||
@@ -1495,8 +1501,9 @@ static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size,
|
||||
hdr.snapid = snapshot;
|
||||
|
||||
hdr.data_length = wlen;
|
||||
hdr.vdi_size = vdi_size;
|
||||
hdr.copy_policy = copy_policy;
|
||||
hdr.vdi_size = s->inode.vdi_size;
|
||||
hdr.copy_policy = s->inode.copy_policy;
|
||||
hdr.copies = s->inode.nr_copies;
|
||||
|
||||
ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen);
|
||||
|
||||
@@ -1507,7 +1514,7 @@ static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size,
|
||||
}
|
||||
|
||||
if (rsp->result != SD_RES_SUCCESS) {
|
||||
error_report("%s, %s", sd_strerror(rsp->result), filename);
|
||||
error_report("%s, %s", sd_strerror(rsp->result), s->inode.name);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
@@ -1564,27 +1571,79 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sheepdog support two kinds of redundancy, full replication and erasure
|
||||
* coding.
|
||||
*
|
||||
* # create a fully replicated vdi with x copies
|
||||
* -o redundancy=x (1 <= x <= SD_MAX_COPIES)
|
||||
*
|
||||
* # create a erasure coded vdi with x data strips and y parity strips
|
||||
* -o redundancy=x:y (x must be one of {2,4,8,16} and 1 <= y < SD_EC_MAX_STRIP)
|
||||
*/
|
||||
static int parse_redundancy(BDRVSheepdogState *s, const char *opt)
|
||||
{
|
||||
struct SheepdogInode *inode = &s->inode;
|
||||
const char *n1, *n2;
|
||||
long copy, parity;
|
||||
char p[10];
|
||||
|
||||
pstrcpy(p, sizeof(p), opt);
|
||||
n1 = strtok(p, ":");
|
||||
n2 = strtok(NULL, ":");
|
||||
|
||||
if (!n1) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
copy = strtol(n1, NULL, 10);
|
||||
if (copy > SD_MAX_COPIES || copy < 1) {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!n2) {
|
||||
inode->copy_policy = 0;
|
||||
inode->nr_copies = copy;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (copy != 2 && copy != 4 && copy != 8 && copy != 16) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
parity = strtol(n2, NULL, 10);
|
||||
if (parity >= SD_EC_MAX_STRIP || parity < 1) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* 4 bits for parity and 4 bits for data.
|
||||
* We have to compress upper data bits because it can't represent 16
|
||||
*/
|
||||
inode->copy_policy = ((copy / 2) << 4) + parity;
|
||||
inode->nr_copies = copy + parity;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sd_create(const char *filename, QEMUOptionParameter *options,
|
||||
Error **errp)
|
||||
{
|
||||
int ret = 0;
|
||||
uint32_t vid = 0, base_vid = 0;
|
||||
int64_t vdi_size = 0;
|
||||
uint32_t vid = 0;
|
||||
char *backing_file = NULL;
|
||||
BDRVSheepdogState *s;
|
||||
char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];
|
||||
char tag[SD_MAX_VDI_TAG_LEN];
|
||||
uint32_t snapid;
|
||||
bool prealloc = false;
|
||||
Error *local_err = NULL;
|
||||
|
||||
s = g_malloc0(sizeof(BDRVSheepdogState));
|
||||
|
||||
memset(vdi, 0, sizeof(vdi));
|
||||
memset(tag, 0, sizeof(tag));
|
||||
if (strstr(filename, "://")) {
|
||||
ret = sd_parse_uri(s, filename, vdi, &snapid, tag);
|
||||
ret = sd_parse_uri(s, filename, s->name, &snapid, tag);
|
||||
} else {
|
||||
ret = parse_vdiname(s, filename, vdi, &snapid, tag);
|
||||
ret = parse_vdiname(s, filename, s->name, &snapid, tag);
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
@@ -1592,7 +1651,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
|
||||
|
||||
while (options && options->name) {
|
||||
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
|
||||
vdi_size = options->value.n;
|
||||
s->inode.vdi_size = options->value.n;
|
||||
} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
|
||||
backing_file = options->value.s;
|
||||
} else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
|
||||
@@ -1606,11 +1665,16 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
} else if (!strcmp(options->name, BLOCK_OPT_REDUNDANCY)) {
|
||||
ret = parse_redundancy(s, options->value.s);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
options++;
|
||||
}
|
||||
|
||||
if (vdi_size > SD_MAX_VDI_SIZE) {
|
||||
if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
|
||||
error_report("too big image size");
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
@@ -1645,12 +1709,10 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
|
||||
goto out;
|
||||
}
|
||||
|
||||
base_vid = s->inode.vdi_id;
|
||||
bdrv_unref(bs);
|
||||
}
|
||||
|
||||
/* TODO: allow users to specify copy number */
|
||||
ret = do_sd_create(s, vdi, vdi_size, base_vid, &vid, 0, 0);
|
||||
ret = do_sd_create(s, &vid, 0);
|
||||
if (!prealloc || ret) {
|
||||
goto out;
|
||||
}
|
||||
@@ -1833,8 +1895,7 @@ static int sd_create_branch(BDRVSheepdogState *s)
|
||||
* false bail out.
|
||||
*/
|
||||
deleted = sd_delete(s);
|
||||
ret = do_sd_create(s, s->name, s->inode.vdi_size, s->inode.vdi_id, &vid,
|
||||
!deleted, s->inode.copy_policy);
|
||||
ret = do_sd_create(s, &vid, !deleted);
|
||||
if (ret) {
|
||||
goto out;
|
||||
}
|
||||
@@ -2097,8 +2158,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = do_sd_create(s, s->name, s->inode.vdi_size, s->inode.vdi_id, &new_vid,
|
||||
1, s->inode.copy_policy);
|
||||
ret = do_sd_create(s, &new_vid, 1);
|
||||
if (ret < 0) {
|
||||
error_report("failed to create inode for snapshot. %s",
|
||||
strerror(errno));
|
||||
@@ -2407,6 +2467,22 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int64_t sd_get_allocated_file_size(BlockDriverState *bs)
|
||||
{
|
||||
BDRVSheepdogState *s = bs->opaque;
|
||||
SheepdogInode *inode = &s->inode;
|
||||
unsigned long i, last = DIV_ROUND_UP(inode->vdi_size, SD_DATA_OBJ_SIZE);
|
||||
uint64_t size = 0;
|
||||
|
||||
for (i = 0; i < last; i++) {
|
||||
if (inode->data_vdi_id[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
size += SD_DATA_OBJ_SIZE;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static QEMUOptionParameter sd_create_options[] = {
|
||||
{
|
||||
.name = BLOCK_OPT_SIZE,
|
||||
@@ -2423,6 +2499,11 @@ static QEMUOptionParameter sd_create_options[] = {
|
||||
.type = OPT_STRING,
|
||||
.help = "Preallocation mode (allowed values: off, full)"
|
||||
},
|
||||
{
|
||||
.name = BLOCK_OPT_REDUNDANCY,
|
||||
.type = OPT_STRING,
|
||||
.help = "Redundancy of the image"
|
||||
},
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@@ -2436,6 +2517,7 @@ static BlockDriver bdrv_sheepdog = {
|
||||
.bdrv_create = sd_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_getlength = sd_getlength,
|
||||
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
|
||||
.bdrv_truncate = sd_truncate,
|
||||
|
||||
.bdrv_co_readv = sd_co_readv,
|
||||
@@ -2465,6 +2547,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
|
||||
.bdrv_create = sd_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_getlength = sd_getlength,
|
||||
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
|
||||
.bdrv_truncate = sd_truncate,
|
||||
|
||||
.bdrv_co_readv = sd_co_readv,
|
||||
@@ -2494,6 +2577,7 @@ static BlockDriver bdrv_sheepdog_unix = {
|
||||
.bdrv_create = sd_create,
|
||||
.bdrv_has_zero_init = bdrv_has_zero_init_1,
|
||||
.bdrv_getlength = sd_getlength,
|
||||
.bdrv_get_allocated_file_size = sd_get_allocated_file_size,
|
||||
.bdrv_truncate = sd_truncate,
|
||||
|
||||
.bdrv_co_readv = sd_co_readv,
|
||||
|
||||
@@ -25,6 +25,24 @@
|
||||
#include "block/snapshot.h"
|
||||
#include "block/block_int.h"
|
||||
|
||||
QemuOptsList internal_snapshot_opts = {
|
||||
.name = "snapshot",
|
||||
.head = QTAILQ_HEAD_INITIALIZER(internal_snapshot_opts.head),
|
||||
.desc = {
|
||||
{
|
||||
.name = SNAPSHOT_OPT_ID,
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "snapshot id"
|
||||
},{
|
||||
.name = SNAPSHOT_OPT_NAME,
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "snapshot name"
|
||||
},{
|
||||
/* end of list */
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
|
||||
const char *name)
|
||||
{
|
||||
@@ -194,7 +212,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
|
||||
* If only @snapshot_id is specified, delete the first one with id
|
||||
* @snapshot_id.
|
||||
* If only @name is specified, delete the first one with name @name.
|
||||
* if none is specified, return -ENINVAL.
|
||||
* if none is specified, return -EINVAL.
|
||||
*
|
||||
* Returns: 0 on success, -errno on failure. If @bs is not inserted, return
|
||||
* -ENOMEDIUM. If @snapshot_id and @name are both NULL, return -EINVAL. If @bs
|
||||
@@ -265,18 +283,71 @@ int bdrv_snapshot_list(BlockDriverState *bs,
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily load an internal snapshot by @snapshot_id and @name.
|
||||
* @bs: block device used in the operation
|
||||
* @snapshot_id: unique snapshot ID, or NULL
|
||||
* @name: snapshot name, or NULL
|
||||
* @errp: location to store error
|
||||
*
|
||||
* If both @snapshot_id and @name are specified, load the first one with
|
||||
* id @snapshot_id and name @name.
|
||||
* If only @snapshot_id is specified, load the first one with id
|
||||
* @snapshot_id.
|
||||
* If only @name is specified, load the first one with name @name.
|
||||
* if none is specified, return -EINVAL.
|
||||
*
|
||||
* Returns: 0 on success, -errno on fail. If @bs is not inserted, return
|
||||
* -ENOMEDIUM. If @bs is not readonly, return -EINVAL. If @bs did not support
|
||||
* internal snapshot, return -ENOTSUP. If qemu can't find a matching @id and
|
||||
* @name, return -ENOENT. If @errp != NULL, it will always be filled on
|
||||
* failure.
|
||||
*/
|
||||
int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
||||
const char *snapshot_name)
|
||||
const char *snapshot_id,
|
||||
const char *name,
|
||||
Error **errp)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
|
||||
if (!drv) {
|
||||
error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, bdrv_get_device_name(bs));
|
||||
return -ENOMEDIUM;
|
||||
}
|
||||
if (!snapshot_id && !name) {
|
||||
error_setg(errp, "snapshot_id and name are both NULL");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!bs->read_only) {
|
||||
error_setg(errp, "Device is not readonly");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (drv->bdrv_snapshot_load_tmp) {
|
||||
return drv->bdrv_snapshot_load_tmp(bs, snapshot_name);
|
||||
return drv->bdrv_snapshot_load_tmp(bs, snapshot_id, name, errp);
|
||||
}
|
||||
error_set(errp, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
|
||||
drv->format_name, bdrv_get_device_name(bs),
|
||||
"temporarily load internal snapshot");
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
|
||||
const char *id_or_name,
|
||||
Error **errp)
|
||||
{
|
||||
int ret;
|
||||
Error *local_err = NULL;
|
||||
|
||||
ret = bdrv_snapshot_load_tmp(bs, id_or_name, NULL, &local_err);
|
||||
if (ret == -ENOENT || ret == -EINVAL) {
|
||||
error_free(local_err);
|
||||
local_err = NULL;
|
||||
ret = bdrv_snapshot_load_tmp(bs, NULL, id_or_name, &local_err);
|
||||
}
|
||||
|
||||
if (error_is_set(&local_err)) {
|
||||
error_propagate(errp, local_err);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,11 @@ static void coroutine_fn stream_run(void *opaque)
|
||||
int n = 0;
|
||||
void *buf;
|
||||
|
||||
if (!bs->backing_hd) {
|
||||
block_job_completed(&s->common, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
s->common.len = bdrv_getlength(bs);
|
||||
if (s->common.len < 0) {
|
||||
block_job_completed(&s->common, s->common.len);
|
||||
|
||||
@@ -331,6 +331,7 @@ static int vdi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
logout("\n");
|
||||
bdi->cluster_size = s->block_size;
|
||||
bdi->vm_state_offset = 0;
|
||||
bdi->unallocated_blocks_are_zero = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
13
block/vhdx.c
13
block/vhdx.c
@@ -1043,6 +1043,18 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num,
|
||||
}
|
||||
|
||||
|
||||
static int vhdx_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
{
|
||||
BDRVVHDXState *s = bs->opaque;
|
||||
|
||||
bdi->cluster_size = s->block_size;
|
||||
|
||||
bdi->unallocated_blocks_are_zero =
|
||||
(s->params.data_bits & VHDX_PARAMS_HAS_PARENT) == 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static coroutine_fn int vhdx_co_readv(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov)
|
||||
@@ -1885,6 +1897,7 @@ static BlockDriver bdrv_vhdx = {
|
||||
.bdrv_co_readv = vhdx_co_readv,
|
||||
.bdrv_co_writev = vhdx_co_writev,
|
||||
.bdrv_create = vhdx_create,
|
||||
.bdrv_get_info = vhdx_get_info,
|
||||
|
||||
.create_options = vhdx_create_options,
|
||||
};
|
||||
|
||||
80
block/vmdk.c
80
block/vmdk.c
@@ -428,6 +428,10 @@ static int vmdk_add_extent(BlockDriverState *bs,
|
||||
extent->l2_size = l2_size;
|
||||
extent->cluster_sectors = flat ? sectors : cluster_sectors;
|
||||
|
||||
if (!flat) {
|
||||
bs->bl.write_zeroes_alignment =
|
||||
MAX(bs->bl.write_zeroes_alignment, cluster_sectors);
|
||||
}
|
||||
if (s->num_extents > 1) {
|
||||
extent->end_sector = (*(extent - 1)).end_sector + extent->sectors;
|
||||
} else {
|
||||
@@ -605,13 +609,20 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
|
||||
header = footer.header;
|
||||
}
|
||||
|
||||
if (le32_to_cpu(header.version) >= 3) {
|
||||
if (le32_to_cpu(header.version) > 3) {
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "VMDK version %d",
|
||||
le32_to_cpu(header.version));
|
||||
qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
|
||||
bs->device_name, "vmdk", buf);
|
||||
return -ENOTSUP;
|
||||
} else if (le32_to_cpu(header.version) == 3 && (flags & BDRV_O_RDWR)) {
|
||||
/* VMware KB 2064959 explains that version 3 added support for
|
||||
* persistent changed block tracking (CBT), and backup software can
|
||||
* read it as version=1 if it doesn't care about the changed area
|
||||
* information. So we are safe to enable read only. */
|
||||
error_setg(errp, "VMDK version 3 must be read only");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (le32_to_cpu(header.num_gtes_per_gt) > 512) {
|
||||
@@ -1419,7 +1430,8 @@ static coroutine_fn int vmdk_co_write(BlockDriverState *bs, int64_t sector_num,
|
||||
|
||||
static int coroutine_fn vmdk_co_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
int nb_sectors)
|
||||
int nb_sectors,
|
||||
BdrvRequestFlags flags)
|
||||
{
|
||||
int ret;
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
@@ -1588,7 +1600,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
Error **errp)
|
||||
{
|
||||
int fd, idx = 0;
|
||||
char desc[BUF_SIZE];
|
||||
char *desc = NULL;
|
||||
int64_t total_size = 0, filesize;
|
||||
const char *adapter_type = NULL;
|
||||
const char *backing_file = NULL;
|
||||
@@ -1596,7 +1608,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
int flags = 0;
|
||||
int ret = 0;
|
||||
bool flat, split, compress;
|
||||
char ext_desc_lines[BUF_SIZE] = "";
|
||||
GString *ext_desc_lines;
|
||||
char path[PATH_MAX], prefix[PATH_MAX], postfix[PATH_MAX];
|
||||
const int64_t split_size = 0x80000000; /* VMDK has constant split size */
|
||||
const char *desc_extent_line;
|
||||
@@ -1624,8 +1636,11 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
"ddb.geometry.sectors = \"63\"\n"
|
||||
"ddb.adapterType = \"%s\"\n";
|
||||
|
||||
ext_desc_lines = g_string_new(NULL);
|
||||
|
||||
if (filename_decompose(filename, path, prefix, postfix, PATH_MAX, errp)) {
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
/* Read out options */
|
||||
while (options && options->name) {
|
||||
@@ -1651,7 +1666,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
strcmp(adapter_type, "lsilogic") &&
|
||||
strcmp(adapter_type, "legacyESX")) {
|
||||
error_setg(errp, "Unknown adapter type: '%s'", adapter_type);
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
if (strcmp(adapter_type, "ide") != 0) {
|
||||
/* that's the number of heads with which vmware operates when
|
||||
@@ -1667,7 +1683,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
strcmp(fmt, "twoGbMaxExtentFlat") &&
|
||||
strcmp(fmt, "streamOptimized")) {
|
||||
error_setg(errp, "Unknown subformat: '%s'", fmt);
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
split = !(strcmp(fmt, "twoGbMaxExtentFlat") &&
|
||||
strcmp(fmt, "twoGbMaxExtentSparse"));
|
||||
@@ -1681,22 +1698,25 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
}
|
||||
if (flat && backing_file) {
|
||||
error_setg(errp, "Flat image can't have backing file");
|
||||
return -ENOTSUP;
|
||||
ret = -ENOTSUP;
|
||||
goto exit;
|
||||
}
|
||||
if (flat && zeroed_grain) {
|
||||
error_setg(errp, "Flat image can't enable zeroed grain");
|
||||
return -ENOTSUP;
|
||||
ret = -ENOTSUP;
|
||||
goto exit;
|
||||
}
|
||||
if (backing_file) {
|
||||
BlockDriverState *bs = bdrv_new("");
|
||||
ret = bdrv_open(bs, backing_file, NULL, 0, NULL, errp);
|
||||
ret = bdrv_open(bs, backing_file, NULL, BDRV_O_NO_BACKING, NULL, errp);
|
||||
if (ret != 0) {
|
||||
bdrv_unref(bs);
|
||||
return ret;
|
||||
goto exit;
|
||||
}
|
||||
if (strcmp(bs->drv->format_name, "vmdk")) {
|
||||
bdrv_unref(bs);
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
parent_cid = vmdk_read_cid(bs, 0);
|
||||
bdrv_unref(bs);
|
||||
@@ -1730,25 +1750,27 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
|
||||
if (vmdk_create_extent(ext_filename, size,
|
||||
flat, compress, zeroed_grain)) {
|
||||
return -EINVAL;
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
filesize -= size;
|
||||
|
||||
/* Format description line */
|
||||
snprintf(desc_line, sizeof(desc_line),
|
||||
desc_extent_line, size / 512, desc_filename);
|
||||
pstrcat(ext_desc_lines, sizeof(ext_desc_lines), desc_line);
|
||||
g_string_append(ext_desc_lines, desc_line);
|
||||
}
|
||||
/* generate descriptor file */
|
||||
snprintf(desc, sizeof(desc), desc_template,
|
||||
(unsigned int)time(NULL),
|
||||
parent_cid,
|
||||
fmt,
|
||||
parent_desc_line,
|
||||
ext_desc_lines,
|
||||
(flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
|
||||
total_size / (int64_t)(63 * number_heads * 512), number_heads,
|
||||
adapter_type);
|
||||
desc = g_strdup_printf(desc_template,
|
||||
(unsigned int)time(NULL),
|
||||
parent_cid,
|
||||
fmt,
|
||||
parent_desc_line,
|
||||
ext_desc_lines->str,
|
||||
(flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
|
||||
total_size / (int64_t)(63 * number_heads * 512),
|
||||
number_heads,
|
||||
adapter_type);
|
||||
if (split || flat) {
|
||||
fd = qemu_open(filename,
|
||||
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
|
||||
@@ -1759,21 +1781,25 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
||||
0644);
|
||||
}
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
ret = -errno;
|
||||
goto exit;
|
||||
}
|
||||
/* the descriptor offset = 0x200 */
|
||||
if (!split && !flat && 0x200 != lseek(fd, 0x200, SEEK_SET)) {
|
||||
ret = -errno;
|
||||
goto exit;
|
||||
goto close_exit;
|
||||
}
|
||||
ret = qemu_write_full(fd, desc, strlen(desc));
|
||||
if (ret != strlen(desc)) {
|
||||
ret = -errno;
|
||||
goto exit;
|
||||
goto close_exit;
|
||||
}
|
||||
ret = 0;
|
||||
exit:
|
||||
close_exit:
|
||||
qemu_close(fd);
|
||||
exit:
|
||||
g_free(desc);
|
||||
g_string_free(ext_desc_lines, true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
15
block/vpc.c
15
block/vpc.c
@@ -455,6 +455,19 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int vpc_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
{
|
||||
BDRVVPCState *s = (BDRVVPCState *)bs->opaque;
|
||||
VHDFooter *footer = (VHDFooter *) s->footer_buf;
|
||||
|
||||
if (cpu_to_be32(footer->type) != VHD_FIXED) {
|
||||
bdi->cluster_size = s->block_size;
|
||||
}
|
||||
|
||||
bdi->unallocated_blocks_are_zero = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vpc_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
@@ -857,6 +870,8 @@ static BlockDriver bdrv_vpc = {
|
||||
.bdrv_read = vpc_co_read,
|
||||
.bdrv_write = vpc_co_write,
|
||||
|
||||
.bdrv_get_info = vpc_get_info,
|
||||
|
||||
.create_options = vpc_create_options,
|
||||
.bdrv_has_zero_init = vpc_has_zero_init,
|
||||
};
|
||||
|
||||
59
exec.c
59
exec.c
@@ -904,6 +904,13 @@ static long gethugepagesize(const char *path)
|
||||
return fs.f_bsize;
|
||||
}
|
||||
|
||||
static sigjmp_buf sigjump;
|
||||
|
||||
static void sigbus_handler(int signal)
|
||||
{
|
||||
siglongjmp(sigjump, 1);
|
||||
}
|
||||
|
||||
static void *file_ram_alloc(RAMBlock *block,
|
||||
ram_addr_t memory,
|
||||
const char *path)
|
||||
@@ -913,9 +920,6 @@ static void *file_ram_alloc(RAMBlock *block,
|
||||
char *c;
|
||||
void *area;
|
||||
int fd;
|
||||
#ifdef MAP_POPULATE
|
||||
int flags;
|
||||
#endif
|
||||
unsigned long hpagesize;
|
||||
|
||||
hpagesize = gethugepagesize(path);
|
||||
@@ -963,21 +967,52 @@ static void *file_ram_alloc(RAMBlock *block,
|
||||
if (ftruncate(fd, memory))
|
||||
perror("ftruncate");
|
||||
|
||||
#ifdef MAP_POPULATE
|
||||
/* NB: MAP_POPULATE won't exhaustively alloc all phys pages in the case
|
||||
* MAP_PRIVATE is requested. For mem_prealloc we mmap as MAP_SHARED
|
||||
* to sidestep this quirk.
|
||||
*/
|
||||
flags = mem_prealloc ? MAP_POPULATE | MAP_SHARED : MAP_PRIVATE;
|
||||
area = mmap(0, memory, PROT_READ | PROT_WRITE, flags, fd, 0);
|
||||
#else
|
||||
area = mmap(0, memory, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
#endif
|
||||
if (area == MAP_FAILED) {
|
||||
perror("file_ram_alloc: can't mmap RAM pages");
|
||||
close(fd);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (mem_prealloc) {
|
||||
int ret, i;
|
||||
struct sigaction act, oldact;
|
||||
sigset_t set, oldset;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = &sigbus_handler;
|
||||
act.sa_flags = 0;
|
||||
|
||||
ret = sigaction(SIGBUS, &act, &oldact);
|
||||
if (ret) {
|
||||
perror("file_ram_alloc: failed to install signal handler");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* unblock SIGBUS */
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGBUS);
|
||||
pthread_sigmask(SIG_UNBLOCK, &set, &oldset);
|
||||
|
||||
if (sigsetjmp(sigjump, 1)) {
|
||||
fprintf(stderr, "file_ram_alloc: failed to preallocate pages\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* MAP_POPULATE silently ignores failures */
|
||||
for (i = 0; i < (memory/hpagesize)-1; i++) {
|
||||
memset(area + (hpagesize*i), 0, 1);
|
||||
}
|
||||
|
||||
ret = sigaction(SIGBUS, &oldact, NULL);
|
||||
if (ret) {
|
||||
perror("file_ram_alloc: failed to reinstall signal handler");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
||||
}
|
||||
|
||||
block->fd = fd;
|
||||
return area;
|
||||
}
|
||||
|
||||
@@ -347,8 +347,8 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
|
||||
s->samples = AUD_get_buffer_size_out (s->voice) >> SHIFT;
|
||||
s->mixbuf = g_malloc0 (s->samples << SHIFT);
|
||||
|
||||
adlib_portio_list[1].offset = s->port;
|
||||
adlib_portio_list[2].offset = s->port + 8;
|
||||
adlib_portio_list[0].offset = s->port;
|
||||
adlib_portio_list[1].offset = s->port + 8;
|
||||
portio_list_init (port_list, OBJECT(s), adlib_portio_list, s, "adlib");
|
||||
portio_list_add (port_list, isa_address_space_io(&s->parent_obj), 0);
|
||||
}
|
||||
|
||||
@@ -444,6 +444,7 @@ static bool intel_hda_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
|
||||
}
|
||||
}
|
||||
if (d->dp_lbase & 0x01) {
|
||||
s = st - d->st;
|
||||
addr = intel_hda_addr(d->dp_lbase & ~0x01, d->dp_ubase);
|
||||
stl_le_pci_dma(&d->pci, addr + 8*s, st->lpib);
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ typedef struct {
|
||||
uint64_t char_tx_time;
|
||||
CharDriverState *chr;
|
||||
qemu_irq irq;
|
||||
struct QEMUTimer *fifo_trigger_handle;
|
||||
struct QEMUTimer *tx_time_handle;
|
||||
QEMUTimer *fifo_trigger_handle;
|
||||
QEMUTimer *tx_time_handle;
|
||||
} UartState;
|
||||
|
||||
static void uart_update_status(UartState *s)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
#include "hw/hw.h"
|
||||
#include "hw/loader.h"
|
||||
#include "trace.h"
|
||||
#include "ui/console.h"
|
||||
#include "hw/pci/pci.h"
|
||||
|
||||
|
||||
@@ -285,7 +285,8 @@ static inline void build_append_array(GArray *array, GArray *val)
|
||||
g_array_append_vals(array, val->data, val->len);
|
||||
}
|
||||
|
||||
static void build_append_nameseg(GArray *array, const char *format, ...)
|
||||
static void GCC_FMT_ATTR(2, 3)
|
||||
build_append_nameseg(GArray *array, const char *format, ...)
|
||||
{
|
||||
/* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
|
||||
char s[] = "XXXX";
|
||||
@@ -630,7 +631,7 @@ build_append_notify(GArray *device, const char *name,
|
||||
GArray *method = build_alloc_array();
|
||||
uint8_t op = 0x14; /* MethodOp */
|
||||
|
||||
build_append_nameseg(method, name);
|
||||
build_append_nameseg(method, "%s", name);
|
||||
build_append_byte(method, 0x02); /* MethodFlags: ArgCount */
|
||||
for (i = skip; i < count; i++) {
|
||||
GArray *target = build_alloc_array();
|
||||
|
||||
@@ -339,15 +339,26 @@ static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
|
||||
.desc = "Standard PC (i440FX + PIIX, 1996)", \
|
||||
.hot_add_cpu = pc_hot_add_cpu
|
||||
|
||||
#define PC_I440FX_1_7_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS
|
||||
static QEMUMachine pc_i440fx_machine_v1_7 = {
|
||||
PC_I440FX_1_7_MACHINE_OPTIONS,
|
||||
.name = "pc-i440fx-1.7",
|
||||
#define PC_I440FX_2_0_MACHINE_OPTIONS \
|
||||
PC_I440FX_MACHINE_OPTIONS, \
|
||||
.default_machine_opts = "firmware=bios-256k.bin"
|
||||
|
||||
static QEMUMachine pc_i440fx_machine_v2_0 = {
|
||||
PC_I440FX_2_0_MACHINE_OPTIONS,
|
||||
.name = "pc-i440fx-2.0",
|
||||
.alias = "pc",
|
||||
.init = pc_init_pci,
|
||||
.is_default = 1,
|
||||
};
|
||||
|
||||
#define PC_I440FX_1_7_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS
|
||||
|
||||
static QEMUMachine pc_i440fx_machine_v1_7 = {
|
||||
PC_I440FX_1_7_MACHINE_OPTIONS,
|
||||
.name = "pc-i440fx-1.7",
|
||||
.init = pc_init_pci,
|
||||
};
|
||||
|
||||
#define PC_I440FX_1_6_MACHINE_OPTIONS PC_I440FX_MACHINE_OPTIONS
|
||||
|
||||
static QEMUMachine pc_i440fx_machine_v1_6 = {
|
||||
@@ -747,6 +758,7 @@ static QEMUMachine xenfv_machine = {
|
||||
|
||||
static void pc_machine_init(void)
|
||||
{
|
||||
qemu_register_machine(&pc_i440fx_machine_v2_0);
|
||||
qemu_register_machine(&pc_i440fx_machine_v1_7);
|
||||
qemu_register_machine(&pc_i440fx_machine_v1_6);
|
||||
qemu_register_machine(&pc_i440fx_machine_v1_5);
|
||||
|
||||
@@ -259,12 +259,22 @@ static void pc_q35_init_1_4(QEMUMachineInitArgs *args)
|
||||
.desc = "Standard PC (Q35 + ICH9, 2009)", \
|
||||
.hot_add_cpu = pc_hot_add_cpu
|
||||
|
||||
#define PC_Q35_2_0_MACHINE_OPTIONS \
|
||||
PC_Q35_MACHINE_OPTIONS, \
|
||||
.default_machine_opts = "firmware=bios-256k.bin"
|
||||
|
||||
static QEMUMachine pc_q35_machine_v2_0 = {
|
||||
PC_Q35_2_0_MACHINE_OPTIONS,
|
||||
.name = "pc-q35-2.0",
|
||||
.alias = "q35",
|
||||
.init = pc_q35_init,
|
||||
};
|
||||
|
||||
#define PC_Q35_1_7_MACHINE_OPTIONS PC_Q35_MACHINE_OPTIONS
|
||||
|
||||
static QEMUMachine pc_q35_machine_v1_7 = {
|
||||
PC_Q35_1_7_MACHINE_OPTIONS,
|
||||
.name = "pc-q35-1.7",
|
||||
.alias = "q35",
|
||||
.init = pc_q35_init,
|
||||
};
|
||||
|
||||
@@ -306,6 +316,7 @@ static QEMUMachine pc_q35_machine_v1_4 = {
|
||||
|
||||
static void pc_q35_machine_init(void)
|
||||
{
|
||||
qemu_register_machine(&pc_q35_machine_v2_0);
|
||||
qemu_register_machine(&pc_q35_machine_v1_7);
|
||||
qemu_register_machine(&pc_q35_machine_v1_6);
|
||||
qemu_register_machine(&pc_q35_machine_v1_5);
|
||||
|
||||
133
hw/misc/vfio.c
133
hw/misc/vfio.c
@@ -52,6 +52,8 @@
|
||||
/* Extra debugging, trap acceleration paths for more logging */
|
||||
#define VFIO_ALLOW_MMAP 1
|
||||
#define VFIO_ALLOW_KVM_INTX 1
|
||||
#define VFIO_ALLOW_KVM_MSI 1
|
||||
#define VFIO_ALLOW_KVM_MSIX 1
|
||||
|
||||
struct VFIODevice;
|
||||
|
||||
@@ -208,6 +210,17 @@ static QLIST_HEAD(, VFIOContainer)
|
||||
static QLIST_HEAD(, VFIOGroup)
|
||||
group_list = QLIST_HEAD_INITIALIZER(group_list);
|
||||
|
||||
#ifdef CONFIG_KVM
|
||||
/*
|
||||
* We have a single VFIO pseudo device per KVM VM. Once created it lives
|
||||
* for the life of the VM. Closing the file descriptor only drops our
|
||||
* reference to it and the device's reference to kvm. Therefore once
|
||||
* initialized, this file descriptor is only released on QEMU exit and
|
||||
* we'll re-use it should another vfio device be attached before then.
|
||||
*/
|
||||
static int vfio_kvm_device_fd = -1;
|
||||
#endif
|
||||
|
||||
static void vfio_disable_interrupts(VFIODevice *vdev);
|
||||
static uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len);
|
||||
static void vfio_pci_write_config(PCIDevice *pdev, uint32_t addr,
|
||||
@@ -579,9 +592,21 @@ static void vfio_msi_interrupt(void *opaque)
|
||||
return;
|
||||
}
|
||||
|
||||
DPRINTF("%s(%04x:%02x:%02x.%x) vector %d\n", __func__,
|
||||
#ifdef VFIO_DEBUG
|
||||
MSIMessage msg;
|
||||
|
||||
if (vdev->interrupt == VFIO_INT_MSIX) {
|
||||
msg = msi_get_message(&vdev->pdev, nr);
|
||||
} else if (vdev->interrupt == VFIO_INT_MSI) {
|
||||
msg = msix_get_message(&vdev->pdev, nr);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
|
||||
DPRINTF("%s(%04x:%02x:%02x.%x) vector %d 0x%"PRIx64"/0x%x\n", __func__,
|
||||
vdev->host.domain, vdev->host.bus, vdev->host.slot,
|
||||
vdev->host.function, nr);
|
||||
vdev->host.function, nr, msg.address, msg.data);
|
||||
#endif
|
||||
|
||||
if (vdev->interrupt == VFIO_INT_MSIX) {
|
||||
msix_notify(&vdev->pdev, nr);
|
||||
@@ -649,7 +674,8 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
|
||||
* Attempt to enable route through KVM irqchip,
|
||||
* default to userspace handling if unavailable.
|
||||
*/
|
||||
vector->virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
|
||||
vector->virq = msg && VFIO_ALLOW_KVM_MSIX ?
|
||||
kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
|
||||
if (vector->virq < 0 ||
|
||||
kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
|
||||
NULL, vector->virq) < 0) {
|
||||
@@ -816,7 +842,8 @@ retry:
|
||||
* Attempt to enable route through KVM irqchip,
|
||||
* default to userspace handling if unavailable.
|
||||
*/
|
||||
vector->virq = kvm_irqchip_add_msi_route(kvm_state, vector->msg);
|
||||
vector->virq = VFIO_ALLOW_KVM_MSI ?
|
||||
kvm_irqchip_add_msi_route(kvm_state, vector->msg) : -1;
|
||||
if (vector->virq < 0 ||
|
||||
kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
|
||||
NULL, vector->virq) < 0) {
|
||||
@@ -878,8 +905,20 @@ static void vfio_disable_msi_common(VFIODevice *vdev)
|
||||
|
||||
static void vfio_disable_msix(VFIODevice *vdev)
|
||||
{
|
||||
int i;
|
||||
|
||||
msix_unset_vector_notifiers(&vdev->pdev);
|
||||
|
||||
/*
|
||||
* MSI-X will only release vectors if MSI-X is still enabled on the
|
||||
* device, check through the rest and release it ourselves if necessary.
|
||||
*/
|
||||
for (i = 0; i < vdev->nr_vectors; i++) {
|
||||
if (vdev->msi_vectors[i].use) {
|
||||
vfio_msix_vector_release(&vdev->pdev, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (vdev->nr_vectors) {
|
||||
vfio_disable_irqindex(vdev, VFIO_PCI_MSIX_IRQ_INDEX);
|
||||
}
|
||||
@@ -1800,6 +1839,34 @@ static void vfio_probe_nvidia_bar5_window_quirk(VFIODevice *vdev, int nr)
|
||||
vdev->host.function);
|
||||
}
|
||||
|
||||
static void vfio_nvidia_88000_quirk_write(void *opaque, hwaddr addr,
|
||||
uint64_t data, unsigned size)
|
||||
{
|
||||
VFIOQuirk *quirk = opaque;
|
||||
VFIODevice *vdev = quirk->vdev;
|
||||
PCIDevice *pdev = &vdev->pdev;
|
||||
hwaddr base = quirk->data.address_match & TARGET_PAGE_MASK;
|
||||
|
||||
vfio_generic_quirk_write(opaque, addr, data, size);
|
||||
|
||||
/*
|
||||
* Nvidia seems to acknowledge MSI interrupts by writing 0xff to the
|
||||
* MSI capability ID register. Both the ID and next register are
|
||||
* read-only, so we allow writes covering either of those to real hw.
|
||||
* NB - only fixed for the 0x88000 MMIO window.
|
||||
*/
|
||||
if ((pdev->cap_present & QEMU_PCI_CAP_MSI) &&
|
||||
vfio_range_contained(addr, size, pdev->msi_cap, PCI_MSI_FLAGS)) {
|
||||
vfio_bar_write(&vdev->bars[quirk->data.bar], addr + base, data, size);
|
||||
}
|
||||
}
|
||||
|
||||
static const MemoryRegionOps vfio_nvidia_88000_quirk = {
|
||||
.read = vfio_generic_quirk_read,
|
||||
.write = vfio_nvidia_88000_quirk_write,
|
||||
.endianness = DEVICE_LITTLE_ENDIAN,
|
||||
};
|
||||
|
||||
/*
|
||||
* Finally, BAR0 itself. We want to redirect any accesses to either
|
||||
* 0x1800 or 0x88000 through the PCI config space access functions.
|
||||
@@ -1826,7 +1893,7 @@ static void vfio_probe_nvidia_bar0_88000_quirk(VFIODevice *vdev, int nr)
|
||||
quirk->data.address_mask = PCIE_CONFIG_SPACE_SIZE - 1;
|
||||
quirk->data.bar = nr;
|
||||
|
||||
memory_region_init_io(&quirk->mem, OBJECT(vdev), &vfio_generic_quirk,
|
||||
memory_region_init_io(&quirk->mem, OBJECT(vdev), &vfio_nvidia_88000_quirk,
|
||||
quirk, "vfio-nvidia-bar0-88000-quirk",
|
||||
TARGET_PAGE_ALIGN(quirk->data.address_mask + 1));
|
||||
memory_region_add_subregion_overlap(&vdev->bars[nr].mem,
|
||||
@@ -3041,6 +3108,59 @@ static void vfio_pci_reset_handler(void *opaque)
|
||||
}
|
||||
}
|
||||
|
||||
static void vfio_kvm_device_add_group(VFIOGroup *group)
|
||||
{
|
||||
#ifdef CONFIG_KVM
|
||||
struct kvm_device_attr attr = {
|
||||
.group = KVM_DEV_VFIO_GROUP,
|
||||
.attr = KVM_DEV_VFIO_GROUP_ADD,
|
||||
.addr = (uint64_t)(unsigned long)&group->fd,
|
||||
};
|
||||
|
||||
if (!kvm_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vfio_kvm_device_fd < 0) {
|
||||
struct kvm_create_device cd = {
|
||||
.type = KVM_DEV_TYPE_VFIO,
|
||||
};
|
||||
|
||||
if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) {
|
||||
DPRINTF("KVM_CREATE_DEVICE: %m\n");
|
||||
return;
|
||||
}
|
||||
|
||||
vfio_kvm_device_fd = cd.fd;
|
||||
}
|
||||
|
||||
if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
|
||||
error_report("Failed to add group %d to KVM VFIO device: %m",
|
||||
group->groupid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void vfio_kvm_device_del_group(VFIOGroup *group)
|
||||
{
|
||||
#ifdef CONFIG_KVM
|
||||
struct kvm_device_attr attr = {
|
||||
.group = KVM_DEV_VFIO_GROUP,
|
||||
.attr = KVM_DEV_VFIO_GROUP_DEL,
|
||||
.addr = (uint64_t)(unsigned long)&group->fd,
|
||||
};
|
||||
|
||||
if (vfio_kvm_device_fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
|
||||
error_report("Failed to remove group %d to KVM VFIO device: %m",
|
||||
group->groupid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int vfio_connect_container(VFIOGroup *group)
|
||||
{
|
||||
VFIOContainer *container;
|
||||
@@ -3189,6 +3309,8 @@ static VFIOGroup *vfio_get_group(int groupid)
|
||||
|
||||
QLIST_INSERT_HEAD(&group_list, group, next);
|
||||
|
||||
vfio_kvm_device_add_group(group);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -3198,6 +3320,7 @@ static void vfio_put_group(VFIOGroup *group)
|
||||
return;
|
||||
}
|
||||
|
||||
vfio_kvm_device_del_group(group);
|
||||
vfio_disconnect_container(group);
|
||||
QLIST_REMOVE(group, next);
|
||||
DPRINTF("vfio_put_group: close group->fd\n");
|
||||
|
||||
@@ -1428,7 +1428,7 @@ static NetClientInfo net_virtio_info = {
|
||||
.size = sizeof(NICState),
|
||||
.can_receive = virtio_net_can_receive,
|
||||
.receive = virtio_net_receive,
|
||||
.cleanup = virtio_net_cleanup,
|
||||
.cleanup = virtio_net_cleanup,
|
||||
.link_status_changed = virtio_net_set_link_status,
|
||||
.query_rx_filter = virtio_net_query_rxfilter,
|
||||
};
|
||||
|
||||
@@ -126,7 +126,7 @@ static const VMStateDescription vmstate_eeprom = {
|
||||
.version_id = EEPROM_VERSION,
|
||||
.minimum_version_id = OLD_EEPROM_VERSION,
|
||||
.minimum_version_id_old = OLD_EEPROM_VERSION,
|
||||
.fields = (VMStateField []) {
|
||||
.fields = (VMStateField[]) {
|
||||
VMSTATE_UINT8(tick, eeprom_t),
|
||||
VMSTATE_UINT8(address, eeprom_t),
|
||||
VMSTATE_UINT8(command, eeprom_t),
|
||||
@@ -157,13 +157,13 @@ void eeprom93xx_write(eeprom_t *eeprom, int eecs, int eesk, int eedi)
|
||||
logout("CS=%u SK=%u DI=%u DO=%u, tick = %u\n",
|
||||
eecs, eesk, eedi, eedo, tick);
|
||||
|
||||
if (! eeprom->eecs && eecs) {
|
||||
if (!eeprom->eecs && eecs) {
|
||||
/* Start chip select cycle. */
|
||||
logout("Cycle start, waiting for 1st start bit (0)\n");
|
||||
tick = 0;
|
||||
command = 0x0;
|
||||
address = 0x0;
|
||||
} else if (eeprom->eecs && ! eecs) {
|
||||
} else if (eeprom->eecs && !eecs) {
|
||||
/* End chip select cycle. This triggers write / erase. */
|
||||
if (eeprom->writable) {
|
||||
uint8_t subcommand = address >> (eeprom->addrbits - 2);
|
||||
@@ -189,7 +189,7 @@ void eeprom93xx_write(eeprom_t *eeprom, int eecs, int eesk, int eedi)
|
||||
}
|
||||
/* Output DO is tristate, read results in 1. */
|
||||
eedo = 1;
|
||||
} else if (eecs && ! eeprom->eesk && eesk) {
|
||||
} else if (eecs && !eeprom->eesk && eesk) {
|
||||
/* Raising edge of clock shifts data in. */
|
||||
if (tick == 0) {
|
||||
/* Wait for 1st start bit. */
|
||||
@@ -230,20 +230,20 @@ void eeprom93xx_write(eeprom_t *eeprom, int eecs, int eesk, int eedi)
|
||||
if (command == 0) {
|
||||
/* Command code in upper 2 bits of address. */
|
||||
switch (address >> (eeprom->addrbits - 2)) {
|
||||
case 0:
|
||||
logout("write disable command\n");
|
||||
eeprom->writable = 0;
|
||||
break;
|
||||
case 1:
|
||||
logout("write all command\n");
|
||||
break;
|
||||
case 2:
|
||||
logout("erase all command\n");
|
||||
break;
|
||||
case 3:
|
||||
logout("write enable command\n");
|
||||
eeprom->writable = 1;
|
||||
break;
|
||||
case 0:
|
||||
logout("write disable command\n");
|
||||
eeprom->writable = 0;
|
||||
break;
|
||||
case 1:
|
||||
logout("write all command\n");
|
||||
break;
|
||||
case 2:
|
||||
logout("erase all command\n");
|
||||
break;
|
||||
case 3:
|
||||
logout("write enable command\n");
|
||||
eeprom->writable = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Read, write or erase word. */
|
||||
@@ -276,7 +276,7 @@ uint16_t eeprom93xx_read(eeprom_t *eeprom)
|
||||
{
|
||||
/* Return status of pin DO (0 or 1). */
|
||||
logout("CS=%u DO=%u\n", eeprom->eecs, eeprom->eedo);
|
||||
return (eeprom->eedo);
|
||||
return eeprom->eedo;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -296,18 +296,18 @@ eeprom_t *eeprom93xx_new(DeviceState *dev, uint16_t nwords)
|
||||
uint8_t addrbits;
|
||||
|
||||
switch (nwords) {
|
||||
case 16:
|
||||
case 64:
|
||||
addrbits = 6;
|
||||
break;
|
||||
case 128:
|
||||
case 256:
|
||||
addrbits = 8;
|
||||
break;
|
||||
default:
|
||||
assert(!"Unsupported EEPROM size, fallback to 64 words!");
|
||||
nwords = 64;
|
||||
addrbits = 6;
|
||||
case 16:
|
||||
case 64:
|
||||
addrbits = 6;
|
||||
break;
|
||||
case 128:
|
||||
case 256:
|
||||
addrbits = 8;
|
||||
break;
|
||||
default:
|
||||
assert(!"Unsupported EEPROM size, fallback to 64 words!");
|
||||
nwords = 64;
|
||||
addrbits = 6;
|
||||
}
|
||||
|
||||
eeprom = (eeprom_t *)g_malloc0(sizeof(*eeprom) + nwords * 2);
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#define MAX_CPUS 1
|
||||
|
||||
#define BIOS_SIZE (1024 * 1024)
|
||||
#define BIOS_FILENAME "ppc_rom.bin"
|
||||
#define NVRAM_SIZE 0x2000
|
||||
#define PROM_FILENAME "openbios-ppc"
|
||||
#define PROM_ADDR 0xfff00000
|
||||
|
||||
@@ -684,7 +684,7 @@ static inline void cpu_ppc_hdecr_excp(PowerPCCPU *cpu)
|
||||
}
|
||||
|
||||
static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp,
|
||||
struct QEMUTimer *timer,
|
||||
QEMUTimer *timer,
|
||||
void (*raise_excp)(PowerPCCPU *),
|
||||
uint32_t decr, uint32_t value,
|
||||
int is_excp)
|
||||
@@ -856,9 +856,9 @@ typedef struct ppc40x_timer_t ppc40x_timer_t;
|
||||
struct ppc40x_timer_t {
|
||||
uint64_t pit_reload; /* PIT auto-reload value */
|
||||
uint64_t fit_next; /* Tick for next FIT interrupt */
|
||||
struct QEMUTimer *fit_timer;
|
||||
QEMUTimer *fit_timer;
|
||||
uint64_t wdt_next; /* Tick for next WDT interrupt */
|
||||
struct QEMUTimer *wdt_timer;
|
||||
QEMUTimer *wdt_timer;
|
||||
|
||||
/* 405 have the PIT, 440 have a DECR. */
|
||||
unsigned int decr_excp;
|
||||
|
||||
@@ -1234,7 +1234,7 @@ struct ppc4xx_gpt_t {
|
||||
MemoryRegion iomem;
|
||||
int64_t tb_offset;
|
||||
uint32_t tb_freq;
|
||||
struct QEMUTimer *timer;
|
||||
QEMUTimer *timer;
|
||||
qemu_irq irqs[5];
|
||||
uint32_t oe;
|
||||
uint32_t ol;
|
||||
|
||||
@@ -64,10 +64,10 @@ typedef struct booke_timer_t booke_timer_t;
|
||||
struct booke_timer_t {
|
||||
|
||||
uint64_t fit_next;
|
||||
struct QEMUTimer *fit_timer;
|
||||
QEMUTimer *fit_timer;
|
||||
|
||||
uint64_t wdt_next;
|
||||
struct QEMUTimer *wdt_timer;
|
||||
QEMUTimer *wdt_timer;
|
||||
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
@@ -1293,6 +1293,11 @@ const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED = {
|
||||
.key = ILLEGAL_REQUEST, .asc = 0x53, .ascq = 0x02
|
||||
};
|
||||
|
||||
/* Illegal request, Invalid Transfer Tag */
|
||||
const struct SCSISense sense_code_INVALID_TAG = {
|
||||
.key = ILLEGAL_REQUEST, .asc = 0x4b, .ascq = 0x01
|
||||
};
|
||||
|
||||
/* Command aborted, I/O process terminated */
|
||||
const struct SCSISense sense_code_IO_ERROR = {
|
||||
.key = ABORTED_COMMAND, .asc = 0x00, .ascq = 0x06
|
||||
@@ -1308,6 +1313,11 @@ const struct SCSISense sense_code_LUN_FAILURE = {
|
||||
.key = ABORTED_COMMAND, .asc = 0x3e, .ascq = 0x01
|
||||
};
|
||||
|
||||
/* Command aborted, Overlapped Commands Attempted */
|
||||
const struct SCSISense sense_code_OVERLAPPED_COMMANDS = {
|
||||
.key = ABORTED_COMMAND, .asc = 0x4e, .ascq = 0x00
|
||||
};
|
||||
|
||||
/* Unit attention, Capacity data has changed */
|
||||
const struct SCSISense sense_code_CAPACITY_CHANGED = {
|
||||
.key = UNIT_ATTENTION, .asc = 0x2a, .ascq = 0x09
|
||||
|
||||
@@ -41,6 +41,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
|
||||
#include <scsi/sg.h>
|
||||
#endif
|
||||
|
||||
#define SCSI_WRITE_SAME_MAX 524288
|
||||
#define SCSI_DMA_BUF_SIZE 131072
|
||||
#define SCSI_MAX_INQUIRY_LEN 256
|
||||
#define SCSI_MAX_MODE_LEN 256
|
||||
@@ -634,6 +635,8 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
|
||||
buflen = 0x40;
|
||||
memset(outbuf + 4, 0, buflen - 4);
|
||||
|
||||
outbuf[4] = 0x1; /* wsnz */
|
||||
|
||||
/* optimal transfer length granularity */
|
||||
outbuf[6] = (min_io_size >> 8) & 0xff;
|
||||
outbuf[7] = min_io_size & 0xff;
|
||||
@@ -1543,10 +1546,16 @@ done:
|
||||
|
||||
static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf)
|
||||
{
|
||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
|
||||
uint8_t *p = inbuf;
|
||||
int len = r->req.cmd.xfer;
|
||||
UnmapCBData *data;
|
||||
|
||||
/* Reject ANCHOR=1. */
|
||||
if (r->req.cmd.buf[1] & 0x1) {
|
||||
goto invalid_field;
|
||||
}
|
||||
|
||||
if (len < 8) {
|
||||
goto invalid_param_len;
|
||||
}
|
||||
@@ -1560,6 +1569,11 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf)
|
||||
goto invalid_param_len;
|
||||
}
|
||||
|
||||
if (bdrv_is_read_only(s->qdev.conf.bs)) {
|
||||
scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
|
||||
return;
|
||||
}
|
||||
|
||||
data = g_new0(UnmapCBData, 1);
|
||||
data->r = r;
|
||||
data->inbuf = &p[8];
|
||||
@@ -1572,6 +1586,115 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf)
|
||||
|
||||
invalid_param_len:
|
||||
scsi_check_condition(r, SENSE_CODE(INVALID_PARAM_LEN));
|
||||
return;
|
||||
|
||||
invalid_field:
|
||||
scsi_check_condition(r, SENSE_CODE(INVALID_FIELD));
|
||||
}
|
||||
|
||||
typedef struct WriteSameCBData {
|
||||
SCSIDiskReq *r;
|
||||
int64_t sector;
|
||||
int nb_sectors;
|
||||
QEMUIOVector qiov;
|
||||
struct iovec iov;
|
||||
} WriteSameCBData;
|
||||
|
||||
static void scsi_write_same_complete(void *opaque, int ret)
|
||||
{
|
||||
WriteSameCBData *data = opaque;
|
||||
SCSIDiskReq *r = data->r;
|
||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
|
||||
|
||||
assert(r->req.aiocb != NULL);
|
||||
r->req.aiocb = NULL;
|
||||
bdrv_acct_done(s->qdev.conf.bs, &r->acct);
|
||||
if (r->req.io_canceled) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
if (scsi_handle_rw_error(r, -ret)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
data->nb_sectors -= data->iov.iov_len / 512;
|
||||
data->sector += data->iov.iov_len / 512;
|
||||
data->iov.iov_len = MIN(data->nb_sectors * 512, data->iov.iov_len);
|
||||
if (data->iov.iov_len) {
|
||||
bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len, BDRV_ACCT_WRITE);
|
||||
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
|
||||
&data->qiov, data->iov.iov_len / 512,
|
||||
scsi_write_same_complete, r);
|
||||
return;
|
||||
}
|
||||
|
||||
scsi_req_complete(&r->req, GOOD);
|
||||
|
||||
done:
|
||||
if (!r->req.io_canceled) {
|
||||
scsi_req_unref(&r->req);
|
||||
}
|
||||
qemu_vfree(data->iov.iov_base);
|
||||
g_free(data);
|
||||
}
|
||||
|
||||
static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
|
||||
{
|
||||
SCSIRequest *req = &r->req;
|
||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
|
||||
uint32_t nb_sectors = scsi_data_cdb_length(r->req.cmd.buf);
|
||||
WriteSameCBData *data;
|
||||
uint8_t *buf;
|
||||
int i;
|
||||
|
||||
/* Fail if PBDATA=1 or LBDATA=1 or ANCHOR=1. */
|
||||
if (nb_sectors == 0 || (req->cmd.buf[1] & 0x16)) {
|
||||
scsi_check_condition(r, SENSE_CODE(INVALID_FIELD));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bdrv_is_read_only(s->qdev.conf.bs)) {
|
||||
scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
|
||||
return;
|
||||
}
|
||||
if (!check_lba_range(s, r->req.cmd.lba, nb_sectors)) {
|
||||
scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer_is_zero(inbuf, s->qdev.blocksize)) {
|
||||
int flags = (req->cmd.buf[1] & 0x8) ? BDRV_REQ_MAY_UNMAP : 0;
|
||||
|
||||
/* The request is used as the AIO opaque value, so add a ref. */
|
||||
scsi_req_ref(&r->req);
|
||||
bdrv_acct_start(s->qdev.conf.bs, &r->acct, nb_sectors * s->qdev.blocksize,
|
||||
BDRV_ACCT_WRITE);
|
||||
r->req.aiocb = bdrv_aio_write_zeroes(s->qdev.conf.bs,
|
||||
r->req.cmd.lba * (s->qdev.blocksize / 512),
|
||||
nb_sectors * (s->qdev.blocksize / 512),
|
||||
flags, scsi_aio_complete, r);
|
||||
return;
|
||||
}
|
||||
|
||||
data = g_new0(WriteSameCBData, 1);
|
||||
data->r = r;
|
||||
data->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
|
||||
data->nb_sectors = nb_sectors * (s->qdev.blocksize / 512);
|
||||
data->iov.iov_len = MIN(data->nb_sectors * 512, SCSI_WRITE_SAME_MAX);
|
||||
data->iov.iov_base = buf = qemu_blockalign(s->qdev.conf.bs, data->iov.iov_len);
|
||||
qemu_iovec_init_external(&data->qiov, &data->iov, 1);
|
||||
|
||||
for (i = 0; i < data->iov.iov_len; i += s->qdev.blocksize) {
|
||||
memcpy(&buf[i], inbuf, s->qdev.blocksize);
|
||||
}
|
||||
|
||||
scsi_req_ref(&r->req);
|
||||
bdrv_acct_start(s->qdev.conf.bs, &r->acct, data->iov.iov_len, BDRV_ACCT_WRITE);
|
||||
r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
|
||||
&data->qiov, data->iov.iov_len / 512,
|
||||
scsi_write_same_complete, data);
|
||||
}
|
||||
|
||||
static void scsi_disk_emulate_write_data(SCSIRequest *req)
|
||||
@@ -1597,6 +1720,10 @@ static void scsi_disk_emulate_write_data(SCSIRequest *req)
|
||||
scsi_disk_emulate_unmap(r, r->iov.iov_base);
|
||||
break;
|
||||
|
||||
case WRITE_SAME_10:
|
||||
case WRITE_SAME_16:
|
||||
scsi_disk_emulate_write_same(r, r->iov.iov_base);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
@@ -1839,29 +1966,10 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
|
||||
break;
|
||||
case WRITE_SAME_10:
|
||||
case WRITE_SAME_16:
|
||||
nb_sectors = scsi_data_cdb_length(r->req.cmd.buf);
|
||||
if (bdrv_is_read_only(s->qdev.conf.bs)) {
|
||||
scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
|
||||
return 0;
|
||||
}
|
||||
if (!check_lba_range(s, r->req.cmd.lba, nb_sectors)) {
|
||||
goto illegal_lba;
|
||||
}
|
||||
|
||||
/*
|
||||
* We only support WRITE SAME with the unmap bit set for now.
|
||||
*/
|
||||
if (!(req->cmd.buf[1] & 0x8)) {
|
||||
goto illegal_request;
|
||||
}
|
||||
|
||||
/* The request is used as the AIO opaque value, so add a ref. */
|
||||
scsi_req_ref(&r->req);
|
||||
r->req.aiocb = bdrv_aio_discard(s->qdev.conf.bs,
|
||||
r->req.cmd.lba * (s->qdev.blocksize / 512),
|
||||
nb_sectors * (s->qdev.blocksize / 512),
|
||||
scsi_aio_complete, r);
|
||||
return 0;
|
||||
DPRINTF("WRITE SAME %d (len %lu)\n",
|
||||
req->cmd.buf[0] == WRITE_SAME_10 ? 10 : 16,
|
||||
(long)r->req.cmd.xfer);
|
||||
break;
|
||||
default:
|
||||
DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]);
|
||||
scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
|
||||
|
||||
@@ -61,8 +61,8 @@ struct M48t59State {
|
||||
time_t stop_time;
|
||||
/* Alarm & watchdog */
|
||||
struct tm alarm;
|
||||
struct QEMUTimer *alrm_timer;
|
||||
struct QEMUTimer *wd_timer;
|
||||
QEMUTimer *alrm_timer;
|
||||
QEMUTimer *wd_timer;
|
||||
/* NVRAM storage */
|
||||
uint8_t *buffer;
|
||||
/* Model parameters */
|
||||
|
||||
18
hw/usb/bus.c
18
hw/usb/bus.c
@@ -203,6 +203,24 @@ void usb_device_ep_stopped(USBDevice *dev, USBEndpoint *ep)
|
||||
}
|
||||
}
|
||||
|
||||
int usb_device_alloc_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps,
|
||||
int streams)
|
||||
{
|
||||
USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
|
||||
if (klass->alloc_streams) {
|
||||
return klass->alloc_streams(dev, eps, nr_eps, streams);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usb_device_free_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps)
|
||||
{
|
||||
USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
|
||||
if (klass->free_streams) {
|
||||
klass->free_streams(dev, eps, nr_eps);
|
||||
}
|
||||
}
|
||||
|
||||
static int usb_qdev_init(DeviceState *qdev)
|
||||
{
|
||||
USBDevice *dev = USB_DEVICE(qdev);
|
||||
|
||||
@@ -623,6 +623,7 @@ void usb_ep_reset(USBDevice *dev)
|
||||
dev->ep_ctl.type = USB_ENDPOINT_XFER_CONTROL;
|
||||
dev->ep_ctl.ifnum = 0;
|
||||
dev->ep_ctl.max_packet_size = 64;
|
||||
dev->ep_ctl.max_streams = 0;
|
||||
dev->ep_ctl.dev = dev;
|
||||
dev->ep_ctl.pipeline = false;
|
||||
for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
|
||||
@@ -636,6 +637,8 @@ void usb_ep_reset(USBDevice *dev)
|
||||
dev->ep_out[ep].ifnum = USB_INTERFACE_INVALID;
|
||||
dev->ep_in[ep].max_packet_size = 0;
|
||||
dev->ep_out[ep].max_packet_size = 0;
|
||||
dev->ep_in[ep].max_streams = 0;
|
||||
dev->ep_out[ep].max_streams = 0;
|
||||
dev->ep_in[ep].dev = dev;
|
||||
dev->ep_out[ep].dev = dev;
|
||||
dev->ep_in[ep].pipeline = false;
|
||||
@@ -764,6 +767,25 @@ int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep)
|
||||
return uep->max_packet_size;
|
||||
}
|
||||
|
||||
void usb_ep_set_max_streams(USBDevice *dev, int pid, int ep, uint8_t raw)
|
||||
{
|
||||
struct USBEndpoint *uep = usb_ep_get(dev, pid, ep);
|
||||
int MaxStreams;
|
||||
|
||||
MaxStreams = raw & 0x1f;
|
||||
if (MaxStreams) {
|
||||
uep->max_streams = 1 << MaxStreams;
|
||||
} else {
|
||||
uep->max_streams = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int usb_ep_get_max_streams(USBDevice *dev, int pid, int ep)
|
||||
{
|
||||
struct USBEndpoint *uep = usb_ep_get(dev, pid, ep);
|
||||
return uep->max_streams;
|
||||
}
|
||||
|
||||
void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, bool enabled)
|
||||
{
|
||||
struct USBEndpoint *uep = usb_ep_get(dev, pid, ep);
|
||||
|
||||
@@ -6,16 +6,6 @@
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static uint8_t usb_lo(uint16_t val)
|
||||
{
|
||||
return val & 0xff;
|
||||
}
|
||||
|
||||
static uint8_t usb_hi(uint16_t val)
|
||||
{
|
||||
return (val >> 8) & 0xff;
|
||||
}
|
||||
|
||||
int usb_desc_device(const USBDescID *id, const USBDescDevice *dev,
|
||||
uint8_t *dest, size_t len)
|
||||
{
|
||||
@@ -385,6 +375,8 @@ static void usb_desc_ep_init(USBDevice *dev)
|
||||
usb_ep_set_ifnum(dev, pid, ep, iface->bInterfaceNumber);
|
||||
usb_ep_set_max_packet_size(dev, pid, ep,
|
||||
iface->eps[e].wMaxPacketSize);
|
||||
usb_ep_set_max_streams(dev, pid, ep,
|
||||
iface->eps[e].bmAttributes_super);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,17 @@ struct USBDesc {
|
||||
|
||||
#define USB_DESC_FLAG_SUPER (1 << 1)
|
||||
|
||||
/* little helpers */
|
||||
static inline uint8_t usb_lo(uint16_t val)
|
||||
{
|
||||
return val & 0xff;
|
||||
}
|
||||
|
||||
static inline uint8_t usb_hi(uint16_t val)
|
||||
{
|
||||
return (val >> 8) & 0xff;
|
||||
}
|
||||
|
||||
/* generate usb packages from structs */
|
||||
int usb_desc_device(const USBDescID *id, const USBDescDevice *dev,
|
||||
uint8_t *dest, size_t len);
|
||||
|
||||
@@ -236,7 +236,7 @@ static const USBDescDevice desc_device_tablet2 = {
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = STR_CONFIG_TABLET,
|
||||
.bmAttributes = 0x80,
|
||||
.bmAttributes = 0xa0,
|
||||
.bMaxPower = 50,
|
||||
.nif = 1,
|
||||
.ifs = &desc_iface_tablet2,
|
||||
|
||||
156
hw/usb/dev-uas.c
156
hw/usb/dev-uas.c
@@ -55,7 +55,7 @@ typedef struct {
|
||||
uint8_t id;
|
||||
uint8_t reserved;
|
||||
uint16_t tag;
|
||||
} QEMU_PACKED uas_ui_header;
|
||||
} QEMU_PACKED uas_iu_header;
|
||||
|
||||
typedef struct {
|
||||
uint8_t prio_taskattr; /* 6:3 priority, 2:0 task attribute */
|
||||
@@ -65,7 +65,7 @@ typedef struct {
|
||||
uint64_t lun;
|
||||
uint8_t cdb[16];
|
||||
uint8_t add_cdb[];
|
||||
} QEMU_PACKED uas_ui_command;
|
||||
} QEMU_PACKED uas_iu_command;
|
||||
|
||||
typedef struct {
|
||||
uint16_t status_qualifier;
|
||||
@@ -73,29 +73,29 @@ typedef struct {
|
||||
uint8_t reserved[7];
|
||||
uint16_t sense_length;
|
||||
uint8_t sense_data[18];
|
||||
} QEMU_PACKED uas_ui_sense;
|
||||
} QEMU_PACKED uas_iu_sense;
|
||||
|
||||
typedef struct {
|
||||
uint16_t add_response_info;
|
||||
uint8_t add_response_info[3];
|
||||
uint8_t response_code;
|
||||
} QEMU_PACKED uas_ui_response;
|
||||
} QEMU_PACKED uas_iu_response;
|
||||
|
||||
typedef struct {
|
||||
uint8_t function;
|
||||
uint8_t reserved;
|
||||
uint16_t task_tag;
|
||||
uint64_t lun;
|
||||
} QEMU_PACKED uas_ui_task_mgmt;
|
||||
} QEMU_PACKED uas_iu_task_mgmt;
|
||||
|
||||
typedef struct {
|
||||
uas_ui_header hdr;
|
||||
uas_iu_header hdr;
|
||||
union {
|
||||
uas_ui_command command;
|
||||
uas_ui_sense sense;
|
||||
uas_ui_task_mgmt task;
|
||||
uas_ui_response response;
|
||||
uas_iu_command command;
|
||||
uas_iu_sense sense;
|
||||
uas_iu_task_mgmt task;
|
||||
uas_iu_response response;
|
||||
};
|
||||
} QEMU_PACKED uas_ui;
|
||||
} QEMU_PACKED uas_iu;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -122,8 +122,8 @@ struct UASDevice {
|
||||
UASRequest *dataout2;
|
||||
|
||||
/* usb 3.0 only */
|
||||
USBPacket *data3[UAS_MAX_STREAMS];
|
||||
USBPacket *status3[UAS_MAX_STREAMS];
|
||||
USBPacket *data3[UAS_MAX_STREAMS + 1];
|
||||
USBPacket *status3[UAS_MAX_STREAMS + 1];
|
||||
};
|
||||
|
||||
struct UASRequest {
|
||||
@@ -145,7 +145,7 @@ struct UASRequest {
|
||||
|
||||
struct UASStatus {
|
||||
uint32_t stream;
|
||||
uas_ui status;
|
||||
uas_iu status;
|
||||
uint32_t length;
|
||||
QTAILQ_ENTRY(UASStatus) next;
|
||||
};
|
||||
@@ -338,7 +338,7 @@ static UASStatus *usb_uas_alloc_status(UASDevice *uas, uint8_t id, uint16_t tag)
|
||||
|
||||
st->status.hdr.id = id;
|
||||
st->status.hdr.tag = cpu_to_be16(tag);
|
||||
st->length = sizeof(uas_ui_header);
|
||||
st->length = sizeof(uas_iu_header);
|
||||
if (uas_using_streams(uas)) {
|
||||
st->stream = tag;
|
||||
}
|
||||
@@ -392,15 +392,13 @@ static void usb_uas_queue_status(UASDevice *uas, UASStatus *st, int length)
|
||||
}
|
||||
}
|
||||
|
||||
static void usb_uas_queue_response(UASDevice *uas, uint16_t tag,
|
||||
uint8_t code, uint16_t add_info)
|
||||
static void usb_uas_queue_response(UASDevice *uas, uint16_t tag, uint8_t code)
|
||||
{
|
||||
UASStatus *st = usb_uas_alloc_status(uas, UAS_UI_RESPONSE, tag);
|
||||
|
||||
trace_usb_uas_response(uas->dev.addr, tag, code);
|
||||
st->status.response.response_code = code;
|
||||
st->status.response.add_response_info = cpu_to_be16(add_info);
|
||||
usb_uas_queue_status(uas, st, sizeof(uas_ui_response));
|
||||
usb_uas_queue_status(uas, st, sizeof(uas_iu_response));
|
||||
}
|
||||
|
||||
static void usb_uas_queue_sense(UASRequest *req, uint8_t status)
|
||||
@@ -416,10 +414,28 @@ static void usb_uas_queue_sense(UASRequest *req, uint8_t status)
|
||||
sizeof(st->status.sense.sense_data));
|
||||
st->status.sense.sense_length = cpu_to_be16(slen);
|
||||
}
|
||||
len = sizeof(uas_ui_sense) - sizeof(st->status.sense.sense_data) + slen;
|
||||
len = sizeof(uas_iu_sense) - sizeof(st->status.sense.sense_data) + slen;
|
||||
usb_uas_queue_status(req->uas, st, len);
|
||||
}
|
||||
|
||||
static void usb_uas_queue_fake_sense(UASDevice *uas, uint16_t tag,
|
||||
struct SCSISense sense)
|
||||
{
|
||||
UASStatus *st = usb_uas_alloc_status(uas, UAS_UI_SENSE, tag);
|
||||
int len, slen = 0;
|
||||
|
||||
st->status.sense.status = CHECK_CONDITION;
|
||||
st->status.sense.status_qualifier = cpu_to_be16(0);
|
||||
st->status.sense.sense_data[0] = 0x70;
|
||||
st->status.sense.sense_data[2] = sense.key;
|
||||
st->status.sense.sense_data[7] = 10;
|
||||
st->status.sense.sense_data[12] = sense.asc;
|
||||
st->status.sense.sense_data[13] = sense.ascq;
|
||||
slen = 18;
|
||||
len = sizeof(uas_iu_sense) - sizeof(st->status.sense.sense_data) + slen;
|
||||
usb_uas_queue_status(uas, st, len);
|
||||
}
|
||||
|
||||
static void usb_uas_queue_read_ready(UASRequest *req)
|
||||
{
|
||||
UASStatus *st = usb_uas_alloc_status(req->uas, UAS_UI_READ_READY,
|
||||
@@ -518,14 +534,14 @@ static void usb_uas_start_next_transfer(UASDevice *uas)
|
||||
}
|
||||
}
|
||||
|
||||
static UASRequest *usb_uas_alloc_request(UASDevice *uas, uas_ui *ui)
|
||||
static UASRequest *usb_uas_alloc_request(UASDevice *uas, uas_iu *iu)
|
||||
{
|
||||
UASRequest *req;
|
||||
|
||||
req = g_new0(UASRequest, 1);
|
||||
req->uas = uas;
|
||||
req->tag = be16_to_cpu(ui->hdr.tag);
|
||||
req->lun = be64_to_cpu(ui->command.lun);
|
||||
req->tag = be16_to_cpu(iu->hdr.tag);
|
||||
req->lun = be64_to_cpu(iu->command.lun);
|
||||
req->dev = usb_uas_get_dev(req->uas, req->lun);
|
||||
return req;
|
||||
}
|
||||
@@ -648,7 +664,7 @@ static void usb_uas_cancel_io(USBDevice *dev, USBPacket *p)
|
||||
return;
|
||||
}
|
||||
if (uas_using_streams(uas)) {
|
||||
for (i = 0; i < UAS_MAX_STREAMS; i++) {
|
||||
for (i = 0; i <= UAS_MAX_STREAMS; i++) {
|
||||
if (uas->status3[i] == p) {
|
||||
uas->status3[i] = NULL;
|
||||
return;
|
||||
@@ -668,16 +684,20 @@ static void usb_uas_cancel_io(USBDevice *dev, USBPacket *p)
|
||||
assert(!"canceled usb packet not found");
|
||||
}
|
||||
|
||||
static void usb_uas_command(UASDevice *uas, uas_ui *ui)
|
||||
static void usb_uas_command(UASDevice *uas, uas_iu *iu)
|
||||
{
|
||||
UASRequest *req;
|
||||
uint32_t len;
|
||||
uint16_t tag = be16_to_cpu(iu->hdr.tag);
|
||||
|
||||
req = usb_uas_find_request(uas, be16_to_cpu(ui->hdr.tag));
|
||||
if (uas_using_streams(uas) && tag > UAS_MAX_STREAMS) {
|
||||
goto invalid_tag;
|
||||
}
|
||||
req = usb_uas_find_request(uas, tag);
|
||||
if (req) {
|
||||
goto overlapped_tag;
|
||||
}
|
||||
req = usb_uas_alloc_request(uas, ui);
|
||||
req = usb_uas_alloc_request(uas, iu);
|
||||
if (req->dev == NULL) {
|
||||
goto bad_target;
|
||||
}
|
||||
@@ -694,7 +714,7 @@ static void usb_uas_command(UASDevice *uas, uas_ui *ui)
|
||||
|
||||
req->req = scsi_req_new(req->dev, req->tag,
|
||||
usb_uas_get_lun(req->lun),
|
||||
ui->command.cdb, req);
|
||||
iu->command.cdb, req);
|
||||
if (uas->requestlog) {
|
||||
scsi_req_print(req->req);
|
||||
}
|
||||
@@ -705,105 +725,97 @@ static void usb_uas_command(UASDevice *uas, uas_ui *ui)
|
||||
}
|
||||
return;
|
||||
|
||||
invalid_tag:
|
||||
usb_uas_queue_fake_sense(uas, tag, sense_code_INVALID_TAG);
|
||||
return;
|
||||
|
||||
overlapped_tag:
|
||||
usb_uas_queue_response(uas, req->tag, UAS_RC_OVERLAPPED_TAG, 0);
|
||||
usb_uas_queue_fake_sense(uas, tag, sense_code_OVERLAPPED_COMMANDS);
|
||||
return;
|
||||
|
||||
bad_target:
|
||||
/*
|
||||
* FIXME: Seems to upset linux, is this wrong?
|
||||
* NOTE: Happens only with no scsi devices at the bus, not sure
|
||||
* this is a valid UAS setup in the first place.
|
||||
*/
|
||||
usb_uas_queue_response(uas, req->tag, UAS_RC_INVALID_INFO_UNIT, 0);
|
||||
usb_uas_queue_fake_sense(uas, tag, sense_code_LUN_NOT_SUPPORTED);
|
||||
g_free(req);
|
||||
}
|
||||
|
||||
static void usb_uas_task(UASDevice *uas, uas_ui *ui)
|
||||
static void usb_uas_task(UASDevice *uas, uas_iu *iu)
|
||||
{
|
||||
uint16_t tag = be16_to_cpu(ui->hdr.tag);
|
||||
uint64_t lun64 = be64_to_cpu(ui->task.lun);
|
||||
uint16_t tag = be16_to_cpu(iu->hdr.tag);
|
||||
uint64_t lun64 = be64_to_cpu(iu->task.lun);
|
||||
SCSIDevice *dev = usb_uas_get_dev(uas, lun64);
|
||||
int lun = usb_uas_get_lun(lun64);
|
||||
UASRequest *req;
|
||||
uint16_t task_tag;
|
||||
|
||||
req = usb_uas_find_request(uas, be16_to_cpu(ui->hdr.tag));
|
||||
if (uas_using_streams(uas) && tag > UAS_MAX_STREAMS) {
|
||||
goto invalid_tag;
|
||||
}
|
||||
req = usb_uas_find_request(uas, be16_to_cpu(iu->hdr.tag));
|
||||
if (req) {
|
||||
goto overlapped_tag;
|
||||
}
|
||||
if (dev == NULL) {
|
||||
goto incorrect_lun;
|
||||
}
|
||||
|
||||
switch (ui->task.function) {
|
||||
switch (iu->task.function) {
|
||||
case UAS_TMF_ABORT_TASK:
|
||||
task_tag = be16_to_cpu(ui->task.task_tag);
|
||||
task_tag = be16_to_cpu(iu->task.task_tag);
|
||||
trace_usb_uas_tmf_abort_task(uas->dev.addr, tag, task_tag);
|
||||
if (dev == NULL) {
|
||||
goto bad_target;
|
||||
}
|
||||
if (dev->lun != lun) {
|
||||
goto incorrect_lun;
|
||||
}
|
||||
req = usb_uas_find_request(uas, task_tag);
|
||||
if (req && req->dev == dev) {
|
||||
scsi_req_cancel(req->req);
|
||||
}
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0);
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE);
|
||||
break;
|
||||
|
||||
case UAS_TMF_LOGICAL_UNIT_RESET:
|
||||
trace_usb_uas_tmf_logical_unit_reset(uas->dev.addr, tag, lun);
|
||||
if (dev == NULL) {
|
||||
goto bad_target;
|
||||
}
|
||||
if (dev->lun != lun) {
|
||||
goto incorrect_lun;
|
||||
}
|
||||
qdev_reset_all(&dev->qdev);
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0);
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE);
|
||||
break;
|
||||
|
||||
default:
|
||||
trace_usb_uas_tmf_unsupported(uas->dev.addr, tag, ui->task.function);
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_TMF_NOT_SUPPORTED, 0);
|
||||
trace_usb_uas_tmf_unsupported(uas->dev.addr, tag, iu->task.function);
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_TMF_NOT_SUPPORTED);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
overlapped_tag:
|
||||
usb_uas_queue_response(uas, req->tag, UAS_RC_OVERLAPPED_TAG, 0);
|
||||
invalid_tag:
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_INVALID_INFO_UNIT);
|
||||
return;
|
||||
|
||||
bad_target:
|
||||
/* FIXME: correct? [see long comment in usb_uas_command()] */
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_INVALID_INFO_UNIT, 0);
|
||||
overlapped_tag:
|
||||
usb_uas_queue_response(uas, req->tag, UAS_RC_OVERLAPPED_TAG);
|
||||
return;
|
||||
|
||||
incorrect_lun:
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_INCORRECT_LUN, 0);
|
||||
usb_uas_queue_response(uas, tag, UAS_RC_INCORRECT_LUN);
|
||||
}
|
||||
|
||||
static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
|
||||
{
|
||||
UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
|
||||
uas_ui ui;
|
||||
uas_iu iu;
|
||||
UASStatus *st;
|
||||
UASRequest *req;
|
||||
int length;
|
||||
|
||||
switch (p->ep->nr) {
|
||||
case UAS_PIPE_ID_COMMAND:
|
||||
length = MIN(sizeof(ui), p->iov.size);
|
||||
usb_packet_copy(p, &ui, length);
|
||||
switch (ui.hdr.id) {
|
||||
length = MIN(sizeof(iu), p->iov.size);
|
||||
usb_packet_copy(p, &iu, length);
|
||||
switch (iu.hdr.id) {
|
||||
case UAS_UI_COMMAND:
|
||||
usb_uas_command(uas, &ui);
|
||||
usb_uas_command(uas, &iu);
|
||||
break;
|
||||
case UAS_UI_TASK_MGMT:
|
||||
usb_uas_task(uas, &ui);
|
||||
usb_uas_task(uas, &iu);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: unknown command ui: id 0x%x\n",
|
||||
__func__, ui.hdr.id);
|
||||
fprintf(stderr, "%s: unknown command iu: id 0x%x\n",
|
||||
__func__, iu.hdr.id);
|
||||
p->status = USB_RET_STALL;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "hw/usb/hcd-ehci.h"
|
||||
#include "trace.h"
|
||||
|
||||
/* Capability Registers Base Address - section 2.2 */
|
||||
#define CAPLENGTH 0x0000 /* 1-byte, 0x0001 reserved */
|
||||
@@ -826,9 +827,9 @@ static void ehci_child_detach(USBPort *port, USBDevice *child)
|
||||
static void ehci_wakeup(USBPort *port)
|
||||
{
|
||||
EHCIState *s = port->opaque;
|
||||
uint32_t portsc = s->portsc[port->index];
|
||||
uint32_t *portsc = &s->portsc[port->index];
|
||||
|
||||
if (portsc & PORTSC_POWNER) {
|
||||
if (*portsc & PORTSC_POWNER) {
|
||||
USBPort *companion = s->companion_ports[port->index];
|
||||
if (companion->ops->wakeup) {
|
||||
companion->ops->wakeup(companion);
|
||||
@@ -836,6 +837,12 @@ static void ehci_wakeup(USBPort *port)
|
||||
return;
|
||||
}
|
||||
|
||||
if (*portsc & PORTSC_SUSPEND) {
|
||||
trace_usb_ehci_port_wakeup(port->index);
|
||||
*portsc |= PORTSC_FPRES;
|
||||
ehci_raise_irq(s, USBSTS_PCD);
|
||||
}
|
||||
|
||||
qemu_bh_schedule(s->async_bh);
|
||||
}
|
||||
|
||||
@@ -1067,6 +1074,14 @@ static void ehci_port_write(void *ptr, hwaddr addr,
|
||||
}
|
||||
}
|
||||
|
||||
if ((val & PORTSC_SUSPEND) && !(*portsc & PORTSC_SUSPEND)) {
|
||||
trace_usb_ehci_port_suspend(port);
|
||||
}
|
||||
if (!(val & PORTSC_FPRES) && (*portsc & PORTSC_FPRES)) {
|
||||
trace_usb_ehci_port_resume(port);
|
||||
val &= ~PORTSC_SUSPEND;
|
||||
}
|
||||
|
||||
*portsc &= ~PORTSC_RO_MASK;
|
||||
*portsc |= val;
|
||||
trace_usb_ehci_portsc_change(addr + s->portscbase, addr >> 2, *portsc, old);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "qemu/timer.h"
|
||||
#include "hw/usb.h"
|
||||
#include "monitor/monitor.h"
|
||||
#include "trace.h"
|
||||
#include "sysemu/dma.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "hw/pci/pci.h"
|
||||
|
||||
@@ -1150,6 +1150,111 @@ static void xhci_free_streams(XHCIEPContext *epctx)
|
||||
epctx->nr_pstreams = 0;
|
||||
}
|
||||
|
||||
static int xhci_epmask_to_eps_with_streams(XHCIState *xhci,
|
||||
unsigned int slotid,
|
||||
uint32_t epmask,
|
||||
XHCIEPContext **epctxs,
|
||||
USBEndpoint **eps)
|
||||
{
|
||||
XHCISlot *slot;
|
||||
XHCIEPContext *epctx;
|
||||
USBEndpoint *ep;
|
||||
int i, j;
|
||||
|
||||
assert(slotid >= 1 && slotid <= xhci->numslots);
|
||||
|
||||
slot = &xhci->slots[slotid - 1];
|
||||
|
||||
for (i = 2, j = 0; i <= 31; i++) {
|
||||
if (!(epmask & (1 << i))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
epctx = slot->eps[i - 1];
|
||||
ep = xhci_epid_to_usbep(xhci, slotid, i);
|
||||
if (!epctx || !epctx->nr_pstreams || !ep) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (epctxs) {
|
||||
epctxs[j] = epctx;
|
||||
}
|
||||
eps[j++] = ep;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
static void xhci_free_device_streams(XHCIState *xhci, unsigned int slotid,
|
||||
uint32_t epmask)
|
||||
{
|
||||
USBEndpoint *eps[30];
|
||||
int nr_eps;
|
||||
|
||||
nr_eps = xhci_epmask_to_eps_with_streams(xhci, slotid, epmask, NULL, eps);
|
||||
if (nr_eps) {
|
||||
usb_device_free_streams(eps[0]->dev, eps, nr_eps);
|
||||
}
|
||||
}
|
||||
|
||||
static TRBCCode xhci_alloc_device_streams(XHCIState *xhci, unsigned int slotid,
|
||||
uint32_t epmask)
|
||||
{
|
||||
XHCIEPContext *epctxs[30];
|
||||
USBEndpoint *eps[30];
|
||||
int i, r, nr_eps, req_nr_streams, dev_max_streams;
|
||||
|
||||
nr_eps = xhci_epmask_to_eps_with_streams(xhci, slotid, epmask, epctxs,
|
||||
eps);
|
||||
if (nr_eps == 0) {
|
||||
return CC_SUCCESS;
|
||||
}
|
||||
|
||||
req_nr_streams = epctxs[0]->nr_pstreams;
|
||||
dev_max_streams = eps[0]->max_streams;
|
||||
|
||||
for (i = 1; i < nr_eps; i++) {
|
||||
/*
|
||||
* HdG: I don't expect these to ever trigger, but if they do we need
|
||||
* to come up with another solution, ie group identical endpoints
|
||||
* together and make an usb_device_alloc_streams call per group.
|
||||
*/
|
||||
if (epctxs[i]->nr_pstreams != req_nr_streams) {
|
||||
FIXME("guest streams config not identical for all eps");
|
||||
return CC_RESOURCE_ERROR;
|
||||
}
|
||||
if (eps[i]->max_streams != dev_max_streams) {
|
||||
FIXME("device streams config not identical for all eps");
|
||||
return CC_RESOURCE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* max-streams in both the device descriptor and in the controller is a
|
||||
* power of 2. But stream id 0 is reserved, so if a device can do up to 4
|
||||
* streams the guest will ask for 5 rounded up to the next power of 2 which
|
||||
* becomes 8. For emulated devices usb_device_alloc_streams is a nop.
|
||||
*
|
||||
* For redirected devices however this is an issue, as there we must ask
|
||||
* the real xhci controller to alloc streams, and the host driver for the
|
||||
* real xhci controller will likely disallow allocating more streams then
|
||||
* the device can handle.
|
||||
*
|
||||
* So we limit the requested nr_streams to the maximum number the device
|
||||
* can handle.
|
||||
*/
|
||||
if (req_nr_streams > dev_max_streams) {
|
||||
req_nr_streams = dev_max_streams;
|
||||
}
|
||||
|
||||
r = usb_device_alloc_streams(eps[0]->dev, eps, nr_eps, req_nr_streams);
|
||||
if (r != 0) {
|
||||
fprintf(stderr, "xhci: alloc streams failed\n");
|
||||
return CC_RESOURCE_ERROR;
|
||||
}
|
||||
|
||||
return CC_SUCCESS;
|
||||
}
|
||||
|
||||
static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx,
|
||||
unsigned int streamid,
|
||||
uint32_t *cc_error)
|
||||
@@ -1495,7 +1600,8 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
|
||||
}
|
||||
|
||||
if (!xhci->slots[slotid-1].uport ||
|
||||
!xhci->slots[slotid-1].uport->dev) {
|
||||
!xhci->slots[slotid-1].uport->dev ||
|
||||
!xhci->slots[slotid-1].uport->dev->attached) {
|
||||
return CC_USB_TRANSACTION_ERROR;
|
||||
}
|
||||
|
||||
@@ -1982,6 +2088,14 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the device has been detached, but the guest has not noticed this
|
||||
yet the 2 above checks will succeed, but we must NOT continue */
|
||||
if (!xhci->slots[slotid - 1].uport ||
|
||||
!xhci->slots[slotid - 1].uport->dev ||
|
||||
!xhci->slots[slotid - 1].uport->dev->attached) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (epctx->retry) {
|
||||
XHCITransfer *xfer = epctx->retry;
|
||||
|
||||
@@ -2206,7 +2320,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
|
||||
trace_usb_xhci_slot_address(slotid, uport->path);
|
||||
|
||||
dev = uport->dev;
|
||||
if (!dev) {
|
||||
if (!dev || !dev->attached) {
|
||||
fprintf(stderr, "xhci: port %s not connected\n", uport->path);
|
||||
return CC_USB_TRANSACTION_ERROR;
|
||||
}
|
||||
@@ -2313,6 +2427,8 @@ static TRBCCode xhci_configure_slot(XHCIState *xhci, unsigned int slotid,
|
||||
return CC_CONTEXT_STATE_ERROR;
|
||||
}
|
||||
|
||||
xhci_free_device_streams(xhci, slotid, ictl_ctx[0] | ictl_ctx[1]);
|
||||
|
||||
for (i = 2; i <= 31; i++) {
|
||||
if (ictl_ctx[0] & (1<<i)) {
|
||||
xhci_disable_ep(xhci, slotid, i);
|
||||
@@ -2334,6 +2450,16 @@ static TRBCCode xhci_configure_slot(XHCIState *xhci, unsigned int slotid,
|
||||
}
|
||||
}
|
||||
|
||||
res = xhci_alloc_device_streams(xhci, slotid, ictl_ctx[1]);
|
||||
if (res != CC_SUCCESS) {
|
||||
for (i = 2; i <= 31; i++) {
|
||||
if (ictl_ctx[1] & (1 << i)) {
|
||||
xhci_disable_ep(xhci, slotid, i);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
slot_ctx[3] &= ~(SLOT_STATE_MASK << SLOT_STATE_SHIFT);
|
||||
slot_ctx[3] |= SLOT_CONFIGURED << SLOT_STATE_SHIFT;
|
||||
slot_ctx[0] &= ~(SLOT_CONTEXT_ENTRIES_MASK << SLOT_CONTEXT_ENTRIES_SHIFT);
|
||||
@@ -3016,6 +3142,14 @@ static void xhci_oper_write(void *ptr, hwaddr reg,
|
||||
} else if (!(val & USBCMD_RS) && (xhci->usbcmd & USBCMD_RS)) {
|
||||
xhci_stop(xhci);
|
||||
}
|
||||
if (val & USBCMD_CSS) {
|
||||
/* save state */
|
||||
xhci->usbsts &= ~USBSTS_SRE;
|
||||
}
|
||||
if (val & USBCMD_CRS) {
|
||||
/* restore state */
|
||||
xhci->usbsts |= USBSTS_SRE;
|
||||
}
|
||||
xhci->usbcmd = val & 0xc0f;
|
||||
xhci_mfwrap_update(xhci);
|
||||
if (val & USBCMD_HCRST) {
|
||||
|
||||
@@ -570,7 +570,8 @@ static void xen_pt_region_update(XenPCIPassthroughState *s,
|
||||
if (args.rc) {
|
||||
XEN_PT_WARN(d, "Region: %d (addr: %#"FMT_PCIBUS
|
||||
", len: %#"FMT_PCIBUS") is overlapped.\n",
|
||||
bar, sec->offset_within_address_space, sec->size);
|
||||
bar, sec->offset_within_address_space,
|
||||
int128_get64(sec->size));
|
||||
}
|
||||
|
||||
if (d->io_regions[bar].type & PCI_BASE_ADDRESS_SPACE_IO) {
|
||||
|
||||
@@ -74,6 +74,10 @@ static int xen_pv_init(PCIDevice *pci_dev)
|
||||
XenPVDevice *d = XEN_PV_DEVICE(pci_dev);
|
||||
uint8_t *pci_conf;
|
||||
|
||||
/* device-id property must always be supplied */
|
||||
if (d->device_id == 0xffff)
|
||||
return -1;
|
||||
|
||||
pci_conf = pci_dev->config;
|
||||
|
||||
pci_set_word(pci_conf + PCI_VENDOR_ID, d->vendor_id);
|
||||
@@ -99,7 +103,7 @@ static int xen_pv_init(PCIDevice *pci_dev)
|
||||
|
||||
static Property xen_pv_props[] = {
|
||||
DEFINE_PROP_UINT16("vendor-id", XenPVDevice, vendor_id, PCI_VENDOR_ID_XEN),
|
||||
DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, PCI_DEVICE_ID_XEN_PVDEVICE),
|
||||
DEFINE_PROP_UINT16("device-id", XenPVDevice, device_id, 0xffff),
|
||||
DEFINE_PROP_UINT8("revision", XenPVDevice, revision, 0x01),
|
||||
DEFINE_PROP_UINT32("size", XenPVDevice, size, 0x400000),
|
||||
DEFINE_PROP_END_OF_LIST()
|
||||
|
||||
@@ -18,6 +18,22 @@ typedef struct BlockDriverInfo {
|
||||
/* offset at which the VM state can be saved (0 if not possible) */
|
||||
int64_t vm_state_offset;
|
||||
bool is_dirty;
|
||||
/*
|
||||
* True if unallocated blocks read back as zeroes. This is equivalent
|
||||
* to the the LBPRZ flag in the SCSI logical block provisioning page.
|
||||
*/
|
||||
bool unallocated_blocks_are_zero;
|
||||
/*
|
||||
* True if the driver can optimize writing zeroes by unmapping
|
||||
* sectors. This is equivalent to the BLKDISCARDZEROES ioctl in Linux
|
||||
* with the difference that in qemu a discard is allowed to silently
|
||||
* fail. Therefore we have to use bdrv_write_zeroes with the
|
||||
* BDRV_REQ_MAY_UNMAP flag for an optimized zero write with unmapping.
|
||||
* After this call the driver has to guarantee that the contents read
|
||||
* back as zero. It is additionally required that the block device is
|
||||
* opened with BDRV_O_UNMAP flag for this to work.
|
||||
*/
|
||||
bool can_write_zeroes_with_unmap;
|
||||
} BlockDriverInfo;
|
||||
|
||||
typedef struct BlockFragInfo {
|
||||
@@ -62,6 +78,18 @@ typedef struct BlockDevOps {
|
||||
void (*resize_cb)(void *opaque);
|
||||
} BlockDevOps;
|
||||
|
||||
typedef enum {
|
||||
BDRV_REQ_COPY_ON_READ = 0x1,
|
||||
BDRV_REQ_ZERO_WRITE = 0x2,
|
||||
/* The BDRV_REQ_MAY_UNMAP flag is used to indicate that the block driver
|
||||
* is allowed to optimize a write zeroes request by unmapping (discarding)
|
||||
* blocks if it is guaranteed that the result will read back as
|
||||
* zeroes. The flag is only passed to the driver if the block device is
|
||||
* opened with BDRV_O_UNMAP.
|
||||
*/
|
||||
BDRV_REQ_MAY_UNMAP = 0x4,
|
||||
} BdrvRequestFlags;
|
||||
|
||||
#define BDRV_O_RDWR 0x0002
|
||||
#define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */
|
||||
#define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */
|
||||
@@ -187,7 +215,11 @@ int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
|
||||
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors);
|
||||
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors);
|
||||
int nb_sectors, BdrvRequestFlags flags);
|
||||
BlockDriverAIOCB *bdrv_aio_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, BdrvRequestFlags flags,
|
||||
BlockDriverCompletionFunc *cb, void *opaque);
|
||||
int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
|
||||
int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov);
|
||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||
void *buf, int count);
|
||||
@@ -209,7 +241,7 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
* because it may allocate memory for the entire region.
|
||||
*/
|
||||
int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors);
|
||||
int nb_sectors, BdrvRequestFlags flags);
|
||||
BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
|
||||
const char *backing_file);
|
||||
int bdrv_get_backing_file_depth(BlockDriverState *bs);
|
||||
@@ -282,6 +314,7 @@ typedef struct BlockRequest {
|
||||
/* Fields to be filled by multiwrite caller */
|
||||
int64_t sector;
|
||||
int nb_sectors;
|
||||
int flags;
|
||||
QEMUIOVector *qiov;
|
||||
BlockDriverCompletionFunc *cb;
|
||||
void *opaque;
|
||||
@@ -316,6 +349,8 @@ int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
|
||||
int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
|
||||
int bdrv_has_zero_init_1(BlockDriverState *bs);
|
||||
int bdrv_has_zero_init(BlockDriverState *bs);
|
||||
bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs);
|
||||
bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs);
|
||||
int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, int *pnum);
|
||||
int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
@@ -388,12 +423,16 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size);
|
||||
bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov);
|
||||
|
||||
struct HBitmapIter;
|
||||
void bdrv_set_dirty_tracking(BlockDriverState *bs, int granularity);
|
||||
int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
|
||||
typedef struct BdrvDirtyBitmap BdrvDirtyBitmap;
|
||||
BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, int granularity);
|
||||
void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
|
||||
BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
|
||||
int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector);
|
||||
void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors);
|
||||
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors);
|
||||
void bdrv_dirty_iter_init(BlockDriverState *bs, struct HBitmapIter *hbi);
|
||||
int64_t bdrv_get_dirty_count(BlockDriverState *bs);
|
||||
void bdrv_dirty_iter_init(BlockDriverState *bs,
|
||||
BdrvDirtyBitmap *bitmap, struct HBitmapIter *hbi);
|
||||
int64_t bdrv_get_dirty_count(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
|
||||
|
||||
void bdrv_enable_copy_on_read(BlockDriverState *bs);
|
||||
void bdrv_disable_copy_on_read(BlockDriverState *bs);
|
||||
@@ -484,6 +523,7 @@ void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
|
||||
|
||||
int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,
|
||||
const char *tag);
|
||||
int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag);
|
||||
int bdrv_debug_resume(BlockDriverState *bs, const char *tag);
|
||||
bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag);
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#define BLOCK_OPT_COMPAT_LEVEL "compat"
|
||||
#define BLOCK_OPT_LAZY_REFCOUNTS "lazy_refcounts"
|
||||
#define BLOCK_OPT_ADAPTER_TYPE "adapter_type"
|
||||
#define BLOCK_OPT_REDUNDANCY "redundancy"
|
||||
|
||||
typedef struct BdrvTrackedRequest {
|
||||
BlockDriverState *bs;
|
||||
@@ -130,7 +131,7 @@ struct BlockDriver {
|
||||
* instead.
|
||||
*/
|
||||
int coroutine_fn (*bdrv_co_write_zeroes)(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors);
|
||||
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags);
|
||||
int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors);
|
||||
int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
|
||||
@@ -175,7 +176,9 @@ struct BlockDriver {
|
||||
int (*bdrv_snapshot_list)(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo **psn_info);
|
||||
int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
|
||||
const char *snapshot_name);
|
||||
const char *snapshot_id,
|
||||
const char *name,
|
||||
Error **errp);
|
||||
int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
|
||||
ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs);
|
||||
|
||||
@@ -218,6 +221,8 @@ struct BlockDriver {
|
||||
/* TODO Better pass a option string/QDict/QemuOpts to add any rule? */
|
||||
int (*bdrv_debug_breakpoint)(BlockDriverState *bs, const char *event,
|
||||
const char *tag);
|
||||
int (*bdrv_debug_remove_breakpoint)(BlockDriverState *bs,
|
||||
const char *tag);
|
||||
int (*bdrv_debug_resume)(BlockDriverState *bs, const char *tag);
|
||||
bool (*bdrv_debug_is_suspended)(BlockDriverState *bs, const char *tag);
|
||||
|
||||
@@ -230,6 +235,23 @@ struct BlockDriver {
|
||||
QLIST_ENTRY(BlockDriver) list;
|
||||
};
|
||||
|
||||
typedef struct BlockLimits {
|
||||
/* maximum number of sectors that can be discarded at once */
|
||||
int max_discard;
|
||||
|
||||
/* optimal alignment for discard requests in sectors */
|
||||
int64_t discard_alignment;
|
||||
|
||||
/* maximum number of sectors that can zeroized at once */
|
||||
int max_write_zeroes;
|
||||
|
||||
/* optimal alignment for write zeroes requests in sectors */
|
||||
int64_t write_zeroes_alignment;
|
||||
|
||||
/* optimal transfer length in sectors */
|
||||
int opt_transfer_length;
|
||||
} BlockLimits;
|
||||
|
||||
/*
|
||||
* Note: the function bdrv_append() copies and swaps contents of
|
||||
* BlockDriverStates, so if you add new fields to this struct, please
|
||||
@@ -283,6 +305,9 @@ struct BlockDriverState {
|
||||
uint64_t total_time_ns[BDRV_MAX_IOTYPE];
|
||||
uint64_t wr_highest_sector;
|
||||
|
||||
/* I/O Limits */
|
||||
BlockLimits bl;
|
||||
|
||||
/* Whether the disk can expand beyond total_sectors */
|
||||
int growable;
|
||||
|
||||
@@ -301,7 +326,7 @@ struct BlockDriverState {
|
||||
bool iostatus_enabled;
|
||||
BlockDeviceIoStatus iostatus;
|
||||
char device_name[32];
|
||||
HBitmap *dirty_bitmap;
|
||||
QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps;
|
||||
int refcnt;
|
||||
int in_use; /* users other than guest access, eg. block migration */
|
||||
QTAILQ_ENTRY(BlockDriverState) list;
|
||||
|
||||
@@ -105,7 +105,6 @@ bool qemu_in_coroutine(void);
|
||||
*/
|
||||
typedef struct CoQueue {
|
||||
QTAILQ_HEAD(, Coroutine) entries;
|
||||
AioContext *ctx;
|
||||
} CoQueue;
|
||||
|
||||
/**
|
||||
@@ -120,12 +119,6 @@ void qemu_co_queue_init(CoQueue *queue);
|
||||
*/
|
||||
void coroutine_fn qemu_co_queue_wait(CoQueue *queue);
|
||||
|
||||
/**
|
||||
* Adds the current coroutine to the head of the CoQueue and transfers control to the
|
||||
* caller of the coroutine.
|
||||
*/
|
||||
void coroutine_fn qemu_co_queue_wait_insert_head(CoQueue *queue);
|
||||
|
||||
/**
|
||||
* Restarts the next coroutine in the CoQueue and removes it from the queue.
|
||||
*
|
||||
|
||||
@@ -27,6 +27,14 @@
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/option.h"
|
||||
|
||||
|
||||
#define SNAPSHOT_OPT_BASE "snapshot."
|
||||
#define SNAPSHOT_OPT_ID "snapshot.id"
|
||||
#define SNAPSHOT_OPT_NAME "snapshot.name"
|
||||
|
||||
extern QemuOptsList internal_snapshot_opts;
|
||||
|
||||
typedef struct QEMUSnapshotInfo {
|
||||
char id_str[128]; /* unique snapshot id */
|
||||
@@ -61,5 +69,10 @@ void bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs,
|
||||
int bdrv_snapshot_list(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo **psn_info);
|
||||
int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
||||
const char *snapshot_name);
|
||||
const char *snapshot_id,
|
||||
const char *name,
|
||||
Error **errp);
|
||||
int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
|
||||
const char *id_or_name,
|
||||
Error **errp);
|
||||
#endif
|
||||
|
||||
@@ -411,6 +411,65 @@ typedef struct {
|
||||
#define R_SPARC_5 44
|
||||
#define R_SPARC_6 45
|
||||
|
||||
/* Bits present in AT_HWCAP for ARM. */
|
||||
|
||||
#define HWCAP_ARM_SWP (1 << 0)
|
||||
#define HWCAP_ARM_HALF (1 << 1)
|
||||
#define HWCAP_ARM_THUMB (1 << 2)
|
||||
#define HWCAP_ARM_26BIT (1 << 3)
|
||||
#define HWCAP_ARM_FAST_MULT (1 << 4)
|
||||
#define HWCAP_ARM_FPA (1 << 5)
|
||||
#define HWCAP_ARM_VFP (1 << 6)
|
||||
#define HWCAP_ARM_EDSP (1 << 7)
|
||||
#define HWCAP_ARM_JAVA (1 << 8)
|
||||
#define HWCAP_ARM_IWMMXT (1 << 9)
|
||||
#define HWCAP_ARM_CRUNCH (1 << 10)
|
||||
#define HWCAP_ARM_THUMBEE (1 << 11)
|
||||
#define HWCAP_ARM_NEON (1 << 12)
|
||||
#define HWCAP_ARM_VFPv3 (1 << 13)
|
||||
#define HWCAP_ARM_VFPv3D16 (1 << 14) /* also set for VFPv4-D16 */
|
||||
#define HWCAP_ARM_TLS (1 << 15)
|
||||
#define HWCAP_ARM_VFPv4 (1 << 16)
|
||||
#define HWCAP_ARM_IDIVA (1 << 17)
|
||||
#define HWCAP_ARM_IDIVT (1 << 18)
|
||||
#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT)
|
||||
#define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs */
|
||||
#define HWCAP_LPAE (1 << 20)
|
||||
|
||||
/* Bits present in AT_HWCAP for PowerPC. */
|
||||
|
||||
#define PPC_FEATURE_32 0x80000000
|
||||
#define PPC_FEATURE_64 0x40000000
|
||||
#define PPC_FEATURE_601_INSTR 0x20000000
|
||||
#define PPC_FEATURE_HAS_ALTIVEC 0x10000000
|
||||
#define PPC_FEATURE_HAS_FPU 0x08000000
|
||||
#define PPC_FEATURE_HAS_MMU 0x04000000
|
||||
#define PPC_FEATURE_HAS_4xxMAC 0x02000000
|
||||
#define PPC_FEATURE_UNIFIED_CACHE 0x01000000
|
||||
#define PPC_FEATURE_HAS_SPE 0x00800000
|
||||
#define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000
|
||||
#define PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000
|
||||
#define PPC_FEATURE_NO_TB 0x00100000
|
||||
#define PPC_FEATURE_POWER4 0x00080000
|
||||
#define PPC_FEATURE_POWER5 0x00040000
|
||||
#define PPC_FEATURE_POWER5_PLUS 0x00020000
|
||||
#define PPC_FEATURE_CELL 0x00010000
|
||||
#define PPC_FEATURE_BOOKE 0x00008000
|
||||
#define PPC_FEATURE_SMT 0x00004000
|
||||
#define PPC_FEATURE_ICACHE_SNOOP 0x00002000
|
||||
#define PPC_FEATURE_ARCH_2_05 0x00001000
|
||||
#define PPC_FEATURE_PA6T 0x00000800
|
||||
#define PPC_FEATURE_HAS_DFP 0x00000400
|
||||
#define PPC_FEATURE_POWER6_EXT 0x00000200
|
||||
#define PPC_FEATURE_ARCH_2_06 0x00000100
|
||||
#define PPC_FEATURE_HAS_VSX 0x00000080
|
||||
|
||||
#define PPC_FEATURE_PSERIES_PERFMON_COMPAT \
|
||||
0x00000040
|
||||
|
||||
#define PPC_FEATURE_TRUE_LE 0x00000002
|
||||
#define PPC_FEATURE_PPC_LE 0x00000001
|
||||
|
||||
/* Bits present in AT_HWCAP, primarily for Sparc32. */
|
||||
|
||||
#define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
|
||||
@@ -420,6 +479,20 @@ typedef struct {
|
||||
#define HWCAP_SPARC_V9 16
|
||||
#define HWCAP_SPARC_ULTRA3 32
|
||||
|
||||
/* Bits present in AT_HWCAP for s390. */
|
||||
|
||||
#define HWCAP_S390_ESAN3 1
|
||||
#define HWCAP_S390_ZARCH 2
|
||||
#define HWCAP_S390_STFLE 4
|
||||
#define HWCAP_S390_MSA 8
|
||||
#define HWCAP_S390_LDISP 16
|
||||
#define HWCAP_S390_EIMM 32
|
||||
#define HWCAP_S390_DFP 64
|
||||
#define HWCAP_S390_HPAGE 128
|
||||
#define HWCAP_S390_ETF3EH 256
|
||||
#define HWCAP_S390_HIGH_GPRS 512
|
||||
#define HWCAP_S390_TE 1024
|
||||
|
||||
/*
|
||||
* 68k ELF relocation types
|
||||
*/
|
||||
|
||||
@@ -65,13 +65,13 @@ struct SerialState {
|
||||
/* Interrupt trigger level for recv_fifo */
|
||||
uint8_t recv_fifo_itl;
|
||||
|
||||
struct QEMUTimer *fifo_timeout_timer;
|
||||
QEMUTimer *fifo_timeout_timer;
|
||||
int timeout_ipending; /* timeout interrupt pending state */
|
||||
|
||||
uint64_t char_transmit_time; /* time to transmit a char in ticks */
|
||||
int poll_msl;
|
||||
|
||||
struct QEMUTimer *modem_status_poll;
|
||||
QEMUTimer *modem_status_poll;
|
||||
MemoryRegion io;
|
||||
};
|
||||
|
||||
|
||||
@@ -146,7 +146,6 @@
|
||||
|
||||
#define PCI_VENDOR_ID_XEN 0x5853
|
||||
#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001
|
||||
#define PCI_DEVICE_ID_XEN_PVDEVICE 0x0002
|
||||
|
||||
#define PCI_VENDOR_ID_NEC 0x1033
|
||||
#define PCI_DEVICE_ID_NEC_UPD720200 0x0194
|
||||
|
||||
@@ -24,10 +24,10 @@ struct ppc_tb_t {
|
||||
/* Decrementer management */
|
||||
uint64_t decr_next; /* Tick for next decr interrupt */
|
||||
uint32_t decr_freq; /* decrementer frequency */
|
||||
struct QEMUTimer *decr_timer;
|
||||
QEMUTimer *decr_timer;
|
||||
/* Hypervisor decrementer management */
|
||||
uint64_t hdecr_next; /* Tick for next hdecr interrupt */
|
||||
struct QEMUTimer *hdecr_timer;
|
||||
QEMUTimer *hdecr_timer;
|
||||
uint64_t purr_load;
|
||||
uint64_t purr_start;
|
||||
void *opaque;
|
||||
|
||||
@@ -199,12 +199,16 @@ extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED;
|
||||
extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT;
|
||||
/* Illegal request, medium removal prevented */
|
||||
extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED;
|
||||
/* Illegal request, Invalid Transfer Tag */
|
||||
extern const struct SCSISense sense_code_INVALID_TAG;
|
||||
/* Command aborted, I/O process terminated */
|
||||
extern const struct SCSISense sense_code_IO_ERROR;
|
||||
/* Command aborted, I_T Nexus loss occurred */
|
||||
extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;
|
||||
/* Command aborted, Logical Unit failure */
|
||||
extern const struct SCSISense sense_code_LUN_FAILURE;
|
||||
/* Command aborted, Overlapped Commands Attempted */
|
||||
extern const struct SCSISense sense_code_OVERLAPPED_COMMANDS;
|
||||
/* LUN not ready, Capacity data has changed */
|
||||
extern const struct SCSISense sense_code_CAPACITY_CHANGED;
|
||||
/* LUN not ready, Medium not present */
|
||||
|
||||
@@ -102,17 +102,26 @@
|
||||
|
||||
#define DeviceRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
|
||||
#define DeviceOutRequest ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
|
||||
#define InterfaceRequest \
|
||||
#define VendorDeviceRequest ((USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE)<<8)
|
||||
#define VendorDeviceOutRequest \
|
||||
((USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_DEVICE)<<8)
|
||||
|
||||
#define InterfaceRequest \
|
||||
((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
|
||||
#define InterfaceOutRequest \
|
||||
((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
|
||||
#define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
|
||||
#define EndpointOutRequest \
|
||||
((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
|
||||
#define ClassInterfaceRequest \
|
||||
((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
|
||||
#define ClassInterfaceOutRequest \
|
||||
((USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
|
||||
#define VendorInterfaceRequest \
|
||||
((USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE)<<8)
|
||||
#define VendorInterfaceOutRequest \
|
||||
((USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE)<<8)
|
||||
|
||||
#define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
|
||||
#define EndpointOutRequest \
|
||||
((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
|
||||
|
||||
#define USB_REQ_GET_STATUS 0x00
|
||||
#define USB_REQ_CLEAR_FEATURE 0x01
|
||||
@@ -189,6 +198,7 @@ struct USBEndpoint {
|
||||
uint8_t type;
|
||||
uint8_t ifnum;
|
||||
int max_packet_size;
|
||||
int max_streams;
|
||||
bool pipeline;
|
||||
bool halted;
|
||||
USBDevice *dev;
|
||||
@@ -314,6 +324,14 @@ typedef struct USBDeviceClass {
|
||||
*/
|
||||
void (*ep_stopped)(USBDevice *dev, USBEndpoint *ep);
|
||||
|
||||
/*
|
||||
* Called by the hcd to alloc / free streams on a bulk endpoint.
|
||||
* Optional may be NULL.
|
||||
*/
|
||||
int (*alloc_streams)(USBDevice *dev, USBEndpoint **eps, int nr_eps,
|
||||
int streams);
|
||||
void (*free_streams)(USBDevice *dev, USBEndpoint **eps, int nr_eps);
|
||||
|
||||
const char *product_desc;
|
||||
const USBDesc *usb_desc;
|
||||
} USBDeviceClass;
|
||||
@@ -421,6 +439,8 @@ void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum);
|
||||
void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep,
|
||||
uint16_t raw);
|
||||
int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep);
|
||||
void usb_ep_set_max_streams(USBDevice *dev, int pid, int ep, uint8_t raw);
|
||||
int usb_ep_get_max_streams(USBDevice *dev, int pid, int ep);
|
||||
void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, bool enabled);
|
||||
void usb_ep_set_halted(USBDevice *dev, int pid, int ep, bool halted);
|
||||
USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep,
|
||||
@@ -550,6 +570,10 @@ void usb_device_flush_ep_queue(USBDevice *dev, USBEndpoint *ep);
|
||||
|
||||
void usb_device_ep_stopped(USBDevice *dev, USBEndpoint *ep);
|
||||
|
||||
int usb_device_alloc_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps,
|
||||
int streams);
|
||||
void usb_device_free_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps);
|
||||
|
||||
const char *usb_device_get_product_desc(USBDevice *dev);
|
||||
|
||||
const USBDesc *usb_device_get_usb_desc(USBDevice *dev);
|
||||
|
||||
@@ -12,7 +12,7 @@ struct qemu_cache_conf {
|
||||
|
||||
extern struct qemu_cache_conf qemu_cache_conf;
|
||||
|
||||
void qemu_cache_utils_init(char **envp);
|
||||
void qemu_cache_utils_init(void);
|
||||
|
||||
/* mildly adjusted code from tcg-dyngen.c */
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
@@ -38,7 +38,7 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
}
|
||||
|
||||
#else
|
||||
#define qemu_cache_utils_init(envp) do { (void) (envp); } while (0)
|
||||
#define qemu_cache_utils_init() do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* QEMU_CACHE_UTILS_H */
|
||||
|
||||
@@ -215,4 +215,29 @@ bool fips_get_state(void);
|
||||
*/
|
||||
char *qemu_get_local_state_pathname(const char *relative_pathname);
|
||||
|
||||
/**
|
||||
* qemu_getauxval:
|
||||
* @type: the auxiliary vector key to lookup
|
||||
*
|
||||
* Search the auxiliary vector for @type, returning the value
|
||||
* or 0 if @type is not present.
|
||||
*/
|
||||
#if defined(CONFIG_GETAUXVAL) || defined(__linux__)
|
||||
unsigned long qemu_getauxval(unsigned long type);
|
||||
#else
|
||||
static inline unsigned long qemu_getauxval(unsigned long type) { return 0; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* qemu_init_auxval:
|
||||
* @envp: the third argument to main
|
||||
*
|
||||
* If supported and required, locate the auxiliary vector at program startup.
|
||||
*/
|
||||
#if defined(CONFIG_GETAUXVAL) || !defined(__linux__)
|
||||
static inline void qemu_init_auxval(char **envp) { }
|
||||
#else
|
||||
void qemu_init_auxval(char **envp);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qemu/notify.h"
|
||||
#include "monitor/monitor.h"
|
||||
#include "trace.h"
|
||||
#include "qapi-types.h"
|
||||
#include "qapi/error.h"
|
||||
|
||||
|
||||
30
kvm-all.c
30
kvm-all.c
@@ -72,7 +72,8 @@ typedef struct kvm_dirty_log KVMDirtyLog;
|
||||
|
||||
struct KVMState
|
||||
{
|
||||
KVMSlot slots[32];
|
||||
KVMSlot *slots;
|
||||
int nr_slots;
|
||||
int fd;
|
||||
int vmfd;
|
||||
int coalesced_mmio;
|
||||
@@ -125,7 +126,7 @@ static KVMSlot *kvm_alloc_slot(KVMState *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
|
||||
for (i = 0; i < s->nr_slots; i++) {
|
||||
if (s->slots[i].memory_size == 0) {
|
||||
return &s->slots[i];
|
||||
}
|
||||
@@ -141,7 +142,7 @@ static KVMSlot *kvm_lookup_matching_slot(KVMState *s,
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
|
||||
for (i = 0; i < s->nr_slots; i++) {
|
||||
KVMSlot *mem = &s->slots[i];
|
||||
|
||||
if (start_addr == mem->start_addr &&
|
||||
@@ -163,7 +164,7 @@ static KVMSlot *kvm_lookup_overlapping_slot(KVMState *s,
|
||||
KVMSlot *found = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
|
||||
for (i = 0; i < s->nr_slots; i++) {
|
||||
KVMSlot *mem = &s->slots[i];
|
||||
|
||||
if (mem->memory_size == 0 ||
|
||||
@@ -185,7 +186,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
|
||||
for (i = 0; i < s->nr_slots; i++) {
|
||||
KVMSlot *mem = &s->slots[i];
|
||||
|
||||
if (ram >= mem->ram && ram < mem->ram + mem->memory_size) {
|
||||
@@ -357,7 +358,7 @@ static int kvm_set_migration_log(int enable)
|
||||
|
||||
s->migration_log = enable;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
|
||||
for (i = 0; i < s->nr_slots; i++) {
|
||||
mem = &s->slots[i];
|
||||
|
||||
if (!mem->memory_size) {
|
||||
@@ -1383,9 +1384,6 @@ int kvm_init(void)
|
||||
#ifdef KVM_CAP_SET_GUEST_DEBUG
|
||||
QTAILQ_INIT(&s->kvm_sw_breakpoints);
|
||||
#endif
|
||||
for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
|
||||
s->slots[i].slot = i;
|
||||
}
|
||||
s->vmfd = -1;
|
||||
s->fd = qemu_open("/dev/kvm", O_RDWR);
|
||||
if (s->fd == -1) {
|
||||
@@ -1409,6 +1407,19 @@ int kvm_init(void)
|
||||
goto err;
|
||||
}
|
||||
|
||||
s->nr_slots = kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS);
|
||||
|
||||
/* If unspecified, use the default value */
|
||||
if (!s->nr_slots) {
|
||||
s->nr_slots = 32;
|
||||
}
|
||||
|
||||
s->slots = g_malloc0(s->nr_slots * sizeof(KVMSlot));
|
||||
|
||||
for (i = 0; i < s->nr_slots; i++) {
|
||||
s->slots[i].slot = i;
|
||||
}
|
||||
|
||||
/* check the vcpu limits */
|
||||
soft_vcpus_limit = kvm_recommended_vcpus(s);
|
||||
hard_vcpus_limit = kvm_max_vcpus(s);
|
||||
@@ -1527,6 +1538,7 @@ err:
|
||||
if (s->fd != -1) {
|
||||
close(s->fd);
|
||||
}
|
||||
g_free(s->slots);
|
||||
g_free(s);
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -189,7 +189,6 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
|
||||
pki_applet->sign_buffer = sign_buffer;
|
||||
pki_applet->sign_buffer_len = size;
|
||||
*response = vcard_make_response(VCARD7816_STATUS_SUCCESS);
|
||||
ret = VCARD_DONE;
|
||||
break;
|
||||
case 0x00:
|
||||
/* we now have the whole buffer, do the operation, result will be
|
||||
|
||||
@@ -934,7 +934,6 @@ vcard_emul_init(const VCardEmulOptions *options)
|
||||
vreader = vreader_new(options->vreader[i].vname, vreader_emul,
|
||||
vreader_emul_delete);
|
||||
vreader_add_reader(vreader);
|
||||
cert_count = options->vreader[i].cert_count;
|
||||
|
||||
vcard_emul_alloc_arrays(&certs, &cert_len, &keys,
|
||||
options->vreader[i].cert_count);
|
||||
|
||||
@@ -63,7 +63,8 @@ struct kvm_regs {
|
||||
|
||||
/* Supported Processor Types */
|
||||
#define KVM_ARM_TARGET_CORTEX_A15 0
|
||||
#define KVM_ARM_NUM_TARGETS 1
|
||||
#define KVM_ARM_TARGET_CORTEX_A7 1
|
||||
#define KVM_ARM_NUM_TARGETS 2
|
||||
|
||||
/* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */
|
||||
#define KVM_ARM_DEVICE_TYPE_SHIFT 0
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
#define EV_SUCCESS 0
|
||||
#define EV_EPERM 1 /* Operation not permitted */
|
||||
#define EV_ENOENT 2 /* Entry Not Found */
|
||||
#define EV_EIO 3 /* I/O error occurred */
|
||||
#define EV_EIO 3 /* I/O error occured */
|
||||
#define EV_EAGAIN 4 /* The operation had insufficient
|
||||
* resources to complete and should be
|
||||
* retried
|
||||
@@ -89,7 +89,7 @@
|
||||
#define EV_ENODEV 7 /* No such device */
|
||||
#define EV_EINVAL 8 /* An argument supplied to the hcall
|
||||
was out of range or invalid */
|
||||
#define EV_INTERNAL 9 /* An internal error occurred */
|
||||
#define EV_INTERNAL 9 /* An internal error occured */
|
||||
#define EV_CONFIG 10 /* A configuration error was detected */
|
||||
#define EV_INVALID_STATE 11 /* The object is in an invalid state */
|
||||
#define EV_UNIMPLEMENTED 12 /* Unimplemented hypercall */
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#define __KVM_HAVE_PPC_SMT
|
||||
#define __KVM_HAVE_IRQCHIP
|
||||
#define __KVM_HAVE_IRQ_LINE
|
||||
#define __KVM_HAVE_GUEST_DEBUG
|
||||
|
||||
struct kvm_regs {
|
||||
__u64 pc;
|
||||
@@ -269,7 +270,24 @@ struct kvm_fpu {
|
||||
__u64 fpr[32];
|
||||
};
|
||||
|
||||
/*
|
||||
* Defines for h/w breakpoint, watchpoint (read, write or both) and
|
||||
* software breakpoint.
|
||||
* These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
|
||||
* for KVM_DEBUG_EXIT.
|
||||
*/
|
||||
#define KVMPPC_DEBUG_NONE 0x0
|
||||
#define KVMPPC_DEBUG_BREAKPOINT (1UL << 1)
|
||||
#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2)
|
||||
#define KVMPPC_DEBUG_WATCH_READ (1UL << 3)
|
||||
struct kvm_debug_exit_arch {
|
||||
__u64 address;
|
||||
/*
|
||||
* exiting to userspace because of h/w breakpoint, watchpoint
|
||||
* (read, write or both) and software breakpoint.
|
||||
*/
|
||||
__u32 status;
|
||||
__u32 reserved;
|
||||
};
|
||||
|
||||
/* for KVM_SET_GUEST_DEBUG */
|
||||
@@ -281,10 +299,6 @@ struct kvm_guest_debug_arch {
|
||||
* Type denotes h/w breakpoint, read watchpoint, write
|
||||
* watchpoint or watchpoint (both read and write).
|
||||
*/
|
||||
#define KVMPPC_DEBUG_NONE 0x0
|
||||
#define KVMPPC_DEBUG_BREAKPOINT (1UL << 1)
|
||||
#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2)
|
||||
#define KVMPPC_DEBUG_WATCH_READ (1UL << 3)
|
||||
__u32 type;
|
||||
__u32 reserved;
|
||||
} bp[16];
|
||||
@@ -429,6 +443,11 @@ struct kvm_get_htab_header {
|
||||
#define KVM_REG_PPC_MMCR0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
|
||||
#define KVM_REG_PPC_MMCR1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
|
||||
#define KVM_REG_PPC_MMCRA (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
|
||||
#define KVM_REG_PPC_MMCR2 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
|
||||
#define KVM_REG_PPC_MMCRS (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x14)
|
||||
#define KVM_REG_PPC_SIAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x15)
|
||||
#define KVM_REG_PPC_SDAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x16)
|
||||
#define KVM_REG_PPC_SIER (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x17)
|
||||
|
||||
#define KVM_REG_PPC_PMC1 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x18)
|
||||
#define KVM_REG_PPC_PMC2 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x19)
|
||||
@@ -499,6 +518,65 @@ struct kvm_get_htab_header {
|
||||
#define KVM_REG_PPC_TLB3PS (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9a)
|
||||
#define KVM_REG_PPC_EPTCFG (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9b)
|
||||
|
||||
/* Timebase offset */
|
||||
#define KVM_REG_PPC_TB_OFFSET (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9c)
|
||||
|
||||
/* POWER8 registers */
|
||||
#define KVM_REG_PPC_SPMC1 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9d)
|
||||
#define KVM_REG_PPC_SPMC2 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9e)
|
||||
#define KVM_REG_PPC_IAMR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9f)
|
||||
#define KVM_REG_PPC_TFHAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa0)
|
||||
#define KVM_REG_PPC_TFIAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa1)
|
||||
#define KVM_REG_PPC_TEXASR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa2)
|
||||
#define KVM_REG_PPC_FSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa3)
|
||||
#define KVM_REG_PPC_PSPB (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xa4)
|
||||
#define KVM_REG_PPC_EBBHR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa5)
|
||||
#define KVM_REG_PPC_EBBRR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa6)
|
||||
#define KVM_REG_PPC_BESCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa7)
|
||||
#define KVM_REG_PPC_TAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa8)
|
||||
#define KVM_REG_PPC_DPDES (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa9)
|
||||
#define KVM_REG_PPC_DAWR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaa)
|
||||
#define KVM_REG_PPC_DAWRX (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xab)
|
||||
#define KVM_REG_PPC_CIABR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xac)
|
||||
#define KVM_REG_PPC_IC (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xad)
|
||||
#define KVM_REG_PPC_VTB (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xae)
|
||||
#define KVM_REG_PPC_CSIGR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xaf)
|
||||
#define KVM_REG_PPC_TACR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb0)
|
||||
#define KVM_REG_PPC_TCSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb1)
|
||||
#define KVM_REG_PPC_PID (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb2)
|
||||
#define KVM_REG_PPC_ACOP (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb3)
|
||||
|
||||
#define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4)
|
||||
#define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5)
|
||||
#define KVM_REG_PPC_PPR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb6)
|
||||
|
||||
/* Architecture compatibility level */
|
||||
#define KVM_REG_PPC_ARCH_COMPAT (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb7)
|
||||
|
||||
/* Transactional Memory checkpointed state:
|
||||
* This is all GPRs, all VSX regs and a subset of SPRs
|
||||
*/
|
||||
#define KVM_REG_PPC_TM (KVM_REG_PPC | 0x80000000)
|
||||
/* TM GPRs */
|
||||
#define KVM_REG_PPC_TM_GPR0 (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0)
|
||||
#define KVM_REG_PPC_TM_GPR(n) (KVM_REG_PPC_TM_GPR0 + (n))
|
||||
#define KVM_REG_PPC_TM_GPR31 (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x1f)
|
||||
/* TM VSX */
|
||||
#define KVM_REG_PPC_TM_VSR0 (KVM_REG_PPC_TM | KVM_REG_SIZE_U128 | 0x20)
|
||||
#define KVM_REG_PPC_TM_VSR(n) (KVM_REG_PPC_TM_VSR0 + (n))
|
||||
#define KVM_REG_PPC_TM_VSR63 (KVM_REG_PPC_TM | KVM_REG_SIZE_U128 | 0x5f)
|
||||
/* TM SPRS */
|
||||
#define KVM_REG_PPC_TM_CR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x60)
|
||||
#define KVM_REG_PPC_TM_LR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x61)
|
||||
#define KVM_REG_PPC_TM_CTR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x62)
|
||||
#define KVM_REG_PPC_TM_FPSCR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x63)
|
||||
#define KVM_REG_PPC_TM_AMR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x64)
|
||||
#define KVM_REG_PPC_TM_PPR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x65)
|
||||
#define KVM_REG_PPC_TM_VRSAVE (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x66)
|
||||
#define KVM_REG_PPC_TM_VSCR (KVM_REG_PPC_TM | KVM_REG_SIZE_U32 | 0x67)
|
||||
#define KVM_REG_PPC_TM_DSCR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x68)
|
||||
#define KVM_REG_PPC_TM_TAR (KVM_REG_PPC_TM | KVM_REG_SIZE_U64 | 0x69)
|
||||
|
||||
/* PPC64 eXternal Interrupt Controller Specification */
|
||||
#define KVM_DEV_XICS_GRP_SOURCES 1 /* 64-bit source attributes */
|
||||
|
||||
|
||||
@@ -27,6 +27,19 @@
|
||||
#define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 << 0)
|
||||
/* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/
|
||||
#define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE (1 << 1)
|
||||
|
||||
/*
|
||||
* There is a single feature flag that signifies the presence of the MSR
|
||||
* that can be used to retrieve both the local APIC Timer frequency as
|
||||
* well as the TSC frequency.
|
||||
*/
|
||||
|
||||
/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */
|
||||
#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 << 11)
|
||||
|
||||
/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */
|
||||
#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 << 11)
|
||||
|
||||
/*
|
||||
* Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM
|
||||
* and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available
|
||||
@@ -136,6 +149,12 @@
|
||||
/* MSR used to read the per-partition time reference counter */
|
||||
#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
|
||||
|
||||
/* MSR used to retrieve the TSC frequency */
|
||||
#define HV_X64_MSR_TSC_FREQUENCY 0x40000022
|
||||
|
||||
/* MSR used to retrieve the local APIC timer frequency */
|
||||
#define HV_X64_MSR_APIC_FREQUENCY 0x40000023
|
||||
|
||||
/* Define the virtual APIC registers */
|
||||
#define HV_X64_MSR_EOI 0x40000070
|
||||
#define HV_X64_MSR_ICR 0x40000071
|
||||
|
||||
@@ -211,9 +211,9 @@ struct kvm_cpuid_entry2 {
|
||||
__u32 padding[3];
|
||||
};
|
||||
|
||||
#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
|
||||
#define KVM_CPUID_FLAG_STATEFUL_FUNC 2
|
||||
#define KVM_CPUID_FLAG_STATE_READ_NEXT 4
|
||||
#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
|
||||
#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
|
||||
#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
|
||||
|
||||
/* for KVM_SET_CPUID2 */
|
||||
struct kvm_cpuid2 {
|
||||
|
||||
@@ -518,6 +518,10 @@ struct kvm_ppc_smmu_info {
|
||||
/* machine type bits, to be used as argument to KVM_CREATE_VM */
|
||||
#define KVM_VM_S390_UCONTROL 1
|
||||
|
||||
/* on ppc, 0 indicate default, 1 should force HV and 2 PR */
|
||||
#define KVM_VM_PPC_HV 1
|
||||
#define KVM_VM_PPC_PR 2
|
||||
|
||||
#define KVM_S390_SIE_PAGE_OFFSET 1
|
||||
|
||||
/*
|
||||
@@ -541,6 +545,7 @@ struct kvm_ppc_smmu_info {
|
||||
#define KVM_TRACE_ENABLE __KVM_DEPRECATED_MAIN_W_0x06
|
||||
#define KVM_TRACE_PAUSE __KVM_DEPRECATED_MAIN_0x07
|
||||
#define KVM_TRACE_DISABLE __KVM_DEPRECATED_MAIN_0x08
|
||||
#define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2)
|
||||
|
||||
/*
|
||||
* Extension capability list.
|
||||
@@ -668,6 +673,7 @@ struct kvm_ppc_smmu_info {
|
||||
#define KVM_CAP_IRQ_XICS 92
|
||||
#define KVM_CAP_ARM_EL1_32BIT 93
|
||||
#define KVM_CAP_SPAPR_MULTITCE 94
|
||||
#define KVM_CAP_EXT_EMUL_CPUID 95
|
||||
|
||||
#ifdef KVM_CAP_IRQ_ROUTING
|
||||
|
||||
@@ -843,6 +849,10 @@ struct kvm_device_attr {
|
||||
#define KVM_DEV_TYPE_FSL_MPIC_20 1
|
||||
#define KVM_DEV_TYPE_FSL_MPIC_42 2
|
||||
#define KVM_DEV_TYPE_XICS 3
|
||||
#define KVM_DEV_TYPE_VFIO 4
|
||||
#define KVM_DEV_VFIO_GROUP 1
|
||||
#define KVM_DEV_VFIO_GROUP_ADD 1
|
||||
#define KVM_DEV_VFIO_GROUP_DEL 2
|
||||
|
||||
/*
|
||||
* ioctls for VM fds
|
||||
@@ -1012,6 +1022,7 @@ struct kvm_s390_ucas_mapping {
|
||||
/* VM is being stopped by host */
|
||||
#define KVM_KVMCLOCK_CTRL _IO(KVMIO, 0xad)
|
||||
#define KVM_ARM_VCPU_INIT _IOW(KVMIO, 0xae, struct kvm_vcpu_init)
|
||||
#define KVM_ARM_PREFERRED_TARGET _IOR(KVMIO, 0xaf, struct kvm_vcpu_init)
|
||||
#define KVM_GET_REG_LIST _IOWR(KVMIO, 0xb0, struct kvm_reg_list)
|
||||
|
||||
#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
|
||||
|
||||
58
linux-user/aarch64/target_structs.h
Normal file
58
linux-user/aarch64/target_structs.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* ARM AArch64 specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
48
linux-user/alpha/target_structs.h
Normal file
48
linux-user/alpha/target_structs.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Alpha specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_uint mode; /* Read/write permission. */
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad1;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
#endif
|
||||
52
linux-user/arm/target_structs.h
Normal file
52
linux-user/arm/target_structs.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* ARM specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
abi_ulong __unused1;
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
abi_ulong __unused2;
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
abi_ulong __unused3;
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
58
linux-user/cris/target_structs.h
Normal file
58
linux-user/cris/target_structs.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* CRIS specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -633,7 +633,7 @@ static int load_flat_file(struct linux_binprm * bprm,
|
||||
/* Get the pointer's value. */
|
||||
if (get_user_ual(addr, rp))
|
||||
return -EFAULT;
|
||||
addr = flat_get_addr_from_rp(rp, relval, flags, &persistent);
|
||||
addr = flat_get_addr_from_rp(addr, relval, flags, &persistent);
|
||||
if (addr != 0) {
|
||||
/*
|
||||
* Do the relocation. PIC relocs in the data section are
|
||||
|
||||
58
linux-user/i386/target_structs.h
Normal file
58
linux-user/i386/target_structs.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* i386 specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
58
linux-user/m68k/target_structs.h
Normal file
58
linux-user/m68k/target_structs.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* m68k specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3663,26 +3663,6 @@ static int parse_args(int argc, char **argv)
|
||||
return optind;
|
||||
}
|
||||
|
||||
static int get_execfd(char **envp)
|
||||
{
|
||||
typedef struct {
|
||||
long a_type;
|
||||
long a_val;
|
||||
} auxv_t;
|
||||
auxv_t *auxv;
|
||||
|
||||
while (*envp++ != NULL) {
|
||||
;
|
||||
}
|
||||
|
||||
for (auxv = (auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) {
|
||||
if (auxv->a_type == AT_EXECFD) {
|
||||
return auxv->a_val;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
struct target_pt_regs regs1, *regs = ®s1;
|
||||
@@ -3701,7 +3681,8 @@ int main(int argc, char **argv, char **envp)
|
||||
|
||||
module_call_init(MODULE_INIT_QOM);
|
||||
|
||||
qemu_cache_utils_init(envp);
|
||||
qemu_init_auxval(envp);
|
||||
qemu_cache_utils_init();
|
||||
|
||||
if ((envlist = envlist_create()) == NULL) {
|
||||
(void) fprintf(stderr, "Unable to allocate envlist\n");
|
||||
@@ -3875,13 +3856,13 @@ int main(int argc, char **argv, char **envp)
|
||||
env->opaque = ts;
|
||||
task_settid(ts);
|
||||
|
||||
execfd = get_execfd(envp);
|
||||
if (execfd < 0) {
|
||||
execfd = qemu_getauxval(AT_EXECFD);
|
||||
if (execfd == 0) {
|
||||
execfd = open(filename, O_RDONLY);
|
||||
}
|
||||
if (execfd < 0) {
|
||||
printf("Error while loading %s: %s\n", filename, strerror(-execfd));
|
||||
_exit(1);
|
||||
if (execfd < 0) {
|
||||
printf("Error while loading %s: %s\n", filename, strerror(errno));
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
|
||||
|
||||
58
linux-user/microblaze/target_structs.h
Normal file
58
linux-user/microblaze/target_structs.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* MicroBlaze specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
48
linux-user/mips/target_structs.h
Normal file
48
linux-user/mips/target_structs.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* MIPS specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_uint mode; /* Read/write permission. */
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad1;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1 +1,19 @@
|
||||
/*
|
||||
* MIPS64 specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "../mips/target_cpu.h"
|
||||
|
||||
2
linux-user/mips64/target_structs.h
Normal file
2
linux-user/mips64/target_structs.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#include "../mips/target_structs.h"
|
||||
|
||||
58
linux-user/openrisc/target_structs.h
Normal file
58
linux-user/openrisc/target_structs.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* OpenRISC specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
60
linux-user/ppc/target_structs.h
Normal file
60
linux-user/ppc/target_structs.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* PowerPC specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_uint mode; /* Read/write permission. */
|
||||
uint32_t __seq; /* Sequence number. */
|
||||
uint32_t __pad1;
|
||||
uint64_t __unused1;
|
||||
uint64_t __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_uint __unused1;
|
||||
#endif
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_uint __unused2;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_uint __unused3;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_uint __unused4;
|
||||
#endif
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused5;
|
||||
abi_ulong __unused6;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -452,5 +452,6 @@ static inline void *lock_user_string(abi_ulong guest_addr)
|
||||
*/
|
||||
#include "target_cpu.h"
|
||||
#include "target_signal.h"
|
||||
#include "target_structs.h"
|
||||
|
||||
#endif /* QEMU_H */
|
||||
|
||||
63
linux-user/s390x/target_structs.h
Normal file
63
linux-user/s390x/target_structs.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* S/390 specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
#if TARGET_ABI_BITS == 64
|
||||
abi_uint mode; /* Read/write permission. */
|
||||
#else
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
#endif
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
58
linux-user/sh4/target_structs.h
Normal file
58
linux-user/sh4/target_structs.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* SH4 specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad1;
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
abi_ushort __pad2;
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused1;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused2;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ulong __unused3;
|
||||
#endif
|
||||
abi_int shm_cpid; /* pid of creator */
|
||||
abi_int shm_lpid; /* pid of last shmop */
|
||||
abi_ulong shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused4;
|
||||
abi_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif
|
||||
63
linux-user/sparc/target_structs.h
Normal file
63
linux-user/sparc/target_structs.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* SPARC specific structures for linux-user
|
||||
*
|
||||
* Copyright (c) 2013 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TARGET_STRUCTS_H
|
||||
#define TARGET_STRUCTS_H
|
||||
|
||||
struct target_ipc_perm {
|
||||
abi_int __key; /* Key. */
|
||||
abi_uint uid; /* Owner's user ID. */
|
||||
abi_uint gid; /* Owner's group ID. */
|
||||
abi_uint cuid; /* Creator's user ID. */
|
||||
abi_uint cgid; /* Creator's group ID. */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_ushort __pad1;
|
||||
abi_ushort mode; /* Read/write permission. */
|
||||
abi_ushort __pad2;
|
||||
#else
|
||||
abi_ushort mode;
|
||||
abi_ushort __pad1;
|
||||
#endif
|
||||
abi_ushort __seq; /* Sequence number. */
|
||||
uint64_t __unused1;
|
||||
uint64_t __unused2;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm; /* operation permission struct */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_uint __pad1;
|
||||
#endif
|
||||
abi_ulong shm_atime; /* time of last shmat() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_uint __pad2;
|
||||
#endif
|
||||
abi_ulong shm_dtime; /* time of last shmdt() */
|
||||
#if TARGET_ABI_BITS == 32
|
||||
abi_uint __pad3;
|
||||
#endif
|
||||
abi_ulong shm_ctime; /* time of last change by shmctl() */
|
||||
abi_long shm_segsz; /* size of segment in bytes */
|
||||
abi_ulong shm_cpid; /* pid of creator */
|
||||
abi_ulong shm_lpid; /* pid of last shmop */
|
||||
abi_long shm_nattch; /* number of current attaches */
|
||||
abi_ulong __unused1;
|
||||
abi_ulong __unused2;
|
||||
};
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user