diff --git a/cmd/incusd/devices.go b/cmd/incusd/devices.go index 4b19df5d0d0..b3fcb15f5d3 100644 --- a/cmd/incusd/devices.go +++ b/cmd/incusd/devices.go @@ -1,37 +1,5 @@ package main -/* -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#include -#include - -#include "../../shared/cgo/memory_utils.h" - -#ifndef HIDIOCGRAWINFO -#define HIDIOCGRAWINFO _IOR('H', 0x03, struct hidraw_devinfo) -struct hidraw_devinfo { - __u32 bustype; - __s16 vendor; - __s16 product; -}; -#endif - -static int get_hidraw_devinfo(int fd, struct hidraw_devinfo *info) -{ - int ret; - - ret = ioctl(fd, HIDIOCGRAWINFO, info); - if (ret) - return -1; - - return 0; -} - -*/ -import "C" - import ( "fmt" "os" @@ -41,16 +9,17 @@ import ( "sort" "strconv" "strings" + "unsafe" "golang.org/x/sys/unix" + "github.com/lxc/incus/v6/internal/linux" "github.com/lxc/incus/v6/internal/server/cgroup" "github.com/lxc/incus/v6/internal/server/device" "github.com/lxc/incus/v6/internal/server/instance" "github.com/lxc/incus/v6/internal/server/instance/instancetype" "github.com/lxc/incus/v6/internal/server/resources" "github.com/lxc/incus/v6/internal/server/state" - _ "github.com/lxc/incus/v6/shared/cgo" // Used by cgo "github.com/lxc/incus/v6/shared/logger" "github.com/lxc/incus/v6/shared/util" ) @@ -709,10 +678,16 @@ func devicesRegister(instances []instance.Instance) { } func getHidrawDevInfo(fd int) (string, string, error) { - info := C.struct_hidraw_devinfo{} - ret, err := C.get_hidraw_devinfo(C.int(fd), &info) - if ret != 0 { - return "", "", err + type hidInfo struct { + busType uint32 + vendor int16 + product int16 + } + + var info hidInfo + _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), linux.IoctlHIDIOCGrawInfo, uintptr(unsafe.Pointer(&info))) + if errno != 0 { + return "", "", fmt.Errorf("Failed setting received UUID: %w", unix.Errno(errno)) } return fmt.Sprintf("%04x", info.vendor), fmt.Sprintf("%04x", info.product), nil diff --git a/internal/linux/ioctls.go b/internal/linux/ioctls.go new file mode 100644 index 00000000000..a69738c8705 --- /dev/null +++ b/internal/linux/ioctls.go @@ -0,0 +1,12 @@ +package linux + +/* +#include +#include +#include +*/ +import "C" + +const IoctlBtrfsSetReceivedSubvol = C.BTRFS_IOC_SET_RECEIVED_SUBVOL +const IoctlHIDIOCGrawInfo = C.HIDIOCGRAWINFO +const IoctlVhostVsockSetGuestCid = C.VHOST_VSOCK_SET_GUEST_CID diff --git a/internal/server/instance/drivers/driver_qemu.go b/internal/server/instance/drivers/driver_qemu.go index c58fe42eeee..41e2c470545 100644 --- a/internal/server/instance/drivers/driver_qemu.go +++ b/internal/server/instance/drivers/driver_qemu.go @@ -7973,10 +7973,10 @@ func (d *qemu) acquireVsockID(vsockID uint32) (*os.File, error) { revert.Add(func() { _ = vsockF.Close() }) // The vsock Context ID cannot be supplied as type uint32. - vsockIDInt := int(vsockID) + vsockIDInt := uint64(vsockID) - // 0x4008AF60 = VHOST_VSOCK_SET_GUEST_CID = _IOW(VHOST_VIRTIO, 0x60, __u64) - _, _, errno := unix.Syscall(unix.SYS_IOCTL, vsockF.Fd(), 0x4008AF60, uintptr(unsafe.Pointer(&vsockIDInt))) + // Call the ioctl to set the context ID. + _, _, errno := unix.Syscall(unix.SYS_IOCTL, vsockF.Fd(), linux.IoctlVhostVsockSetGuestCid, uintptr(unsafe.Pointer(&vsockIDInt))) if errno != 0 { if !errors.Is(errno, unix.EADDRINUSE) { return nil, fmt.Errorf("Failed ioctl syscall to vhost socket: %q", errno.Error()) diff --git a/internal/server/storage/drivers/driver_btrfs_utils.go b/internal/server/storage/drivers/driver_btrfs_utils.go index 93c9dbdd201..2787d737868 100644 --- a/internal/server/storage/drivers/driver_btrfs_utils.go +++ b/internal/server/storage/drivers/driver_btrfs_utils.go @@ -19,6 +19,7 @@ import ( "golang.org/x/sys/unix" "gopkg.in/yaml.v2" + "github.com/lxc/incus/v6/internal/linux" "github.com/lxc/incus/v6/internal/revert" "github.com/lxc/incus/v6/internal/server/backup" "github.com/lxc/incus/v6/shared/api" @@ -62,8 +63,7 @@ func setReceivedUUID(path string, UUID string) error { copy(args.uuid[:], binUUID) - // 0xC0C09425 = _IOWR(BTRFS_IOCTL_MAGIC, 37, struct btrfs_ioctl_received_subvol_args) - _, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), 0xC0C09425, uintptr(unsafe.Pointer(&args))) + _, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), linux.IoctlBtrfsSetReceivedSubvol, uintptr(unsafe.Pointer(&args))) if errno != 0 { return fmt.Errorf("Failed setting received UUID: %w", unix.Errno(errno)) }