From nobody Sun May 19 03:12:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652318543027815.1341726142341; Wed, 11 May 2022 18:22:23 -0700 (PDT) Received: from localhost ([::1]:51196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1noxX4-0001wR-0r for importer@patchew.org; Wed, 11 May 2022 21:22:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noxV3-0000QP-F7 for qemu-devel@nongnu.org; Wed, 11 May 2022 21:20:17 -0400 Received: from [106.39.185.57] (port=36010 helo=smtp.cecloud.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1noxV0-0002Ui-6h for qemu-devel@nongnu.org; Wed, 11 May 2022 21:20:16 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp.cecloud.com (Postfix) with ESMTP id C01ED100002E2; Thu, 12 May 2022 09:19:58 +0800 (CST) Received: from localhost.localdomain (unknown [111.48.58.11]) by smtp.cecloud.com (postfix) whith ESMTP id P3903393T281471059030384S1652318397480418_; Thu, 12 May 2022 09:19:58 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 X-IP-DOMAINF: 1 X-UNIQUE-TAG: <570626b31ae9a4148bfd4b6678cb8dbf> X-RL-SENDER: luzhipeng@cestc.cn X-SENDER: luzhipeng@cestc.cn X-LOGIN-NAME: luzhipeng@cestc.cn X-FST-TO: qemu-devel@nongnu.org X-RCPT-COUNT: 7 X-SENDER-IP: 111.48.58.11 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 From: luzhipeng To: qemu-devel Cc: Michael Roth , Konstantin Kostiuk , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Michal Privoznik , luzhipeng Subject: [PATCH RESEND] qga: add guest-get-diskstats command for Linux guests Date: Thu, 12 May 2022 09:19:30 +0800 Message-Id: <20220512011930.214-1-luzhipeng@cestc.cn> X-Mailer: git-send-email 2.34.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 106.39.185.57 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=106.39.185.57; envelope-from=luzhipeng@cestc.cn; helo=smtp.cecloud.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1652318545813100001 Content-Type: text/plain; charset="utf-8" Add a new 'guest-get-diskstats' command for report disk io statistics for Linux guests. This can be usefull for getting io flow or handling IO fault, no need to enter guests. Signed-off-by: luzhipeng --- qga/commands-posix.c | 94 ++++++++++++++++++++++++++++++++++++++++++++ qga/commands-win32.c | 6 +++ qga/qapi-schema.json | 86 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 69f209af87..2b96c9ae6e 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2783,6 +2783,93 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_inf= o(Error **errp) return info; } =20 +#define MAX_NAME_LEN 128 +static GuestDiskStatsInfoList *guest_get_diskstats(Error **errp) +{ +#ifdef CONFIG_LINUX + GuestDiskStatsInfoList *head =3D NULL, **tail =3D &head; + const char *diskstats =3D "/proc/diskstats"; + FILE *fp; + size_t n; + char *line =3D NULL; + char dev_name[MAX_NAME_LEN]; + int i; + unsigned int ios_pgr, tot_ticks, rq_ticks, wr_ticks, dc_ticks, fl_tick= s; + unsigned long rd_ios, rd_merges_or_rd_sec, rd_ticks_or_wr_sec, wr_ios; + unsigned long wr_merges, rd_sec_or_wr_ios, wr_sec; + unsigned long dc_ios, dc_merges, dc_sec, fl_ios; + unsigned int major, minor; + + fp =3D fopen(diskstats, "r"); + if (fp =3D=3D NULL) { + error_setg_errno(errp, errno, "open(\"%s\")", diskstats); + return NULL; + } + while (getline(&line, &n, fp) !=3D -1) { + i =3D sscanf(line, "%u %u %s %lu %lu %lu" + "%lu %lu %lu %lu %u %u %u %u" + "%lu %lu %lu %u %lu %u", + &major, &minor, dev_name, + &rd_ios, &rd_merges_or_rd_sec, &rd_sec_or_wr_ios, + &rd_ticks_or_wr_sec, &wr_ios, &wr_merges, &wr_sec, + &wr_ticks, &ios_pgr, &tot_ticks, &rq_ticks, + &dc_ios, &dc_merges, &dc_sec, &dc_ticks, + &fl_ios, &fl_ticks); + GuestDiskStatsInfo *diskstatinfo =3D g_malloc0(sizeof *diskstatinf= o); + GuestDiskStats *diskstat =3D g_malloc0(sizeof *diskstat); + if (i >=3D 14) { + diskstatinfo->name =3D g_strdup(dev_name); + diskstatinfo->major =3D major; + diskstatinfo->minor =3D minor; + diskstat->rd_ios =3D rd_ios; + diskstat->rd_merges =3D rd_merges_or_rd_sec; + diskstat->rd_sectors =3D rd_sec_or_wr_ios; + diskstat->rd_ticks =3D rd_ticks_or_wr_sec; + diskstat->wr_ios =3D wr_ios; + diskstat->wr_merges =3D wr_merges; + diskstat->wr_sectors =3D wr_sec; + diskstat->wr_ticks =3D wr_ticks; + diskstat->ios_pgr =3D ios_pgr; + diskstat->tot_ticks =3D tot_ticks; + diskstat->rq_ticks =3D rq_ticks; + if (i >=3D 18) { + diskstat->dc_ios =3D dc_ios; + diskstat->dc_merges =3D dc_merges; + diskstat->dc_sectors =3D dc_sec; + diskstat->dc_ticks =3D dc_ticks; + } + if (i >=3D 20) { + diskstat->fl_ios =3D fl_ios; + diskstat->fl_ticks =3D fl_ticks; + } + diskstatinfo->stats =3D diskstat; + QAPI_LIST_APPEND(tail, diskstatinfo); + } else if (i =3D=3D 7) { + diskstatinfo->name =3D g_strdup(dev_name); + diskstatinfo->major =3D major; + diskstatinfo->minor =3D minor; + diskstat->rd_ios =3D rd_ios; + diskstat->rd_sectors =3D rd_merges_or_rd_sec; + diskstat->wr_ios =3D rd_sec_or_wr_ios; + diskstat->wr_sectors =3D rd_ticks_or_wr_sec; + } else { + g_free(diskstat); + g_free(diskstatinfo); + } + } + fclose(fp); + return head; +#else + g_debug("disk stats reporting available only for Linux"); + return NULL; +#endif +} + +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) +{ + return guest_get_diskstats(errp); +} + #else /* defined(__linux__) */ =20 void qmp_guest_suspend_disk(Error **errp) @@ -3131,6 +3218,13 @@ GuestDiskInfoList *qmp_guest_get_disks(Error **errp) return NULL; } =20 +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + + #endif /* CONFIG_FSFREEZE */ =20 #if !defined(CONFIG_FSTRIM) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index d56b5fd2a7..dcdeb76a68 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -2532,3 +2532,9 @@ char *qga_get_host_name(Error **errp) =20 return g_utf16_to_utf8(tmp, size, NULL, NULL, NULL); } + +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 4d8e506c9e..ec48629476 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1490,3 +1490,89 @@ { 'command': 'guest-ssh-remove-authorized-keys', 'data': { 'username': 'str', 'keys': ['str'] }, 'if': 'CONFIG_POSIX' } + +## +# @GuestDiskStats: +# +# @rd-sectors: of sectors read +# +# @wr-sectors: of sectors write +# +# @dc-sectors: of sectors discard +# +# @rd-ios: of read operations issued to the device +# +# @rd-merges: of read requests merged +# +# @wr-ios: of write operations issued to the device +# +# @wr-merges: of write requests merged +# +# @dc-ios: of discard operations issued to the device +# +# @dc-merges: of discard requests merged +# +# @fl-ios: of flush requests issued to the device +# +# @rd-ticks: Time of read requests in queue +# +# @wr-ticks: Time of write requests in queue +# +# @dc-ticks: Time of discard requests in queue +# +# @fl-ticks: Time of flush requests in queue +# +# @ios-pgr: of I/Os in progress +# +# @tot-ticks: of ticks total (for this device) for I/O +# +# @rq-ticks: of ticks requests spent in queue +# +# Since: 7.1 +## +{ 'struct': 'GuestDiskStats', + 'data': {'rd-sectors': 'uint64', + 'wr-sectors': 'uint64', + 'dc-sectors': 'uint64', + 'rd-ios': 'uint64', + 'rd-merges': 'uint64', + 'wr-ios': 'uint64', + 'wr-merges': 'uint64', + 'dc-ios': 'uint64', + 'dc-merges': 'uint64', + 'fl-ios': 'uint64', + 'rd-ticks': 'uint64', + 'wr-ticks': 'uint64', + 'dc-ticks': 'uint64', + 'fl-ticks': 'uint64', + 'ios-pgr': 'uint64', + 'tot-ticks': 'uint64', + 'rq-ticks': 'uint64' + } } + +## +# @GuestDiskStatsInfo: +# +# @name disk name +# +# @major major of disk +# +# @minor minor of disk +## +{ 'struct': 'GuestDiskStatsInfo', + 'data': {'name': 'str', + 'major': 'uint64', + 'minor': 'uint64', + 'stats': 'GuestDiskStats' } } + +## +# @guest-get-diskstats: +# +# Retrieve information about disk io. +# Returns: List of disk stats of guest. +# +# Since: 7.1 +## +{ 'command': 'guest-get-diskstats', + 'returns': ['GuestDiskStatsInfo'] +} --=20 2.31.1