From nobody Sun Feb 8 18:09:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560953860; cv=none; d=zoho.com; s=zohoarc; b=E3zkOsVnSiPFiLo/mWyDLGjHMv6Hch0YFH4MNI9jIjGjZwrx1R/sTN6e873OytIVzNmpntWlD1eP6wwegInti1dUApsPxmy8FpFP6NWqZr2JJqXo5hnquuQEXkVGKF30RMPIGs5y6nDgHgwuHzxIm5gtrox+HoIYqtBTArW/ZFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560953860; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZdiLaQbpAgwujFRdLVR1OZqUKlHhfaoHnMUk66+V2Rk=; b=eUzDlk658tlfAUSezMPDs6++Z9nQy+20SmOIyRH+7S2cOgB7cNpavSFOlA37FDA1f7Mo3ohygck2wjLIQc8qpGUxCiBQ18Yg5Ab4U2CBCcM5O/Czm7Ijdd+Mhj+oiGNR3U6um9E7XkJpCylsKlMlxQvd+59LYX2++n6wqM3mnm4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560953860977833.6457750280263; Wed, 19 Jun 2019 07:17:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0704930C31AA; Wed, 19 Jun 2019 14:17:34 +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 CEB6710190A8; Wed, 19 Jun 2019 14:17:32 +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 1257A1806B1A; Wed, 19 Jun 2019 14:17:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5JEGvrg017684 for ; Wed, 19 Jun 2019 10:16:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18C6B60FFE; Wed, 19 Jun 2019 14:16:57 +0000 (UTC) Received: from antique-laptop.redhat.com (ovpn-200-46.brq.redhat.com [10.40.200.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75E9660FAB for ; Wed, 19 Jun 2019 14:16:56 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 16:16:47 +0200 Message-Id: <89d11dbd6cd11bda97731b6613e74bfbb1428575.1560953706.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] util: vircgroup: introduce virCgroup(Get|Set)ValueRaw 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 19 Jun 2019 14:17:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If we need to get a path of specific file and we need to check its existence before we use it then we can reuse that path to get/set values instead of calling the existing get/set value functions which would be building the path again. Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 62 ++++++++++++++++++++++++++-------------- src/util/vircgrouppriv.h | 6 ++++ 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index f58e336404..278453ea2f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -455,28 +455,22 @@ virCgroupGetBlockDevString(const char *path) =20 =20 int -virCgroupSetValueStr(virCgroupPtr group, - int controller, - const char *key, +virCgroupSetValueRaw(const char *path, const char *value) { - VIR_AUTOFREE(char *) keypath =3D NULL; - char *tmp =3D NULL; + char *tmp; =20 - if (virCgroupPathOfController(group, controller, key, &keypath) < 0) - return -1; - - VIR_DEBUG("Set value '%s' to '%s'", keypath, value); - if (virFileWriteStr(keypath, value, 0) < 0) { + VIR_DEBUG("Set value '%s' to '%s'", path, value); + if (virFileWriteStr(path, value, 0) < 0) { if (errno =3D=3D EINVAL && - (tmp =3D strrchr(keypath, '/'))) { + (tmp =3D strrchr(path, '/'))) { virReportSystemError(errno, _("Invalid value '%s' for '%s'"), value, tmp + 1); return -1; } virReportSystemError(errno, - _("Unable to write to '%s'"), keypath); + _("Unable to write to '%s'"), path); return -1; } =20 @@ -485,24 +479,18 @@ virCgroupSetValueStr(virCgroupPtr group, =20 =20 int -virCgroupGetValueStr(virCgroupPtr group, - int controller, - const char *key, +virCgroupGetValueRaw(const char *path, char **value) { - VIR_AUTOFREE(char *) keypath =3D NULL; int rc; =20 *value =3D NULL; =20 - if (virCgroupPathOfController(group, controller, key, &keypath) < 0) - return -1; + VIR_DEBUG("Get value %s", path); =20 - VIR_DEBUG("Get value %s", keypath); - - if ((rc =3D virFileReadAll(keypath, 1024*1024, value)) < 0) { + if ((rc =3D virFileReadAll(path, 1024*1024, value)) < 0) { virReportSystemError(errno, - _("Unable to read from '%s'"), keypath); + _("Unable to read from '%s'"), path); return -1; } =20 @@ -514,6 +502,36 @@ virCgroupGetValueStr(virCgroupPtr group, } =20 =20 +int +virCgroupSetValueStr(virCgroupPtr group, + int controller, + const char *key, + const char *value) +{ + VIR_AUTOFREE(char *) keypath =3D NULL; + + if (virCgroupPathOfController(group, controller, key, &keypath) < 0) + return -1; + + return virCgroupSetValueRaw(keypath, value); +} + + +int +virCgroupGetValueStr(virCgroupPtr group, + int controller, + const char *key, + char **value) +{ + VIR_AUTOFREE(char *) keypath =3D NULL; + + if (virCgroupPathOfController(group, controller, key, &keypath) < 0) + return -1; + + return virCgroupGetValueRaw(keypath, value); +} + + int virCgroupGetValueForBlkDev(virCgroupPtr group, int controller, diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 9110c77297..758091811e 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -58,6 +58,12 @@ struct _virCgroup { virCgroupV2Controller unified; }; =20 +int virCgroupSetValueRaw(const char *path, + const char *value); + +int virCgroupGetValueRaw(const char *path, + char **value); + int virCgroupSetValueStr(virCgroupPtr group, int controller, const char *key, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list