Page MenuHomeFreeBSD

bhyvectl: print a better error message when vm_open fails
ClosedPublic

Authored by rew on Mar 7 2021, 2:15 AM.

Details

Summary

Use errno to print a more descriptive error message when vm_open() fails

libvmm: preserve errno when vm_device_open() fails
vm_destroy() squashes errno by making a dive into sysctlbyname() - we
can safely skip vm_destroy() here since it's not doing any critical
clean up at this point. Replace vm_destroy() with a free() call.

PR: 250671
Submitted by: marko@apache.org

Diff Detail

Repository
R10 FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

rew requested review of this revision.Mar 7 2021, 2:15 AM
This revision is now accepted and ready to land.Mar 7 2021, 2:17 AM
jhb added inline comments.
lib/libvmmapi/vmmapi.c
136

free() can also trash errno in theory since it could potentially invoke madvise(), etc. It's probably safest to just explicitly save and restore errno around it.

usr.sbin/bhyvectl/bhyvectl.c
1953

Maybe use err() here?

lib/libvmmapi/vmmapi.c
136

got it

should I bring back vm_destroy() since the errno will be restored anyway?

usr.sbin/bhyvectl/bhyvectl.c
1953

I went with fprintf(stderr) because it was used elsewhere in this file and I didn't see any usage of err().

would have to #include <err.h>
something like err(1, "could not open %s", vmname);?

I've got no strong feelings here, let me know what you prefer.