Skip to content

Commit a2e5cb7

Browse files
zhangckidjasowang
authored andcommitted
net/colo-compare.c: Expose compare "max_queue_size" to users
This patch allow users to set the "max_queue_size" according to their environment. Signed-off-by: Zhang Chen <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 9a8d949 commit a2e5cb7

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

net/colo-compare.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static bool colo_compare_active;
5959
static QemuMutex event_mtx;
6060
static QemuCond event_complete_cond;
6161
static int event_unhandled_count;
62+
static uint32_t max_queue_size;
6263

6364
/*
6465
* + CompareState ++
@@ -222,7 +223,7 @@ static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
222223
*/
223224
static int colo_insert_packet(GQueue *queue, Packet *pkt, uint32_t *max_ack)
224225
{
225-
if (g_queue_get_length(queue) <= MAX_QUEUE_SIZE) {
226+
if (g_queue_get_length(queue) <= max_queue_size) {
226227
if (pkt->ip->ip_p == IPPROTO_TCP) {
227228
fill_pkt_tcp_info(pkt, max_ack);
228229
g_queue_insert_sorted(queue,
@@ -1134,6 +1135,37 @@ static void compare_set_expired_scan_cycle(Object *obj, Visitor *v,
11341135
s->expired_scan_cycle = value;
11351136
}
11361137

1138+
static void get_max_queue_size(Object *obj, Visitor *v,
1139+
const char *name, void *opaque,
1140+
Error **errp)
1141+
{
1142+
uint32_t value = max_queue_size;
1143+
1144+
visit_type_uint32(v, name, &value, errp);
1145+
}
1146+
1147+
static void set_max_queue_size(Object *obj, Visitor *v,
1148+
const char *name, void *opaque,
1149+
Error **errp)
1150+
{
1151+
Error *local_err = NULL;
1152+
uint32_t value;
1153+
1154+
visit_type_uint32(v, name, &value, &local_err);
1155+
if (local_err) {
1156+
goto out;
1157+
}
1158+
if (!value) {
1159+
error_setg(&local_err, "Property '%s.%s' requires a positive value",
1160+
object_get_typename(obj), name);
1161+
goto out;
1162+
}
1163+
max_queue_size = value;
1164+
1165+
out:
1166+
error_propagate(errp, local_err);
1167+
}
1168+
11371169
static void compare_pri_rs_finalize(SocketReadState *pri_rs)
11381170
{
11391171
CompareState *s = container_of(pri_rs, CompareState, pri_rs);
@@ -1251,6 +1283,11 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
12511283
s->expired_scan_cycle = REGULAR_PACKET_CHECK_MS;
12521284
}
12531285

1286+
if (!max_queue_size) {
1287+
/* Set default queue size to 1024 */
1288+
max_queue_size = MAX_QUEUE_SIZE;
1289+
}
1290+
12541291
if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
12551292
!qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
12561293
return;
@@ -1370,6 +1407,10 @@ static void colo_compare_init(Object *obj)
13701407
compare_get_expired_scan_cycle,
13711408
compare_set_expired_scan_cycle, NULL, NULL);
13721409

1410+
object_property_add(obj, "max_queue_size", "uint32",
1411+
get_max_queue_size,
1412+
set_max_queue_size, NULL, NULL);
1413+
13731414
s->vnet_hdr = false;
13741415
object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
13751416
compare_set_vnet_hdr);

qemu-options.hx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4695,7 +4695,7 @@ SRST
46954695
stored. The file format is libpcap, so it can be analyzed with
46964696
tools such as tcpdump or Wireshark.
46974697

4698-
``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}``
4698+
``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
46994699
Colo-compare gets packet from primary\_inchardevid and
47004700
secondary\_inchardevid, than compare primary packet with
47014701
secondary packet. If the packets are same, we will output
@@ -4707,7 +4707,8 @@ SRST
47074707
vnet\_hdr\_len. Then compare\_timeout=@var{ms} determines the
47084708
maximum delay colo-compare wait for the packet.
47094709
The expired\_scan\_cycle=@var{ms} to set the period of scanning
4710-
expired primary node network packets.
4710+
expired primary node network packets. The max\_queue\_size=@var{size}
4711+
is to set the max compare queue size depend on user environment.
47114712
If you want to use Xen COLO, will need the notify\_dev to
47124713
notify Xen colo-frame to do checkpoint.
47134714

0 commit comments

Comments
 (0)