[libvirt] [PATCH 3/5] util: Add getters for cgroup block device I/O throttling

Martin Kletzander mkletzan at redhat.com
Tue Aug 18 23:35:52 UTC 2015


On Tue, Aug 18, 2015 at 01:15:43PM -0400, John Ferlan wrote:
>On 08/03/2015 10:50 AM, Martin Kletzander wrote:
>> Since now they were not needed, but I sense they will be in a short
>> while.
>>
>> Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
>> ---
>>  src/libvirt_private.syms |   5 +
>>  src/util/vircgroup.c     | 277 ++++++++++++++++++++++++++++++++++++++++++++++-
>>  src/util/vircgroup.h     |  20 ++++
>>  3 files changed, 299 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
>> index afa85ded9061..9d527fb8b99a 100644
>> --- a/src/util/vircgroup.c
>> +++ b/src/util/vircgroup.c
>> @@ -804,6 +804,36 @@ virCgroupGetValueStr(virCgroupPtr group,
>>
>>
>>  static int
>> +virCgroupGetValueForBlkDev(virCgroupPtr group,
>> +                           int controller,
>> +                           const char *key,
>> +                           const char *path,
>> +                           char **value)
>> +{
>> +    char *prefix = NULL;
>> +    char *str = NULL;
>> +    char **lines = NULL;
>> +    int ret = -1;
>> +
>> +    if (virCgroupGetValueStr(group, controller, key, &str) < 0)
>> +        goto error;
>> +
>> +    if (!(prefix = virCgroupGetBlockDevString(path)))
>> +        return -1;
>
>^^^
>str is leaked.  (Coverity found)
>

Copy-paste error, thanks for catching that.

>> +
>> +    if (!(lines = virStringSplit(str, "\n", -1)))
>> +        goto error;
>> +
>> +    ret = VIR_STRDUP(*value, virStringGetFirstWithPrefix(lines, prefix));
>
>                                ^^^ can return NULL
>
>VIR_STRDUP(*value, NULL)
>
>??
>

That wouldn't actually do any harm, the function would return 0, but
to make it as clear as possible, this is the diff that I applied
before pushing:

diff --git c/src/util/vircgroup.c w/src/util/vircgroup.c
index 9d527fb8b99a..c94512a148b9 100644
--- c/src/util/vircgroup.c
+++ w/src/util/vircgroup.c
@@ -819,12 +819,15 @@ virCgroupGetValueForBlkDev(virCgroupPtr group,
         goto error;

     if (!(prefix = virCgroupGetBlockDevString(path)))
-        return -1;
+        goto error;

     if (!(lines = virStringSplit(str, "\n", -1)))
         goto error;

-    ret = VIR_STRDUP(*value, virStringGetFirstWithPrefix(lines, prefix));
+    if (VIR_STRDUP(*value, virStringGetFirstWithPrefix(lines, prefix)) < 0)
+        goto error;
+
+    ret = 0;
  error:
     VIR_FREE(str);
     VIR_FREE(prefix);
--

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150818/6baeae1b/attachment-0001.sig>


More information about the libvir-list mailing list