Skip to contentSkip to conversation

Propagate kernel errors in libxc

PATCH New Ben Guthro 1 participant 1 message Nov 12, 2007

lore
Share & tools
lore

Ben Guthro

author
#0 lore raw

PATCH 1/1 Propagate kernel errors in libxc

When the hypervisor returns and error through the kernel or when simply when the kernel returns an error, the ioctl() call in userspace returns -1 with the error value in errno.

This lib_xc was dropping this useful errno value by only returning the -1. This change continues to propagate the -errno value up the call chain.

The impetus for this change was xc_domain_getinfo() previously it was not possible to distinguish the difference between an error and the domainID (or greater) not existing in the hypervisor. Now callers can compare the return value against -ESRCH to distinguish the difference between errors and the domain not existing.

tools/libxc/xc_linux.c +6 -1
diff -r fcd625c4f896 tools/libxc/xc_linux.c
@@ -153,7 +153,12 @@ int xc_map_foreign_ranges(int xc_handle,
 
 static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
 {
-    return ioctl(xc_handle, cmd, data);
+    int ret = ioctl(xc_handle, cmd, data);
+	if (ret >= 0)
+		return ret;
+	if (errno) // kernel errors are passed through errno with ioctl() ret == -1
+		return (errno > 0) ? -errno : errno;
+	return ret;
 }
 
 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel