#include "user-record.h"
#include "user-util.h"
#include "utf8.h"
+#include "vmspawn-bind-volume.h"
#include "vmspawn-mount.h"
#include "vmspawn-qemu-config.h"
#include "vmspawn-qmp.h"
static sd_id128_t arg_uuid = {};
static char **arg_kernel_cmdline_extra = NULL;
static ExtraDriveContext arg_extra_drives = {};
+static BindVolumes arg_bind_volumes = {};
static char *arg_background = NULL;
static bool arg_pass_ssh_key = true;
static char *arg_ssh_key_type = NULL;
STATIC_DESTRUCTOR_REGISTER(arg_forward_journal, freep);
STATIC_DESTRUCTOR_REGISTER(arg_kernel_cmdline_extra, strv_freep);
STATIC_DESTRUCTOR_REGISTER(arg_extra_drives, extra_drive_context_done);
+STATIC_DESTRUCTOR_REGISTER(arg_bind_volumes, bind_volumes_done);
STATIC_DESTRUCTOR_REGISTER(arg_background, freep);
STATIC_DESTRUCTOR_REGISTER(arg_ssh_key_type, freep);
STATIC_DESTRUCTOR_REGISTER(arg_smbios11, strv_freep);
break;
}
+ OPTION_LONG("bind-volume", "PROVIDER:VOLUME[:CONFIG][:KEY=VALUE,...]",
+ "Acquire a storage volume from a StorageProvider and attach it to the VM"): {
+ _cleanup_(bind_volume_freep) BindVolume *bv = NULL;
+
+ r = bind_volume_parse(opts.arg, &bv);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse --bind-volume= argument '%s': %m", opts.arg);
+
+ if (disk_type_from_bind_volume_config(bv->config) < 0) {
+ _cleanup_free_ char *valid = NULL;
+ for (DiskType t = 0; t < _DISK_TYPE_MAX; t++)
+ if (!strextend_with_separator(&valid, ", ", disk_type_to_string(t)))
+ return log_oom();
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown device type '%s' for --bind-volume=. Valid values: %s.",
+ bv->config, valid);
+ }
+
+ if (!GREEDY_REALLOC(arg_bind_volumes.items, arg_bind_volumes.n_items + 1))
+ return log_oom();
+ arg_bind_volumes.items[arg_bind_volumes.n_items++] = TAKE_PTR(bv);
+ break;
+ }
+
OPTION_LONG("bind-user", "NAME", "Bind user from host to virtual machine"):
if (!valid_user_group_name(opts.arg, /* flags= */ 0))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid user name to bind: %s", opts.arg);
/* Build drive info for QMP-based setup. vmspawn opens all image files and
* passes fds to QEMU via add-fd — QEMU never needs filesystem access. */
- drives->drives = new0(DriveInfo*, 1 + arg_extra_drives.n_drives);
+ drives->drives = new0(DriveInfo*, 1 + arg_extra_drives.n_drives + arg_bind_volumes.n_items);
if (!drives->drives)
return log_oom();
if (r < 0)
return r;
+ r = vmspawn_bind_volume_prepare_boot(arg_runtime_scope, &arg_bind_volumes, drives);
+ if (r < 0)
+ return r;
+
return assign_pcie_ports(c);
}