forked from rapido-linux/rapido
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtime.vars
376 lines (316 loc) · 11.2 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
#!/bin/bash
#
# Copyright (C) SUSE LINUX GmbH 2016-2017, all rights reserved.
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) version 3.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
_fail() {
echo "error: $*"
exit 1
}
_warn() {
echo "warning: $*"
}
# process user defined configuration
. ${RAPIDO_DIR}/rapido.conf \
|| _fail "rapido.conf missing - see rapido.conf.example"
_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() {
local which_bin="$(which which)"
# 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
BTRFS_PROGS_BINS="$(PATH=$p $which_bin \
mkfs.btrfs \
btrfs \
btrfs-convert \
btrfstune)" \
|| _fail "missing btrfs-progs binaries"
}
_rt_require_blktests() {
_rt_require_conf_dir BLKTESTS_SRC
[ -x "$BLKTESTS_SRC/check" ] || _fail "missing $BLKTESTS_SRC/check"
}
_rt_require_dracut_args() {
_rt_require_conf_dir KERNEL_SRC
local kver="$(cat ${KERNEL_SRC}/include/config/kernel.release)"
[ -n "$kver" ] || _fail "failed to read kernel.release at $KERNEL_SRC"
# --confdir sees Dracut use rapido specific configuration, instead of
# processing /etc/dracut.conf.d/*.conf
local dracut_args="--confdir ${RAPIDO_DIR}/dracut.conf.d \
--force --tmpdir ${RAPIDO_DIR}/initrds/ \
--kver $kver"
if [ -n "$DRACUT_SRC" ]; then
DRACUT="$DRACUT_SRC/dracut.sh"
dracut_args=" --local $dracut_args"
else
DRACUT="dracut"
fi
$DRACUT --list-modules &>/dev/null \
|| _fail "cannot run $DRACUT"
# 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_args="$dracut_args --kmoddir $kmoddir"
fi
DRACUT_EXTRA_ARGS="$DRACUT_EXTRA_ARGS $dracut_args"
}
_rt_require_qemu_args() {
_rt_require_conf_dir KERNEL_SRC
local f="$KERNEL_SRC/.config"
local arch_dir boot_dir boot_img qemu_bin
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"
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="$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
boot_dir="$KERNEL_SRC/arch/$arch_dir/boot"
[ -d "$boot_dir" ] || \
_fail "directory for kernel image is missing ('$boot_dir'), build needed?"
QEMU_KERNEL_IMG="$boot_dir/$boot_img"
[ "$boot_img" = "vmlinux" ] && QEMU_KERNEL_IMG="$KERNEL_SRC/$boot_img"
[ -f "$QEMU_KERNEL_IMG" ] || \
_fail "no kernel image present at $QEMU_KERNEL_IMG, wrong detection or build needed"
QEMU_BIN="$(which $qemu_bin 2>/dev/null)"
[ -z "$QEMU_BIN" ] && _fail "missing $qemu_bin"
}
_rt_require_lib() {
local libname
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'"
LIBS_INSTALL_LIST="$LIBS_INSTALL_LIST $library"
done
}
_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"
}
# initramfs output path
DRACUT_OUT="${RAPIDO_DIR}/initrds/myinitrd"
_rt_xattr_qemu_args_set() {
local img="$1"
local qemu_args="$2"
local xattr_key="user.rapido.qemu_args"
[ -n "$img" ] || _fail "img parameter is manditory"
[ -f "$img" ] || _fail "no image at $img"
[ -n "$qemu_args" ] || _fail "qemu_args parameter is manditory"
setfattr -n "$xattr_key" -v "$qemu_args" $img \
|| _fail "failed to set xattr on $img"
}
_rt_xattr_qemu_args_get() {
local img="$1"
local xattr_key="user.rapido.qemu_args"
[ -n "$img" ] || _fail "img parameter is manditory"
[ -f "$img" ] || _fail "no image at $img"
getfattr --only-values -n $xattr_key $img 2> /dev/null
}
_rt_xattr_vm_networkless_set() {
local img="$1"
local xattr_key="user.rapido.vm_networkless"
[ -n "$img" ] || _fail "img parameter is manditory"
[ -f "$img" ] || _fail "no image at $img"
setfattr -n "$xattr_key" -v "1" $img \
|| _fail "failed to set xattr on $img"
}
_rt_xattr_vm_networkless_get() {
local img="$1"
local xattr_key="user.rapido.vm_networkless"
[ -n "$img" ] || _fail "img parameter is manditory"
[ -f "$img" ] || _fail "no image at $img"
getfattr --only-values -n $xattr_key $img 2> /dev/null
}
_rt_xattr_vm_resources_set() {
local img="$1"
local cpus="$2"
local mem="$3"
local xattr_key="user.rapido.vm_resources"
local re='^[0-9]+$'
[ -n "$img" ] || _fail "img parameter is manditory"
[ -f "$img" ] || _fail "no image at $img"
[[ $cpus =~ $re ]] || _fail "num CPUs must be numeric"
re='^[0-9]+[MGmg]?$'
[[ $mem =~ $re ]] || _fail "invalid memory string: $mem"
setfattr -n "$xattr_key" -v "-smp cpus=${cpus} -m $mem" $img \
|| _fail "failed to set xattr on $img"
}
_rt_xattr_vm_resources_get() {
local img="$1"
local xattr_key="user.rapido.vm_resources"
[ -n "$img" ] || _fail "img parameter is manditory"
[ -f "$img" ] || _fail "no image at $img"
getfattr --only-values -n $xattr_key $img 2> /dev/null
}