Fix SR-IOV VF counting in sriovdp init script
[ta/caas-danm.git] / docker-build / sriovdp / init.sh
1 #!/bin/sh
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 while true; do
17   date
18   err=0
19
20   rootdevs=`jq -r .resourceList[].rootDevices[] </etc/pcidp/config.json 2>/dev/null`
21   if [[ -n "$rootdevs" ]]; then
22     for pci in $rootdevs; do
23       vf=`cat /sys/bus/pci/devices/0000:$pci/sriov_numvfs`
24       echo "$pci: $vf VFs"
25       if [[ -z "$vf" || "$vf" == "0" ]]; then
26         echo "No VFs found -> SR-IOV DP cannot be started"
27         err=1
28       fi
29     done
30   else
31     echo "No SR-IOV designated PF found -> SR-IOV DP cannot be started"
32     err=1
33   fi
34
35   if [ $err -eq 0 ]; then
36     exit 0
37   else
38     echo "Error happened -> sleep 10 -> retry"
39     sleep 10
40   fi
41 done