Page MenuHomeFreeBSD

bhyvectl: print a better error message when vm_open fails
ClosedPublic

Authored by rew on Mar 7 2021, 2:15 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Sep 14, 12:14 AM
Unknown Object (File)
Sat, Sep 13, 4:26 PM
Unknown Object (File)
Wed, Sep 10, 6:51 AM
Unknown Object (File)
Sep 3 2025, 6:11 AM
Unknown Object (File)
Aug 18 2025, 10:54 PM
Unknown Object (File)
Aug 16 2025, 9:36 AM
Unknown Object (File)
Aug 16 2025, 6:04 AM
Unknown Object (File)
Aug 15 2025, 11:31 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
rG FreeBSD src repository
Lint
Lint Not Applicable
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.