util: Initialize virResctrlInfo struct right away

There is no need to have virResctrlGetInfo() when it must be called after
virResctrlInfoNew() anyway, otherwise it's just an unusable object.  When we
wrap the logic inside the New() function we'll save some calls later as well.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Martin Kletzander 2018-02-08 15:47:46 +01:00
parent 089c81b0e1
commit c95b9557b5
4 changed files with 14 additions and 7 deletions

View File

@ -1604,7 +1604,7 @@ virCapabilitiesInitResctrl(virCapsPtr caps)
if (!caps->host.resctrl)
return -1;
return virResctrlGetInfo(caps->host.resctrl);
return 0;
}

View File

@ -2632,7 +2632,6 @@ virResctrlAllocNew;
virResctrlAllocRemove;
virResctrlAllocSetID;
virResctrlAllocSetSize;
virResctrlGetInfo;
virResctrlInfoGetCache;
virResctrlInfoNew;

View File

@ -314,7 +314,7 @@ virResctrlUnlock(int fd)
/* virResctrlInfo-related definitions */
int
static int
virResctrlGetInfo(virResctrlInfoPtr resctrl)
{
DIR *dirp = NULL;
@ -448,10 +448,21 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
virResctrlInfoPtr
virResctrlInfoNew(void)
{
virResctrlInfoPtr ret = NULL;
if (virResctrlInitialize() < 0)
return NULL;
return virObjectNew(virResctrlInfoClass);
ret = virObjectNew(virResctrlInfoClass);
if (!ret)
return NULL;
if (virResctrlGetInfo(ret) < 0) {
virObjectUnref(ret);
return NULL;
}
return ret;
}

View File

@ -55,9 +55,6 @@ typedef virResctrlInfo *virResctrlInfoPtr;
virResctrlInfoPtr
virResctrlInfoNew(void);
int
virResctrlGetInfo(virResctrlInfoPtr resctrl);
int
virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
unsigned int level,