Minor touchups

This commit is contained in:
AlexSSD7 2023-09-01 16:29:01 +01:00
commit ab519c54dc
10 changed files with 15 additions and 14 deletions

View file

@ -53,7 +53,7 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&vmDebugFlag, "vm-debug", false, "Enables the VM debug mode. This will open an accessible VM monitor. You can log in with root user and no password.")
rootCmd.PersistentFlags().BoolVar(&unrestrictedNetworkingFlag, "vm-unrestricted-networking", false, "Enables unrestricted networking. This will allow the VM to connect to the internet.")
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB (the default is %v in LUKS mode)", defaultMemAllocLUKS))
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB. (the default is %v in LUKS mode)", defaultMemAllocLUKS))
rootCmd.PersistentFlags().Uint32Var(&vmOSUpTimeoutFlag, "vm-os-up-timeout", 30, "Specifies the VM OS-up timeout in seconds.")
rootCmd.PersistentFlags().Uint32Var(&vmSSHSetupTimeoutFlag, "vm-ssh-setup-timeout", 60, "Specifies the VM SSH server setup timeout in seconds. This cannot be lower than the OS-up timeout.")

View file

@ -50,6 +50,7 @@ var runCmd = &cobra.Command{
if vmMemAllocFlag != defaultMemAlloc {
slog.Warn("Enforcing minimum LUKS memory allocation. Please add --allow-luks-low-memory to disable this.", "min", vmMemAllocFlag, "specified", vmMemAllocFlag)
}
vmMemAllocFlag = defaultMemAllocLUKS
}
}

View file

@ -32,9 +32,9 @@ var shellCmd = &cobra.Command{
continue
}
fpr, err := vm.ParsePortForwardString(fp)
fpr, err := vm.ParsePortForwardingRuleString(fp)
if err != nil {
slog.Error("Failed to parse port forward string", "index", i, "value", fp, "error", err.Error())
slog.Error("Failed to parse port forwarding rule string", "index", i, "value", fp, "error", err.Error())
os.Exit(1)
}
@ -43,7 +43,7 @@ var shellCmd = &cobra.Command{
os.Exit(runVM(passthroughArg, func(ctx context.Context, i *vm.VM, fm *vm.FileManager, trc *share.NetTapRuntimeContext) int {
if trc != nil {
slog.Info("Tap networking is active", "host-ip", trc.Net.HostIP, "vm-ip", trc.Net.GuestIP)
slog.Info("Tap host-VM networking is active", "host-ip", trc.Net.HostIP, "vm-ip", trc.Net.GuestIP)
}
err := runVMShell(ctx, i)

View file

@ -68,6 +68,10 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManag
if len(passthroughConfig.USB) != 0 {
// Log USB-related warnings.
// Unfortunately USB passthrough is unstable in macOS and Windows. On Windows, you also need to install external
// libusbK driver, which nullifies the UX. This is a problem with how QEMU works, and unfortunately there isn't
// much we can do about it from our side.
switch runtime.GOOS {
case "windows":
// TODO: To document: installation of libusbK driver with Zadig utility.

View file

@ -76,10 +76,6 @@ func CheckRunAsRoot() (bool, error) {
defer func() { _ = windows.FreeSid(sid) }()
// This appears to cast a null pointer so I'm not sure why this
// works, but this guy says it does and it Works for Me™:
// https://github.com/golang/go/issues/28804#issuecomment-438838144
member, err := windows.Token(0).IsMember(sid)
if err != nil {
return false, errors.Wrap(err, "check win sid membership")

View file

@ -44,8 +44,7 @@ func NewFTPBackend(uc *UserConfiguration) (Backend, *VMShareOptions, error) {
passivePortCount: passivePortCount,
extIP: uc.ftpExtIP,
}, &VMShareOptions{
Ports: ports,
EnableTap: false,
Ports: ports,
}, nil
}

View file

@ -14,7 +14,7 @@ func getNetworkSharePort(subsequent uint16) (uint16, error) {
}
func getClosestAvailPortWithSubsequent(port uint16, subsequent uint16) (uint16, error) {
// We use 10 as port range
// We use 10 as port range.
for i := port; i < 65535; i += subsequent {
ok, err := checkPortAvailable(i, subsequent)
if err != nil {
@ -31,6 +31,7 @@ func getClosestAvailPortWithSubsequent(port uint16, subsequent uint16) (uint16,
func checkPortAvailable(port uint16, subsequent uint16) (bool, error) {
if port+subsequent < port {
// We check for uint16 overflow here.
return false, fmt.Errorf("subsequent ports exceed allowed port range")
}

View file

@ -19,7 +19,7 @@ func GetLogErrMsg(s string, logLabel string) string {
origLogLen := len(logToInclude)
const maxLogLen = 256
if origLogLen > maxLogLen {
logToInclude = fmt.Sprintf("[%v chars trimmed]", origLogLen) + logToInclude[len(logToInclude)-maxLogLen:]
logToInclude = fmt.Sprintf("[%v chars trimmed]", origLogLen-maxLogLen) + logToInclude[len(logToInclude)-maxLogLen:]
}
return fmt.Sprintf("(%v: '%v')", logLabel, logToInclude)

View file

@ -158,7 +158,7 @@ func (fm *FileManager) Mount(devName string, mo MountOptions) error {
return fmt.Errorf("device name is empty")
}
// It does allow mapper/ prefix for mapped devices.
// It does allow "mapper/" prefix for mapped devices.
// This is to enable the support for LVM and LUKS.
if !utils.ValidateDevName(devName) {
return fmt.Errorf("bad device name")

View file

@ -15,7 +15,7 @@ type PortForwardingRule struct {
VMPort uint16
}
func ParsePortForwardString(s string) (PortForwardingRule, error) {
func ParsePortForwardingRuleString(s string) (PortForwardingRule, error) {
split := strings.Split(s, ":")
switch len(split) {
case 2: