Debian Codegraph @

src/shared/machine-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "shared-forward.h"
5 #include "storage-util.h"
6
7 typedef enum ImageFormat {
8 IMAGE_FORMAT_RAW,
9 IMAGE_FORMAT_QCOW2,
10 _IMAGE_FORMAT_MAX,
11 _IMAGE_FORMAT_INVALID = -EINVAL,
12 } ImageFormat;
13
14 typedef enum DiskType {
15 DISK_TYPE_VIRTIO_BLK,
16 DISK_TYPE_VIRTIO_SCSI,
17 DISK_TYPE_NVME,
18 DISK_TYPE_VIRTIO_SCSI_CDROM,
19 _DISK_TYPE_MAX,
20 _DISK_TYPE_INVALID = -EINVAL,
21 } DiskType;
22
23 DECLARE_STRING_TABLE_LOOKUP(image_format, ImageFormat);
24 DECLARE_STRING_TABLE_LOOKUP(disk_type, DiskType);
25 DECLARE_STRING_TABLE_LOOKUP(block_driver, DiskType);
26 DECLARE_STRING_TABLE_LOOKUP(qemu_device_driver, DiskType);
27
28 /* Parse "[FORMAT:][DISKTYPE:]PATH"; *format and *disk_type are in-out. */
29 int parse_disk_spec(
30 const char *arg,
31 ImageFormat *format,
32 DiskType *disk_type,
33 char **ret_path);
34
35 typedef enum ReadOnlyMode {
36 READ_ONLY_NO,
37 READ_ONLY_YES,
38 READ_ONLY_AUTO,
39 _READ_ONLY_MAX,
40 _READ_ONLY_INVALID = -EINVAL,
41 } ReadOnlyMode;
42
43 DECLARE_STRING_TABLE_LOOKUP(read_only_mode, ReadOnlyMode);
44
45 /* Map ReadOnlyMode onto the Acquire() wire tristate (-1 unset/auto, 0 no, 1 yes). */
46 static inline int read_only_mode_to_tristate(ReadOnlyMode m) {
47 switch (m) {
48 case READ_ONLY_NO: return 0;
49 case READ_ONLY_YES: return 1;
50 default: return -1;
51 }
52 }
53
54 /* Parsed "PROVIDER:VOLUME[:CONFIG][:K=V,K=V,...]" used by --bind-volume,
55 * machinectl bind-volume, and (future) the BindVolume= unit setting. The 'config'
56 * field is opaque here and interpreted per-backend (vmspawn: a DiskType name;
57 * nspawn: a mount path). */
58 typedef struct BindVolume {
59 char *provider;
60 char *volume;
61 char *config;
62
63 /* Acquire() parameters parsed from the trailing key=value list. */
64 char *template;
65 CreateMode create_mode;
66 ReadOnlyMode read_only;
67 uint64_t create_size_bytes;
68 VolumeType request_as;
69 } BindVolume;
70
71 #define BIND_VOLUME_INIT \
72 (BindVolume) { \
73 .create_mode = _CREATE_MODE_INVALID, \
74 .read_only = _READ_ONLY_INVALID, \
75 .create_size_bytes = UINT64_MAX, \
76 .request_as = _VOLUME_TYPE_INVALID, \
77 }
78
79 BindVolume* bind_volume_free(BindVolume *v);
80 DEFINE_TRIVIAL_CLEANUP_FUNC(BindVolume*, bind_volume_free);
81
82 int bind_volume_parse(const char *arg, BindVolume **ret);
83
84 /* Validate a "<provider>:<volume>" binding name as used by AddStorage/RemoveStorage.
85 * ret_provider/ret_volume may each be NULL when the caller only wants validation. */
86 int machine_storage_name_split(const char *s, char **ret_provider, char **ret_volume);