Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvm: add VM Settings for virtual GPU hardware type and memory #5513

Merged
merged 8 commits into from Oct 4, 2021
4 changes: 4 additions & 0 deletions api/src/main/java/com/cloud/vm/VmDetailConstants.java
Expand Up @@ -40,6 +40,10 @@ public interface VmDetailConstants {
String KVM_VNC_PORT = "kvm.vnc.port";
String KVM_VNC_ADDRESS = "kvm.vnc.address";

// KVM specific, custom virtual GPU hardware
String VIDEO_HARDWARE = "video.hardware";
String VIDEO_RAM = "video.ram";

// Mac OSX guest specific (internal)
String SMC_PRESENT = "smc.present";
String FIRMWARE = "firmware";
Expand Down
Expand Up @@ -3879,6 +3879,8 @@ private void fillVMOrTemplateDetailOptions(final Map<String, List<String>> optio

if (HypervisorType.KVM.equals(hypervisorType)) {
options.put(VmDetailConstants.ROOT_DISK_CONTROLLER, Arrays.asList("osdefault", "ide", "scsi", "virtio"));
options.put(VmDetailConstants.VIDEO_HARDWARE, Arrays.asList("cirrus", "vga", "qxl", "virtio"));
options.put(VmDetailConstants.VIDEO_RAM, Arrays.asList("16384", "32768", "65536"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leolleeooleo
can videoram be any integer value ?
if so, you can use

options.put(VmDetailConstants.VIDEO_RAM, Collections.emptyList());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leolleeooleo
I was not asking you to change the values. sorry for confusion.
I just wanted to know if there is any restriction here . for example, the min value, the max value, or it must be power of 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if VIDEO_RAM = 0, VIDEO_HARDWARE will not work.

If not power of 2, libvirt will auto make it to power of 2.

if (_videoModel != null && !_videoModel.isEmpty() && _videoRam != 0){

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it better to change to the following ?

            if (_videoModel != null && !_videoModel.isEmpty()) {
                videoBuilder.append("<video>\n");
                if (_videoRam != 0) {
                    videoBuilder.append("<model type='" + _videoModel + "' vram='" + _videoRam + "'/>\n");
                } else {
                    videoBuilder.append("<model type='" + _videoModel + "'/>\n");
                }
                videoBuilder.append("</video>\n");
                return videoBuilder.toString();
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good idea.
I was worry about it if videoRam is not provided.
I had test it with no error, and here are the document.
https://libvirt.org/formatdomain.html#video-devices
If no value is provided the default is used.

}

if (HypervisorType.VMware.equals(hypervisorType)) {
Expand Down