From nobody Mon Apr 29 13:02:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576587537; cv=none; d=zohomail.com; s=zohoarc; b=OzCjLZ8M9cI+aMZkAOZ0lTjOx/WxsJH7QdBZ9dYN3Od34Dw7Ctv2PpmQb4F0HyhDaFWApkkU7fQ3csDykZrIAA3cxXbWzOl+OyEo8IvmeYjfrtx7zJ+qnFYm57RmaQvmEwe0WMAfyP9o9UNo3AO9ZijDfER1GPleUbBobUA4fOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576587537; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=dpallPtjJtmNZvVH5G65yox8CRz47Y6NkkIw3WRGBS8=; b=N77KT8zcrEbO9bXv5yeOLbQZOSx5jNbga1bvkUkq37x7dCX3L7cVcwatzJOWXhuZAEgmPJgQJqhbH0nsTyHOgYjE7N/mL7m9zIylSXDzwpdqbaj3+2yV6DTogQ5XAImttmPrY86RcxAmuQ9rZWnNR+fG9MDtRfuBzwUGa4nNVbU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576587537055726.4737418488334; Tue, 17 Dec 2019 04:58:57 -0800 (PST) Received: from localhost ([::1]:40058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCRD-00068Y-N0 for importer@patchew.org; Tue, 17 Dec 2019 07:58:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54022) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCMV-0000Ok-QF for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihCMT-0001DG-TB for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:03 -0500 Received: from mga18.intel.com ([134.134.136.126]:49326) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihCMT-00016O-Kd for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:01 -0500 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2019 04:53:55 -0800 Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008.jf.intel.com with ESMTP; 17 Dec 2019 04:53:53 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,325,1571727600"; d="scan'208";a="209689617" From: Zhang Chen To: Jason Wang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-dev Subject: [PATCH V4 1/5] net/awd.c: Introduce Advanced Watch Dog module framework Date: Tue, 17 Dec 2019 20:45:50 +0800 Message-Id: <20191217124554.30818-2-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217124554.30818-1-chen.zhang@intel.com> References: <20191217124554.30818-1-chen.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen 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. If you want to use it, please add "--enable-awd" when configure qemu. Demo command: -object advanced-watchdog,id=3Dawd1,server=3Don,awd_node=3Dd_node,notificat= ion_node=3Dremote_server,opt_script=3Dopt_script_path,iothread=3Dawd_iothre= ad,pulse_interval=3D1000,timeout=3D5000 Signed-off-by: Zhang Chen --- configure | 9 ++ net/Makefile.objs | 1 + net/awd.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 20 ++++ 4 files changed, 291 insertions(+) create mode 100644 net/awd.c diff --git a/configure b/configure index 6099be1d84..49d1830de4 100755 --- a/configure +++ b/configure @@ -383,6 +383,7 @@ vhost_scsi=3D"" vhost_vsock=3D"" vhost_user=3D"" vhost_user_fs=3D"" +awd=3D"no" kvm=3D"no" hax=3D"no" hvf=3D"no" @@ -1304,6 +1305,10 @@ for opt do ;; --enable-vhost-user-fs) vhost_user_fs=3D"yes" ;; + --disable-awd) awd=3D"no" + ;; + --enable-awd) awd=3D"yes" + ;; --disable-opengl) opengl=3D"no" ;; --enable-opengl) opengl=3D"yes" @@ -1780,6 +1785,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: vhost-crypto vhost-user-crypto backend support vhost-kernel vhost kernel backend support vhost-user vhost-user backend support + awd Advanced Watch Dog support spice spice rbd rados block device (rbd) libiscsi iscsi support @@ -7043,6 +7049,9 @@ fi if test "$vhost_user" =3D "yes" ; then echo "CONFIG_VHOST_USER=3Dy" >> $config_host_mak fi +if test "$awd" =3D "yes" ; then + echo "CONFIG_AWD=3Dy" >> $config_host_mak +fi if test "$vhost_user_fs" =3D "yes" ; then echo "CONFIG_VHOST_USER_FS=3Dy" >> $config_host_mak fi diff --git a/net/Makefile.objs b/net/Makefile.objs index c5d076d19c..187e655443 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -19,6 +19,7 @@ common-obj-y +=3D colo-compare.o common-obj-y +=3D colo.o common-obj-y +=3D filter-rewriter.o common-obj-y +=3D filter-replay.o +common-obj-$(CONFIG_AWD) +=3D awd.o =20 tap-obj-$(CONFIG_LINUX) =3D tap-linux.o tap-obj-$(CONFIG_BSD) =3D tap-bsd.o diff --git a/net/awd.c b/net/awd.c new file mode 100644 index 0000000000..d42b4a7372 --- /dev/null +++ b/net/awd.c @@ -0,0 +1,261 @@ +/* + * Advanced Watch Dog + * + * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) + * (a.k.a. Fault Tolerance or Continuous Replication) + * + * Copyright (c) 2019 Intel Corporation + * + * Author: Zhang Chen + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "trace.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "net/net.h" +#include "qom/object_interfaces.h" +#include "qom/object.h" +#include "chardev/char-fe.h" +#include "qemu/sockets.h" +#include "sysemu/iothread.h" + +#define TYPE_AWD "advanced-watchdog" +#define AWD(obj) OBJECT_CHECK(AwdState, (obj), TYPE_AWD) + +#define AWD_READ_LEN_MAX NET_BUFSIZE +/* Default advanced watchdog pulse interval */ +#define AWD_PULSE_INTERVAL_DEFAULT 5000 +/* Default advanced watchdog timeout */ +#define AWD_TIMEOUT_DEFAULT 2000 + +typedef struct AwdState { + Object parent; + + bool server; + char *awd_node; + char *notification_node; + char *opt_script; + uint32_t pulse_interval; + uint32_t timeout; + IOThread *iothread; +} AwdState; + +typedef struct AwdClass { + ObjectClass parent_class; +} AwdClass; + +static char *awd_get_node(Object *obj, Error **errp) +{ + AwdState *s =3D AWD(obj); + + return g_strdup(s->awd_node); +} + +static void awd_set_node(Object *obj, const char *value, Error **errp) +{ + AwdState *s =3D AWD(obj); + + g_free(s->awd_node); + s->awd_node =3D g_strdup(value); +} + +static char *noti_get_node(Object *obj, Error **errp) +{ + AwdState *s =3D AWD(obj); + + return g_strdup(s->notification_node); +} + +static void noti_set_node(Object *obj, const char *value, Error **errp) +{ + AwdState *s =3D AWD(obj); + + g_free(s->notification_node); + s->notification_node =3D g_strdup(value); +} + +static char *opt_script_get_node(Object *obj, Error **errp) +{ + AwdState *s =3D AWD(obj); + + return g_strdup(s->opt_script); +} + +static void opt_script_set_node(Object *obj, const char *value, Error **er= rp) +{ + AwdState *s =3D AWD(obj); + + g_free(s->opt_script); + s->opt_script =3D g_strdup(value); +} + +static bool awd_get_server(Object *obj, Error **errp) +{ + AwdState *s =3D AWD(obj); + + return s->server; +} + +static void awd_set_server(Object *obj, bool value, Error **errp) +{ + AwdState *s =3D AWD(obj); + + s->server =3D value; +} + +static void awd_get_interval(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + AwdState *s =3D AWD(obj); + uint32_t value =3D s->pulse_interval; + + visit_type_uint32(v, name, &value, errp); +} + +static void awd_set_interval(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + AwdState *s =3D AWD(obj); + Error *local_err =3D NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &local_err); + if (local_err) { + goto out; + } + if (!value) { + error_setg(&local_err, "Property '%s.%s' requires a positive value= ", + object_get_typename(obj), name); + goto out; + } + s->pulse_interval =3D value; + +out: + error_propagate(errp, local_err); +} + +static void awd_get_timeout(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + AwdState *s =3D AWD(obj); + uint32_t value =3D s->timeout; + + visit_type_uint32(v, name, &value, errp); +} + +static void awd_set_timeout(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + AwdState *s =3D AWD(obj); + Error *local_err =3D NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &local_err); + if (local_err) { + goto out; + } + + if (!value) { + error_setg(&local_err, "Property '%s.%s' requires a positive value= ", + object_get_typename(obj), name); + goto out; + } + s->timeout =3D value; + +out: + error_propagate(errp, local_err); +} + +static void awd_complete(UserCreatable *uc, Error **errp) +{ + AwdState *s =3D AWD(uc); + + if (!s->awd_node || !s->iothread || + !s->notification_node || !s->opt_script) { + error_setg(errp, "advanced-watchdog needs 'awd_node', " + "'notification_node', 'opt_script' " + "and 'server' property set"); + return; + } + + return; +} + +static void awd_class_init(ObjectClass *oc, void *data) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + + ucc->complete =3D awd_complete; +} + +static void awd_init(Object *obj) +{ + AwdState *s =3D AWD(obj); + + object_property_add_str(obj, "awd_node", + awd_get_node, awd_set_node, + NULL); + + object_property_add_str(obj, "notification_node", + noti_get_node, noti_set_node, + NULL); + + object_property_add_str(obj, "opt_script", + opt_script_get_node, opt_script_set_node, + NULL); + + object_property_add_bool(obj, "server", + awd_get_server, + awd_set_server, NULL); + + object_property_add(obj, "pulse_interval", "uint32", + awd_get_interval, + awd_set_interval, NULL, NULL, NULL); + + object_property_add(obj, "timeout", "uint32", + awd_get_timeout, + awd_set_timeout, NULL, NULL, NULL); + + object_property_add_link(obj, "iothread", TYPE_IOTHREAD, + (Object **)&s->iothread, + object_property_allow_set_link, + OBJ_PROP_LINK_STRONG, NULL); +} + +static void awd_finalize(Object *obj) +{ + AwdState *s =3D AWD(obj); + + g_free(s->awd_node); + g_free(s->notification_node); +} + +static const TypeInfo awd_info =3D { + .name =3D TYPE_AWD, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(AwdState), + .instance_init =3D awd_init, + .instance_finalize =3D awd_finalize, + .class_size =3D sizeof(AwdClass), + .class_init =3D awd_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void register_types(void) +{ + type_register_static(&awd_info); +} + +type_init(register_types); diff --git a/qemu-options.hx b/qemu-options.hx index 65c9473b73..40417afab5 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4589,6 +4589,26 @@ 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 tcpdu= mp or Wireshark. =20 +@item -object advanced-watchdog,id=3D@var{id},awd_node=3D@var{chardevid},n= otification_node=3D@var{chardevid},server=3D@var{server},iothread=3D@var{id= },opt_script=3D@var{path}[,pulse_interval=3D@var{time_ms},timeout=3D@var{ti= me_ms}] + +Advanced Watch Dog is an universal monitoring module on VMM side, it can b= e used +to detect network down(VMM to guest, VMM to VMM, VMM to another remote ser= ver) +and do previously set operation. AWD(Advanced WatchDog) use awd_node +@var{chardevid} parameter to connect with a -chardev node for heartbeat +service, and the service use the server @var{server} parameter to divided = into +server side and client side. The iothread @var{id} parameter make AWD atta= ch to +iothread and run independently of the main loop. The pulse_interval @var{t= ime_ms} +and timeout @var{time_ms} are heartbeat service property, default property= are +pulse_interval=3D5000, timeout=3D2000. AWD use the notification_node @var{= chardevid} +attach another -chardev socket node to do previously set operation, user c= an +setup the operation(user command) in opt_script file, AWD will open this s= cript +and send it to notification_node. It make user have basic VM/Host network +monitoring tools and basic false tolerance and recovery solution. + +Usage cases: +Send message to admin, notify another VMM, send qmp command to qemu do some +operation like restart the VM, build VMM heartbeat system, etc. + @item -object colo-compare,id=3D@var{id},primary_in=3D@var{chardevid},seco= ndary_in=3D@var{chardevid},outdev=3D@var{chardevid},iothread=3D@var{id}[,vn= et_hdr_support][,notify_dev=3D@var{id}] =20 Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@v= ar{chardevid}, than compare primary packet with --=20 2.17.1 From nobody Mon Apr 29 13:02:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576587321; cv=none; d=zohomail.com; s=zohoarc; b=fp0ygHgV7qqE4KkbB1Y83Ed9Uzo1iHZ/Z9bjWfEowKv9BHeLTWWGAiIJKOM+Ds7+ZQGXFECzyP7rb7vdmhHvZM1CMuFjOS89T1njlPVU2T8O3kKuPTGm75BeVnbwLA2Xexk8rgU9wDjDAYXzEdzyhJ/j7LB7bnxAAVFoytSS8G4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576587321; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=IeLX1OvBrenBmPp2PbsEh+TVa+eDXY976VojxizdQWk=; b=BLmUcBqhmpggCOQr5hl6NdWfA+oXVYvFEnAMmzdgWQMH62tVlta84VFaZsldPejU9qQH/h+qKiH+GJB8oU/mA+VvknKX8F/JVyUAoCv2wnNuFcROu0sE+EszkXvAq4YL04kRryQzBHeV7lvJxJ7EUJ+rmu633hg8wZINjGWL3kk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576587321434678.5410059562727; Tue, 17 Dec 2019 04:55:21 -0800 (PST) Received: from localhost ([::1]:39990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCNj-0001fD-8I for importer@patchew.org; Tue, 17 Dec 2019 07:55:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53963) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCMT-0000OP-Vs for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihCMS-0001Bb-6a for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:01 -0500 Received: from mga18.intel.com ([134.134.136.126]:49328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihCMR-00018a-Ty for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:00 -0500 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2019 04:53:56 -0800 Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008.jf.intel.com with ESMTP; 17 Dec 2019 04:53:55 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,325,1571727600"; d="scan'208";a="209689629" From: Zhang Chen To: Jason Wang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-dev Subject: [PATCH V4 2/5] net/awd.c: Initailize input/output chardev Date: Tue, 17 Dec 2019 20:45:51 +0800 Message-Id: <20191217124554.30818-3-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217124554.30818-1-chen.zhang@intel.com> References: <20191217124554.30818-1-chen.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen 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. Signed-off-by: Zhang Chen --- net/awd.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/net/awd.c b/net/awd.c index d42b4a7372..ad3d39c982 100644 --- a/net/awd.c +++ b/net/awd.c @@ -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; =20 @@ -175,9 +177,30 @@ out: error_propagate(errp, local_err); } =20 +static int find_and_check_chardev(Chardev **chr, + char *chr_name, + Error **errp) +{ + *chr =3D qemu_chr_find(chr_name); + if (*chr =3D=3D 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 =3D AWD(uc); + Chardev *chr; =20 if (!s->awd_node || !s->iothread || !s->notification_node || !s->opt_script) { @@ -187,6 +210,20 @@ static void awd_complete(UserCreatable *uc, Error **er= rp) return; } =20 + 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; } =20 --=20 2.17.1 From nobody Mon Apr 29 13:02:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576587321; cv=none; d=zohomail.com; s=zohoarc; b=cbGqXR+f/EwT0cEmWiJ/15/9CF8nFAkmL1HoOLlagwSJUQg0bADVWTNKmToqE7VtZhhs9w1EoUDXReP3ZS+6GWMUfvYiH3ljsd4RcjQogsCg63sOLLvjNWwgrYCr56WykHWplfoqLW9K+2xzfZlKtJ8dJbjGSWd9bnyHXqTmsTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576587321; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=6m2o4C740CqQ1sS5Rlqj24nnFN8WZGUSXw5LbKRYFP4=; b=NglXiNIu/AEBHsDU6p5FeAhsS9ltfxMh3q/nz10CF8C8zwb1BDMWZcCao2qf2zCW0bMZewE8Ed9HFJ3+4FW0zVmw3qhYiZKGfSfkfW/ZD90RIimcr6VRGB2PpoDlmXlaK/z5x/PagASwXnliDZkISyNmRVr221C4A00vdhZ/ZeU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157658732187169.72272123739037; Tue, 17 Dec 2019 04:55:21 -0800 (PST) Received: from localhost ([::1]:39993 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCNj-0001hq-T0 for importer@patchew.org; Tue, 17 Dec 2019 07:55:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53978) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCMU-0000OR-0h for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihCMS-0001Bp-La for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:01 -0500 Received: from mga18.intel.com ([134.134.136.126]:49328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihCMS-00018a-Dc for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:00 -0500 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2019 04:53:58 -0800 Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008.jf.intel.com with ESMTP; 17 Dec 2019 04:53:57 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,325,1571727600"; d="scan'208";a="209689636" From: Zhang Chen To: Jason Wang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-dev Subject: [PATCH V4 3/5] net/awd.c: Load advanced watch dog worker thread job Date: Tue, 17 Dec 2019 20:45:52 +0800 Message-Id: <20191217124554.30818-4-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217124554.30818-1-chen.zhang@intel.com> References: <20191217124554.30818-1-chen.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen 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. Signed-off-by: Zhang Chen --- net/awd.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/net/awd.c b/net/awd.c index ad3d39c982..04f40e7cc8 100644 --- a/net/awd.c +++ b/net/awd.c @@ -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; =20 typedef struct AwdClass { ObjectClass parent_class; } AwdClass; =20 +static int awd_chr_send(AwdState *s, + const uint8_t *buf, + uint32_t size) +{ + int ret =3D 0; + uint32_t len =3D htonl(size); + + if (!size) { + return 0; + } + + ret =3D qemu_chr_fe_write_all(&s->chr_awd_node, (uint8_t *)&len, + sizeof(len)); + if (ret !=3D sizeof(len)) { + goto err; + } + + ret =3D qemu_chr_fe_write_all(&s->chr_awd_node, (uint8_t *)buf, + size); + if (ret !=3D 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 =3D AWD(opaque); + int ret; + + ret =3D net_fill_rstate(&s->awd_rs, buf, size); + if (ret =3D=3D -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 =3D opaque; + char buf[] =3D "advanced-watchdog pulse"; + + awd_chr_send(s, (uint8_t *)buf, sizeof(buf)); +} + +static void awd_regular_pulse(void *opaque) +{ + AwdState *s =3D 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 =3D opaque; + int ret =3D 0; + + ret =3D 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 =3D iothread_get_aio_context(s->iothread); + + s->timeout_timer =3D aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL, SCALE_MS, + awd_timeout, s); + + s->pulse_timer =3D aio_timer_new(ctx, QEMU_CLOCK_VIRTUAL, SCALE_MS, + awd_regular_pulse, s); + + if (!s->pulse_interval) { + s->pulse_interval =3D AWD_PULSE_INTERVAL_DEFAULT; + } + + if (!s->timeout) { + s->timeout =3D 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 =3D NULL; + } + + if (s->timeout_timer) { + timer_del(s->timeout_timer); + timer_free(s->timeout_timer); + s->timeout_timer =3D NULL; + } + } + static char *awd_get_node(Object *obj, Error **errp) { AwdState *s =3D AWD(obj); @@ -177,6 +297,22 @@ out: error_propagate(errp, local_err); } =20 +static void awd_rs_finalize(SocketReadState *awd_rs) +{ + AwdState *s =3D container_of(awd_rs, AwdState, awd_rs); + + if (!s->server) { + char buf[] =3D "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,46 @@ static int find_and_check_chardev(Chardev **chr, return 0; } =20 +static void awd_iothread(AwdState *s) +{ + object_ref(OBJECT(s->iothread)); + s->worker_context =3D 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 =3D fopen(s->opt_script, "r"); + if (opt_fd =3D=3D NULL) { + error_report("advanced-watchdog can't open " + "opt_script: %s", s->opt_script); + return -1; + } + + fseek(opt_fd, 0, SEEK_END); + fsize =3D ftell(opt_fd); + fseek(opt_fd, 0, SEEK_SET); + s->opt_script_data =3D malloc(fsize + 1); + + if (!fread(s->opt_script_data, 1, fsize, opt_fd)) { + error_report("advanced-watchdog can't read " + "opt_script: %s", s->opt_script); + return -1; + } + + fclose(opt_fd); + + return 0; +} + static void awd_complete(UserCreatable *uc, Error **errp) { AwdState *s =3D AWD(uc); @@ -224,6 +400,16 @@ static void awd_complete(UserCreatable *uc, Error **er= rp) return; } =20 + 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; } =20 @@ -272,6 +458,13 @@ static void awd_finalize(Object *obj) { AwdState *s =3D AWD(obj); =20 + 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); } --=20 2.17.1 From nobody Mon Apr 29 13:02:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576587323; cv=none; d=zohomail.com; s=zohoarc; b=GEfuMj7GAYA3AibaDZJY9cFbBUI6ethvPPBTYoJ3PleIweEHnAez/sjqgxvHwV0nZ3TxzFeRKsQlTFWK/3XgUcaCF9OaQa8BsqQv6bQE2PSZ/OtICdA/6pV5K8+7/gNYW43CujGnVEJ/JyNcwKXFKeBU0HRylPPUSpPW5GqqRKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576587323; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=0YUuhQE6/lPVjHp5S5Dyi/GZ3Qpe+/eOuWynzOle6Jc=; b=b0/hQNztrcGWf4wtqfFA6jBDnCoqOmES//dkN3siAhndr81e82S57ev8OGfaPnR1+MNForKlwf37axUYCPjLfVBfr4BBUVK6lu6I8i1+DQ/V47jcskaeGHUyoouppeQlS7gsGJlOO+LDfq+S/JYzqBLj7vC8yj/3QECk73TpfXM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576587323767214.19588541146481; Tue, 17 Dec 2019 04:55:23 -0800 (PST) Received: from localhost ([::1]:39994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCNk-0001iz-SQ for importer@patchew.org; Tue, 17 Dec 2019 07:55:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53979) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCMU-0000OS-17 for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihCMT-0001Cc-3n for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:01 -0500 Received: from mga18.intel.com ([134.134.136.126]:49328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihCMS-00018a-SY for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:01 -0500 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2019 04:53:59 -0800 Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008.jf.intel.com with ESMTP; 17 Dec 2019 04:53:58 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,325,1571727600"; d="scan'208";a="209689641" From: Zhang Chen To: Jason Wang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-dev Subject: [PATCH V4 4/5] vl.c: Make Advanced Watch Dog delayed initialization Date: Tue, 17 Dec 2019 20:45:53 +0800 Message-Id: <20191217124554.30818-5-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217124554.30818-1-chen.zhang@intel.com> References: <20191217124554.30818-1-chen.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen Advanced Watch Dog module needs chardev socket to initialize properly before running. Signed-off-by: Zhang Chen --- vl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vl.c b/vl.c index 6a65a64bfd..048fe458b9 100644 --- a/vl.c +++ b/vl.c @@ -2689,6 +2689,13 @@ static bool object_create_initial(const char *type, = QemuOpts *opts) return false; } =20 + /* + * 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_*()). --=20 2.17.1 From nobody Mon Apr 29 13:02:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576587477; cv=none; d=zohomail.com; s=zohoarc; b=luuh+7J1ZtxtI79JZNY6tgNNTZeUMTx/m7sht/EkXEnw7lfnJbThMiQcrYaaQO4hAQDR87e3tiGRMJwnjhRzspf5pVh6mefiJ7vIGf06XyXRIbbahIRDxppMol95QNSCI3L3xuRjt4aUpXGnpuSEwCdKw07AYAx/MnhKoRgXHgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576587477; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=GDWMXa+W7vjXwQhayk3hViAjgIOsDx5IeBt9fJJqlts=; b=d9Mi778XOkaqmcy1IqY8/vqP7CZpMNCRDl1SivRTtt+KVYWeeuncv0gzb6l3pT0a9NYzytovL1wALxa61y3nkHcAa61XyIw1YOtLEsqYPfOqiJz2QVtZ7STeJcIU2r2jBU0GXmatrWuf68QVRBu4V2WxVD88QE+jMNjLTYQjv0g= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576587477006716.9303908124128; Tue, 17 Dec 2019 04:57:57 -0800 (PST) Received: from localhost ([::1]:40052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCQE-0005FG-N7 for importer@patchew.org; Tue, 17 Dec 2019 07:57:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54011) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihCMV-0000OZ-9V for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihCMU-0001Di-1E for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:03 -0500 Received: from mga18.intel.com ([134.134.136.126]:49328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihCMT-00018a-Mv for qemu-devel@nongnu.org; Tue, 17 Dec 2019 07:54:01 -0500 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2019 04:54:01 -0800 Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008.jf.intel.com with ESMTP; 17 Dec 2019 04:54:00 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,325,1571727600"; d="scan'208";a="209689654" From: Zhang Chen To: Jason Wang , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-dev Subject: [PATCH V4 5/5] docs/awd.txt: Add doc to introduce Advanced WatchDog(AWD) module Date: Tue, 17 Dec 2019 20:45:54 +0800 Message-Id: <20191217124554.30818-6-chen.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217124554.30818-1-chen.zhang@intel.com> References: <20191217124554.30818-1-chen.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen Add docs to introduce Advanced WatchDog detail and usage. Signed-off-by: Zhang Chen --- docs/awd.txt | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 docs/awd.txt diff --git a/docs/awd.txt b/docs/awd.txt new file mode 100644 index 0000000000..0ce513be5a --- /dev/null +++ b/docs/awd.txt @@ -0,0 +1,88 @@ +Advanced Watch Dog (AWD) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Copyright (c) 2019 Intel Corporation. +Author: Zhang Chen + +This work is licensed under the terms of the GNU GPL, version 2 or later. +See the COPYING file in the top-level directory. + +Introduction +------------ + +Advanced Watch Dog is an universal monitoring module on VMM side, it can b= e used +to detect network issues(VMM to guest, VMM to VMM, VMM to another remote s= erver) +and do previously set operation. Current AWD accept any input as the signal +to refresh the watchdog timer, and we can also make a certain interactive +protocol here. Users can pre-write some command or some messages in the +AWD opt-script as the notification output. We noticed that there is no way +for VMM communicate directly, so we engaged with real customer found that = they +need a lightweight and efficient mechanism to solve some practical problem= s, +for example Edge Computing cases(they think high level software is too hea= vy +to use in Edge or it is hard to manage and combine with VM instance). +It make user have basic VM/Host network monitoring tools and basic false +tolerance and recovery solution. + +Use case +-------- + +1. Monitor local guest status. +Running a simple application in guest for send signal to the local AWD mod= ule, +if timeout occur, AWD will notify high level admin or do some previously s= et +operation. For example send exit command to local QMP interface or qemu mo= nitor. + +2. Monitor other VMM. +AWD module can be connected to each other to build heartbeat service. + +3. Monitor other remote service. +In some cases, remote service have certain relationship with current VM. If +network connection have some issue, AWD can do some urgent operation like = reboot +local VM. etc... + +AWD usage +--------- + +User must "--enable-awd" in Qemu configuration. + +1. Monitor local guest status. + +-chardev socket,id=3Ddetection,host=3D0.0.0.0,port=3D9009,server,nowait +-chardev socket,id=3Dnotification,host=3D127.0.0.1,port=3D4445 +-object iothread,id=3Diothread1 +-object advanced-watchdog,id=3Dawd1,server=3Don,awd_node=3Ddetection,notif= ication_node=3Dnotification,opt_script=3Dcolo_opt_script,iothread=3Diothrea= d1,pulse_interval=3D1000,timeout=3D5000 +-monitor tcp::4445,server,nowait + +qemu_opt_script: +quit + +Guest service need connect to detection node, admin can check notification= node +to get message when timeout occur. + +2. Monitor other VMM. + +Demo usage(for COLO heartbeat service): + +In primary node: + +-chardev socket,id=3Dh1,host=3D3.3.3.3,port=3D9009,server,nowait +-chardev socket,id=3Dheartbeat0,host=3D3.3.3.3,port=3D4445 +-object iothread,id=3Diothread1 +-object advanced-watchdog,id=3Dheart1,server=3Don,awd_node=3Dh1,notificati= on_node=3Dheartbeat0,opt_script=3Dcolo_primary_opt_script,iothread=3Diothre= ad1,pulse_interval=3D1000,timeout=3D5000 + +colo_primary_opt_script: +x_colo_lost_heartbeat + +In secondary node: + +-monitor tcp::4445,server,nowait +-chardev socket,id=3Dh1,host=3D3.3.3.3,port=3D9009,reconnect=3D1 +-chardev socket,id=3Dheart1,host=3D3.3.3.8,port=3D4445 +-object iothread,id=3Diothread1 +-object advanced-watchdog,id=3Dheart1,server=3Doff,awd_node=3Dh1,notificat= ion_node=3Dheart1,opt_script=3Dcolo_secondary_opt_script,iothread=3Diothrea= d1,timeout=3D10000 + +colo_secondary_opt_script: +nbd_server_stop +x_colo_lost_heartbeat + +3. Monitor other remote service. + +Same like monitor local guest except detection node and notification node. --=20 2.17.1