From patchwork Tue Oct 30 14:43:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="f37BCKU8"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvs16cTZz9s9J for ; Wed, 31 Oct 2018 02:04:53 +1100 (AEDT) Received: from localhost ([::1]:53752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVZb-0002YM-Hw for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 11:04:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGV-0007n7-Nj for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGQ-0000cA-JF for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:07 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:35458) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGQ-0000bm-En for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:02 -0400 Received: by mail-qk1-x72f.google.com with SMTP id v68-v6so7396843qka.2 for ; Tue, 30 Oct 2018 07:45: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; bh=b60sY/Qw6hLNM3jT0LJpKmQaEbzVAgZEFb44f/LeZZA=; b=f37BCKU8MC72PTrVPOOhp/kSbp0uF9lOvJzxNc7LXzNx2e0Ahru6YvHFhf8DGdDnlN KFlenSKwyY1JzfjyidGQ+HMEhluiY7v8fFt7K975ztzNBskC/Qpaav0dtBhURnmwwqTV fyaRTWxBkphQqT55b+I+svYAORdOYC8tZGk4MZhNivWin/TKuJ4Y8Ix3zS7uFTA24slV +GdKfDPa0k+Y0IJn0xiDv3tHtoT66ZXbjZa4fywIun/e+RMz3DyNPA7SE9xhCxk1UJ+I tAAyvHmFl7/pZdCZlI2xOXdP+A7zYpsMxVhedd2FOm1ocxdXsdf/u/o7TS/HIPLL3SrO qmug== 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=FFmUdZpoZpmTuU0y2QhMmxLuKdFnejVUp67Tnfii9vNeFieaRhcYJwqm2v903bTpXR BDDIpeWGBthIowGLj3VUR5ycB44cbUTbPpiuVwYG2NjBev77XjOV3ox64ceQQUzyqwDk mnrmzXjrjEdTJCFKkt1nlsflZvVsrNfceb87hlX3vkHkKPyLtVXVgwc30sl2GnmJOT6q jfADhV8pS1XWT/xdPDcexMrXdXeCTPZ/oUyd/2X4Iw6nE7hJaZQPXNXN+NFbvFN5ouxx MaaS+rG1aLA0AKs7i30GDT/tDI3SKHiItM7EoDdZn8s4FD8o+cXTMlg1YGY5s751gWf/ 7+2A== X-Gm-Message-State: AGRZ1gJQBHT9nXm4IHPWswgFVaBZs/60vaaSRF4O4jIWmP7kUPkB91XU vMUPRv+SQkcWd/hexw7PzEyBp/jR X-Google-Smtp-Source: AJdET5cRQSvqy+T7b+txN/goCbAa+h7fPuRTcJjBYHf1ompf0zLSjJs/YAJGEZ4jBeLOHuibbWQbow== X-Received: by 2002:ae9:c10c:: with SMTP id z12mr851284qki.22.1540910700933; Tue, 30 Oct 2018 07:45:00 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id y126-v6sm16584682qky.94.2018.10.30.07.44.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:59 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:35 -0500 Message-Id: <20181030144358.23144-2-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::72f Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NCb75agN"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvhx5GBXz9s7W for ; Wed, 31 Oct 2018 01:57:53 +1100 (AEDT) Received: from localhost ([::1]:53711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVSp-0002xE-6L for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:57:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGn-000890-D0 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGk-00016Q-LO for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:25 -0400 Received: from mail-qt1-x82c.google.com ([2607:f8b0:4864:20::82c]:46272) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGi-0000wu-IK for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:21 -0400 Received: by mail-qt1-x82c.google.com with SMTP id c16-v6so13687730qtj.13 for ; Tue, 30 Oct 2018 07:45:17 -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=NCb75agNvDbZyp/GWWvf4hR5pXLRsNHRmCEfdYQgkAxGvjfUG6MbU9YQpM4AxG3NSl nOuslu8xqCFhgcbvzxdtr5rop/iiYv4TzfEnBYvYQbkAUsohUUbP3+fy1MMiANoE1bdx 6BwFSA7MT2mJMDrH0aecjnicfvPkOXc5TcObCQI+qWLtEIsw0YDpotuF2rWoxvlEo0th Ssw2/w2nnlQ9/ip77bttoaeae788ZN17PGfA1oX8DISNG23sBhx4ZP1jauDWMMNEHdVm dclp6L4eDC46YjA/B1+mM+RQYL99PM18IU9uSIlsCkSXvYOJk87PuF85ww89ZcKBR3Z2 g2AA== 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=I6QA/8FNwyjUfiuoz3eEOOY1AkUKRj9fN1c6iW9O+gRlZ5kFQC3L/h/Ts8JSMsoEF4 yfyYsrzbfjUkQio1dl5I8cU5tzIDl+OIZoUJ1Isn+7vY/X3n75u4MmAd6urzGMTtjNyo 1zcInQxb0421cQDKsRx+S+TcmVfUZAdY1C2N7xROWbuZ+su+GgZHhtuSJzxPrSsjLIod EcNqUC6DI8T9jAkA2nFLRqjgG6quxXx5FZMON2zHWJ/JIL1dgTf1UYnQsY42jkINXFbf WY2dLURm8BWmh7yzfW1eiXgOabYKsVOLlqA9/STA6FIr8w7MkD54L2KfWB342u4vP4LX IAxQ== X-Gm-Message-State: AGRZ1gJgHbbNUa0JJR/svvNt3ikXOX4u5MAmnoup2vQ3+7ZQFuxOjMdQ o+zcr9UnR2D3D+6B6pHs0AaqZEfa X-Google-Smtp-Source: AJdET5eqEYEQemb0l8PF9HXJiBXl32Gh/vs6ol4IJz6iBWOaUq43cyHtcBMCQYaBU7TL5V/GTtLHvw== X-Received: by 2002:ac8:33fc:: with SMTP id d57mr1269546qtb.82.1540910715499; Tue, 30 Oct 2018 07:45:15 -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-v6sm11580187qkf.92.2018.10.30.07.45.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:14 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:36 -0500 Message-Id: <20181030144358.23144-3-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::82c Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LpTgEoBz"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kw0H3Ymgz9s89 for ; Wed, 31 Oct 2018 02:11:11 +1100 (AEDT) Received: from localhost ([::1]:53785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVfg-00082f-Vw for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 11:11:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGn-00088z-C3 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGk-00016K-Kc for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:24 -0400 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]:36193) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGi-00011u-KE for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:21 -0400 Received: by mail-qt1-x842.google.com with SMTP id u34-v6so13729479qth.3 for ; Tue, 30 Oct 2018 07:45: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=IyZMeptQhY8QjDMqhWNkZZuHVaNTU7U8+5/FjdMQJl8=; b=LpTgEoBzLWh5gaBsqbep4KHzAjFwJtBKJMmuhSdiqCa4W20prSUaANlDOyrqNOE3TN ouHS9RILRaFpk16FSvFoO98v3GnBwb0wu9WLmHK1JA+GPLCwyJfBcHgn+8FLK252DPg+ BOClQKl2Tzi2fucvfunyyr4hwHJaK457p6F5nmgVqw1ZjaOF6caqmZ89734iqTLmlzlm CqVz6d1PxB1Ai2OeRQucMVKOfcjNFP+Nxk7dM0w7EYNOOlZFZJJC+KqK3D9JNZG7hvmO Kv/BXNt9ww37ild4kq47FQtb3Et3TZrnLLPSYJ9wPRpPhlOZwKc/mOjBqbJsKBQdBhBG NkCg== 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=QsueKvaDqB3LjEfAoT1K8azcKL+hUb6970GwnsQ4UUB9eqagvncdfYBeiqZaW9CUqR YB2iGsSxT0T2ht5nlJz8i9AEpdyHT48eUwAyUiX78KS2to+LlQAVJ03YwASRTnpcwkIo 7ULzd7SVBCMH/JCKlBwWBSXdaquEkF/1S+qX6Fb/UQPkTuhm/e2QBaZ/Z4yLWd8alW+G AUR8weyu1bclnCsOIhEXBobE1dQDEgcOIP8Hb5H791RLMxu971TvmVQTxhdVEdGDhRfB uLjriJG/9k4S3jge1K17QIxLwVbzRDC6OhqIdzNSAh0c+1wIpMOs7DfQAPgkbCzpYMPJ tivQ== X-Gm-Message-State: AGRZ1gJ6+QaW5ZdxWu8GsYnat4VBPk86Ze+a0Z+UEP22wykK4AKblnTo D2uj9ZgPoe1XKv6YUCuxl+lz+nn4 X-Google-Smtp-Source: AJdET5eTLOLRWg+KSfw9IAWTIuOr+//fvA2nxypKdgyMLpqCIyomBFuCn6OOR8voUfi3BzDjsp08kw== X-Received: by 2002:ac8:3f3b:: with SMTP id c56-v6mr2504344qtk.33.1540910718379; Tue, 30 Oct 2018 07:45:18 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id t36-v6sm14558958qth.83.2018.10.30.07.45.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:17 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:37 -0500 Message-Id: <20181030144358.23144-4-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::842 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990894 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lHsCzj4F"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvZN1j14z9s9G for ; Wed, 31 Oct 2018 01:52:12 +1100 (AEDT) Received: from localhost ([::1]:53681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVNJ-0004xH-Jw for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:52:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGw-0008Ez-6p for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGn-0001AH-HZ for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:28 -0400 Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]:35635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGn-000168-8x for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:25 -0400 Received: by mail-qt1-x82a.google.com with SMTP id a10-v6so13732970qtp.2 for ; Tue, 30 Oct 2018 07:45:22 -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=EERxl2rjpJQKP4Wxr3vhB//mp2OyQ3hWRpPjBXDP4is=; b=lHsCzj4F53ZrWl7Y/F953MjBPYsIgzsXNFCQSwHv3eN7cuXUduRP1w9sL6MgSxjszQ l9e37khYFz1G8HBUC7abRHYDKU9zJd1cOdfBLAwUmA5BPK8kp9ncsT0sBd2+dEIP+mzv upMWQHFLpONf5cEsh6yfNAvFEF3hH7C9mG1ZLnHPaQWl7hL97SHtfw3zwZhEn+mLs3F2 tTa4pXe4gyEVymp4Go2azcWidWzFGvMu/Apk7EDC12+NEQLxzYEiy9MVZLi+8uuF9Wjb ZU1JgIiUvh2J1c8+ZO9yQ+VXgrjE50gLyerR/tmfPd2OA6UDNaf3AhPlopAfGFn00eo7 CcJA== 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=EERxl2rjpJQKP4Wxr3vhB//mp2OyQ3hWRpPjBXDP4is=; b=qW7ukgyXQUOVGx/aWUrKApI9893yjB03l9STYBt0GvGiHya8v6Wj8Hhn4bm0Sxjto4 J0Yo/8gjbQffOA5EuIe12xUaoTeCqQXwE1Tp0fw9aNcu7SRHwsOQO/FyQHUU4Aiiliqa Dxf9IEMPeSgpti6fCIkaakRi4oPIgk7SXDv+5QZAtBkBXt5NqkjUdf6KviEBAfEcq8O0 9XX7a7/QvqYoSynrlisVL0uWDZQlUg1WMbbc9f7nW1IxO4AAJmXNtRcLrDJ6JsOrM74l zbUMZWt29bv0ONNpvUI6eZzKMDjLiWXY32tHeYnMphMnOvYHXfbPVnU5VWZHKuHltGlz xbyw== X-Gm-Message-State: AGRZ1gKE5jL0LKFVXKV+yZAGJOPhYyGT1hSBMYSxh6j3q6LE50EqMlrF w6BDBjpzdMjf6jyb2azhiyxqALLY X-Google-Smtp-Source: AJdET5dxPDfw3L+yTyvDPRtZeReCiqDsSh6DGq0I8nxQZHv/dX3eKmXVh5RUllM9hJijhkj5NzkfQQ== X-Received: by 2002:a0c:f787:: with SMTP id s7mr11278593qvn.167.1540910721383; Tue, 30 Oct 2018 07:45:21 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id q38-v6sm18599829qtc.9.2018.10.30.07.45.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:20 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:38 -0500 Message-Id: <20181030144358.23144-5-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::82a Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Tomáš Golembiovský Signed-off-by: Tomáš Golembiovský Reviewed-by: Marc-André Lureau *make libudev optional to avoid breaking existing build/test environments Signed-off-by: Michael Roth --- configure | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/configure b/configure index 1c473ce95b..eea3b0c7a4 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 @@ -5603,6 +5605,17 @@ if test "$libnfs" != "no" ; then fi fi +########################################## +# Do we have libudev +if test "$libudev" != "no" ; then + if $pkg_config libudev; then + libudev="yes" + libudev_libs=$($pkg_config --libs libudev) + 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" @@ -6027,6 +6040,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" @@ -6862,6 +6876,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 Tue Oct 30 14:43:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YKhgT87k"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kw3y0gbGz9s9G for ; Wed, 31 Oct 2018 02:14:22 +1100 (AEDT) Received: from localhost ([::1]:53812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVil-0003h8-7x for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 11:14:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVH4-0008Lm-BV for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGw-0001KU-6l for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:41 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:35642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGn-00019g-Ql for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:26 -0400 Received: by mail-qt1-x831.google.com with SMTP id a10-v6so13733158qtp.2 for ; Tue, 30 Oct 2018 07:45:25 -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=YKhgT87ke3mHFyG74ss+Xsqkuatn6H7jidZGYQT2IRJHc6ky80PUW2dCvT+f9d54tq atv/0eDX9y3moCh8kAqB/w7pRKm7OGjQ4Ta5fN+Ee5uNoP/EKknrZk+FYzW94RnGoblp EEHneF+9cRoEeCeMBmbjDH1vds9XfkZUTLHW0aGgKiCts8YHRyf539g/Xuo7fQf5JQMb V14ScQ03Xsvyk9rMlIyM9qYCP7AVqimebdtpYD3zQafCVi22mbElNycH9wQFcD+QXThK Q6sXNi8mQrQGGZdWEU4pby2otanOAamhjtXRYm8wd0wTOqOrz1ckPHa1Gp3c+shV5agd aWEg== 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=fzup7PlvuNpNhqWIuDnDUQdxlxLqW2FsEkblRWsZn/4T+5KqRKRnktilL9ujIlbvzs HFkoZAKpXthXqyqbFTtHOBD3SaHnoaGtB5TKhkLwQQU7xoa53kKMPwAWy6JNsQDhJPXC 913u7HwLgA7fQBUY7TM0yiVFWB39/7DPXhYAVpDVZNdCLbTxe01bSOYByjXgIrfHynq5 zPcVdL17f7Zn1bxti75BDjjRHjUPprBLifh+MD576LVcfeoif46mFMLtPyBLVj+iSYvq /W16/Q1Rl4pjsbv1VHfivVsRTWI/eO1LzjVT8G9Ad2xLjDmjWOPw/Gvc6Ubuc5bcm+jP DoZQ== X-Gm-Message-State: AGRZ1gKAxgBE/xZgETl8+7+PI/6p7vAMykxfaI/U428FrJcsugNRT6xL hU68+xql7WeTGgS8RqO7bgHiVSGD X-Google-Smtp-Source: AJdET5fBPh/92WaQwlxQ+L0LcV2h+Es8wtL+fPACjWJ5BqEbYjnJiC1CddC1BYBiCCyopFdZAnSqiw== X-Received: by 2002:a0c:b0c3:: with SMTP id p3mr16994882qvc.174.1540910724040; Tue, 30 Oct 2018 07:45:24 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id g83-v6sm3075074qkb.57.2018.10.30.07.45.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:22 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:39 -0500 Message-Id: <20181030144358.23144-6-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YU/TMvOX"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kw6S610sz9s9h for ; Wed, 31 Oct 2018 02:16:32 +1100 (AEDT) Received: from localhost ([::1]:53826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVkr-0005D8-EO for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 11:16:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVHR-0000CW-Su for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:46:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVHL-000205-P6 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:46:05 -0400 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]:33454) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVHJ-0001D0-Sr for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:58 -0400 Received: by mail-qk1-x732.google.com with SMTP id o89so7397632qko.0 for ; Tue, 30 Oct 2018 07:45:28 -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=YU/TMvOXQUHWGY5dDgJciuLMBGDuozDE8l2cWMP3eMW9Tpk4xPOF4/vd+utdf1VEL7 Rb9dfQCNqTxvphaMMWZuTLohQpYkPgggRXFuIzA0gfvyD6lCyEPMk6+USEEA4rWui6fW 2nQFOY7i88T9x3bAknVlmahBu9dD5wku6+sxBPFFnlYByg5wktYa6hYcZ5HvyozsWRvV uA3UaOhWTWIrNwgj2s4WuckDqUHlS+Gzp1xce5iywWXXGZW3ML8P/YYCyw9Ez9ybZga8 7kxDbPDu3WASNAZjAMxG6w/Mu3y6ImtMk9Q+xnNRTvrqcIM7QM1Am+MlrfdRSDAeCWrg VL+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=nJQYQIjRSHr2tP7RJknGWpav4tRSKKGks1XYgWf6vn+exCOubkmRGF2rNp+NPXbY/T jkvOynGx3eNQ6wkZ7Ckd+pZTPN0XjG4Py+tv6X3ZxB9kQXeBhBMAAznrK7uNyOl1jj6o EUv0XOPzxo1FyfBCqz+LoKTeMs4cB3GiD+a2bSSadEZ3JCdfoUdMr6WgImPJE0QLOXLD dfPkYj0+0B56Dh2lgqWklPYmZYSPFFiLTjcwL34MEPlSgKCleuOqo2PNU53glzVna3Oi V/AB+Pa03g8Leld3eghyHCEz7dToPG4l8X6rCCB0lzwUH1/T0SGi2X2iqYdtyrQYG8mk C3RQ== X-Gm-Message-State: AGRZ1gIs2d/RAMr5Ib57lx0DkQCK0QcevPo7+N4oO261GGOl/apkOOWc MtaFPchHt8wiJ0SzfCBeLBlKKGk6 X-Google-Smtp-Source: AJdET5ezn+SCWZ3gx9xbyRRkxZZSTLgbeWsx3gP+yb8tS52cu51JcxooAg+o/pQIHygvrSmOMWg/rw== X-Received: by 2002:a37:6389:: with SMTP id x131mr5090477qkb.149.1540910726748; Tue, 30 Oct 2018 07:45:26 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id u123-v6sm13482180qkd.51.2018.10.30.07.45.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:25 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:40 -0500 Message-Id: <20181030144358.23144-7-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::732 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990903 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="G5wY9r5q"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvmL2NKMz9s9G for ; Wed, 31 Oct 2018 02:00:50 +1100 (AEDT) Received: from localhost ([::1]:53728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVVf-0006gs-EK for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 11:00:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVHI-0008W1-1d for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVHC-0001gd-36 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:55 -0400 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]:37575) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVHB-0001Fy-S3 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:49 -0400 Received: by mail-qt1-x842.google.com with SMTP id d14-v6so13746559qto.4 for ; Tue, 30 Oct 2018 07:45: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=OMsafrgRN8K7qYrDHmXKNcug1Hah0nOGn2aWbm0aBsM=; b=G5wY9r5qRMM9ToqpAWp2z1+k/zRC+EoZCvbNPB7STxNb8m1mipgZmywaKqKCTvGDkU z4hi8RFvK+jLLKuevjyNl8UOcNjMjeIuZQ9VcGhpE0iwVpSGHNCGVq3E7+XbowcZSaee WEVxRJnE9L44koNXT18nwJRLwWii6R7t4e7HtNFqyoTOcdPMEb0+cUrs8DrtztrJu656 /urG4ht7nFzz9POQtCj31IolQZen1nwOm1C4X66fXgK645ro79efU1F4BPtOUvlDDj3v SPb4vHXquOfTk4d09xBNH5eChWuqAievMw3rz6S97BYwq51DoOIdzxRf9HyfVuCmbj4n +tCQ== 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=PDxxHOBxeXOFjyfUv5pScKZJeMsAlbgqTHt0kYevxVVR/9Ym4dYazeqFCwFtdcg1ZJ EEnqww9kGNBuVZGONyMsdDM4JXyCN+A1ZczGOzKoIyushK9KdFlG5aXbAbzxPWLgiAE4 gI+Mi6sAn/OF1EUzUdS907En+Sfbx1luCKB0cNvAEnu07UEYGH+fajMQqICMkxNkvBhT LQVFBwHzvDPzA3Ouxt0NyEc5XwgiXruIoyJBuiTd6O/cgFziH/FTtt3gcu3GcprLNdDo /0cVyhgwrv8FIBENmeaEN1BFFwxEqFeEt0OzYNIbAs3Wh/jhi6AXuBu+A7r1mXQ90p7s IccA== X-Gm-Message-State: AGRZ1gKbU3OHbYEljnsMefgBs1Cj0h/yFrXx2CSAiNVdLd0IOL6o64Bc yQHsiURHaDjivotyQ4+IzDR20jjt X-Google-Smtp-Source: AJdET5dKBCRG866jbi5/tbU9yVo8VU0UvKUl9mOMPiDAlkbRRg6oNphWhRFaZnKGgwEr+smhWqn7Dw== X-Received: by 2002:a0c:d810:: with SMTP id h16mr16805142qvj.19.1540910729325; Tue, 30 Oct 2018 07:45:29 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id k18-v6sm18768963qtc.54.2018.10.30.07.45.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:28 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:41 -0500 Message-Id: <20181030144358.23144-8-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::842 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GKoH4ZZB"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvdn06qmz9s9J for ; Wed, 31 Oct 2018 01:55:09 +1100 (AEDT) Received: from localhost ([::1]:53692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVQA-0000c1-KC for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:55:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVHR-0000CY-V2 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:46:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVHL-0001zt-Lq for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:46:05 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:44766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVHJ-0001Jq-Mw for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:58 -0400 Received: by mail-qk1-x735.google.com with SMTP id n12so7367654qkh.11 for ; Tue, 30 Oct 2018 07:45:33 -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=GKoH4ZZB9tVMSVkp1P+gh/ekSJnTNYHTpPWOfDhvCxrpuLC1PKk9fREtGIepFFQ8+u BHlK+hUWwUkc8iA9866scYvIVA0Sder+AuFhISSfurmXcUBHyBBS9GD7RVi4d0ObT2ij lj+pkCu3KwMWwqiN+j2926hSAqKB8ZwT5sP3ZNpgCiizzOmDwxdls7SGyePTq3V7mV00 7o5WtprmFVgQ+xHXGDXORVdMFhNmFPksnjoNwav/VD19+EFVVuntRpvtH029eDrptiyc 2km6YQ+adyjRnw0bhLZ3R8CF7Y6RGujyS7sWuyE1m9WP4lZpiZ3fYuC9ClXOfvcU6Upo /VBQ== 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=d8KzIOgvNdvpogBJivjJCYR+7M2zvkEbzYqT1bvgdzRMNQBfJcbjqKJffvxxnZ1GfH 2BKwqmWC4W/3NYynu5398xn1XSHIccCDCrgdM8MxyXegbMlgynkeErBjtLyFPMvCrn/w 7kZYtCCv2CyZfEMUN8H6A6sYqT+hrrUGEmyS3a+KDMVEgnbYMv29zw9L9xoNVSBA0364 II+NwniURPrMErEj4hfhwb4qxDDmlMPhYLiuf7qrJMv9q3QyVrSDYaFSKGzJuJqBPKMk tKg3d2Nde6/6IIJHbMJKoQNQZjhPPu4f8yS8DZ2J0sjsFG5bNHI/W852ICJ7wYSHvIit IwRw== X-Gm-Message-State: AGRZ1gL5aASKa/vd7vJMPCKki6k7ZWBeqBtLJmJZ9Khv5bauEJW2pq3j K/HVvSHknxriqJW0DanfetYmLtPx X-Google-Smtp-Source: AJdET5c/QWeDuc4MemPn9uZTmOY0dY5E9h3mR+y9/t4WUQQHp78vols+JUJJocrgpUArSOPmLm3DaQ== X-Received: by 2002:a37:a315:: with SMTP id m21mr15862294qke.152.1540910732469; Tue, 30 Oct 2018 07:45:32 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id o41-v6sm19531297qto.38.2018.10.30.07.45.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:31 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:42 -0500 Message-Id: <20181030144358.23144-9-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::735 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NiRdbBNj"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvbd1KrYz9s9G for ; Wed, 31 Oct 2018 01:53:17 +1100 (AEDT) Received: from localhost ([::1]:53682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVOM-0005iJ-7j for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:53:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVG8-0007Va-R3 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVG6-00007V-TK for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:44 -0400 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]:46270) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVG6-0008HR-Lk for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:42 -0400 Received: by mail-qt1-x832.google.com with SMTP id c16-v6so13683820qtj.13 for ; Tue, 30 Oct 2018 07:44:27 -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=NiRdbBNjTrwMKi7lSt3Z11eKucRHGQBOjmw9roH+Q8wCSzzxG4v8QzS2w5JgvduWrd xL2mJ26LmNpRYoRlcv1bdFJ6cAJcsnj4Npl6uk6HmpxCpsreq5HHp/HI3dpiOtXFSRbP /z7p44x8NGZG7n5Oq+BEBCIXY+co4Sb+qYGLSiihHGZFwYV1g/VeGWjOVzjANnvgMQtD rNDH6svtMZaYnuOxrFy9eRdwgZhfwxeThApRadLhInql7dOkn2aKdzkOsU6zpQ+rld59 WQT3Mj6AUR4zmG8On3N2fuT8NM6Rcr29Pixg56rSWQ7k3bbggqvOWVfVkYKdDwng8Leo mRGw== 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=WHBpMglTNl7I1qILsw0vLFeG58BVeolOZZpPdpTWrX9PqkhknYfV6zssn7ERnU7LRz cEd2J9SvLqrh61yAB7TVQClPujUfZijlMJkJ3pTBjIL0IKbW8HKJlyyaqfmL4u8Xgztr Lzb8nO8i3d/g9W232GbZYwPo7E6rS7F/rp3S6J+55oXjHPjEZNJIyeyoQnabbPdiTAIV 6hYYU5BMHvlpAsXX0ZN+Qj6UQkUSEW49KjAS5V2o6EVv1txTKjFXcmhNCPG9pUKFf+gM Nb2wjSvlsjQJvjqYFt1EyPYacBuixpEOZbpXTlrzMAUFb8cr1izlAJ5j76e7h0a/lo7l 5EaA== X-Gm-Message-State: AGRZ1gJ/1QrlZ10aICXJarNJ3TtqJyr3fn95zIobnYSOVWmKfK6xl1mH qCEXoKvsTRg3nyqZzOGxPKyPRFAF X-Google-Smtp-Source: AJdET5eolyHboDk/o2XyxpyakW7ulb+WQrh36HsIfeW365O6XnPqbvRMK8nIlwrRIZ0xsg7+xGqSgA== X-Received: by 2002:a0c:db04:: with SMTP id d4mr9095707qvk.114.1540910666142; Tue, 30 Oct 2018 07:44:26 -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-v6sm18065678qth.32.2018.10.30.07.44.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:25 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:44 -0500 Message-Id: <20181030144358.23144-11-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ttZ8ThvG"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvVZ5Lvyz9s9G for ; Wed, 31 Oct 2018 01:48:54 +1100 (AEDT) Received: from localhost ([::1]:53659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVK7-0001yG-Py for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:48:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVG9-0007Ve-GT for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVG7-00009b-QK for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:45 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:39215) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVG7-0008Lr-DR for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:43 -0400 Received: by mail-qt1-x831.google.com with SMTP id g10-v6so13718785qtq.6 for ; Tue, 30 Oct 2018 07:44: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 :mime-version:content-transfer-encoding; bh=RPJEUP7diCJbHKDeII8UxiVI5VxahZogKC/CIYD6XH8=; b=ttZ8ThvGqil9qW1NvUN8bJFBb21GfI1CLe6pcMIIGi2lMPzOZfWV9NZAYspl9m6XHG ZVTw8bAT5oqA9ZSLW7Vb5kl0r6qlIIgxH/mgZ6viwHMhSdmpVBhGDb2fZger1lGk7O8V hNpIuoDoKdRUdE+NVpHEGud6jUW8GOlB4vKdxM1QdQMTT7UuWozFyFvR6V90SH4gT5ih 1Xc7DMGU5K0CqXj4d2xYja4RC15P8rvi2weeP0coygjA8g/b0FU+SQmEzD6hFPmDTMLB l7dmKK/GH4nDVYhcq1DEgijERN+KFEOgcdoROrE6wUb59r+Z+PBn8o5/+lbcRFrVvt4w W6VA== 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=iIlwsDkY0fNQJYhJIDWkmKbsddzSGFFE+ZjJPFsTh1UN4VRsHfORDSfYDB/5HTcyAq VZzFCC/MGB9x6gpG2Lavmg3EtKIorJYgaZFneMg0OgH0NASwBhpDawgjISX0XBpQtjmz hBkgDpVhBtRzIA8bQjYAjay3xyzRnbuV1vNVZYJUOqPzGHKT9RurvDqDqFuGL8SDlE1V TA0rxROeYKRN390jx7UfhfF7A8JOlh1Baah/tBOASZoTlbuIhYNnQVyGmmKwOw0peC/k SGACMI55H5DLkKYG8ovt0dbH0+LAuYiXn/+O1YAq+DlXX5Ra7qzZGXTY0W862NjEsQqv i0FA== X-Gm-Message-State: AGRZ1gIj8ezgbSjEPzb0V/gE/MLPYvEQTiIK9i6odM6YlWvPxROX7nlK 1Th4ydj4+8NN0fEZq5aHlE9C4RG4 X-Google-Smtp-Source: AJdET5edD7Drb8eiEvcnKfdzUdzkgaUT+KFdUgH624IRTjNFytyXc2QCg1AD5+GYaR9I1bf//x+c0Q== X-Received: by 2002:ac8:4787:: with SMTP id k7-v6mr2478519qtq.191.1540910671660; Tue, 30 Oct 2018 07:44: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 n39-v6sm18063573qtn.36.2018.10.30.07.44.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:30 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:45 -0500 Message-Id: <20181030144358.23144-12-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R7tay646"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvQp52Hpz9s9h for ; Wed, 31 Oct 2018 01:45:38 +1100 (AEDT) Received: from localhost ([::1]:53645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGx-0007aE-SY for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:45:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVG8-0007VZ-Pr for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVG7-00009N-Kr for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:44 -0400 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]:44092) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVG7-0008Rg-Ak for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:43 -0400 Received: by mail-qt1-x834.google.com with SMTP id b22-v6so13703209qtr.11 for ; Tue, 30 Oct 2018 07:44:36 -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=R7tay646zrtWVJei7ZeKShbPq2bnuF10vuqvhoLbiggiOX1EUx/HfR14LGnn/f7QTM adVhO17djyk6ItMRX1dkySFV70LJtgbYy8S7bp1QTM8fTFroHuFSJo3K/Cn+PymtsMQr clRhIRtdsMTA9Asb1F7wbPdXPXOVIBiHXkGCa+TZkTYpaEZn9GZ7JU1bK2CsjJwrGVwi VltsPjT1RDD3/qVyB1DhhD70XiFHPL0xsvzXcM19TNMc4yjV1EOS0kQHmQIFuCvOl16O DmyLK6YPSYDsDAOBmWEYmBjj8HcXncvzqey5mdDLiizHbI+zz8QrvSCy+Opt6mXLLhvb XD6w== 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=UvjFOp+xFB1WsuFlAXmlxdBSqAN6/H/HzVPCWeY3wwGUyMbe6soia8MOOTmFAQBPdW RJSpfSDx7V5/VcIj22m/ebySQVN3G/PQbI8VpZUsfaAxd7vD1Kk98Roap8Qny2JCjJ/R OeT2NKIZpw7qLYSuUP0HcxtdvcM/LSxiymCAcadIB93JtacI4OKoFcb+WbtJJFgyfUlP y2U8j32LU3bLMIXfJdhebLmcOKBXdqpFApxW5HZm/ZrQuEqIc7ljlYGXVfuoFdctEehl 9hvaioI9sAXweKU6fjCVJHJWHFZQvjLORQ5sljXMeWFIMrp33QC+0IlotgG1Z3Qz64No zvJw== X-Gm-Message-State: AGRZ1gK+OH3+mw7dIE0KAEc986QrYZ/8Rl9aJuOKKH7JlEZMy0HQShyb 71/V12lGfPugmqaRqiz5qMkoDgaU X-Google-Smtp-Source: AJdET5d7ao+G220PJrFGs02Uf3AjO/cWCHE6XAY0UAnvLZ6thzVIWT1z8lHBlF0+srwc5tEF59uBDA== X-Received: by 2002:ac8:701d:: with SMTP id x29-v6mr2515910qtm.161.1540910674702; Tue, 30 Oct 2018 07:44: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 h49-v6sm18065928qth.32.2018.10.30.07.44.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:33 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:46 -0500 Message-Id: <20181030144358.23144-13-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::834 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mGyXbSaO"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvVd5tzpz9s7W for ; Wed, 31 Oct 2018 01:48:57 +1100 (AEDT) Received: from localhost ([::1]:53661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVKA-00021E-RC for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:48:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVG9-0007Vc-6f for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVG7-00009V-LS for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:45 -0400 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]:36241) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVG7-0008TW-AN for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:43 -0400 Received: by mail-qt1-x829.google.com with SMTP id u34-v6so13726271qth.3 for ; Tue, 30 Oct 2018 07:44:39 -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=mGyXbSaOiteF8B8DtVng9Zcyp4A+yiwPYdZywl3XrRHDP1jUIuM+mms0/WzHSujlmy j+OVdL1aV0TE8g75DBExotdbInG8xQclV94THvvALkJCOzmGl8OGRS9hmxjKCkDzoQDc RPg0Jkm9pGF7E6KZjvCG/4HD9XuJGwpEzoZp/DaA9Ow6/u+8KhgY31aXxQYVEFauJ6Wu ZiG8L9Gdrvh9eXO2dnbncx0TCX4Le2pfzIFL0JAyo0NCTy1oCxviW3FW0WUggyMJpT3G rb7X+wTcw7sAppQ35JJLXnRm0AUGLt+i5dgeB/2uVU5oAOR01B5CGvvqqHuEAe+K/szG CkfQ== 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=XN7MPhfEsN9k+kbgvvcb9L4PLL8wuZi4iK6Qow5qb6Zwecki4ppVJlz98kRaj1B/an PiNEDCg/698oPq5xtDFlIYfPJzh5nkrylV95IMB8Sw+fWQvKxvZHttFdAWy0TB9vasPs 7U7RPSspNVKM3ZopojDGKat6VdjvlMy5n5ZZdDyvbEHS0RelGdbfp1E6gJhVhxiCutqN Jh3YrjOhj2ibJ3IOrRO0HEMhI45SaaZGtnhgFWD42pI6SvBfJinhDKjexE3waf/VF4Jx nRJ/lv/+JjVmE5jNJfQXj65h/ZxbG0CXx9ueSo8QSZlQDARBOeQPJ7P2evOUDS/I3apI ZTTQ== X-Gm-Message-State: AGRZ1gKXA6JwFn8h6HjqSB5LrEenp/9J+vgHNmGfa+RXJG31Aa5A25Ov HGMXKAFNoOM0Cbyk2BSeC8PNPWh1 X-Google-Smtp-Source: AJdET5c+YFg06D6SRol81cxb5l8SJ2A3Z1gNPquGuDj+Adis5AEatscPJr7EoyVvPZNLGrymA/wZHw== X-Received: by 2002:a0c:8a54:: with SMTP id 20mr16850813qvu.94.1540910677416; Tue, 30 Oct 2018 07:44: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 a4-v6sm17559999qkb.62.2018.10.30.07.44.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:36 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:47 -0500 Message-Id: <20181030144358.23144-14-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::829 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990900 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="luOaNOYv"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvfv3nDcz9s7W for ; Wed, 31 Oct 2018 01:56:07 +1100 (AEDT) Received: from localhost ([::1]:53701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVR6-0001WA-RZ for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:56:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGB-0007W7-56 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVG7-0000AF-UI for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:47 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:45432) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVG7-00005q-FQ for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:43 -0400 Received: by mail-qt1-x831.google.com with SMTP id l9-v6so13691529qtj.12 for ; Tue, 30 Oct 2018 07:44: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 :mime-version:content-transfer-encoding; bh=q4qvYUHQbKVfk7EWyk8ZHhYnBemb39mILFxX0uRYWYU=; b=luOaNOYvEB5f3hllTNkJDgXNzsjUapmbp6K03/IVbwBJ1NngJqEPd8620mf5KVR/gZ Dr/pTQQjQ4KobT/h9TrHygrzlQhL/KxA8r2S7Q4XviXogtyVIVsaZDMMHpI+4Dy4WqcT rSNfcODJ35YlgYOKociDSzeZUku3mgxIFr+KIZI071cze7ZJ2SiV/Ejc93pvNqYEO62x B5a7Lk1uz8dgoQmfC1lOIqBp5kTCmMRigAM7WtWJ8MFELYRbN/pjsYy2JxZ0YGuPG/1o edUx9TaP/vEbf90Tq/+1Jm12TYbGrJaXBHY+OA5iN2glxBtc+5fHjSgPNzNOmP5ec0k2 PHUg== 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=lDNHQxbzeeYoVEEpMbreLG7w8SuGpOTAMr+Eo7JhEHL8OXU4gtymBi9wfAcBG23lbP vRPk5LZGdoWtllZe9TrkYt/y1Hz3NF1YaBzgysVn7A3ubkszMMjTG/6kJkLf5jXz6Swy jmriuTtEh7hT8JCVCuGND0XNrq4V4Y8K1WRApolqAUc8CtYPDjqH3HWBI46m55CVnKf4 1STSmdkmOE9D86zYd4J9taQ/xxuAKl9ANh33yO8xPy9adeB5ciLCILgBGMelPV2te0/T 0QbI4FELiiA+f7bpUD2yuxRL9GLYEGleMvSEWoUfDtcKhvhI/eok3sucMrPAYEdIpDKb H4EQ== X-Gm-Message-State: AGRZ1gIAKanTUtl82mNdeclVYWhtaybat4ocsvthzqkwmIIy+HTNwP8o eA61e+OsBC9gjQV+U5j9TID7S9FS X-Google-Smtp-Source: AJdET5djYHayvGYRpJ69VXk7vuZN5zosCPgKc9YQQrQG7mmM9eW7NHlcdRnlCvM1ikWX0jL5NXnHIw== X-Received: by 2002:ac8:22ed:: with SMTP id g42-v6mr2578200qta.105.1540910680493; Tue, 30 Oct 2018 07:44: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 i35-v6sm13894211qtb.16.2018.10.30.07.44.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:39 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:48 -0500 Message-Id: <20181030144358.23144-15-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LJ2jCaXj"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvQq1Vdcz9sB5 for ; Wed, 31 Oct 2018 01:45:39 +1100 (AEDT) Received: from localhost ([::1]:53644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGy-0007ZE-B2 for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:45:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGB-0007W8-9B for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVG9-0000Dm-6V for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:47 -0400 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]:33588) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVG8-0000B8-R3 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:45 -0400 Received: by mail-qt1-x833.google.com with SMTP id i15-v6so13758995qtr.0 for ; Tue, 30 Oct 2018 07:44: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 :mime-version:content-transfer-encoding; bh=V4QuD/SdmHm1xhwRyGU/67Fuszx4RPOvYIaCUYitays=; b=LJ2jCaXjyAPxlLXXZcoVfWT/tJhh2d2T8xiiZNKnuRDRUNN1u3ejk1ZLC0P8AXgQPQ L9cAt57HORpyyRjVaSHOYRS/O/eVj7S+PKDGDyR4U7sX0YpUMKMfs0M88MW3f6OJ+F8E WWA9ykjLMSNIIrjgZyEu40u9mxO7G3if0G+qJ0h+3YhGyetlDdJnTdabn8+mHcX+vijM 7V84Iv7qoQ7Q2IECuyTwGiVJdhhCqci8VfxeuevkENMiJHNukdYOWOUAFCS/038edFxY UG/o7HnGzGDxoh8f+r4cndKIS7mfowC3ZwhnnwCqbM7ImYgQ4arKXpNKG6XtOUDesjqV Z3uw== 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=i9cZtKyR1A4scDRyKnJy7wovE1d7OTXsOYPLjfeSrHu0ouZ2jS5d1k/S6CSg6Eue8a iDw0GPKjCSEGmSd9LEShpyzbjTLFxaRv2IhCd3CNaqKmpuCXT0EP1+799A5CV+RFA0yo JWww5A/eNlM4pZyp2mn1brBbUn0VEAUu06FhSerIJsnPi93UunbsMXsB+SXRPVx10LOt gEuCfMghgHuuo1xftpYwv6Ag5xfO4yns/PkQOQN4DMWbljt7a+xif6oWNt3WuFcxEqYy IU6iWqZBeyTO8pZbdVoxGhNDtm62Hyy4o8VKM77sV2gcrIztTt5O61k2pjtKGh8htQ0r WXbQ== X-Gm-Message-State: AGRZ1gJtkVTPyqKAKCFYnScNI9SFanupEt5v7zrvTCIXduy2J9H97mok pRMt2uCHLBHgkH4xPcdr1JHUMR73 X-Google-Smtp-Source: AJdET5e4e5aFZ3QZ+anUywhDfGpAFcBTSc6AR6UySEm3LKJGWCUVEma58SPWCxDC5OpvmCS/MQPJZA== X-Received: by 2002:a0c:89b4:: with SMTP id 49mr17050831qvr.85.1540910683375; Tue, 30 Oct 2018 07:44: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-v6sm10844571qte.24.2018.10.30.07.44.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:42 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:49 -0500 Message-Id: <20181030144358.23144-16-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g+5jA+Qy"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvVY5YqWz9s7W for ; Wed, 31 Oct 2018 01:48:53 +1100 (AEDT) Received: from localhost ([::1]:53657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVK6-0001wz-SX for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:48:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGG-0007a2-9p for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGB-0000IJ-Gx for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:52 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:45433) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGB-0000Hm-AF for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:47 -0400 Received: by mail-qt1-x831.google.com with SMTP id l9-v6so13691967qtj.12 for ; Tue, 30 Oct 2018 07:44: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=reWrzN1nbgrUa5M9CT6ngaBhfrzDoBBYAKpSG9utug0=; b=g+5jA+QymCopuIt9XUkeQH/gkr9FuWKjrOo9Ek5V/cYr2mbgts2ESJvWqZXQZ9yPok 0Dx2t1xLN+ETfjvThMwkb1Q4J424kuS0ZloYuQxsULPjdYZ0oqsA/cMSzeVXsUxDa52v lAYNfTRw+QU3FeGE9WXRFBsN3Mu+iyCELZwbOneB3nz4zvznZpIJP1yvnHN4oUhaut42 kbQNYJM5Gz5846WQUs++B9NXpt6fzlbe+mNBTcK4ryE9RLbm8q+QvwZlgQ2/U775ZCGL Sj0hy4HOzbfZaIyPFlQcRmY9odFG+E2dcZwoXPLP/ENmuC8kqTezhhXvuQEsHIpGE0dk 0yAA== 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=YOfv/wbAmPp7LWRizL3vTjBVB0lhcICVJCBnlihNVoICgQ3fhRJGZYOetL4f0Tdz45 5EqeSMIYwlqrVubub92aPrUBzcClW8k+8vPF3nNNHMEmzbYZyLUU04uwygo5gVVIkG4S +uCwOKlBu0+POAodLpXzwnaeQJmDUOFnZtn9i4HyYD3kYw21cz4Yet7Ke6BxdB7H1Wc5 0MlrpMq/NSyzM1HlTQPM7ZuWiET1c2duY1AM1dGNJLflx4HwLYnxx4kTFaVxzpB5IAqO PKcOXlg6DJ/HoC/aytcKLRSXBIA8gwslWpHrcWKTpTL9qG+2S7xNT+TYGK+N5o7YqJL6 NnrA== X-Gm-Message-State: AGRZ1gJ5TVgpWfZCdPSgh3PnTmZN0/cFVrV5Uc+D1HckR0gFsKuouWMP XcRM567TCWN9CQBLY66ABs2LLerh X-Google-Smtp-Source: AJdET5dLZNpYIFSH0hvT3Uo5WPJSxcunR+hVVMWndfzyH5lUjVooWBG38OD0dW6S9G12KCVD1ogfMA== X-Received: by 2002:ac8:53c6:: with SMTP id c6mr2582079qtq.278.1540910686080; Tue, 30 Oct 2018 07:44: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 e54-v6sm11703975qta.4.2018.10.30.07.44.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:44 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:50 -0500 Message-Id: <20181030144358.23144-17-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kj2OWN7o"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvZM4yv1z9s7W for ; Wed, 31 Oct 2018 01:52:11 +1100 (AEDT) Received: from localhost ([::1]:53680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVNJ-0004wU-4F for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:52:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGJ-0007dI-F2 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGE-0000LS-Cf for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:55 -0400 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:36249) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGE-0000K5-6i for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:50 -0400 Received: by mail-qt1-x830.google.com with SMTP id u34-v6so13727171qth.3 for ; Tue, 30 Oct 2018 07:44: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 :mime-version:content-transfer-encoding; bh=hV7f/126Dfw1LuCXzTvvDVsft6NVkBl1N3OPxeFvDMY=; b=kj2OWN7ooDU/P/NIMRMpOp+bM2zCHzq1/gdUY930O5lrVuYfjz3QyewoUvORCll9ka v9K9hg3+voyEUC60y7phCnYvnuvsqk1R4MV1I1hw6OL7PNJlpP10vssr1njScscsU1KF f37MYq+1j3SBR0YIVMQNDrDYHZqUp+dZxwF01InJxSjY5MZlC6yTOOzmo/GF4Wz7o/JP ad9lJ5gQ9HIC85boV+QgnOz/OwnYUhjJ1X8VFWvwIXba4U9gLT1W3+bi5tUjIH0uGUTL i3CSHkLkFv9ZIq/l9hbA/1TqVGEs5WAkNTHxWEy3x8yZH23Z6Ze+1MIA3fJ0CcpajdXs 8+PA== 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=nMD+LFkUoq3xJJjRttnL1spBCyAmkmahwa0IgsULzPei2KKljCx89V88QnGJjnSp4B rdiYKKkwT9wvsjpfF7OJWedJYtYhZvQLl4t7Mbe2Z6WwFfX2/WMi+vrE3cAbQe0d8kRS Cz9+pUQsXWPoHhadzEzMK5jR5//rQK3kU4wKxoEwDInXCSwwQSYAP2UJNBxaAlgpReZt Olp4Z6HGu1yAn9LBeI3KAkEHlyvzjVJByaSugGaOCu99ol2+pIl89AooWYtm9DJiFwLL 4CwyFccFW0LOY8Iu4cljOu8Y8pD9DJxnb63nuQoT3bUxfYqqeKDK2LDUh90GyFBnt40D 56vw== X-Gm-Message-State: AGRZ1gIUjSd6DojYnfE2VYoMlN1tO2imKa8tTwFW020KHA7kDMRByO4Z FqHEyPwd+PtiSDzt5zHBVQEM6obk X-Google-Smtp-Source: AJdET5fO0sYrPjiks9YgSeD1nwLLt+yGZDUfCffQMCxB3XbAWi0hkwZNv9YfOUIKXrt/6R/p5m4n8A== X-Received: by 2002:a0c:b789:: with SMTP id l9mr16952566qve.34.1540910688918; Tue, 30 Oct 2018 07:44:48 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id l13sm6696656qkh.45.2018.10.30.07.44.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:47 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:51 -0500 Message-Id: <20181030144358.23144-18-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::830 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="czzKtheD"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvk84vmsz9s7W for ; Wed, 31 Oct 2018 01:58:56 +1100 (AEDT) Received: from localhost ([::1]:53715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVTq-0005Ae-8q for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:58:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGJ-0007dJ-Fj for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGH-0000SL-Q5 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:55 -0400 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]:34007) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGH-0000Rb-Kf for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:53 -0400 Received: by mail-qk1-x732.google.com with SMTP id a132so7407382qkg.1 for ; Tue, 30 Oct 2018 07:44: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 :mime-version:content-transfer-encoding; bh=tXnxRiw5dgfWTyLrIDra9WPBMKy8b+BOWuJZw8waj94=; b=czzKtheDBstZq+IDzsmN/sT/sIRgq2lOhFml265/aRUn1WnqDzbDaL/f56WvzDuRzE eOlUyYjgIjjbnQjNTCTTJiwxUZ9iHOJKd+Cnu3ulGMwwM0s7pW4hvb4NH99dC11EKnRL RIkrcxpo3mOL4+IeByc2VaIuwaDlF9YQN3729A7lZWzfs+M8Qo4EFcrAjgtjfSyqBTeU QpqvGxZ2l+NTarCgkVCFzzEfAuf+EBU/YGJCczlJn/RwqLphi0s9D46KryDw0w18sqH7 FEtozTO9wfsvSqEo1CJSxJCvGo3WVAQwKXrfN8gx5/MzWuypQvhWCvtgd6+SBRvGU4sM C5sQ== 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=F8wd+0fbn6ORj7kUgoX4G7QVakkXBFskS3KMpybRubH/610fxakASpnr1ih/qfH9uN Gl5tbJ2y0YWz8lgxFvh/hX0/Roxu/8yTFwihAsiSlmrX8R/Upi/D/UjpbVbAPJvhEagP xQ3I3LxpckX4gbNV9ITExQ0zzhJkq4Hto07DFWekVACtiZ+Ozuj4VVivq+FvY/8CcC6n 9297Pd6lgv4IsYXB6ZGcCeXs0KY3OvN38dfe6ozr1wh8P8nq67DcHIYLokT+9eTQzsF3 k4tyWfBPwPccIu4etroJVB5nDH4W4+bDLL5TexRDmnHPIQo4emO6ItF+ftR26ekqvyfe YaBA== X-Gm-Message-State: AGRZ1gKjePI28iuL3hQvJEYAiuxyepQm3XQ0j2mJqudqQhqQk2Q/itj4 YySQV55rfVHCcWzoELdnPWjcWlbD X-Google-Smtp-Source: AJdET5dYS0GG2RX5LxoQdb+ACh+FaMAHFcHopUaA0w+MV6tH/gAPfJ16IvZk/ZvgMtNsa6jhSydOIA== X-Received: by 2002:a37:153:: with SMTP id 80mr5617852qkb.122.1540910691978; Tue, 30 Oct 2018 07:44:51 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id c8-v6sm14900599qkb.81.2018.10.30.07.44.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:50 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:52 -0500 Message-Id: <20181030144358.23144-19-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::732 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990904 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Fyz2ry1T"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvnh2Gwpz9s9J for ; Wed, 31 Oct 2018 02:02:00 +1100 (AEDT) Received: from localhost ([::1]:53741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVWn-0007b1-PF for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 11:01:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGM-0007dR-3N for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGL-0000WQ-5P for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:58 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:33798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGK-0000Vd-Ne for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:57 -0400 Received: by mail-qt1-x831.google.com with SMTP id z2-v6so13770333qts.1 for ; Tue, 30 Oct 2018 07:44: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; bh=J2hDdIIMnNOSP+USzHUBuxWsUR55MYaTRzDvre6P60A=; b=Fyz2ry1TpqIu50shL3hkLhyXRS9i03GuB21AeTzokUELPF/X4VI71DcWklMJT+dxt5 Bc3ls8FgbSet0hiBuGevvoPnTbS0dfUtp1fCzSIRMLM8b52bksz7yfL6MVb3NUo5Yzij 7qHw95yKKWvvTxOyDNTq7AB+KLMJwy0sSJ42+E5kPltfDDnt0/w8Ve9fZ8By+STqEMAm hy8uu7Ffolml1nZjCmdTM014R6VQZAIcT9M/eFIdSrk6wV09S6Fzdn/xumgOrVEByBxu r2hC15j3V9zRyG02hhqrYVdh1RFmzQU01+nxDahx+8uWkF4Qgn32doDXMY2/1zp2xuU8 LBXQ== 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=ogzq3tUmjhxQ5/7D44GtzRSvJMx3unTmOXliONvzAXm4kh33Ws1pw8kHVrc88WDqCs tLAhIvv+JTiYrCRlORQ/p85OdYcGSa8RAme5yJMNl+yWPIqMjRWV/nlrMkgWL1ijl4eB 6vfezg1tZXjR5ibkKOSjK+dHt/r02eKO8l8pVV1Stb4iF94PMBIdsewd0DDuHIui5EQV 1HrCSg4GbpXob+Yc2EBuxaMgY+7INdxDH2v/w8OnoBhuQv17+Ia5NwsCS1Wpq73e9DNk 9LMvtliA64EMMz3bzEOdRYH4IT4kBpFu2dx55v2b4Ct2wiF+OlEjiPreTYtQNQk8h9Z8 6bsw== X-Gm-Message-State: AGRZ1gLQve/5B8W4XtO/Hm5QvkS0IA8DHMLC5Vk6sWq/mlo+V8HfBY7P 7XM5T+bkT16sP3mp2R0TdsVh5lv2 X-Google-Smtp-Source: AJdET5cKtzXqM9kBgxEOMTjEDuDIq8fZHrESSIrZ4ebdXGxIGuuZZdpf/mBPg2i7dmLEw+kQXvPs3w== X-Received: by 2002:a0c:d8fd:: with SMTP id w58mr13320078qvj.103.1540910695401; Tue, 30 Oct 2018 07:44:55 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 94sm29822333qks.8.2018.10.30.07.44.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:54 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:53 -0500 Message-Id: <20181030144358.23144-20-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::831 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qmV0sHg0"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvdp42Pbz9s7W for ; Wed, 31 Oct 2018 01:55:10 +1100 (AEDT) Received: from localhost ([::1]:53693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVQC-0000dP-2j for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:55:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGO-0007fM-CK for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGN-0000ZD-IA for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:00 -0400 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]:37190) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGN-0000Yg-CQ for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:44:59 -0400 Received: by mail-qt1-x834.google.com with SMTP id d14-v6so13743993qto.4 for ; Tue, 30 Oct 2018 07:44: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; bh=ab6VptyiBF+UH0FW+m/qIjGDhVLzmPY8RK/Fm0aX5X0=; b=qmV0sHg03KnSMAAkWydmxqGIue7cps/v3mPW9VKlthuB780d1Tl9zQIWIYit9q0SsR B3S8SGE9+8lyTzcIKXsbD1Nlov5+Sjr4YdEY5cGe0zqAtkmKC6K60RNvO1urhFzAB+Gl aRkh0sr/3wTtpCkWX6RgbnJ+qTH0D/uczyuRHOxuZoUYCJOhRjJ+OQUl3M803ZBmH766 07RKGbO0gouY5133lqRc7WaDO/qw7rIriT0ax3gI9tldcLSPuKHTJbN3bCRu+JPegZVd Sr1HET11KuwvRD2gevqZMqph5937vHH9JPaek/75rhEypN8y3KrPIsPmxHM5pm3YqwQQ vALg== 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=DweMW9NzBbO6vgJaumq4eJFIp67iQQmxcI9R/8Oz6dBSysaKz/R39NQ+OfE7MfIVHx Bb3V5y+a62sWrt+4zXfrPUddcr4aVEJ5m/8GpzZpYm21f0DgBKrq3MLNj5RLcsNEABDe bFcpbyujmd10ugolVxgz2yTIlzPLHIwBdUVH2YuA+oMjpmy7vSCbsdqPaESEfH76d2fV meQ/4DtwqUniTC6kSr51f2SR0FwFFty6DAk6ZuFDxafYUw3CjL9tWSP2+btAev4slx5d eYKcMxnpITZE0pcEjhgyzMVbZktvnvqDjnCxDrtPIXCR3vPmBOYzkyZxda+sIEsI7h0m qN/g== X-Gm-Message-State: AGRZ1gKiSQFx0aOPqaogRr76f8xFKkehC53wFl6voD9E+qOqwsAbYB1B US0i94y8/pqWE+iF/H93AJ2HGlE7 X-Google-Smtp-Source: AJdET5f9nuLSLC8V0azwRVcf5kXOoiL0+z1tt9wkaJFLjuIdSZxdG7Wkzok1AbCTGcmK2IgUhbrnfg== X-Received: by 2002:a0c:b458:: with SMTP id e24mr17060340qvf.37.1540910698048; Tue, 30 Oct 2018 07:44: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 j4-v6sm14525710qte.84.2018.10.30.07.44.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:44:57 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:54 -0500 Message-Id: <20181030144358.23144-21-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::834 Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hsZef++/"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvZJ273Tz9s9G for ; Wed, 31 Oct 2018 01:52:07 +1100 (AEDT) Received: from localhost ([::1]:53676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVND-0004r9-UE for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:52:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGV-0007n8-OM for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGT-0000eS-CJ for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:07 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:33587) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGT-0000e2-6z for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:05 -0400 Received: by mail-qt1-x82f.google.com with SMTP id i15-v6so13760459qtr.0 for ; Tue, 30 Oct 2018 07:45: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; bh=bQg6nndu4WqXPXDR4YukMSLGAa2GpB46yZFWniLRgXE=; b=hsZef++/z9tUPPghRJF5wLFcidmogrzdUpwd5Pg4KszLALls9k50lPYMixgb6zXp/5 +/St2uyDn6TG+TBCZOOs1ksft3OAQhK9ZQynbXj9YMVFOnL+kaY0iQqGSpx/vkf/VCDw uANSUeE8ryvm48dL6i+ihyPTD4uRnUloMb2/7ybAXtqcphuQP1LV6Oy5dZlo45hNwR/a HkB4EK4Whhrx99dTdH5euL3n40DJE75/GQy3T4ZwVIHggAUYt9JRO2PQEH7rqfrfwODE r5rlqne9wvY2g9thuLuHvwAZRls5Oxt9rlBBiJp6yac4Upnztl8AJEbbQgA6TNV06O4u LLRw== 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=Ryi+xCh1Nh4BIQNJHAnb9wGp6l60b9ZYU0X26bb9oT5g4/Epnker6Iya+xqFm4OgH6 DzzCPr9Gxz99vVE1YxQ0qcPFTnCf+Z33A70lk8FcO4R7qNhWNX4c0DwTxH9+FnAMxteH 75Ovs+WB2iJBCY1kibKCE+71qnTIjH2jxVRMF1xYzfYr1bXY+VHbDVA7ZBxWebRgjJvz T+ECDtpNHAZtv1MjBuLRXzdx9Hj4IzPoWF7N0Ago/mrPP04XZhYA32V05+sOizn6J4HW vDJDXw04p9tsWLNF+CXxqHiRSU3jcaGzQnocaQX2NFHkt4Q6nZsxVaVnhoSLlgLYgrEG tJPQ== X-Gm-Message-State: AGRZ1gLNfj6oh+FGQYSO8VWiYsY1A0QcklEhEfyHa2Xiwo+ED7Lesn1m kwHD5NTBqm/XqX8BJaORa1Q+b7Hr X-Google-Smtp-Source: AJdET5cjHIFPBwIzc933B8P0Jq87s+VJEXVG2hituDD80T0Ju3t1om/AQcjyAFLkI/Yf5lRs8MO9JQ== X-Received: by 2002:a0c:99e5:: with SMTP id y37-v6mr17039358qve.133.1540910703889; Tue, 30 Oct 2018 07:45: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 e39-v6sm18843895qte.43.2018.10.30.07.45.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:02 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:55 -0500 Message-Id: <20181030144358.23144-22-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AD3j1ZLj"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvdd6cS7z9s7W for ; Wed, 31 Oct 2018 01:55:01 +1100 (AEDT) Received: from localhost ([::1]:53690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVQ2-0000YH-RN for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:54:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGW-0007oL-VB for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGW-0000ib-5v for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:08 -0400 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]:37189) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGW-0000iM-0g for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:08 -0400 Received: by mail-qt1-x832.google.com with SMTP id d14-v6so13744683qto.4 for ; Tue, 30 Oct 2018 07:45:07 -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=AD3j1ZLjkP4kSGvESXnXHQQgtNqX/7tELNWybvfgrLoPljkOA6Ur+kiDRIvBav8TbD W1ssT8/QLos1WzdrgnvzZ4AOwRLgVM3Z2Z7b5mvgUvgZcYlvmJbbNM64SoKjLiD3VZya Q/yV5KTbV2kzvTNubohC0RQMKoel5y5pmQDathLcbK5kQNFt8EZFK/WfEG4UMkjZmnlR RwoH0I7o8VjtF+92xOKnG0pDvAUWoSsGIRinf4nwvnsgKWIdY7U0qWeoZAFGE9WtuqFR u4o4muTqdCFjYYig5IXxRK9TLfFUhg9VUDEhsAwttHLRp+IDqJF9nBFDk3Sb28bCdQEH rZ0w== 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=mEgUHiQZe645d4FkFc5cmXK/TgLzfCQr/IOyLollFPH51VHfqNu2/X2LYOme35g4VG 7NUmWiNLJFN9aATWWYAXHvz/GPpcDPi11Whx8ltj+CiKduVlivD7602VUDDH+sLJrtEE tNuRfd4RAeqHZ+IDg/gjMcyhjnd/d6HCCaPTMwVkvgw6Epd3NhbkUg24Z9Iy4OS/Uijf gxYOGPODVrwqH0IvEgO5MZgZ+wCeyJLj4hxHpXiuxr4WedAw1fZegfFqvGrLjuscKBXr uplDQa6jm0BBRh1ktfgePrnBw3RTOfDGJ6horc/WawakgtQjSd7y1SyCaMC48AFlbDJz rZGg== X-Gm-Message-State: AGRZ1gIJt18k2bGpL8aT65jYDuJrcCFz92R4F7dOCHmePjNbJ+69sU2B Ev+pZlAbdeadTRYgvsq6tLSt7SmY X-Google-Smtp-Source: AJdET5diJjpmKwgYv1M/107zSWGOtAMUdl52rs/TPQSWklP6Ap8Oy67U4SJpCzhuh7JIqJars5Pb1Q== X-Received: by 2002:aed:2806:: with SMTP id r6-v6mr2477490qtd.189.1540910706857; Tue, 30 Oct 2018 07:45: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 i38-v6sm7282753qti.77.2018.10.30.07.45.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:05 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:56 -0500 Message-Id: <20181030144358.23144-23-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 990911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HmZsSvpk"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvwn4lmgz9rxp for ; Wed, 31 Oct 2018 02:08:09 +1100 (AEDT) Received: from localhost ([::1]:53771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVcl-0004mh-0o for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 11:08:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGa-0007wm-Q9 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGZ-0000om-Jw for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:12 -0400 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:40703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGZ-0000nc-An for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:11 -0400 Received: by mail-qt1-x82f.google.com with SMTP id k12so7857772qtf.7 for ; Tue, 30 Oct 2018 07:45: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=mK5a7Z5zumPu2nLwlxQAQAUPJW+cZQHhbt7ia2+g+Zw=; b=HmZsSvpkZNzR760lqMpHpqwP+AirAiVhJOmco+Fnk7mFxV6aRpdNegu7m8Vq/XGB9x tA1cyVOW0ZihZ7BZpL8LjVDeKtb4s4UakJKzUET69wnVLB0tn7kWxeayYcCztXsU9Num tVw8vz1QZw/SnJqVx75dl1QmuhsNNaaWitmwowJs6OaUoop8fwr8SmDh/87Wgxl8KjW2 v1BOhV1dKT1CP9irnjnsNWLUsyPEtdhZdpj/nlezCsakplB+V8zFJmEgDbM3BKJVWOnL JHL8ZdvO8o37G32NQdLO3R+FPDtVZEmnjLxOT6K3NXRZgE870X38sGBrYnrNlpvrCZu5 kAtA== 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=FNw4rllk1EQQ/EJUIArhDVhaQMbRLiR1ZkIo0e7syEGo5jdED5WFf+YvXQ2wjAuJ9v hEsTMUu19egMpArT+jDRg1+oBJorb+nQJo4tlvA53fSbIiUzid1jWS2B4bpKgs3kYneg KK3BLUCqoayOz2xFL9KCYWXo85DzJUmCBHAtnIJIbE3GYjEm02lGNRfPd172u1MHzdUP qiM8QIx66GL1NJt8yAMy7oVmsdOIyMktzCws6i25ysDTTgaLvSrtLP6nG55AooVLpox0 khNnleH5sPONXz/0kM8L2JW0EWuM4DcY+zl7s6c1i7GITVdX6r6ahKi8f2Vxy4C7OsNW W9rQ== X-Gm-Message-State: AGRZ1gK5P86xUOqS1r7ckTtbW4BarI5Mq0V21bZeR2p3oX3/5nBoUdjE 8PibQhSW4eQQ0JcdVQFGQbF6ZjBc X-Google-Smtp-Source: AJdET5e4Xn8/Mqi8mwXQc0dRXs9BXdOQ2SV2T/C2oCrSDznEIUO2D3+KUHUa9EVfNQMHuCwURElNOw== X-Received: by 2002:ac8:1aa8:: with SMTP id x37-v6mr2496044qtj.44.1540910709750; Tue, 30 Oct 2018 07:45: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 5-v6sm16934690qtz.8.2018.10.30.07.45.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:08 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:57 -0500 Message-Id: <20181030144358.23144-24-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Tue Oct 30 14:43: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: 990889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NNOGqhit"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kvVg4BTJz9s7W for ; Wed, 31 Oct 2018 01:48:59 +1100 (AEDT) Received: from localhost ([::1]:53662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVKC-00022H-Ak for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2018 10:48:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVGk-00087n-MQ for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVGe-0000vn-Pu for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:22 -0400 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]:39581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHVGc-0000tk-Qf for qemu-devel@nongnu.org; Tue, 30 Oct 2018 10:45:15 -0400 Received: by mail-qk1-x72f.google.com with SMTP id e4so7379190qkh.6 for ; Tue, 30 Oct 2018 07:45:14 -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=NNOGqhit/tliEgtN/Wkip/6ixvc2XGp/+s4Gfq+DZ1Kh8jGtwrlk3jhq6hgOarbkEq 5meH3gSk/d+m5YvpReUhv3HtlKJZbsRzTjyZzXvg2akaEYeGmjPa96IRdlF4kM5KmPJg EXWKXZWFSiwL/L69C2e8H/8Zv6IJKWl9BTj0/i4Qjy/LFZEwoWe1goSr+YXFXeZOtRvo U+VH8V3lfKV4KLadJjnH2tJTXCwT46AyU3X3nOsxRDWXHGJeP1HDr8d0yYZ9CloOb6xt 9VpxBxjvNPlBlZvmfiapNjuC5vnfylpoVgyqpNTgG6NU6nHfioxN8C6leeJ4Xsj3HkLf qBeQ== 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=o4oIx6bDlJxfmhRMSOBByiZJvK78269hCP9OnCKFOvo///Li1Q11geJqzR5sH/bFGN EdOPHe3SVKNacdUDJ5oG24pK4EuUCx30hKwc8w6al3E/kP0pVl+JpuK8tphOoMajY3zR fv6P88SULm/HnjFqXscDXGcRHqFjkWXAJQ+x+KvFAR5VOy5DxEH8r0FpZnAff/AMarql giyNqq4lMGmw6LwWgrLoAoXrc2RnO+u5RiLOxlJVTI7kq7+l/h4fQ1vXbaEz/JKp5U2c s2m5RgUBBF7Nl1XN7ha5Gfl+z4mLQ6TM2iUo7ja31zxZSXO0L3dQ87iH0Odw5ohnvUg/ 1P4A== X-Gm-Message-State: AGRZ1gLq/m9f5BG3zdJQnZrCQcVw7r5tBgzqN4U9pLK/capHr7rXP9zy RMnglLfdCsbYjla/wcbQX6YhA55B X-Google-Smtp-Source: AJdET5dGCag6vTX8V7jyGZAeJ+X0khZUmARPFx6S1lk3B7jHINMr2jiyuQ727LlWFhwouebXl76Tsg== X-Received: by 2002:a37:27d2:: with SMTP id n201mr9718808qkn.18.1540910712828; Tue, 30 Oct 2018 07:45:12 -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-v6sm13992415qkb.71.2018.10.30.07.45.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Oct 2018 07:45:11 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 09:43:58 -0500 Message-Id: <20181030144358.23144-25-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030144358.23144-1-mdroth@linux.vnet.ibm.com> References: <20181030144358.23144-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::72f Subject: [Qemu-devel] [PULL 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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,