VirtualBox

Ignore:
Timestamp:
Nov 21, 2024 3:44:25 PM (3 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
166048
Message:

FE/Qt: bugref:10802. Don't use hard coded port numbers during medium attachmnet. The new code searches for unused ports and failing that it increases port count.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.cpp

    r106707 r107090  
    693693        QApplication::translate("UIMessageCenter", "Storage controller failure ..."),
    694694        QApplication::translate("UIMessageCenter", "Failed to acquire storage controller parameter.") +
     695        UIErrorString::formatErrorInfo(comStorageController));
     696}
     697
     698/* static */
     699void UINotificationMessage::cannotChangeStorageControllerParameter(const CStorageController &comStorageController)
     700{
     701    createMessage(
     702        QApplication::translate("UIMessageCenter", "Storage controller failure ..."),
     703        QApplication::translate("UIMessageCenter", "Failed to change storage controller parameter.") +
    695704        UIErrorString::formatErrorInfo(comStorageController));
    696705}
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h

    r106312 r107090  
    307307          * @param  comStorageController  Brings the object parameter get acquired from. */
    308308        static void cannotAcquireStorageControllerParameter(const CStorageController &comStorageController);
     309        /** Notifies about inability to change IStorageController parameter.
     310          * @param  comStorageController  Brings the object parameter being changed for. */
     311        static void cannotChangeStorageControllerParameter(const CStorageController &comStorageController);
    309312        /** Notifies about inability to acquire IMediumAttachment parameter.
    310313          * @param  comMediumAttachment  Brings the object parameter get acquired from. */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp

    r107002 r107090  
    284284        {
    285285            KStorageBus enmHDDBus = gpGlobalSession->guestOSTypeManager().getRecommendedHDStorageBus(m_guestOSTypeId);
    286             CStorageController comHDDController = m_machine.GetStorageControllerByInstance(enmHDDBus, 0);
     286            CStorageController comHDDController = machine.GetStorageControllerByInstance(enmHDDBus, 0);
    287287            if (!comHDDController.isNull())
    288288            {
    289                 machine.AttachDevice(comHDDController.GetName(), 0, 0, KDeviceType_HardDisk, m_virtualDisk);
     289                LONG uPortNumber = portNumberForDevice(comHDDController);
     290                machine.AttachDevice(comHDDController.GetName(), uPortNumber, 0, KDeviceType_HardDisk, m_virtualDisk);
    290291                if (!machine.isOk())
    291292                    UINotificationMessage::cannotAttachDevice(machine, UIMediumDeviceType_HardDisk, m_strMediumPath,
    292                                                               StorageSlot(enmHDDBus, 0, 0), notificationCenter());
     293                                                              StorageSlot(enmHDDBus, uPortNumber, 0), notificationCenter());
    293294            }
     295        }
     296        /* Save machine settings here because  portNumberForDevice needs to inquiry port attachments of the controller: */
     297        if (machine.isOk())
     298        {
     299            machine.SaveSettings();
     300            if (machine.isOk())
     301                success = true;
     302            else
     303                UINotificationMessage::cannotSaveMachineSettings(machine, notificationCenter());
    294304        }
    295305
    296306        /* Attach optical drive: */
    297307        KStorageBus enmDVDBus = gpGlobalSession->guestOSTypeManager().getRecommendedDVDStorageBus(m_guestOSTypeId);
    298         CStorageController comDVDController = m_machine.GetStorageControllerByInstance(enmDVDBus, 0);
     308        CStorageController comDVDController = machine.GetStorageControllerByInstance(enmDVDBus, 0);
    299309        if (!comDVDController.isNull())
    300310        {
     
    309319                    UINotificationMessage::cannotOpenMedium(vbox, strISOFilePath, notificationCenter());
    310320            }
    311             machine.AttachDevice(comDVDController.GetName(), 1, 0, KDeviceType_DVD, opticalDisk);
     321            LONG uPortNumber = portNumberForDevice(comDVDController);
     322            machine.AttachDevice(comDVDController.GetName(), uPortNumber, 0, KDeviceType_DVD, opticalDisk);
    312323            if (!machine.isOk())
    313324                UINotificationMessage::cannotAttachDevice(machine, UIMediumDeviceType_DVD, QString(),
    314325                                                          StorageSlot(enmDVDBus, 1, 0), notificationCenter());
    315326        }
     327        /* Save machine settings here because  portNumberForDevice needs to inquiry port attachments of the controller: */
     328        if (machine.isOk())
     329        {
     330            machine.SaveSettings();
     331            if (machine.isOk())
     332                success = true;
     333            else
     334                UINotificationMessage::cannotSaveMachineSettings(machine, notificationCenter());
     335        }
    316336
    317337        /* Attach an empty floppy drive if recommended */
    318338        if (gpGlobalSession->guestOSTypeManager().getRecommendedFloppy(m_guestOSTypeId))
    319339        {
    320             CStorageController comFloppyController = m_machine.GetStorageControllerByInstance(KStorageBus_Floppy, 0);
     340            CStorageController comFloppyController = machine.GetStorageControllerByInstance(KStorageBus_Floppy, 0);
    321341            if (!comFloppyController.isNull())
    322342            {
     
    830850    return true;
    831851}
     852
     853LONG UIWizardNewVM::portNumberForDevice(CStorageController &comController)
     854{
     855    QVector<CMediumAttachment> attachments = m_machine.GetMediumAttachmentsOfController(comController.GetName());
     856    QVector<LONG> attachmentPorts(attachments.size(), -1);
     857    for (int i = 0; i < attachmentPorts.size(); ++i)
     858        attachmentPorts[i] = attachments[i].GetPort();
     859    LONG portCount = comController.GetPortCount();
     860    /* Check if any of the ports in range [0, portCount) is unused. If so return it: */
     861    for (int i = 0; i < portCount; ++i)
     862    {
     863        if (!attachmentPorts.contains(i))
     864            return i;
     865    }
     866
     867
     868    if (!comController.isOk())
     869    {
     870        UINotificationMessage::cannotAcquireStorageControllerParameter(comController);
     871        return -1;
     872    }
     873    /* Check if we can increase the port count: */
     874    if (portCount + 1 >= (LONG)comController.GetMaxPortCount())
     875    {
     876        UINotificationMessage::cannotChangeStorageControllerParameter(comController);
     877        return -1;
     878    }
     879    comController.SetPortCount(portCount + 1);
     880    if (!comController.isOk())
     881    {
     882        UINotificationMessage::cannotChangeStorageControllerParameter(comController);
     883        return -1;
     884    }
     885    /* Use the last port: */
     886    return comController.GetPortCount() - 1;
     887}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.h

    r106061 r107090  
    4343/* Forward declarations: */
    4444class UIActionPool;
     45class CStorageController;
    4546
    4647enum SelectedDiskSource
     
    188189    void deleteVirtualDisk();
    189190    bool checkUnattendedInstallError(const CUnattended &comUnattended) const;
     191    LONG portNumberForDevice(CStorageController &comController);
    190192    /** @name Variables
    191193     * @{ */
Note: See TracChangeset for help on using the changeset viewer.

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