[libvirt] [PATCH 3/8] qemu: Move preserved mount points path generation into a separate function

Michal Privoznik posted 8 patches 8 years, 7 months ago
[libvirt] [PATCH 3/8] qemu: Move preserved mount points path generation into a separate function
Posted by Michal Privoznik 8 years, 7 months ago
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>
---
 src/qemu/qemu_domain.c | 59 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 212717c80..286d60761 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7572,6 +7572,41 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
 }
 
 
+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:
  *
@@ -7628,30 +7663,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg,
         goto error;
 
     for (i = 0; i < nmounts; i++) {
-        char *tmp;
-        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)
+        if (!(paths[i] = qemuDomainGetPreservedMountPath(cfg, vm, mounts[i])))
             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)
-- 
2.13.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/8] qemu: Move preserved mount points path generation into a separate function
Posted by John Ferlan 8 years, 7 months ago

On 06/22/2017 12:18 PM, Michal Privoznik wrote:
> 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>
> ---
>  src/qemu/qemu_domain.c | 59 ++++++++++++++++++++++++++++++--------------------
>  1 file changed, 36 insertions(+), 23 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 212717c80..286d60761 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -7572,6 +7572,41 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
>  }
>  
>  

/* Returns allocated string on success which the caller must free and
NULL on failure */

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/8] qemu: Move preserved mount points path generation into a separate function
Posted by Michal Privoznik 8 years, 7 months ago
On 06/27/2017 11:40 PM, John Ferlan wrote:
> 
> 
> On 06/22/2017 12:18 PM, Michal Privoznik wrote:
>> 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>
>> ---
>>  src/qemu/qemu_domain.c | 59 ++++++++++++++++++++++++++++++--------------------
>>  1 file changed, 36 insertions(+), 23 deletions(-)
>>
>> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>> index 212717c80..286d60761 100644
>> --- a/src/qemu/qemu_domain.c
>> +++ b/src/qemu/qemu_domain.c
>> @@ -7572,6 +7572,41 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
>>  }
>>  
>>  
> 
> /* Returns allocated string on success which the caller must free and
> NULL on failure */

Okay, I've extended this to:

/**
 * 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. */

> 
> Reviewed-by: John Ferlan <jferlan@redhat.com>

Thanks.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/8] qemu: Move preserved mount points path generation into a separate function
Posted by John Ferlan 8 years, 7 months ago

On 07/10/2017 09:09 AM, Michal Privoznik wrote:
> On 06/27/2017 11:40 PM, John Ferlan wrote:
>>
>>
>> On 06/22/2017 12:18 PM, Michal Privoznik wrote:
>>> 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>
>>> ---
>>>  src/qemu/qemu_domain.c | 59 ++++++++++++++++++++++++++++++--------------------
>>>  1 file changed, 36 insertions(+), 23 deletions(-)
>>>
>>> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>>> index 212717c80..286d60761 100644
>>> --- a/src/qemu/qemu_domain.c
>>> +++ b/src/qemu/qemu_domain.c
>>> @@ -7572,6 +7572,41 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
>>>  }
>>>  
>>>  
>>
>> /* Returns allocated string on success which the caller must free and
>> NULL on failure */
> 
> Okay, I've extended this to:
> 
> /**
>  * 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. */
> 

I hope the */ ended up on a new line...

>>
>> Reviewed-by: John Ferlan <jferlan@redhat.com>
> 
> Thanks.
> 
> Michal
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list