Merge pull request #1954 from amshinde/propagate-vsock-error

vsock: Propogate error for vsock ioctl
This commit is contained in:
Archana Shinde
2019-08-12 17:22:25 -07:00
committed by GitHub

View File

@@ -73,18 +73,18 @@ func FindContextID() (*os.File, uint64, error) {
// Looking for the first available context ID.
for cid := contextID; cid <= maxUInt; cid++ {
if err := ioctlFunc(vsockFd.Fd(), ioctlVhostVsockSetGuestCid, uintptr(unsafe.Pointer(&cid))); err == nil {
if err = ioctlFunc(vsockFd.Fd(), ioctlVhostVsockSetGuestCid, uintptr(unsafe.Pointer(&cid))); err == nil {
return vsockFd, cid, nil
}
}
// Last chance to get a free context ID.
for cid := contextID - 1; cid >= firstContextID; cid-- {
if err := ioctlFunc(vsockFd.Fd(), ioctlVhostVsockSetGuestCid, uintptr(unsafe.Pointer(&cid))); err == nil {
if err = ioctlFunc(vsockFd.Fd(), ioctlVhostVsockSetGuestCid, uintptr(unsafe.Pointer(&cid))); err == nil {
return vsockFd, cid, nil
}
}
vsockFd.Close()
return nil, 0, fmt.Errorf("Could not get a unique context ID for the vsock")
return nil, 0, fmt.Errorf("Could not get a unique context ID for the vsock : %s", err)
}