VirtualBox

Ticket #19320: vbox-import_export_nvme.patch

File vbox-import_export_nvme.patch, 18.8 KB (added by davecardwell, 5 years ago)

Patch for ticket #19320 adding import/export support for NVMe (MIT licensed)

  • src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceEditorWidget.cpp

     
    482482                    case KVirtualSystemDescriptionType_HardDiskControllerSATA: value = UIApplianceEditorWidget::tr("Storage Controller (SATA)"); break;
    483483                    case KVirtualSystemDescriptionType_HardDiskControllerSCSI: value = UIApplianceEditorWidget::tr("Storage Controller (SCSI)"); break;
    484484                    case KVirtualSystemDescriptionType_HardDiskControllerSAS:  value = UIApplianceEditorWidget::tr("Storage Controller (SAS)"); break;
     485                    case KVirtualSystemDescriptionType_HardDiskControllerNVMe: value = UIApplianceEditorWidget::tr("Storage Controller (NVMe)"); break;
    485486                    case KVirtualSystemDescriptionType_CDROM:                  value = UIApplianceEditorWidget::tr("DVD"); break;
    486487                    case KVirtualSystemDescriptionType_Floppy:                 value = UIApplianceEditorWidget::tr("Floppy"); break;
    487488                    case KVirtualSystemDescriptionType_NetworkAdapter:         value = UIApplianceEditorWidget::tr("Network Adapter"); break;
     
    656657                    case KVirtualSystemDescriptionType_HardDiskControllerSATA: value = UIIconPool::iconSet(":/sata_16px.png"); break;
    657658                    case KVirtualSystemDescriptionType_HardDiskControllerSCSI: value = UIIconPool::iconSet(":/scsi_16px.png"); break;
    658659                    case KVirtualSystemDescriptionType_HardDiskControllerSAS:  value = UIIconPool::iconSet(":/sas_16px.png"); break;
     660                    case KVirtualSystemDescriptionType_HardDiskControllerNVMe: value = UIIconPool::iconSet(":/pcie_16px.png"); break;
    659661                    case KVirtualSystemDescriptionType_HardDiskImage:          value = UIIconPool::iconSet(":/hd_16px.png"); break;
    660662                    case KVirtualSystemDescriptionType_CDROM:                  value = UIIconPool::iconSet(":/cd_16px.png"); break;
    661663                    case KVirtualSystemDescriptionType_Floppy:                 value = UIIconPool::iconSet(":/fd_16px.png"); break;
     
    13401342                if (types[i] == KVirtualSystemDescriptionType_HardDiskControllerIDE ||
    13411343                    types[i] == KVirtualSystemDescriptionType_HardDiskControllerSATA ||
    13421344                    types[i] == KVirtualSystemDescriptionType_HardDiskControllerSCSI ||
    1343                     types[i] == KVirtualSystemDescriptionType_HardDiskControllerSAS)
     1345                    types[i] == KVirtualSystemDescriptionType_HardDiskControllerSAS ||
     1346                    types[i] == KVirtualSystemDescriptionType_HardDiskControllerNVMe)
    13441347                    controllerMap[i] = pHardwareItem;
    13451348            }
    13461349        }
     
    16811684    KVirtualSystemDescriptionType_HardDiskControllerSATA,
    16821685    KVirtualSystemDescriptionType_HardDiskControllerSCSI,
    16831686    KVirtualSystemDescriptionType_HardDiskControllerSAS,
     1687    KVirtualSystemDescriptionType_HardDiskControllerNVMe,
    16841688    /* OCI */
    16851689    KVirtualSystemDescriptionType_CloudProfileName,
    16861690    KVirtualSystemDescriptionType_CloudBucket,
  • src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceExportEditorWidget.cpp

     
    5050            << KVirtualSystemDescriptionType_HardDiskControllerSATA
    5151            << KVirtualSystemDescriptionType_HardDiskControllerSCSI
    5252            << KVirtualSystemDescriptionType_HardDiskControllerSAS
     53            << KVirtualSystemDescriptionType_HardDiskControllerNVMe
    5354            << KVirtualSystemDescriptionType_CloudProfileName;
    5455    }
    5556};
  • src/VBox/Main/idl/VirtualBox.xidl

     
    40244024    <const name="CloudOCISubnetCompartment" value="47" />
    40254025    <const name="CloudPublicSSHKey" value="48" />
    40264026    <const name="BootingFirmware" value="49" />
     4027    <const name="HardDiskControllerNVMe" value="50" />
    40274028  </enum>
    40284029
    40294030  <enum
  • src/VBox/Main/include/ovfreader.h

     
    534534{
    535535    uint32_t                idController;       // instance ID (Item/InstanceId); this gets referenced from VirtualDisk
    536536
    537     enum ControllerSystemType { IDE, SATA, SCSI };
    538     ControllerSystemType    system;             // one of IDE, SATA, SCSI
     537    enum ControllerSystemType { IDE, SATA, SCSI, NVMe };
     538    ControllerSystemType    system;             // one of IDE, SATA, SCSI, NVMe
    539539
    540540    RTCString        strControllerType;
    541541            // controller subtype (Item/ResourceSubType); e.g. "LsiLogic"; can be empty (esp. for IDE)
  • src/VBox/Main/src-server/ApplianceImpl.cpp

     
    17701770            case VirtualSystemDescriptionType_HardDiskControllerSATA:
    17711771            case VirtualSystemDescriptionType_HardDiskControllerSCSI:
    17721772            case VirtualSystemDescriptionType_HardDiskControllerSAS:
     1773            case VirtualSystemDescriptionType_HardDiskControllerNVMe:
    17731774                if (d.strRef == strRef)
    17741775                    return &d;
    17751776                break;
  • src/VBox/Main/src-server/ApplianceImplExport.cpp

     
    185185        int32_t lIDEControllerSecondaryIndex = 0;
    186186        int32_t lSATAControllerIndex = 0;
    187187        int32_t lSCSIControllerIndex = 0;
     188        int32_t lNVMeControllerIndex = 0;
    188189
    189190        /* Fetch all available storage controllers */
    190191        com::SafeIfaceArray<IStorageController> nwControllers;
     
    195196        ComPtr<IStorageController> pSATAController;
    196197        ComPtr<IStorageController> pSCSIController;
    197198        ComPtr<IStorageController> pSASController;
     199        ComPtr<IStorageController> pNVMeController;
    198200        for (size_t j = 0; j < nwControllers.size(); ++j)
    199201        {
    200202            StorageBus_T eType;
     
    212214            else if (   eType == StorageBus_SAS
    213215                     && pSASController.isNull())
    214216                pSASController = nwControllers[j];
     217            else if (   eType == StorageBus_PCIe)
     218                pNVMeController = nwControllers[j];
    215219        }
    216220
    217221//     <const name="HardDiskControllerIDE" value="6" />
     
    292296                                 strVBox);
    293297        }
    294298
     299        if (!pNVMeController.isNull())
     300        {
     301            Utf8Str strVBox = "NVMe";
     302            lNVMeControllerIndex = (int32_t)pNewDesc->m->maDescriptions.size();
     303            pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskControllerNVMe,
     304                                 Utf8StrFmt("%d", lNVMeControllerIndex),
     305                                 strVBox,
     306                                 strVBox);
     307        }
     308
    295309//     <const name="HardDiskImage" value="9" />
    296310//     <const name="Floppy" value="18" />
    297311//     <const name="CDROM" value="19" />
     
    344358                strStBus = "SCSI";
    345359                else if ( storageBus == StorageBus_SAS)
    346360                strStBus = "SAS";
     361                else if ( storageBus == StorageBus_PCIe)
     362                strStBus = "PCIe";
    347363                LogRel(("Warning: skip the medium (bus: %s, slot: %d, port: %d). No storage device attached.\n",
    348364                strStBus.c_str(), lDevice, lChannel));
    349365                continue;
     
    520536                    lControllerVsys = lSCSIControllerIndex;
    521537                    break;
    522538
     539                case StorageBus_PCIe:
     540                    lChannelVsys = lChannel;        // should be between 0 and 255
     541                    lControllerVsys = lNVMeControllerIndex;
     542                    break;
     543
    523544                case StorageBus_Floppy:
    524545                    lChannelVsys = 0;
    525546                    lControllerVsys = 0;
     
    14771498    int32_t lSATAControllerIndex = 0;
    14781499    uint32_t idSCSIController = 0;
    14791500    int32_t lSCSIControllerIndex = 0;
     1501    uint32_t idNVMeController = 0;
     1502    int32_t lNVMeControllerIndex = 0;
    14801503
    14811504    uint32_t ulInstanceID = 1;
    14821505
     
    14991522                          : desc.type == VirtualSystemDescriptionType_HardDiskControllerSATA ? "HardDiskControllerSATA"
    15001523                          : desc.type == VirtualSystemDescriptionType_HardDiskControllerSCSI ? "HardDiskControllerSCSI"
    15011524                          : desc.type == VirtualSystemDescriptionType_HardDiskControllerSAS ? "HardDiskControllerSAS"
     1525                          : desc.type == VirtualSystemDescriptionType_HardDiskControllerNVMe ? "HardDiskControllerNVMe"
    15021526                          : desc.type == VirtualSystemDescriptionType_HardDiskImage ? "HardDiskImage"
    15031527                          : Utf8StrFmt("%d", desc.type).c_str()),
    15041528                         desc.strRef.c_str(),
     
    16891713                    }
    16901714                    break;
    16911715
     1716                case VirtualSystemDescriptionType_HardDiskControllerNVMe:
     1717                    /*  <Item>
     1718                            <rasd:Caption>nvmeController0</rasd:Caption>
     1719                            <rasd:Description>NVMe Controller</rasd:Description>
     1720                            <rasd:InstanceId>4</rasd:InstanceId>
     1721                            <rasd:ResourceType>20</rasd:ResourceType>
     1722                            <rasd:ResourceSubType>nvme</rasd:ResourceSubType>
     1723                            <rasd:Address>0</rasd:Address>
     1724                            <rasd:BusNumber>0</rasd:BusNumber>
     1725                        </Item>
     1726                    */
     1727                    if (uLoop == 1)
     1728                    {
     1729                        strDescription = "NVMe Controller";
     1730                        strCaption = "nvmeController0";
     1731                        type = ovf::ResourceType_OtherStorageDevice; // 20
     1732                        // it seems that OVFTool always writes these two, and since we can only
     1733                        // have one NVMe controller, we'll use this as well
     1734                        lAddress = 0;
     1735                        lBusNumber = 0;
     1736
     1737                        if (    desc.strVBoxCurrent.isEmpty()      // NVMe is the default in VirtualBox
     1738                             || (!desc.strVBoxCurrent.compare("nvme", Utf8Str::CaseInsensitive))
     1739                            )
     1740                            strResourceSubType = "nvme";
     1741                        else
     1742                            throw setError(VBOX_E_NOT_SUPPORTED,
     1743                                           tr("Invalid config string \"%s\" in NVMe controller"),
     1744                                           desc.strVBoxCurrent.c_str());
     1745
     1746                        // remember this ID
     1747                        idNVMeController = ulInstanceID;
     1748                        lNVMeControllerIndex = lIndexThis;
     1749                    }
     1750                    break;
     1751
    16921752                case VirtualSystemDescriptionType_HardDiskImage:
    16931753                    /*  <Item>
    16941754                            <rasd:Caption>disk1</rasd:Caption>
     
    17251785                                ulParent = idSCSIController;
    17261786                            else if (lControllerIndex == lSATAControllerIndex)
    17271787                                ulParent = idSATAController;
     1788                            else if (lControllerIndex == lNVMeControllerIndex)
     1789                                ulParent = idNVMeController;
    17281790                        }
    17291791                        if (pos2 != Utf8Str::npos)
    17301792                            RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos2 + 8, NULL, 0, &lAddressOnParent);
     
    18021864                                ulParent = idSCSIController;
    18031865                            else if (lControllerIndex == lSATAControllerIndex)
    18041866                                ulParent = idSATAController;
     1867                            else if (lControllerIndex == lNVMeControllerIndex)
     1868                                ulParent = idNVMeController;
    18051869                        }
    18061870                        if (pos2 != Utf8Str::npos)
    18071871                            RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos2 + 8, NULL, 0, &lAddressOnParent);
  • src/VBox/Main/src-server/ApplianceImplImport.cpp

     
    561561            uint16_t cIDEused = 0;
    562562            uint16_t cSATAused = 0; NOREF(cSATAused);
    563563            uint16_t cSCSIused = 0; NOREF(cSCSIused);
     564            uint16_t cNVMeused = 0; NOREF(cNVMeused);
    564565            ovf::ControllersMap::const_iterator hdcIt;
    565566            /* Iterate through all storage controllers */
    566567            for (hdcIt = vsysThis.mapControllers.begin();
     
    649650                                            strControllerID.c_str());
    650651                        ++cSCSIused;
    651652                    break;
     653
     654                    case ovf::HardDiskController::NVMe:
     655                        /* Check for the constrains */
     656                        if (cNVMeused < 1)
     657                        {
     658                            /* We only support a plain NVMe controller, so use them always */
     659                            pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskControllerNVMe,
     660                                                 strControllerID,
     661                                                 hdc.strControllerType,
     662                                                 "NVMe");
     663                        }
     664                        else
     665                        {
     666                            /* Warn only once */
     667                            if (cNVMeused == 1)
     668                                i_addWarning(tr("The virtual system \"%s\" requests support for more than one "
     669                                                "NVMe controller, but VirtualBox has support for only one"),
     670                                                vsysThis.strName.c_str());
     671
     672                        }
     673                        ++cNVMeused;
     674                    break;
    652675                }
    653676            }
    654677
     
    35163539            break;
    35173540        }
    35183541
     3542        case ovf::HardDiskController::NVMe:
     3543        {
     3544            controllerName = "NVMe";
     3545            lControllerPort = (long)ulAddressOnParent;
     3546            lDevice = (long)0;
     3547            break;
     3548        }
     3549
    35193550        default: break;
    35203551    }
    35213552
     
    42294260        if (FAILED(rc)) throw rc;
    42304261    }
    42314262
     4263    /* Storage controller NVMe */
     4264    std::list<VirtualSystemDescriptionEntry*> vsdeHDCNVMe =
     4265        vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskControllerNVMe);
     4266    if (vsdeHDCNVMe.size() > 1)
     4267        throw setError(VBOX_E_FILE_ERROR,
     4268                       tr("Too many NVMe controllers in OVF; import facility only supports one"));
     4269    if (!vsdeHDCNVMe.empty())
     4270    {
     4271        ComPtr<IStorageController> pController;
     4272        const Utf8Str &hdcVBox = vsdeHDCNVMe.front()->strVBoxCurrent;
     4273        if (hdcVBox == "NVMe")
     4274        {
     4275            rc = pNewMachine->AddStorageController(Bstr("NVMe").raw(),
     4276                                                   StorageBus_PCIe,
     4277                                                   pController.asOutParam());
     4278            if (FAILED(rc)) throw rc;
     4279        }
     4280        else
     4281            throw setError(VBOX_E_FILE_ERROR,
     4282                           tr("Invalid NVMe controller type \"%s\""),
     4283                           hdcVBox.c_str());
     4284    }
     4285
    42324286    /* Now its time to register the machine before we add any storage devices */
    42334287    rc = mVirtualBox->RegisterMachine(pNewMachine);
    42344288    if (FAILED(rc)) throw rc;
  • src/VBox/Main/testcase/tstOVF.cpp

     
    194194                    pcszType = "scsi";
    195195                break;
    196196
     197                case VirtualSystemDescriptionType_HardDiskControllerNVMe:
     198                    pcszType = "nvme";
     199                break;
     200
    197201                case VirtualSystemDescriptionType_HardDiskImage:
    198202                    pcszType = "hd";
    199203                break;
  • src/VBox/Main/xml/ovfreader.cpp

     
    640640                        // handled separately in second loop below
    641641                        break;
    642642
    643                     case ResourceType_OtherStorageDevice:        // 20       SATA controller
     643                    case ResourceType_OtherStorageDevice:        // 20       SATA/NVMe controller
    644644                    {
    645645                        /* <Item>
    646646                            <rasd:Description>SATA Controller</rasd:Description>
     
    661661
    662662                            vsys.mapControllers[i.ulInstanceID] = hdc;
    663663                        }
     664                        else if (   i.strResourceSubType.compare("nvme", RTCString::CaseInsensitive) == 0
     665                            || i.strResourceSubType.compare("vmware.nvme.controller", RTCString::CaseInsensitive) == 0)
     666                        {
     667                            HardDiskController hdc;
     668                            hdc.system = HardDiskController::NVMe;
     669                            hdc.idController = i.ulInstanceID;
     670                            hdc.strControllerType = i.strResourceSubType;
     671
     672                            vsys.mapControllers[i.ulInstanceID] = hdc;
     673                        }
    664674                        else
    665                             throw OVFLogicError(N_("Error reading \"%s\": Host resource of type \"Other Storage Device (%d)\" is supported with SATA AHCI controllers only, line %d (subtype:%s)"),
     675                            throw OVFLogicError(N_("Error reading \"%s\": Host resource of type \"Other Storage Device (%d)\" is supported with SATA AHCI and NVMe controllers only, line %d (subtype:%s)"),
    666676                                                m_strPath.c_str(),
    667677                                                ResourceType_OtherStorageDevice,
    668678                                                i.ulLineNumber, i.strResourceSubType.c_str() );

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy