forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-vm-pvm
197 lines (173 loc) · 4.67 KB
/
build-vm-pvm
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
#PowerVM build functions
pvm_setup_bootloader(){
disk=$1
parted -s $disk mklabel msdos
parted -s $disk mkpart primary ext2 0 $bootloader_size
parted -s $disk set 1 boot on
parted -s $disk set 1 prep on
parted -s $disk mkpart primary ext3 8M 100%
bl_target=${disk}1
}
pvm_getdiskname(){
lv=$1
if [ -z "$SKIP" ];then
args=$(pvmctl scsi list -f ' ' -d VirtualDisk.udid ClientAdapter.loc_code --where VirtualDisk.name=$lv)
eval $args
host=$(ls-vscsi | grep $loc_code| awk -F " " '{print $1}')
udid=$(echo $udid | cut -c 3-)
devid="/dev/disk/by-id/scsi-SAIX_VDASD_$udid"
until test -L $devid;do
sleep 1;
echo "- - -" > /sys/class/scsi_host/$host/scan
done
dev=$(readlink -f $devid)
fi
case $lv in
*root) test -z "$SKIP" && pvm_setup_bootloader "$dev"
VM_ROOT="${dev}2";;
*swap) VM_SWAP="${dev}";;
esac
}
pvm_execute(){
cmd=$@
pvmctl $cmd
}
pvm_is_created() {
dev=$1
$(pvmctl lv list -d LogicalVolume.name | grep -q $dev) && SKIP=1
}
pvm_createdev() {
name=$1
size=$2
target=$3
size_gb=`expr $size / 1024`
test -z $3 && target=$master_lpar
pvm_is_created $name
if [ -z "$SKIP" ];then
pvm_execute lv create --name $name --size $size_gb
target=$master_lpar
fi
pvm_execute scsi create --vg name=rootvg --type lv --lpar name=$target --stor-id $name
test -z "$SKIP" && pvm_getdiskname $name
}
pvm_lpar_is_running(){
state=$(pvmctl lpar list -d LogicalPartition.state --where LogicalPartition.name=$lpname |awk -F "=" '{print $2}')
CONSOLEPID=`pgrep -f "cat $hvcdev"`
if [ "$state" = "running" ];then
return 0
else
test -n $CONSOLEPID && kill -TERM $CONSOLEPID
return 1
fi
}
pvm_watch_build(){
while pvm_lpar_is_running $lpname;do
sleep 10
done
}
pvm_detachdev(){
lv=$1
lpar=$2
pvm_execute scsi delete --lpar name=$lpar --type lv --stor-id $lv
}
pvm_deletelv(){
viosvrcmd --id 1 -c "rmbdsp -bd $1"
}
pvm_nametoid(){
local id
name=$1
lparid=$(pvmctl lpar list -d LogicalPartition.id -i name=$name | awk -F "=" '{print $2}')
}
pvm_openconsole(){
id=$1
pvmutil -o create_vterm_dev --id $id
hvcsadmin -console $id
hvcdev=$(hvcsadmin -console $id|awk '{print $4}')
}
pvm_closeconsole(){
hvcdev=$(hvcsadmin -console $id|awk '{print $4}')
hvcsadmin -close $hvcdev
pvmutil -o delete_vterm_dev --id $1
}
vm_kill_pvm() {
pvm_execute lpar power-off --hard -i name="$VM_NAME"
}
vm_startup_pvm(){
cpus=$BUILD_JOBS
cores=`echo 0.05 \* $cpus| bc -l`
pvm_execute lpar create --name $lpname --mem $VM_MEMSIZE --proc-unit $cores --proc $cpus --proc-type shared --sharing-mode uncapped --type $lpartype
pvm_nametoid $lpname
vm_attach_root_pvm $lpname
vm_attach_swap_pvm $lpname
pvm_openconsole $lparid
pvm_execute lpar power-on -i name=$lpname
pvm_watch_build &
PID=$!
cat $hvcdev
vm_detach_root_pvm $lpname
vm_detach_swap_pvm $lpname
}
vm_verify_options_pvm(){
test -z "$VM_WORKER_NO" && VM_WORKER_NO=1
lpname="worker-$VM_WORKER_NO"
lpartype="AIX/Linux"
bootloader_size="8M"
rootlv="$lpname"-root
swaplv="$lpname"-swap
master_lpar=$(cat /proc/device-tree/ibm,partition-name)
}
vm_attach_root_pvm(){
target=$1
pvm_createdev $rootlv $VMDISK_ROOTSIZE $target
}
vm_attach_swap_pvm(){
pvm_createdev $swaplv $VMDISK_SWAPSIZE $target
}
vm_detach_swap_pvm(){
lpar=$1
test -z $lpar && lpar=$master_lpar
pvm_detachdev $swaplv $lpar
}
vm_detach_root_pvm(){
lpar=$1
test -z $lpar && lpar=$master_lpar
pvm_detachdev $rootlv $lpar
}
vm_cleanup_pvm(){
pvm_nametoid $lpname
pvm_closeconsole $lparid
vm_detach_root_pvm $lpname
vm_detach_root_pvm
vm_detach_swap_pvm $lpname
vm_detach_swap_pvm
pvm_execute lpar delete -i name=$lpname
pvm_deletelv $rootlv
pvm_deletelv $swaplv
}
vm_sysrq_pvm(){
:
}
vm_wipe_pvm(){
:
}
vm_fixup_pvm(){
VM_SWAPDEV=/dev/sdb
GRUBDIR=`mktemp -d /tmp/grubinstall.XXXXXXXXXX`
modules="ext2 part_msdos linux disk elf"
grubcfg="$GRUBDIR/grub.cfg"
grubimg="$GRUBDIR/grub.img"
cat <<'EOF' >> $GRUBDIR/grub.cfg
insmod ext2
insmod part_msdos
insmod linux
insmod disk
insmod elf
set root='ieee1275//vdevice/v-scsi@30000002/disk@8100000000000000,msdos2'
linux /.build.kernel.kvm init=/.build/build console=hvc0 root=/dev/sda2 rw elevator=noop $vm_linux_kernel_parameter
initrd /.build.initrd.kvm
boot
EOF
grub2-mkimage -O powerpc-ieee1275 -o $grubimg -c $grubcfg $modules
dd if=$grubimg of=$bl_target
rm -rf $GRUBDIR
}