From nobody Mon Feb 9 17:35:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1626265834098409.15758709893043; Wed, 14 Jul 2021 05:30:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-535-6cwA93xlNJGeNqiwUyZZhQ-1; Wed, 14 Jul 2021 08:30:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 508B519057A1; Wed, 14 Jul 2021 12:30:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 208F426E51; Wed, 14 Jul 2021 12:30:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D2F9B1832E78; Wed, 14 Jul 2021 12:30:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16ECTCTT023953 for ; Wed, 14 Jul 2021 08:29:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8A6F2200E49B; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 842112012E34 for ; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33A8996B04D for ; Wed, 14 Jul 2021 12:29:12 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-TGiiixuYMl-5W0MJSScLrg-1; Wed, 14 Jul 2021 08:29:07 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GPxY12hpzz7BH1; Wed, 14 Jul 2021 20:25:25 +0800 (CST) Received: from dggpeml500009.china.huawei.com (7.185.36.209) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:28:58 +0800 Received: from 90078.china.huawei.com (10.174.187.199) by dggpeml500009.china.huawei.com (7.185.36.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 14 Jul 2021 20:28:58 +0800 X-MC-Unique: 6cwA93xlNJGeNqiwUyZZhQ-1 X-MC-Unique: TGiiixuYMl-5W0MJSScLrg-1 From: Yang Fei To: Subject: [PATCH v2 1/3] util: Move virGetCgroupValueRaw to vircgroup.c and rename it virGetValueRaw Date: Wed, 14 Jul 2021 20:28:52 +0800 Message-ID: <20210714122854.46848-2-yangfei85@huawei.com> In-Reply-To: <20210714122854.46848-1-yangfei85@huawei.com> References: <20210714122854.46848-1-yangfei85@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.199] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500009.china.huawei.com (7.185.36.209) X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 16ECTCTT023953 X-loop: libvir-list@redhat.com Cc: liangpeng10@huawei.com, yubihong@huawei.com, yangfei85@huawei.com, pkrempa@redhat.com, xiexiangyou@huawei.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1626265834784100004 Content-Type: text/plain; charset="utf-8" Move virGetCgroupValueRaw from vircgroup.c, so that we can call it more appropriately at any where. And change it to a more generic name virGetValueRaw. Replace virGetCgroupValueRaw by virGetValueRaw in cgroup data obtain. Signed-off-by: Yang Fei --- src/util/vircgroup.c | 29 ++--------------------------- src/util/vircgrouppriv.h | 3 --- src/util/vircgroupv1.c | 5 +++-- src/util/vircgroupv2.c | 5 +++-- src/util/virutil.c | 23 +++++++++++++++++++++++ src/util/virutil.h | 3 +++ 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 65a81e8d6f..80a06c78b9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -48,6 +48,7 @@ #include "virtypedparam.h" #include "virhostcpu.h" #include "virthread.h" +#include "virutil.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -539,31 +540,6 @@ virCgroupSetValueRaw(const char *path, return 0; } =20 - -int -virCgroupGetValueRaw(const char *path, - char **value) -{ - int rc; - - *value =3D NULL; - - VIR_DEBUG("Get value %s", path); - - if ((rc =3D virFileReadAll(path, 1024*1024, value)) < 0) { - virReportSystemError(errno, - _("Unable to read from '%s'"), path); - return -1; - } - - /* Terminated with '\n' has sometimes harmful effects to the caller */ - if (rc > 0 && (*value)[rc - 1] =3D=3D '\n') - (*value)[rc - 1] =3D '\0'; - - return 0; -} - - int virCgroupSetValueStr(virCgroup *group, int controller, @@ -590,10 +566,9 @@ virCgroupGetValueStr(virCgroup *group, if (virCgroupPathOfController(group, controller, key, &keypath) < 0) return -1; =20 - return virCgroupGetValueRaw(keypath, value); + return virGetValueRaw(keypath, value); } =20 - int virCgroupGetValueForBlkDev(const char *str, const char *path, diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index caf7ed84db..627308d995 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -76,9 +76,6 @@ int virCgroupSetValueDBus(const char *unitName, int virCgroupSetValueRaw(const char *path, const char *value); =20 -int virCgroupGetValueRaw(const char *path, - char **value); - int virCgroupSetValueStr(virCgroup *group, int controller, const char *key, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 8a04bb2e4a..2a40de51a0 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -42,6 +42,7 @@ #include "virerror.h" #include "viralloc.h" #include "virthread.h" +#include "virutil.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -1042,7 +1043,7 @@ virCgroupV1GetBlkioWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if (virStrToLong_ui(value, NULL, 10, weight) < 0) { @@ -1297,7 +1298,7 @@ virCgroupV1GetBlkioDeviceWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 8881d3a88a..1c444d58f2 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -41,6 +41,7 @@ #include "virlog.h" #include "virstring.h" #include "virsystemd.h" +#include "virutil.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -701,7 +702,7 @@ virCgroupV2GetBlkioWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if ((tmp =3D strstr(value, "default "))) { @@ -907,7 +908,7 @@ virCgroupV2GetBlkioDeviceWeight(virCgroup *group, return -1; } =20 - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; =20 if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) diff --git a/src/util/virutil.c b/src/util/virutil.c index 311cbbf93a..c0d25fe247 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1936,3 +1936,26 @@ virPipeNonBlock(int fds[2]) { return virPipeImpl(fds, true, true); } + +int +virGetValueRaw(const char *path, + char **value) +{ + int rc; + + *value =3D NULL; + + VIR_DEBUG("Get value %s", path); + + if ((rc =3D virFileReadAll(path, 1024*1024, value)) < 0) { + virReportSystemError(errno, + _("Unable to read from '%s'"), path); + return -1; + } + + /* Terminated with '\n' has sometimes harmful effects to the caller */ + if (rc > 0 && (*value)[rc - 1] =3D=3D '\n') + (*value)[rc - 1] =3D '\0'; + + return 0; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 854b494890..851b421476 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -225,3 +225,6 @@ int virPipeQuiet(int fds[2]); * Returns: -1 on error, 0 on success */ int virPipeNonBlock(int fds[2]); + +int virGetValueRaw(const char *path, + char **value); --=20 2.23.0