From patchwork Wed Oct 31 01:37:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 513D314E2 for ; Wed, 31 Oct 2018 01:48:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C8B22A2BC for ; Wed, 31 Oct 2018 01:48:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A56D2A2DB; Wed, 31 Oct 2018 01:48:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A656B2A2BC for ; Wed, 31 Oct 2018 01:48:38 +0000 (UTC) Received: from localhost ([::1]:56623 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfcc-0000Ew-01 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:48:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUu-0000Z5-SS for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUt-0002IZ-GL for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:40 -0400 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]:35453) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUt-0002HO-7m for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:39 -0400 Received: by mail-qt1-x832.google.com with SMTP id a10-v6so15979256qtp.2 for ; Tue, 30 Oct 2018 18:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=b60sY/Qw6hLNM3jT0LJpKmQaEbzVAgZEFb44f/LeZZA=; b=JLnCa5Qsz47oAgJ123bBFGm/erfROu2XS+mKcGJu32py4DzoPMe5ewz4PtQPFnt5DU xq9OJlTiVaKp9P4ygOGXl+JmJGpu6KdihNxMYGOlKDPQXz3lfv24QDoVnX/hIbSVuhJs GpsEfUge88S+6oFCKEcRSZLjijg57kuews43rE6mmgOkHo4J+Y7KkNJTHexbkfgq8Oy1 KxnGeYRC7NUKJsnBSICOnt/GAdn4eiAAuYjd5ZVTBVbBV1RPwF8bQtfr02BpWUF4Y5uy tjE+kV17qm4YlQr+0QssanEagc7wBdTBPa94+r1aHNtCzsiNajt0az9sk9nCzknjaBz9 4sFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=b60sY/Qw6hLNM3jT0LJpKmQaEbzVAgZEFb44f/LeZZA=; b=reJ8TtlJlVEiphs7FQYH3fsP0ixs7tvAArpw0c93Fa5Cxobff4+bgzLNpSRtwfJ0BC E1KJjHCr5JcGr7VOMAh7JeNa9K50faeiXJC9Chq+QPZ0jy+JSx4c5fSxiJlDlqRukRH5 x5bfRkHebpzZJmpAYzb9nKuEhNkmUNI3DmePhtyxvdmgKLr/vvc7HLghjI5ZWCAQfc76 o58zQEDAUoAayd4PIDtV7TId0rRLOCQEpUSRybeE/OnXj1iKH1HeagArWYkFE5XLVYS1 xqFOZWgGnFEfiDl2NGIMamQByWbzSalHJLgTGmoCO3z9nkxMTu3Ntg+EFDg5J70N8RLd aKYw== X-Gm-Message-State: AGRZ1gLfOw2/2tjWUAPhsv5aDokUG5s0Wu40fwBiIPoWGKzTO7H/uIGY IZBYGeuAV4BCqv6yhv96a6N8J2ZH X-Google-Smtp-Source: AJdET5dXKGJyJcVc/naorEYSuGk/bZ0NL/Lk1dx3n431gbhdC1BUd+b/H+clgtalKL0T3VTlLuXC3A== X-Received: by 2002:ac8:41c8:: with SMTP id o8mr994871qtm.232.1540950037370; Tue, 30 Oct 2018 18:40:37 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id u16sm343407qkg.14.2018.10.30.18.40.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:36 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:37:58 -0500 Message-Id: <20181031013821.24023-2-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::832 Subject: [Qemu-devel] [PULL v2 01/24] qga: Support Unicode paths in guest-file-open on win32 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: Jonathon Reinhart , peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jonathon Reinhart Currently, the win32 port of QEMU Guest Agent does not properly handle Unicode paths. The JSON decoder produces a valid UTF-8 path string, but this is passed directly to CreateFileA, which is expecting an ANSI string and not UTF-8. This leads to mangled filenames. This patch follows the example of qmp_guest_set_user_password() and uses g_utf8_to_utf16() to convert the string to UTF-16 and calls CreateFileW() explicitly. Signed-off-by: Jonathon Reinhart Signed-off-by: Michael Roth --- qga/commands-win32.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 98d9735389..416343b97b 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -160,13 +160,15 @@ static void handle_set_nonblocking(HANDLE fh) int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **errp) { - int64_t fd; + int64_t fd = -1; HANDLE fh; HANDLE templ_file = NULL; DWORD share_mode = FILE_SHARE_READ; DWORD flags_and_attr = FILE_ATTRIBUTE_NORMAL; LPSECURITY_ATTRIBUTES sa_attr = NULL; OpenFlags *guest_flags; + GError *gerr = NULL; + wchar_t *w_path = NULL; if (!has_mode) { mode = "r"; @@ -175,16 +177,21 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, guest_flags = find_open_flag(mode); if (guest_flags == NULL) { error_setg(errp, "invalid file open mode"); - return -1; + goto done; + } + + w_path = g_utf8_to_utf16(path, -1, NULL, NULL, &gerr); + if (!w_path) { + goto done; } - fh = CreateFile(path, guest_flags->desired_access, share_mode, sa_attr, + fh = CreateFileW(w_path, guest_flags->desired_access, share_mode, sa_attr, guest_flags->creation_disposition, flags_and_attr, templ_file); if (fh == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open file '%s'", path); - return -1; + goto done; } /* set fd non-blocking to avoid common use cases (like reading from a @@ -196,10 +203,17 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, if (fd < 0) { CloseHandle(fh); error_setg(errp, "failed to add handle to qmp handle table"); - return -1; + goto done; } slog("guest-file-open, handle: % " PRId64, fd); + +done: + if (gerr) { + error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message); + g_error_free(gerr); + } + g_free(w_path); return fd; } From patchwork Wed Oct 31 01:37:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39B8415E9 for ; Wed, 31 Oct 2018 01:58:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2529D2ABC8 for ; Wed, 31 Oct 2018 01:58:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 165112ABDF; Wed, 31 Oct 2018 01:58:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 55EBA2ABC8 for ; Wed, 31 Oct 2018 01:58:14 +0000 (UTC) Received: from localhost ([::1]:56675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHflt-0002Iu-22 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:58:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfV9-0000kU-Ts for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfV7-0002TN-UD for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:55 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:35556) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfV7-0002SZ-Mo for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:53 -0400 Received: by mail-qk1-x72b.google.com with SMTP id v68-v6so8591835qka.2 for ; Tue, 30 Oct 2018 18:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=FcLif28K1pIf3aoGq4daxTCTebZyNpPWXObhEcZ21EA=; b=kYKoeGm8G1/3V7zHLlNPjdJIVw3opta4FdGKzyMg/e+DieDhSukF9vm7NUeVtcFdr0 +eLKD6sLwmVzzGTabewqjMJkkEdbx0FtmPuJSeUW5aWPigaWyW2jfAi+mVHg9jejCcNd qbj3uVz1AgZsR3n76u16O9aWCD8w6QJBgVe7v2kVTxEXYir0NmQ1X/opYkAsM0JeHC8L 8wf1+nS1spvZzYCFkGR3p2KSUguVZpfJM8oMV+8eEfCFSTja7+NOw3L6okG9EwLnYiRL 0RgfZ/xjRZPWpxiIUJVGOuYvoyCrEWTi1zo/igaqezjGq3BYhbfujKwSrE5KZlkeiXrz MLFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=FcLif28K1pIf3aoGq4daxTCTebZyNpPWXObhEcZ21EA=; b=Ul7MvV3OR2sgnwtmUyoElSxHwwBcUL1rswgWarqWonJTtAK+UtoYc3u0SNsIXiBG/B EMM5Vu9C8HoL7ssrATIjfyrtSrjUwjwCbLTq5nT5hjyZg73fgflV89p/JX1ps1uuzM6A A/pDWAmh3NVWLoC9uljesdyyFZuCVi2ggUDhqhSyrXgGp+km1SaRZPJ9BV3x2xmrFtu8 ayxaS1LTkCbDPuikUbO35SG+mrbc0mt7m8JmuQzfVcj/hY5X9uL4sRj4phCLlFapvd+e ZPW9jXTjftrzdNQIlpQ8WWjNatCcKcMpRuELZZwKf2s6LS06UZYtPDrOSwL+rBfkEE1L Rjlw== X-Gm-Message-State: AGRZ1gJB+uUPXT5itB3Q5wVDv/LV5ZzXBNOXFgE5Mu3Pnqjto/ainf7o BH5yQkf1NwCjR+od6EpPAxBl9IkP X-Google-Smtp-Source: AJdET5dqAGdeS2IYup9otZl6fK5u/4Ws1F6q1GbboUsOOn7tasJxfPkCUGsF2oPlX4fq9eKG3vSI8Q== X-Received: by 2002:a37:a884:: with SMTP id r126mr862800qke.143.1540950052093; Tue, 30 Oct 2018 18:40:52 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id z196sm12077782qkz.37.2018.10.30.18.40.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:50 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:37:59 -0500 Message-Id: <20181031013821.24023-3-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::72b Subject: [Qemu-devel] [PULL v2 02/24] qga-win: add support for qmp_guest_fsfreeze_freeze_list 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: peter.maydell@linaro.org, Chen Hanxiao Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Chen Hanxiao This patch add support for freeze specified fs. The valid mountpoints list member are [1]: The path of a mounted folder, for example, Y:\MountX\ A drive letter, for example, D:\ A volume GUID path of the form \\?\Volume{GUID}\, where GUID identifies the volume A UNC path that specifies a remote file share, for example, \\Clusterx\Share1\ [1] https://docs.microsoft.com/en-us/windows/desktop/api/vsbackup/nf-vsbackup-ivssbackupcomponents-addtosnapshotset Cc: Michael Roth Signed-off-by: Chen Hanxiao Signed-off-by: Michael Roth --- qga/commands-win32.c | 21 ++++----- qga/main.c | 2 +- qga/vss-win32.c | 5 +- qga/vss-win32.h | 3 +- qga/vss-win32/requester.cpp | 92 ++++++++++++++++++++++++++----------- qga/vss-win32/requester.h | 13 ++++-- 6 files changed, 91 insertions(+), 45 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 416343b97b..347577f2a4 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -790,6 +790,13 @@ GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) * The frozen state is limited for up to 10 seconds by VSS. */ int64_t qmp_guest_fsfreeze_freeze(Error **errp) +{ + return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); +} + +int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, + strList *mountpoints, + Error **errp) { int i; Error *local_err = NULL; @@ -804,7 +811,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp) /* cannot risk guest agent blocking itself on a write in this state */ ga_set_frozen(ga_state); - qga_vss_fsfreeze(&i, true, &local_err); + qga_vss_fsfreeze(&i, true, mountpoints, &local_err); if (local_err) { error_propagate(errp, local_err); goto error; @@ -822,15 +829,6 @@ error: return 0; } -int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, - strList *mountpoints, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - - return 0; -} - /* * Thaw local file systems using Volume Shadow-copy Service. */ @@ -843,7 +841,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) return 0; } - qga_vss_fsfreeze(&i, false, errp); + qga_vss_fsfreeze(&i, false, NULL, errp); ga_unset_frozen(ga_state); return i; @@ -1660,7 +1658,6 @@ GList *ga_command_blacklist_init(GList *blacklist) "guest-set-vcpus", "guest-get-memory-blocks", "guest-set-memory-blocks", "guest-get-memory-block-size", - "guest-fsfreeze-freeze-list", NULL}; char **p = (char **)list_unsupported; diff --git a/qga/main.c b/qga/main.c index c399320d3c..afcd268ee3 100644 --- a/qga/main.c +++ b/qga/main.c @@ -151,7 +151,7 @@ static void quit_handler(int sig) WaitForSingleObject(hEventTimeout, 0); CloseHandle(hEventTimeout); } - qga_vss_fsfreeze(&i, false, &err); + qga_vss_fsfreeze(&i, false, NULL, &err); if (err) { g_debug("Error unfreezing filesystems prior to exiting: %s", error_get_pretty(err)); diff --git a/qga/vss-win32.c b/qga/vss-win32.c index a541f3ae01..f444a25a70 100644 --- a/qga/vss-win32.c +++ b/qga/vss-win32.c @@ -147,7 +147,8 @@ void ga_uninstall_vss_provider(void) } /* Call VSS requester and freeze/thaw filesystems and applications */ -void qga_vss_fsfreeze(int *nr_volume, bool freeze, Error **errp) +void qga_vss_fsfreeze(int *nr_volume, bool freeze, + strList *mountpoints, Error **errp) { const char *func_name = freeze ? "requester_freeze" : "requester_thaw"; QGAVSSRequesterFunc func; @@ -164,5 +165,5 @@ void qga_vss_fsfreeze(int *nr_volume, bool freeze, Error **errp) return; } - func(nr_volume, &errset); + func(nr_volume, mountpoints, &errset); } diff --git a/qga/vss-win32.h b/qga/vss-win32.h index 4f8e39aa5c..ce2abe5a72 100644 --- a/qga/vss-win32.h +++ b/qga/vss-win32.h @@ -22,6 +22,7 @@ bool vss_initialized(void); int ga_install_vss_provider(void); void ga_uninstall_vss_provider(void); -void qga_vss_fsfreeze(int *nr_volume, bool freeze, Error **errp); +void qga_vss_fsfreeze(int *nr_volume, bool freeze, + strList *mountpints, Error **errp); #endif diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp index 3d9c9716c0..5378c55d23 100644 --- a/qga/vss-win32/requester.cpp +++ b/qga/vss-win32/requester.cpp @@ -234,7 +234,7 @@ out: } } -void requester_freeze(int *num_vols, ErrorSet *errset) +void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset) { COMPointer pAsync; HANDLE volume; @@ -246,6 +246,7 @@ void requester_freeze(int *num_vols, ErrorSet *errset) WCHAR short_volume_name[64], *display_name = short_volume_name; DWORD wait_status; int num_fixed_drives = 0, i; + int num_mount_points = 0; if (vss_ctx.pVssbc) { /* already frozen */ *num_vols = 0; @@ -337,39 +338,73 @@ void requester_freeze(int *num_vols, ErrorSet *errset) goto out; } - volume = FindFirstVolumeW(short_volume_name, sizeof(short_volume_name)); - if (volume == INVALID_HANDLE_VALUE) { - err_set(errset, hr, "failed to find first volume"); - goto out; - } - for (;;) { - if (GetDriveTypeW(short_volume_name) == DRIVE_FIXED) { + if (mountpoints) { + PWCHAR volume_name_wchar; + for (volList *list = (volList *)mountpoints; list; list = list->next) { + size_t len = strlen(list->value) + 1; + size_t converted = 0; VSS_ID pid; - hr = vss_ctx.pVssbc->AddToSnapshotSet(short_volume_name, + + volume_name_wchar = new wchar_t[len]; + mbstowcs_s(&converted, volume_name_wchar, len, + list->value, _TRUNCATE); + + hr = vss_ctx.pVssbc->AddToSnapshotSet(volume_name_wchar, g_gProviderId, &pid); if (FAILED(hr)) { - WCHAR volume_path_name[PATH_MAX]; - if (GetVolumePathNamesForVolumeNameW( - short_volume_name, volume_path_name, - sizeof(volume_path_name), NULL) && *volume_path_name) { - display_name = volume_path_name; - } err_set(errset, hr, "failed to add %S to snapshot set", - display_name); - FindVolumeClose(volume); + volume_name_wchar); + delete volume_name_wchar; goto out; } - num_fixed_drives++; + num_mount_points++; + + delete volume_name_wchar; } - if (!FindNextVolumeW(volume, short_volume_name, - sizeof(short_volume_name))) { - FindVolumeClose(volume); - break; + + if (num_mount_points == 0) { + /* If there is no valid mount points, just exit. */ + goto out; } } - if (num_fixed_drives == 0) { - goto out; /* If there is no fixed drive, just exit. */ + if (!mountpoints) { + volume = FindFirstVolumeW(short_volume_name, sizeof(short_volume_name)); + if (volume == INVALID_HANDLE_VALUE) { + err_set(errset, hr, "failed to find first volume"); + goto out; + } + + for (;;) { + if (GetDriveTypeW(short_volume_name) == DRIVE_FIXED) { + VSS_ID pid; + hr = vss_ctx.pVssbc->AddToSnapshotSet(short_volume_name, + g_gProviderId, &pid); + if (FAILED(hr)) { + WCHAR volume_path_name[PATH_MAX]; + if (GetVolumePathNamesForVolumeNameW( + short_volume_name, volume_path_name, + sizeof(volume_path_name), NULL) && + *volume_path_name) { + display_name = volume_path_name; + } + err_set(errset, hr, "failed to add %S to snapshot set", + display_name); + FindVolumeClose(volume); + goto out; + } + num_fixed_drives++; + } + if (!FindNextVolumeW(volume, short_volume_name, + sizeof(short_volume_name))) { + FindVolumeClose(volume); + break; + } + } + + if (num_fixed_drives == 0) { + goto out; /* If there is no fixed drive, just exit. */ + } } hr = vss_ctx.pVssbc->PrepareForBackup(pAsync.replace()); @@ -435,7 +470,12 @@ void requester_freeze(int *num_vols, ErrorSet *errset) goto out; } - *num_vols = vss_ctx.cFrozenVols = num_fixed_drives; + if (mountpoints) { + *num_vols = vss_ctx.cFrozenVols = num_mount_points; + } else { + *num_vols = vss_ctx.cFrozenVols = num_fixed_drives; + } + return; out: @@ -449,7 +489,7 @@ out1: } -void requester_thaw(int *num_vols, ErrorSet *errset) +void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset) { COMPointer pAsync; diff --git a/qga/vss-win32/requester.h b/qga/vss-win32/requester.h index 2a39d734a2..5a8e8faf0c 100644 --- a/qga/vss-win32/requester.h +++ b/qga/vss-win32/requester.h @@ -34,9 +34,16 @@ typedef struct ErrorSet { STDAPI requester_init(void); STDAPI requester_deinit(void); -typedef void (*QGAVSSRequesterFunc)(int *, ErrorSet *); -void requester_freeze(int *num_vols, ErrorSet *errset); -void requester_thaw(int *num_vols, ErrorSet *errset); +typedef struct volList volList; + +struct volList { + volList *next; + char *value; +}; + +typedef void (*QGAVSSRequesterFunc)(int *, void *, ErrorSet *); +void requester_freeze(int *num_vols, void *volList, ErrorSet *errset); +void requester_thaw(int *num_vols, void *volList, ErrorSet *errset); #ifdef __cplusplus } From patchwork Wed Oct 31 01:38:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3156515E9 for ; Wed, 31 Oct 2018 01:55:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 217532ABA3 for ; Wed, 31 Oct 2018 01:55:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 153B32ABBB; Wed, 31 Oct 2018 01:55:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7CE642ABA3 for ; Wed, 31 Oct 2018 01:55:10 +0000 (UTC) Received: from localhost ([::1]:56661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfiv-0007Nd-PK for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:55:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfVF-0000oO-4A for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfVA-0002Wr-IE for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:01 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:41763) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfVA-0002Va-9y for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:56 -0400 Received: by mail-qk1-x741.google.com with SMTP id 189so7167050qkj.8 for ; Tue, 30 Oct 2018 18:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IyZMeptQhY8QjDMqhWNkZZuHVaNTU7U8+5/FjdMQJl8=; b=bikuWlXFRjLpnDXgwqGHTweiyX1e9dukuDo5zo6/up8njbQBCjFVsWinBL5CT1RdxY uRV4qU0R2ESW3jSJszMPYafPO3hOK+RWuGuIT752PlMFFzSDmVVnhZNb0VC+tGARuLIY ZipQXBQrLzB0rwf+HvwNeqDZvEI+agOIl9JCnhQ07EZ+9sn0x3K33YrnXnDWZTHAXgeM eidL+aRc6L+1vDuCGaH0JJ75o0JMp0/eC5c/YaII9TRgF3QBGNyKoCAp771LnupSwmo9 aadYUcTlFDtDvfEcALrc7GRP1Emc1bnjbWpY/4AJmbhalhlqgJ8syIv/Om8oNSPtwwkY OHyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IyZMeptQhY8QjDMqhWNkZZuHVaNTU7U8+5/FjdMQJl8=; b=N/oiK+Of+o5mRQFfnf0VHIlmGEhBkpmyEW9u2bwdO9jkBclzFe8n10cv7YZAXHf0EH 7LxMmnvAMMcA/u6XswOMxK9kZi+sSbIEJQ1CEDVW9B6XZAu64PBMj3+J3dtCaz9Cu7RA Yq6WPIG38AdILipBpzpvlqB/IzBSBF5Qw4VYCh+/owCQfzp88ji51dUUUQrtx2XXiBE8 /eU54xrAEI7pUyxTHLtGqQsJoUQb3yQ9p+8N3RSmtvgRVJpZHoVi7t5JHVgSwSE3DhnE FP6wGNFQypZLR8Or8ZWRcMRrcB6NK75sdDxy5HE7/alk1ZLF/I+AlU3Eq+jPW+43s2gi DUAw== X-Gm-Message-State: AGRZ1gI3SdrQ5iZT8Bbgj/rcX5i0sejoYBghCWg7DLUEdz80WhVbueGZ LQ87j+g8PkRvBtI6PWEbhNMkOXMH X-Google-Smtp-Source: AJdET5ebxYAceuvPBJRQA09rsgtwM9N3yHYLkMwYUSuK+UiOaVLBRaJYMlg03zTMEejMRad+cmFfqw== X-Received: by 2002:a37:8984:: with SMTP id l126-v6mr868559qkd.195.1540950054839; Tue, 30 Oct 2018 18:40:54 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id m46-v6sm20954154qtc.93.2018.10.30.18.40.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:53 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:00 -0500 Message-Id: <20181031013821.24023-4-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::741 Subject: [Qemu-devel] [PULL v2 03/24] qga: ignore non present cpus when handling qmp_guest_get_vcpus() 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: peter.maydell@linaro.org, Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Igor Mammedov If VM has VCPUs plugged sparselly (for example a VM started with 3 VCPUs (cpu0, cpu1 and cpu2) and then cpu1 was hotunplugged so only cpu0 and cpu2 are present), QGA will rise a error error: internal error: unable to execute QEMU agent command 'guest-get-vcpus': open("/sys/devices/system/cpu/cpu1/"): No such file or directory when virsh vcpucount FOO --guest is executed. Fix it by ignoring non present CPUs when fetching CPUs status from sysfs. Signed-off-by: Igor Mammedov Reviewed-by: Laszlo Ersek Reviewed-by: Marc-André Lureau Signed-off-by: Michael Roth --- qga/commands-posix.c | 115 ++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 37e8a2d791..42d30f078e 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2035,61 +2035,56 @@ static long sysconf_exact(int name, const char *name_str, Error **errp) * Written members remain unmodified on error. */ static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu, - Error **errp) + char *dirpath, Error **errp) { - char *dirpath; + int fd; + int res; int dirfd; + static const char fn[] = "online"; - dirpath = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/", - vcpu->logical_id); dirfd = open(dirpath, O_RDONLY | O_DIRECTORY); if (dirfd == -1) { error_setg_errno(errp, errno, "open(\"%s\")", dirpath); - } else { - static const char fn[] = "online"; - int fd; - int res; - - fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); - if (fd == -1) { - if (errno != ENOENT) { - error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); - } else if (sys2vcpu) { - vcpu->online = true; - vcpu->can_offline = false; - } else if (!vcpu->online) { - error_setg(errp, "logical processor #%" PRId64 " can't be " - "offlined", vcpu->logical_id); - } /* otherwise pretend successful re-onlining */ - } else { - unsigned char status; - - res = pread(fd, &status, 1, 0); - if (res == -1) { - error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn); - } else if (res == 0) { - error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath, - fn); - } else if (sys2vcpu) { - vcpu->online = (status != '0'); - vcpu->can_offline = true; - } else if (vcpu->online != (status != '0')) { - status = '0' + vcpu->online; - if (pwrite(fd, &status, 1, 0) == -1) { - error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath, - fn); - } - } /* otherwise pretend successful re-(on|off)-lining */ + return; + } - res = close(fd); - g_assert(res == 0); - } + fd = openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); + if (fd == -1) { + if (errno != ENOENT) { + error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); + } else if (sys2vcpu) { + vcpu->online = true; + vcpu->can_offline = false; + } else if (!vcpu->online) { + error_setg(errp, "logical processor #%" PRId64 " can't be " + "offlined", vcpu->logical_id); + } /* otherwise pretend successful re-onlining */ + } else { + unsigned char status; + + res = pread(fd, &status, 1, 0); + if (res == -1) { + error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn); + } else if (res == 0) { + error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath, + fn); + } else if (sys2vcpu) { + vcpu->online = (status != '0'); + vcpu->can_offline = true; + } else if (vcpu->online != (status != '0')) { + status = '0' + vcpu->online; + if (pwrite(fd, &status, 1, 0) == -1) { + error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath, + fn); + } + } /* otherwise pretend successful re-(on|off)-lining */ - res = close(dirfd); + res = close(fd); g_assert(res == 0); } - g_free(dirpath); + res = close(dirfd); + g_assert(res == 0); } GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) @@ -2107,17 +2102,21 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) while (local_err == NULL && current < sc_max) { GuestLogicalProcessor *vcpu; GuestLogicalProcessorList *entry; - - vcpu = g_malloc0(sizeof *vcpu); - vcpu->logical_id = current++; - vcpu->has_can_offline = true; /* lolspeak ftw */ - transfer_vcpu(vcpu, true, &local_err); - - entry = g_malloc0(sizeof *entry); - entry->value = vcpu; - - *link = entry; - link = &entry->next; + int64_t id = current++; + char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/", + id); + + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + vcpu = g_malloc0(sizeof *vcpu); + vcpu->logical_id = id; + vcpu->has_can_offline = true; /* lolspeak ftw */ + transfer_vcpu(vcpu, true, path, &local_err); + entry = g_malloc0(sizeof *entry); + entry->value = vcpu; + *link = entry; + link = &entry->next; + } + g_free(path); } if (local_err == NULL) { @@ -2138,7 +2137,11 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) processed = 0; while (vcpus != NULL) { - transfer_vcpu(vcpus->value, false, &local_err); + char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/", + vcpus->value->logical_id); + + transfer_vcpu(vcpus->value, false, path, &local_err); + g_free(path); if (local_err != NULL) { break; } From patchwork Wed Oct 31 01:38:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3072D14E2 for ; Wed, 31 Oct 2018 01:52:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FFF32A925 for ; Wed, 31 Oct 2018 01:52:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1456A2A9AE; Wed, 31 Oct 2018 01:52:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ADAAF2A925 for ; Wed, 31 Oct 2018 01:52:39 +0000 (UTC) Received: from localhost ([::1]:56647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfgU-00041h-E0 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:52:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfVI-0000rZ-8J for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfVF-0002ZR-Gl for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:04 -0400 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]:34667) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfVF-0002YD-8q for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:01 -0400 Received: by mail-qt1-x82e.google.com with SMTP id z2-v6so16023830qts.1 for ; Tue, 30 Oct 2018 18:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E4sEx9c8q9y+5BIR/AOl49WHAQfHX88H5T2zjUp56XQ=; b=tNQ9mJ/n0LL4pO8DkUbIDK2H/PrX8pqmH71tf/ePM8wVMs7Kf0bJsZHfotX7acfdpo F0bjelwpI71VAZxr6Bx5iA/yJ6Q59bvOlSINVvl4SweLEsXXmakL7pcsqGi7e1j6p36i p3v9NZrJi4QflGPdJRXiuNqyKO+9H1H0t0xetPilBcpQ0+HPiqF/iexSifbrmGYQFvJN Z69d+fiy5T5hh/PWkgJTz0VM5tJKQZwo3zW0dygsz8xMDiXpU5oggrXXkOLWvXVZxKg9 FwDmunRTTffibnEQP5YUmMi50NYAxCDz1VEOvSKk4PN4zBmrc5kMaGLRyxz18KKDOwSj Rdsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=E4sEx9c8q9y+5BIR/AOl49WHAQfHX88H5T2zjUp56XQ=; b=CZOSR56OVTlIl+EWjdQjGnXUTGXLWvf4zR1eLUhJ5F9xrEVh0CVls9fFGVDo29tEQ8 F5gXd3fQGv5OSGBVVCHSiDkoSTe6oOMV6mrwpg4SCxlt9whhn73J7sPmb7srwes/268N UJTVrfzE13qf61YA9tOu9HOi5o+gqiDa/voS2aM4GriARLHOhQ8YfPNpSWnM7znd/E5e tb0rbe/vopbDYto9R9YXc8slOqPsAcrHg7n9xyiUgBWvq8FGkzwuiBtDywQ2CtSF+pBW 8DGAQxE+LvBbF6so2vGRM6g3/w1mDxCm0tBiqsEL/oFsvcWcOIMM41873UZrIzBlYaxx vZfw== X-Gm-Message-State: AGRZ1gIkUwnnqCkz3nigEgHz0SH6hXRBLGx2LSm06BSOHMc7jRYoM/C4 S1j3XZMXJLSkJF1qCO4wlFjtPsov X-Google-Smtp-Source: AJdET5eOhDao/S1YAsVsLcEEU2pmBkoMQlEUyl76Oogu4PPhR0Xk6iRrGwuhU457GreDTMPH9koXGQ== X-Received: by 2002:ac8:23ed:: with SMTP id r42-v6mr928608qtr.89.1540950057789; Tue, 30 Oct 2018 18:40:57 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id y15-v6sm12602582qtn.34.2018.10.30.18.40.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:56 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:01 -0500 Message-Id: <20181031013821.24023-5-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82e Subject: [Qemu-devel] [PULL v2 04/24] configure: add test for libudev 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Signed-off-by: Tomáš Golembiovský Reviewed-by: Marc-André Lureau *make libudev optional to avoid breaking existing build/test environments *disable libudev for --static builds Signed-off-by: Michael Roth --- configure | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/configure b/configure index a898e21c68..406f48f46e 100755 --- a/configure +++ b/configure @@ -474,6 +474,7 @@ libxml2="" docker="no" debug_mutex="no" libpmem="" +libudev="no" # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64="aarch64-linux-gnu-gcc" @@ -870,6 +871,7 @@ Linux) vhost_vsock="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES" supported_os="yes" + libudev="yes" ;; esac @@ -5609,6 +5611,19 @@ if test "$libnfs" != "no" ; then fi fi +########################################## +# Do we have libudev +if test "$libudev" != "no" ; then + if $pkg_config libudev && test "$static" != "yes"; then + if test "$static" != "yes"; then + libudev="yes" + libudev_libs=$($pkg_config --libs libudev) + fi + else + libudev="no" + fi +fi + # Now we've finished running tests it's OK to add -Werror to the compiler flags if test "$werror" = "yes"; then QEMU_CFLAGS="-Werror $QEMU_CFLAGS" @@ -6033,6 +6048,7 @@ echo "VxHS block device $vxhs" echo "capstone $capstone" echo "docker $docker" echo "libpmem support $libpmem" +echo "libudev $libudev" if test "$sdl_too_old" = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -6868,6 +6884,11 @@ if test "$docker" != "no"; then echo "HAVE_USER_DOCKER=y" >> $config_host_mak fi +if test "$libudev" != "no"; then + echo "CONFIG_LIBUDEV=y" >> $config_host_mak + echo "LIBUDEV_LIBS=$libudev_libs" >> $config_host_mak +fi + # use included Linux headers if test "$linux" = "yes" ; then mkdir -p linux-headers From patchwork Wed Oct 31 01:38:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A99E15E9 for ; Wed, 31 Oct 2018 01:55:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 867BB2ABA3 for ; Wed, 31 Oct 2018 01:55:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74ADC2ABBB; Wed, 31 Oct 2018 01:55:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED82F2ABA3 for ; Wed, 31 Oct 2018 01:55:03 +0000 (UTC) Received: from localhost ([::1]:56658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfip-0007ID-8b for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:55:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfVL-0000vN-QP for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfVI-0002aq-J5 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:07 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:33439) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfVI-0002Zw-C7 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:04 -0400 Received: by mail-qt1-x82f.google.com with SMTP id i15-v6so16014231qtr.0 for ; Tue, 30 Oct 2018 18:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ANbaKq6jbZhZybVA7mJIDsdQslcijwVNxDlVYklzAFc=; b=S05JLEH75MMfd21gttnigtdS1NnYdbXgTT4AVzGuMcBegDmfDFsaf5eSQPWvl8vr8t Es9S+zhxhOI2zGx+Iu1oherGcxyVy91CvlDvRhkYo5M4htCzPQEd2SWjj8UQI9HVxD3c tYEYowTvspsKqPlEXFPnts+M+szoETf4SxbGivT1aD9KsNsDUcbXCm+ywNzQlnHCGwqO h4WHmPr/ytknFGePrf5Rn21e+JDfDwhOGcaQABloFyzhZRlIMrD/iK5mYsXh3ZMo421o xjZKrKfbQCaP33c4RuRcvgEzEBMU/mSXA9yOf6sMQLtkLusDWUzznmzQ/wriKYt+2a7/ AAlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ANbaKq6jbZhZybVA7mJIDsdQslcijwVNxDlVYklzAFc=; b=XN/r+S2if7g+MNbo+SpysDin5hctHtr8CEjPU64vWv/du6yTnkswwJ95XUohICtKgg Nm835fCmZFlmF1ZAKTydBWrOBz7s11CKNSbuN5mf6CXnhxhJcjadVZA4aYr3Zr5+tP9D tsTk2hJPi/vviVkAAt1CvGZpHmpks4Zn9dRglmT5SHeSEMu3YY2PJyXGyk+zi9SA9CJV JcUaC/lljuavntVRRjQV+5bExL9NceSS6TuttQEZ0y3VuxeC5DDT2wN3HOm+mSGmFOqP KzlHyON7TLgkS8enQR2VdnTUQX5zs4dBan7K8NbFwsRL1wxYGpCcaYIywSQhnfZt5t+n vhNw== X-Gm-Message-State: AGRZ1gLLICGcIVJ1xkPIOOTK9C3SwVS/aVFeL1GC++p2ymEONoUPQnal Rkd858ZYKvUzz5DKuBgi5Ur9YEab X-Google-Smtp-Source: AJdET5e3s1A7rbnQK+TOZpGnOMWEvZzkakwPTHHg8PK0H6TwFK+Ud7w6vdDj818LYHQcMxicPHilSg== X-Received: by 2002:ac8:1096:: with SMTP id a22-v6mr927040qtj.359.1540950061288; Tue, 30 Oct 2018 18:41:01 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id d6-v6sm4976306qth.18.2018.10.30.18.40.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:41:00 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:02 -0500 Message-Id: <20181031013821.24023-6-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82f Subject: [Qemu-devel] [PULL v2 05/24] qga: linux: report disk serial number 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Add reporting of disk serial number on Linux guests. The feature depends on libudev. Example: { "name": "dm-2", "mountpoint": "/", ... "disk": [ { "serial": "SAMSUNG_MZ7LN512HCHP-000L1_S1ZKNXAG822493", ... } ], } Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/Makefile.objs | 1 + qga/commands-posix.c | 32 ++++++++++++++++++++++++++++++-- qga/qapi-schema.json | 4 +++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/qga/Makefile.objs b/qga/Makefile.objs index ed08c5917c..80e6bb3c2e 100644 --- a/qga/Makefile.objs +++ b/qga/Makefile.objs @@ -1,3 +1,4 @@ +commands-posix.o-libs := $(LIBUDEV_LIBS) qga-obj-y = commands.o guest-agent-command-state.o main.o qga-obj-$(CONFIG_POSIX) += commands-posix.o channel-posix.o qga-obj-$(CONFIG_WIN32) += commands-win32.o channel-win32.o service-win32.o diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 42d30f078e..41bd11b2b5 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -48,6 +48,10 @@ extern char **environ; #include #include +#ifdef CONFIG_LIBUDEV +#include +#endif + #ifdef FIFREEZE #define CONFIG_FSFREEZE #endif @@ -872,6 +876,10 @@ static void build_guest_fsinfo_for_real_device(char const *syspath, GuestDiskAddressList *list = NULL; bool has_ata = false, has_host = false, has_tgt = false; char *p, *q, *driver = NULL; +#ifdef CONFIG_LIBUDEV + struct udev *udev = NULL; + struct udev_device *udevice = NULL; +#endif p = strstr(syspath, "/devices/pci"); if (!p || sscanf(p + 12, "%*x:%*x/%x:%x:%x.%x%n", @@ -936,6 +944,21 @@ static void build_guest_fsinfo_for_real_device(char const *syspath, list = g_malloc0(sizeof(*list)); list->value = disk; +#ifdef CONFIG_LIBUDEV + udev = udev_new(); + udevice = udev_device_new_from_syspath(udev, syspath); + if (udev == NULL || udevice == NULL) { + g_debug("failed to query udev"); + } else { + const char *serial; + serial = udev_device_get_property_value(udevice, "ID_SERIAL"); + if (serial != NULL && *serial != 0) { + disk->serial = g_strdup(serial); + disk->has_serial = true; + } + } +#endif + if (strcmp(driver, "ata_piix") == 0) { /* a host per ide bus, target*:0::0 */ if (!has_host || !has_tgt) { @@ -995,14 +1018,19 @@ static void build_guest_fsinfo_for_real_device(char const *syspath, list->next = fs->disk; fs->disk = list; - g_free(driver); - return; + goto out; cleanup: if (list) { qapi_free_GuestDiskAddressList(list); } +out: g_free(driver); +#ifdef CONFIG_LIBUDEV + udev_unref(udev); + udev_device_unref(udevice); +#endif + return; } static void build_guest_fsinfo_for_device(char const *devpath, diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index dfbc4a5e32..3bcda6257e 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -834,13 +834,15 @@ # @bus: bus id # @target: target id # @unit: unit id +# @serial: serial number (since: 3.1) # # Since: 2.2 ## { 'struct': 'GuestDiskAddress', 'data': {'pci-controller': 'GuestPCIAddress', 'bus-type': 'GuestDiskBusType', - 'bus': 'int', 'target': 'int', 'unit': 'int'} } + 'bus': 'int', 'target': 'int', 'unit': 'int', + '*serial': 'str'} } ## # @GuestFilesystemInfo: From patchwork Wed Oct 31 01:38:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DA6F15E9 for ; Wed, 31 Oct 2018 01:57:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EC852ABC8 for ; Wed, 31 Oct 2018 01:57:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1327B2ABDF; Wed, 31 Oct 2018 01:57:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AF5452ABC8 for ; Wed, 31 Oct 2018 01:57:26 +0000 (UTC) Received: from localhost ([::1]:56674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfl8-0000o4-1u for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:57:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfVQ-000104-UG for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfVM-0002do-D2 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:12 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:38510) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfVM-0002bC-6Z for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:08 -0400 Received: by mail-qt1-x82f.google.com with SMTP id v1-v6so11758418qtq.5 for ; Tue, 30 Oct 2018 18:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ogb5hMscvBR7/97F7+QGB34/MnUmfKCPRhsa5QI4p84=; b=QiIM4hC88jDZm+65RrJFmlKVhdC0vCjRjTQtcLuHYnTOR4sEb5gsEbjcSg/MTEmJhK rH14GuxSjN/NPND1SwkEXrM1XApBzsO2Hq/Ir/XMHX1mspKqZnt+S/Dwr/UDuuO0yMUC 3tHqHg/JF6erZXZbFzC75IEA3qzNIWp/9NQsdPhWbqqIo1iaHQ3PNeCRE1acMucGS5wc WINYRpoIM50QTZA+Itv9D5HZ+tK6UBeyXCWWJegfTHMQBgQ8cXLA1x4u4XldwgIB1CoF MHGcoh/wWdFXpRoUuIesiwt50XYa1wkThE3797L1HyNeWmB7iJB+sHmGZV5oOBxja+EL r3/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Ogb5hMscvBR7/97F7+QGB34/MnUmfKCPRhsa5QI4p84=; b=UiyVwHXWQGxO84fVneKkV/PZO53H1hVbC9nPyaWLuqdtoJgPvaCZNsF8Ub4mZmX/T3 F13s1g0An6ykXHYwwKBR8oqwVStWKyLgE1dKkt8PCeMayRK8HGzVXsTt3WuYvenKpWN1 XrdOKJ3YCs2byeNlZhoq1psI2vz01UMiwt2GpOL/crhedOJ5yj/zH0KQOACXE3TLJ56H nBWH0sy/alcgwYKY1Tz9WGciqlVZKfYasmPbDkEcF+oOgl0SY4EK1iVF0HjChHsi/IG3 Bt6jPcaE2ozKJBbKibihtfYf8qytPtxNCLg1JFxAca4joYUtI5Yd/Dz+Xs7bFAmN8gCi bzzw== X-Gm-Message-State: AGRZ1gLP7SZfFdBVA9Lem5iPCakvysb8o8cNidtQ7+o8gAgQvL3DtTxO p3TXlUZzPkOkAR4rWuxnIoxbQ2PV X-Google-Smtp-Source: AJdET5c8BO1+pzRZ2hePOBYD840YiZ1exVm7F9KLgWhL5J/XUqSvlAThmbwb15jPXZj6CFve0/s8hw== X-Received: by 2002:a0c:d29b:: with SMTP id q27mr988494qvh.62.1540950063932; Tue, 30 Oct 2018 18:41:03 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id x141-v6sm8950832qka.9.2018.10.30.18.41.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:41:02 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:03 -0500 Message-Id: <20181031013821.24023-7-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82f Subject: [Qemu-devel] [PULL v2 06/24] qga: linux: return disk device in guest-get-fsinfo 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Report device node of the disk on Linux (e.g. "/dev/sda2"). Requirs libudev. Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/commands-posix.c | 7 ++++++- qga/qapi-schema.json | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 41bd11b2b5..1877976522 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -950,7 +950,12 @@ static void build_guest_fsinfo_for_real_device(char const *syspath, if (udev == NULL || udevice == NULL) { g_debug("failed to query udev"); } else { - const char *serial; + const char *devnode, *serial; + devnode = udev_device_get_devnode(udevice); + if (devnode != NULL) { + disk->dev = g_strdup(devnode); + disk->has_dev = true; + } serial = udev_device_get_property_value(udevice, "ID_SERIAL"); if (serial != NULL && *serial != 0) { disk->serial = g_strdup(serial); diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 3bcda6257e..c6725b3ec8 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -835,6 +835,7 @@ # @target: target id # @unit: unit id # @serial: serial number (since: 3.1) +# @dev: device node (POSIX) or device UNC (Windows) (since: 3.1) # # Since: 2.2 ## @@ -842,7 +843,7 @@ 'data': {'pci-controller': 'GuestPCIAddress', 'bus-type': 'GuestDiskBusType', 'bus': 'int', 'target': 'int', 'unit': 'int', - '*serial': 'str'} } + '*serial': 'str', '*dev': 'str'} } ## # @GuestFilesystemInfo: From patchwork Wed Oct 31 01:38:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 824A613A4 for ; Wed, 31 Oct 2018 01:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 724612ABC8 for ; Wed, 31 Oct 2018 01:57:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6672E2ABDF; Wed, 31 Oct 2018 01:57:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A7CB2ABC8 for ; Wed, 31 Oct 2018 01:57:21 +0000 (UTC) Received: from localhost ([::1]:56673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfl2-0000jk-4i for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:57:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfVQ-000105-UP for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfVM-0002e2-Ih for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:12 -0400 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]:35189) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfVM-0002dD-D9 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:08 -0400 Received: by mail-qk1-x744.google.com with SMTP id v68-v6so8592100qka.2 for ; Tue, 30 Oct 2018 18:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OMsafrgRN8K7qYrDHmXKNcug1Hah0nOGn2aWbm0aBsM=; b=ZGqLNlOfJBjZ4DCPUZz7TLnowtBzZ7U+k3/B44pfwgFYzJHDCcZLOG4j3gUyoJfNcL EzUuTOcqJZ2Q81Yaz3NeDqthroSvvYsZl8gP/bdY5ILGGCnA89FtHzXdLBpEVmyutmjy YxyC0nanIEv38yeB1A/J461yEQ641mblwU+4m5R1x9UAes1Try1Gx/NnGwH1LC56Lhx5 wNqr2/4DyBn+P09HxCWeVur/PT76RCxa12h+1wDljIjDj3rSAdfR7vGujzdSGS6ImVP5 XUQ5gv5Y1ZQ9Wz+NQj02nemTMu1/kHOXdG1VvK5j1LTOAo5Uq9Xg46lkaBKAexmVLHdF 8ynQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=OMsafrgRN8K7qYrDHmXKNcug1Hah0nOGn2aWbm0aBsM=; b=NZcybLlCHpCa4Ud366tOGKFkDYNr1tlD+ob3U8aB0VUTkGbTDbYKhWIpRbv/SWxwf9 JlC0dhAdQwPn/lpaeR3E00Js2eE3cBezQzCSN9VEzMEXSfAPMcaFtfvROISqssU/2PvY Bgfuq8O9wR0nTIhIVoLUUBJrYHYwHc+5SWTjHDnkVtCzvCDHyY0F4mIUZ/ERQwEYVgcZ duGlhUgMV88wTPF4MjwJVxfcUXup9VwBU+gcRiil3ET2Dg/cclONZc6Q95v6TvXXMaSS Q1ZT7ggud2hfNnNHupJ8A0rkbgKOynYCA8V3tIG/1WFn7bDWbGaiXS6x3z34Whkznyik tPuQ== X-Gm-Message-State: AGRZ1gJNidqb2DylPSH31GN9fIDdrpaT0iXTOekLQjs8dibbI3+jlRss qtcS1IJFDkhnBZHnHOxnQRHnYNkO X-Google-Smtp-Source: AJdET5eT4sQRTn9qNTBwo2COeMrmgUylzcCFFWw60CqGKHZRSliksaSQPbI22pfFdgvMqDeVZM9Frg== X-Received: by 2002:a37:8d:: with SMTP id t13mr888070qkg.93.1540950066985; Tue, 30 Oct 2018 18:41:06 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id v23-v6sm19088010qtv.65.2018.10.30.18.41.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:41:05 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:04 -0500 Message-Id: <20181031013821.24023-8-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::744 Subject: [Qemu-devel] [PULL v2 07/24] qga-win: prevent crash when executing fsinfo command 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: Sameeh Jubran , peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sameeh Jubran The fsinfo command is currently implemented for Windows only and it's disk parameter can be enabled by adding the define "CONFIG_QGA_NTDDSCSI" to the qga code. When enabled and executed the qemu-ga crashed with the following message: ------------------------------------------------ File qapi/qapi-visit-core.c, Line 49 Expression: !(v->type & VISITOR_OUTPUT) || *obj) ------------------------------------------------ After some digging, turns out that the GuestPCIAddress is null and the qapi visitor doesn't like that, so we can always allocate it instead and initiate all it's members to -1. Signed-off-by: Sameeh Jubran Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Michael Roth Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/commands-win32.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 347577f2a4..f0e6f6128b 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -499,6 +499,11 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) char *buffer = NULL; GuestPCIAddress *pci = NULL; char *name = g_strdup(&guid[4]); + pci = g_malloc0(sizeof(*pci)); + pci->domain = -1; + pci->slot = -1; + pci->function = -1; + pci->bus = -1; if (!QueryDosDevice(name, dev_name, ARRAY_SIZE(dev_name))) { error_setg_win32(errp, GetLastError(), "failed to get dos device name"); @@ -570,7 +575,6 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) func = addr & 0x0000FFFF; dev = (addr >> 16) & 0x0000FFFF; - pci = g_malloc0(sizeof(*pci)); pci->domain = dev; pci->slot = slot; pci->function = func; From patchwork Wed Oct 31 01:38:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B211115E9 for ; Wed, 31 Oct 2018 01:59:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A21A42A21C for ; Wed, 31 Oct 2018 01:59:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9635A2A25B; Wed, 31 Oct 2018 01:59:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0CF492A21C for ; Wed, 31 Oct 2018 01:59:39 +0000 (UTC) Received: from localhost ([::1]:56685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfnG-0003ty-8C for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:59:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfVQ-000103-UL for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfVP-0002fz-Mx for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:12 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:33436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfVP-0002fd-Gm for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:11 -0400 Received: by mail-qt1-x82b.google.com with SMTP id i15-v6so16014497qtr.0 for ; Tue, 30 Oct 2018 18:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jqJy8O/Q/q3DF/vRTGPc19Bl200H+tWJBLN5cD9F4O8=; b=D2S7rorGFIvmAm5vm1nLGI4s34uuERT8pMeZCy1zfdfPu/yY2U+rNWiOaSe2ccq+yU rG+eOv7yujaseThbkXUIrPU0kPCxkCrZazGRhGHHAJ5cL50qlslYR0ETl4Qexa1LlHqU DE9DWyZpl4+txb7DNuuO+N8J0njLwuJjBijQy3BO2rs6s6hVpoPLRXsDOdxx1cyuwTO+ wLohv1QTXsoi9W/hRkJoaA9w+vDZvFwxRR9HFzf2gVYtMQuZFNG17xBVa8Z+SnvXQwmz ERnPBaoiCrwL3PNwrJXSjhZFKgA9tklNrtXC/dkSGUD+r3ieYgXUv6a8oQks/v/vwLFe Otyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jqJy8O/Q/q3DF/vRTGPc19Bl200H+tWJBLN5cD9F4O8=; b=gVshutOY/TJL9PsVlZFDjKfxKDhqorFk2GtgHaQ18rDyxyyQMdtzcxeNXmdcrsg02f twHrWrq9izzrynNx+iRODBhCeViiiTLz+iMj+h2Pi0ASrzOKXL9bhPer3v2HLPzCuscZ 5eV1/TDB920zi3xbbXuAKzwzpALuZTkK5kzh07jF2VYQRUrlmeQdF44wOCeNYtqYMVeA ilMCCLVlUibQuq8Z87VOiFUDcJ7gk2zO0dRONDHvWqplJytA8v6PihIBvdK1Kh8icC3L fM1WytZg/ZuxPmnIJmD2hbrrip99XKmw/CZQYfh0EvPN8fZJbAkmpPUevpPvzNZztOmV turg== X-Gm-Message-State: AGRZ1gKOSFn24u795dyH0UEr9hQ4GNYR8rqU0BfgINZrlPob0Sq5Nqud Mdpnw4sc6EM5b+4IXKl5qRzxHSB0 X-Google-Smtp-Source: AJdET5d2ZIAwVNZODnlrnw5IojAltCd67kJ7tQtUw7d9KYJ0Qbm9H87hlk+X4NIJn9W/KTwuSBdHgg== X-Received: by 2002:ac8:22ed:: with SMTP id g42-v6mr994854qta.105.1540950069892; Tue, 30 Oct 2018 18:41:09 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 34-v6sm9722204qty.58.2018.10.30.18.41.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:41:08 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:05 -0500 Message-Id: <20181031013821.24023-9-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82b Subject: [Qemu-devel] [PULL v2 08/24] qga-win: fsinfo: pci-info: allow partial info 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: Sameeh Jubran , peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sameeh Jubran The call to SetupDiGetDeviceRegistryProperty might fail because the value doesn't exist in the registry, in this case we shouldn't exit from the loop but instead continue to look for other available values in the registry and set this value as unavailable (-1). Signed-off-by: Sameeh Jubran Signed-off-by: Michael Roth Signed-off-by: Tomáš Golembiovský *squash in fix for when get_pci_info() returns NULL pci_controller field *fix handling for error_set() cases in get_pci_info(), not just NULL return *force all -1 PCI addr fields if any single one of them isn't found Signed-off-by: Michael Roth --- qga/commands-win32.c | 46 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index f0e6f6128b..4fe1517778 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -499,6 +499,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) char *buffer = NULL; GuestPCIAddress *pci = NULL; char *name = g_strdup(&guid[4]); + bool partial_pci = false; pci = g_malloc0(sizeof(*pci)); pci->domain = -1; pci->slot = -1; @@ -519,7 +520,8 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) { - DWORD addr, bus, slot, func, dev, data, size2; + DWORD addr, bus, slot, data, size2; + int func, dev; while (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, &data, (PBYTE)buffer, size, @@ -549,21 +551,24 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_BUSNUMBER, &data, (PBYTE)&bus, size, NULL)) { - break; + bus = -1; + partial_pci = true; } /* The function retrieves the device's address. This value will be * transformed into device function and number */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_ADDRESS, &data, (PBYTE)&addr, size, NULL)) { - break; + addr = -1; + partial_pci = true; } /* This call returns UINumber of DEVICE_CAPABILITIES structure. * This number is typically a user-perceived slot number. */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_UI_NUMBER, &data, (PBYTE)&slot, size, NULL)) { - break; + slot = -1; + partial_pci = true; } /* SetupApi gives us the same information as driver with @@ -573,12 +578,19 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) * DeviceNumber = (USHORT)(((propertyAddress) >> 16) & 0x0000FFFF); * SPDRP_ADDRESS is propertyAddress, so we do the same.*/ - func = addr & 0x0000FFFF; - dev = (addr >> 16) & 0x0000FFFF; - pci->domain = dev; - pci->slot = slot; - pci->function = func; - pci->bus = bus; + if (partial_pci) { + pci->domain = -1; + pci->slot = -1; + pci->function = -1; + pci->bus = -1; + } else { + func = ((int) addr == -1) ? -1 : addr & 0x0000FFFF; + dev = ((int) addr == -1) ? -1 : (addr >> 16) & 0x0000FFFF; + pci->domain = dev; + pci->slot = (int) slot; + pci->function = func; + pci->bus = (int) bus; + } break; } @@ -622,6 +634,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) DWORD len; int bus; HANDLE vol_h; + Error *local_err = NULL; scsi_ad = &addr; char *name = g_strndup(guid, strlen(guid)-1); @@ -640,6 +653,16 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) disk = g_malloc0(sizeof(*disk)); disk->bus_type = find_bus_type(bus); + /* always set pci_controller as required by schema. get_pci_info() should + * report -1 values for non-PCI buses rather than fail. fail the command + * if that doesn't hold since that suggests some other unexpected + * breakage + */ + disk->pci_controller = get_pci_info(name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out_close; + } if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID #if (_WIN32_WINNT >= 0x0600) /* This bus type is not supported before Windows Server 2003 SP1 */ @@ -654,12 +677,9 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) disk->unit = addr.Lun; disk->target = addr.TargetId; disk->bus = addr.PathId; - disk->pci_controller = get_pci_info(name, errp); } /* We do not set error in this case, because we still have enough * information about volume. */ - } else { - disk->pci_controller = NULL; } list = g_malloc0(sizeof(*list)); From patchwork Wed Oct 31 01:38:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E88113BF for ; Wed, 31 Oct 2018 01:44:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E92328710 for ; Wed, 31 Oct 2018 01:44:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82A1E2AC34; Wed, 31 Oct 2018 01:44:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A4B8D28710 for ; Wed, 31 Oct 2018 01:44:44 +0000 (UTC) Received: from localhost ([::1]:56603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfYp-0004yy-L6 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:44:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUc-0000JH-4w for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUY-000249-3C for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:22 -0400 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]:36402) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUX-0001ru-SE for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:17 -0400 Received: by mail-qk1-x742.google.com with SMTP id o125so5328419qkf.3 for ; Tue, 30 Oct 2018 18:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V12rGQsTUHuze1dHFF69yG9N87hdC2Z0Se0NxY6Wtew=; b=LGIuaTCCvLpmWNKzx9be42cYnBpVyQqm3fXRgYwcs6DHkA1EpNLr1HM6LvMtDkCJFT L2GmOTI1rwDFgji8EkoaK+313fdFVuPMiqg55f0RDGulcLRyPA8CAjE7mhGQspvRppy7 l5IzMI+M5O4NARTq8GM64inXPSocZhw915oid7Q1cV3chL9Wpi6Lqm0+qUSSWQXxcXKa 7DtbxL1vQJH4ynMzVKbNOVWVXNLVe9aDNF5L+LK93SnVA+f6ra81w2zxM8My2ZN4/dDD lBcFZFhydHdRmZi/SyEG3Ly/mEXv+5enHv5KWKVoe3qMycjEg0AUIOyWRhDOlvwZMa2O QtZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=V12rGQsTUHuze1dHFF69yG9N87hdC2Z0Se0NxY6Wtew=; b=fQjd0Dut8+usCv9BXYyQEU8ZWEc0hMMLpOFDvHBAUz+QQ41pnECQPs633s3FUdV5Bv wuC77R6gJFo3mJNlNxf/0RI63F0UbXgGp0MJNa77cFEWTZ/s9VTiPmjisQL3yp4dERMR QmZRjet8Dg5f3/MiQA5sytZLsCwB0w42NhiJd2XqxG+Hv0hbsAnPxgYSjaW12rcrEdA/ +lr9UsitzhHjASG4vmMDQLcGTMbyiA+58yeaIMXGL4AJVm6e2LGvjJJGVKLAdwBMQtwC +KE3H08JBgIaIHu1uFmjtd35gRUfaUyiuB0XyYmabw5aeyieR3C6aX9V/1bkLeeAMYyv SaYQ== X-Gm-Message-State: AGRZ1gKXqP/f9wlX3dRL4TCrqEeLJ8YBxzY28y65DNVsyLewDEbO3m6w rX2gmuIXkxrEjxV4I6+slLrh+CEy X-Google-Smtp-Source: AJdET5f9JAPu9XfK9CvvjZHqs2DGxQiXp3FO3YlCGrPXuuFYzCh5ck9Ar8pyQBKfBnf/q+hsg8wIbA== X-Received: by 2002:a37:de15:: with SMTP id h21-v6mr901640qkj.254.1540949998978; Tue, 30 Oct 2018 18:39:58 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id g80sm1057706qkh.41.2018.10.30.18.39.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:39:57 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:06 -0500 Message-Id: <20181031013821.24023-10-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::742 Subject: [Qemu-devel] [PULL v2 09/24] build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský There was inconsistency between commits: 50cbebb9a3 configure: add configure check for ntdddisk.h a3ef3b2272 qga: added bus type and disk location path The first commit added #define CONFIG_QGA_NTDDDISK but the second commit expected the name to be CONFIG_QGA_NTDDSCSI. As a result the code in second patch was never used. Renaming the option to CONFIG_QGA_NTDDSCSI to match the name of header file that is being checked for. Signed-off-by: Tomáš Golembiovský Reviewed-by: Marc-André Lureau Reviewed-by: Sameeh Jubran Signed-off-by: Michael Roth --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 406f48f46e..081a3069e3 100755 --- a/configure +++ b/configure @@ -6144,7 +6144,7 @@ if test "$mingw32" = "yes" ; then echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak fi if test "$guest_agent_ntddscsi" = "yes" ; then - echo "CONFIG_QGA_NTDDDISK=y" >> $config_host_mak + echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak fi if test "$guest_agent_msi" = "yes"; then echo "QEMU_GA_MSI_ENABLED=yes" >> $config_host_mak From patchwork Wed Oct 31 01:38:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C597913BF for ; Wed, 31 Oct 2018 01:44:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5A4328710 for ; Wed, 31 Oct 2018 01:44:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9F0A2AC34; Wed, 31 Oct 2018 01:44:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B75C28710 for ; Wed, 31 Oct 2018 01:44:47 +0000 (UTC) Received: from localhost ([::1]:56604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfYs-000553-Ed for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:44:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUc-0000JJ-59 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUX-000233-3D for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:22 -0400 Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]:33557) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUV-0001tC-KM for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:16 -0400 Received: by mail-qk1-x736.google.com with SMTP id o89so8595578qko.0 for ; Tue, 30 Oct 2018 18:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2TYlUdwcjes9Hsxl3QO7bcr473sAzRxMT3hABlS6QMc=; b=cmkymjPXbVhnagJUxaQ+lNcisIfQKECUiuQsHDeeyBnq8RZHmymcAxM5G9y/JBUsdH IS8hGXBVbqZxXBSQwpaFMDj29IGQVi2OYxXxhvF0LyojZpvN7AxTNT1Bkv4H0IDi0ImQ IBQCJT4ziRBWXdrkWN24xA4e7jNXCDQBIntqfNsia3FNUk2wZPNCDRdYnfDzJ5fAG3Xh rwvPzvgfpZI83XKThB28WtGsLtjBLuj9nmg5aJx0LTBGafYO6gZUSUR+Jl3RFso632zp Tmct5GIpUQbBJkyHyZQ7umqCPW0oPYUzJNTimHbDGX0m0OiTWA40MqRfTmBzFDQKiIbS jnXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2TYlUdwcjes9Hsxl3QO7bcr473sAzRxMT3hABlS6QMc=; b=rNSLtOhp1I26dO+Tz6x4Q+z8Kn3NLXnjQ4WD/B8Gmx6Lu7Qg+9Mk4s4lr1PUoKhZO/ YVRq3bXljQUPfm4Y8rBVV+rqSs8hqdOH8AYvYlu4R/Navc03Dc41OUn42Xf70gxv8b9g 2eLI/NYb+JmfZDBeAxQsPieBB0JzloMe806DXW2IAeMya52Xygabq0Qkhf7K/J3zEUK7 bI/sV3v51Jrx702uNB116spPH2GyHxKpGNkqN/Btkslzr/W6UlzOtK0y52xxObMElPGV zC/jHVKazogo4ulIpp4UqfEFpQXt3pms8ZtthOGz8PTTYftaYc1I5mHHxJJ1KiaSwcv4 5PAA== X-Gm-Message-State: AGRZ1gLZP7L56ZE/9E/RaL8UmDzl/qgn7nj0vnAHyRjZPVREbiJs0K+T jcwxHu1fPND8/oQwQqS5RPLGn0Js X-Google-Smtp-Source: AJdET5cwjgDWDzGCXJ32LNWsIHyWS3RedqOYobGfw5sZnhpqCoDuE006740BtZNgpCYrufyy/G6A7A== X-Received: by 2002:a37:ac05:: with SMTP id e5mr966360qkm.102.1540950002174; Tue, 30 Oct 2018 18:40:02 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 53-v6sm18429959qtw.52.2018.10.30.18.40.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:01 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:07 -0500 Message-Id: <20181031013821.24023-11-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::736 Subject: [Qemu-devel] [PULL v2 10/24] qga-win: add debugging information 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The windows code generaly lacks debug information (compared to posix code). This patch adds some related to HW info in guest-get-fsinfo command. Signed-off-by: Tomáš Golembiovský Reviewed-by: Marc-André Lureau Signed-off-by: Michael Roth --- qga/commands-win32.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 4fe1517778..1a21aac5ad 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -89,6 +89,12 @@ static OpenFlags guest_file_open_modes[] = { {"a+b", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS } }; +#define debug_error(msg) do { \ + char *suffix = g_win32_error_message(GetLastError()); \ + g_debug("%s: %s", (msg), suffix); \ + g_free(suffix); \ +} while (0) + static OpenFlags *find_open_flag(const char *mode_str) { int mode; @@ -518,6 +524,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) goto out; } + g_debug("enumerating devices"); dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) { DWORD addr, bus, slot, data, size2; @@ -543,6 +550,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) if (g_strcmp0(buffer, dev_name)) { continue; } + g_debug("found device %s", dev_name); /* There is no need to allocate buffer in the next functions. The size * is known and ULONG according to @@ -551,6 +559,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_BUSNUMBER, &data, (PBYTE)&bus, size, NULL)) { + debug_error("failed to get bus"); bus = -1; partial_pci = true; } @@ -559,6 +568,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) * transformed into device function and number */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_ADDRESS, &data, (PBYTE)&addr, size, NULL)) { + debug_error("failed to get address"); addr = -1; partial_pci = true; } @@ -567,6 +577,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) * This number is typically a user-perceived slot number. */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_UI_NUMBER, &data, (PBYTE)&slot, size, NULL)) { + debug_error("failed to get slot"); slot = -1; partial_pci = true; } @@ -639,6 +650,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) scsi_ad = &addr; char *name = g_strndup(guid, strlen(guid)-1); + g_debug("getting disk info for: %s", name); vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (vol_h == INVALID_HANDLE_VALUE) { @@ -646,6 +658,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) goto out_free; } + g_debug("getting bus type"); bus = get_disk_bus_type(vol_h, errp); if (bus < 0) { goto out_close; @@ -653,6 +666,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) disk = g_malloc0(sizeof(*disk)); disk->bus_type = find_bus_type(bus); + g_debug("bus type %d", disk->bus_type); /* always set pci_controller as required by schema. get_pci_info() should * report -1 values for non-PCI buses rather than fail. fail the command * if that doesn't hold since that suggests some other unexpected @@ -672,6 +686,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) /* We are able to use the same ioctls for different bus types * according to Microsoft docs * https://technet.microsoft.com/en-us/library/ee851589(v=ws.10).aspx */ + g_debug("getting pci-controller info"); if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_ad, sizeof(SCSI_ADDRESS), &len, NULL)) { disk->unit = addr.Lun; From patchwork Wed Oct 31 01:38:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC96913BF for ; Wed, 31 Oct 2018 01:41:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB4C328E47 for ; Wed, 31 Oct 2018 01:41:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D83F28ED0; Wed, 31 Oct 2018 01:41:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 30EFE28E47 for ; Wed, 31 Oct 2018 01:41:50 +0000 (UTC) Received: from localhost ([::1]:56590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfW1-0001U4-By for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:41:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUc-0000JK-5N for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUY-00024V-AZ for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:22 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:37016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUY-0001vC-28 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:18 -0400 Received: by mail-qt1-x82b.google.com with SMTP id d14-v6so15999371qto.4 for ; Tue, 30 Oct 2018 18:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RPJEUP7diCJbHKDeII8UxiVI5VxahZogKC/CIYD6XH8=; b=hp3qt9IkDOcpKi589Sh7ImPk1oCZ109zYp31HNhpfEZN8jXga4DVJoURtaFmH3vI34 h1jNECGqQAYS7NGeRXt+TOaoKwEpWSYZQNMFv9tGwWLFv82XmzR3sHAhdwLFQM/Ambj9 h+gvIjt1wiKQcHR7nxSJQnibDrX1zo4MJxUK390Hlvmdj3YPJMlTb5OqF3+laLmmT8GB Np+7PW6w3+orm6yfylXD8qBRPs821Npp6UI2SltDy9Y/PaiwbBPSNFBOwSyvF9rhkAX4 Sfk8vairhSXB73TRMDyLjs+OnXEdVe19z3ObrOTA54pTopb8isptrZZxv9w3HzNADxbb UXhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=RPJEUP7diCJbHKDeII8UxiVI5VxahZogKC/CIYD6XH8=; b=mj8c7wL71dgqLTbgLjR2JW35s333hGcivegG5G1zAq9N65iWwJ3woiZetiTm2Y3yi9 gbAt3MQeEQZA8wguizXpSc/rUsVxGHU3WOfhPZmdvitd1RPl6wZ8ERpywmUKJZdDyZPG LiOMhCZk7oBCLgy0TBf2m7Y9gd3YCmeb+qvCaLYuW5n0E82WkrxfCISKyAYRz8eP6pJx AinBdniNFCEfy5zoioLDCJyy8nT2pfr6Jbg44P+bfwvte4fCVINPkZ8s8EtNIcP8eLxp SUlKt6qzIRoMDkpjHHKjO84KHzrW29/rPRuIFxaaFpL0kW2S0MC1ODS95fdUjTV4m2+L dD9A== X-Gm-Message-State: AGRZ1gK0yqud5WttqBLOBs6zTo/EOpFI9LR2EkKKJswWoqRJ8x9aeK2H bV4tHlfeB2YrNGLOPtcvmySDhEaz X-Google-Smtp-Source: AJdET5dQ40HT/pw/oJy96XL2B8ZT//i5rKUZpOWLQOr1YRbj+6JfLUeX3Kb+TzHULXhJlGmuGCOAHg== X-Received: by 2002:a0c:acaf:: with SMTP id m44mr972780qvc.142.1540950008068; Tue, 30 Oct 2018 18:40:08 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id h49-v6sm19498217qth.32.2018.10.30.18.40.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:06 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:08 -0500 Message-Id: <20181031013821.24023-12-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82b Subject: [Qemu-devel] [PULL v2 11/24] qga-win: refactor disk properties (bus) 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Refactor code that queries bus type to be more generic. The function get_disk_bus_type() has been renamed to build_guest_disk_info(). Following commit(s) will extend this function. Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/commands-win32.c | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 1a21aac5ad..1e91aa2343 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -613,25 +613,28 @@ out: return pci; } -static int get_disk_bus_type(HANDLE vol_h, Error **errp) +static void get_disk_properties(HANDLE vol_h, GuestDiskAddress *disk, + Error **errp) { STORAGE_PROPERTY_QUERY query; STORAGE_DEVICE_DESCRIPTOR *dev_desc, buf; DWORD received; + ULONG size = sizeof(buf); dev_desc = &buf; - dev_desc->Size = sizeof(buf); query.PropertyId = StorageDeviceProperty; query.QueryType = PropertyStandardQuery; if (!DeviceIoControl(vol_h, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(STORAGE_PROPERTY_QUERY), dev_desc, - dev_desc->Size, &received, NULL)) { + size, &received, NULL)) { error_setg_win32(errp, GetLastError(), "failed to get bus type"); - return -1; + return; } + disk->bus_type = find_bus_type(dev_desc->BusType); + g_debug("bus type %d", disk->bus_type); - return dev_desc->BusType; + return; } /* VSS provider works with volumes, thus there is no difference if @@ -643,7 +646,6 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) GuestDiskAddress *disk; SCSI_ADDRESS addr, *scsi_ad; DWORD len; - int bus; HANDLE vol_h; Error *local_err = NULL; @@ -655,17 +657,16 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) 0, NULL); if (vol_h == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open volume"); - goto out_free; + goto err; } - g_debug("getting bus type"); - bus = get_disk_bus_type(vol_h, errp); - if (bus < 0) { - goto out_close; + disk = g_malloc0(sizeof(*disk)); + get_disk_properties(vol_h, disk, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto err_close; } - disk = g_malloc0(sizeof(*disk)); - disk->bus_type = find_bus_type(bus); g_debug("bus type %d", disk->bus_type); /* always set pci_controller as required by schema. get_pci_info() should * report -1 values for non-PCI buses rather than fail. fail the command @@ -675,12 +676,14 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) disk->pci_controller = get_pci_info(name, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out_close; + goto err_close; } - if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID + if (disk->bus_type == GUEST_DISK_BUS_TYPE_SCSI + || disk->bus_type == GUEST_DISK_BUS_TYPE_IDE + || disk->bus_type == GUEST_DISK_BUS_TYPE_RAID #if (_WIN32_WINNT >= 0x0600) /* This bus type is not supported before Windows Server 2003 SP1 */ - || bus == BusTypeSas + || disk->bus_type == GUEST_DISK_BUS_TYPE_SAS #endif ) { /* We are able to use the same ioctls for different bus types @@ -700,11 +703,17 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) list = g_malloc0(sizeof(*list)); list->value = disk; list->next = NULL; -out_close: CloseHandle(vol_h); -out_free: g_free(name); return list; + +err_close: + g_free(disk); + CloseHandle(vol_h); +err: + g_free(name); + + return NULL; } #else From patchwork Wed Oct 31 01:38:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E91CE1751 for ; Wed, 31 Oct 2018 01:41:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7D9E28AA1 for ; Wed, 31 Oct 2018 01:41:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC11828EBD; Wed, 31 Oct 2018 01:41:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7537228AA1 for ; Wed, 31 Oct 2018 01:41:52 +0000 (UTC) Received: from localhost ([::1]:56591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfW3-0001WM-M1 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:41:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUc-0000JG-4q for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUX-00023Q-Ji for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:22 -0400 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:37477) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUX-0001zm-BE for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:17 -0400 Received: by mail-qk1-x72e.google.com with SMTP id 131so8583457qkd.4 for ; Tue, 30 Oct 2018 18:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lJTCbkkBdols6F5fbem69Rs++cbtn/Hjin27UsxH/WM=; b=YWjNaqGiNa3MOqzEDK0DTqCql5MsLjythZQCQ5RRRfVq8V6KpNziMPeXXbbOO8JHuD 2SFIB4rFRX/2xq1Scx/sfnWT//P2tYLSr6t7xSI8g+su6cZJidplmTgxQg/QEFhsqqMC Nc78qGGynXgnXHGITl8OXSOJEFwphL4fR0yktiGWDxSdjjtpHtm/L0KXAK7yMz5GtFto Fl6faJRCqwgdL2zEPaFjkp5Nj4YJn71vaXbs2g/07KmEX0Yq3xbuwZfYSulB+4m5J7s9 58D7RnEIecMo25TFj/syUZSksTnEY/HC7EtlFU8VFSkMr5u/rN9SE97imaDsDcajTify Hdjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=lJTCbkkBdols6F5fbem69Rs++cbtn/Hjin27UsxH/WM=; b=INLw2uCT9lw/v5979oZMFqAdgj4+daTa4yaKhjUhwBWicPGpjWKtsg/s4cESbNx/CE hOdSk4eglXVW+b7ZxGj8o9Ll0X4Dqy9WFCAROZ5VDBaf9SuvxYJCxkV/BmZ7jCdnz3ls Wj5xL4w+lWI4eYCoZK8IUjOrtm/Tj7QbWVnbLKrTKfxLjiZb8tuDkCVowoJ7+ONX9dlX OBCGV4SGVd+du877jxmsuoeNWTGm8eNhqmEHksJ50bnDFzNYK0Ny39B1H8HUqwMfZmuh 0fvvCRKIHQJCeCo5O69uYm9fMB1FvWp7+VxMnAWB9zFL5zOZwx2hWMv2/eGLTlcY2a6Z tj4w== X-Gm-Message-State: AGRZ1gJr5h4msvidKNYGBHlx3JTScEUdv5WzCT3O70tXLNAM3QLcloq+ w76fBsxgTv6Voexx6jDW4/NquRJy X-Google-Smtp-Source: AJdET5dH6o78vuXiTSRYpQxiNlPoYSzZPXWv51qiN1QGVAsyC8o6rXsuXvwQz9Nv6KEHIP8s6Zbrrw== X-Received: by 2002:a37:8006:: with SMTP id b6-v6mr913971qkd.178.1540950011255; Tue, 30 Oct 2018 18:40:11 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 24-v6sm21670104qts.19.2018.10.30.18.40.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:10 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:09 -0500 Message-Id: <20181031013821.24023-13-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::72e Subject: [Qemu-devel] [PULL v2 12/24] qga-win: report disk serial number 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Signed-off-by: Tomáš Golembiovský *coding style fix-ups (declarations at beginning of block) *improve readability for user-visible errors *cover additional edge-cases with debug statements Signed-off-by: Michael Roth --- qga/commands-win32.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 1e91aa2343..2d7b56d538 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -634,6 +634,36 @@ static void get_disk_properties(HANDLE vol_h, GuestDiskAddress *disk, disk->bus_type = find_bus_type(dev_desc->BusType); g_debug("bus type %d", disk->bus_type); + /* Query once more. Now with long enough buffer. */ + size = dev_desc->Size; + dev_desc = g_malloc0(size); + if (!DeviceIoControl(vol_h, IOCTL_STORAGE_QUERY_PROPERTY, &query, + sizeof(STORAGE_PROPERTY_QUERY), dev_desc, + size, &received, NULL)) { + error_setg_win32(errp, GetLastError(), "failed to get serial number"); + g_debug("failed to get serial number"); + goto out_free; + } + if (dev_desc->SerialNumberOffset > 0) { + const char *serial; + size_t len; + + if (dev_desc->SerialNumberOffset >= received) { + error_setg(errp, "failed to get serial number: offset outside the buffer"); + g_debug("serial number offset outside the buffer"); + goto out_free; + } + serial = (char *)dev_desc + dev_desc->SerialNumberOffset; + len = received - dev_desc->SerialNumberOffset; + g_debug("serial number \"%s\"", serial); + if (*serial != 0) { + disk->serial = g_strndup(serial, len); + disk->has_serial = true; + } + } +out_free: + g_free(dev_desc); + return; } From patchwork Wed Oct 31 01:38:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1A8913B5 for ; Wed, 31 Oct 2018 01:41:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE44F28AA1 for ; Wed, 31 Oct 2018 01:41:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B17B3293C5; Wed, 31 Oct 2018 01:41:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 308C828AA1 for ; Wed, 31 Oct 2018 01:41:50 +0000 (UTC) Received: from localhost ([::1]:56589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfW1-0001TQ-Qk for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:41:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUc-0000JD-45 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUY-00023o-0i for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:22 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:37478) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUX-000217-Ms for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:17 -0400 Received: by mail-qk1-x72f.google.com with SMTP id 131so8583501qkd.4 for ; Tue, 30 Oct 2018 18:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NVXUYNeDrhjdeO57CII9mlPqqLk8udmn1Njwjh+9JQY=; b=Wy7nQLKUB5zOKOatUtVxl9Aa0Yox0pkyBl2bQLFlSztIL4YHTyd/cGxD3XT29RB3hv UhnPGDa8lfIqr7dnVeT9o1zM2CmFcZ0bTHGg3p9NHJPEu1oGDfoEB0YzKdi+gegw+BDU +D8PUvFf5mc90ZsszreOkcT8bcu3sqE7+FUaekDKPiiaVg2uKFczP340rHoLUOf/NIr/ /BUW+Tj70pg3QHjGFyZLqnYfQP3jmGxZJQ7DvPiyOBnI81qs/vUAyn/JuxIsQzpVEJjx sI4iT5+Ts2HbSpAgYyN7hwF3+r772s7pguxAH98Bg6AGXU12lBPYDF3zLt+OYXh0i9Zb UT9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NVXUYNeDrhjdeO57CII9mlPqqLk8udmn1Njwjh+9JQY=; b=VmjbA1Nf/6VonuIZnSU9pIJhmxGhMflYWtDQuCCF+pQ8P2gHkIX6O/X1P81tyXVUmQ tdIdKhEK0GtDCxNfO8DtWhgaJVtW599GsVavZ7vSDvdMp4lqYih6+nmbb8uC8MYmCG5J WtjuWUpGa0BC0wv9NdHFijZLyqRH5GY3LmnemJMQ5BEnVyfZVDL49k71xaNVT44/cMFL VuGif4Lh/bxuHEKcXoj4azRfV833XyBvYrHvg+Jji4Yp+pZz6aVGxgDr35YSoByGxQ0B 1aJunIALGsWa6PN+KXHFsVTGGiLbdGhQjuxCmQKH0EC5CB85gRo9wFv/jZ3pq/0QHzQ/ SmwQ== X-Gm-Message-State: AGRZ1gI1aENp8jCuUhiHs28nGYGFh+1mMkh+PLmMhy7GLYMlHuGaxIsy DUNSPVErvmy7OjEV19JdUq6yZK4y X-Google-Smtp-Source: AJdET5cnbp0PuBsi2px6waD4S5wn+T9mzP+5Zgr+8asPBOg5uqBQtXnoioG6DrxAO8yxXLLdFtrTsw== X-Received: by 2002:a37:7041:: with SMTP id l62-v6mr906522qkc.294.1540950014016; Tue, 30 Oct 2018 18:40:14 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id o27sm5750025qkh.35.2018.10.30.18.40.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:12 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:10 -0500 Message-Id: <20181031013821.24023-14-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::72f Subject: [Qemu-devel] [PULL v2 13/24] qga-win: refactor disk info 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Refactor building of disk info into a function that builds the list and a function that returns infor for single disk. This will be used in future commit that will handle multi-disk volumes. Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/commands-win32.c | 52 +++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 2d7b56d538..21a88d31e1 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -667,20 +667,15 @@ out_free: return; } -/* VSS provider works with volumes, thus there is no difference if - * the volume consist of spanned disks. Info about the first disk in the - * volume is returned for the spanned disk group (LVM) */ -static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) +static void get_single_disk_info(char *name, GuestDiskAddress *disk, + Error **errp) { - GuestDiskAddressList *list = NULL; - GuestDiskAddress *disk; SCSI_ADDRESS addr, *scsi_ad; DWORD len; HANDLE vol_h; Error *local_err = NULL; scsi_ad = &addr; - char *name = g_strndup(guid, strlen(guid)-1); g_debug("getting disk info for: %s", name); vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, @@ -690,7 +685,6 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) goto err; } - disk = g_malloc0(sizeof(*disk)); get_disk_properties(vol_h, disk, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -730,20 +724,44 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) * information about volume. */ } - list = g_malloc0(sizeof(*list)); - list->value = disk; - list->next = NULL; - CloseHandle(vol_h); - g_free(name); - return list; - err_close: - g_free(disk); CloseHandle(vol_h); err: + return; +} + +/* VSS provider works with volumes, thus there is no difference if + * the volume consist of spanned disks. Info about the first disk in the + * volume is returned for the spanned disk group (LVM) */ +static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) +{ + Error *local_err = NULL; + GuestDiskAddressList *list = NULL, *cur_item = NULL; + GuestDiskAddress *disk = NULL; + + /* strip final backslash */ + char *name = g_strdup(guid); + if (g_str_has_suffix(name, "\\")) { + name[strlen(name) - 1] = 0; + } + + disk = g_malloc0(sizeof(GuestDiskAddress)); + get_single_disk_info(name, disk, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + + cur_item = g_malloc0(sizeof(*list)); + cur_item->value = disk; + disk = NULL; + list = cur_item; + +out: + qapi_free_GuestDiskAddress(disk); g_free(name); - return NULL; + return list; } #else From patchwork Wed Oct 31 01:38:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9365413BF for ; Wed, 31 Oct 2018 01:47:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81E462AC2F for ; Wed, 31 Oct 2018 01:47:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75B002AC47; Wed, 31 Oct 2018 01:47:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CAB7E2AC2F for ; Wed, 31 Oct 2018 01:47:40 +0000 (UTC) Received: from localhost ([::1]:56621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfbg-0007Wl-45 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:47:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUc-0000JI-58 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUY-000253-PX for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:22 -0400 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]:34669) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUY-00023u-HA for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:18 -0400 Received: by mail-qt1-x833.google.com with SMTP id z2-v6so16022371qts.1 for ; Tue, 30 Oct 2018 18:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q4qvYUHQbKVfk7EWyk8ZHhYnBemb39mILFxX0uRYWYU=; b=l2dBUQV82P21jkw+vQd01DrAF1b7Sfv5Fg3mMtAcGFXfaPbRfwLjY2xliaBFvrD66N YYQhuYBvt/K5ur0LezNWgfftbgItUV9ZmY9yYXTkOPTmVZ3dfv/8kVxxiWKFghNmQzKk /io+lLvwkks910vJGTaXQqDrzt46IiACtVW5nOI3RNY/8TJs1YU+kAjVtWt5DtPvnLQD drtGpecJZ1NES1u5cTyMfvW+xFSjVHlf68BYUqQME69ti3fCgGnCKh9seyna1ZjUT8qd 8Nmrz3TfjzG6V+S6FFnF2YMy6v5F9BS4QZFvTqHuhzIhgpilNc0nYL5GN/PlzSdXmMnc hwJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=q4qvYUHQbKVfk7EWyk8ZHhYnBemb39mILFxX0uRYWYU=; b=iC5JuLlkyq9Qtg3+/fT/Ap/MlraeyZleqIZM5F9iCXbzHGQju++hb0dFeGOnli4gPg j86YwCE1K/BeNe5eLCheElj+9cTJcFb0/WYXjW+3o8k6uz5ULdlOXD1RFSMRK2hLj5gl BOuF+3SBzRk2j27ze+EFyp2+yNqNQBu1KFhMphFqfqB0V7KySSsM9AMgoodQuFUcZdHB zxLB/Y/AqAaK91NGHvLZ7KekFpWCoCJjCztSal1PlVgqLAggMn3QGlLeaVBB9VUUmPcH jKPABurZc/dxtHYAXT4EGpexEQtW2drf5mJPxR2JAJCzTWU6xVFGuo5OhATnJzX6hzxv 4RPQ== X-Gm-Message-State: AGRZ1gKZrjcasuc/+r5noYsG29BYdtCCeIqD+dBEzNp6x30l6NmfOuAV /hrADXquQwSw9Yug32yLOVlqjupe X-Google-Smtp-Source: AJdET5e0rykzt9iGoIQMBixtEzC5nc9Mu472LHRktE55I4v5j2VoPS8aO0Ok5GZS49oCoC0dLBXjnw== X-Received: by 2002:aed:3165:: with SMTP id 92-v6mr962927qtg.72.1540950016916; Tue, 30 Oct 2018 18:40:16 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id m124-v6sm14876445qkd.19.2018.10.30.18.40.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:15 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:11 -0500 Message-Id: <20181031013821.24023-15-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::833 Subject: [Qemu-devel] [PULL v2 14/24] qga-win: handle multi-disk volumes 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Probe the volume for disk extents and return list of all disks. Originally only first disk of composite volume was returned. Note that the patch changes get_pci_info() from one state of brokenness into a different state of brokenness. In other words it still does not do what it's supposed to do (see comment in code). If anyone knows how to fix it, please step in. Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/commands-win32.c | 126 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 108 insertions(+), 18 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 21a88d31e1..90432bbfce 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -491,9 +491,26 @@ static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE bus) return win2qemu[(int)bus]; } +/* XXX: The following function is BROKEN! + * + * It does not work and probably has never worked. When we query for list of + * disks we get cryptic names like "\Device\0000001d" instead of + * "\PhysicalDriveX" or "\HarddiskX". Whether the names can be translated one + * way or the other for comparison is an open question. + * + * When we query volume names (the original version) we are able to match those + * but then the property queries report error "Invalid function". (duh!) + */ + +/* DEFINE_GUID(GUID_DEVINTERFACE_VOLUME, 0x53f5630dL, 0xb6bf, 0x11d0, 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b); +*/ +DEFINE_GUID(GUID_DEVINTERFACE_DISK, + 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2, + 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b); + static GuestPCIAddress *get_pci_info(char *guid, Error **errp) { @@ -517,7 +534,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) goto out; } - dev_info = SetupDiGetClassDevs(&GUID_DEVINTERFACE_VOLUME, 0, 0, + dev_info = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (dev_info == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to get devices tree"); @@ -672,20 +689,20 @@ static void get_single_disk_info(char *name, GuestDiskAddress *disk, { SCSI_ADDRESS addr, *scsi_ad; DWORD len; - HANDLE vol_h; + HANDLE disk_h; Error *local_err = NULL; scsi_ad = &addr; g_debug("getting disk info for: %s", name); - vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + disk_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - if (vol_h == INVALID_HANDLE_VALUE) { - error_setg_win32(errp, GetLastError(), "failed to open volume"); - goto err; + if (disk_h == INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to open disk"); + return; } - get_disk_properties(vol_h, disk, &local_err); + get_disk_properties(disk_h, disk, &local_err); if (local_err) { error_propagate(errp, local_err); goto err_close; @@ -714,7 +731,7 @@ static void get_single_disk_info(char *name, GuestDiskAddress *disk, * according to Microsoft docs * https://technet.microsoft.com/en-us/library/ee851589(v=ws.10).aspx */ g_debug("getting pci-controller info"); - if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_ad, + if (DeviceIoControl(disk_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_ad, sizeof(SCSI_ADDRESS), &len, NULL)) { disk->unit = addr.Lun; disk->target = addr.TargetId; @@ -725,8 +742,7 @@ static void get_single_disk_info(char *name, GuestDiskAddress *disk, } err_close: - CloseHandle(vol_h); -err: + CloseHandle(disk_h); return; } @@ -738,6 +754,10 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) Error *local_err = NULL; GuestDiskAddressList *list = NULL, *cur_item = NULL; GuestDiskAddress *disk = NULL; + int i; + HANDLE vol_h; + DWORD size; + PVOLUME_DISK_EXTENTS extents = NULL; /* strip final backslash */ char *name = g_strdup(guid); @@ -745,20 +765,90 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) name[strlen(name) - 1] = 0; } - disk = g_malloc0(sizeof(GuestDiskAddress)); - get_single_disk_info(name, disk, &local_err); - if (local_err) { - error_propagate(errp, local_err); + g_debug("opening %s", name); + vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + 0, NULL); + if (vol_h == INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to open volume"); goto out; } - cur_item = g_malloc0(sizeof(*list)); - cur_item->value = disk; - disk = NULL; - list = cur_item; + /* Get list of extents */ + g_debug("getting disk extents"); + size = sizeof(VOLUME_DISK_EXTENTS); + extents = g_malloc0(size); + if (!DeviceIoControl(vol_h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, + 0, extents, size, NULL, NULL)) { + DWORD last_err = GetLastError(); + if (last_err == ERROR_MORE_DATA) { + /* Try once more with big enough buffer */ + size = sizeof(VOLUME_DISK_EXTENTS) + + extents->NumberOfDiskExtents*sizeof(DISK_EXTENT); + g_free(extents); + extents = g_malloc0(size); + if (!DeviceIoControl( + vol_h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, + 0, extents, size, NULL, NULL)) { + error_setg_win32(errp, GetLastError(), + "failed to get disk extents"); + return NULL; + } + } else if (last_err == ERROR_INVALID_FUNCTION) { + /* Possibly CD-ROM or a shared drive. Try to pass the volume */ + g_debug("volume not on disk"); + disk = g_malloc0(sizeof(GuestDiskAddress)); + get_single_disk_info(name, disk, &local_err); + if (local_err) { + g_debug("failed to get disk info, ignoring error: %s", + error_get_pretty(local_err)); + error_free(local_err); + goto out; + } + list = g_malloc0(sizeof(*list)); + list->value = disk; + disk = NULL; + list->next = NULL; + goto out; + } else { + error_setg_win32(errp, GetLastError(), + "failed to get disk extents"); + goto out; + } + } + g_debug("Number of extents: %lu", extents->NumberOfDiskExtents); + + /* Go through each extent */ + for (i = 0; i < extents->NumberOfDiskExtents; i++) { + char *disk_name = NULL; + disk = g_malloc0(sizeof(GuestDiskAddress)); + + /* Disk numbers directly correspond to numbers used in UNCs + * + * See documentation for DISK_EXTENT: + * https://docs.microsoft.com/en-us/windows/desktop/api/winioctl/ns-winioctl-_disk_extent + * + * See also Naming Files, Paths and Namespaces: + * https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#win32-device-namespaces + */ + disk_name = g_strdup_printf("\\\\.\\PhysicalDrive%lu", + extents->Extents[i].DiskNumber); + get_single_disk_info(disk_name, disk, &local_err); + g_free(disk_name); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + cur_item = g_malloc0(sizeof(*list)); + cur_item->value = disk; + disk = NULL; + cur_item->next = list; + list = cur_item; + } + out: qapi_free_GuestDiskAddress(disk); + g_free(extents); g_free(name); return list; From patchwork Wed Oct 31 01:38:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4967013BF for ; Wed, 31 Oct 2018 01:50:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3927F2A83A for ; Wed, 31 Oct 2018 01:50:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DB522A8A8; Wed, 31 Oct 2018 01:50:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE3012A83A for ; Wed, 31 Oct 2018 01:50:14 +0000 (UTC) Received: from localhost ([::1]:56636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfeA-0001Qv-17 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:50:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUg-0000Mc-Pt for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUb-00026L-5O for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:24 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:33439) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUa-000267-WF for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:21 -0400 Received: by mail-qt1-x831.google.com with SMTP id i15-v6so16012861qtr.0 for ; Tue, 30 Oct 2018 18:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V4QuD/SdmHm1xhwRyGU/67Fuszx4RPOvYIaCUYitays=; b=kaNfjQVg4Kp1ehNHWgH1U5U5DSVCKMTVHcEZQHrIlbGOmYuyDcDznOn8VGsWBgbG+b 8UcPtQX1OPjyTrQ/pR7TKfN8hjMsXw7AMH5NKaUTdaekgj59mTirWz9gMn05lb0oJi4b j9O3QtYxRw+JJkAPpgx9rmvXyi9kxFpv4JxqS7KldJ2h5LVrOB+cBdLwCUrAPK7HQq3/ fBBvtuW8yQsBoHiDikwZkwW0F4LHnnhLK3CTwD+KG7zISnqDC9UgZqQ5KV/0iiuRUBDw CDIcTelXzDjRVvES1DnQxFYLwAFCa1T16P42rEEwJGKGokU+IGwIYa+32HsfMaylDyTS Aq6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=V4QuD/SdmHm1xhwRyGU/67Fuszx4RPOvYIaCUYitays=; b=ORyGta8n4/m+tBAkJMd92fspL5etjqdJ7hcl9uayWP4KaV9pAUCYPAmKxPNgLMr52h 8Swaz7KtGT7WAgr2R2tIMwb/rzQCdinaRt6UZT+87srNScahzJ1xPhwhNOHqNWj6g4xW gu60i27fLLrbZ8gShfJPHQv/4Ix3gfZ57eTccQhF0Ut8Ye9J2kC+XxTofn5+/8hiqEbu oBOsK/OkEX0bZmvhRRxtGSE7S44B1Da3SECEf9d8qdiUi+QicAwCx5j6GNBNzUnpBBnJ //fHeFleU0ndD7phb5Rkm1mjubN2MRf1bzTSmCDTVzXHuSB+3fMeS8akMj1I7FoBX6KP QH7w== X-Gm-Message-State: AGRZ1gLNCQqOrf5OmmHwgV/nwVYSYPLDXI/raRDtaML2DjdbvSq/xmKb sq2mL33Mjfpm48lzf6YwZjLcW9hy X-Google-Smtp-Source: AJdET5cgTrJUV/IxcxUzecGo4YPAun/CbqM3KKHPOOsh1RyntM19e+EnyrVZgMATjowR1e1uCL3vyA== X-Received: by 2002:ac8:36d9:: with SMTP id b25mr987650qtc.49.1540950019757; Tue, 30 Oct 2018 18:40:19 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id d20-v6sm1805231qtm.49.2018.10.30.18.40.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:18 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:12 -0500 Message-Id: <20181031013821.24023-16-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::831 Subject: [Qemu-devel] [PULL v2 15/24] qga-win: return disk device in guest-get-fsinfo 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský Report device UNC of the disk. It is reported as "\\.\PhysicalDriveX". Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/commands-win32.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 90432bbfce..30d6c639c3 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -684,8 +684,7 @@ out_free: return; } -static void get_single_disk_info(char *name, GuestDiskAddress *disk, - Error **errp) +static void get_single_disk_info(GuestDiskAddress *disk, Error **errp) { SCSI_ADDRESS addr, *scsi_ad; DWORD len; @@ -694,8 +693,8 @@ static void get_single_disk_info(char *name, GuestDiskAddress *disk, scsi_ad = &addr; - g_debug("getting disk info for: %s", name); - disk_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + g_debug("getting disk info for: %s", disk->dev); + disk_h = CreateFile(disk->dev, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (disk_h == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open disk"); @@ -714,7 +713,7 @@ static void get_single_disk_info(char *name, GuestDiskAddress *disk, * if that doesn't hold since that suggests some other unexpected * breakage */ - disk->pci_controller = get_pci_info(name, &local_err); + disk->pci_controller = get_pci_info(disk->dev, &local_err); if (local_err) { error_propagate(errp, local_err); goto err_close; @@ -797,7 +796,9 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) /* Possibly CD-ROM or a shared drive. Try to pass the volume */ g_debug("volume not on disk"); disk = g_malloc0(sizeof(GuestDiskAddress)); - get_single_disk_info(name, disk, &local_err); + disk->has_dev = true; + disk->dev = g_strdup(name); + get_single_disk_info(disk, &local_err); if (local_err) { g_debug("failed to get disk info, ignoring error: %s", error_get_pretty(local_err)); @@ -819,7 +820,6 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) /* Go through each extent */ for (i = 0; i < extents->NumberOfDiskExtents; i++) { - char *disk_name = NULL; disk = g_malloc0(sizeof(GuestDiskAddress)); /* Disk numbers directly correspond to numbers used in UNCs @@ -830,10 +830,11 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) * See also Naming Files, Paths and Namespaces: * https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#win32-device-namespaces */ - disk_name = g_strdup_printf("\\\\.\\PhysicalDrive%lu", + disk->has_dev = true; + disk->dev = g_strdup_printf("\\\\.\\PhysicalDrive%lu", extents->Extents[i].DiskNumber); - get_single_disk_info(disk_name, disk, &local_err); - g_free(disk_name); + + get_single_disk_info(disk, &local_err); if (local_err) { error_propagate(errp, local_err); goto out; From patchwork Wed Oct 31 01:38:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AD461751 for ; Wed, 31 Oct 2018 01:52:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B0E62A925 for ; Wed, 31 Oct 2018 01:52:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F9532A9AE; Wed, 31 Oct 2018 01:52:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 048E02A925 for ; Wed, 31 Oct 2018 01:52:45 +0000 (UTC) Received: from localhost ([::1]:56648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfga-0004Hm-At for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:52:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUu-0000YP-DT for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUt-0002IS-EW for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:40 -0400 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:43411) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUt-00028B-5h for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:39 -0400 Received: by mail-qt1-x82b.google.com with SMTP id q41-v6so15954314qtq.10 for ; Tue, 30 Oct 2018 18:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=reWrzN1nbgrUa5M9CT6ngaBhfrzDoBBYAKpSG9utug0=; b=f+K9lcH5HelSTND1Sd9pwRDpKdi1V9PVYrAlYMfjmH57C+zO+NlZO6tk+HhXhHYV/6 0mecBTxs8D01N2QDsN29avGZQLa1wjV45LG3646QxyHqLaTQVHSGb4QELDhXSkpcGpi4 e1eImgzMTKk10kXoUZJ2UmcPY8eRYVxBvdBp/CITZ+8+laTDCagP0poELfU5R4UxD1s0 00v3dEnbOvDjryoRqcqaRpzLVlRakaJKwcjo2Iz+Gsuu8yMM5dsTrbibs8JfXPSgS7SK 0JolrO7bqNuRxz9BoirABC6nnYMj4fIfgLYKzf178f8y/fYRzp8PSTZ8G2UqswwIzU5T bE5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=reWrzN1nbgrUa5M9CT6ngaBhfrzDoBBYAKpSG9utug0=; b=VbGHWUwKT/z0kAkuIVM9y82+avSnAFaxUr9gKN2NZU8p2C4bOLNd8ml2HKoe392+a3 lLbYlFaC4mo7411QnUYRXimEO7I29suRLqYyMcHEiv/D3BWsRnM84/qMCCoeR4TGUSZq gJ6qk1jFKi1jgjd84qfPrZVeOQDDVz8aVRm5YGAjJBGvVVrpmR/AQ6gfuCKfICub/dzB tdAG4m4Gpl4x31iojrmD6pmdp59n7nD0T5yQJJeO0cD9Rdc9/x2oDR2SrBAw5N6NWTry O9I3KBxYes+ENNMIzBtSlfjdInx4ZQS7aaUUbBZhC0B+4Fu4/VA5J1GnXdlfT6StGdpF 9PPQ== X-Gm-Message-State: AGRZ1gJwhxE10bVBTdpABFCn691V98HMcP0yWwLkiWeIgAgsT85fC7hg BT+MKHbguQEuYDI528qvZnWzMoo8 X-Google-Smtp-Source: AJdET5ddub6Ov80O3hqwa1X0rwMJaCCfJphTLyK+BrxpcmFVincvWwAjZqWUyS8NDFQNjDKdyJ/tbg== X-Received: by 2002:ac8:2e44:: with SMTP id s4mr961726qta.355.1540950022864; Tue, 30 Oct 2018 18:40:22 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id m21-v6sm2933222qtq.15.2018.10.30.18.40.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:21 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:13 -0500 Message-Id: <20181031013821.24023-17-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82b Subject: [Qemu-devel] [PULL v2 16/24] qga-win: demystify namespace stripping 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: peter.maydell@linaro.org, =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tomáš Golembiovský It was not obvious what exactly the cryptic string copying does to the GUID. This change makes the intent clearer. Signed-off-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/commands-win32.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 30d6c639c3..a1b7512d46 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -521,7 +521,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) char dev_name[MAX_PATH]; char *buffer = NULL; GuestPCIAddress *pci = NULL; - char *name = g_strdup(&guid[4]); + char *name = NULL; bool partial_pci = false; pci = g_malloc0(sizeof(*pci)); pci->domain = -1; @@ -529,6 +529,13 @@ static GuestPCIAddress *get_pci_info(char *guid, Error **errp) pci->function = -1; pci->bus = -1; + if (g_str_has_prefix(guid, "\\\\.\\") || + g_str_has_prefix(guid, "\\\\?\\")) { + name = g_strdup(guid + 4); + } else { + name = g_strdup(guid); + } + if (!QueryDosDevice(name, dev_name, ARRAY_SIZE(dev_name))) { error_setg_win32(errp, GetLastError(), "failed to get dos device name"); goto out; From patchwork Wed Oct 31 01:38:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF83913BF for ; Wed, 31 Oct 2018 01:47:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EBCF2AC2F for ; Wed, 31 Oct 2018 01:47:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 919F82AC47; Wed, 31 Oct 2018 01:47:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3CB352AC2F for ; Wed, 31 Oct 2018 01:47:37 +0000 (UTC) Received: from localhost ([::1]:56620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfbc-0007T3-6C for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:47:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUs-0000YI-Ha for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUp-0002GF-OX for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:38 -0400 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]:42446) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUo-0002BT-7t for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:34 -0400 Received: by mail-qt1-x832.google.com with SMTP id z20-v6so15959556qti.9 for ; Tue, 30 Oct 2018 18:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hV7f/126Dfw1LuCXzTvvDVsft6NVkBl1N3OPxeFvDMY=; b=bBSoU+np53d+iIddavD9B5mL1qFlfd5birk+myxhxMWqIgY8IjFIBbBAlIaAhDqVXu rVLsmUJ5mKi3S4xkpwiFHohPc8YfvHJiQs6OMRtOwmLxD0hGNp5KZO9kK41ziXkzr2DB 79kYOA2nQQvZ+DeJ8/qGvvfIqzawLMKaVsUTh+gz8VVbuX7K44ifHcdMVxddCjqMrAmw S2Xd1go6ocKxhklIRT5S6DDQUhn98tO3stD1LhrQrkjJMvRM9g439ypH4afTvhoxqYUB 2M9X1tF8/6F+iVIgUbfmAWyNNwOpeaAQOuOZVTSqbeIQ0DZUjv57fiXvNfVIQg5oN8Og E2TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=hV7f/126Dfw1LuCXzTvvDVsft6NVkBl1N3OPxeFvDMY=; b=dLxWcJfFwt6hpSspg3HFprnOnPIZkbx7WPi8RCkQ1JMfybsG9x4S+XoYEPrg8C81mP Fi+gMSDXIl/JVpfyW0ydiQ6t+ni9Z8gAX7PGtW1fq7VqM9gir5HJua2J0tzfEuc2p1ZV NzACRT3K4cFS3eRw9x2IKBczKu8XD3sz2uplOx6nMmsRZU2Xwl0bWdlXa+PfNFR6Us5T 5XBB9d/+mlxXhFuHJ2K5x0G+jAnxoQ9Fg6a3hZ7ivi+O4nIGHDlHR3H806GLCpAPlDsx COTk1HUwpI8J7iTM1pHV1jdPND9wsPZNccfa0mO4e1BU5ahnIlODsjX+JvZBMtfPxXGy 9F+g== X-Gm-Message-State: AGRZ1gIKSfsF1B97B33Rfek0bZZzKJR4fxWaotF85yuOYHDeYGazEbsm /m5J9rCnmLryod7qZTjkAl7tIiw5 X-Google-Smtp-Source: AJdET5f1GnnFxF97Y4PzwMS6GWECoqdzasXqHJCUWY7pWcxH7hjhhnYG5RD7TwGbtS388o+UbASs6g== X-Received: by 2002:ac8:f10:: with SMTP id e16-v6mr1004751qtk.262.1540950025869; Tue, 30 Oct 2018 18:40:25 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id z196sm12075942qkz.37.2018.10.30.18.40.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:24 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:14 -0500 Message-Id: <20181031013821.24023-18-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::832 Subject: [Qemu-devel] [PULL v2 17/24] qga: fix an off-by-one issue 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: peter.maydell@linaro.org, Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Li Qiang Signed-off-by: Li Qiang Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Michael Roth --- qga/commands-win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index a1b7512d46..ef1d7d48d2 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -485,7 +485,7 @@ static STORAGE_BUS_TYPE win2qemu[] = { static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE bus) { - if (bus > ARRAY_SIZE(win2qemu) || (int)bus < 0) { + if (bus >= ARRAY_SIZE(win2qemu) || (int)bus < 0) { return GUEST_DISK_BUS_TYPE_UNKNOWN; } return win2qemu[(int)bus]; From patchwork Wed Oct 31 01:38:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB4E513BF for ; Wed, 31 Oct 2018 01:45:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A8DD2AC2F for ; Wed, 31 Oct 2018 01:45:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EF272AC47; Wed, 31 Oct 2018 01:45:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0A3752AC2F for ; Wed, 31 Oct 2018 01:45:57 +0000 (UTC) Received: from localhost ([::1]:56610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfa1-0006GB-3u for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:45:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUs-0000YJ-Il for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUn-0002Ev-Ez for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:38 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:39087) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUm-0002D2-ME for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:33 -0400 Received: by mail-qt1-x82f.google.com with SMTP id g10-v6so15970012qtq.6 for ; Tue, 30 Oct 2018 18:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tXnxRiw5dgfWTyLrIDra9WPBMKy8b+BOWuJZw8waj94=; b=TLp+sSSjHoXtBvUg1r0PLIU1gIzW0UibpBnDD/LZPUHLxWLiAsrIJlkAMYOit52H2H RJ4ENGvi9/Dm/ahx2jgrfnSZOmMfu4VHTMs/sTgX4ES9UoKQCJoHYlY1p1qrxsMKRKYE b4qJpnWFse5mnLYJe505/cl50Ktgb44yMPbex+36wACe4gzs7+6q3P2Tuty+x1V089AU 4ipKMttlwxPxSLt9V0RmeIEjSjRfbE9EE1M4vnqpzJgD0cXrLkZI7+CRtX9ioNsJyUca t6qMYejS56wvUFFrEoK8vV5+P3baTNo1enlsFJXEvA+LYe90ORf4IDIosuinBQAnthvJ RrVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=tXnxRiw5dgfWTyLrIDra9WPBMKy8b+BOWuJZw8waj94=; b=NBmh/VTyD4T/W6blIzMRWgIxWoLop9yfk6xpMsMnZZ+Gd7sc3sl3wvLK6AXoQaFEF9 BcVzGkjmnanXOoqOYlvoTn0Oo9TGL6CB2SE0apf0A8wP1TMz9UszE6V2X4ykmeplcnZQ 2v46LyVTYdN8V0v3rAR9pXx4tN3XpQyKHnjm9auNMjnt7IXd+HZaq/zl4XEQZjQEmSRA 9XsWWIRET7frp5/1YDGmGtD2r0M+5H/nYVq03/h0j3oKL55tAxnACVXEtXuhbc4aIfbf xxbwAgGLnA0F7kEJrmlbDzd1ZtZE6QPnRwJqJFCFN/sceJ+2aCsFDbaLYXJ7SJ40ZsPW 5bbA== X-Gm-Message-State: AGRZ1gKJiU+kKzxfTWJM46EZzdB7hUisaRVJNHZs7dg51SdNXu+Eac3o /o49Jn4J21GvqvIbCm7kmkJntL/r X-Google-Smtp-Source: AJdET5dXaLUgpz36D0/EcGZYYFVLnsumTthybWATb9iqjQjhwpzEppD/EDRQLho7fBofMGWRXYLlGA== X-Received: by 2002:a0c:fa8f:: with SMTP id o15mr969873qvn.135.1540950028894; Tue, 30 Oct 2018 18:40:28 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id g80sm1059483qkh.41.2018.10.30.18.40.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:27 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:15 -0500 Message-Id: <20181031013821.24023-19-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82f Subject: [Qemu-devel] [PULL v2 18/24] 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Marc-André Lureau 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 afcd268ee3..ab3eaa5163 100644 --- a/qga/main.c +++ b/qga/main.c @@ -1211,9 +1211,21 @@ static bool check_is_frozen(GAState *s) return false; } -static int run_agent(GAState *s, GAConfig *config, int socket_activation) +static GAState *initialize_agent(GAConfig *config) { - ga_state = s; + GAState *s = g_new0(GAState, 1); + + g_assert(ga_state == NULL); + + s->log_level = config->log_level; + s->log_file = stderr; +#ifdef CONFIG_FSFREEZE + s->fsfreeze_hook = config->fsfreeze_hook; +#endif + s->pstate_filepath = g_strdup_printf("%s/qga.state", config->state_dir); + s->state_filepath_isfrozen = g_strdup_printf("%s/qga.state.isfrozen", + config->state_dir); + s->frozen = check_is_frozen(s); 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, int socket_activation) if (g_mkdir_with_parents(config->state_dir, S_IRWXU) == -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 @@ -1254,7 +1266,7 @@ static int run_agent(GAState *s, GAConfig *config, int socket_activation) if (!log_file) { g_critical("unable to open specified log file: %s", strerror(errno)); - return EXIT_FAILURE; + return NULL; } s->log_file = log_file; } @@ -1265,7 +1277,7 @@ static int run_agent(GAState *s, GAConfig *config, int socket_activation) s->pstate_filepath, ga_is_frozen(s))) { g_critical("failed to load persistent state"); - return EXIT_FAILURE; + return NULL; } config->blacklist = 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 s->main_loop = g_main_loop_new(NULL, false); + ga_state = 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 = 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, int socket_activation) int main(int argc, char **argv) { int ret = EXIT_SUCCESS; - GAState *s = g_new0(GAState, 1); + GAState *s; GAConfig *config = g_new0(GAConfig, 1); int socket_activation; @@ -1383,44 +1420,25 @@ int main(int argc, char **argv) } } - s->log_level = config->log_level; - s->log_file = stderr; -#ifdef CONFIG_FSFREEZE - s->fsfreeze_hook = config->fsfreeze_hook; -#endif - s->pstate_filepath = g_strdup_printf("%s/qga.state", config->state_dir); - s->state_filepath_isfrozen = g_strdup_printf("%s/qga.state.isfrozen", - config->state_dir); - s->frozen = check_is_frozen(s); - if (config->dumpconf) { config_dump(config); goto end; } + s = initialize_agent(config); + if (!s) { + g_critical("error initializing guest agent"); + goto end; + } ret = run_agent(s, config, socket_activation); + cleanup_agent(s); 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); } config_free(config); - if (s->main_loop) { - g_main_loop_unref(s->main_loop); - } - g_free(s); return ret; } From patchwork Wed Oct 31 01:38:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BD2D13B5 for ; Wed, 31 Oct 2018 01:43:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88B9C28AA1 for ; Wed, 31 Oct 2018 01:43:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79F4828EBD; Wed, 31 Oct 2018 01:43:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0E56328AA1 for ; Wed, 31 Oct 2018 01:43:03 +0000 (UTC) Received: from localhost ([::1]:56592 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfXC-0002UH-AS for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:43:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUt-0000YM-B9 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUs-0002HG-8W for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:39 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:35448) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUr-0002EY-BE for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:38 -0400 Received: by mail-qt1-x82d.google.com with SMTP id a10-v6so15979019qtp.2 for ; Tue, 30 Oct 2018 18:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=J2hDdIIMnNOSP+USzHUBuxWsUR55MYaTRzDvre6P60A=; b=J2nAOd5pogfB8B5OnyEentTxuMlPDwMZEkiKEs7EAnpypqpVuHfvUqnBvzLUFuzazM n9iJr5nM9yvjw/kCn3aXaGbPb6kGn1WH8mMI7JmAl55ZQmQoFqrJ0Ph/7ZwuOkaB5X0v Z1zS2/c1iI0qASwsI1oiuXp8KQXiPd3o5I81mNqMAozEkZbIFeL/iQrtBA6P0NMG5C0t 68SDOngY5RHRF3rRsBX6sHDJ+/iaa381oJasff7JkbjI7rSEC5DOy7XgQW7hEVk1Ritk 4/x8ah1NcsGYPH5gBsUdU7odK6mJ5cpVNcsB2l+jarqiq2UReirCGPpJaZVEXKLLniO2 iSSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=J2hDdIIMnNOSP+USzHUBuxWsUR55MYaTRzDvre6P60A=; b=F/fCn9yRZSfWs89URf0pDWgJCW2w8OVa7m4I24f5UA1OcH4W6SZrEU8+fXCEWkMHUz qP/kg8OfGn3wHR5FeLWXJV/Ha6eak5fHmLGMRXamUE3K6eDoxMKNhDJIkxcCl4etb9S2 cJ9BBEgNy9iGHRlISYiVfTz/q/6+5VMSd2vsdSTUzexFv6QwbSTRO/quDw/KhN7rmeBQ l0/x9+RsRIo9Z5f2XLqJs8IFI614fSkei4v6kznNWpZ9jzy1QzSJ6wq5H4yktUHnbRHw B7Y+O3a7afI88dHgRtjCIzC0BlruITKZZVA3n9hatXV6Hs1RSqvbFO3tS5llb6/sOM1c gPHA== X-Gm-Message-State: AGRZ1gK26a1J+4dUCqTNKCM9CQYEVkUYwLAkJkuTprsK3KdqouXnEgvS BIxBVBzYUX+MAdbvbXgntQNJr71F X-Google-Smtp-Source: AJdET5ddsH2YZx1+ahob4hA9gxrbZRTl+VchfZJcJ97RJej9xavhnrWuJMVCZRfA52AJ6nQ1sMFnxg== X-Received: by 2002:aed:36a4:: with SMTP id f33-v6mr966904qtb.367.1540950031529; Tue, 30 Oct 2018 18:40:31 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id v23-v6sm19086056qtv.65.2018.10.30.18.40.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:30 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:16 -0500 Message-Id: <20181031013821.24023-20-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82d Subject: [Qemu-devel] [PULL v2 19/24] 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: peter.maydell@linaro.org, Sameeh Jubran Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 *dont move GAConfig struct, just the typedef *fix build bisect for w32 Signed-off-by: Michael Roth --- qga/main.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/qga/main.c b/qga/main.c index ab3eaa5163..eb31f99b38 100644 --- a/qga/main.c +++ b/qga/main.c @@ -69,6 +69,8 @@ typedef struct GAPersistentState { int64_t fd_counter; } GAPersistentState; +typedef struct GAConfig GAConfig; + struct GAState { JSONMessageParser parser; GMainLoop *main_loop; @@ -94,6 +96,8 @@ struct GAState { #endif gchar *pstate_filepath; GAPersistentState pstate; + GAConfig *config; + int socket_activation; }; struct GAState *ga_state; @@ -905,7 +909,7 @@ static GList *split_list(const gchar *str, const gchar *delim) return list; } -typedef struct GAConfig { +struct GAConfig { char *channel_path; char *method; char *log_filepath; @@ -922,7 +926,7 @@ typedef struct GAConfig { int daemonize; GLogLevelFlags log_level; int dumpconf; -} GAConfig; +}; static void config_load(GAConfig *config) { @@ -1211,7 +1215,7 @@ static bool check_is_frozen(GAState *s) return false; } -static GAState *initialize_agent(GAConfig *config) +static GAState *initialize_agent(GAConfig *config, int socket_activation) { GAState *s = g_new0(GAState, 1); @@ -1304,6 +1308,8 @@ static GAState *initialize_agent(GAConfig *config) s->main_loop = g_main_loop_new(NULL, false); + s->config = config; + s->socket_activation = socket_activation; ga_state = s; return s; } @@ -1327,17 +1333,17 @@ static void cleanup_agent(GAState *s) ga_state = NULL; } -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; } #ifndef _WIN32 g_main_loop_run(ga_state->main_loop); #else - if (config->daemonize) { + if (s->config->daemonize) { SERVICE_TABLE_ENTRY service_table[] = { { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; StartServiceCtrlDispatcher(service_table); @@ -1425,12 +1431,12 @@ int main(int argc, char **argv) goto end; } - s = initialize_agent(config); + s = initialize_agent(config, socket_activation); if (!s) { g_critical("error initializing guest agent"); goto end; } - ret = run_agent(s, config, socket_activation); + ret = run_agent(s); cleanup_agent(s); end: From patchwork Wed Oct 31 01:38:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61B6F14E2 for ; Wed, 31 Oct 2018 01:50:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D96D2A83A for ; Wed, 31 Oct 2018 01:50:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BFE82A8A8; Wed, 31 Oct 2018 01:50:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CDB722A83A for ; Wed, 31 Oct 2018 01:50:11 +0000 (UTC) Received: from localhost ([::1]:56634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfe7-0001Lp-5M for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:50:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUu-0000YN-6s for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUt-0002IF-Ay for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:40 -0400 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:36093) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUs-0002G4-Vg for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:39 -0400 Received: by mail-qt1-x830.google.com with SMTP id u34-v6so15976663qth.3 for ; Tue, 30 Oct 2018 18:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ab6VptyiBF+UH0FW+m/qIjGDhVLzmPY8RK/Fm0aX5X0=; b=KPcixcl3Uahim3055cETAg4RYuf226LIPInImmTgu7tFa+WeAyKamy7KkuWoVJ+C+T r4olGtSeklLYVdEfhpAfhqnc+5NgFA047aMzWANaAmeLgBpzTYkMDxu5DMPn/ZTgd7yB aiXtB/LASSyGXTxscYsjihm0L05mY6uX8lLy+VJ3CIU+v6qnerzGg1W6su5p1iLm2sX1 INLpotXwTPGTL5YQsH7P5BIiXkXSzsxNDZhYP2eVtmZiB++UF5wGLL/GI/VQKHgIW5Ou 4qJZmIyzK0dzD04Iwg/jgLU8uV7eelaq6QClWLT8kV+IPPPH1rR/IVV6WfaF9kYsouuC knBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ab6VptyiBF+UH0FW+m/qIjGDhVLzmPY8RK/Fm0aX5X0=; b=bDwllWO3CNWSemTrMACIGPakPnZksrxeG0hwInMyp4ZYiQ3x+F04TkirSouJ55Di5X 4Y37GTlVfVN6di06ztY867sbzWJ/2BiBpniK35mCr0QDcTB981h4XKrBfB8+fZmGLClz vwn2VyesMabFIRt1kIc98JBvqPrvriV3FjXCQPA5lp4wmeTwQ30bC8aPANKdLeiMB1JV BQpAt6MCSkGPica8G+SM4MdDJQQpyDRn/eyqTICG+tphVpJ1gvXqBIjAtkEPYtS7TyNn HWB901w1C+3GL4rPspRViGjb4l6Mp1JOYIvUtLmzKaJD1bYMAJ8yuJfQQoq6F0dmH5QP YCQA== X-Gm-Message-State: AGRZ1gKhYhfw4HAl45/+XB/kM3a0jdQckHFGULKPg2T90qPeWJnDS/SP Hx+XnXuXCOFow/Me2w4kTo2OtXa4 X-Google-Smtp-Source: AJdET5cBQ0jlPk0SoKqWoBBuvESyH0hoNI7c+6DcDdwz2k+YmBQRlMsFxhqDOsks9U/95u9TiPVmGw== X-Received: by 2002:ac8:164a:: with SMTP id x10mr992605qtk.67.1540950034435; Tue, 30 Oct 2018 18:40:34 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id j4-v6sm15568556qte.84.2018.10.30.18.40.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:33 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:17 -0500 Message-Id: <20181031013821.24023-21-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::830 Subject: [Qemu-devel] [PULL v2 20/24] 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: Bishara AbuHattoum , peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Michael Roth --- qga/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/qga/main.c b/qga/main.c index eb31f99b38..761007deb4 100644 --- a/qga/main.c +++ b/qga/main.c @@ -119,6 +119,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, LPVOID ctx); VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif +static int run_agent(GAState *s); static void init_dfl_pathnames(void) @@ -712,7 +713,7 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[]) service->status.dwWaitHint = 0; SetServiceStatus(service->status_handle, &service->status); - g_main_loop_run(ga_state->main_loop); + run_agent(ga_state); service->status.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(service->status_handle, &service->status); @@ -1340,17 +1341,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 (s->config->daemonize) { - SERVICE_TABLE_ENTRY service_table[] = { - { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; - StartServiceCtrlDispatcher(service_table); - } else { - g_main_loop_run(ga_state->main_loop); - } -#endif return EXIT_SUCCESS; } @@ -1436,7 +1428,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[] = { + { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; + StartServiceCtrlDispatcher(service_table); + } else { + ret = run_agent(s); + } +#else ret = run_agent(s); +#endif + cleanup_agent(s); end: From patchwork Wed Oct 31 01:38:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10661993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7BAF14E2 for ; Wed, 31 Oct 2018 01:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5E512A83A for ; Wed, 31 Oct 2018 01:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA3C82A8E4; Wed, 31 Oct 2018 01:51:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 205262A83A for ; Wed, 31 Oct 2018 01:51:10 +0000 (UTC) Received: from localhost ([::1]:56637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHff3-00027A-D8 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:51:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfUx-0000bU-BC for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUv-0002Kb-Le for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:42 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:44838) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUv-0002KD-GN for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:41 -0400 Received: by mail-qk1-x729.google.com with SMTP id n12so8565530qkh.11 for ; Tue, 30 Oct 2018 18:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=bQg6nndu4WqXPXDR4YukMSLGAa2GpB46yZFWniLRgXE=; b=dsVzD4iN3+gQHb/l/MiNZbllRDxbAD6TpOF7lBkFgSQPco9FKuj0aBjFwKtWO99tLC sVBePnlKuLmGEXNNISCFtvX92DXpd2MWZ158MLMOGgKnZ185l91djSeQpsVMxC64/VuT 7KiYsSDGG0/UArKBmaRt+nRsNCWiPpJDgHtyoXibBmite8uX3ZAj2MP3/NrSTBlURz1p bb3PuIRiw2Os0R8vRfxPOc4ABC7p/ucZ1c8Zglir44+qAXDR8yR4QLNp8hEyf4d0rG8n fzgCe3sm1purqRgZGzrT5X5xiW7EvrlW94Ob3/g9JggacaNXG+lRPW5P18pPecXAGXmw iciw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=bQg6nndu4WqXPXDR4YukMSLGAa2GpB46yZFWniLRgXE=; b=MEMb9i7kunnjpxsKCuE5kHlhnWgWMmuHW+XgXmM8v18+dn0gZBGECBS7IQEwRVnqlE DUJxxA4MT214v/PUWqAmDW1rPXM3PCBN2muE5qmIDuWQB/v3eDr8hzHmtZPGgXe9KaQR ir8UFllYXupowKnuWZO/fUauXJt70mEV/6uR2A10r9EBj6BfycSNr8pLSRaLke7SMX7H JgKFY8w8K4ctlzuj/rrwG040ysjUjjfneyfsHRk56ISLcVxPbEAf8CLkSZjySSHB1oqq pewzieqeGKoAuvD2gXz9a51mTKJQlBBzr3HAJJPfbF62lO0DsBX7gAYDolDhVeLjs6Lz QLoQ== X-Gm-Message-State: AGRZ1gJ3BBFDmAZzhHZOu/BrcnOHkRM4STaJtRngMv+AzjZy0Z1w2Lcj rh1GymA6PAPrRqA290fgvyrEKkAv X-Google-Smtp-Source: AJdET5fMC+cxQXJpyFDKCbmvC0waflOWsmsTH+FzVm0o2VK4IVvO1rVwMSwGSUv+mVqz4yPY8AIGkg== X-Received: by 2002:a37:f706:: with SMTP id q6mr905053qkj.96.1540950040186; Tue, 30 Oct 2018 18:40:40 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id a186-v6sm4952296qkd.82.2018.10.30.18.40.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:39 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:18 -0500 Message-Id: <20181031013821.24023-22-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::729 Subject: [Qemu-devel] [PULL v2 21/24] 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 761007deb4..506a314140 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.conf" +#define QGA_RETRY_INTERVAL 5 static struct { const char *state_dir; @@ -98,6 +99,7 @@ struct GAState { GAPersistentState pstate; GAConfig *config; int socket_activation; + bool force_exit; }; struct GAState *ga_state; @@ -120,6 +122,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, 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); static void init_dfl_pathnames(void) @@ -168,9 +171,7 @@ static void quit_handler(int sig) } g_debug("received signal num %d, quitting", sig); - if (g_main_loop_is_running(ga_state->main_loop)) { - g_main_loop_quit(ga_state->main_loop); - } + stop_agent(ga_state, true); } #ifndef _WIN32 @@ -255,6 +256,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 future\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" @@ -614,6 +619,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] = 0; @@ -927,6 +933,7 @@ struct GAConfig { int daemonize; GLogLevelFlags log_level; int dumpconf; + bool retry_path; }; static void config_load(GAConfig *config) @@ -976,6 +983,10 @@ static void config_load(GAConfig *config) /* enable all log levels */ config->log_level = G_LOG_LEVEL_MASK; } + if (g_key_file_has_key(keyfile, "general", "retry-path", NULL)) { + config->retry_path = + g_key_file_get_boolean(keyfile, "general", "retry-path", &gerr); + } if (g_key_file_has_key(keyfile, "general", "blacklist", NULL)) { config->bliststr = g_key_file_get_string(keyfile, "general", "blacklist", &gerr); @@ -1037,6 +1048,8 @@ static void config_dump(GAConfig *config) g_key_file_set_string(keyfile, "general", "statedir", config->state_dir); g_key_file_set_boolean(keyfile, "general", "verbose", config->log_level == G_LOG_LEVEL_MASK); + g_key_file_set_boolean(keyfile, "general", "retry-path", + config->retry_path); tmp = list_join(config->blacklist, ','); g_key_file_set_string(keyfile, "general", "blacklist", tmp); g_free(tmp); @@ -1055,7 +1068,7 @@ static void config_dump(GAConfig *config) static void config_parse(GAConfig *config, int argc, char **argv) { - const char *sopt = "hVvdm:p:l:f:F::b:s:t:D"; + const char *sopt = "hVvdm:p:l:f:F::b:s:t:Dr"; int opt_ind = 0, ch; const struct option lopt[] = { { "help", 0, NULL, 'h' }, @@ -1075,6 +1088,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 } }; @@ -1119,6 +1133,9 @@ static void config_parse(GAConfig *config, int argc, char **argv) case 'D': config->dumpconf = 1; break; + case 'r': + config->retry_path = true; + break; case 'b': { if (is_help_option(optarg)) { qmp_for_each_command(&ga_commands, ga_print_cmd, NULL); @@ -1322,9 +1339,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) { @@ -1334,7 +1348,7 @@ static void cleanup_agent(GAState *s) ga_state = NULL; } -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)) { @@ -1344,9 +1358,41 @@ static int run_agent(GAState *s) g_main_loop_run(ga_state->main_loop); + if (s->channel) { + ga_channel_free(s->channel); + } + return EXIT_SUCCESS; } +static int run_agent(GAState *s) +{ + int ret = EXIT_SUCCESS; + + s->force_exit = false; + + do { + ret = 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 = 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 = EXIT_SUCCESS; From patchwork Wed Oct 31 01:38:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CA7E13BF for ; Wed, 31 Oct 2018 01:53:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AD9F2AAFA for ; Wed, 31 Oct 2018 01:53:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 092082AB09; Wed, 31 Oct 2018 01:53:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AB1C62AAFA for ; Wed, 31 Oct 2018 01:53:39 +0000 (UTC) Received: from localhost ([::1]:56650 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfhT-0006Gw-0z for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:53:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfV6-0000ht-VN for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfUy-0002MC-Rq for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:49 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:45302) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfUy-0002Lv-GC for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:44 -0400 Received: by mail-qt1-x82d.google.com with SMTP id l9-v6so15948097qtj.12 for ; Tue, 30 Oct 2018 18:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aQGNc6BTaCf/YRgBGfwzjlAuGKMF/EXD2CCPOpt5Prw=; b=PbynzEr1ojSmb6q/tS2CwzFZhGoJRjDq2h32o5b9q/0FwIxyiAepXz0J85oYeo/ojr j7MRHEb9VNS7AJp3rjObQJQUlQzvBOGavAOZ/AXzbr8QKT4ilY5jNYnBlpYkm1jPf9dB 2f1HVau2nkLKC8CZXF/A7Msdykhg8QDDVUXPD5ABII7ykYMd69rJ/q0KbLcbyZfoyF4t am7fXoQxe24E6FUA3MEP87Mcj832PjD9PPHV3S5p/BjdwalBP23LULHDXNnkIgXXY3RW gZOUKa7/lhrbprsmzN4U57xzKX1SC90/c+1jdWHSHsOsz3r3X0WvSRuJTUwmMhl4Jq+x 6N7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aQGNc6BTaCf/YRgBGfwzjlAuGKMF/EXD2CCPOpt5Prw=; b=nppBWz43Wo7719ty6QrDkdD08hU29DbkhBYYAHebCw2/Vs1wfnXHrhAKBRxfH171HA PU8V0JphgAGfMsiByXEXUmY6iDzIQ51Z35ZBPoYPEBGG0k7w2FjGr1JDdT6PFJxppzw9 DGxnZsrK76+HhV4yA6aYKCpIXxU7MVAkvEKaE5tCTRDI5iSFVsHKBaCeQZ7vcDnQ/eGl 9aYdtNW+ooykPZMF4jyfHH05gE1xhUjhfglVwWe9UtgPEoJIpzS2cmSw+2GaL9BkO2Oj /YtQG0IGobfmHNBsf2IQ5ELqAGi9QFQCstZXgFmIs+a/SNnbO8yq+FSZNX5ZMW3jWl/L jW5Q== X-Gm-Message-State: AGRZ1gIC4T+RVdOB0Vrj5n6AD7tIcPySxwpOrAg9aU+2zFJbPu1NYLdz TsTIZ3/3C8Ket8Kc4ytQC/1iQjsx X-Google-Smtp-Source: AJdET5c0cWtxIK9Mx2bWho/kY3K2Ty9wQEmk7ihHX/iUSbe6VGmR1MqRs9eIoibB2743pQoZ18E5/w== X-Received: by 2002:ac8:4359:: with SMTP id a25mr964241qtn.361.1540950043276; Tue, 30 Oct 2018 18:40:43 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id l33-v6sm11883325qte.24.2018.10.30.18.40.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:42 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:19 -0500 Message-Id: <20181031013821.24023-23-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82d Subject: [Qemu-devel] [PULL v2 22/24] 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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="LocalSystem" ErrorControl="ignore" Interactive="no" - Arguments="-d" + Arguments="-d --retry-path" > From patchwork Wed Oct 31 01:38:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DD5715E9 for ; Wed, 31 Oct 2018 01:55:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F2062ABA3 for ; Wed, 31 Oct 2018 01:55:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4333E2ABBB; Wed, 31 Oct 2018 01:55:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DFDBA2ABA3 for ; Wed, 31 Oct 2018 01:55:57 +0000 (UTC) Received: from localhost ([::1]:56665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfjh-00083e-4L for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 21:55:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfV7-0000hz-25 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfV3-0002Qs-MY for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:52 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:41688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfV3-0002NM-E8 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:49 -0400 Received: by mail-qt1-x82f.google.com with SMTP id l41-v6so15967721qtl.8 for ; Tue, 30 Oct 2018 18:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mK5a7Z5zumPu2nLwlxQAQAUPJW+cZQHhbt7ia2+g+Zw=; b=ZAKatNyH0RRdWoxYx8VYcLlWz4+7XvkoiQu3i+JyKtoyKBRNIDwqZbtMrs7GrWF5eF ERw4ShRsinqPmCiu3ubrypzUVpFIf63KQckZ36W4T99AoJ8SH6OSCmbzxaSihhkbINMP FXCsm1l8TSNUGcPBfajiXVNAlv3UhZ3zPRj4V5Pp0aTdViUF96+oLifjtT0n6oOIRkiu KTDDInHQN96PO0w47RZ/LM69WSKERnVbQieWzRUwwsu37JGFjjaS0f7Y3MmRsrayd3zz 1ROkGCha6rLQIRJBa+bMe/bJnjq0mVCLozaXT8hPlQSPmE7CiUErGrnwLjIB+3ZHwSTB SzAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mK5a7Z5zumPu2nLwlxQAQAUPJW+cZQHhbt7ia2+g+Zw=; b=aQuvETNm7A6/Nb3n8M4svE6eWS2uui/4hF+2WpL0xoVOKrh0Kij+iate+LqjnGA2yu jdwR+Pgy/gYHy+7ljeh71oQ1nVJQoz+hfgW1TDnXaW1WnmHrq0W9MzLI2Z7+jHxqdAiG VsmbRUjJAIq9uH1Tp/B+SeFYz2FunUlIOJT5l1JCW3M8/iPo3XIZPkthrZ5/7gIBXNB3 u2wRe2AosLXSfTMoCOiM9wcmcD/SFnaqumFyIdAp+JHMYLHpRdhKmHTyCUTgI//q2asd hy6Dfb2xK955D0MspuTbnYnPlGLy73qX3CaHqR+TtTvU5U1Uq5whJBhxFSPT9vI76nAe ce3A== X-Gm-Message-State: AGRZ1gILWGXyoSw9TQSi2zFJAySGHL39LKdGXb3vdZ5bg9QgziCwjy40 IgAMorOMbWvrkAuBb6hBW4aSHCv8 X-Google-Smtp-Source: AJdET5duHEdBO+xOruEFiJyD2OEqaE9/DXfF/b3ZnfpU2Hu7xNdVxcnGSHIujMxOLRYH885kKILoWQ== X-Received: by 2002:ac8:2807:: with SMTP id 7-v6mr986584qtq.31.1540950046094; Tue, 30 Oct 2018 18:40:46 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id j51-v6sm8460161qtj.26.2018.10.30.18.40.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:45 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:20 -0500 Message-Id: <20181031013821.24023-24-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82f Subject: [Qemu-devel] [PULL v2 23/24] 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Useful in general, but especially now that errors might occur more frequently with --retry-path set. Signed-off-by: Michael Roth Reviewed-by: Marc-André Lureau 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, GAChannelMethod method, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL); if (c->handle == 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; } From patchwork Wed Oct 31 01:38:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10662017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C4A913B5 for ; Wed, 31 Oct 2018 02:00:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A64F2A258 for ; Wed, 31 Oct 2018 02:00:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E3472A5D7; Wed, 31 Oct 2018 02:00:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6AF452A258 for ; Wed, 31 Oct 2018 02:00:26 +0000 (UTC) Received: from localhost ([::1]:56691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfo1-0004X5-Os for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 22:00:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHfVF-0000oN-4A for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHfVA-0002X3-Ju for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:41:01 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:38509) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHfVA-0002RD-BC for qemu-devel@nongnu.org; Tue, 30 Oct 2018 21:40:56 -0400 Received: by mail-qt1-x82f.google.com with SMTP id v1-v6so11757965qtq.5 for ; Tue, 30 Oct 2018 18:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+3EgmmikQq+I7mn9Hitw7dh66ejEiEkMl9ZvZ+ITy6g=; b=Cw2kNsG0MXcakmk036m+23MM77b3HVOQLWTTypm2ft7XBtXD35N/Ho8AG5Co43vp8b WNxA4uSEiSbisoxpXHJamb2UUjlxtm6sKxWd7zAQqS4VXzJ+plAXN+sf4xJ6R74nqOzv 8LXjWJJk8rJ2OMJuUVLV9J/nJWq29LLGfX7uk/kYg/BHKf+HXSmYUSoVUjYVIuBqaG38 wSVmeiRDYrbJNrlG34qNr5zQF/qra2PRTMwZfcqO647rZGFfIYGFJXw3aTMqO0vnUnGj 4Gj8blpIGNEWLbvbfURRHdQzy/1/qgq9py1qTMvycWAbhI7jJ7c5e7LlDV5BXFbUhPu9 D94w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+3EgmmikQq+I7mn9Hitw7dh66ejEiEkMl9ZvZ+ITy6g=; b=hbm/MI1ZFHGuhPoZvWDjpIfs/JGl2CaxDm3NZUaYFMB6vkFtXJ9B5v8NlGJS+soL/n JMw0bQVQbOICl8sR0Na7PeFyduiJP6lZn4UfmKznVQeXTOkeGtYcArmVRzmLrJ/CD0k4 jz33PQGLYcOBEuOqINuS77kerYVul6WmcuyZb3WKzu6x6XF+XHO/fbi5olgG1hIIVyJz hbMmP+qOyz6sG0JlaAx7lpD1Vq7fRjWT3znC32nunE3OLQOLZMw390uQ3cCxvdzVCUrj UGwad8Q9hHdvPnfc74/dBB5q7fwZmTsBQFDDb87CWVaspZ+vzqcCJXJysbfFbdCcnK9N 0/6w== X-Gm-Message-State: AGRZ1gLYOcIoSEky4BWDpTutxmVxo+/umVB3UTsH8qtf3nqGLV8nC0TD xbmf3Km1Uu8L6qs51qSQjM2FO2EC X-Google-Smtp-Source: AJdET5d9P3s/KIhxGbyrVhtqhkgXMwxQL63BT5ysCj0rEhDCP6jmUCb9IzSS5SOjZxwaPpRO801MwQ== X-Received: by 2002:a0c:f584:: with SMTP id k4mr1001257qvm.22.1540950049025; Tue, 30 Oct 2018 18:40:49 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id p67-v6sm11248254qka.23.2018.10.30.18.40.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 18:40:47 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:38:21 -0500 Message-Id: <20181031013821.24023-25-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> References: <20181031013821.24023-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82f Subject: [Qemu-devel] [PULL v2 24/24] 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: Bishara AbuHattoum , peter.maydell@linaro.org, Sameeh Jubran Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Bishara AbuHattoum 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 Signed-off-by: Michael Roth --- 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 506a314140..87a0711c14 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 @@ -83,6 +84,7 @@ struct GAState { bool logging_enabled; #ifdef _WIN32 GAService service; + HANDLE wakeup_event; #endif bool delimit_response; bool frozen; @@ -119,6 +121,7 @@ static const char *ga_freeze_whitelist[] = { #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); @@ -677,6 +680,36 @@ static gboolean channel_init(GAState *s, const gchar *method, const gchar *path, } #ifdef _WIN32 +DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data) +{ + DWORD ret = NO_ERROR; + PDEV_BROADCAST_HDR broadcast_header = (PDEV_BROADCAST_HDR)data; + + if (broadcast_header->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { + switch (type) { + /* Device inserted */ + case DBT_DEVICEARRIVAL: + /* Start QEMU-ga's service */ + if (!SetEvent(ga_state->wakeup_event)) { + ret = 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 = GetLastError(); + } + break; + default: + ret = ERROR_CALL_NOT_IMPLEMENTED; + } + } + return ret; +} + DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, LPVOID ctx) { @@ -688,9 +721,13 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: quit_handler(SIGTERM); + SetEvent(ga_state->wakeup_event); service->status.dwCurrentState = SERVICE_STOP_PENDING; SetServiceStatus(service->status_handle, &service->status); break; + case SERVICE_CONTROL_DEVICEEVENT: + handle_serial_device_events(type, data); + break; default: ret = ERROR_CALL_NOT_IMPLEMENTED; @@ -717,10 +754,24 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[]) service->status.dwServiceSpecificExitCode = NO_ERROR; service->status.dwCheckPoint = 0; service->status.dwWaitHint = 0; + DEV_BROADCAST_DEVICEINTERFACE notification_filter; + ZeroMemory(¬ification_filter, sizeof(notification_filter)); + notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; + notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); + notification_filter.dbcc_classguid = GUID_VIOSERIAL_PORT; + + service->device_notification_handle = + 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); run_agent(ga_state); + UnregisterDeviceNotification(service->device_notification_handle); service->status.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(service->status_handle, &service->status); } @@ -1328,12 +1379,24 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation) s->config = config; s->socket_activation = socket_activation; + +#ifdef _WIN32 + s->wakeup_event = CreateEvent(NULL, TRUE, FALSE, TEXT("WakeUp")); + if (s->wakeup_event == NULL) { + g_critical("CreateEvent failed"); + return NULL; + } +#endif + ga_state = s; return s; } 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); @@ -1365,6 +1428,27 @@ static int run_agent_once(GAState *s) return EXIT_SUCCESS; } +static void wait_for_channel_availability(GAState *s) +{ + g_warning("waiting for channel path..."); +#ifndef _WIN32 + sleep(QGA_RETRY_INTERVAL); +#else + DWORD dwWaitResult; + + dwWaitResult = 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 = EXIT_SUCCESS; @@ -1375,7 +1459,7 @@ static int run_agent(GAState *s) ret = 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); 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 emulator and virtualizer." +static const GUID GUID_VIOSERIAL_PORT = { 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; int ga_install_service(const char *path, const char *logfile,