Advertisement
Guest User

Untitled

a guest
May 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. get_sriov_pci_root_addresses() {
  4. for dir in $(find /sys/devices/ -name sriov_totalvfs -exec dirname {} \;); do
  5. if [ $(cat $dir/sriov_numvfs) -gt 0 ]; then
  6. # use perl because sed doesn't support non-greedy matching
  7. basename $dir | perl -pe 's|(.*?:)(.*)|\2|'
  8. fi
  9. done
  10. }
  11.  
  12. create_pci_string() {
  13. local quoted_values=($(echo "${pci_addresses[@]}" | xargs printf "\"%s\" " ))
  14. local quoted_as_string=${quoted_values[@]}
  15. if [ "$quoted_as_string" = "\"\"" ]; then
  16. pci_string=""
  17. else
  18. pci_string=${quoted_as_string// /, }
  19. fi
  20. }
  21.  
  22. sriov_device_plugin() {
  23. pci_addresses=$(get_sriov_pci_root_addresses)
  24. create_pci_string
  25.  
  26. cat <<EOF > /etc/pcidp/config.json
  27. {
  28. "resourceList":
  29. [
  30. {
  31. "resourceName": "sriov",
  32. "rootDevices": [$pci_string],
  33. "sriovMode": true,
  34. "deviceType": "vfio"
  35. }
  36. ]
  37. }
  38. EOF
  39. }
  40.  
  41. mkdir -p /etc/pcidp
  42. sriov_device_plugin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement