[libvirt] [PATCH v2 07/12] storage: Use virStoragePoolObjGetAutostartLink

John Ferlan posted 12 patches 7 years, 8 months ago
[libvirt] [PATCH v2 07/12] storage: Use virStoragePoolObjGetAutostartLink
Posted by John Ferlan 7 years, 8 months ago
Use the new accessor API for storage_driver.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/storage/storage_driver.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 7b1396f..a7a77ba 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -814,6 +814,7 @@ static int
 storagePoolUndefine(virStoragePoolPtr pool)
 {
     virStoragePoolObjPtr obj;
+    const char *autostartLink;
     virObjectEventPtr event = NULL;
     int ret = -1;
 
@@ -838,18 +839,17 @@ storagePoolUndefine(virStoragePoolPtr pool)
         goto cleanup;
     }
 
+    autostartLink = virStoragePoolObjGetAutostartLink(obj);
     if (virStoragePoolObjDeleteDef(obj) < 0)
         goto cleanup;
 
-    if (unlink(obj->autostartLink) < 0 &&
-        errno != ENOENT &&
-        errno != ENOTDIR) {
+    if (autostartLink && unlink(autostartLink) < 0 &&
+        errno != ENOENT && errno != ENOTDIR) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to delete autostart link '%s': %s"),
-                  obj->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf)));
+                  autostartLink, virStrerror(errno, ebuf, sizeof(ebuf)));
     }
 
-    VIR_FREE(obj->autostartLink);
 
     event = virStoragePoolEventLifecycleNew(obj->def->name,
                                             obj->def->uuid,
@@ -1268,6 +1268,7 @@ storagePoolSetAutostart(virStoragePoolPtr pool,
 {
     virStoragePoolObjPtr obj;
     const char *configFile;
+    const char *autostartLink;
     int ret = -1;
 
     storageDriverLock();
@@ -1283,6 +1284,8 @@ storagePoolSetAutostart(virStoragePoolPtr pool,
         goto cleanup;
     }
 
+    autostartLink = virStoragePoolObjGetAutostartLink(obj);
+
     autostart = (autostart != 0);
 
     if (obj->autostart != autostart) {
@@ -1294,18 +1297,18 @@ storagePoolSetAutostart(virStoragePoolPtr pool,
                 goto cleanup;
             }
 
-            if (symlink(configFile, obj->autostartLink) < 0) {
+            if (symlink(configFile, autostartLink) < 0) {
                 virReportSystemError(errno,
                                      _("Failed to create symlink '%s' to '%s'"),
-                                     obj->autostartLink, configFile);
+                                     autostartLink, configFile);
                 goto cleanup;
             }
         } else {
-            if (unlink(obj->autostartLink) < 0 &&
+            if (autostartLink && unlink(autostartLink) < 0 &&
                 errno != ENOENT && errno != ENOTDIR) {
                 virReportSystemError(errno,
                                      _("Failed to delete symlink '%s'"),
-                                     obj->autostartLink);
+                                     autostartLink);
                 goto cleanup;
             }
         }
-- 
2.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 07/12] storage: Use virStoragePoolObjGetAutostartLink
Posted by Michal Privoznik 7 years, 7 months ago
On 08/24/2017 03:09 PM, John Ferlan wrote:
> Use the new accessor API for storage_driver.
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/storage/storage_driver.c | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
> index 7b1396f..a7a77ba 100644
> --- a/src/storage/storage_driver.c
> +++ b/src/storage/storage_driver.c
> @@ -814,6 +814,7 @@ static int
>  storagePoolUndefine(virStoragePoolPtr pool)
>  {
>      virStoragePoolObjPtr obj;
> +    const char *autostartLink;
>      virObjectEventPtr event = NULL;
>      int ret = -1;
>  
> @@ -838,18 +839,17 @@ storagePoolUndefine(virStoragePoolPtr pool)
>          goto cleanup;
>      }
>  
> +    autostartLink = virStoragePoolObjGetAutostartLink(obj);

virStoragePoolObjGetAutostartLink() should look a bit different. Now
it's returning char * which suggests that caller is supposed to free the
retval. But in fact they shouldn't. const char * would be better. But
lets save that for a follow up patch.

Michal

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