From nobody Sun May 19 13:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153891027125258.094270927279695; Sun, 7 Oct 2018 04:04:31 -0700 (PDT) Received: from localhost ([::1]:41902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96rN-00061x-BF for importer@patchew.org; Sun, 07 Oct 2018 07:04:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96pW-00052x-3m for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g96pT-0007OB-8N for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:33 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:40444) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g96pT-0007N5-1f for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:31 -0400 Received: by mail-wr1-x429.google.com with SMTP id d2-v6so13293486wro.7 for ; Sun, 07 Oct 2018 04:02:30 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id v106-v6sm22065671wrc.85.2018.10.07.04.02.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 04:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dHwUI+oW9kBY8nFNgQ/u+ElfvzyazbIhkaMKkkwlxpo=; b=RGvKwuOCHOTg02AGE6C8PXbbda20pTqOJ8Pq1AOEinqvOVV1oNGcCkRJGI8mGOkwRY q7Bid1d9U6plVCA69894m2Y59KrPjf88ICxhSWklKYX4fg+Pxf1PtWGKx2Hh43VpHfVG DNp/m3HwfAItBL8waHnPgZUnrseNu5ueth9cgZ9JVjWP6Fgnh4GP1uEiIFjlfHR7fCMD USMSla6ndDkHnn+2jpHID4MtPM15dMbk6xYy71PozI9E2sfs5Gt/gODj7HSOkpWuXTqx bJG7A/YPwOJaOvm8WEy5tuM9I+8FTyn5o3MkOvyW/OAwEgIIVV4X9ze4YZbTAL6JoKyd 1EGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dHwUI+oW9kBY8nFNgQ/u+ElfvzyazbIhkaMKkkwlxpo=; b=Vyj1Q3XLSgLzvfQngMjRoEEV5b3wRdJTUkylzZMiEyABMd5xCTSWRvtnjBliHW++Ti Ck9xhfdhYEqeVlFwDnhNqqVFpMaw3twfLzSneeB+Vb3JO/TAiD9QeFO4YljMc2hoz+mF me94Y+ufF6ZI7izW9ulWV8R9BlnhHjlo3DVIQ59qQO7zAmvzafpiYWjCV9DmeZ7bbCSA cuDeyrO3uC6zvRzzyPDi5en4Yqx+otvprWJK1IqBYIELJa6eQtcQdRy1IX7pYMTBmLWh /5M+GAiWQpTniavIbRbf3Thw6jDzEOgDHCkGTs2vRdzjYKr9/yM5bRDUJt4T2iQfhhfQ Q/bw== X-Gm-Message-State: ABuFfogDBjCFMA5h41IgFveBSix3+8qsALecqbsjny/MH3CYBrRX07TH urjmAdmCeJ5E5/Ci3cKgGGUBXcTMf2U= X-Google-Smtp-Source: ACcGV63BYVjInu2bkb5ybXUilXnnYWiuT282mR/5ibStphnfJt4Q/5TSM/jFEIuEfUjIXFp+9795UQ== X-Received: by 2002:adf:e0c9:: with SMTP id e9-v6mr13716466wri.199.1538910149734; Sun, 07 Oct 2018 04:02:29 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 7 Oct 2018 14:02:17 +0300 Message-Id: <20181007110223.129692-2-bishara@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181007110223.129692-1-bishara@daynix.com> References: <20181007110223.129692-1-bishara@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::429 Subject: [Qemu-devel] [PATCH v2 1/7] qga: group agent init/cleanup init separate routines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth This patch better separates the init/cleanup routines out into separate functions to make the start-up procedure a bit easier to follow. This will be useful when we eventually break out the actual start/stop of the agent's main loop into separates routines that can be called multiple times after the init phase. Signed-off-by: Michael Roth --- qga/main.c | 82 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/qga/main.c b/qga/main.c index c399320d3c..fd02086bfc 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1211,9 +1211,21 @@ static bool check_is_frozen(GAState *s) return false; } =20 -static int run_agent(GAState *s, GAConfig *config, int socket_activation) +static GAState *initialize_agent(GAConfig *config) { - ga_state =3D s; + GAState *s =3D g_new0(GAState, 1); + + g_assert(ga_state =3D=3D NULL); + + s->log_level =3D config->log_level; + s->log_file =3D stderr; +#ifdef CONFIG_FSFREEZE + s->fsfreeze_hook =3D config->fsfreeze_hook; +#endif + s->pstate_filepath =3D g_strdup_printf("%s/qga.state", config->state_d= ir); + s->state_filepath_isfrozen =3D g_strdup_printf("%s/qga.state.isfrozen", + config->state_dir); + s->frozen =3D check_is_frozen(s); =20 g_log_set_default_handler(ga_log, s); g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR); @@ -1229,7 +1241,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) if (g_mkdir_with_parents(config->state_dir, S_IRWXU) =3D=3D -1) { g_critical("unable to create (an ancestor of) the state directory" " '%s': %s", config->state_dir, strerror(errno)); - return EXIT_FAILURE; + return NULL; } #endif =20 @@ -1254,7 +1266,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) if (!log_file) { g_critical("unable to open specified log file: %s", strerror(errno)); - return EXIT_FAILURE; + return NULL; } s->log_file =3D log_file; } @@ -1265,7 +1277,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) s->pstate_filepath, ga_is_frozen(s))) { g_critical("failed to load persistent state"); - return EXIT_FAILURE; + return NULL; } =20 config->blacklist =3D ga_command_blacklist_init(config->blacklist); @@ -1286,12 +1298,37 @@ static int run_agent(GAState *s, GAConfig *config, = int socket_activation) #ifndef _WIN32 if (!register_signal_handlers()) { g_critical("failed to register signal handlers"); - return EXIT_FAILURE; + return NULL; } #endif =20 s->main_loop =3D g_main_loop_new(NULL, false); =20 + ga_state =3D s; + return s; +} + +static void cleanup_agent(GAState *s) +{ + if (s->command_state) { + ga_command_state_cleanup_all(s->command_state); + ga_command_state_free(s->command_state); + json_message_parser_destroy(&s->parser); + } + if (s->channel) { + ga_channel_free(s->channel); + } + g_free(s->pstate_filepath); + g_free(s->state_filepath_isfrozen); + if (s->main_loop) { + g_main_loop_unref(s->main_loop); + } + g_free(s); + ga_state =3D NULL; +} + +static int run_agent(GAState *s, GAConfig *config, int socket_activation) +{ if (!channel_init(ga_state, config->method, config->channel_path, socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)= ) { g_critical("failed to initialize guest agent channel"); @@ -1315,7 +1352,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) int main(int argc, char **argv) { int ret =3D EXIT_SUCCESS; - GAState *s =3D g_new0(GAState, 1); + GAState *s; GAConfig *config =3D g_new0(GAConfig, 1); int socket_activation; =20 @@ -1383,44 +1420,25 @@ int main(int argc, char **argv) } } =20 - s->log_level =3D config->log_level; - s->log_file =3D stderr; -#ifdef CONFIG_FSFREEZE - s->fsfreeze_hook =3D config->fsfreeze_hook; -#endif - s->pstate_filepath =3D g_strdup_printf("%s/qga.state", config->state_d= ir); - s->state_filepath_isfrozen =3D g_strdup_printf("%s/qga.state.isfrozen", - config->state_dir); - s->frozen =3D check_is_frozen(s); - if (config->dumpconf) { config_dump(config); goto end; } =20 + s =3D initialize_agent(config); + if (!s) { + g_critical("error initializing guest agent"); + goto end; + } ret =3D run_agent(s, config, socket_activation); + cleanup_agent(s); =20 end: - if (s->command_state) { - ga_command_state_cleanup_all(s->command_state); - ga_command_state_free(s->command_state); - json_message_parser_destroy(&s->parser); - } - if (s->channel) { - ga_channel_free(s->channel); - } - g_free(s->pstate_filepath); - g_free(s->state_filepath_isfrozen); - if (config->daemonize) { unlink(config->pid_filepath); } =20 config_free(config); - if (s->main_loop) { - g_main_loop_unref(s->main_loop); - } - g_free(s); =20 return ret; } --=20 2.17.0 From nobody Sun May 19 13:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538910277272978.2605780344591; Sun, 7 Oct 2018 04:04:37 -0700 (PDT) Received: from localhost ([::1]:41904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96rQ-00067Y-UX for importer@patchew.org; Sun, 07 Oct 2018 07:04:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96pY-00053j-9L for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g96pV-0007Oy-UC for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:35 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:47038) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g96pU-0007OI-7w for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:33 -0400 Received: by mail-wr1-x431.google.com with SMTP id a2-v6so10658508wrc.13 for ; Sun, 07 Oct 2018 04:02:32 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id v106-v6sm22065671wrc.85.2018.10.07.04.02.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 04:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=al26aAdSyVWCbpaZIzAp/P6j8DXugnrKo2QzRCIW76c=; b=Mk4mVLlAOQx0za4455OADNvOTDOPPyB0sYfVDA1C2cl4RLlB3ysVW27cqXu9U4HEGL ZFCSsc+HH8R63+R/flyV30enIZR/sx5cMIVEBYzZbrY7eSbr9GN2jAmuhNdVLfAYWv6v 6f84mmACY2A469QHfaeEdjq/WGAMM5/gd3SeeuEaiuHsYvjM4LtYFX4ZZ/+hexYWYsZo 0key9ZW38iMjG4i5mnJt3N98tqlMItvuoTc0AvELce7Nu0m1iadf8l7Kl5rvhH5dsPkc cQLExkPJ8WhDgOfr7m5/hkK9roD6CBtXOuzAwA8cSgLGJDtYaP4Pxga591NAMNXr1AU9 lhzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=al26aAdSyVWCbpaZIzAp/P6j8DXugnrKo2QzRCIW76c=; b=pXH6mQCawHFrtUp/JoBLbECbrtMqZEqpALBuenhLSiof5cYampBfW1O1nrUwo4ba/a KkVhJ95xfLsSVDwyL0hG4jtPAcwZwENIrBMqC/bwab9D+bQLVv+lHbC9Ff7dH7cTLZOV A6D6HT4zfb7Abb1w+/xqJWPsp2IBn320AUxcrs4BhIs4534wqZGRUvgRzvf2/reahY12 EE5k2jjbv4u8wXPhuHoopQYeJHZPb7oEisw868X6BKEoEaHVyPJpQ3cxlahzSHMLBMtB lVm9Fyn1ijV45fiASbGK74lj1qSoiBT+t896meEJlijpxMr9UJropHJzgBouU+9uAaAH FOMw== X-Gm-Message-State: ABuFfoiapZpftnGTDYDS47BaHQ1K/w4kVBjec6CPkjC+ufsWJ1tnub7J hnNRs3usWChFAzPxxwgG6TisD9D61BI= X-Google-Smtp-Source: ACcGV63rtmWkQPLszYJi8FcC1ebZWmZLmOVxWi7dju9imNPb2KTd64FqDG2adXxkcNxk0+skdKI7EQ== X-Received: by 2002:adf:f248:: with SMTP id b8-v6mr12370714wrp.184.1538910150964; Sun, 07 Oct 2018 04:02:30 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 7 Oct 2018 14:02:18 +0300 Message-Id: <20181007110223.129692-3-bishara@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181007110223.129692-1-bishara@daynix.com> References: <20181007110223.129692-1-bishara@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 Subject: [Qemu-devel] [PATCH v2 2/7] qga: hang GAConfig/socket_activation off of GAState global X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth For w32 services we rely on the global GAState to access resources associated with the agent within service_main(). Currently this is sufficient for starting the agent since we open the channel once prior to calling service_main(), and simply start the GMainLoop to start the agent from within service_main(). Eventually we want to be able to also [re-]open the communication channel from within service_main(), which requires access to config/socket_activation variables, so we hang them off GAState in preparation for that. Signed-off-by: Michael Roth Signed-off-by: Sameeh Jubran --- qga/main.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/qga/main.c b/qga/main.c index fd02086bfc..9f4dc0b2c5 100644 --- a/qga/main.c +++ b/qga/main.c @@ -69,6 +69,25 @@ typedef struct GAPersistentState { int64_t fd_counter; } GAPersistentState; =20 +typedef struct GAConfig { + char *channel_path; + char *method; + char *log_filepath; + char *pid_filepath; +#ifdef CONFIG_FSFREEZE + char *fsfreeze_hook; +#endif + char *state_dir; +#ifdef _WIN32 + const char *service; +#endif + gchar *bliststr; /* blacklist may point to this string */ + GList *blacklist; + int daemonize; + GLogLevelFlags log_level; + int dumpconf; +} GAConfig; + struct GAState { JSONMessageParser parser; GMainLoop *main_loop; @@ -94,6 +113,8 @@ struct GAState { #endif gchar *pstate_filepath; GAPersistentState pstate; + GAConfig *config; + int socket_activation; }; =20 struct GAState *ga_state; @@ -905,25 +926,6 @@ static GList *split_list(const gchar *str, const gchar= *delim) return list; } =20 -typedef struct GAConfig { - char *channel_path; - char *method; - char *log_filepath; - char *pid_filepath; -#ifdef CONFIG_FSFREEZE - char *fsfreeze_hook; -#endif - char *state_dir; -#ifdef _WIN32 - const char *service; -#endif - gchar *bliststr; /* blacklist may point to this string */ - GList *blacklist; - int daemonize; - GLogLevelFlags log_level; - int dumpconf; -} GAConfig; - static void config_load(GAConfig *config) { GError *gerr =3D NULL; @@ -1211,7 +1213,7 @@ static bool check_is_frozen(GAState *s) return false; } =20 -static GAState *initialize_agent(GAConfig *config) +static GAState *initialize_agent(GAConfig *config, int socket_activation) { GAState *s =3D g_new0(GAState, 1); =20 @@ -1304,6 +1306,8 @@ static GAState *initialize_agent(GAConfig *config) =20 s->main_loop =3D g_main_loop_new(NULL, false); =20 + s->config =3D config; + s->socket_activation =3D socket_activation; ga_state =3D s; return s; } @@ -1327,10 +1331,10 @@ static void cleanup_agent(GAState *s) ga_state =3D NULL; } =20 -static int run_agent(GAState *s, GAConfig *config, int socket_activation) +static int run_agent(GAState *s) { - if (!channel_init(ga_state, config->method, config->channel_path, - socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)= ) { + if (!channel_init(s, s->config->method, s->config->channel_path, + s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : = -1)) { g_critical("failed to initialize guest agent channel"); return EXIT_FAILURE; } @@ -1425,12 +1429,12 @@ int main(int argc, char **argv) goto end; } =20 - s =3D initialize_agent(config); + s =3D initialize_agent(config, socket_activation); if (!s) { g_critical("error initializing guest agent"); goto end; } - ret =3D run_agent(s, config, socket_activation); + ret =3D run_agent(s); cleanup_agent(s); =20 end: --=20 2.17.0 From nobody Sun May 19 13:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538910428487905.9583960752385; Sun, 7 Oct 2018 04:07:08 -0700 (PDT) Received: from localhost ([::1]:41919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96tq-0008Gv-Fl for importer@patchew.org; Sun, 07 Oct 2018 07:07:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96pY-00053k-A8 for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g96pW-0007PL-Bb for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:35 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:35114) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g96pW-0007Oc-31 for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:34 -0400 Received: by mail-wr1-x42b.google.com with SMTP id w5-v6so17745658wrt.2 for ; Sun, 07 Oct 2018 04:02:33 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id v106-v6sm22065671wrc.85.2018.10.07.04.02.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 04:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1AZuVMdkFcKF3/GsgG9BEsBgA5oRIQC868BuIQbRYK0=; b=llEvaiieZXaNtt68ZwOvysCEsTcP4DDArlRVUPd/Ns4W5tv3Mag6qNUpqPM+xibtAL FjWjvP/0s2QRgk7fiPRLficuk8DQm/o9EK0pZtFHZa3IrqihMhKj25b56j6a/T95bYk4 wRk727cwRmCV7IqhdINz5XSS/7KqPYj7xC5vpWPbBOt8Nw/9nRnQEZ+3Hj4Wd6iDwKwA Sk/qi41YTlM4P3TyNWe7P9HUlYmYEfdhklOFVcE1kya+2cQF8VYBsKogW4yqq+n6EIjP n8lbwb92eWDTu6SJ4CwHLTcNR6jCdWxI5xNHL601cvmV2nlGmfh4wW25gHT+kpJtYY+l E8GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1AZuVMdkFcKF3/GsgG9BEsBgA5oRIQC868BuIQbRYK0=; b=L0/i8sDAqWZ76VHL7LO3Q6O6Tk+UP2tEZ8acBhPYLttqGqi8eEsKdpChVfAot50xag dfid/oy8tZxRy7TG0Dq8RFld9NVaSrTqq6JEiawj0j/LMUcAeS/KJW3pR6c5KQepCItd 5CGDJo8PIp1SDZtT4vN3vNtQP7rLYbVs0ClS4SN+ksmtCKAtZdFgBr4TgyqlDag/64r1 aYXr3/PcLBSM5Yr3MRQVXdxCDielK2O67xETlbwacCwv9XNU9V5Vkpsg0z+HjiwjmT6l dVfXj7TLAFkcHVFnIzK5WCRGLdTE7pWmrDBpuvipn0Eg69800LEXfyNcaPt3SOw057J1 F5aw== X-Gm-Message-State: ABuFfogxFs8ikUsFnmpIaP7Y8YuNcoRS3nSNWe+WkD4bCylo+F/Zg0jw A7FZyQiiB3NnyDAiblumZWZ1NZga0/4= X-Google-Smtp-Source: ACcGV62Ps5qc7MEW4Vbh3BcILJqb7zsYyJMEEbF4aey4BwvE+VdjItrJvmtwrLEmAaRrfGsHeq6DEw== X-Received: by 2002:adf:a3d0:: with SMTP id m16-v6mr13584090wrb.312.1538910152197; Sun, 07 Oct 2018 04:02:32 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 7 Oct 2018 14:02:19 +0300 Message-Id: <20181007110223.129692-4-bishara@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181007110223.129692-1-bishara@daynix.com> References: <20181007110223.129692-1-bishara@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42b Subject: [Qemu-devel] [PATCH v2 3/7] qga: move w32 service handling out of run_agent() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth Eventually we want a w32 service to be able to restart the qga main loop from within service_main(). To allow for this we move service handling out of run_agent() such that service_main() calls run_agent() instead of the reverse. Signed-off-by: Michael Roth Signed-off-by: Bishara AbuHattoum --- qga/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/qga/main.c b/qga/main.c index 9f4dc0b2c5..23a0a46b84 100644 --- a/qga/main.c +++ b/qga/main.c @@ -136,6 +136,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD typ= e, LPVOID data, LPVOID ctx); VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif +static int run_agent(GAState *s); =20 static void init_dfl_pathnames(void) @@ -729,7 +730,7 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[]) service->status.dwWaitHint =3D 0; SetServiceStatus(service->status_handle, &service->status); =20 - g_main_loop_run(ga_state->main_loop); + run_agent(ga_state); =20 service->status.dwCurrentState =3D SERVICE_STOPPED; SetServiceStatus(service->status_handle, &service->status); @@ -1338,17 +1339,8 @@ static int run_agent(GAState *s) g_critical("failed to initialize guest agent channel"); return EXIT_FAILURE; } -#ifndef _WIN32 + g_main_loop_run(ga_state->main_loop); -#else - if (config->daemonize) { - SERVICE_TABLE_ENTRY service_table[] =3D { - { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; - StartServiceCtrlDispatcher(service_table); - } else { - g_main_loop_run(ga_state->main_loop); - } -#endif =20 return EXIT_SUCCESS; } @@ -1434,7 +1426,19 @@ int main(int argc, char **argv) g_critical("error initializing guest agent"); goto end; } + +#ifdef _WIN32 + if (config->daemonize) { + SERVICE_TABLE_ENTRY service_table[] =3D { + { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; + StartServiceCtrlDispatcher(service_table); + } else { + ret =3D run_agent(s); + } +#else ret =3D run_agent(s); +#endif + cleanup_agent(s); =20 end: --=20 2.17.0 From nobody Sun May 19 13:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538910511139777.3777892885266; Sun, 7 Oct 2018 04:08:31 -0700 (PDT) Received: from localhost ([::1]:41927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96vB-0000qV-LZ for importer@patchew.org; Sun, 07 Oct 2018 07:08:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96pa-00055h-GJ for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g96pY-0007Q7-9O for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:38 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:33902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g96pW-0007PD-Pc for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:35 -0400 Received: by mail-wr1-x42c.google.com with SMTP id z4-v6so17740351wrb.1 for ; Sun, 07 Oct 2018 04:02:34 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id v106-v6sm22065671wrc.85.2018.10.07.04.02.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 04:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J+jOLYhXgvu41G5QnA8GkxA8S56LZLc6TOBP8Vx0d10=; b=S8n+a5eJpG5m1rU4Bq7gF9CjrREdJ646mLXVoJhOEQrABqMRjSqUWWqv5IHxcD0Xp8 F5z8FY22Qshrp5mRGlat9LxSz+c7UPcYMXqe5uoiIdfmWnDsyub/lZp9QfIuvUJ8HYQa 3QDYq0+8F3HhJWTtlcSdf8SOOnXXvphfGHrb/cj5v8uovucMDq7NPqCoVcaXGD8VXuSq 2B9GSKVF+CAJ2mbg58ZRS+oF2lnAS9S7VBW87eF0zAnv2U8U+UbytxhE5j8NBFTXJ+eO iQNNBEqcgteoIXi8JnfV5Mx+JtlanOX5fhQtPLU9eBcyyKvhEXTZNMwEb76+0AbieUsW 2X/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J+jOLYhXgvu41G5QnA8GkxA8S56LZLc6TOBP8Vx0d10=; b=Y+PDEDt/0NZ+gKJ7GDfRhoXdv9MzcsABfYMhCv46bzq/CZpftmMiV52avWeEsUi8jV n2yo1J/jTIHBQF2AG77vgM2/tDKkaDzvW6vPusbC+DrNTs48rzHZRn0Mup3K21TCBZSk 5stF1D7AsdDizWJMZfY50cErdq41xTQLbrpp6XGbS9FF/E4BqKQvjhTjbcu+VcA+VYOf y7491qsuY1P7//IzIIXHONPZx1VkvRau+iW/uq9lDP92Sprxi02NnYAKbF5eaIqbcsEm BMuz82CJ66ZhD948TtAq9hVN7XgH8KdjwT3rKMm71Umu4fNwQv4cUNiSJkh1yk9P77l2 UBqQ== X-Gm-Message-State: ABuFfogiCCACnAHo5HGVP4Q6DAHXv43D0Y3VI00LREAUsIfxbYXOVcKt 9SJsboU7DxRQO4NU5aC0pXDoIyvr/pM= X-Google-Smtp-Source: ACcGV61Jb0uOPhRUE8eBQ+D9d6/OH0TY6Fopy94VVAqV9bH4HOc3xZYlHAz+rzhDktXFFunPFOW8fw== X-Received: by 2002:a5d:4a86:: with SMTP id o6-v6mr14153273wrq.132.1538910153396; Sun, 07 Oct 2018 04:02:33 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 7 Oct 2018 14:02:20 +0300 Message-Id: <20181007110223.129692-5-bishara@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181007110223.129692-1-bishara@daynix.com> References: <20181007110223.129692-1-bishara@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c Subject: [Qemu-devel] [PATCH v2 4/7] qga: add --retry-path option for re-initializing channel on failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth This adds an option to instruct the agent to periodically attempt re-opening the communication channel after a channel error has occurred. The main use-case for this is providing an OS-independent way of allowing the agent to survive situations like hotplug/unplug of the communication channel, or initial guest set up where the agent may be installed/started prior to the installation of the channel device's driver. There are nicer ways of implementing this functionality via things like systemd services, but this option is useful for platforms like *BSD/w32. Currently a channel error will result in the GSource for that channel being removed from the GMainLoop, but the main loop continuing to run. That behavior results in a dead loop when --retry-path isn't set, and prevents us from knowing when to attempt re-opening the channel when it is set, so we also force the loop to exit as part of this patch. Signed-off-by: Michael Roth --- qga/main.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/qga/main.c b/qga/main.c index 23a0a46b84..f359499aaa 100644 --- a/qga/main.c +++ b/qga/main.c @@ -58,6 +58,7 @@ #endif #define QGA_SENTINEL_BYTE 0xFF #define QGA_CONF_DEFAULT CONFIG_QEMU_CONFDIR G_DIR_SEPARATOR_S "qemu-ga.co= nf" +#define QGA_RETRY_INTERVAL 5 =20 static struct { const char *state_dir; @@ -86,6 +87,7 @@ typedef struct GAConfig { int daemonize; GLogLevelFlags log_level; int dumpconf; + bool retry_path; } GAConfig; =20 struct GAState { @@ -115,6 +117,7 @@ struct GAState { GAPersistentState pstate; GAConfig *config; int socket_activation; + bool force_exit; }; =20 struct GAState *ga_state; @@ -137,6 +140,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD typ= e, LPVOID data, VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif static int run_agent(GAState *s); +static void stop_agent(GAState *s, bool requested); =20 static void init_dfl_pathnames(void) @@ -185,9 +189,7 @@ static void quit_handler(int sig) } g_debug("received signal num %d, quitting", sig); =20 - if (g_main_loop_is_running(ga_state->main_loop)) { - g_main_loop_quit(ga_state->main_loop); - } + stop_agent(ga_state, true); } =20 #ifndef _WIN32 @@ -272,6 +274,10 @@ QEMU_COPYRIGHT "\n" " to list available RPCs)\n" " -D, --dump-conf dump a qemu-ga config file based on current config\n" " options / command-line parameters to stdout\n" +" -r, --retry-path attempt re-opening path if it's unavailable or closed= \n" +" due to an error which may be recoverable in the futur= e\n" +" (virtio-serial driver re-install, serial device hot\n" +" plug/unplug, etc.)\n" " -h, --help display this help and exit\n" "\n" QEMU_HELP_BOTTOM "\n" @@ -631,6 +637,7 @@ static gboolean channel_event_cb(GIOCondition condition= , gpointer data) switch (status) { case G_IO_STATUS_ERROR: g_warning("error reading channel"); + stop_agent(s, false); return false; case G_IO_STATUS_NORMAL: buf[count] =3D 0; @@ -974,6 +981,10 @@ static void config_load(GAConfig *config) /* enable all log levels */ config->log_level =3D G_LOG_LEVEL_MASK; } + if (g_key_file_has_key(keyfile, "general", "retry-path", NULL)) { + config->retry_path =3D + g_key_file_get_boolean(keyfile, "general", "retry-path", &gerr= ); + } if (g_key_file_has_key(keyfile, "general", "blacklist", NULL)) { config->bliststr =3D g_key_file_get_string(keyfile, "general", "blacklist", &gerr); @@ -1035,6 +1046,8 @@ static void config_dump(GAConfig *config) g_key_file_set_string(keyfile, "general", "statedir", config->state_di= r); g_key_file_set_boolean(keyfile, "general", "verbose", config->log_level =3D=3D G_LOG_LEVEL_MASK); + g_key_file_set_boolean(keyfile, "general", "retry-path", + config->retry_path); tmp =3D list_join(config->blacklist, ','); g_key_file_set_string(keyfile, "general", "blacklist", tmp); g_free(tmp); @@ -1053,7 +1066,7 @@ static void config_dump(GAConfig *config) =20 static void config_parse(GAConfig *config, int argc, char **argv) { - const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:D"; + const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:Dr"; int opt_ind =3D 0, ch; const struct option lopt[] =3D { { "help", 0, NULL, 'h' }, @@ -1073,6 +1086,7 @@ static void config_parse(GAConfig *config, int argc, = char **argv) { "service", 1, NULL, 's' }, #endif { "statedir", 1, NULL, 't' }, + { "retry-path", 0, NULL, 'r' }, { NULL, 0, NULL, 0 } }; =20 @@ -1117,6 +1131,9 @@ static void config_parse(GAConfig *config, int argc, = char **argv) case 'D': config->dumpconf =3D 1; break; + case 'r': + config->retry_path =3D true; + break; case 'b': { if (is_help_option(optarg)) { qmp_for_each_command(&ga_commands, ga_print_cmd, NULL); @@ -1320,9 +1337,6 @@ static void cleanup_agent(GAState *s) ga_command_state_free(s->command_state); json_message_parser_destroy(&s->parser); } - if (s->channel) { - ga_channel_free(s->channel); - } g_free(s->pstate_filepath); g_free(s->state_filepath_isfrozen); if (s->main_loop) { @@ -1332,7 +1346,7 @@ static void cleanup_agent(GAState *s) ga_state =3D NULL; } =20 -static int run_agent(GAState *s) +static int run_agent_once(GAState *s) { if (!channel_init(s, s->config->method, s->config->channel_path, s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : = -1)) { @@ -1342,9 +1356,41 @@ static int run_agent(GAState *s) =20 g_main_loop_run(ga_state->main_loop); =20 + if (s->channel) { + ga_channel_free(s->channel); + } + return EXIT_SUCCESS; } =20 +static int run_agent(GAState *s) +{ + int ret =3D EXIT_SUCCESS; + + s->force_exit =3D false; + + do { + ret =3D run_agent_once(s); + if (s->config->retry_path && !s->force_exit) { + g_warning("agent stopped unexpectedly, restarting..."); + sleep(QGA_RETRY_INTERVAL); + } + } while (s->config->retry_path && !s->force_exit); + + return ret; +} + +static void stop_agent(GAState *s, bool requested) +{ + if (!s->force_exit) { + s->force_exit =3D requested; + } + + if (g_main_loop_is_running(s->main_loop)) { + g_main_loop_quit(s->main_loop); + } +} + int main(int argc, char **argv) { int ret =3D EXIT_SUCCESS; --=20 2.17.0 From nobody Sun May 19 13:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538910426589381.49152405756615; Sun, 7 Oct 2018 04:07:06 -0700 (PDT) Received: from localhost ([::1]:41918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96tl-0008FD-Ik for importer@patchew.org; Sun, 07 Oct 2018 07:06:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96pa-00055g-Fh for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g96pY-0007QK-G4 for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:38 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g96pY-0007Pm-8U for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:36 -0400 Received: by mail-wm1-x343.google.com with SMTP id z25-v6so6724027wmf.1 for ; Sun, 07 Oct 2018 04:02:35 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id v106-v6sm22065671wrc.85.2018.10.07.04.02.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 04:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XWsPhefjBYmhcw85fxs1rnH1eHySNgk2ocvDPpYbhMg=; b=tA79YtNlvlZCC5WID5mIJ5anzAm8fAEUn8d5hqn30ZE/7Lb1Ba/YXAZA2Wxcr4x/GH wn6MMBhrbt82p+RpdQPwVubzY5YYnyYJUGB/PAbuDoluj/yfRORgTxPL04krXJkYmrqD /KxXLKT+bNCKLo4hPr6+w31nnROtKduVJ93vCpEhQuj2lqk7YAukmQftt+QhG3PBljQA wpnmhhFDNkvn80XVlN9/3v2hcvs+bYC8EKNyiqFfI7MIzDuxfHByqpG35HrpPYeF2aEL c1+UXbDxnLKmqL6T7Fs5GeXQ5JSGXAS0L+D88QhOSZYs+oszKPW90oZfp/RsGX+9TBPx yIIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XWsPhefjBYmhcw85fxs1rnH1eHySNgk2ocvDPpYbhMg=; b=X/7FEgHBVSgsJPLO6MKXCoGe7pwOA/6hnDmy8OJI0yfBqolrSlVrUJBbktHcr4ayEn 4iONSrka+8PdrQb1W7OIbW8XnJGMsPD9+FY2Ah+x7Ol6wOcGhXn0FqK2ONchi51dE+r+ 33rllDfufupZapFHn173rVgo1oFxdXWCyLjmxhOUsHTsj2IDWGjy+Nlysa469+zzf21E RBZGIx8Ai8r/mSRZ+dPOQ5aH7u+zYU1TKM6GVZMPPM3v1upYA83E7F+pHk3uJ1+wY4ky lB3QLvs8sGy4IIDVGuJK8Qb5sdyWz+iRQKljFoGD2y8pMidaUjTxnEwqj7b1qkFGqNgK y61w== X-Gm-Message-State: ABuFfoht06Si67aBdFFPZWGOi6qLfzku1PP7Hlon8dLu6eTQef/LPdLV F4RD3ESCO5Tq92D60+UmSVh/UHiId4I= X-Google-Smtp-Source: ACcGV63o3saAtuUpa/PJpB/CSpvCwFtZ2u7g/314cacfqjnIoo61pBqWoYBhZIL/mFFLlIN1xGMXlg== X-Received: by 2002:a1c:5801:: with SMTP id m1-v6mr12131589wmb.118.1538910154709; Sun, 07 Oct 2018 04:02:34 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 7 Oct 2018 14:02:21 +0300 Message-Id: <20181007110223.129692-6-bishara@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181007110223.129692-1-bishara@daynix.com> References: <20181007110223.129692-1-bishara@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PATCH v2 5/7] qga-win: install service with --retry-path set by default X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth It's nicer from a management perspective that the agent can survive hotplug/unplug of the channel device, or be started prior to the installation of the channel device's driver without and still be able to resume normal function afterward. On linux there are alternatives like systemd to support this, but on w32 --retry-path is the only option so it makes sense to set it by default when installed as a w32 service. Signed-off-by: Michael Roth --- qga/installer/qemu-ga.wxs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index f751a7e9f7..64bf90bd85 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -78,7 +78,7 @@ Account=3D"LocalSystem" ErrorControl=3D"ignore" Interactive=3D"no" - Arguments=3D"-d" + Arguments=3D"-d --retry-path" > --=20 2.17.0 From nobody Sun May 19 13:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538910590207663.2312316113162; Sun, 7 Oct 2018 04:09:50 -0700 (PDT) Received: from localhost ([::1]:41931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96wW-0001h7-Uj for importer@patchew.org; Sun, 07 Oct 2018 07:09:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96pc-00057Z-Fc for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g96pa-0007RB-Nj for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:39 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:43416) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g96pa-0007QO-Ct for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:38 -0400 Received: by mail-wr1-x42f.google.com with SMTP id n1-v6so17725722wrt.10 for ; Sun, 07 Oct 2018 04:02:37 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id v106-v6sm22065671wrc.85.2018.10.07.04.02.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 04:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=orkLVc9uhB748h/rs1mltCzuJfP0UZFKyHcFtTVkXFc=; b=Z2qnNQc6KUt86QxxiUpCqTYeT4UJWGPLo0G33ft9Lr9/Xl6qdVqPji5by5802eETIL opLHy0SDAuUTVP79M1KyVU2y426vOG+PLSz8RsyKes2AgOmS5tLdaK8rddm53WBn+/qm +qlGQCdcfzzgJuI6sOMzpxjp7+g3tkKyPpQVKT7CCnNCW5ataSWyeYpZosyaF/YL9MeG ioQvHspiBF75mDLQfMmbPvs4qZ3wpmaDjmdZhvIgIBumPYuM5PkspUgxm0Y2UbSXBGuR TftvJ46gXuE8VTB+20g0nO2EDdMbvCJ/bM7PO1JbDMcnEwXnBA+h4VNBMGO8PWzRPgOK 7BJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=orkLVc9uhB748h/rs1mltCzuJfP0UZFKyHcFtTVkXFc=; b=EoB8Aa03Aacw6n6PPx+rJ7ClM7ViFpmNqfVcydy3hvkXB0CP1ryknR3j7mZxX+JXS4 uhf46OIuXVzDqiQofa4/DuN3KAxGzV9VdfrLlRYnOyWATmwGWRASUY15Cc2UybXbpSjo nqt09rhisEK2PnZ3YJ9TtCGQawQ4vhDoviGpr+pHiwaIDDI4FxUV02COa5KAQ0FkeUg2 yPL3vcCBtPs1LfC+kH7XVUypmZQ9osqwApsuCgV0lzO5140r4oxNU3RLIKH9hkk8OorY kT1MBvg7T9Z8b5FS7SeQjVIbdzUHawFawNEKd5YFrHpcHhPj7XPW6/KXH5ApswIMp7gd DhFQ== X-Gm-Message-State: ABuFfogb0pPX6GhFxlQeUT8yi0q8f0rBsg5dV3TjDR5sR9AYJBNngeig 0fFjr76ONIixWpOmmzE+jljlvz9FUZ4= X-Google-Smtp-Source: ACcGV61rJLlOih4gihNgB8VZlVgRDPjzMu55A2DQY2mzJOmVjGQob0IeT6xhl81I3H7+teAiW3P5qQ== X-Received: by 2002:a5d:620b:: with SMTP id y11-v6mr2361604wru.105.1538910156027; Sun, 07 Oct 2018 04:02:36 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 7 Oct 2018 14:02:22 +0300 Message-Id: <20181007110223.129692-7-bishara@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181007110223.129692-1-bishara@daynix.com> References: <20181007110223.129692-1-bishara@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42f Subject: [Qemu-devel] [PATCH v2 6/7] qga-win: report specific error when failing to open channel X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth Useful in general, but especially now that errors might occur more frequently with --retry-path set. Signed-off-by: Michael Roth --- qga/channel-win32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qga/channel-win32.c b/qga/channel-win32.c index b3597a8a0f..c86f4388db 100644 --- a/qga/channel-win32.c +++ b/qga/channel-win32.c @@ -302,7 +302,8 @@ static gboolean ga_channel_open(GAChannel *c, GAChannel= Method method, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, = NULL); if (c->handle =3D=3D INVALID_HANDLE_VALUE) { - g_critical("error opening path %s", newpath); + g_critical("error opening path %s: %s", newpath, + g_win32_error_message(GetLastError())); return false; } =20 --=20 2.17.0 From nobody Sun May 19 13:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538910664672803.2070689534931; Sun, 7 Oct 2018 04:11:04 -0700 (PDT) Received: from localhost ([::1]:41939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96xf-0002PV-Dx for importer@patchew.org; Sun, 07 Oct 2018 07:10:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g96pf-0005AW-NY for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g96pc-0007Rg-Dn for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:43 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:54937) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g96pa-0007Qi-Lf for qemu-devel@nongnu.org; Sun, 07 Oct 2018 07:02:39 -0400 Received: by mail-wm1-x332.google.com with SMTP id r63-v6so5487361wma.4 for ; Sun, 07 Oct 2018 04:02:38 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id v106-v6sm22065671wrc.85.2018.10.07.04.02.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Oct 2018 04:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=juxLvr/LIiLIEhtMaAIzFgmqfG2tvV0bFhAvGvKcS5A=; b=mgV2X/W2v80qEgWQbI6yvbT65oxlw/TZwd46+3MfqfbOJpDjQ9xa7cv4wfOldwzQOJ M/gjuzy6k57Tuu3AFlTuSQpAt2bCp3/3B+Yzv9Av+hd3VYPkuPiStYWsvetnvpqFviW2 vEelWXjotiWeSvYc+MduZpGmKmPebvscKvVinTSz59xdmopCefImTca4QIq7HIYmLOrH J253lqYjiTBCbU3SFeM7wUFx1cYAgcsR1ZUGDEWmFmgeOIzbErrKx3IWJiTt3kHVlKZt 1LnDKAEjIa4LoqDtNz6EshzJBd648Flylidyg79RIrVqCIoCehYYi1tALuOwEqDZxHDk RSwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=juxLvr/LIiLIEhtMaAIzFgmqfG2tvV0bFhAvGvKcS5A=; b=YOPdEo+wBfrj+pnnGbqaUzttO+//cEcKNymnEy6fqNt2EJ90tHvF3NpfBmOtvmWbAL EHOW8z3iqoA+vkFIfnmdJvd9gPRBjk8BZvGDhSSRci90AMGawqEdGnYPxZGX1bnUbT/W 7fKipQQ4biba9Ksb2wG/0xw1B5qKlL12COPFL6qiH4o2xS3VSa20gYRJ0XoDnC0qaoiE r9VCOj5XGJ2VzGBm0zkQoAUb/I911N+0sbFUMGaQfX/29Zk7FK0Ucyb4ilMMx3UMnDqs ndfEKYTywpgoil9FKn+tBylxs4fgP/NtUjcjn5O66XzHetVG72coOvTSiGi0iiW9hauN 1qcg== X-Gm-Message-State: ABuFfoj7AnCgJjGUM0eZVS9oDo8lCnKtpcySxYMZXZUk9NCkGh8jpTex EERCq9msudDPkgEuqIWfoPOLNkYspAA= X-Google-Smtp-Source: ACcGV6033UmSF8fxn1v76od6jjrUhP1OfMu4f7vpTkeKjehFOzRAW7RNg27FsBUtY3Wg6KKOfaIucA== X-Received: by 2002:a1c:8e8c:: with SMTP id q134-v6mr2160028wmd.112.1538910157209; Sun, 07 Oct 2018 04:02:37 -0700 (PDT) From: Bishara AbuHattoum To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 7 Oct 2018 14:02:23 +0300 Message-Id: <20181007110223.129692-8-bishara@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181007110223.129692-1-bishara@daynix.com> References: <20181007110223.129692-1-bishara@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::332 Subject: [Qemu-devel] [PATCH v2 7/7] qga-win: changing --retry-path option behavior X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Sameeh Jubran Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently whenever the qemu-ga's service doesn't find the virtio-serial the run_agent() loops in a QGA_RETRY_INTERVAL (default 5 seconds) intervals and try to restart the qemu-ga which causes a synchronous loop. Changed to wait and listen for the serial events by registering for notifications a proper serial event handler that deals with events: DBT_DEVICEARRIVAL indicates that the device has been inserted and is available DBT_DEVICEREMOVECOMPLETE indicates that the devive has been removed Which allow us to determine when the channel path is available for the qemu-ga to restart. Signed-off-by: Bishara AbuHattoum Signed-off-by: Sameeh Jubran --- qga/main.c | 86 ++++++++++++++++++++++++++++++++++++++++++++- qga/service-win32.h | 4 +++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/qga/main.c b/qga/main.c index f359499aaa..c5bb063b1c 100644 --- a/qga/main.c +++ b/qga/main.c @@ -34,6 +34,7 @@ #include "qemu/systemd.h" #include "qemu-version.h" #ifdef _WIN32 +#include #include "qga/service-win32.h" #include "qga/vss-win32.h" #endif @@ -101,6 +102,7 @@ struct GAState { bool logging_enabled; #ifdef _WIN32 GAService service; + HANDLE wakeup_event; #endif bool delimit_response; bool frozen; @@ -137,6 +139,7 @@ static const char *ga_freeze_whitelist[] =3D { #ifdef _WIN32 DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, LPVOID ctx); +DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data); VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif static int run_agent(GAState *s); @@ -695,6 +698,36 @@ static gboolean channel_init(GAState *s, const gchar *= method, const gchar *path, } =20 #ifdef _WIN32 +DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data) +{ + DWORD ret =3D NO_ERROR; + PDEV_BROADCAST_HDR broadcast_header =3D (PDEV_BROADCAST_HDR)data; + + if (broadcast_header->dbch_devicetype =3D=3D DBT_DEVTYP_DEVICEINTERFAC= E) { + switch (type) { + /* Device inserted */ + case DBT_DEVICEARRIVAL: + /* Start QEMU-ga's service */ + if (!SetEvent(ga_state->wakeup_event)) { + ret =3D GetLastError(); + } + break; + /* Device removed */ + case DBT_DEVICEQUERYREMOVE: + case DBT_DEVICEREMOVEPENDING: + case DBT_DEVICEREMOVECOMPLETE: + /* Stop QEMU-ga's service */ + if (!ResetEvent(ga_state->wakeup_event)) { + ret =3D GetLastError(); + } + break; + default: + ret =3D ERROR_CALL_NOT_IMPLEMENTED; + } + } + return ret; +} + DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, LPVOID ctx) { @@ -706,9 +739,13 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD ty= pe, LPVOID data, case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: quit_handler(SIGTERM); + SetEvent(ga_state->wakeup_event); service->status.dwCurrentState =3D SERVICE_STOP_PENDING; SetServiceStatus(service->status_handle, &service->status); break; + case SERVICE_CONTROL_DEVICEEVENT: + handle_serial_device_events(type, data); + break; =20 default: ret =3D ERROR_CALL_NOT_IMPLEMENTED; @@ -735,10 +772,24 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[]) service->status.dwServiceSpecificExitCode =3D NO_ERROR; service->status.dwCheckPoint =3D 0; service->status.dwWaitHint =3D 0; + DEV_BROADCAST_DEVICEINTERFACE notification_filter; + ZeroMemory(¬ification_filter, sizeof(notification_filter)); + notification_filter.dbcc_devicetype =3D DBT_DEVTYP_DEVICEINTERFACE; + notification_filter.dbcc_size =3D sizeof(DEV_BROADCAST_DEVICEINTERFACE= ); + notification_filter.dbcc_classguid =3D GUID_VIOSERIAL_PORT; + + service->device_notification_handle =3D + RegisterDeviceNotification(service->status_handle, + ¬ification_filter, DEVICE_NOTIFY_SERVICE_HANDLE); + if (!service->device_notification_handle) { + g_critical("Failed to register device notification handle!\n"); + return; + } SetServiceStatus(service->status_handle, &service->status); =20 run_agent(ga_state); =20 + UnregisterDeviceNotification(service->device_notification_handle); service->status.dwCurrentState =3D SERVICE_STOPPED; SetServiceStatus(service->status_handle, &service->status); } @@ -1326,12 +1377,24 @@ static GAState *initialize_agent(GAConfig *config, = int socket_activation) =20 s->config =3D config; s->socket_activation =3D socket_activation; + +#ifdef _WIN32 + s->wakeup_event =3D CreateEvent(NULL, TRUE, FALSE, TEXT("WakeUp")); + if (s->wakeup_event =3D=3D NULL) { + g_critical("CreateEvent failed"); + return NULL; + } +#endif + ga_state =3D s; return s; } =20 static void cleanup_agent(GAState *s) { +#ifdef _WIN32 + CloseHandle(s->wakeup_event); +#endif if (s->command_state) { ga_command_state_cleanup_all(s->command_state); ga_command_state_free(s->command_state); @@ -1363,6 +1426,27 @@ static int run_agent_once(GAState *s) return EXIT_SUCCESS; } =20 +static void wait_for_channel_availability(GAState *s) +{ + g_warning("waiting for channel path..."); +#ifndef _WIN32 + sleep(QGA_RETRY_INTERVAL); +#else + DWORD dwWaitResult; + + dwWaitResult =3D WaitForSingleObject(s->wakeup_event, INFINITE); + + switch (dwWaitResult) { + case WAIT_OBJECT_0: + break; + case WAIT_TIMEOUT: + break; + default: + g_critical("WaitForSingleObject failed"); + } +#endif +} + static int run_agent(GAState *s) { int ret =3D EXIT_SUCCESS; @@ -1373,7 +1457,7 @@ static int run_agent(GAState *s) ret =3D run_agent_once(s); if (s->config->retry_path && !s->force_exit) { g_warning("agent stopped unexpectedly, restarting..."); - sleep(QGA_RETRY_INTERVAL); + wait_for_channel_availability(s); } } while (s->config->retry_path && !s->force_exit); =20 diff --git a/qga/service-win32.h b/qga/service-win32.h index 89e99dfede..7b16d69b57 100644 --- a/qga/service-win32.h +++ b/qga/service-win32.h @@ -20,9 +20,13 @@ #define QGA_SERVICE_NAME "qemu-ga" #define QGA_SERVICE_DESCRIPTION "Enables integration with QEMU machine em= ulator and virtualizer." =20 +static const GUID GUID_VIOSERIAL_PORT =3D { 0x6fde7521, 0x1b65, 0x48ae, +{ 0xb6, 0x28, 0x80, 0xbe, 0x62, 0x1, 0x60, 0x26 } }; + typedef struct GAService { SERVICE_STATUS status; SERVICE_STATUS_HANDLE status_handle; + HDEVNOTIFY device_notification_handle; } GAService; =20 int ga_install_service(const char *path, const char *logfile, --=20 2.17.0