mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: Move preserved mount points path generation into a separate function
This function is going to be used on other places, so instead of copying code we can just call the function. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
7154917908
commit
4d8a914be0
@ -7573,6 +7573,53 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuDomainGetPreservedMountPath:
|
||||||
|
* @cfg: driver configuration data
|
||||||
|
* @vm: domain object
|
||||||
|
* @mount: mount point path to convert
|
||||||
|
*
|
||||||
|
* For given @mount point return new path where the mount point
|
||||||
|
* should be moved temporarily whilst building the namespace.
|
||||||
|
*
|
||||||
|
* Returns: allocated string on success which the caller must free,
|
||||||
|
* NULL on failure.
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
const char *mount)
|
||||||
|
{
|
||||||
|
char *path = NULL;
|
||||||
|
char *tmp;
|
||||||
|
const char *suffix = mount + strlen(DEVPREFIX);
|
||||||
|
size_t off;
|
||||||
|
|
||||||
|
if (STREQ(mount, "/dev"))
|
||||||
|
suffix = "dev";
|
||||||
|
|
||||||
|
if (virAsprintf(&path, "%s/%s.%s",
|
||||||
|
cfg->stateDir, vm->def->name, suffix) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* Now consider that @mount is "/dev/blah/blah2".
|
||||||
|
* @suffix then points to "blah/blah2". However, caller
|
||||||
|
* expects all the @paths to be the same depth. The
|
||||||
|
* caller doesn't always do `mkdir -p` but sometimes bare
|
||||||
|
* `touch`. Therefore fix all the suffixes. */
|
||||||
|
off = strlen(path) - strlen(suffix);
|
||||||
|
|
||||||
|
tmp = path + off;
|
||||||
|
while (*tmp) {
|
||||||
|
if (*tmp == '/')
|
||||||
|
*tmp = '.';
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuDomainGetPreservedMounts:
|
* qemuDomainGetPreservedMounts:
|
||||||
*
|
*
|
||||||
@ -7629,30 +7676,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
for (i = 0; i < nmounts; i++) {
|
for (i = 0; i < nmounts; i++) {
|
||||||
char *tmp;
|
if (!(paths[i] = qemuDomainGetPreservedMountPath(cfg, vm, mounts[i])))
|
||||||
const char *suffix = mounts[i] + strlen(DEVPREFIX);
|
|
||||||
size_t off;
|
|
||||||
|
|
||||||
if (STREQ(mounts[i], "/dev"))
|
|
||||||
suffix = "dev";
|
|
||||||
|
|
||||||
if (virAsprintf(&paths[i], "%s/%s.%s",
|
|
||||||
cfg->stateDir, vm->def->name, suffix) < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Now consider that mounts[i] is "/dev/blah/blah2".
|
|
||||||
* @suffix then points to "blah/blah2". However, caller
|
|
||||||
* expects all the @paths to be the same depth. The
|
|
||||||
* caller doesn't always do `mkdir -p` but sometimes bare
|
|
||||||
* `touch`. Therefore fix all the suffixes. */
|
|
||||||
off = strlen(paths[i]) - strlen(suffix);
|
|
||||||
|
|
||||||
tmp = paths[i] + off;
|
|
||||||
while (*tmp) {
|
|
||||||
if (*tmp == '/')
|
|
||||||
*tmp = '.';
|
|
||||||
tmp++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devPath)
|
if (devPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user