qemu: Move memPath generation from memoryBackingDir to a separate function

In near future we will need more than just a plain VIR_STRDUP().
Better implement that in a separate function and in
qemuBuildMemoryBackendStr() which is complicated enough already.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Michal Privoznik 2017-10-23 11:33:06 +02:00
parent fe70fd0c10
commit ae1b5d47e5
3 changed files with 22 additions and 1 deletions

View File

@ -3439,7 +3439,7 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendProps,
} else { } else {
/* We can have both pagesize and mem source. If that's the case, /* We can have both pagesize and mem source. If that's the case,
* prefer hugepages as those are more specific. */ * prefer hugepages as those are more specific. */
if (VIR_STRDUP(memPath, cfg->memoryBackingDir) < 0) if (qemuGetMemoryBackingPath(cfg, &memPath) < 0)
goto cleanup; goto cleanup;
} }

View File

@ -1748,3 +1748,21 @@ qemuGetDomainHupageMemPath(const virDomainDef *def,
return 0; return 0;
} }
/**
* qemuGetMemoryBackingPath:
* @cfg: the driver config
* @memPath: constructed path
*
* Constructs path to memory backing dir and stores it at @memPath.
*
* Returns: 0 on success,
* -1 otherwise (with error reported).
*/
int
qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg,
char **memPath)
{
return VIR_STRDUP(*memPath, cfg->memoryBackingDir);
}

View File

@ -363,4 +363,7 @@ int qemuGetDomainHupageMemPath(const virDomainDef *def,
virQEMUDriverConfigPtr cfg, virQEMUDriverConfigPtr cfg,
unsigned long long pagesize, unsigned long long pagesize,
char **memPath); char **memPath);
int qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg,
char **memPath);
#endif /* __QEMUD_CONF_H */ #endif /* __QEMUD_CONF_H */