tstest/tailmac: add support for mounting host directories in the guest (#13957)

updates tailscale/corp#24197

tailmac run now supports the --share option which will allow you
to specify a directory on the host which can be mounted in the guest
using  mount_virtiofs vmshare <path>.

Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
This commit is contained in:
Jonathan Nobels
2024-10-29 13:49:51 -04:00
committed by GitHub
parent 0f9a054cba
commit aecb0ab76b
5 changed files with 35 additions and 14 deletions

View File

@@ -14,6 +14,7 @@ class Config: Codable {
var mac = "52:cc:cc:cc:cc:01"
var ethermac = "52:cc:cc:cc:ce:01"
var port: UInt32 = 51009
var sharedDir: String?
// The virtual machines ID. Also double as the directory name under which
// we will store configuration, block device, etc.

View File

@@ -141,5 +141,18 @@ struct TailMacConfigHelper {
func createKeyboardConfiguration() -> VZKeyboardConfiguration {
return VZMacKeyboardConfiguration()
}
func createDirectoryShareConfiguration(tag: String) -> VZDirectorySharingDeviceConfiguration? {
guard let dir = config.sharedDir else { return nil }
let sharedDir = VZSharedDirectory(url: URL(fileURLWithPath: dir), readOnly: false)
let share = VZSingleDirectoryShare(directory: sharedDir)
// Create the VZVirtioFileSystemDeviceConfiguration and assign it a unique tag.
let sharingConfiguration = VZVirtioFileSystemDeviceConfiguration(tag: tag)
sharingConfiguration.share = share
return sharingConfiguration
}
}