char *pri_indev;
char *sec_indev;
char *outdev;
- CharDriverState *chr_pri_in;
- CharDriverState *chr_sec_in;
- CharDriverState *chr_out;
+ CharBackend chr_pri_in;
+ CharBackend chr_sec_in;
+ CharBackend chr_out;
SocketReadState pri_rs;
SocketReadState sec_rs;
ObjectClass parent_class;
} CompareClass;
-typedef struct CompareChardevProps {
- bool is_socket;
-} CompareChardevProps;
-
enum {
PRIMARY_IN = 0,
SECONDARY_IN,
};
-static int compare_chr_send(CharDriverState *out,
+static int compare_chr_send(CharBackend *out,
const uint8_t *buf,
uint32_t size);
{
struct tcphdr *ptcp, *stcp;
int res;
- char *sdebug, *ddebug;
trace_colo_compare_main("compare tcp");
if (ppkt->size != spkt->size) {
(spkt->size - ETH_HLEN));
if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
- sdebug = strdup(inet_ntoa(ppkt->ip->ip_src));
- ddebug = strdup(inet_ntoa(ppkt->ip->ip_dst));
- fprintf(stderr, "%s: src/dst: %s/%s p: seq/ack=%u/%u"
- " s: seq/ack=%u/%u res=%d flags=%x/%x\n",
- __func__, sdebug, ddebug,
- (unsigned int)ntohl(ptcp->th_seq),
- (unsigned int)ntohl(ptcp->th_ack),
- (unsigned int)ntohl(stcp->th_seq),
- (unsigned int)ntohl(stcp->th_ack),
- res, ptcp->th_flags, stcp->th_flags);
-
- fprintf(stderr, "Primary len = %d\n", ppkt->size);
- qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", ppkt->size);
- fprintf(stderr, "Secondary len = %d\n", spkt->size);
- qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
+ trace_colo_compare_pkt_info_src(inet_ntoa(ppkt->ip->ip_src),
+ ntohl(stcp->th_seq),
+ ntohl(stcp->th_ack),
+ res, stcp->th_flags,
+ spkt->size);
+
+ trace_colo_compare_pkt_info_dst(inet_ntoa(ppkt->ip->ip_dst),
+ ntohl(ptcp->th_seq),
+ ntohl(ptcp->th_ack),
+ res, ptcp->th_flags,
+ ppkt->size);
- g_free(sdebug);
- g_free(ddebug);
+ qemu_hexdump((char *)ppkt->data, stderr,
+ "colo-compare ppkt", ppkt->size);
+ qemu_hexdump((char *)spkt->data, stderr,
+ "colo-compare spkt", spkt->size);
}
return res;
}
if (result) {
- ret = compare_chr_send(s->chr_out, pkt->data, pkt->size);
+ ret = compare_chr_send(&s->chr_out, pkt->data, pkt->size);
if (ret < 0) {
error_report("colo_send_primary_packet failed");
}
}
}
-static int compare_chr_send(CharDriverState *out,
+static int compare_chr_send(CharBackend *out,
const uint8_t *buf,
uint32_t size)
{
ret = net_fill_rstate(&s->pri_rs, buf, size);
if (ret == -1) {
- qemu_chr_add_handlers(s->chr_pri_in, NULL, NULL, NULL, NULL);
+ qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL,
+ NULL, NULL, true);
error_report("colo-compare primary_in error");
}
}
ret = net_fill_rstate(&s->sec_rs, buf, size);
if (ret == -1) {
- qemu_chr_add_handlers(s->chr_sec_in, NULL, NULL, NULL, NULL);
+ qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL,
+ NULL, NULL, true);
error_report("colo-compare secondary_in error");
}
}
worker_context = g_main_context_new();
- qemu_chr_add_handlers_full(s->chr_pri_in, compare_chr_can_read,
- compare_pri_chr_in, NULL, s, worker_context);
- qemu_chr_add_handlers_full(s->chr_sec_in, compare_chr_can_read,
- compare_sec_chr_in, NULL, s, worker_context);
+ qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read,
+ compare_pri_chr_in, NULL, s, worker_context, true);
+ qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read,
+ compare_sec_chr_in, NULL, s, worker_context, true);
compare_loop = g_main_loop_new(worker_context, FALSE);
if (packet_enqueue(s, PRIMARY_IN)) {
trace_colo_compare_main("primary: unsupported packet in");
- compare_chr_send(s->chr_out, pri_rs->buf, pri_rs->packet_len);
+ compare_chr_send(&s->chr_out, pri_rs->buf, pri_rs->packet_len);
} else {
/* compare connection */
g_queue_foreach(&s->conn_list, colo_compare_connection, s);
* Return 0 is success.
* Return 1 is failed.
*/
-static int find_and_check_chardev(CharDriverState **chr,
+static int find_and_check_chardev(Chardev **chr,
char *chr_name,
Error **errp)
{
- CompareChardevProps props;
-
*chr = qemu_chr_find(chr_name);
if (*chr == NULL) {
error_setg(errp, "Device '%s' not found",
return 1;
}
- memset(&props, 0, sizeof(props));
-
if (!qemu_chr_has_feature(*chr, QEMU_CHAR_FEATURE_RECONNECTABLE)) {
error_setg(errp, "chardev \"%s\" is not reconnectable",
chr_name);
return 1;
}
+
return 0;
}
static void colo_compare_complete(UserCreatable *uc, Error **errp)
{
CompareState *s = COLO_COMPARE(uc);
+ Chardev *chr;
char thread_name[64];
static int compare_id;
return;
}
- if (find_and_check_chardev(&s->chr_pri_in, s->pri_indev, errp)) {
+ if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
+ !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
return;
}
- if (find_and_check_chardev(&s->chr_sec_in, s->sec_indev, errp)) {
+ if (find_and_check_chardev(&chr, s->sec_indev, errp) ||
+ !qemu_chr_fe_init(&s->chr_sec_in, chr, errp)) {
return;
}
- if (find_and_check_chardev(&s->chr_out, s->outdev, errp)) {
+ if (find_and_check_chardev(&chr, s->outdev, errp) ||
+ !qemu_chr_fe_init(&s->chr_out, chr, errp)) {
return;
}
- qemu_chr_fe_claim_no_fail(s->chr_pri_in);
-
- qemu_chr_fe_claim_no_fail(s->chr_sec_in);
-
- qemu_chr_fe_claim_no_fail(s->chr_out);
-
net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize);
net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize);
{
CompareState *s = COLO_COMPARE(obj);
- if (s->chr_pri_in) {
- qemu_chr_add_handlers(s->chr_pri_in, NULL, NULL, NULL, NULL);
- qemu_chr_fe_release(s->chr_pri_in);
- }
- if (s->chr_sec_in) {
- qemu_chr_add_handlers(s->chr_sec_in, NULL, NULL, NULL, NULL);
- qemu_chr_fe_release(s->chr_sec_in);
- }
- if (s->chr_out) {
- qemu_chr_fe_release(s->chr_out);
- }
+ qemu_chr_fe_deinit(&s->chr_pri_in);
+ qemu_chr_fe_deinit(&s->chr_sec_in);
+ qemu_chr_fe_deinit(&s->chr_out);
g_queue_free(&s->conn_list);