Skip to contentSkip to conversation

Introduce Advanced Watch Dog module

RFC PATCH Superseded Zhang Chen 5 participants 14 messages Oct 16, 2019 – Oct 24, 2019 Networking

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

cover Introduce Advanced Watch Dog module

From: Zhang Chen <[email protected]>

Advanced Watch Dog is an universal monitoring module on VMM side, it can be used to detect network down(VMM to guest, VMM to VMM, VMM to another remote server) and do previously set operation. for example: send message to admin, notify another VMM, send qmp command to qemu do some operation like restart the VM, build VMM heartbeat system, etc.
It make user have basic VM/Host network monitoring tools and basic false tolerance and recovery solution.

Demo usage(for COLO heartbeat):

In primary node:

-chardev socket,id=h1,host=3.3.3.3,port=9009,server,nowait
-chardev socket,id=heartbeat0,host=3.3.3.3,port=4445
-object iothread,id=iothread2
-object advanced-watchdog,id=heart1,server=on,awd_node=h1,notification_node=heartbeat0,opt_script=colo_opt_script_path,iothread=iothread1,pulse_interval=1000,timeout=5000

In secondary node:

-monitor tcp::4445,server,nowait
-chardev socket,id=h1,host=3.3.3.3,port=9009,reconnect=1
-chardev socket,id=heart1,host=3.3.3.8,port=4445
-object iothread,id=iothread1
-object advanced-watchdog,id=heart1,server=off,awd_node=h1,notification_node=heart1,opt_script=colo_secondary_opt_script,iothread=iothread1,timeout=10000

Zhang Chen (4):
net/awd.c: Introduce Advanced Watch Dog module framework net/awd.c: Initailize input/output chardev net/awd.c: Load advanced watch dog worker thread job vl.c: Make Advanced Watch Dog delayed initialization

 net/Makefile.objs |   1 +
 net/awd.c         | 486 ++++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx   |   6 +
 vl.c              |   7 +
 4 files changed, 500 insertions(+)
 create mode 100644 net/awd.c
Signature · 1 line
2.17.1
author
#1 lore raw

RFC PATCH 1/4 net/awd.c: Introduce Advanced Watch Dog module framework

From: Zhang Chen <[email protected]>

This patch introduce a new module named Advanced Watch Dog,
and defined the input and output parameter. AWD use standard chardev
as the way of communicationg with the outside world.
Demo command:
-object advanced-watchdog,id=heart1,server=on,awd_node=h1,notification_node=heartbeat0,opt_script=opt_script_path,iothread=iothread1,pulse_interval=1000,timeout=5000

---
 net/Makefile.objs |   1 +
 net/awd.c         | 261 ++++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx   |   6 ++
 3 files changed, 268 insertions(+)
 create mode 100644 net/awd.c
net/Makefile.objs +1 -0
index c5d076d19c..139b1394e9 100644
@@ -19,6 +19,7 @@ common-obj-y += colo-compare.o
 common-obj-y += colo.o
 common-obj-y += filter-rewriter.o
 common-obj-y += filter-replay.o
+common-obj-y += awd.o
 
 tap-obj-$(CONFIG_LINUX) = tap-linux.o
 tap-obj-$(CONFIG_BSD) = tap-bsd.o
net/awd.c new file +261 -0

261 lines not on this page · raw message

qemu-options.hx +6 -0
index 793d70ff93..a4c1e2e2d1 100644
@@ -4520,6 +4520,12 @@ Dump the network traffic on netdev @var{dev} to the file specified by
 The file format is libpcap, so it can be analyzed with tools such as tcpdump
 or Wireshark.
 
+@item -object advanced-watchdog,id=@var{id},awd_node=@var{chardevid},notification_node=@var{chardevid},server=@var{server},iothread=@var{id}[,pulse_interval=@var{time_ms},timeout=@var{time_ms}]
+
+Advanced Watch Dog is an universal monitoring module on VMM side, it can be used to detect network down(VMM to guest, VMM to VMM, VMM to another remote server) and do previously set operation.
+for example: send message to admin, notify another VMM, send qmp command to qemu do some operation like restart the VM, build VMM heartbeat system, etc.
+It make user have basic VM/Host network monitoring tools and basic false tolerance and recovery solution.
+
 @item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},outdev=@var{chardevid},iothread=@var{id}[,vnet_hdr_support][,notify_dev=@var{id}]
 
 Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@var{chardevid}, than compare primary packet with
Signature · 1 line
2.17.1
#2 lore raw

Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Quoted 7 lines · Zhang Chen

From: Zhang Chen <[email protected]>

This patch introduce a new module named Advanced Watch Dog, and
defined the input and output parameter. AWD use standard chardev as
the way of communicationg with the outside world. Demo command:
-object advanced-watchdog,id=heart1,server=on,awd_node=h1,notification_node=heartbeat0,opt_script=opt_script_path,iothread=iothread1,pulse_interval=1000,timeout=5000

Is there a standard or specification for how to interact with this? Is this something that was developed explicitly for these patches, or did it exist before?

Paolo

#3 lore raw

RE: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Quoted 18 lines

-----Original Message-----
From: Paolo Bonzini <[email protected]>
Sent: Tuesday, October 22, 2019 1:24 AM
To: Zhang, Chen <[email protected]>; Jason Wang <[email protected]>; qemu-dev <[email protected]>
Cc: Zhang Chen <[email protected]>
Subject: Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Quoted 7 lines · Zhang Chen

From: Zhang Chen <[email protected]>

This patch introduce a new module named Advanced Watch Dog, and defined the input and output parameter. AWD use standard chardev as the way of communicationg with the outside world. Demo command:
-object
advanced-

Quoted 7 lines

watchdog,id=heart1,server=on,awd_node=h1,notification_node=he

Quoted 2 lines

artbeat0,opt_script=opt_script_path,iothread=iothread1,pulse_interval= 1000,timeout=5000

Is there a standard or specification for how to interact with this? Is this something that was developed explicitly for these patches, or did it exist before?

Hi Paolo,

Thanks you for your attention.
Current AWD patch just accept any input as the signal to refresh the watchdog timer,
and we can also make a certain interactive protocol here. For the output user can pre-write
some command or some messages in the AWD opt-script. We noticed that there is no way
for VMM communicate directly, maybe some people think we don't need such things(up layer
software like openstack can handle it). But we engaged with real customer found that in some cases,
they need a lightweight and efficient mechanism to solve some practical problems(openstack is too heavy). For example in COLO (https://wiki.qemu.org/Features/COLO).
We need heartbeat service to detect two node status, current implement need another application
running in the host to do this job, if found issue it will send message to local Qemu by qmp command,
This is very complicated in actual scenarios, we have to bind each heartbeat service with
the VM instance and handle lots of internal errors. Advanced watch dog can solve this issue in most cases. At the same time, AWD also can be used in a variety of scenarios, it can active detect Qemu status and
do some simple automatic processing for example kill itself when it loss control with openstack(just need simple paired service).

Thanks
Zhang Chen

Quoted 1 line

Paolo

#4 lore raw

Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

In reply to Zhang Chen

Hi Chen,

Quoted 21 lines · Zhang Chen

From: Zhang Chen <[email protected]>

This patch introduce a new module named Advanced Watch Dog,
and defined the input and output parameter. AWD use standard chardev
as the way of communicationg with the outside world.
Demo command:
-object advanced-watchdog,id=heart1,server=on,awd_node=h1,notification_node=heartbeat0,opt_script=opt_script_path,iothread=iothread1,pulse_interval=1000,timeout=5000

---
  net/Makefile.objs |   1 +
  net/awd.c         | 261 ++++++++++++++++++++++++++++++++++++++++++++++
  qemu-options.hx   |   6 ++
  3 files changed, 268 insertions(+)

create mode 100644 net/awd.c

net/Makefile.objs +0 -0
index c5d076d19c..139b1394e9 100644

net/Makefile.objs common-obj-y += colo-compare.o · line 22

Quoted 4 lines
net/Makefile.objs +1 -0
@@ -19,6 +19,7 @@ common-obj-y += colo-compare.o
  common-obj-y += colo.o
  common-obj-y += filter-rewriter.o
  common-obj-y += filter-replay.o
+common-obj-y += awd.o

Can you add a net/Kconfig file introducing the ADVANCED_WATCHDOG selector?

config COLO_ADVANCED_WATCHDOG
bool
default n

Then use here:

    common-obj-$(COLO_ADVANCED_WATCHDOG) += awd.o

Thanks,

Phil.

Quoted 3 lines
net/Makefile.objs +0 -0
  tap-obj-$(CONFIG_LINUX) = tap-linux.o
  tap-obj-$(CONFIG_BSD) = tap-bsd.o

[...]

#5 lore raw

RE: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Quoted 47 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Wednesday, October 23, 2019 7:01 PM
To: Zhang, Chen <[email protected]>; Jason Wang <[email protected]>; Paolo Bonzini <[email protected]>; qemu- dev <[email protected]>
Cc: Zhang Chen <[email protected]>
Subject: Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Hi Chen,

Quoted 8 lines · Zhang Chen

From: Zhang Chen <[email protected]>

This patch introduce a new module named Advanced Watch Dog, and defined the input and output parameter. AWD use standard chardev as the way of communicationg with the outside world.
Demo command:
-object
advanced-

watchdog,id=heart1,server=on,awd_node=h1,notification_node=he

Quoted 7 lines

artbeat0,opt_script=opt_script_path,iothread=iothread1,pulse_interval= 1000,timeout=5000

---
  net/Makefile.objs |   1 +
  net/awd.c         | 261

++++++++++++++++++++++++++++++++++++++++++++++

net/Makefile.objs common-obj-y += colo-compare.o · line 22

Quoted 13 lines
  qemu-options.hx   |   6 ++
  3 files changed, 268 insertions(+)

create mode 100644 net/awd.c

net/Makefile.objs index renamed from net/Makefile.objs +0 -0

c5d076d19c..139b1394e9 100644

net/Makefile.objs +1 -0
@@ -19,6 +19,7 @@ common-obj-y += colo-compare.o
  common-obj-y += colo.o
  common-obj-y += filter-rewriter.o
  common-obj-y += filter-replay.o
+common-obj-y += awd.o

Can you add a net/Kconfig file introducing the ADVANCED_WATCHDOG selector?

Quoted 8 lines

config COLO_ADVANCED_WATCHDOG
bool
default n

Then use here:

     common-obj-$(COLO_ADVANCED_WATCHDOG) += awd.o

Sure, but AWD is a universal module, COLO is just the first user. Maybe use "config ADVANCED_WATCHDOG" is better.

Thanks
Zhang Chen

Quoted 8 lines

Thanks,

Phil.

Quoted 3 lines
net/Makefile.objs +0 -0
  tap-obj-$(CONFIG_LINUX) = tap-linux.o
  tap-obj-$(CONFIG_BSD) = tap-bsd.o

[...]

#6 lore raw

Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Quoted 50 lines · Chen
Quoted 50 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Wednesday, October 23, 2019 7:01 PM
To: Zhang, Chen <[email protected]>; Jason Wang <[email protected]>; Paolo Bonzini <[email protected]>; qemu- dev <[email protected]>
Cc: Zhang Chen <[email protected]>
Subject: Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Hi Chen,

Quoted 8 lines · Zhang Chen

From: Zhang Chen <[email protected]>

This patch introduce a new module named Advanced Watch Dog, and defined the input and output parameter. AWD use standard chardev as the way of communicationg with the outside world.
Demo command:
-object
advanced-

watchdog,id=heart1,server=on,awd_node=h1,notification_node=he

Quoted 7 lines

artbeat0,opt_script=opt_script_path,iothread=iothread1,pulse_interval= 1000,timeout=5000

---
   net/Makefile.objs |   1 +
   net/awd.c         | 261

++++++++++++++++++++++++++++++++++++++++++++++

net/Makefile.objs common-obj-y += colo-compare.o · line 22

Quoted 13 lines
   qemu-options.hx   |   6 ++
   3 files changed, 268 insertions(+)

create mode 100644 net/awd.c

net/Makefile.objs index renamed from net/Makefile.objs +0 -0

c5d076d19c..139b1394e9 100644

net/Makefile.objs +1 -0
@@ -19,6 +19,7 @@ common-obj-y += colo-compare.o
   common-obj-y += colo.o
   common-obj-y += filter-rewriter.o
   common-obj-y += filter-replay.o
+common-obj-y += awd.o

Can you add a net/Kconfig file introducing the ADVANCED_WATCHDOG selector?

config COLO_ADVANCED_WATCHDOG
bool
default n

Quoted 7 lines
Quoted 4 lines

Then use here:

      common-obj-$(COLO_ADVANCED_WATCHDOG) += awd.o

Sure, but AWD is a universal module, COLO is just the first user. Maybe use "config ADVANCED_WATCHDOG" is better.

Oh I see, better then.

Then we might add (later)

config COLO

      ...
      select ADVANCED_WATCHDOG

Thanks!

Phil.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
net/Makefile.objs +0 -0
   tap-obj-$(CONFIG_LINUX) = tap-linux.o
   tap-obj-$(CONFIG_BSD) = tap-bsd.o

[...]

#7 lore raw

RE: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Quoted 72 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Wednesday, October 23, 2019 7:39 PM
To: Zhang, Chen <[email protected]>; Jason Wang <[email protected]>; Paolo Bonzini <[email protected]>; qemu- dev <[email protected]>
Cc: Zhang Chen <[email protected]>
Subject: Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Quoted 5 lines · Chen
Quoted 5 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Wednesday, October 23, 2019 7:01 PM
To: Zhang, Chen <[email protected]>; Jason Wang <[email protected]>; Paolo Bonzini <[email protected]>; qemu-

dev

Quoted 46 lines
Quoted 46 lines

<[email protected]>
Cc: Zhang Chen <[email protected]>
Subject: Re: [RFC PATCH 1/4] net/awd.c: Introduce Advanced Watch Dog module framework

Hi Chen,

Quoted 8 lines · Zhang Chen

From: Zhang Chen <[email protected]>

This patch introduce a new module named Advanced Watch Dog, and defined the input and output parameter. AWD use standard chardev as the way of communicationg with the outside world.
Demo command:
-object
advanced-

watchdog,id=heart1,server=on,awd_node=h1,notification_node=he

Quoted 8 lines

artbeat0,opt_script=opt_script_path,iothread=iothread1,pulse_interva l=
1000,timeout=5000

---
   net/Makefile.objs |   1 +
   net/awd.c         | 261

++++++++++++++++++++++++++++++++++++++++++++++

net/Makefile.objs common-obj-y += colo-compare.o · line 22

Quoted 13 lines
   qemu-options.hx   |   6 ++
   3 files changed, 268 insertions(+)

create mode 100644 net/awd.c

net/Makefile.objs index renamed from net/Makefile.objs +0 -0

c5d076d19c..139b1394e9 100644

net/Makefile.objs +1 -0
@@ -19,6 +19,7 @@ common-obj-y += colo-compare.o
   common-obj-y += colo.o
   common-obj-y += filter-rewriter.o
   common-obj-y += filter-replay.o
+common-obj-y += awd.o

Can you add a net/Kconfig file introducing the ADVANCED_WATCHDOG selector?

config COLO_ADVANCED_WATCHDOG
bool
default n

Quoted 7 lines
Quoted 4 lines

Then use here:

      common-obj-$(COLO_ADVANCED_WATCHDOG) += awd.o

Sure, but AWD is a universal module, COLO is just the first user. Maybe use "config ADVANCED_WATCHDOG" is better.

Quoted 8 lines

Oh I see, better then.

Then we might add (later)

   config COLO
       ...
       select ADVANCED_WATCHDOG

I noticed that we haven't the "net/kconfig" file, the AWD isn't a HW in the hw/net. Do you means we can add the selector in "configuration" file?
We can add some related configuration command like "--enable-advanced-watchdog" and default is "no".

Thanks
Zhang Chen

Quoted 7 lines

Thanks!

Phil.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
net/Makefile.objs +0 -0
   tap-obj-$(CONFIG_LINUX) = tap-linux.o
   tap-obj-$(CONFIG_BSD) = tap-bsd.o

[...]

author
#8 lore raw

RFC PATCH 2/4 net/awd.c: Initailize input/output chardev

In reply to Zhang Chen

From: Zhang Chen <[email protected]>

Find and check the chardev awd_node and notification_node, The awd_node used for keep connect with outside(like VM client/other host/Remote server), and the notification_node used for do some operation when disconnect event occur.

---
 net/awd.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
net/awd.c +37 -0
index d42b4a7372..ad3d39c982 100644
@@ -42,6 +42,8 @@ typedef struct AwdState {
     char *opt_script;
     uint32_t pulse_interval;
     uint32_t timeout;
+    CharBackend chr_awd_node;
+    CharBackend chr_notification_node;
     IOThread *iothread;
 } AwdState;
 
@@ -175,9 +177,30 @@ out:
     error_propagate(errp, local_err);
 }
 
+static int find_and_check_chardev(Chardev **chr,
+                                  char *chr_name,
+                                  Error **errp)
+{
+    *chr = qemu_chr_find(chr_name);
+    if (*chr == NULL) {
+        error_setg(errp, "Device '%s' not found",
+                   chr_name);
+        return 1;
+    }
+
+    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 awd_complete(UserCreatable *uc, Error **errp)
 {
     AwdState *s = AWD(uc);
+    Chardev *chr;
 
     if (!s->awd_node || !s->iothread ||
         !s->notification_node || !s->opt_script) {
@@ -187,6 +210,20 @@ static void awd_complete(UserCreatable *uc, Error **errp)
         return;
     }
 
+    if (find_and_check_chardev(&chr, s->awd_node, errp) ||
+        !qemu_chr_fe_init(&s->chr_awd_node, chr, errp)) {
+        error_setg(errp, "advanced-watchdog can't find chardev awd_node: %s",
+                   s->awd_node);
+        return;
+    }
+
+    if (find_and_check_chardev(&chr, s->notification_node, errp) ||
+        !qemu_chr_fe_init(&s->chr_notification_node, chr, errp)) {
+        error_setg(errp, "advanced-watchdog can't find "
+                   "chardev notification_node: %s", s->notification_node);
+        return;
+    }
+
     return;
 }
 
Signature · 1 line
2.17.1
author
#9 lore raw

RFC PATCH 3/4 net/awd.c: Load advanced watch dog worker thread job

In reply to Zhang Chen

From: Zhang Chen <[email protected]>

This patch load pulse_timer and timeout_timer in the new iothread. The pulse timer will send pulse info to awd_node, and the timeout timer will check the reply pulse from awd_node. If timeout occur, it will send opt_script's data to the notification_node.

---
 net/awd.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 188 insertions(+)
net/awd.c +188 -0
index ad3d39c982..ea7f628437 100644
@@ -40,17 +40,137 @@ typedef struct AwdState {
     char *awd_node;
     char *notification_node;
     char *opt_script;
+    char *opt_script_data;
     uint32_t pulse_interval;
     uint32_t timeout;
     CharBackend chr_awd_node;
     CharBackend chr_notification_node;
+    SocketReadState awd_rs;
+
+    QEMUTimer *pulse_timer;
+    QEMUTimer *timeout_timer;
     IOThread *iothread;
+    GMainContext *worker_context;
 } AwdState;
 
 typedef struct AwdClass {
     ObjectClass parent_class;
 } AwdClass;
 
+static int awd_chr_send(AwdState *s,
+                        const uint8_t *buf,
+                        uint32_t size)
+{
+    int ret = 0;
+    uint32_t len = htonl(size);
+
+    if (!size) {
+        return 0;
+    }
+
+    ret = qemu_chr_fe_write_all(&s->chr_awd_node, (uint8_t *)&len,
+                                sizeof(len));
+    if (ret != sizeof(len)) {
+        goto err;
+    }
+
+    ret = qemu_chr_fe_write_all(&s->chr_awd_node, (uint8_t *)buf,
+                                size);
+    if (ret != size) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    return ret < 0 ? ret : -EIO;
+}
+
+static int awd_chr_can_read(void *opaque)
+{
+    return AWD_READ_LEN_MAX;
+}
+
+static void awd_node_in(void *opaque, const uint8_t *buf, int size)
+{
+    AwdState *s = AWD(opaque);
+    int ret;
+
+    ret = net_fill_rstate(&s->awd_rs, buf, size);
+    if (ret == -1) {
+        qemu_chr_fe_set_handlers(&s->chr_awd_node, NULL, NULL, NULL, NULL,
+                                 NULL, NULL, true);
+        error_report("advanced-watchdog get pulse error");
+    }
+}
+
+static void awd_send_pulse(void *opaque)
+{
+    AwdState *s = opaque;
+    char buf[] = "advanced-watchdog pulse";
+
+    awd_chr_send(s, (uint8_t *)buf, sizeof(buf));
+}
+
+static void awd_regular_pulse(void *opaque)
+{
+    AwdState *s = opaque;
+
+    awd_send_pulse(s);
+    timer_mod(s->pulse_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+              s->pulse_interval);
+}
+
+static void awd_timeout(void *opaque)
+{
+    AwdState *s = opaque;
+    int ret = 0;
+
+    ret = qemu_chr_fe_write_all(&s->chr_notification_node,
+                                (uint8_t *)s->opt_script_data,
+                                strlen(s->opt_script_data));
+    if (ret) {
+        error_report("advanced-watchdog notification failure");
+    }
+}
+
+static void awd_timer_init(AwdState *s)
+{
+    AioContext *ctx = iothread_get_aio_context(s->iothread);
+
+    s->timeout_timer = aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL, SCALE_MS,
+                                     awd_timeout, s);
+
+    s->pulse_timer = aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL, SCALE_MS,
+                                      awd_regular_pulse, s);
+
+    if (!s->pulse_interval) {
+        s->pulse_interval = AWD_PULSE_INTERVAL_DEFAULT;
+    }
+
+    if (!s->timeout) {
+        s->timeout = AWD_TIMEOUT_DEFAULT;
+    }
+
+    timer_mod(s->pulse_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+              s->pulse_interval);
+}
+
+static void awd_timer_del(AwdState *s)
+{
+    if (s->pulse_timer) {
+        timer_del(s->pulse_timer);
+        timer_free(s->pulse_timer);
+        s->pulse_timer = NULL;
+    }
+
+    if (s->timeout_timer) {
+        timer_del(s->timeout_timer);
+        timer_free(s->timeout_timer);
+        s->timeout_timer = NULL;
+    }
+ }
+
 static char *awd_get_node(Object *obj, Error **errp)
 {
     AwdState *s = AWD(obj);
@@ -177,6 +297,22 @@ out:
     error_propagate(errp, local_err);
 }
 
+static void awd_rs_finalize(SocketReadState *awd_rs)
+{
+    AwdState *s = container_of(awd_rs, AwdState, awd_rs);
+
+    if (!s->server) {
+        char buf[] = "advanced-watchdog reply pulse";
+
+        awd_chr_send(s, (uint8_t *)buf, sizeof(buf));
+    }
+
+    timer_mod(s->timeout_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
+              s->timeout);
+
+    error_report("advanced-watchdog got message : %s", awd_rs->buf);
+}
+
 static int find_and_check_chardev(Chardev **chr,
                                   char *chr_name,
                                   Error **errp)
@@ -197,6 +333,41 @@ static int find_and_check_chardev(Chardev **chr,
     return 0;
 }
 
+static void awd_iothread(AwdState *s)
+{
+    object_ref(OBJECT(s->iothread));
+    s->worker_context = iothread_get_g_main_context(s->iothread);
+
+    qemu_chr_fe_set_handlers(&s->chr_awd_node, awd_chr_can_read,
+                             awd_node_in, NULL, NULL,
+                             s, s->worker_context, true);
+
+    awd_timer_init(s);
+}
+
+static int get_opt_script_data(AwdState *s)
+{
+    FILE *opt_fd;
+    long fsize;
+
+    opt_fd = fopen(s->opt_script, "r");
+    if (opt_fd == NULL) {
+        error_report("advanced-watchdog can't read "
+                     "opt_script: %s", s->opt_script);
+        return -1;
+    }
+
+    fseek(opt_fd, 0, SEEK_END);
+    fsize = ftell(opt_fd);
+    fseek(opt_fd, 0, SEEK_SET);
+    s->opt_script_data = malloc(fsize + 1);
+    fread(s->opt_script_data, 1, fsize, opt_fd);
+
+    fclose(opt_fd);
+
+    return 0;
+}
+
 static void awd_complete(UserCreatable *uc, Error **errp)
 {
     AwdState *s = AWD(uc);
@@ -224,6 +395,16 @@ static void awd_complete(UserCreatable *uc, Error **errp)
         return;
     }
 
+    if (get_opt_script_data(s)) {
+        error_setg(errp, "advanced-watchdog can't get "
+                   "opt script data: %s", s->opt_script);
+        return;
+    }
+
+    net_socket_rs_init(&s->awd_rs, awd_rs_finalize, false);
+
+    awd_iothread(s);
+
     return;
 }
 
@@ -272,6 +453,13 @@ static void awd_finalize(Object *obj)
 {
     AwdState *s = AWD(obj);
 
+    qemu_chr_fe_deinit(&s->chr_awd_node, false);
+    qemu_chr_fe_deinit(&s->chr_notification_node, false);
+
+    if (s->iothread) {
+        awd_timer_del(s);
+    }
+
     g_free(s->awd_node);
     g_free(s->notification_node);
 }
Signature · 1 line
2.17.1
author
#10 lore raw

RFC PATCH 4/4 vl.c: Make Advanced Watch Dog delayed initialization

In reply to Zhang Chen

From: Zhang Chen <[email protected]>

Because Advanced Watch Dog module needs chardev socket to initialize properly before.

---
 vl.c | 7 +++++++
 1 file changed, 7 insertions(+)
vl.c +7 -0
index 4489cfb2bb..4094f61d28 100644
@@ -2683,6 +2683,13 @@ static bool object_create_initial(const char *type, QemuOpts *opts)
         return false;
     }
 
+    /*
+     * Reason: Advanced Watch Dog property "chardev".
+     */
+    if (g_str_equal(type, "advanced-watchdog")) {
+        return false;
+    }
+
     /* Memory allocation by backends needs to be done
      * after configure_accelerator() (due to the tcg_enabled()
      * checks at memory_region_init_*()).
Signature · 1 line
2.17.1
#11 lore raw
In reply to Zhang Chen
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

Clone of 'https://git.qemu.org/git/dtc.git' into submodule path 'dtc' failed
failed to update submodule dtc
Submodule 'dtc' (https://git.qemu.org/git/dtc.git) unregistered for path 'dtc' make[1]: *** [/var/tmp/patchew-tester-tmp-2eq69u33/src/docker-src.2019-10-16-11.34.59.10123] Error 1 make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-2eq69u33/src'
make: *** [docker-run-test-quick@centos7] Error 2

real 0m3.762s
user 0m2.349s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#12 lore raw
Quoted 19 lines · On Wed, Oct 16, 2019 at 11:35 PM <[email protected]> wrote:

Patchew URL:
https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

Quoted 12 lines

Clone of 'https://git.qemu.org/git/dtc.git' into submodule path 'dtc' failed
failed to update submodule dtc
Submodule 'dtc' (https://git.qemu.org/git/dtc.git) unregistered for path 'dtc'
make[1]: *** [/var/tmp/patchew-tester-tmp-2eq69u33/src/docker-src.2019-10-16-11.34.59.10123] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-2eq69u33/src'
make: *** [docker-run-test-quick@centos7] Error 2

It looks this problem dose not caused by my patch series?

Thanks
Zhang Chen

Quoted 11 lines

real 0m3.762s
user 0m2.349s

The full log is available at

http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message
.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#13 lore raw
In reply to [email protected]
Quoted 17 lines · On Wed, Oct 16, 2019 at 11:35 PM <[email protected]> wrote:

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

Quoted 7 lines

Clone of 'https://git.qemu.org/git/dtc.git' into submodule path 'dtc' failed
failed to update submodule dtc
Submodule 'dtc' (https://git.qemu.org/git/dtc.git) unregistered for path 'dtc' make[1]: *** [/var/tmp/patchew-tester-tmp-2eq69u33/src/docker-src.2019-10-16-11.34.59.10123] Error 1 make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-2eq69u33/src'
make: *** [docker-run-test-quick@centos7] Error 2

It looks this problem dose not caused by my patch series?

Thanks
Zhang Chen

Quoted 9 lines

real 0m3.762s
user 0m2.349s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]