mirror of https://github.com/proxmox/mirror_qemu
char: use a feature bit for replay
Use a feature flag rather than a structure field for "replay". Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>master
parent
ad5c679c7f
commit
5ebd67030c
|
@ -69,6 +69,8 @@ typedef enum {
|
||||||
/* Whether it is possible to send/recv file descriptors
|
/* Whether it is possible to send/recv file descriptors
|
||||||
* over the data channel */
|
* over the data channel */
|
||||||
QEMU_CHAR_FEATURE_FD_PASS,
|
QEMU_CHAR_FEATURE_FD_PASS,
|
||||||
|
/* Whether replay or record mode is enabled */
|
||||||
|
QEMU_CHAR_FEATURE_REPLAY,
|
||||||
|
|
||||||
QEMU_CHAR_FEATURE_LAST,
|
QEMU_CHAR_FEATURE_LAST,
|
||||||
} CharDriverFeature;
|
} CharDriverFeature;
|
||||||
|
@ -97,7 +99,6 @@ struct CharDriverState {
|
||||||
int logfd;
|
int logfd;
|
||||||
int be_open;
|
int be_open;
|
||||||
guint fd_in_tag;
|
guint fd_in_tag;
|
||||||
bool replay;
|
|
||||||
DECLARE_BITMAP(features, QEMU_CHAR_FEATURE_LAST);
|
DECLARE_BITMAP(features, QEMU_CHAR_FEATURE_LAST);
|
||||||
QTAILQ_ENTRY(CharDriverState) next;
|
QTAILQ_ENTRY(CharDriverState) next;
|
||||||
};
|
};
|
||||||
|
|
33
qemu-char.c
33
qemu-char.c
|
@ -277,6 +277,11 @@ static int qemu_chr_fe_write_buffer(CharDriverState *s, const uint8_t *buf, int
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool qemu_chr_replay(CharDriverState *chr)
|
||||||
|
{
|
||||||
|
return qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY);
|
||||||
|
}
|
||||||
|
|
||||||
int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
|
int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
|
||||||
{
|
{
|
||||||
CharDriverState *s = be->chr;
|
CharDriverState *s = be->chr;
|
||||||
|
@ -286,7 +291,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->replay && replay_mode == REPLAY_MODE_PLAY) {
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
|
||||||
int offset;
|
int offset;
|
||||||
replay_char_write_event_load(&ret, &offset);
|
replay_char_write_event_load(&ret, &offset);
|
||||||
assert(offset <= len);
|
assert(offset <= len);
|
||||||
|
@ -303,7 +308,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
|
||||||
|
|
||||||
qemu_mutex_unlock(&s->chr_write_lock);
|
qemu_mutex_unlock(&s->chr_write_lock);
|
||||||
|
|
||||||
if (s->replay && replay_mode == REPLAY_MODE_RECORD) {
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
|
||||||
replay_char_write_event_save(ret, ret < 0 ? 0 : ret);
|
replay_char_write_event_save(ret, ret < 0 ? 0 : ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +320,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len)
|
||||||
int offset;
|
int offset;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (s->replay && replay_mode == REPLAY_MODE_PLAY) {
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
|
||||||
replay_char_write_event_load(&res, &offset);
|
replay_char_write_event_load(&res, &offset);
|
||||||
assert(offset <= len);
|
assert(offset <= len);
|
||||||
qemu_chr_fe_write_buffer(s, buf, offset, &offset);
|
qemu_chr_fe_write_buffer(s, buf, offset, &offset);
|
||||||
|
@ -324,7 +329,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len)
|
||||||
|
|
||||||
res = qemu_chr_fe_write_buffer(s, buf, len, &offset);
|
res = qemu_chr_fe_write_buffer(s, buf, len, &offset);
|
||||||
|
|
||||||
if (s->replay && replay_mode == REPLAY_MODE_RECORD) {
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
|
||||||
replay_char_write_event_save(res, offset);
|
replay_char_write_event_save(res, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +360,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->replay && replay_mode == REPLAY_MODE_PLAY) {
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
|
||||||
return replay_char_read_all_load(buf);
|
return replay_char_read_all_load(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +377,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
if (s->replay && replay_mode == REPLAY_MODE_RECORD) {
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
|
||||||
replay_char_read_all_save_error(res);
|
replay_char_read_all_save_error(res);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -385,7 +390,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->replay && replay_mode == REPLAY_MODE_RECORD) {
|
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
|
||||||
replay_char_read_all_save_buf(buf, offset);
|
replay_char_read_all_save_buf(buf, offset);
|
||||||
}
|
}
|
||||||
return offset;
|
return offset;
|
||||||
|
@ -396,7 +401,7 @@ int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg)
|
||||||
CharDriverState *s = be->chr;
|
CharDriverState *s = be->chr;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (!s || !s->driver->chr_ioctl || s->replay) {
|
if (!s || !s->driver->chr_ioctl || qemu_chr_replay(s)) {
|
||||||
res = -ENOTSUP;
|
res = -ENOTSUP;
|
||||||
} else {
|
} else {
|
||||||
res = s->driver->chr_ioctl(s, cmd, arg);
|
res = s->driver->chr_ioctl(s, cmd, arg);
|
||||||
|
@ -427,7 +432,7 @@ void qemu_chr_be_write_impl(CharDriverState *s, uint8_t *buf, int len)
|
||||||
|
|
||||||
void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len)
|
void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len)
|
||||||
{
|
{
|
||||||
if (s->replay) {
|
if (qemu_chr_replay(s)) {
|
||||||
if (replay_mode == REPLAY_MODE_PLAY) {
|
if (replay_mode == REPLAY_MODE_PLAY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -442,7 +447,7 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)
|
||||||
CharDriverState *s = be->chr;
|
CharDriverState *s = be->chr;
|
||||||
int fd;
|
int fd;
|
||||||
int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1;
|
int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1;
|
||||||
if (s && s->replay) {
|
if (s && qemu_chr_replay(s)) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Replay: get msgfd is not supported for serial devices yet\n");
|
"Replay: get msgfd is not supported for serial devices yet\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -4249,8 +4254,10 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename)
|
||||||
CharDriverState *chr;
|
CharDriverState *chr;
|
||||||
chr = qemu_chr_new_noreplay(label, filename);
|
chr = qemu_chr_new_noreplay(label, filename);
|
||||||
if (chr) {
|
if (chr) {
|
||||||
chr->replay = replay_mode != REPLAY_MODE_NONE;
|
if (replay_mode != REPLAY_MODE_NONE) {
|
||||||
if (chr->replay && chr->driver->chr_ioctl) {
|
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_REPLAY);
|
||||||
|
}
|
||||||
|
if (qemu_chr_replay(chr) && chr->driver->chr_ioctl) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Replay: ioctl is not supported for serial devices yet\n");
|
"Replay: ioctl is not supported for serial devices yet\n");
|
||||||
}
|
}
|
||||||
|
@ -4997,7 +5004,7 @@ void qmp_chardev_remove(const char *id, Error **errp)
|
||||||
error_setg(errp, "Chardev '%s' is busy", id);
|
error_setg(errp, "Chardev '%s' is busy", id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (chr->replay) {
|
if (qemu_chr_replay(chr)) {
|
||||||
error_setg(errp,
|
error_setg(errp,
|
||||||
"Chardev '%s' cannot be unplugged in record/replay mode", id);
|
"Chardev '%s' cannot be unplugged in record/replay mode", id);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue