-
Notifications
You must be signed in to change notification settings - Fork 22
/
runtime.vars
576 lines (496 loc) · 18.3 KB
/
runtime.vars
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#!/bin/bash
# SPDX-License-Identifier: (LGPL-2.1 OR LGPL-3.0)
# Copyright (C) SUSE LLC 2016-2022, all rights reserved.
_fail() {
echo "error: $*"
exit 1
}
_warn() {
echo "warning: $*"
}
# Set a bunch of default parameter settings which may be overridden by the
# subsequent RAPIDO_CONF include...
# Dracut initramfs output path and QEMU input
DRACUT_OUT="${RAPIDO_DIR}/initrds/myinitrd"
# default directory to write QEMU pidfiles
QEMU_PID_DIR="${RAPIDO_DIR}/initrds"
# default VM network config path, also used for tap provisioning
VM_NET_CONF="${RAPIDO_DIR}/net-conf"
# QEMU defaults: CLI with console redirection. Provide VMs with an RNG device.
QEMU_EXTRA_ARGS="-nographic -device virtio-rng-pci"
if [[ -n $RAPIDO_CONF ]]; then
# explicit user-provided conf path; fail if missing.
. "$RAPIDO_CONF" || _fail "$RAPIDO_CONF missing"
else
# use default rapido.conf path; continue if missing.
RAPIDO_CONF="${RAPIDO_DIR}/rapido.conf"
. "$RAPIDO_CONF" 2> /dev/null \
|| _warn "$(realpath $RAPIDO_CONF) missing - see rapido.conf.example"
fi
_rt_ceph_src_globals_set() {
[ -d "$CEPH_SRC" ] || _fail "$CEPH_SRC is not a directory"
[ -f "${CEPH_SRC}/build/CMakeCache.txt" ] \
|| _fail "${CEPH_SRC} cmake build missing"
# cmake build, compiled binaries and configs are in build subdir
RBD_NAMER_BIN="${CEPH_SRC}/src/ceph-rbdnamer"
RBD_UDEV_RULES="${CEPH_SRC}/udev/50-rbd.rules"
CEPH_MOUNT_BIN="${CEPH_SRC}/build/bin/mount.ceph"
CEPH_FUSE_BIN="${CEPH_SRC}/build/bin/ceph-fuse"
CEPH_CONF_BIN="${CEPH_SRC}/build/bin/ceph-conf"
CEPH_RADOS_LIB="${CEPH_SRC}/build/lib/librados.so"
CEPH_RBD_LIB="${CEPH_SRC}/build/lib/librbd.so"
CEPH_COMMON_LIB="${CEPH_SRC}/build/lib/libceph-common.so"
CEPHFS_LIB="${CEPH_SRC}/build/lib/libcephfs.so"
CEPH_CONF="${CEPH_SRC}/build/ceph.conf"
CEPH_KEYRING="${CEPH_SRC}/build/keyring"
}
_rt_ceph_installed_globals_set() {
[ -n "$CEPH_USER" ] || _fail "CEPH_USER not configured"
# use installed Ceph binaries and configs
RBD_NAMER_BIN="/usr/bin/ceph-rbdnamer"
RBD_UDEV_RULES="/usr/lib/udev/rules.d/50-rbd.rules"
CEPH_MOUNT_BIN="/usr/sbin/mount.ceph"
CEPH_FUSE_BIN="/usr/bin/ceph-fuse"
CEPH_CONF_BIN="/usr/bin/ceph-conf"
CEPH_RADOS_LIB="/usr/lib64/librados.so"
CEPH_RBD_LIB="/usr/lib64/librbd.so"
CEPH_COMMON_LIB="/usr/lib64/libceph-common.so"
CEPHFS_LIB="/usr/lib64/libcephfs.so"
CEPH_CONF="/etc/ceph/ceph.conf"
CEPH_KEYRING="/etc/ceph/ceph.client.${CEPH_USER}.keyring"
}
_rt_require_ceph() {
if [ -n "$CEPH_SRC" ]; then
_rt_ceph_src_globals_set
else
_rt_ceph_installed_globals_set
fi
[ -f "$RBD_NAMER_BIN" ] || _fail "missing $RBD_NAMER_BIN"
[ -f "$RBD_UDEV_RULES" ] || _fail "missing $RBD_UDEV_RULES"
[ -f "$CEPH_MOUNT_BIN" ] || _fail "missing $CEPH_MOUNT_BIN"
[ -f "$CEPH_FUSE_BIN" ] || _fail "missing $CEPH_FUSE_BIN"
[ -f "$CEPH_CONF_BIN" ] || _fail "missing $CEPH_CONF_BIN"
[ -f "$CEPH_RADOS_LIB" ] || _fail "missing $CEPH_RADOS_LIB"
[ -f "$CEPH_RBD_LIB" ] || _fail "missing $CEPH_RBD_LIB"
[ -f "$CEPH_COMMON_LIB" ] || _fail "missing $CEPH_COMMON_LIB"
[ -f "$CEPHFS_LIB" ] || _fail "missing $CEPHFS_LIB"
[ -f "$CEPH_CONF" ] || _fail "missing $CEPH_CONF"
[ -f "$CEPH_KEYRING" ] || _fail "missing $CEPH_KEYRING"
}
_ceph_get_key() {
${CEPH_CONF_BIN} -c ${CEPH_KEYRING} -s "client.$CEPH_USER" key 2> /dev/null
}
_ceph_get_conf() {
local section=$1
shift 1
local key="$@"
${CEPH_CONF_BIN} -c ${CEPH_CONF} -s "$section" "$key" 2> /dev/null
}
_rt_write_ceph_config() {
local vm_ceph_conf=$1
[ -f "$vm_ceph_conf" ] || _fail "missing file $vm_ceph_conf"
[ -f "$CEPH_CONF" ] || _fail "missing $CEPH_CONF"
[ -f "$CEPH_KEYRING" ] || _fail "missing $CEPH_KEYRING"
[ -f "$CEPH_CONF_BIN" ] || _fail "missing $CEPH_CONF_BIN"
[ -n "$CEPH_USER" ] || _fail "CEPH_USER not configured"
# get key
local value="$(_ceph_get_key)"
[ -n "$value" ] || _fail "Can't find key for client.$CEPH_USER"
echo "CEPH_USER_KEY=$value" >> $vm_ceph_conf
# get monitor address
value=""
if [ -n "$CEPH_MON_NAME" ]; then
value="$(_ceph_get_conf "mon.${CEPH_MON_NAME}" "mon addr")"
fi
if [ -z "$value" ]; then
value="$(_ceph_get_conf "global" "mon host")"
fi
[ -n "$value" ] || _fail "Can't find mon address"
# get both msgr v1 and v2 monitor addresses
local addrv1="${value##*v1:}"
addrv1="${addrv1%%[],]*}"
echo "CEPH_MON_ADDRESS_V1=$addrv1" >> $vm_ceph_conf
local addrv2="${value##*v2:}"
addrv2="${addrv2%%[],]*}"
[ "$addrv1" != "$addrv2" ] && echo "CEPH_MON_ADDRESS_V2=$addrv2" >> $vm_ceph_conf
# get mds_root_ino_{uid,gid}
value="$(_ceph_get_conf "mds" "mds root ino uid")"
[ -n "$value" ] && echo "CEPH_ROOT_INO_UID=$value" >> $vm_ceph_conf
value="$(_ceph_get_conf "mds" "mds root ino gid")"
[ -n "$value" ] && echo "CEPH_ROOT_INO_GID=$value" >> $vm_ceph_conf
}
# Ceph binaries and libraries can be sourced from CEPH_SRC or locally installed
# system paths.
# This helper allows cut scripts to use dracut --install "CEPH_X_BIN" (which
# pulls in ldd dependencies, as opposed to --include "CEPH_X_BIN" "$tgt"), and
# then use those paths directly in the autorun script (after including
# vm_ceph.env).
_rt_write_ceph_bin_paths() {
local vm_ceph_conf=$1
[ -f "$vm_ceph_conf" ] || _fail "missing file $vm_ceph_conf"
# sanity check. _rt_require_ceph() should have already done this...
[ -f "$CEPH_MOUNT_BIN" ] || _fail "missing $CEPH_MOUNT_BIN"
[ -f "$CEPH_FUSE_BIN" ] || _fail "missing $CEPH_FUSE_BIN"
echo "CEPH_MOUNT_BIN=${CEPH_MOUNT_BIN}" >> $vm_ceph_conf
echo "CEPH_FUSE_BIN=${CEPH_FUSE_BIN}" >> $vm_ceph_conf
}
_rt_require_fstests() {
_rt_require_conf_dir FSTESTS_SRC
[ -x "$FSTESTS_SRC/check" ] || _fail "missing $FSTESTS_SRC/check"
}
_rt_require_btrfs_progs() {
declare -n req_inst_ref="$1" || _fail "output ref parameter required"
# sbin paths search paths may be needed for non-root
local p="${PATH}:/sbin:/usr/sbin"
if [ -n "$BTRFS_PROGS_SRC" ]; then
p="${BTRFS_PROGS_SRC}"
fi
req_inst_ref+=( $(PATH=$p type -P \
mkfs.btrfs \
btrfs \
btrfs-convert \
btrfstune) ) \
|| _fail "missing btrfs-progs binaries"
# optional: fstests should skip if not available
req_inst_ref+=( $(PATH=$p type -P btrfs-corrupt-block) )
}
_rt_require_bcachefs_tools() {
declare -n req_inst_ref="$1" || _fail "output ref parameter required"
# sbin paths search paths may be needed for non-root
local p="${PATH}:/sbin:/usr/sbin"
if [ -n "$BCACHEFS_TOOLS_SRC" ]; then
p="${BCACHEFS_TOOLS_SRC}"
fi
req_inst_ref+=( $(PATH=$p type -P bcachefs) ) \
|| _fail "missing bcachefs-tools binaries"
}
_rt_require_exfat_progs() {
declare -n req_inst_ref="$1" || _fail "output ref parameter required"
# sbin paths search paths may be needed for non-root
local p="${PATH}:/sbin:/usr/sbin"
if [ -n "$EXFAT_PROGS_SRC" ]; then
p="${EXFAT_PROGS_SRC}/mkfs:${EXFAT_PROGS_SRC}/fsck"
p="${p}:${EXFAT_PROGS_SRC}/dump:${EXFAT_PROGS_SRC}/tune"
fi
req_inst_ref+=( $(PATH=$p type -P mkfs.exfat fsck.exfat tune.exfat) ) \
|| _fail "missing exfat_progs binaries"
# dump.exfat not present in older versions and isn't needed for fstests
req_inst_ref+=( $(PATH=$p type -P dump.exfat) )
}
_rt_require_samba_srv() {
declare -n req_inst_ref="$1" || _fail "output ref parameter required"
local p="${PATH}:/sbin:/usr/sbin:/usr/lib64/samba/"
local mods_p="/usr/lib64/samba"
if [ -n "$SAMBA_SRC" ]; then
p="${SAMBA_SRC}/bin"
mods_p="${SAMBA_SRC}/bin/modules"
fi
# any subsequent parameters are treated as extra modules
shift
req_inst_ref+=("${mods_p}/pdb/tdbsam.so")
while (( $# > 0 )) ; do
[ -f "${mods_p}/${1}" ] || _fail "Samba module $1 missing"
req_inst_ref+=("${mods_p}/${1}")
shift
done
req_inst_ref+=( $(PATH=$p type -P smbpasswd smbstatus smbd) ) \
|| _fail "missing samba server binaries"
# rpcd helpers not strictly required for SMB server functionality
req_inst_ref+=( $(PATH=$p type -P samba-dcerpcd rpcd_classic \
rpcd_epmapper rpcd_fsrvp rpcd_lsad rpcd_mdssvc rpcd_rpcecho \
rpcd_spoolss rpcd_winreg) )
}
_rt_require_ksmbd_tools() {
declare -n req_inst_ref="$1" || _fail "output ref parameter required"
local p="${PATH}:/usr/libexec:/sbin:/usr/sbin"
if [ -n "$KSMBD_TOOLS_SRC" ]; then
p="${KSMBD_TOOLS_SRC}/tools"
fi
req_inst_ref+=( $(PATH=$p type -P ksmbd.tools) ) \
|| _fail "missing ksmbd.tools binary"
}
_rt_require_blktests() {
_rt_require_conf_dir BLKTESTS_SRC
[ -x "$BLKTESTS_SRC/check" ] || _fail "missing $BLKTESTS_SRC/check"
}
_rt_require_dracut_args() {
# Arguments correspond to scripts that will be run on boot.
# Multiple scripts can be specified and will be run in the order of
# parameters. This order is controlled by prepending an index to the
# destination filename.
local init_src=$1 init_dst kver kmods=()
# Specify core init scripts responsible for starting autorun.
# The Dracut "cmdline" hook is executed prior to root parameter parsing.
local env_src="$RAPIDO_DIR/vm_autorun.env"
local rinit_src="$RAPIDO_DIR/autorun/00-rapido-init.sh"
local rinit_dst="/lib/dracut/hooks/cmdline/00-rapido-init.sh"
local conf_src="$RAPIDO_CONF"
[[ -f $RAPIDO_CONF ]] || conf_src="${RAPIDO_DIR}/dracut.conf.d/.empty"
DRACUT_RAPIDO_ARGS+=(--include "$conf_src" /rapido.conf \
--include "$env_src" /rapido.rc \
--include "$rinit_src" "$rinit_dst")
# start at 100 and strip first digit on use - hack for zero-padding
local i=100
while [ -n "$init_src" ]; do
[ -f "$init_src" ] \
|| _fail "_rt_require_dracut_args $init_src not a file"
init_dst="/rapido_autorun/${i:1:3}-$(basename $init_src)"
DRACUT_RAPIDO_ARGS+=(--include "$init_src" "$init_dst")
((i++))
shift
init_src=$1
done
if [[ -n $KERNEL_SRC ]]; then
kver="$(cat "${KERNEL_SRC}/include/config/kernel.release")"
[[ -n $kver ]] \
|| _fail "failed to read kernel.release at $KERNEL_SRC"
else
kver="$(uname -r)"
fi
# --confdir sees Dracut use rapido specific configuration, instead of
# processing /etc/dracut.conf.d/*.conf
DRACUT_RAPIDO_ARGS+=(--confdir "${RAPIDO_DIR}/dracut.conf.d" \
--force --kver "$kver")
if [ -n "$DRACUT_SRC" ]; then
DRACUT="$DRACUT_SRC/dracut.sh"
DRACUT_RAPIDO_ARGS+=(--local)
else
DRACUT="dracut"
fi
# The optional KERNEL_INSTALL_MOD_PATH rapido.conf parameter can be used
# to specify where Dracut should try to pull built kernel modules from.
if [ -n "$KERNEL_INSTALL_MOD_PATH" ]; then
local kmoddir="$KERNEL_INSTALL_MOD_PATH/lib/modules/$kver"
[ -d "$kmoddir" ] \
|| _fail "missing $kmoddir"
DRACUT_RAPIDO_ARGS+=(--kmoddir "$kmoddir")
fi
[ "$QEMU_EXTRA_ARGS" == "${QEMU_EXTRA_ARGS/virtio-rng-pci}" ] \
|| kmods+=("virtio-rng")
[ -n "$VIRTFS_SHARE_PATH" ] && kmods+=("9pnet" "9pnet_virtio" "9p")
((${#kmods[*]} > 0)) \
&& DRACUT_RAPIDO_ARGS+=("--add-drivers" "${kmods[*]}")
# Append any rapido.conf user-defined parameters
DRACUT_RAPIDO_ARGS+=($DRACUT_EXTRA_ARGS)
}
_rt_require_networking() {
local bins=(udevadm systemd-udevd systemd-networkd \
systemd-networkd-wait-online)
local net_deps=($(PATH="/usr/lib/systemd:${PATH}" type -P ${bins[*]})) \
|| _fail "missing network dependency in: ${bins[*]}"
# a /etc/systemd/network -> /rapido-rsc/net/vm# symlink is created at
# runtime based on the vm# assigned and propagated via kernel cmdline.
[ -d "$VM_NET_CONF" ] \
|| _fail "Network configuration required. See net-conf.example"
DRACUT_RAPIDO_ARGS+=(--install "ip ping ${net_deps[*]}" \
--include "$VM_NET_CONF" /rapido-rsc/net \
--drivers "virtio_net af_packet")
}
_rt_require_qemu_args() {
local arch_dir boot_dir boot_img qemu_bin f kver_sfx
if [[ -n $KERNEL_SRC ]]; then
_rt_require_conf_dir KERNEL_SRC
f="$KERNEL_SRC/.config"
else
kver_sfx="-$(uname -r)"
f="/boot/config${kver_sfx}"
[[ -r $f ]] \
|| _fail "unable to boot local kernel: $f inaccessible"
fi
QEMU_ARCH_VARS=()
if [ -c /dev/kvm ]; then
QEMU_ARCH_VARS=(-machine accel=kvm)
fi
# TODO: add other archs from arch/*/Kconfig
if grep -q 'CONFIG_X86_64=y' "$f"; then
arch_dir="x86"
boot_img="bzImage"
# local x86-64 kernels are symlinked at /boot/vmlinuz
[[ -n "$KERNEL_SRC" ]] || boot_img=vmlinuz
qemu_bin="qemu-system-x86_64"
QEMU_KERNEL_CONSOLE="ttyS0"
elif grep -q 'CONFIG_ARM64=y' "$f"; then
arch_dir="arm64"
boot_img="Image"
qemu_bin="qemu-system-aarch64"
QEMU_ARCH_VARS+=(-machine virt,gic-version=host -cpu host)
QEMU_KERNEL_CONSOLE="ttyAMA0"
elif grep -q 'CONFIG_PPC64=y' "$f"; then
arch_dir="powerpc"
boot_img="vmlinux"
qemu_bin="qemu-system-ppc64"
QEMU_KERNEL_CONSOLE="hvc0"
elif grep -q 'CONFIG_S390=y' "$f"; then
arch_dir="s390"
boot_img="bzImage"
qemu_bin="qemu-system-s390x"
QEMU_KERNEL_CONSOLE="ttysclp0"
else
_fail "arch not detected, add it first"
fi
if [[ -n "$KERNEL_SRC" ]]; then
boot_dir="$KERNEL_SRC/arch/$arch_dir/boot"
[[ $boot_img == "vmlinux" ]] && boot_dir="$KERNEL_SRC"
[[ -d $boot_dir ]] || \
_fail "directory for kernel image is missing ('$boot_dir'), build needed?"
else
boot_dir="/boot"
fi
QEMU_KERNEL_IMG="$boot_dir/${boot_img}${kver_sfx}"
[ -f "$QEMU_KERNEL_IMG" ] || \
_fail "no kernel image present at $QEMU_KERNEL_IMG, wrong detection or build needed"
QEMU_BIN="$(type -P $qemu_bin 2>/dev/null)"
[ -z "$QEMU_BIN" ] && _fail "missing $qemu_bin"
}
_rt_require_lib() {
declare -n req_inst_ref="$1" || _fail "output ref parameter required"
local libname
shift
for libname in $1; do
local library=`/sbin/ldconfig -p \
| awk 'index($1, "'${libname}'") == 1 {print $NF}'`
[ -n "$library" ] || _fail "can't find library '$libname'"
req_inst_ref+=("$library")
done
}
# Append PAM module paths for $2... to the bash array referenced at $1. The
# modules link against libpam, so dracut's dependency tracking will handle that.
_rt_require_pam_mods() {
# TODO: PAM paths below currently only cover Tumbleweed and Leap 15.4
local p="/usr/lib64/security/:/lib64/security/"
declare -n mod_paths_ref="$1"
shift
mod_paths_ref+=( $(PATH="$p" type -P "$@") ) \
|| _fail "path $p doesn't provide all PAM modules: $@"
}
_rt_require_conf_setting() {
local parms=("$@")
local conf
local val
for conf in "${parms[@]}"; do
eval "val=\${$conf}"
[ -n "$val" ] || _fail "$conf is not set in rapido.conf"
done
}
# check that each parameter is set in rapido.conf, and corresponds to a local
# directory.
_rt_require_conf_dir() {
local parms=("$@")
local conf
local dir
for conf in "${parms[@]}"; do
eval "dir=\${$conf}"
[ -n "$dir" ] || _fail "$conf is not set"
[ -d "$dir" ] || _fail "$conf (${dir}) is not a directory"
done
}
_rt_require_samba_ctdb() {
_rt_require_conf_dir SAMBA_SRC
[ -x "${SAMBA_SRC}/bin/default/ctdb/ctdb" ] || _fail "ctdb not found"
[ -x "${SAMBA_SRC}/bin/default/ctdb/ctdbd" ] || _fail "ctdbd not found"
# renamed with 4.9 events.d -> event
CTDB_EVENTS_DIR="$(ls -d ${SAMBA_SRC}/ctdb/config/events*)"
[ -d "$CTDB_EVENTS_DIR" ] || _fail "$CTDB_EVENTS_DIR missing"
}
# Determine gcc compiler dependencies and append them to the list ref $1.
# $2... is an ordered list of header files to obtain via "gcc -M" compilation,
# which outputs full paths for all recursive includes.
_rt_require_gcc() {
local hdr_incs hdr_paths
declare -n req_inst_ref="$1" || _fail "output ref parameter required"
shift
(( $# > 0 )) && printf -v hdr_incs '#include <%s>\n' "$@"
hdr_paths=$(gcc -x c -M - <<<"
#define _GNU_SOURCE
$hdr_incs
int main(void) {return 0;}") || _fail "$hdr_incs compilation failed"
# trim gcc's '-:' srcfile prefix and '\' newline markers
hdr_paths=${hdr_paths#-:}
req_inst_ref+=( ${hdr_paths//\\/} )
# XXX: this looks very flakey and version specific
req_inst_ref+=("gcc" "cc"
$(gcc -print-prog-name=cc1;
gcc -print-prog-name=as;
gcc -print-prog-name=ld;
gcc -print-file-name=liblto_plugin.so;
gcc -print-file-name=crt1.o;
gcc -print-file-name=crti.o;
gcc -print-file-name=crtbegin.o;
gcc -print-file-name=crtend.o;
gcc -print-file-name=crtn.o;
gcc -print-file-name=libc.so;
gcc -print-file-name=libc_nonshared.a;
gcc -print-file-name=libgcc_s.so;
gcc -print-libgcc-file-name)
)
}
# TODO remove this: it's only used for qemu-rbd, which could instead rely on
# custom configuration via rapido.conf:QEMU_EXTRA_ARGS
_rt_qemu_custom_args_set() {
local qemu_args_file="$1"
[ -f "$qemu_args_file" ] || _fail "qemu_args_file missing"
DRACUT_RAPIDO_ARGS+=(--include "$qemu_args_file" \
"/rapido-rsc/qemu/custom_args")
}
_rt_cpu_resources_set() {
local cpus="$1"
[[ $cpus =~ ^[0-9]+$ ]] || _fail "num vCPUs must be numeric"
DRACUT_RAPIDO_ARGS+=(--include "${RAPIDO_DIR}/dracut.conf.d/.empty" \
"/rapido-rsc/cpu/${cpus}")
}
_rt_mem_resources_set() {
local mem="$1"
# require explicit mem units. Avoid exposing qemu's defaults
[[ $mem =~ ^[0-9]+[mMgGtT]$ ]] || _fail "invalid memory string: $mem"
DRACUT_RAPIDO_ARGS+=(--include "${RAPIDO_DIR}/dracut.conf.d/.empty" \
"/rapido-rsc/mem/${mem}")
}
# Read resources set via _rt_cpu_resources_set() and _rt_mem_resources_set(),
# then convert them into corresponding QEMU parameters. Additionally handle
# _rt_qemu_custom_args_set() and network (presence) in the same pass.
# XXX this only checks the first cpio archive, while an initramfs may be made
# up of multiple chained archives. Dracut only chains CPU microcode archives,
# which we disable via early_microcode=no.
_rt_qemu_resources_get() {
local img="$1"
# Bash 4.3+ array passed via reference
typeset -n args_ref=$2 || _fail "failed to pass array by reference"
typeset -n netd_flag_ref=$3 || _fail
local p custom_args
# rapido defaults...
local cpus="2"
local mem="512M"
[ -n "$img" ] || _fail "img parameter is manditory"
[ -f "$img" ] || _fail "no image at $img"
for p in $(cpio --quiet --list \
"rapido-rsc/*/*" "rapido-rsc/net" < "$img"); do
if [[ $p =~ ^rapido-rsc/cpu/([0-9]+)$ ]]; then
cpus="${BASH_REMATCH[1]}"
elif [[ $p =~ ^rapido-rsc/mem/([0-9]+[MGmg]?)$ ]]; then
mem="${BASH_REMATCH[1]}"
elif [[ $p =~ ^rapido-rsc/qemu/custom_args$ ]]; then
# expensive, but should be rare.
custom_args="$(cpio --quiet --extract --to-stdout \
rapido-rsc/qemu/custom_args < "$img")" \
|| _fail "failed to extract qemu/custom_args"
elif [[ $p =~ ^rapido-rsc/net$ ]]; then
netd_flag_ref="true"
fi
done
args_ref+=(-smp "cpus=${cpus}" -m "$mem" $custom_args)
}
_rt_human_size_in_b() {
local human_size="$1"
typeset -n size_in_b_ref=$2
local i
local units=("[bB]?" "[kK]" "[mM]" "[gG]" "[tT]")
local multi=1
for ((i = 0; i < ${#units}; i++)); do
if [[ $human_size =~ ^([0-9]+)${units[$i]}$ ]]; then
size_in_b_ref=$((BASH_REMATCH[1] * multi))
return
fi
((multi *= 1024))
done
_fail "invalid size: $human_size"
}