]> xenbits.xensource.com Git - libvirt.git/commitdiff
virfile: Fix error path for forked virFileRemove
authorJohn Ferlan <jferlan@redhat.com>
Wed, 30 Sep 2015 21:37:27 +0000 (17:37 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 5 Oct 2015 12:14:44 +0000 (08:14 -0400)
As it turns out the caller in this case expects a return < 0 for failure
and to get/use "errno" rather than using the negative of returned status.
Again different than the create path.

If someone "deleted" a file from the pool without using virsh vol-delete,
then the unlink/rmdir would return an error (-1) and set errno to ENOENT.
The caller checks errno for ENOENT when determining whether to throw an
error message indicating the failure.  Without the change, the error
message is:

error: Failed to delete vol $vol
error: cannot unlink file '/$pathto/$vol': Success

This patch thus allows the fork path to follow the non-fork path
where unlink/rmdir return -1 and errno.

src/util/virfile.c

index 3d7efdc15e0949f81ba64d1994693ef6e2cbf8f8..a81f04c1a43c834b13ef72d4a219b56b616a83ba 100644 (file)
@@ -2364,8 +2364,10 @@ virFileRemove(const char *path,
                 status = EACCES;
         }
 
-        if (status)
-            ret = -status;
+        if (status) {
+            errno = status;
+            ret = -1;
+        }
 
         return ret;
     }