Skip to content

Commit

Permalink
Add setup to emulate SCSI devices (#691)
Browse files Browse the repository at this point in the history
Use emulated scsi devices in the provisioned nodes for development and
testing.

Set the variable KUBEVIRT_PROVIDER_EXTRA_ARGS="--scsi 1G" for creating a
SCSI disk during the node creation.

Signed-off-by: Alice Frosi <[email protected]>
  • Loading branch information
alicefr authored Oct 27, 2021
1 parent 8198e9c commit 7ca1f13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cluster-provision/centos8/scripts/vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ while true; do
-b | --block-device ) BLOCK_DEV="$2"; shift 2 ;;
-s | --block-device-size ) BLOCK_DEV_SIZE="$2"; shift 2 ;;
-n | --nvme-device-size ) NVME_DISK_SIZES+="$2 "; shift 2 ;;
-t | --scsi-device-size ) SCSI_DISK_SIZES+="$2 "; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
Expand Down Expand Up @@ -117,6 +118,14 @@ for size in ${NVME_DISK_SIZES[@]}; do
let "disk_num+=1"
done

disk_num=0
for size in ${SCSI_DISK_SIZES[@]}; do
echo "Creating disk "$size" for SCSI disk emulation"
disk="/scsi-"${disk_num}".img"
qemu-img create -f raw $disk $size
let "disk_num+=1"
done

exec qemu-system-x86_64 -enable-kvm -drive format=qcow2,file=${next},if=virtio,cache=unsafe ${block_dev_arg} \
-device virtio-net-pci,netdev=network0,mac=52:55:00:d1:55:${n} \
-netdev tap,id=network0,ifname=tap${n},script=no,downscript=no \
Expand Down
15 changes: 14 additions & 1 deletion cluster-provision/gocli/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ EOF
`
etcdDataDir = "/var/lib/etcd"
nvmeDiskImagePrefix = "/nvme"
scsiDiskImagePrefix = "/scsi"
)

var cli *client.Client
var nvmeDisks []string
var scsiDisks []string

type dockerSetting struct {
Proxy string
Expand Down Expand Up @@ -102,6 +104,7 @@ func NewRunCommand() *cobra.Command {
run.Flags().String("container-suffix", "", "Override container suffix stored at the cli binary")
run.Flags().String("gpu", "", "pci address of a GPU to assign to a node")
run.Flags().StringArrayVar(&nvmeDisks, "nvme", []string{}, "size of the emulate NVMe disk to pass to the node")
run.Flags().StringArrayVar(&scsiDisks, "scsi", []string{}, "size of the emulate SCSI disk to pass to the node")
run.Flags().Bool("run-etcd-on-memory", false, "configure etcd to run on RAM memory, etcd data will not be persistent")
run.Flags().String("etcd-capacity", "512M", "set etcd data mount size.\nthis flag takes affect only when 'run-etcd-on-memory' is specified")
run.Flags().Uint("hugepages-2m", 64, "number of hugepages of size 2M to allocate")
Expand Down Expand Up @@ -507,6 +510,16 @@ func run(cmd *cobra.Command, args []string) (retErr error) {
vmArgsNvmeDisks = append(vmArgsNvmeDisks, fmt.Sprintf("--nvme-device-size %s", size))
}
}
var vmArgsSCSIDisks []string
if len(scsiDisks) > 0 {
nodeQemuArgs = fmt.Sprintf("%s -device virtio-scsi-pci,id=scsi0", nodeQemuArgs)
for i, size := range scsiDisks {
resource.MustParse(size)
disk := fmt.Sprintf("%s-%d.img", scsiDiskImagePrefix, i)
nodeQemuArgs = fmt.Sprintf("%s -drive file=%s,if=none,id=drive%d -device scsi-hd,drive=drive%d,bus=scsi0.0,channel=0,scsi-id=0,lun=%d", nodeQemuArgs, disk, i, i, i)
vmArgsSCSIDisks = append(vmArgsSCSIDisks, fmt.Sprintf("--scsi-device-size %s", size))
}
}

additionalArgs := []string{}
if len(nodeQemuArgs) > 0 {
Expand All @@ -531,7 +544,7 @@ func run(cmd *cobra.Command, args []string) (retErr error) {
Env: []string{
fmt.Sprintf("NODE_NUM=%s", nodeNum),
},
Cmd: []string{"/bin/bash", "-c", fmt.Sprintf("/vm.sh -n /var/run/disk/disk.qcow2 --memory %s --cpu %s %s %s %s", memory, strconv.Itoa(int(cpu)), blockDev, strings.Join(vmArgsNvmeDisks, " "), strings.Join(additionalArgs, " "))},
Cmd: []string{"/bin/bash", "-c", fmt.Sprintf("/vm.sh -n /var/run/disk/disk.qcow2 --memory %s --cpu %s %s %s %s %s", memory, strconv.Itoa(int(cpu)), blockDev, strings.Join(vmArgsSCSIDisks, " "), strings.Join(vmArgsNvmeDisks, " "), strings.Join(additionalArgs, " "))},
}

if cephEnabled {
Expand Down

0 comments on commit 7ca1f13

Please sign in to comment.