代码拉取完成,页面将自动刷新
From 3e17cc136a1cb2a2ae5798448c553b16694ec408 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Sun, 27 Sep 2020 15:25:41 +0800
Subject: [PATCH] vcpustat: modify vcpu info acquirement from debugfs
Previous judgement to determine whether the vcpustat info matches the process is:
strstr(buf, pid) == buf + 1
But there is an exception that the kvm exit times may contain process pid string.
And then, we will calculate the delta between two defferent process.
So, modify this judgement codition.
---
src/vcpu_stat.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/vcpu_stat.c b/src/vcpu_stat.c
index 2076563..7ec2371 100644
--- a/src/vcpu_stat.c
+++ b/src/vcpu_stat.c
@@ -15,7 +15,6 @@
#include "type.h"
#include "vcpu_stat.h"
-#define PID_STRING_SIZE 20
#define KVM_VCPU_STAT_PATH "/sys/kernel/debug/kvm/vcpu_stat"
struct file_item vcpu_stat_stab[] = {
@@ -57,12 +56,9 @@ const int vcpu_stat_size = sizeof(vcpu_stat_stab) / sizeof(struct file_item);
int get_vcpu_stat(struct domain *dom)
{
char buf[BUF_SIZE];
- char pid[PID_STRING_SIZE];
+ unsigned int pid;
FILE *fp = NULL;
- if (snprintf(pid, PID_STRING_SIZE, "%u", dom->pid) < 0) {
- return -1;
- }
fp = fopen(KVM_VCPU_STAT_PATH, "r");
if (!fp) {
return -1;
@@ -72,7 +68,9 @@ int get_vcpu_stat(struct domain *dom)
char *p_next = NULL;
int i = 0;
- if (strstr(buf, pid) == NULL) {
+ /* judge whether vcpu pid is match */
+ sscanf(buf, "%u", &pid);
+ if (pid != dom->pid) {
continue;
}
for (p = strtok_r(buf, " \t\r\n", &p_next); p && i < vcpu_stat_size;
--
2.23.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。