From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996384030658.9245619340071; Wed, 31 Oct 2018 07:33:04 -0700 (PDT) Received: from localhost ([::1]:59936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrYM-0004ef-R1 for importer@patchew.org; Wed, 31 Oct 2018 10:33:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMr-00015d-R6 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMn-0007KV-FW for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:09 -0400 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:34529) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMm-0007Et-6Y for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:04 -0400 Received: by mail-oi1-x243.google.com with SMTP id f21-v6so10586605oig.1 for ; Wed, 31 Oct 2018 07:20: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 g9sm2829478otj.13.2018.10.31.07.20.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:52 -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=LCqg9TtpYEWEwSGoQ5XqwKE2YUIIttTnJxD/IURnpCEj/CjrUIRrHxdJPoLIBD3F/c CU00M2MTLobyuG8lDco0uDgnMlXKOcIevVhQp9NjykwPn33qq2z8k/JFkoTbKqefiRxX IZMZy8l+Q1OWsH+2w1yOpxIz9/pQhAAAchj/5nAkIjvk4+d2jzID/Dta7HYcI/IZGhLu 3bJe7yirEqyhRQZ7YWcVNtiwAuswA1azlrrf7ERUm3nqopHyqRKGanI43zAJV/RGTju2 gXttNiPkzm6pj8hI4mKyXbayCf3Il/2RbU/rRNYrqcoBYF4zHGnZaqYxGVvyTnmVUSvn U7bQ== 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=qg3uOtTlGWN/g+aKkya4ddrlYT0iwlUm/SV8o/I7KeKFSyEvbeahQ4sE4jprOwNin2 ZS0V7+9c5YGq6NZF1YkFFonxs0IFzwNMXey1Bdimae1VcLz214faJhpcRwUnxH9cLO8m 3M/PVE32hvsQXn+S6ivl7jRzlX/p35PNLAdSBicIuTcsI4RCi1nl8PFCWQnJvaSkTeYo lxeKkthHczEXAG47sBlN1KAiDcACXacaE5k7l+VX/Qb7gSnniV2XzfNpAZWJDCwirPhP dm7l8BTsfmVzyGmVnYf+Qfg4FRF7Pmv6qAYR/PhCQmvhfWmD6XqaF11Fh0Xjc94hsPqP JIWw== X-Gm-Message-State: AGRZ1gIL/Itn0VrkrxmsgBacyyYXSYiijLa70l9YqaJAEWT+8jApBx4t tDdJatKP/GwGt/Ewsa3jGwBuuD15 X-Google-Smtp-Source: AJdET5fbFDzKz+sjgCgr6sloUHmbi6ezTUWad+c/ykaFRUYEqnKzV3aMMuAcEECQfGsv4ABHDQ5/Bw== X-Received: by 2002:aca:d0d5:: with SMTP id j82-v6mr1981360oiy.170.1540995653776; Wed, 31 Oct 2018 07:20:53 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:02 -0500 Message-Id: <20181031141925.30026-2-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-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::243 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jonathon Reinhart Currently, the win32 port of QEMU Guest Agent does not properly handle Unic= ode paths. The JSON decoder produces a valid UTF-8 path string, but this is pas= sed directly to CreateFileA, which is expecting an ANSI string and not UTF-8. T= his 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 =3D -1; HANDLE fh; HANDLE templ_file =3D NULL; DWORD share_mode =3D FILE_SHARE_READ; DWORD flags_and_attr =3D FILE_ATTRIBUTE_NORMAL; LPSECURITY_ATTRIBUTES sa_attr =3D NULL; OpenFlags *guest_flags; + GError *gerr =3D NULL; + wchar_t *w_path =3D NULL; =20 if (!has_mode) { mode =3D "r"; @@ -175,16 +177,21 @@ int64_t qmp_guest_file_open(const char *path, bool ha= s_mode, guest_flags =3D find_open_flag(mode); if (guest_flags =3D=3D NULL) { error_setg(errp, "invalid file open mode"); - return -1; + goto done; + } + + w_path =3D g_utf8_to_utf16(path, -1, NULL, NULL, &gerr); + if (!w_path) { + goto done; } =20 - fh =3D CreateFile(path, guest_flags->desired_access, share_mode, sa_at= tr, + fh =3D CreateFileW(w_path, guest_flags->desired_access, share_mode, sa= _attr, guest_flags->creation_disposition, flags_and_attr, templ_file); if (fh =3D=3D INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open file '%s'", path); - return -1; + goto done; } =20 /* 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 ha= s_mode, if (fd < 0) { CloseHandle(fh); error_setg(errp, "failed to add handle to qmp handle table"); - return -1; + goto done; } =20 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; } =20 --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996308757686.7500780383351; Wed, 31 Oct 2018 07:31:48 -0700 (PDT) Received: from localhost ([::1]:59933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrX9-0003kY-Ee for importer@patchew.org; Wed, 31 Oct 2018 10:31:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMs-00016d-SA for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMr-0007M1-A1 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:10 -0400 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]:41966) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMq-0007LK-OB for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:08 -0400 Received: by mail-oi1-x235.google.com with SMTP id i10-v6so1385543oii.8 for ; Wed, 31 Oct 2018 07:21:07 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id v131-v6sm238954oig.27.2018.10.31.07.21.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21:04 -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=eU0aVBiYnvrCGPzBRGgI1FcmPEEKrRT0yk0TjQiVrbsmpFuVoKweBkna6TIxRlPvlO 4DCGKGYru7cWJAs/h50mLbxSXmGAit99pvm+0EsfYLCU1IoGZOfWLfv+67/pBh84Pi1o p/cajA2UD7aFt27q4QDx4d0w26i01IARa+UWp4yuGfqHHkuhbo9TEBsPsnmUQxLnqMud QBHW2SBJHx/W4UsWuyHQ2/16dMwkZpb42yR4MLGYGtKm7BZrwBjeEbjv4I/azy97rQip vi1AQdaziAlV7JZq/zk0xkAEjRvN5pADOaKaEUtNja9Tze/R+hbnAYZAyJdznP5hMUCC fhAw== 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=TsQln6uMNfG44FVL66H60o4zM70ww4iOZBJoW5u6rk2QyXPEG0tKj3uw5K1tD87ip5 p5WtNy5P5BuWHXIAt4/4g2+yGIQPlsk9CyBU/jGHpIofF3kih9yXunMgLeKPKUN9OLgX WxeQrKuD/+s5v+NalEGbrG99WBj+DRMpvbbYGJM4Nyhj+Fe1NJZYi6XEpS6OExRgbb8Q akII2+TjZxH7BM4jhe1ycmKfSIJj5GZwVwCibW6fUM80ySiWNBnhyJnoIZwKOTr1gJsH k7YV42F/Xa19Bm8AKAJ+Ut6qc0QI3NlGFrGzizNQt6PQNxF3fcAOCjLGfU6IXoOl/HuF I+TQ== X-Gm-Message-State: AGRZ1gKTew7Wqv3q4tXgK7lLf7tHhX1nKp/QI5jLMPz6xzy5mFz5ur1m 5KDrXd35kCwnpurh2QqMRZO/FU4J X-Google-Smtp-Source: AJdET5fgstBMcy0fqXmFsAwHxUsQJ1rSf5Fzfy9eJddalutU8gki3E+l07GqhEC8WyzkrlGtczxL2Q== X-Received: by 2002:aca:afcb:: with SMTP id y194-v6mr1808868oie.199.1540995665930; Wed, 31 Oct 2018 07:21:05 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:03 -0500 Message-Id: <20181031141925.30026-3-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-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::235 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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-vsback= up-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 =3D 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); =20 - 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; } =20 -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; } =20 - qga_vss_fsfreeze(&i, false, errp); + qga_vss_fsfreeze(&i, false, NULL, errp); =20 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 =3D (char **)list_unsupported; =20 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) } =20 /* 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 =3D freeze ? "requester_freeze" : "requester_tha= w"; QGAVSSRequesterFunc func; @@ -164,5 +165,5 @@ void qga_vss_fsfreeze(int *nr_volume, bool freeze, Erro= r **errp) return; } =20 - 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); =20 -void qga_vss_fsfreeze(int *nr_volume, bool freeze, Error **errp); +void qga_vss_fsfreeze(int *nr_volume, bool freeze, + strList *mountpints, Error **errp); =20 #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: } } =20 -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 =3D short_volume_name; DWORD wait_status; int num_fixed_drives =3D 0, i; + int num_mount_points =3D 0; =20 if (vss_ctx.pVssbc) { /* already frozen */ *num_vols =3D 0; @@ -337,39 +338,73 @@ void requester_freeze(int *num_vols, ErrorSet *errset) goto out; } =20 - volume =3D FindFirstVolumeW(short_volume_name, sizeof(short_volume_nam= e)); - if (volume =3D=3D INVALID_HANDLE_VALUE) { - err_set(errset, hr, "failed to find first volume"); - goto out; - } - for (;;) { - if (GetDriveTypeW(short_volume_name) =3D=3D DRIVE_FIXED) { + if (mountpoints) { + PWCHAR volume_name_wchar; + for (volList *list =3D (volList *)mountpoints; list; list =3D list= ->next) { + size_t len =3D strlen(list->value) + 1; + size_t converted =3D 0; VSS_ID pid; - hr =3D vss_ctx.pVssbc->AddToSnapshotSet(short_volume_name, + + volume_name_wchar =3D new wchar_t[len]; + mbstowcs_s(&converted, volume_name_wchar, len, + list->value, _TRUNCATE); + + hr =3D 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_na= me) { - display_name =3D 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 =3D=3D 0) { + /* If there is no valid mount points, just exit. */ + goto out; } } =20 - if (num_fixed_drives =3D=3D 0) { - goto out; /* If there is no fixed drive, just exit. */ + if (!mountpoints) { + volume =3D FindFirstVolumeW(short_volume_name, sizeof(short_volume= _name)); + if (volume =3D=3D INVALID_HANDLE_VALUE) { + err_set(errset, hr, "failed to find first volume"); + goto out; + } + + for (;;) { + if (GetDriveTypeW(short_volume_name) =3D=3D DRIVE_FIXED) { + VSS_ID pid; + hr =3D 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 =3D 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 =3D=3D 0) { + goto out; /* If there is no fixed drive, just exit. */ + } } =20 hr =3D vss_ctx.pVssbc->PrepareForBackup(pAsync.replace()); @@ -435,7 +470,12 @@ void requester_freeze(int *num_vols, ErrorSet *errset) goto out; } =20 - *num_vols =3D vss_ctx.cFrozenVols =3D num_fixed_drives; + if (mountpoints) { + *num_vols =3D vss_ctx.cFrozenVols =3D num_mount_points; + } else { + *num_vols =3D vss_ctx.cFrozenVols =3D num_fixed_drives; + } + return; =20 out: @@ -449,7 +489,7 @@ out1: } =20 =20 -void requester_thaw(int *num_vols, ErrorSet *errset) +void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset) { COMPointer pAsync; =20 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); =20 -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); =20 #ifdef __cplusplus } --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996861654512.3252901844514; Wed, 31 Oct 2018 07:41:01 -0700 (PDT) Received: from localhost ([::1]:59987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrfx-0005as-Q9 for importer@patchew.org; Wed, 31 Oct 2018 10:40:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMx-0001CC-VA for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMs-0007N0-C3 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:14 -0400 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]:39522) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMs-0007Ly-5c for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:10 -0400 Received: by mail-oi1-x244.google.com with SMTP id e3-v6so13739958oiy.6 for ; Wed, 31 Oct 2018 07:21: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 z53sm10245353otz.0.2018.10.31.07.21.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21: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 :mime-version:content-transfer-encoding; bh=IyZMeptQhY8QjDMqhWNkZZuHVaNTU7U8+5/FjdMQJl8=; b=Av7E33FYSgXh1I78M5DFNo8xDR0zrtBMA/H5SPsMn5T8uPSLBGg0R9yPRwoUtAkCHK JcrLipdRQHzAIU+eeLah5U56Olwnz+E2B19f++992eMDAooS8vKQjQCvzf8ob6XzLQbw mkXA85pfgg035d+Ul5ZaYfJyl2ime1biZnNVzI33qjTmuYGQt6C5GETvj46rf2urMXkl gKqSfCKhJbi8JEnGy6N7cl8273/dYnwvgZDu8usZwzxsvt7SsJknJqiku/eLnDyqdvCJ UplCiey7EkFYLrrBs52jspyNoavVftR5Rny6plBTDNSJsZHuMO14c5rkU88zEMEhjBu1 63XQ== 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=exa0H7xhmHXn/iAezv5lbHTagxI8sgVSP0+IIdQxGGX5LSTNuSXMvzveI03uDKg+QA cljYUzCeXq7v58zjk3zdWigUTTukYEnlqA7f/IjWbZw8uXpQX1G3ILCvdCO9aIcdR6WB Xg35Nrknjz62Wk9/ha2KtVM54NFs81ZdLdO726sKVEjTok5dK6yu5+rQwIZC6K38fARj WaMLYFhGgel2FMuR25FmSufjZF1uev5CTWlXfFT6AhRL8251csmGv4a6xXAQuQJwHGck U5bOEBmsSwt6TbNXIVHUATVoHS+9B32pBEo8tied5NBIUR1LOh90+iDEDsRd+ds4RPFR 6JNw== X-Gm-Message-State: AGRZ1gIsZaYSxsyZYzVJq5OGr3Jy9HmIVnlHc+SeR2E8SEMWDFUyycx2 0ukIQPFHW5WQlDBMgt0xBwD+WNMT X-Google-Smtp-Source: AJdET5fsi7WvGnNhzHpIgR7w/u8Q4uvIo/waou9VLfUQeSURhB4Z27smyE6Iy60YUIeJQcUsM8RQhA== X-Received: by 2002:a54:4390:: with SMTP id u16-v6mr1986506oiv.186.1540995668152; Wed, 31 Oct 2018 07:21:08 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:04 -0500 Message-Id: <20181031141925.30026-4-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::244 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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-vc= pus': 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=C3=A9 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 *nam= e_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[] =3D "online"; =20 - dirpath =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/", - vcpu->logical_id); dirfd =3D open(dirpath, O_RDONLY | O_DIRECTORY); if (dirfd =3D=3D -1) { error_setg_errno(errp, errno, "open(\"%s\")", dirpath); - } else { - static const char fn[] =3D "online"; - int fd; - int res; - - fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); - if (fd =3D=3D -1) { - if (errno !=3D ENOENT) { - error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, = fn); - } else if (sys2vcpu) { - vcpu->online =3D true; - vcpu->can_offline =3D 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 =3D pread(fd, &status, 1, 0); - if (res =3D=3D -1) { - error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath,= fn); - } else if (res =3D=3D 0) { - error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpa= th, - fn); - } else if (sys2vcpu) { - vcpu->online =3D (status !=3D '0'); - vcpu->can_offline =3D true; - } else if (vcpu->online !=3D (status !=3D '0')) { - status =3D '0' + vcpu->online; - if (pwrite(fd, &status, 1, 0) =3D=3D -1) { - error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dir= path, - fn); - } - } /* otherwise pretend successful re-(on|off)-lining */ + return; + } =20 - res =3D close(fd); - g_assert(res =3D=3D 0); - } + fd =3D openat(dirfd, fn, sys2vcpu ? O_RDONLY : O_RDWR); + if (fd =3D=3D -1) { + if (errno !=3D ENOENT) { + error_setg_errno(errp, errno, "open(\"%s/%s\")", dirpath, fn); + } else if (sys2vcpu) { + vcpu->online =3D true; + vcpu->can_offline =3D 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 =3D pread(fd, &status, 1, 0); + if (res =3D=3D -1) { + error_setg_errno(errp, errno, "pread(\"%s/%s\")", dirpath, fn); + } else if (res =3D=3D 0) { + error_setg(errp, "pread(\"%s/%s\"): unexpected EOF", dirpath, + fn); + } else if (sys2vcpu) { + vcpu->online =3D (status !=3D '0'); + vcpu->can_offline =3D true; + } else if (vcpu->online !=3D (status !=3D '0')) { + status =3D '0' + vcpu->online; + if (pwrite(fd, &status, 1, 0) =3D=3D -1) { + error_setg_errno(errp, errno, "pwrite(\"%s/%s\")", dirpath, + fn); + } + } /* otherwise pretend successful re-(on|off)-lining */ =20 - res =3D close(dirfd); + res =3D close(fd); g_assert(res =3D=3D 0); } =20 - g_free(dirpath); + res =3D close(dirfd); + g_assert(res =3D=3D 0); } =20 GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) @@ -2107,17 +2102,21 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Erro= r **errp) while (local_err =3D=3D NULL && current < sc_max) { GuestLogicalProcessor *vcpu; GuestLogicalProcessorList *entry; - - vcpu =3D g_malloc0(sizeof *vcpu); - vcpu->logical_id =3D current++; - vcpu->has_can_offline =3D true; /* lolspeak ftw */ - transfer_vcpu(vcpu, true, &local_err); - - entry =3D g_malloc0(sizeof *entry); - entry->value =3D vcpu; - - *link =3D entry; - link =3D &entry->next; + int64_t id =3D current++; + char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", + id); + + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + vcpu =3D g_malloc0(sizeof *vcpu); + vcpu->logical_id =3D id; + vcpu->has_can_offline =3D true; /* lolspeak ftw */ + transfer_vcpu(vcpu, true, path, &local_err); + entry =3D g_malloc0(sizeof *entry); + entry->value =3D vcpu; + *link =3D entry; + link =3D &entry->next; + } + g_free(path); } =20 if (local_err =3D=3D NULL) { @@ -2138,7 +2137,11 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorLis= t *vcpus, Error **errp) =20 processed =3D 0; while (vcpus !=3D NULL) { - transfer_vcpu(vcpus->value, false, &local_err); + char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", + vcpus->value->logical_id); + + transfer_vcpu(vcpus->value, false, path, &local_err); + g_free(path); if (local_err !=3D NULL) { break; } --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540997394813402.63680058291686; Wed, 31 Oct 2018 07:49:54 -0700 (PDT) Received: from localhost ([::1]:60043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrof-0007NA-8y for importer@patchew.org; Wed, 31 Oct 2018 10:49:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrNS-0001X4-Mx for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrNO-0007c8-Rb for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:46 -0400 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]:45546) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrNN-0007Nf-3K for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:42 -0400 Received: by mail-oi1-x232.google.com with SMTP id p144-v6so9840378oic.12 for ; Wed, 31 Oct 2018 07:21:11 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id v131-v6sm239084oig.27.2018.10.31.07.21.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gM9bIEC86ruumo18/CYbGRbIeu+lifiq4ffb5gYPTqI=; b=XWUMv5+9UxRVkQR6V6+jXhOQ78bRa6+/4pKOpeYZgRhZLFmcwBOUceTp8IESgbbr6v DP8ULZauIu44vWfYKYL+fP8cBE9G+7Hizin9QFxsW39d/dtlrVogFwBiglMBDtZidFKy MJBFoayC2vJ1GkoNDoj5gK3UvDDkLw99t2cfKxYq4dqQlhMu5Cadj924tVJ/m/JoTofl Sy86nytcQuI2RhXiOgd7RZJOEST+/jKKCI8FNOjHFtz17qC068jdFb7GTqJH3DwWqVH/ iEeoDw8IR7JTUu8uo+DmOMM+b4xV8zBiZotHkxe0p1dFlIFTE+ZiJFQH6rI3uV/Y4wO0 z8zg== 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=gM9bIEC86ruumo18/CYbGRbIeu+lifiq4ffb5gYPTqI=; b=pKg6yyZrbPclmb1LShZELoXWKAQKzBjpEDa7cC1BgGa/V/BILYUAhlJamJ9AT6riIA 2xXXY9psvNeEvpPy4A6cOWFXEBFX1lXZFJrnMzf7hAANPWZlDjVLVJ02MHt7HI+hMUOi J2LXSC2MB/OYnMNFKnJJmgfY5kRVd/Bj4kAvmLI1DFgEU6atwREprpCNOr7VYbpMDY5+ Jg8U7sl+PxADzNxZqBeTL7ns3BCDC2sRxI1aVh++LdS9riBBGfV/88gv8TcqkseW77c4 9eYk0SzpK6mmyDrfK/n1Ak8OTfDoIJBO81S+18BtfaIimVvrDHPlxJmkqZgQWpySRWTu Of0w== X-Gm-Message-State: AGRZ1gJmyviXjhU+dniW3YG4SekVZR6ofzDr3iqhwOxnst4RnR7C36gd gqv5s6Nt0JrruOXSt7B0bkldvYSC X-Google-Smtp-Source: AJdET5cVroG/Q/Pgghl56f/z8gI1zZP2lqWIjUj6bg+c7GdZATFJ/burtKr8dqLs++KTCxFa9KvMKQ== X-Received: by 2002:aca:5f43:: with SMTP id t64-v6mr1780649oib.115.1540995670373; Wed, 31 Oct 2018 07:21:10 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:05 -0500 Message-Id: <20181031141925.30026-5-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::232 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Reviewed-by: Marc-Andr=C3=A9 Lureau *make libudev optional to avoid breaking existing build/test environments *disable libudev for --static builds Signed-off-by: Michael Roth --- configure | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/configure b/configure index a898e21c68..61276982c6 100755 --- a/configure +++ b/configure @@ -474,6 +474,7 @@ libxml2=3D"" docker=3D"no" debug_mutex=3D"no" libpmem=3D"" +libudev=3D"no" =20 # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64=3D"aarch64-linux-gnu-gcc" @@ -870,6 +871,7 @@ Linux) vhost_vsock=3D"yes" QEMU_INCLUDES=3D"-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QE= MU_INCLUDES" supported_os=3D"yes" + libudev=3D"yes" ;; esac =20 @@ -5609,6 +5611,17 @@ if test "$libnfs" !=3D "no" ; then fi fi =20 +########################################## +# Do we have libudev +if test "$libudev" !=3D "no" ; then + if $pkg_config libudev && test "$static" !=3D "yes"; then + libudev=3D"yes" + libudev_libs=3D$($pkg_config --libs libudev) + else + libudev=3D"no" + fi +fi + # Now we've finished running tests it's OK to add -Werror to the compiler = flags if test "$werror" =3D "yes"; then QEMU_CFLAGS=3D"-Werror $QEMU_CFLAGS" @@ -6033,6 +6046,7 @@ echo "VxHS block device $vxhs" echo "capstone $capstone" echo "docker $docker" echo "libpmem support $libpmem" +echo "libudev $libudev" =20 if test "$sdl_too_old" =3D "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -6868,6 +6882,11 @@ if test "$docker" !=3D "no"; then echo "HAVE_USER_DOCKER=3Dy" >> $config_host_mak fi =20 +if test "$libudev" !=3D "no"; then + echo "CONFIG_LIBUDEV=3Dy" >> $config_host_mak + echo "LIBUDEV_LIBS=3D$libudev_libs" >> $config_host_mak +fi + # use included Linux headers if test "$linux" =3D "yes" ; then mkdir -p linux-headers --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996582561809.244093933508; Wed, 31 Oct 2018 07:36:22 -0700 (PDT) Received: from localhost ([::1]:59955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrbZ-0000AC-D3 for importer@patchew.org; Wed, 31 Oct 2018 10:36:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrNU-0001Yx-Ee for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrNT-0007eX-Jq for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:48 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]:36636) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrNT-0007OW-BU for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:47 -0400 Received: by mail-oi1-x22c.google.com with SMTP id r127-v6so12003127oie.3 for ; Wed, 31 Oct 2018 07:21:13 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id i62-v6sm5067846oif.37.2018.10.31.07.21.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21: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=ANbaKq6jbZhZybVA7mJIDsdQslcijwVNxDlVYklzAFc=; b=HvE90RNhIObuAsKNpRJw7RZPgV1zaAde6IrkqocdEAEcWR5bxGCtNggz/J0DaL1xID wiz9ImLKj1EeQc+4dOIuMergpG8Xm3Zy2Z7Xp//Fw8AsOmmO3LWOkkN+un2lPKWUVbrr 7BfFjQ/aHICyh9abHFlqe0AwIWpzjMmMDbf/lrsEAhEf2tyYpfOF8NtnRF1eRRjNWRCR SpPKSRpOJVjEoYxhD4xS+I//7JWqXkfGjjouTjwDLhVKBoA6ebekEHCBoLH/zZsQP7ev TZMvX8FlZ/SBa3wYgvhpgng7aJfExh0SuAAr7iajaPDlpsx0MuZn/IM1f+6iv8sFrUhI FTgw== 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=UznQfxF44JI5CIwJAMJiJ71ukubrd7kkHhzFGjsIncDAkYOxXk2wSRdwPbZdQeSGVH cLVpZRA4VPLKo/hrec/UVY6t4JCwJXSFlaPXCCH+kEjRRxI6JW1CnHUEHWEU06LhylEr cat3+DtSLMVPUoCplgnVX59+r3/uzEvP/tspug8rBa7BjuW61nZxshH5hOFXIlfuQ+f5 Lzb5HLFQen+FEgwn2mC2urHZcClXZUrW2wmu+P/JB00kzqHBca6SF+Sp/ppLc1OqhFLl sTht8y2BFFJ0exEc99yqb8QwS5LRhSv292aPOBLAcTcz5oQuEO7c40NmuJqhAl+JC7w2 TINA== X-Gm-Message-State: AGRZ1gJdKO9WrDtB60tg7OtBICKCRgi/4kwr5G1nCHcwXM7k33h2qKnz sceNBBnWOeFjABBgN8N3Bj7QsFN7 X-Google-Smtp-Source: AJdET5dDTuP+JqAhdCelJVicRVoXR63u+UelzO/fUpYQJefqXe2wav2u6XE4OiUs3FSAIfAV+08WdQ== X-Received: by 2002:aca:aa84:: with SMTP id t126-v6mr1994487oie.218.1540995672542; Wed, 31 Oct 2018 07:21:12 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:06 -0500 Message-Id: <20181031141925.30026-6-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::22c Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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=C3=A1=C5=A1 Golembiovsk=C3=BD 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 :=3D $(LIBUDEV_LIBS) qga-obj-y =3D commands.o guest-agent-command-state.o main.o qga-obj-$(CONFIG_POSIX) +=3D commands-posix.o channel-posix.o qga-obj-$(CONFIG_WIN32) +=3D commands-win32.o channel-win32.o service-win3= 2.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 =20 +#ifdef CONFIG_LIBUDEV +#include +#endif + #ifdef FIFREEZE #define CONFIG_FSFREEZE #endif @@ -872,6 +876,10 @@ static void build_guest_fsinfo_for_real_device(char co= nst *syspath, GuestDiskAddressList *list =3D NULL; bool has_ata =3D false, has_host =3D false, has_tgt =3D false; char *p, *q, *driver =3D NULL; +#ifdef CONFIG_LIBUDEV + struct udev *udev =3D NULL; + struct udev_device *udevice =3D NULL; +#endif =20 p =3D 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 co= nst *syspath, list =3D g_malloc0(sizeof(*list)); list->value =3D disk; =20 +#ifdef CONFIG_LIBUDEV + udev =3D udev_new(); + udevice =3D udev_device_new_from_syspath(udev, syspath); + if (udev =3D=3D NULL || udevice =3D=3D NULL) { + g_debug("failed to query udev"); + } else { + const char *serial; + serial =3D udev_device_get_property_value(udevice, "ID_SERIAL"); + if (serial !=3D NULL && *serial !=3D 0) { + disk->serial =3D g_strdup(serial); + disk->has_serial =3D true; + } + } +#endif + if (strcmp(driver, "ata_piix") =3D=3D 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, =20 list->next =3D fs->disk; fs->disk =3D list; - g_free(driver); - return; + goto out; =20 cleanup: if (list) { qapi_free_GuestDiskAddressList(list); } +out: g_free(driver); +#ifdef CONFIG_LIBUDEV + udev_unref(udev); + udev_device_unref(udevice); +#endif + return; } =20 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'} } =20 ## # @GuestFilesystemInfo: --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996520840289.49678036128614; Wed, 31 Oct 2018 07:35:20 -0700 (PDT) Received: from localhost ([::1]:59945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHraS-0007hd-69 for importer@patchew.org; Wed, 31 Oct 2018 10:35:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrNS-0001X6-Nh for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrNQ-0007cy-VK for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:46 -0400 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:43430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrNO-0007QA-RU for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:43 -0400 Received: by mail-ot1-x341.google.com with SMTP id k9so14659673otl.10 for ; Wed, 31 Oct 2018 07:21:16 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 69sm2720915otc.23.2018.10.31.07.21.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21:13 -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=RwP9J8ZsTfs1eJqD5N8TaULfxCKDxA0xkStzUIJ8R7hfidxtWd78K8ZR+4S4v50UUe HIX0xXMa5wN2H9o8pQnQOa6Y/Ku+MhB7cLClZvXiQke8N6w/IO+AStx8OnqL6bx3z9xH vS+MYmWbriHGvR7DdotcBCzpXGgcthWXCSoeDyJ9UAyEmP+tSzNzpmbuZIWssmGxUwt3 mklN2OjajTexVuCL6bTqLRe4utwsOxdPWndf82Chj+KAoKaUl7llC3DKbyvX7NaMfrrc p1Cn47PhC4t1oSqI7U29Yy/L5wdJkoRRMT58VJ1lQ9mI9cu74Mu8wSV8gtiVgSFfsy+u oB4A== 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=eMcF2lX6CrgKCYJ+HfNhodDj2LxGv8HHTGPCf8rWNJhTFwIbW2ojbEjjBjhvWP1RlP FBeioZka1JFfmKlgNNtGVZ5vJMQ//lJFyXzeH5MXhcz/7qJzGuhhMf3RxD6Htgm0ZCRC IKkZv8t7AREf/ahfx8waiNTo/ypg9jFW8cvcr4Bh+k5kErrA9nRxDj8zD40ouQ8tH4Zf JLqYRq6mn9yPkDDjylJU1tLezccqTerfgDAi+ovlmATLlxZX2jX2ucrpJIxYLm3KzQ/g YggGhBtvJUmTrBxwbasu20sooqbPJaNxutyKvp+gPKWQU8dABXIXtPvUJUD56YnUwSg6 w47A== X-Gm-Message-State: AGRZ1gLLS94RffM8AqD7ulksknX7/TO1vdfJ610VhL8MO67n9g2xZYp5 cOqz7F+iKYrE4x7d25NxWGfg+Q3e X-Google-Smtp-Source: AJdET5fRlq4hKUvij84qJowgs5WLwaREMus2EYuyQ2i3LMnnBzj8KwlmAOKAUVKQUiQRLUSYxsS+Ow== X-Received: by 2002:a9d:3c0c:: with SMTP id q12mr1835610otc.63.1540995674696; Wed, 31 Oct 2018 07:21:14 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:07 -0500 Message-Id: <20181031141925.30026-7-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::341 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Report device node of the disk on Linux (e.g. "/dev/sda2"). Requirs libudev. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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 co= nst *syspath, if (udev =3D=3D NULL || udevice =3D=3D NULL) { g_debug("failed to query udev"); } else { - const char *serial; + const char *devnode, *serial; + devnode =3D udev_device_get_devnode(udevice); + if (devnode !=3D NULL) { + disk->dev =3D g_strdup(devnode); + disk->has_dev =3D true; + } serial =3D udev_device_get_property_value(udevice, "ID_SERIAL"); if (serial !=3D NULL && *serial !=3D 0) { disk->serial =3D 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'} } =20 ## # @GuestFilesystemInfo: --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540997195476291.9244846931988; Wed, 31 Oct 2018 07:46:35 -0700 (PDT) Received: from localhost ([::1]:60023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrlQ-0003Wp-9z for importer@patchew.org; Wed, 31 Oct 2018 10:46:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrNN-0001UA-2U for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrNL-0007am-EO for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:40 -0400 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]:37005) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrNH-0007Rw-BM for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:35 -0400 Received: by mail-oi1-x244.google.com with SMTP id w66-v6so9427619oiw.4 for ; Wed, 31 Oct 2018 07:21: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 c7-v6sm9000315oia.58.2018.10.31.07.21.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OMsafrgRN8K7qYrDHmXKNcug1Hah0nOGn2aWbm0aBsM=; b=bfsalCBrCvDRS2Af8vEzs38WUdVPA3nwhuTt5rzeiysNB6pO+3/iWjyrHGt3wVmFyH 51/B6tmKEccyFaeet5yhFes4dPKySw9pCsGcicfZKLTKYdvJcm7ZPUix+9MqwzzcpfOQ P1RigdYz2EcBlY5ZTVUK3XHby8ljz0VL3exTTbLVmYT1dfEvdKEo88JmG8hwYTRr+Jcx oaNp9UIECJ2T2gicCztU5W8dUG/Z7YlDkrYsZtGcbt5ArR2+aRY/BrlFR5LecnT5LcRj qWaHubSsURN+EALbPLescwMTHn3fwP+7l7fPgwqXiqmkMAfVh9Swtz2vF2mXKz8rH0m0 l4uQ== 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=nuIIFlL5AmyWAKCtXN1s735VcpnIk+MGXjbFYA4EULyxiHvfQaYn79EqoLNF9uuyxC u8UftMDTcuTcKMBKMOAKCdcsukxNz5eUsM2CJgcyoQPOpLrVSTIzTBR2QMZVeJCx2GkQ kG2kOaIiQWTCqGld8xDq/5oncpXVZV85+s8tuyLp/oQM7es5on5nSpKYVw//cRAmTqd6 3jEXx/xCeC4tNNfREqVvqVKQX7yd4wVrFDRmcMoC2QV9Q3ER9Ydp2tQEiiNym21g0v0k 6j0tiIdCHUpdso8RYi4PxK6jyz7R9evbnlpgzi4qUGMR2bEQD0/KNtNKPUD3hT2BoIwL /Y9A== X-Gm-Message-State: AGRZ1gLbJ5Iv/pKfWKlCFNR1AscSuSro1hLSgTweXtjGWPyE3yC5fWBG fH+ju/OQuILrKg7hajNAUTjaDkON X-Google-Smtp-Source: AJdET5drz1dgFh+xdvnnxyQBIGkWF+T7mjD6bx3ww6EebmoXtoPo4ZGrB5lSI8WHCF9b7mkjLpqf9w== X-Received: by 2002:a54:4607:: with SMTP id p7-v6mr1845959oip.126.1540995676885; Wed, 31 Oct 2018 07:21:16 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:08 -0500 Message-Id: <20181031141925.30026-8-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::244 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 mess= age: Reviewed-by: Philippe Mathieu-Daud=C3=A9 ------------------------------------------------ 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=C3=A9 Signed-off-by: Michael Roth Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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 =3D NULL; GuestPCIAddress *pci =3D NULL; char *name =3D g_strdup(&guid[4]); + pci =3D g_malloc0(sizeof(*pci)); + pci->domain =3D -1; + pci->slot =3D -1; + pci->function =3D -1; + pci->bus =3D -1; =20 if (!QueryDosDevice(name, dev_name, ARRAY_SIZE(dev_name))) { error_setg_win32(errp, GetLastError(), "failed to get dos device n= ame"); @@ -570,7 +575,6 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) =20 func =3D addr & 0x0000FFFF; dev =3D (addr >> 16) & 0x0000FFFF; - pci =3D g_malloc0(sizeof(*pci)); pci->domain =3D dev; pci->slot =3D slot; pci->function =3D func; --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15409970254199.427193076048866; Wed, 31 Oct 2018 07:43:45 -0700 (PDT) Received: from localhost ([::1]:60001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrii-00005U-2g for importer@patchew.org; Wed, 31 Oct 2018 10:43:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrNM-0001U2-UB for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrNF-0007Yv-OW for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:40 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]:44769) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrND-0007Tg-9L for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:31 -0400 Received: by mail-ot1-x330.google.com with SMTP id p23so14663960otf.11 for ; Wed, 31 Oct 2018 07:21:20 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id o189-v6sm7391722oih.15.2018.10.31.07.21.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21: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 :mime-version:content-transfer-encoding; bh=jqJy8O/Q/q3DF/vRTGPc19Bl200H+tWJBLN5cD9F4O8=; b=NddRb8ca1Spd7L8C4nr8hkNwYu+RHyWTJXiCjzCorIWql/E19ZQ+JLlxAnUUmsSNvy asS7n0f+MXXq8C0PU6vtzmfGn1C+47X4i3+V6Hn7ExWIUxgSPO3dV2/C/j7oSrDN9ASQ j0+gGODAJCOSRIiDUZVWbtJrjjJMR2MVQGKLllGhWa085aBKTlWm3wwyGHqetR6mjGWN EGFN8SG41irKzXDm2pva6horjhRqVcsEsWPCGEpjCXPj3nI8vhbhznYkEg0Z9q0kRyFl uCMCi5FUAcSg4lhgo5J6Cu+SK7VQzxe1isZcAVtNH4GRbQSFk3lI2pJvTqbxLq7ze2Tw 03Eg== 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=EUFhX7SfWIntym9FHhDzFvTxwpSvKYrzY2KrJ3XAZE6/wgP6053h021Aov5jMxTybW ehREGtPJ4zn1G6CCdVd0MalehG1Seex2YRbC5S9x8qyOENeWNq7aW05imF6yb12mixoQ LXJhxEdn6R1cdDLUY8K0WVoS4ptXlFRBoxW+QxojOqa/48yRGN6PLGZHMxJbFjTwZu7b 714nJQ20IkPYb6Cy1pSFqnkIx5NO74p48xoK4GIG9puKEMAMDzJzixbVEM/LHrbscc+R uyDiJeTcrgjyP3jgYmiUZRKDy2VRAFiikqQVBZNSAoeefXgny5GkvaifBJmWY7KgobXK H3RQ== X-Gm-Message-State: AGRZ1gIeyNE0iXVL7Hi2nQcQRj0IToXcrVGF5QDSYWsZqOgHX0e4zYkd RTf1YyNvSxYPFCq5Us6U4UqPLb1Y X-Google-Smtp-Source: AJdET5f+E8dzEAWnYuSeKb+Ko5XGkrgevGe0vOIyDGEfPvUwh8mEywiAegqKER0QSSic8UqBDrTuBA== X-Received: by 2002:a9d:2ff1:: with SMTP id b46mr1857603otd.69.1540995679013; Wed, 31 Oct 2018 07:21:19 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:09 -0500 Message-Id: <20181031141925.30026-9-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::330 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A1=C5=A1 Golembiovsk=C3=BD *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 =3D NULL; GuestPCIAddress *pci =3D NULL; char *name =3D g_strdup(&guid[4]); + bool partial_pci =3D false; pci =3D g_malloc0(sizeof(*pci)); pci->domain =3D -1; pci->slot =3D -1; @@ -519,7 +520,8 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) =20 dev_info_data.cbSize =3D sizeof(SP_DEVINFO_DATA); for (i =3D 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_N= AME, &data, (PBYTE)buffer, size, @@ -549,21 +551,24 @@ static GuestPCIAddress *get_pci_info(char *guid, Erro= r **errp) */ if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_BUSNUMBER, &data, (PBYTE)&bus, size, NULL)) { - break; + bus =3D -1; + partial_pci =3D true; } =20 /* 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 =3D -1; + partial_pci =3D true; } =20 /* 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 =3D -1; + partial_pci =3D true; } =20 /* SetupApi gives us the same information as driver with @@ -573,12 +578,19 @@ static GuestPCIAddress *get_pci_info(char *guid, Erro= r **errp) * DeviceNumber =3D (USHORT)(((propertyAddress) >> 16) & 0x0000FFF= F); * SPDRP_ADDRESS is propertyAddress, so we do the same.*/ =20 - func =3D addr & 0x0000FFFF; - dev =3D (addr >> 16) & 0x0000FFFF; - pci->domain =3D dev; - pci->slot =3D slot; - pci->function =3D func; - pci->bus =3D bus; + if (partial_pci) { + pci->domain =3D -1; + pci->slot =3D -1; + pci->function =3D -1; + pci->bus =3D -1; + } else { + func =3D ((int) addr =3D=3D -1) ? -1 : addr & 0x0000FFFF; + dev =3D ((int) addr =3D=3D -1) ? -1 : (addr >> 16) & 0x0000FFF= F; + pci->domain =3D dev; + pci->slot =3D (int) slot; + pci->function =3D func; + pci->bus =3D (int) bus; + } break; } =20 @@ -622,6 +634,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) DWORD len; int bus; HANDLE vol_h; + Error *local_err =3D NULL; =20 scsi_ad =3D &addr; char *name =3D g_strndup(guid, strlen(guid)-1); @@ -640,6 +653,16 @@ static GuestDiskAddressList *build_guest_disk_info(cha= r *guid, Error **errp) =20 disk =3D g_malloc0(sizeof(*disk)); disk->bus_type =3D find_bus_type(bus); + /* always set pci_controller as required by schema. get_pci_info() sho= uld + * report -1 values for non-PCI buses rather than fail. fail the comma= nd + * if that doesn't hold since that suggests some other unexpected + * breakage + */ + disk->pci_controller =3D get_pci_info(name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out_close; + } if (bus =3D=3D BusTypeScsi || bus =3D=3D BusTypeAta || bus =3D=3D BusT= ypeRAID #if (_WIN32_WINNT >=3D 0x0600) /* This bus type is not supported before Windows Server 2003 S= P1 */ @@ -654,12 +677,9 @@ static GuestDiskAddressList *build_guest_disk_info(cha= r *guid, Error **errp) disk->unit =3D addr.Lun; disk->target =3D addr.TargetId; disk->bus =3D addr.PathId; - disk->pci_controller =3D 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 =3D NULL; } =20 list =3D g_malloc0(sizeof(*list)); --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996144875919.9196211884182; Wed, 31 Oct 2018 07:29:04 -0700 (PDT) Received: from localhost ([::1]:59917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrUQ-0001VK-BM for importer@patchew.org; Wed, 31 Oct 2018 10:28:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMf-0000vB-7N for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMa-0007DW-Hl for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:55 -0400 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:42710) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMa-0006v6-6j for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:52 -0400 Received: by mail-ot1-x343.google.com with SMTP id j3so8869805otl.9 for ; Wed, 31 Oct 2018 07:20:25 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id m65-v6sm9031059oif.45.2018.10.31.07.20.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20: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=kPRjs/isTOkv09ltsDbUFAShE5SdXioSBw8XjJCetxo=; b=nHL+MnODtlo0YtY2axjB/ue2DsgEstg/usdRbmbVKefpEXjLFWNlPVxibjavV4Z9SX u2dqwrCKwS/VJK1Fmzd49bb94LsCDdNY41G13zGu+dcxb0JboBRF/O3V0s5KZnjYNpFk oRMjxWslo4vItNJCR8rpEaojWlCIcccVKaBJztOLMXJjAGO0y3hYGF5dqZX/D/sffg24 tt1IbYGPTyHHh2tgpvND4KE670yTLtVkje6QF4GHWo4rF3+z3L2XwUct9+yiLmjjCRv1 S00xScKZRvaz6dZWZmt9ZHzNVuDpzTLDdBkrSYm+/yTOFlmMaYEMEW+JwHMpV6RZmE0g oWxA== 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=kPRjs/isTOkv09ltsDbUFAShE5SdXioSBw8XjJCetxo=; b=b72PZfqKhLyruJoGcKl81Y0IyU+J3F065nw1sku4MWGUBZ8jFvBg7zNq50u5WMCpSB IMPCJG+MOI0YvOJfRZM6uhIzv8wpQCmHhlZq0HTvLHN6QlOvx6uQwhPu1nxwLqHZn0VS tSq3MsUuJ3PiFBlBrCBMJuw/7l1sbSy+C30GM4R30+vOGsqZzwJ7z3McaH0ef1yjT5zy tmLIhwW5B2KpJ8kXUqqCwSOVXFr4tlm5GKzFoG/dWXj2kq6b5DDdRm0wk6YKNigfPiin eHZgkiFRkPRSZcM4AqLIAGkMrvHa6YvakyK4RPr8eTo1XQZFmBiOohPtNlPoujCjkkW0 rKRg== X-Gm-Message-State: AGRZ1gIX3dgyxpNF/FHLDi+NT2vVgnxaFrn/DZ6xLmoVnNbQXXF+kxJo QL8Dg1HJ6CHFz/XZ6qaq9LPq1xoq X-Google-Smtp-Source: AJdET5cR2QuQcentJ/pchPU8uRDVhhLanheCeziq53Y6FmJD9+H9WXgKujSRqYv46CIbJb4nl/jEyw== X-Received: by 2002:a9d:38b9:: with SMTP id p54mr2038517otc.303.1540995623227; Wed, 31 Oct 2018 07:20:23 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:10 -0500 Message-Id: <20181031141925.30026-10-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::343 Subject: [Qemu-devel] [PULL v3 09/24] build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD There was inconsistency between commits: 50cbebb9a3 configure: add configure check for ntdddisk.h a3ef3b2272 qga: added bus type and disk location path The first commit added #define CONFIG_QGA_NTDDDISK but the second commit expected the name to be CONFIG_QGA_NTDDSCSI. As a result the code in second patch was never used. Renaming the option to CONFIG_QGA_NTDDSCSI to match the name of header file that is being checked for. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Sameeh Jubran Signed-off-by: Michael Roth --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 61276982c6..95f3d44ecd 100755 --- a/configure +++ b/configure @@ -6142,7 +6142,7 @@ if test "$mingw32" =3D "yes" ; then echo "WIN_SDK=3D\"$win_sdk\"" >> $config_host_mak fi if test "$guest_agent_ntddscsi" =3D "yes" ; then - echo "CONFIG_QGA_NTDDDISK=3Dy" >> $config_host_mak + echo "CONFIG_QGA_NTDDSCSI=3Dy" >> $config_host_mak fi if test "$guest_agent_msi" =3D "yes"; then echo "QEMU_GA_MSI_ENABLED=3Dyes" >> $config_host_mak --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996526906653.0461977814402; Wed, 31 Oct 2018 07:35:26 -0700 (PDT) Received: from localhost ([::1]:59947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHraY-0007mg-ST for importer@patchew.org; Wed, 31 Oct 2018 10:35:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMf-0000vG-7i for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMZ-0007CH-E9 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:55 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:33790) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMY-0006wi-Uo for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:51 -0400 Received: by mail-oi1-x231.google.com with SMTP id c25-v6so13756981oiy.0 for ; Wed, 31 Oct 2018 07:20:27 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id a11-v6sm1200412oib.20.2018.10.31.07.20.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:24 -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=1tf5MH/hdz7EU70w7EmnOhBcf+PBwZwDbxK+mFuMPW4=; b=mwlKdym4jjtnWJeSWGUV0rErhOWxOUEWTCPtRKuIrQzE7XcnR76rQG2ZyrlOMkWEAB P3dNo8FTQ1EJt0DFZZS4byJ7qUi8YJaGfGhvHaNBS1W8lWlO0LuzvDk4rgLjcjPcEul7 KOZGmlvkkt34fpGKFSsJalX1RH+k0qjZUjrEyW/TlAj5vr9F+vV+vra9xul+6FCHDfqE FmHiwm1Vfl/tJAtCsXjW7h2M/tlAXVLLufmnJZwear0Dt6XNhsftXR3iQTqHCN10YhQ5 JjYm1sgY2uCbtfwdM1MODXYC+uDLsw98hMIgv1w+uUCEhL9tyhqg1wBMZ5y7led9Nxel TbtA== 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=1tf5MH/hdz7EU70w7EmnOhBcf+PBwZwDbxK+mFuMPW4=; b=EJWp81nAw+5fUblZiRrJf2A57hCD4SwVm8xJ4UDCIp+kEPl5YN3Lw0kRujNBCGZt2Y O9C1Q2IpPSfp3LuvHpCYrrjdKN/NJSGBWOOJovzSoPCif233JleuanWeRDOQ8rDS7OMp gbBhdT5mmPaVnjdnvu/gdAy7twhkmBmPT6jN3j1lPUM7+Hq97buHo8ktspbVR2P7ZhEz NWxJ7/oJtqQH0YlTP0o0XvtJcI19VXdQ2NfFj8p3eEjCCQo54xh1dWR5Ag2r7k5Yt3iL 9HlKpTV6DoRXZyZ9G+zWfqFHdWb10iituxxp2xoU2MXhVxIru9wIt/17k7J1tiqSv1Bq M5Aw== X-Gm-Message-State: AGRZ1gJcgQeEArH1fBzrmfMkHdqWwrf2UNuB1kdcOBsHC+4SqsNe3SYA u4eZu2QeW5ODvNnz+1lmf1hLhKyR X-Google-Smtp-Source: AJdET5cC2EAoLGm3B0HVLo23lRZRBNAFIMDod+ggHUIqEWqGF0D9+UMZBJRyJR/+VedV9LO45HxpLQ== X-Received: by 2002:aca:6257:: with SMTP id w84-v6mr1789937oib.326.1540995625711; Wed, 31 Oct 2018 07:20:25 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:11 -0500 Message-Id: <20181031141925.30026-11-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::231 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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=C3=A1=C5=A1 Golembiovsk=C3=BD Reviewed-by: Marc-Andr=C3=A9 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[] =3D { {"a+b", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS } }; =20 +#define debug_error(msg) do { \ + char *suffix =3D 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; } =20 + g_debug("enumerating devices"); dev_info_data.cbSize =3D sizeof(SP_DEVINFO_DATA); for (i =3D 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); =20 /* 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 =3D -1; partial_pci =3D 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 =3D -1; partial_pci =3D 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 =3D -1; partial_pci =3D true; } @@ -639,6 +650,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) scsi_ad =3D &addr; char *name =3D g_strndup(guid, strlen(guid)-1); =20 + g_debug("getting disk info for: %s", name); vol_h =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (vol_h =3D=3D INVALID_HANDLE_VALUE) { @@ -646,6 +658,7 @@ static GuestDiskAddressList *build_guest_disk_info(char= *guid, Error **errp) goto out_free; } =20 + g_debug("getting bus type"); bus =3D 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) =20 disk =3D g_malloc0(sizeof(*disk)); disk->bus_type =3D find_bus_type(bus); + g_debug("bus type %d", disk->bus_type); /* always set pci_controller as required by schema. get_pci_info() sho= uld * report -1 values for non-PCI buses rather than fail. fail the comma= nd * 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=3Dws.10)= .aspx */ + g_debug("getting pci-controller info"); if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_a= d, sizeof(SCSI_ADDRESS), &len, NULL)) { disk->unit =3D addr.Lun; --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540995797185534.5972191144884; Wed, 31 Oct 2018 07:23:17 -0700 (PDT) Received: from localhost ([::1]:59882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrOh-00022H-Tu for importer@patchew.org; Wed, 31 Oct 2018 10:23:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMY-0000pf-4q for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMW-00078u-5D for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:50 -0400 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]:42163) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMU-0006yd-5l for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:46 -0400 Received: by mail-ot1-x32d.google.com with SMTP id j3so8870204otl.9 for ; Wed, 31 Oct 2018 07:20: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 65sm10634726ott.63.2018.10.31.07.20.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:29 -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=JNXBxt6SrXKs6N/0dtP6D/r1uKGm5hafTF1jNiYXD9Va8qdoNC3NIH6bqhDc7maYdf BtDg8217wRNj+bysIJ7Oe3ANvVTBvUd9TLeZjX/kTcyjHmu8/IHOmH34S6R1VlrvAo3Q daCIFr6aFetMr10GoAlQptK5Bdwf7dlIqMUE2d+C8ZvAprBGEGI3VgYrzqKjKvgmeSR0 l7vQJvJ/1FVKAYFHzwanm0pst1UHaDAoqB06QAAJrSRKmy95+19O7WwV2LiJnHcPTwA+ WJLJGEaV6Ssg5iyLp1drCCIOecZz6QOVyaO9Y2RQhqtlu8rlGwkLtRfLoSJEDPzVd+lj Ua3g== 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=hQW60lWkhs2UwTjHXgZgO1pEpXLz1Itv1e8VxMoS3j1Z//prZdMhuurocwU07RxO7p xKOrMZxrV0l6YRyX9J9EpgOsGCuUFzQ+kSBdiDcDBG5/sn6LUdggEEJOrDTaddBbgzf/ EzG3FmDP54nePdlCtqDZftr8YuMiNnA7rSvrkZujdgurx0VK1Rt/W1Tzmm/OSUGZj0PU korovdaPJ3bNolqj4eXNPf6fLa0+WcLAvBsuffB4+9tdj5bn27LzfE8nOy+Od/EzKoAw ev5ZwI8qt3bAhc3WDnWSYXQS47rTpzzDhBkjVwnq+FZx+SxtxipuaNGt2cNa9xxrhysW kKHA== X-Gm-Message-State: AGRZ1gIWFYqWU6kmyQBX7hX+LHWuUaOu/Okomd4nPtFV8s8KZCZUvNim deMhPWajYD1ekF+1xCL7HKSprPiA X-Google-Smtp-Source: AJdET5eD+PiIxpPSTPdugfafh6kVzJkOjOOWDi2TLZz7Na+k6WLmFxICi7TnPEZtvfwWkp8AOWp5OQ== X-Received: by 2002:a9d:3474:: with SMTP id v107mr2101073otb.122.1540995630567; Wed, 31 Oct 2018 07:20:30 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:12 -0500 Message-Id: <20181031141925.30026-12-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::32d Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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=C3=A1=C5=A1 Golembiovsk=C3=BD 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; } =20 -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 =3D sizeof(buf); =20 dev_desc =3D &buf; - dev_desc->Size =3D sizeof(buf); query.PropertyId =3D StorageDeviceProperty; query.QueryType =3D PropertyStandardQuery; =20 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 =3D find_bus_type(dev_desc->BusType); + g_debug("bus type %d", disk->bus_type); =20 - return dev_desc->BusType; + return; } =20 /* 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 =3D NULL; =20 @@ -655,17 +657,16 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) 0, NULL); if (vol_h =3D=3D INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open volume"); - goto out_free; + goto err; } =20 - g_debug("getting bus type"); - bus =3D get_disk_bus_type(vol_h, errp); - if (bus < 0) { - goto out_close; + disk =3D g_malloc0(sizeof(*disk)); + get_disk_properties(vol_h, disk, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto err_close; } =20 - disk =3D g_malloc0(sizeof(*disk)); - disk->bus_type =3D find_bus_type(bus); g_debug("bus type %d", disk->bus_type); /* always set pci_controller as required by schema. get_pci_info() sho= uld * report -1 values for non-PCI buses rather than fail. fail the comma= nd @@ -675,12 +676,14 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) disk->pci_controller =3D get_pci_info(name, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out_close; + goto err_close; } - if (bus =3D=3D BusTypeScsi || bus =3D=3D BusTypeAta || bus =3D=3D BusT= ypeRAID + if (disk->bus_type =3D=3D GUEST_DISK_BUS_TYPE_SCSI + || disk->bus_type =3D=3D GUEST_DISK_BUS_TYPE_IDE + || disk->bus_type =3D=3D GUEST_DISK_BUS_TYPE_RAID #if (_WIN32_WINNT >=3D 0x0600) /* This bus type is not supported before Windows Server 2003 S= P1 */ - || bus =3D=3D BusTypeSas + || disk->bus_type =3D=3D 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(ch= ar *guid, Error **errp) list =3D g_malloc0(sizeof(*list)); list->value =3D disk; list->next =3D 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; } =20 #else --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540995969455542.011857641846; Wed, 31 Oct 2018 07:26:09 -0700 (PDT) Received: from localhost ([::1]:59903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrRg-00063D-7D for importer@patchew.org; Wed, 31 Oct 2018 10:26:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMc-0000sL-Fj for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMa-0007D1-9n for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:53 -0400 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]:44759) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMZ-000716-UL for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:52 -0400 Received: by mail-ot1-x32b.google.com with SMTP id p23so14661256otf.11 for ; Wed, 31 Oct 2018 07:20: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 o9sm3547269ote.10.2018.10.31.07.20.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:31 -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=hR3bhLFlWdjCIzqTKTMwoGwEfXQ/oLWy3A8mRyuxCvgLrtwPxZfDh4CCO4UnJERbHl ff1UBzCAm6zcfPuldkwoEmxuakzF3hKpoWlLgl5khxebDwhG9s+VUfCvy8fJ9/eIPygy 2hKDhI31N8HF+buUwNL5H7n5+SkdAlp0IYdbe3yFyQGHICC7Y/ATTJimephZxprrepQu iGOzuWBIGKxlhjHFZ07vL60EAFkQ9JkUqZ04TtoSaH+H2ydVURrNsmoEbaMuBovQ4Ib2 F+t6cjkHJV99FC51BgnDBgTbHuhyjrfRqiPw1Z0aWj6vkpwYSQCbJPtzqgxFci9n78rH r7bw== 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=V+4u9T9CgC1/bU/CEJTpyKV1/bF75Y/H1K3y+FLCoffn2h/5k9q7pMJaA0uJikaks8 jNuuIwgvrMx4K0v3J8oDCRxPUYcFRoAvpKFuA7Co6/Y+XZPqGdgSY6MBKb00xQTrcsd6 WYpJNFe214iFqpF2BuGlnxmDHWyKrXZXmVqrjtKAK7WcE4Es/fov8vddjPJD2euFXk7f /TZTway02ePJ3mcdmDzJvM/N5iGdDgBWAulJo+8+7MqoZNRpgBzyh0sVIzPjs1TGv+Au wKZuvpDZynT2wsGz1Ne6brHSsetaflwJo75t8/kcagbzzR0lbG1I1velhC3L9XkgUOkN q2QA== X-Gm-Message-State: AGRZ1gL4eTyXWJ95csrdhFETPUMDoM4UzXZTm0e7DaKp/RwJkSG35Rll SaRJFvEpIdBXcqwv+cqf0Jy6Q0dl X-Google-Smtp-Source: AJdET5clTFHWz+J8sc5ERcITx+pVJnCk3KUiJPQR3rcJPLl6O9oDvdBMdw+qV2sEctAdOLWxoyZFwA== X-Received: by 2002:a9d:2ff8:: with SMTP id b53mr1914615otd.229.1540995633015; Wed, 31 Oct 2018 07:20:33 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:13 -0500 Message-Id: <20181031141925.30026-13-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::32b Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD *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, GuestDis= kAddress *disk, disk->bus_type =3D find_bus_type(dev_desc->BusType); g_debug("bus type %d", disk->bus_type); =20 + /* Query once more. Now with long enough buffer. */ + size =3D dev_desc->Size; + dev_desc =3D 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 numbe= r"); + 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 >=3D 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 =3D (char *)dev_desc + dev_desc->SerialNumberOffset; + len =3D received - dev_desc->SerialNumberOffset; + g_debug("serial number \"%s\"", serial); + if (*serial !=3D 0) { + disk->serial =3D g_strndup(serial, len); + disk->has_serial =3D true; + } + } +out_free: + g_free(dev_desc); + return; } =20 --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540995961412338.4485185203049; Wed, 31 Oct 2018 07:26:01 -0700 (PDT) Received: from localhost ([::1]:59901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrRY-0005zM-5B for importer@patchew.org; Wed, 31 Oct 2018 10:26:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMZ-0000pl-Ax for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMY-0007Aa-3E for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:51 -0400 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]:40302) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMW-00073G-63 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:48 -0400 Received: by mail-oi1-x232.google.com with SMTP id u130-v6so8989805oie.7 for ; Wed, 31 Oct 2018 07:20:36 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id i62-v6sm5067229oif.37.2018.10.31.07.20.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:34 -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=ZorIpP7B9gAW6ye/YyQsiSslNpG+AofuV36UmYSeCf4lknt/ng8sufJCAqf6k/5MU6 87lUvIssBcDcsmh/0/iUsBjFZ3dBTShj3Qvec3l/ylr8eMbM5Metc7Lzr6E/7X4geLIn 8LHlIewgZY6bS49HegssZVbLL+3u+gw6pVwsHSg2iE5F3UpJog6TX2+0AaniYj7mGXrA NEvwFX+fBgagfW4JIwG1VXhcl462XBjJuu/ENGpJbTbX+9oe+hU723WEyDhla+BS4cKZ xCerbHSLZ0xt5SG8xi2oviv6LYELbEEq+x/QfhUC98li4dUgLawqoSVJNlkWryhFSnme JLmA== 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=c5H1S0JzpkNNv6PFv2hx1TZuGqtx+yH+Dx8ju2TdhGq2emnlqJO0fzRaoReYWlAbM8 /MGHN0MhMA8Li58/T66RgOheontllIoD3OkDQ8JsuJLuTsJqGjjbsl9Nqct+LXjqlOZH bTYLqulcOBASVgs0aznWZMSB5XdSkCcfa8ylguN1TTVoAj0X1AvOmZXRSAol8JaDsUIX AMQA4JaMsBJ1E7x5wfUNPLBpujGG+vqOlsBK2rjP4n4TDE1HMpaZcp8Gh+lHZRjmyvSr k9xXFO/GuGyDyyxenJ8otQzcWGPll3/xy+R83zgHlBetMArqytIIVqmBaA5ecy//tMPO 6o8Q== X-Gm-Message-State: AGRZ1gL5d3wJOn9LftLeKClISPTLDBm8Bw+2HCSXOw3e2V3RFMI7Y+u4 MKKRLDjS15/tzsafo46hNwkKAI5U X-Google-Smtp-Source: AJdET5fHrcv0HsJ8sXmdYrJRsdi9d37SS+6JN284LsE8GUcTdIAvfuIwd2IOUWf13+D9tchH78GhSg== X-Received: by 2002:a54:4390:: with SMTP id u16-v6mr1985329oiv.186.1540995635304; Wed, 31 Oct 2018 07:20:35 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:14 -0500 Message-Id: <20181031141925.30026-14-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::232 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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=C3=A1=C5=A1 Golembiovsk=C3=BD 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; } =20 -/* 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 **err= p) +static void get_single_disk_info(char *name, GuestDiskAddress *disk, + Error **errp) { - GuestDiskAddressList *list =3D NULL; - GuestDiskAddress *disk; SCSI_ADDRESS addr, *scsi_ad; DWORD len; HANDLE vol_h; Error *local_err =3D NULL; =20 scsi_ad =3D &addr; - char *name =3D g_strndup(guid, strlen(guid)-1); =20 g_debug("getting disk info for: %s", name); vol_h =3D 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; } =20 - disk =3D 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(ch= ar *guid, Error **errp) * information about volume. */ } =20 - list =3D g_malloc0(sizeof(*list)); - list->value =3D disk; - list->next =3D 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 **err= p) +{ + Error *local_err =3D NULL; + GuestDiskAddressList *list =3D NULL, *cur_item =3D NULL; + GuestDiskAddress *disk =3D NULL; + + /* strip final backslash */ + char *name =3D g_strdup(guid); + if (g_str_has_suffix(name, "\\")) { + name[strlen(name) - 1] =3D 0; + } + + disk =3D g_malloc0(sizeof(GuestDiskAddress)); + get_single_disk_info(name, disk, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + + cur_item =3D g_malloc0(sizeof(*list)); + cur_item->value =3D disk; + disk =3D NULL; + list =3D cur_item; + +out: + qapi_free_GuestDiskAddress(disk); g_free(name); =20 - return NULL; + return list; } =20 #else --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996142306705.2156231393985; Wed, 31 Oct 2018 07:29:02 -0700 (PDT) Received: from localhost ([::1]:59915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrUJ-0001No-SX for importer@patchew.org; Wed, 31 Oct 2018 10:28:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMa-0000qB-EP for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMY-0007BI-Kd for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:52 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]:45632) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMY-00074C-9Q for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:50 -0400 Received: by mail-ot1-x330.google.com with SMTP id g10so3611733otl.12 for ; Wed, 31 Oct 2018 07:20:38 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id 111sm23000172otf.51.2018.10.31.07.20.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20: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=q4qvYUHQbKVfk7EWyk8ZHhYnBemb39mILFxX0uRYWYU=; b=i3JjbzbOe2zUd/6qYCMvqSgl5iTbGQApToI1l4XnZe3TtObADTcSzLNvKPzULKaAqk VtyaZdckYdhn/z+9uCGHtXnLJPKe3vhoMu4SSgfSeY4509FbY10iV4T76nXQgHmYsxBb FpuAC194cEtpu0TMmMAuV6nr0bjB8sG4RYnLyRyA89QAIu2iBx72l/M10ezcKxdWOHG+ yaKB5hohrBlxc+7iAnT04HM42bq/AV0Tp9rs+mPZCPsfK3yGkp54Dbrb0UyKNwGZ0mtn r/F4/niupYcOAQilR4VtxuoyvuPVYq9kLMejJ5fc6ad3xWlwPV43M38NgOUVq47PO6zJ C0eA== 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=rvNtdT/4joKbJebl2vea/tRYluga37WlCqZD46+dd5lE1JUa3r5LvwiEZYNUQ9nKm5 f1r8EkmPP1zDQMnUwmUON3uQ2nV3fCnV1XgMxGua0A3tLHpND3basRGdC5aeTpJ0eh/h gYvSCbLXCbXjjFTi1rzOQKEuIGqumnU73o5kdUowu9qwHaQ+oFw5nCVUoGaOsUZ7U3xV ymDeRVyMZFq7MUiuovLjAlugGOAeXGhfCeZfQCR4t7F0m0hUBc/aZWgScU8DgXSwOxLk 4tAEgwDOJPlqOR3Q8ITDNJk3Y+4VCGsJn8Lm1r3haw1jI0QcyQxKP04FProTOZS/Zrqb ABPA== X-Gm-Message-State: AGRZ1gJRhIb3sCXZukzvjSDQyR8O30T/o3q5KywCItO/zFTm1KcavYQ1 +1bi7L0Oy0/jdW3hQ4fwhn2VrGDa X-Google-Smtp-Source: AJdET5dDPtE8g0R2Om+RXILVI7f414U1RZEPY/GVCjUHo4ONBU8QwOJ2PhJLn4ImHj6NL8cWPe1UXw== X-Received: by 2002:a9d:388c:: with SMTP id p12mr2026351otc.158.1540995637530; Wed, 31 Oct 2018 07:20:37 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:15 -0500 Message-Id: <20181031141925.30026-15-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::330 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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=C3=A1=C5=A1 Golembiovsk=C3=BD 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]; } =20 +/* 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); + =20 static GuestPCIAddress *get_pci_info(char *guid, Error **errp) { @@ -517,7 +534,7 @@ static GuestPCIAddress *get_pci_info(char *guid, Error = **errp) goto out; } =20 - dev_info =3D SetupDiGetClassDevs(&GUID_DEVINTERFACE_VOLUME, 0, 0, + dev_info =3D SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (dev_info =3D=3D 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, GuestDis= kAddress *disk, { SCSI_ADDRESS addr, *scsi_ad; DWORD len; - HANDLE vol_h; + HANDLE disk_h; Error *local_err =3D NULL; =20 scsi_ad =3D &addr; =20 g_debug("getting disk info for: %s", name); - vol_h =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + disk_h =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - if (vol_h =3D=3D INVALID_HANDLE_VALUE) { - error_setg_win32(errp, GetLastError(), "failed to open volume"); - goto err; + if (disk_h =3D=3D INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to open disk"); + return; } =20 - 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, GuestDiskA= ddress *disk, * according to Microsoft docs * https://technet.microsoft.com/en-us/library/ee851589(v=3Dws.10)= .aspx */ g_debug("getting pci-controller info"); - if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_a= d, + if (DeviceIoControl(disk_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_= ad, sizeof(SCSI_ADDRESS), &len, NULL)) { disk->unit =3D addr.Lun; disk->target =3D addr.TargetId; @@ -725,8 +742,7 @@ static void get_single_disk_info(char *name, GuestDiskA= ddress *disk, } =20 err_close: - CloseHandle(vol_h); -err: + CloseHandle(disk_h); return; } =20 @@ -738,6 +754,10 @@ static GuestDiskAddressList *build_guest_disk_info(cha= r *guid, Error **errp) Error *local_err =3D NULL; GuestDiskAddressList *list =3D NULL, *cur_item =3D NULL; GuestDiskAddress *disk =3D NULL; + int i; + HANDLE vol_h; + DWORD size; + PVOLUME_DISK_EXTENTS extents =3D NULL; =20 /* strip final backslash */ char *name =3D g_strdup(guid); @@ -745,20 +765,90 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *guid, Error **errp) name[strlen(name) - 1] =3D 0; } =20 - disk =3D 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 =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + 0, NULL); + if (vol_h =3D=3D INVALID_HANDLE_VALUE) { + error_setg_win32(errp, GetLastError(), "failed to open volume"); goto out; } =20 - cur_item =3D g_malloc0(sizeof(*list)); - cur_item->value =3D disk; - disk =3D NULL; - list =3D cur_item; + /* Get list of extents */ + g_debug("getting disk extents"); + size =3D sizeof(VOLUME_DISK_EXTENTS); + extents =3D g_malloc0(size); + if (!DeviceIoControl(vol_h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, + 0, extents, size, NULL, NULL)) { + DWORD last_err =3D GetLastError(); + if (last_err =3D=3D ERROR_MORE_DATA) { + /* Try once more with big enough buffer */ + size =3D sizeof(VOLUME_DISK_EXTENTS) + + extents->NumberOfDiskExtents*sizeof(DISK_EXTENT); + g_free(extents); + extents =3D 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 =3D=3D ERROR_INVALID_FUNCTION) { + /* Possibly CD-ROM or a shared drive. Try to pass the volume */ + g_debug("volume not on disk"); + disk =3D 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 =3D g_malloc0(sizeof(*list)); + list->value =3D disk; + disk =3D NULL; + list->next =3D 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 =3D 0; i < extents->NumberOfDiskExtents; i++) { + char *disk_name =3D NULL; + disk =3D 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/n= s-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 =3D 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 =3D g_malloc0(sizeof(*list)); + cur_item->value =3D disk; + disk =3D NULL; + cur_item->next =3D list; + list =3D cur_item; + } + =20 out: qapi_free_GuestDiskAddress(disk); + g_free(extents); g_free(name); =20 return list; --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540995797170369.9882984096396; Wed, 31 Oct 2018 07:23:17 -0700 (PDT) Received: from localhost ([::1]:59883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrOk-00025l-Rc for importer@patchew.org; Wed, 31 Oct 2018 10:23:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMY-0000pg-5g for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMU-000785-S4 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:50 -0400 Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]:34561) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMT-00074u-Fq for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:46 -0400 Received: by mail-ot1-x329.google.com with SMTP id e9so13179033oti.1 for ; Wed, 31 Oct 2018 07:20:41 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id g20sm9767999oth.30.2018.10.31.07.20.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V4QuD/SdmHm1xhwRyGU/67Fuszx4RPOvYIaCUYitays=; b=tKr2sCtusI0M+rQzEoiUQLKh/Esoo8WMuKHsIRYQZ9LLojG130ge8XXQ+2xoOnCbzG h/Pypk0/v8clatv6jrOdFZyqI8spSAFpqD4GPKCjzsMY8EyU/iPcBm+AnLEM3++E8jGv EUKM0cl8WVp6on+25ecQZwcD27ui6RS8DJR2ORwhoPj2y4WeOpGFMwEmmnrSqG7ZGLN8 bxYss81cROHuqogJpUve7nPH03nfLKzbApbSYGPKGUTP9jrTWYJvJ3Ts+AYDuavsZjrw p1AOsCCZhjbeHDDxf0v6w2mJ+X6OBX67QPrFRJlhK9nmjfGVccnHIvq7OZ/Z1stkRW+Z rZnw== 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=pNYcumkKeD/ZQPpwMtYdOSgs73DWrhbykzrKSJVgx+cg7a8qKbYWSWn1tf36QQpXDD 8UbHkkG7K9n31ql2ueTADbeCZlZe+zCkBmmEiwnDwrR5LkeuSpTH8t8HqPxDxz/RMj1d FFCcLugqLn2WjbMMFca6WKVuMNCV6uqeKSkOpgYyDLYf6fC7ipDwbxlMrcqFUqRaN0ME EiYOkkw4x6gxJt7xqmCQB3h2BtEah1kNWFqKZw+zY1FHqSq9BISn5N006xPdTSrdv2bF TVIPLdjOwEAdDII5nPjZOJxcDDbpXIIg9DGzu7+aiClM7pN6OWs69Q7l08zUxDsrvUD6 o7Og== X-Gm-Message-State: AGRZ1gIJr/aE/5LPlmtdkNmmxF1XuB39QOtnBq6Z+Klyz4+G5tukb4kG WEdP0ZG33JktqteKSiZhPuDmZcXl X-Google-Smtp-Source: AJdET5fbbrMP0OEs2QXN4S7KfsWeVtyMM8gPZxf+o5kvwrKfMyz+nL+U4jlD5PHqnRyq2AJ43/K1CA== X-Received: by 2002:a9d:348:: with SMTP id 66mr1869129otv.300.1540995639738; Wed, 31 Oct 2018 07:20:39 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:16 -0500 Message-Id: <20181031141925.30026-16-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::329 Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Report device UNC of the disk. It is reported as "\\.\PhysicalDriveX". Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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; } =20 -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, GuestDiskA= ddress *disk, =20 scsi_ad =3D &addr; =20 - g_debug("getting disk info for: %s", name); - disk_h =3D CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + g_debug("getting disk info for: %s", disk->dev); + disk_h =3D CreateFile(disk->dev, 0, FILE_SHARE_READ, NULL, OPEN_EXISTI= NG, 0, NULL); if (disk_h =3D=3D INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open disk"); @@ -714,7 +713,7 @@ static void get_single_disk_info(char *name, GuestDiskA= ddress *disk, * if that doesn't hold since that suggests some other unexpected * breakage */ - disk->pci_controller =3D get_pci_info(name, &local_err); + disk->pci_controller =3D 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 =3D g_malloc0(sizeof(GuestDiskAddress)); - get_single_disk_info(name, disk, &local_err); + disk->has_dev =3D true; + disk->dev =3D 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) =20 /* Go through each extent */ for (i =3D 0; i < extents->NumberOfDiskExtents; i++) { - char *disk_name =3D NULL; disk =3D g_malloc0(sizeof(GuestDiskAddress)); =20 /* Disk numbers directly correspond to numbers used in UNCs @@ -830,10 +830,11 @@ static GuestDiskAddressList *build_guest_disk_info(ch= ar *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 =3D g_strdup_printf("\\\\.\\PhysicalDrive%lu", + disk->has_dev =3D true; + disk->dev =3D 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; --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540995797473244.33177317604589; Wed, 31 Oct 2018 07:23:17 -0700 (PDT) Received: from localhost ([::1]:59884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrOp-00027N-0e for importer@patchew.org; Wed, 31 Oct 2018 10:23:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMa-0000q6-BM for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMZ-0007C0-7I for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:52 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]:40297) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMY-00075e-R1 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:50 -0400 Received: by mail-oi1-x22c.google.com with SMTP id u130-v6so8990148oie.7 for ; Wed, 31 Oct 2018 07:20: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 111sm23000449otf.51.2018.10.31.07.20.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20: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=reWrzN1nbgrUa5M9CT6ngaBhfrzDoBBYAKpSG9utug0=; b=JiBoeuFlbmUNatJHqR387bz6Y4cMizXFaGWZafmtqbrkjVdEymGE8Um78ArWUVXHJq HJXLgGsB6FV/2mCpDpkKTBdHXxXcsBz1fURrbRL3Riz7ONA8ILnVP6S6uCobbUgCQaMt j7xi6q/VxA/ajF/1TSkJr18yN1SkDICeYfyhLz1HyJhsIIcEiO0H8Nw7K4RAvfgEuser Q81tRxSiNLbfUrSdyaHB4rswONPpKwoy32oL84pyWOZXlX3nxvrcXtQ4c6GgJlSJ8xGC ezeq1YcljqKz2avR1zWt+f07gHLxGBZvShXwtaNVljdnf4biL6gyQtDa5kpnuqOYSuda 1Nbw== 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=Fs0FcfeNaqcAPKsjDiWfBGiltRagnE4lSkTalnCDwz1jdAZ0Haa22KnzxkABDRe9BJ g49/sPosJiYHhvqwcBOCYKJGocjflPh5tBpkVrSvP4PekGiWrE4EM5B8e66/Tg3SywCM rWojpR8jQ3RxYrhzEmXV4FbkaZmb/Bm81aKqWMFKGSHVjpkgjwCaKP7S9kUOusGMNLn8 HiQzp4TQC9M7GH8baktOXaZup9x6S33MQq+wgZc161ciPxGU3YvLRnlrigIKhhFVWnsC V03c/0Lw6egbz/POvEJqbJ/2a/d8Q2Mj9B87iaZh9qUeYi5/VMNUT8nIPm6U14LY8N6U wiGQ== X-Gm-Message-State: AGRZ1gJ3igwSLJvcpaIPRWWabA3S5p7IVkDtU2yA2hCRZ8OnQVLQaRT5 xHzon6rz/Yz/AxDkFRDLVRx7nUmq X-Google-Smtp-Source: AJdET5fdZQvLa/It6g6/i8b398Q6noG6td5ZO5jL2QpnWqig4mik/iyE5TTGfa5ae2/743siMrwjjg== X-Received: by 2002:aca:d7c6:: with SMTP id o189-v6mr1933703oig.33.1540995642330; Wed, 31 Oct 2018 07:20:42 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:17 -0500 Message-Id: <20181031141925.30026-17-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::22c Subject: [Qemu-devel] [PULL v3 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?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD It was not obvious what exactly the cryptic string copying does to the GUID. This change makes the intent clearer. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD 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 =3D NULL; GuestPCIAddress *pci =3D NULL; - char *name =3D g_strdup(&guid[4]); + char *name =3D NULL; bool partial_pci =3D false; pci =3D g_malloc0(sizeof(*pci)); pci->domain =3D -1; @@ -529,6 +529,13 @@ static GuestPCIAddress *get_pci_info(char *guid, Error= **errp) pci->function =3D -1; pci->bus =3D -1; =20 + if (g_str_has_prefix(guid, "\\\\.\\") || + g_str_has_prefix(guid, "\\\\?\\")) { + name =3D g_strdup(guid + 4); + } else { + name =3D g_strdup(guid); + } + if (!QueryDosDevice(name, dev_name, ARRAY_SIZE(dev_name))) { error_setg_win32(errp, GetLastError(), "failed to get dos device n= ame"); goto out; --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996520762469.91661354883445; Wed, 31 Oct 2018 07:35:20 -0700 (PDT) Received: from localhost ([::1]:59946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHraS-0007iX-0S for importer@patchew.org; Wed, 31 Oct 2018 10:35:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMg-0000wV-Tv for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMY-0007Bi-VQ for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:57 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]:36637) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMY-000778-Kz for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:50 -0400 Received: by mail-oi1-x230.google.com with SMTP id r127-v6so12001767oie.3 for ; Wed, 31 Oct 2018 07:20:45 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id i62-v6sm5067365oif.37.2018.10.31.07.20.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:43 -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=SQrTnODaDmsrlnKjhgpkvMxasXORy1msBwtbxDpDSIo7Jy1pHXVp1IlSkPzY32eaoK WBTq597eXPRDoBPCpDx8A05TB9TG60etQriO319anOVmzjO17jNRDWyHTZQfPxb0/Qaf zsiiaQPpBNmk4CH/TIng0BWC7EM6sPEpD4RRRAn4UHA/fGLq8SA+7MIPqrzfmwu+lRPC ob2bkqTOan9apWtQ9YS0Pi/zfAkTQrx+YwMUCAtZKnGwhGhn9eHMeDMeMlZPQvXvk+1y tnb7z1CmSgxagXBWvm10LLXkL/UDo1hPAlDGzzVPZSCD0Uij7Ykxh8uKAqY85udE0vE7 LydQ== 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=Oi9v6a0/uzB6ougba6tP9GbJuzNk4CbykAM4ROf3YhZ4vnZv5SYZHyTbfvwey5oIHY T7H8Dqb6oJTRHpKGyD0x9Ewln/4T6Zf0t7nBJz4fe0oQIHQq6A4tKWOXsrZ/4Vnq9UH4 wa1f7yzIHDxXw/IC5YDuvANELiXIv0xyiqyUqTzC+3nXcqvB97arXx8SnWNEUMezfvO1 3f+HFBuLIceiycCU21qCzWoisFMl0iA6obnX9+MEX+mndBfMZG6snXtc+cLEvMRZyKbF aw1FngPH8AX/IzBFIzSf44V7LXqolOCDsZte2XxwMvpROkRZRf8sR5fMXkYkrwHuY1my TPkQ== X-Gm-Message-State: AGRZ1gKpGGO8G9+vX/7B7JTLaXqcothA+IfX8NbEnJNHASGG5vhxdmpI 0NoawmnhGupE9Hwqf7JR6Fm8oBWP X-Google-Smtp-Source: AJdET5dKOO+O/3zaaNyTooF+DgEBMfXAIFaKZGf8/USdCl/c2UctQFTf+B2Hz9eHyJ9MMNWORWXBFQ== X-Received: by 2002:aca:efd6:: with SMTP id n205-v6mr1807953oih.3.1540995644663; Wed, 31 Oct 2018 07:20:44 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:18 -0500 Message-Id: <20181031141925.30026-18-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::230 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang Signed-off-by: Li Qiang Reviewed-by: Philippe Mathieu-Daud=C3=A9 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[] =3D { =20 static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE bus) { - if (bus > ARRAY_SIZE(win2qemu) || (int)bus < 0) { + if (bus >=3D ARRAY_SIZE(win2qemu) || (int)bus < 0) { return GUEST_DISK_BUS_TYPE_UNKNOWN; } return win2qemu[(int)bus]; --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540995797460685.5118995723803; Wed, 31 Oct 2018 07:23:17 -0700 (PDT) Received: from localhost ([::1]:59885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrOo-00027i-Qh for importer@patchew.org; Wed, 31 Oct 2018 10:23:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMa-0000qE-H5 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMY-0007BZ-UF for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:52 -0400 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]:33452) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMY-00078k-Ko for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:50 -0400 Received: by mail-ot1-x32b.google.com with SMTP id q1so5239573otk.0 for ; Wed, 31 Oct 2018 07:20: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 v2sm6648599otb.15.2018.10.31.07.20.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:45 -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=qze9BFeHW36P1lKqCOgTiE5N5Ec6A/0jKQBYuqnVA8R/EG919AgHj/WevCSl1iWBEF y7G/k/mYVqrUPM8G6BkjmBmNE6TqrjeBuzkxHDfMZoL8SnNfN6LrjPgAqjsF2tZqzhqY 0Dd2Dy0AXSu2KYbzhNMKrEA4+zpgZapw3aTES56whxmd9TDDbBvXKTKFp0L+kw6sDS2M OZNbzc0vE2j9ZKl59mYTfSqP4pqziWKo/7Hk9hma3Pm5xsSYoPiGJgttgqlkB/m6diT9 M9zw8GjGYu7308eTUyHUryZWDeJ6GctIAzQcSHM+weVFZc3NPUSyue9QihWYhQaFRFvQ 5Udw== 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=tj121bM/EJ/fbi1Tpx4TxiWnNag3BZ/lw5fdjRO+FptgzlrFvu2ZRWNiDPzoPzEkys Rp3WaEjn8zuqBxOKxbytiG/VBM9nrAVgY6pFyIgyrOrpUocJ241feXeW6jZ+elX/TISR ecacBvxX76/Arn8QzimPWbsomGhcZCt/VOJCTbVWh8yhz23f8XTJbJ6+soguClsi64PA fWT3AhpNlE1ku7eb+FaAXX7laZESd+OjxtybxpibuZfM7vOt4lnQm0H/Sbfcy+0w2vYk YFaE01dr9lwCD+aeKoqgiq3jsNTpAPzBgX/lYkeWWAR0UpKfdWJS794lHN5OGt5ZS3uG myTw== X-Gm-Message-State: AGRZ1gI+8xvQjYhRw/U1fiblTyhaViGCnDqvzQSZ5lwcCa+hrKESJMfS YYO/eizT0OCvta5KcfWbHs1+lncI X-Google-Smtp-Source: AJdET5cZagg+yh+fnzifpp1IxBYwopv9glDqOGuKfs+jkNw+NVRSBYUDlf2dOS2JYlkeD7etIm2TqA== X-Received: by 2002:a9d:566:: with SMTP id 93mr1197316otw.232.1540995646835; Wed, 31 Oct 2018 07:20:46 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:19 -0500 Message-Id: <20181031141925.30026-19-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::32b Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9 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; } =20 -static int run_agent(GAState *s, GAConfig *config, int socket_activation) +static GAState *initialize_agent(GAConfig *config) { - ga_state =3D s; + GAState *s =3D g_new0(GAState, 1); + + g_assert(ga_state =3D=3D NULL); + + s->log_level =3D config->log_level; + s->log_file =3D stderr; +#ifdef CONFIG_FSFREEZE + s->fsfreeze_hook =3D config->fsfreeze_hook; +#endif + s->pstate_filepath =3D g_strdup_printf("%s/qga.state", config->state_d= ir); + s->state_filepath_isfrozen =3D g_strdup_printf("%s/qga.state.isfrozen", + config->state_dir); + s->frozen =3D check_is_frozen(s); =20 g_log_set_default_handler(ga_log, s); g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR); @@ -1229,7 +1241,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) if (g_mkdir_with_parents(config->state_dir, S_IRWXU) =3D=3D -1) { g_critical("unable to create (an ancestor of) the state directory" " '%s': %s", config->state_dir, strerror(errno)); - return EXIT_FAILURE; + return NULL; } #endif =20 @@ -1254,7 +1266,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) if (!log_file) { g_critical("unable to open specified log file: %s", strerror(errno)); - return EXIT_FAILURE; + return NULL; } s->log_file =3D log_file; } @@ -1265,7 +1277,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) s->pstate_filepath, ga_is_frozen(s))) { g_critical("failed to load persistent state"); - return EXIT_FAILURE; + return NULL; } =20 config->blacklist =3D ga_command_blacklist_init(config->blacklist); @@ -1286,12 +1298,37 @@ static int run_agent(GAState *s, GAConfig *config, = int socket_activation) #ifndef _WIN32 if (!register_signal_handlers()) { g_critical("failed to register signal handlers"); - return EXIT_FAILURE; + return NULL; } #endif =20 s->main_loop =3D g_main_loop_new(NULL, false); =20 + ga_state =3D s; + return s; +} + +static void cleanup_agent(GAState *s) +{ + if (s->command_state) { + ga_command_state_cleanup_all(s->command_state); + ga_command_state_free(s->command_state); + json_message_parser_destroy(&s->parser); + } + if (s->channel) { + ga_channel_free(s->channel); + } + g_free(s->pstate_filepath); + g_free(s->state_filepath_isfrozen); + if (s->main_loop) { + g_main_loop_unref(s->main_loop); + } + g_free(s); + ga_state =3D NULL; +} + +static int run_agent(GAState *s, GAConfig *config, int socket_activation) +{ if (!channel_init(ga_state, config->method, config->channel_path, socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)= ) { g_critical("failed to initialize guest agent channel"); @@ -1315,7 +1352,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) int main(int argc, char **argv) { int ret =3D EXIT_SUCCESS; - GAState *s =3D g_new0(GAState, 1); + GAState *s; GAConfig *config =3D g_new0(GAConfig, 1); int socket_activation; =20 @@ -1383,44 +1420,25 @@ int main(int argc, char **argv) } } =20 - s->log_level =3D config->log_level; - s->log_file =3D stderr; -#ifdef CONFIG_FSFREEZE - s->fsfreeze_hook =3D config->fsfreeze_hook; -#endif - s->pstate_filepath =3D g_strdup_printf("%s/qga.state", config->state_d= ir); - s->state_filepath_isfrozen =3D g_strdup_printf("%s/qga.state.isfrozen", - config->state_dir); - s->frozen =3D check_is_frozen(s); - if (config->dumpconf) { config_dump(config); goto end; } =20 + s =3D initialize_agent(config); + if (!s) { + g_critical("error initializing guest agent"); + goto end; + } ret =3D run_agent(s, config, socket_activation); + cleanup_agent(s); =20 end: - if (s->command_state) { - ga_command_state_cleanup_all(s->command_state); - ga_command_state_free(s->command_state); - json_message_parser_destroy(&s->parser); - } - if (s->channel) { - ga_channel_free(s->channel); - } - g_free(s->pstate_filepath); - g_free(s->state_filepath_isfrozen); - if (config->daemonize) { unlink(config->pid_filepath); } =20 config_free(config); - if (s->main_loop) { - g_main_loop_unref(s->main_loop); - } - g_free(s); =20 return ret; } --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996315398917.6786012104976; Wed, 31 Oct 2018 07:31:55 -0700 (PDT) Received: from localhost ([::1]:59935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrXG-0003pe-8P for importer@patchew.org; Wed, 31 Oct 2018 10:31:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMf-0000vC-7d for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMa-0007Cl-7R for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:55 -0400 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]:36642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMZ-0007BA-U1 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:52 -0400 Received: by mail-oi1-x235.google.com with SMTP id r127-v6so12001987oie.3 for ; Wed, 31 Oct 2018 07:20:50 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id p130-v6sm7817113oig.1.2018.10.31.07.20.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20: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; bh=J2hDdIIMnNOSP+USzHUBuxWsUR55MYaTRzDvre6P60A=; b=IM+uoSorS7Lm7jSbmm2J8QMMCUOl7+3pvKqTizWSj3NEgUqCmML/fzTQv75IpgIfnM 3l773jcZ9nWfbsnJNhKCYna3BT8v4ZaXt3Rt8A8vYy3gRkxTlJ0ybHrmnvXGwri9dSFM JUgy7Wv6u5GtVICnXO8vxywEyTeyyX0Q62UrIU3JrB6bDLQPK8hF/xs4CiPvzgKPec9b 6Lnn+ujVYfSAJWtEW0CCY1XU/b9vWxv4fgoKWS6TeeA66vQVySb5NgduJBa6q74/9Rp6 qCtIl5gtxAyU6chJKVLyeECs0HUaPNzaQK9nQ/TSzcelAwF/L77jmhKI0t/YkME9i4B2 TkwA== 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=FR4G67yqzvR1VBCdo/fd3yr6+OOu2iCoL8UwGa006xLUyTUtDDxQXJu0v5FQ/X+cb0 bKxiolf8ZHuhycCO8yImzkagg2gW3KtGS/7/w/RKHZ7qhNlaFwAJS1qQk//CTtVbpFld DtW38/60lO6HvvYuXgwE/MIZc7WkSrnEapYllEWCDIYkgT+ScqHh1riHvcL925tay5JN bX3Jgf5LiJnGjRVSgrkqfS9uHBzgCXIpORX9k0OpTcU+pfNRgBu2Lgon47yVVrWxNUPA 2vz19zsNnZq7VTXzRPKyc+9U+VY5fPuTRCnvL4kQhgW3bnUpsTTdmTrO0uIKRPjnKQIo oUuA== X-Gm-Message-State: AGRZ1gLj+43RObYG82sFbz7OkcAKdxlx3IxmzJoZh2aCQx70W0DE4wx8 C/m5bcs66geaSMKOr4gyQBOSr+a9 X-Google-Smtp-Source: AJdET5fDWnEIJvghzcT3qyUnj9wMYVdcIQqVMkmn1WRLaUZX2IMOMY1gxCuitWZMa/FybFhcK8D4og== X-Received: by 2002:aca:aa4f:: with SMTP id t76-v6mr1952788oie.273.1540995649244; Wed, 31 Oct 2018 07:20:49 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:20 -0500 Message-Id: <20181031141925.30026-20-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-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::235 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; =20 +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; }; =20 struct GAState *ga_state; @@ -905,7 +909,7 @@ static GList *split_list(const gchar *str, const gchar = *delim) return list; } =20 -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; +}; =20 static void config_load(GAConfig *config) { @@ -1211,7 +1215,7 @@ static bool check_is_frozen(GAState *s) return false; } =20 -static GAState *initialize_agent(GAConfig *config) +static GAState *initialize_agent(GAConfig *config, int socket_activation) { GAState *s =3D g_new0(GAState, 1); =20 @@ -1304,6 +1308,8 @@ static GAState *initialize_agent(GAConfig *config) =20 s->main_loop =3D g_main_loop_new(NULL, false); =20 + s->config =3D config; + s->socket_activation =3D socket_activation; ga_state =3D s; return s; } @@ -1327,17 +1333,17 @@ static void cleanup_agent(GAState *s) ga_state =3D NULL; } =20 -static int run_agent(GAState *s, GAConfig *config, int socket_activation) +static int run_agent(GAState *s) { - if (!channel_init(ga_state, config->method, config->channel_path, - socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)= ) { + if (!channel_init(s, s->config->method, s->config->channel_path, + s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : = -1)) { g_critical("failed to initialize guest agent channel"); return EXIT_FAILURE; } #ifndef _WIN32 g_main_loop_run(ga_state->main_loop); #else - if (config->daemonize) { + if (s->config->daemonize) { SERVICE_TABLE_ENTRY service_table[] =3D { { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; StartServiceCtrlDispatcher(service_table); @@ -1425,12 +1431,12 @@ int main(int argc, char **argv) goto end; } =20 - s =3D initialize_agent(config); + s =3D initialize_agent(config, socket_activation); if (!s) { g_critical("error initializing guest agent"); goto end; } - ret =3D run_agent(s, config, socket_activation); + ret =3D run_agent(s); cleanup_agent(s); =20 end: --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996315531430.1072588999774; Wed, 31 Oct 2018 07:31:55 -0700 (PDT) Received: from localhost ([::1]:59934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrXG-0003p4-Bf for importer@patchew.org; Wed, 31 Oct 2018 10:31:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMf-0000vA-7O for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMb-0007E2-93 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:55 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]:42968) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMb-0007Dm-2Z for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:20:53 -0400 Received: by mail-oi1-x22f.google.com with SMTP id h23-v6so13725839oih.9 for ; Wed, 31 Oct 2018 07:20:53 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id r7-v6sm8743154oih.24.2018.10.31.07.20.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ab6VptyiBF+UH0FW+m/qIjGDhVLzmPY8RK/Fm0aX5X0=; b=tw/6PUKm51MgHmsLqhIkyX0RtUIAiXZvFzTeGhCK4pJgEf307lLiPxYNg2wuEZQtRZ hSsxcJLcY8nO1RfRuJ8sFDNADl3HSOUF4DPyo5aXTuVfwVrt0CF5c9N0H9UA6EUD/chL BsadsDmH3Dzu4rv5U0Mqqq0GWU4habpB1P5DnptJtc7geLKskij2bfPZkwCGL9/mBpQc P2xf4aHV7oh9/o14wg9CxqQEKODCMct25BjpzCTyJQkpXHCH2RiHtht3UzFc6cwRdouB YlH5yJeFH2rCwqrU3nG2G1djgAJ7ixfs9XZWp2KiwLOnNVcPfe0lI/gu7JXZx5OkbCA6 tvWw== 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=ioFBvuYt6ERWDlIbsda4M7tJwxtm4czHD9ejQRwFEhbQC1PU8eHknnE/bZ62LnvD/E Y1VUmMkqF/jYVei6FKYLdb9yfhF2SvBG7SV4x4iKHEIp7KMgx6TB2HQe1BTr+Ulj5gHN 9J7Nw2kEUcdsotZprLpeYhH/6fBM+LpXxoKx2RM75d/eqbwvay0zlRXXJbvcRzsgvuNV 17RhjI5sE0+bAzv1Gw5c3K2WOIgoKjtJXKzPWKVcKC+pLv/NbhbO/m70nbYDMLvVX5P/ 8E9b3Vk+LKjtTQ+a8s8ps1io3oDbLQJwHu9cNcc5Yo2kOkN3QyEMFJK4QbmONdeBUhAc Cggg== X-Gm-Message-State: AGRZ1gIW47MBWWNI3TXdtY4kgLFfESZnmPypQAm+2E7MV24KoPD8FaTl WPULRnFbtj4pz06xfVneSrwaqL6E X-Google-Smtp-Source: AJdET5dRPd7aWiwIqohu0KX5OIb52L9dCGZK4Q5hhopth6AFmcFCqXhJapT+xaqjtVGbWM9hT9tXKA== X-Received: by 2002:aca:1b0f:: with SMTP id b15-v6mr1821626oib.215.1540995651562; Wed, 31 Oct 2018 07:20:51 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:21 -0500 Message-Id: <20181031141925.30026-21-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-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::22f Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 typ= e, LPVOID data, LPVOID ctx); VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif +static int run_agent(GAState *s); =20 static void init_dfl_pathnames(void) @@ -712,7 +713,7 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[]) service->status.dwWaitHint =3D 0; SetServiceStatus(service->status_handle, &service->status); =20 - g_main_loop_run(ga_state->main_loop); + run_agent(ga_state); =20 service->status.dwCurrentState =3D SERVICE_STOPPED; SetServiceStatus(service->status_handle, &service->status); @@ -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[] =3D { - { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; - StartServiceCtrlDispatcher(service_table); - } else { - g_main_loop_run(ga_state->main_loop); - } -#endif =20 return EXIT_SUCCESS; } @@ -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[] =3D { + { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; + StartServiceCtrlDispatcher(service_table); + } else { + ret =3D run_agent(s); + } +#else ret =3D run_agent(s); +#endif + cleanup_agent(s); =20 end: --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996142031131.2790520799026; Wed, 31 Oct 2018 07:29:02 -0700 (PDT) Received: from localhost ([::1]:59914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrUJ-0001NX-Ki for importer@patchew.org; Wed, 31 Oct 2018 10:28:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMs-00016I-Gr for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMr-0007Lu-6z for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:10 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]:34568) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMq-0007FO-Mr for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:08 -0400 Received: by mail-ot1-x32f.google.com with SMTP id e9so13179908oti.1 for ; Wed, 31 Oct 2018 07:20:57 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id s83-v6sm8471561oia.9.2018.10.31.07.20.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:54 -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=AcFEjj1sRRAy4L8KxWPbYcmepUv80wh+zvbpeoN4uAQoQvpf+zKnQL1KsZBxAOsQ3R Jvncyxw/1EL2YEFUAmMbTXtv0XqQuT6/PB0t71YGj0fzkG4sJcjE1ET7nkLGWiUXpXOb pv7tYVaMLYhtHzuQhMrQEh8QMCiNi/cRKTNv50gUs0v0LqHnuNVwLhGOHV0K3Mg56Jnq Q7MdJAUUoqqBeOTEpOcyjFe3upYpppQ07tYJetIpQu1rAoL7AT/9Ci2hq8L2S5pO15y+ zUmkooLcY2tMQwYA1CnQxnrGt7DjMenVOxiARopeYMPI79XfszHQOWS2ymRVVrf8T+QI KARg== 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=I/XUQwfO1QjfffeNkKSz3NyTrbE2htxeO3W+hurGWJP+shw+oF7JZDnwJpX0POiXHl U/vPgjPQJIRg4zEWpT6qcghWDfx+Ij8SXYkthgy1nLBTYeNuNj8h/3nGnmAXQxNQMV+v uoOLhYF6eZd3VAgyhcvUBADiw1Uk53YZVoRbnkQlCsu7NW/eNYpB61tjC8EDuzKQyJQe DYv9lZhpLlZ9ZqLL/XQSE4ykn/7CHzladFLXCsaupKb63opORbyUPKQ21llm4TvbBYq6 jQM3u4fIebIPNErbQkFNYLMNWUC0GtMK1zmxuLN0oxfuJZ9+Z3s+5Fzg4ZprN94cltk5 iwXA== X-Gm-Message-State: AGRZ1gLz4qwjHrj8iLY7dHK0BMqkPVNrNSISrMRfuHV1JH5aWP9lqHfn 2XsQl7SBeSB46ubGuCUvATkWTtNZ X-Google-Smtp-Source: AJdET5cu7amrgBAMszVIS+HoXzNYxkDHuSNXHXPDxwSiTlFA6HxvQstfXsPh0QLlyk65VDKqZFLGeg== X-Received: by 2002:a9d:740c:: with SMTP id n12mr1797817otk.247.1540995656026; Wed, 31 Oct 2018 07:20:56 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:22 -0500 Message-Id: <20181031141925.30026-22-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-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::32f Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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.co= nf" +#define QGA_RETRY_INTERVAL 5 =20 static struct { const char *state_dir; @@ -98,6 +99,7 @@ struct GAState { GAPersistentState pstate; GAConfig *config; int socket_activation; + bool force_exit; }; =20 struct GAState *ga_state; @@ -120,6 +122,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD typ= e, LPVOID data, VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif static int run_agent(GAState *s); +static void stop_agent(GAState *s, bool requested); =20 static void init_dfl_pathnames(void) @@ -168,9 +171,7 @@ static void quit_handler(int sig) } g_debug("received signal num %d, quitting", sig); =20 - if (g_main_loop_is_running(ga_state->main_loop)) { - g_main_loop_quit(ga_state->main_loop); - } + stop_agent(ga_state, true); } =20 #ifndef _WIN32 @@ -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 futur= e\n" +" (virtio-serial driver re-install, serial device hot\n" +" plug/unplug, etc.)\n" " -h, --help display this help and exit\n" "\n" QEMU_HELP_BOTTOM "\n" @@ -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] =3D 0; @@ -927,6 +933,7 @@ struct GAConfig { int daemonize; GLogLevelFlags log_level; int dumpconf; + bool retry_path; }; =20 static void config_load(GAConfig *config) @@ -976,6 +983,10 @@ static void config_load(GAConfig *config) /* enable all log levels */ config->log_level =3D G_LOG_LEVEL_MASK; } + if (g_key_file_has_key(keyfile, "general", "retry-path", NULL)) { + config->retry_path =3D + g_key_file_get_boolean(keyfile, "general", "retry-path", &gerr= ); + } if (g_key_file_has_key(keyfile, "general", "blacklist", NULL)) { config->bliststr =3D g_key_file_get_string(keyfile, "general", "blacklist", &gerr); @@ -1037,6 +1048,8 @@ static void config_dump(GAConfig *config) g_key_file_set_string(keyfile, "general", "statedir", config->state_di= r); g_key_file_set_boolean(keyfile, "general", "verbose", config->log_level =3D=3D G_LOG_LEVEL_MASK); + g_key_file_set_boolean(keyfile, "general", "retry-path", + config->retry_path); tmp =3D list_join(config->blacklist, ','); g_key_file_set_string(keyfile, "general", "blacklist", tmp); g_free(tmp); @@ -1055,7 +1068,7 @@ static void config_dump(GAConfig *config) =20 static void config_parse(GAConfig *config, int argc, char **argv) { - const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:D"; + const char *sopt =3D "hVvdm:p:l:f:F::b:s:t:Dr"; int opt_ind =3D 0, ch; const struct option lopt[] =3D { { "help", 0, NULL, 'h' }, @@ -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 } }; =20 @@ -1119,6 +1133,9 @@ static void config_parse(GAConfig *config, int argc, = char **argv) case 'D': config->dumpconf =3D 1; break; + case 'r': + config->retry_path =3D true; + break; case 'b': { if (is_help_option(optarg)) { qmp_for_each_command(&ga_commands, ga_print_cmd, NULL); @@ -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 =3D NULL; } =20 -static int run_agent(GAState *s) +static int run_agent_once(GAState *s) { if (!channel_init(s, s->config->method, s->config->channel_path, s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : = -1)) { @@ -1344,9 +1358,41 @@ static int run_agent(GAState *s) =20 g_main_loop_run(ga_state->main_loop); =20 + if (s->channel) { + ga_channel_free(s->channel); + } + return EXIT_SUCCESS; } =20 +static int run_agent(GAState *s) +{ + int ret =3D EXIT_SUCCESS; + + s->force_exit =3D false; + + do { + ret =3D run_agent_once(s); + if (s->config->retry_path && !s->force_exit) { + g_warning("agent stopped unexpectedly, restarting..."); + sleep(QGA_RETRY_INTERVAL); + } + } while (s->config->retry_path && !s->force_exit); + + return ret; +} + +static void stop_agent(GAState *s, bool requested) +{ + if (!s->force_exit) { + s->force_exit =3D requested; + } + + if (g_main_loop_is_running(s->main_loop)) { + g_main_loop_quit(s->main_loop); + } +} + int main(int argc, char **argv) { int ret =3D EXIT_SUCCESS; --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540996696357278.52980763552534; Wed, 31 Oct 2018 07:38:16 -0700 (PDT) Received: from localhost ([::1]:59970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrdP-0002C8-45 for importer@patchew.org; Wed, 31 Oct 2018 10:38:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMr-00015b-Pn for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMo-0007Ks-3K for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:09 -0400 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]:39703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMm-0007Gz-Gc for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:04 -0400 Received: by mail-oi1-x229.google.com with SMTP id e3-v6so13739465oiy.6 for ; Wed, 31 Oct 2018 07:20:59 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id b82-v6sm1446302oif.19.2018.10.31.07.20.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:57 -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=ZXbxZuNLyWR7ChjRQfVpPPa0dpca9lglQdborglig+L3sawXJf0Qq93HhjRLQN2Gzj 02xzjbNFoCrW5GFnbk4oJLSP7XKexTDyrDCfkdDIk5D3ci2mG8Ygwn6TuQn+tlIIZxjq ikbJDLCEuQC/tdnhAK8q0azMU9Rfw4yYsijj8kBZMNzF2zMfkVwFb2jLpKlP30ZLopH3 NQlrQWZd7ExRwILqIKIe4CR+bTfKdd5+aHwvHvM4qEc6flVZUbzFTQcD/FxVJWS8Npth knT/HvNMrFO2FwbGJAALfWjnHdFrAnyHhF3UjPZLVbcIJd4KYszbj96QZ+XKxkJNBQLn 4wRQ== 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=rhaCXKy9AxCH3XftVB16U/0rOcntJBEnikdgIJRT98QxljHl6OoJ1PpGGSYMNCwed1 iAzZe8HAueGG+o8dek2bA5UymOpjimP2WmtZp4S+ofCeeJbvoL1d4kSrw3rIELc4b8w1 5v/r+JGHKhPj6hjy+1X6RMIP4zQYUTBuKAGpXG8t5T9jEoMh7Wbo1Ojzu3+OcFxdHOdk AcRmfLvTvM+TfMFZtpR6gwSS1dg0Ezg/aNQhGLgGhVfOh1zZVpg3o8k9/l4htY9U2UEB 6BihzKfpnRcEeTJXPto8E86NKEVMeyCvnKay8qSr0EFw+Ch6FSKvXg0Q77RYqhSdjmMT L1kg== X-Gm-Message-State: AGRZ1gLpRe9THektnRFoCOJaus9t22IfCuKLCKv4fld9Sg0R+DkApSpH 0ojDjAyAquUjymD3G8Z2CwRlUgU5 X-Google-Smtp-Source: AJdET5dRFzJ0d2lai7olCwwQMiPErPJaAPa3WHQjzsJda+c9FuWHuLENjRyLvmbE7hU/i85ZRAK5TQ== X-Received: by 2002:aca:dcd7:: with SMTP id t206-v6mr1816280oig.20.1540995658166; Wed, 31 Oct 2018 07:20:58 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:23 -0500 Message-Id: <20181031141925.30026-23-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-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::229 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's nicer from a management perspective that the agent can survive hotplug/unplug of the channel device, or be started prior to the installation of the channel device's driver without and still be able to resume normal function afterward. On linux there are alternatives like systemd to support this, but on w32 --retry-path is the only option so it makes sense to set it by default when installed as a w32 service. Signed-off-by: Michael Roth --- qga/installer/qemu-ga.wxs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index f751a7e9f7..64bf90bd85 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -78,7 +78,7 @@ Account=3D"LocalSystem" ErrorControl=3D"ignore" Interactive=3D"no" - Arguments=3D"-d" + Arguments=3D"-d --retry-path" > --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540995963032494.258523154517; Wed, 31 Oct 2018 07:26:03 -0700 (PDT) Received: from localhost ([::1]:59902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrRZ-00060X-Ov for importer@patchew.org; Wed, 31 Oct 2018 10:26:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMs-00016b-Qx for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMp-0007LG-35 for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:10 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:42971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMo-0007Hq-Eq for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:06 -0400 Received: by mail-oi1-x231.google.com with SMTP id h23-v6so13726244oih.9 for ; Wed, 31 Oct 2018 07:21:01 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id b185-v6sm8655062oia.12.2018.10.31.07.20.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mK5a7Z5zumPu2nLwlxQAQAUPJW+cZQHhbt7ia2+g+Zw=; b=IrfOLkt30oWhmRmqZoZo6e42MlozfUvdPu1a9C2kDhSjBFUU7RSKiT2/wmHlSGpv1a dNK133+QYJlVBvODB1uRGtiw/Lay7TAT9byzA2BleSR+72DMrHhlHLmF44u86Mqdudi1 uI9VB71K5zeN0XSaYAOzXjx7sKskrY9kBLZnqgWyFGYRUdojNlhZxdy+l6CPhugJ/BiB 78+GlATakA6i1Y91iIwAgy4oeAEWOu4s7aNoL1lCbSOI/6imvXtAJjy1/VfZXWqG/xFY tZk/2A9FZBgK0kxQ9AySJy6vaJ9hqO78zK+xv8vu5EpXAsdAKKea/E3TmJIfXzFwHuFN L97Q== 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=dHRwmKWVfeAtXw8m3CVUcNU4/gQN6fE6up1hSzblF4OIlioYyR63nQqzjBsuLE2baT se3uElzJfUjByPYg6QO38GFmWvlkHBMwJx5+Ji9Ulmx/3EPp3gQJPRapPtOIMGhTBQik P4Xu8kapQ/i+FpTd+k7N7Qwi3MmlukP1MBE1sQ1DABPlEPEfX0bvlm8VGGm2rrzn3n3Q IyvC1wQejIbtQLeIwF6aW8duhJFET+cDUSxyRTDgkmMVI30B3LDzQlz+yNDPzBsjH0l/ ycN2jhqRfGddOcNKvBs09mb1WlBTRA/VkzaM4CPQswGXr4CEFJykt4tsJBHXBtg3IbBm 6cpg== X-Gm-Message-State: AGRZ1gJM8y16eOwsyjOJJe1YFS9pl068hJ045fyT0p/BkCvhDOuVyNUB j/KDVQ7vngn6h3B9AzsB2WnoYH6X X-Google-Smtp-Source: AJdET5dRua6chhAUpJder7zL7KSz63Ch3g/bNfCrYqYm6BK9xulDGAcoMM0waJgsfyuTI9FKAmxvqA== X-Received: by 2002:aca:5fc6:: with SMTP id t189-v6mr1992161oib.103.1540995660337; Wed, 31 Oct 2018 07:21:00 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:24 -0500 Message-Id: <20181031141925.30026-24-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::231 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9 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, GAChannel= Method method, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, = NULL); if (c->handle =3D=3D INVALID_HANDLE_VALUE) { - g_critical("error opening path %s", newpath); + g_critical("error opening path %s: %s", newpath, + g_win32_error_message(GetLastError())); return false; } =20 --=20 2.17.1 From nobody Sun May 5 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154099669100928.72224798539571; Wed, 31 Oct 2018 07:38:11 -0700 (PDT) Received: from localhost ([::1]:59969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrdJ-0001lP-Jt for importer@patchew.org; Wed, 31 Oct 2018 10:38:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHrMr-00015m-Tq for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHrMq-0007Lj-Kp for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:09 -0400 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]:35881) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHrMq-0007KL-9h for qemu-devel@nongnu.org; Wed, 31 Oct 2018 10:21:08 -0400 Received: by mail-ot1-x333.google.com with SMTP id x4so14686582otg.3 for ; Wed, 31 Oct 2018 07:21:05 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id u11sm9585825otc.14.2018.10.31.07.21.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 07:21: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=+3EgmmikQq+I7mn9Hitw7dh66ejEiEkMl9ZvZ+ITy6g=; b=FJ5dqZknNAQNX4GElhFPTUQDtxCjySlFjcAbM7IH/FfS0NUX1E5tHlFRFPIbiDs8CO Tqr4FLpv7DqpdBc+aMed1aGPxQDu1d4wo6TwJC3xhEL49zUHf94eT4VMTexbFTgKiiDE COlveZZt43wSeE3NePFH675eslxfeb1AARbnYUX+XDxkn+Wv/4in+cVwNLWlmgvT1wEZ l3GoKmafTy/62RuI4RSPaM22kmNfw1Ej3spZZSyquLKRGep3qfIvi6vncDaAl0fwQijw lvq6Y3idlbRUBi96WhSlyHJBsL+ibLaln5qxnr2shCSfTFZzbzgi2s8Q2iN5vn8td16I 2Twg== 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=lxAGfkJgAJ4JFAiMoSxm31RObclZYdynn6iuEqXpogFsxtVpLI/gJDQqlxXBl9LmGj LpATP3/0cE6B1Zl29uDGDMkItvbyQL0XfZtyKSFMUcdtUsY45UQnUqc6gUlPbLgIOQTw zHrgh156xR4IQzhCnw0c/Vc87vnkZLh/eujn/9Kgz8gx/CNP0NukEVid60OZpTfNVx7B vyH+HRCaDnztTsJjP552AOlzliQ9upMP9Cq1Qr9eNq+got03wCV/XXoJLMJHTm1tVJ7L OXHf6CGSwENVGdzyeH4e2ABdLGUjFNwuRm/1zDhrOzSJCnLvgXoflruf1ubRJinFWz/K U+YQ== X-Gm-Message-State: AGRZ1gIoG8bbZ9zWYJi5FMjfKVKtqX8kVTt4g447qZ4EdCcNIdOK11nc 2DrsF2fWDULxu+HvKJf+LaG8Qbwq X-Google-Smtp-Source: AJdET5fD6GQb6sDkl/zlaMCwmPkaRgAcdKVWy+Nic9WcOqj9ADmmSPYAVKddulrrRPBIrQl+NIoI1A== X-Received: by 2002:a9d:600f:: with SMTP id h15mr1812366otj.42.1540995663571; Wed, 31 Oct 2018 07:21:03 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2018 09:19:25 -0500 Message-Id: <20181031141925.30026-25-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031141925.30026-1-mdroth@linux.vnet.ibm.com> References: <20181031141925.30026-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::333 Subject: [Qemu-devel] [PULL v3 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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[] =3D { #ifdef _WIN32 DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, LPVOID ctx); +DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data); VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif static int run_agent(GAState *s); @@ -677,6 +680,36 @@ static gboolean channel_init(GAState *s, const gchar *= method, const gchar *path, } =20 #ifdef _WIN32 +DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data) +{ + DWORD ret =3D NO_ERROR; + PDEV_BROADCAST_HDR broadcast_header =3D (PDEV_BROADCAST_HDR)data; + + if (broadcast_header->dbch_devicetype =3D=3D DBT_DEVTYP_DEVICEINTERFAC= E) { + switch (type) { + /* Device inserted */ + case DBT_DEVICEARRIVAL: + /* Start QEMU-ga's service */ + if (!SetEvent(ga_state->wakeup_event)) { + ret =3D GetLastError(); + } + break; + /* Device removed */ + case DBT_DEVICEQUERYREMOVE: + case DBT_DEVICEREMOVEPENDING: + case DBT_DEVICEREMOVECOMPLETE: + /* Stop QEMU-ga's service */ + if (!ResetEvent(ga_state->wakeup_event)) { + ret =3D GetLastError(); + } + break; + default: + ret =3D ERROR_CALL_NOT_IMPLEMENTED; + } + } + return ret; +} + DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, LPVOID ctx) { @@ -688,9 +721,13 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD ty= pe, LPVOID data, case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: quit_handler(SIGTERM); + SetEvent(ga_state->wakeup_event); service->status.dwCurrentState =3D SERVICE_STOP_PENDING; SetServiceStatus(service->status_handle, &service->status); break; + case SERVICE_CONTROL_DEVICEEVENT: + handle_serial_device_events(type, data); + break; =20 default: ret =3D ERROR_CALL_NOT_IMPLEMENTED; @@ -717,10 +754,24 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[]) service->status.dwServiceSpecificExitCode =3D NO_ERROR; service->status.dwCheckPoint =3D 0; service->status.dwWaitHint =3D 0; + DEV_BROADCAST_DEVICEINTERFACE notification_filter; + ZeroMemory(¬ification_filter, sizeof(notification_filter)); + notification_filter.dbcc_devicetype =3D DBT_DEVTYP_DEVICEINTERFACE; + notification_filter.dbcc_size =3D sizeof(DEV_BROADCAST_DEVICEINTERFACE= ); + notification_filter.dbcc_classguid =3D GUID_VIOSERIAL_PORT; + + service->device_notification_handle =3D + RegisterDeviceNotification(service->status_handle, + ¬ification_filter, DEVICE_NOTIFY_SERVICE_HANDLE); + if (!service->device_notification_handle) { + g_critical("Failed to register device notification handle!\n"); + return; + } SetServiceStatus(service->status_handle, &service->status); =20 run_agent(ga_state); =20 + UnregisterDeviceNotification(service->device_notification_handle); service->status.dwCurrentState =3D SERVICE_STOPPED; SetServiceStatus(service->status_handle, &service->status); } @@ -1328,12 +1379,24 @@ static GAState *initialize_agent(GAConfig *config, = int socket_activation) =20 s->config =3D config; s->socket_activation =3D socket_activation; + +#ifdef _WIN32 + s->wakeup_event =3D CreateEvent(NULL, TRUE, FALSE, TEXT("WakeUp")); + if (s->wakeup_event =3D=3D NULL) { + g_critical("CreateEvent failed"); + return NULL; + } +#endif + ga_state =3D s; return s; } =20 static void cleanup_agent(GAState *s) { +#ifdef _WIN32 + CloseHandle(s->wakeup_event); +#endif if (s->command_state) { ga_command_state_cleanup_all(s->command_state); ga_command_state_free(s->command_state); @@ -1365,6 +1428,27 @@ static int run_agent_once(GAState *s) return EXIT_SUCCESS; } =20 +static void wait_for_channel_availability(GAState *s) +{ + g_warning("waiting for channel path..."); +#ifndef _WIN32 + sleep(QGA_RETRY_INTERVAL); +#else + DWORD dwWaitResult; + + dwWaitResult =3D WaitForSingleObject(s->wakeup_event, INFINITE); + + switch (dwWaitResult) { + case WAIT_OBJECT_0: + break; + case WAIT_TIMEOUT: + break; + default: + g_critical("WaitForSingleObject failed"); + } +#endif +} + static int run_agent(GAState *s) { int ret =3D EXIT_SUCCESS; @@ -1375,7 +1459,7 @@ static int run_agent(GAState *s) ret =3D run_agent_once(s); if (s->config->retry_path && !s->force_exit) { g_warning("agent stopped unexpectedly, restarting..."); - sleep(QGA_RETRY_INTERVAL); + wait_for_channel_availability(s); } } while (s->config->retry_path && !s->force_exit); =20 diff --git a/qga/service-win32.h b/qga/service-win32.h index 89e99dfede..7b16d69b57 100644 --- a/qga/service-win32.h +++ b/qga/service-win32.h @@ -20,9 +20,13 @@ #define QGA_SERVICE_NAME "qemu-ga" #define QGA_SERVICE_DESCRIPTION "Enables integration with QEMU machine em= ulator and virtualizer." =20 +static const GUID GUID_VIOSERIAL_PORT =3D { 0x6fde7521, 0x1b65, 0x48ae, +{ 0xb6, 0x28, 0x80, 0xbe, 0x62, 0x1, 0x60, 0x26 } }; + typedef struct GAService { SERVICE_STATUS status; SERVICE_STATUS_HANDLE status_handle; + HDEVNOTIFY device_notification_handle; } GAService; =20 int ga_install_service(const char *path, const char *logfile, --=20 2.17.1