Changeset 5218 in vbox
- Timestamp:
- Oct 10, 2007 1:33:06 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 25152
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r5171 r5218 2616 2616 2617 2617 /** 2618 * Returns @c true if the given DVD image is attached to this machine either 2619 * in the current state or in any of the snapshots. 2620 * 2621 * @param aId Image ID to check. 2622 * @param aUsage Type of the check. 2623 * 2624 * @note Locks this object + DVD object for reading. 2625 */ 2626 bool Machine::isDVDImageUsed (const Guid &aId, ResourceUsage_T aUsage) 2627 { 2628 AutoCaller autoCaller (this); 2629 AssertComRCReturn (autoCaller.rc() || autoCaller.state() == Limited, false); 2630 2631 /* answer 'not attached' if the VM is limited */ 2632 if (autoCaller.state() == Limited) 2633 return false; 2634 2635 AutoReaderLock alock (this); 2636 2637 Machine *m = this; 2638 2639 /* take the session machine when appropriate */ 2640 if (!mData->mSession.mMachine.isNull()) 2641 m = mData->mSession.mMachine; 2642 2643 /* first, check the current state */ 2644 { 2645 const ComObjPtr <DVDDrive> &dvd = m->dvdDrive(); 2646 AssertReturn (!dvd.isNull(), false); 2647 2648 AutoReaderLock dvdLock (dvd); 2649 2650 /* loop over the backed up (permanent) and current (temporary) DVD data */ 2651 DVDDrive::Data *d [2]; 2652 if (dvd->data().isBackedUp()) 2653 { 2654 d [0] = dvd->data().backedUpData(); 2655 d [1] = dvd->data().data(); 2656 } 2657 else 2658 { 2659 d [0] = dvd->data().data(); 2660 d [1] = NULL; 2661 } 2662 2663 if (!(aUsage & ResourceUsage_PermanentUsage)) 2664 d [0] = NULL; 2665 if (!(aUsage & ResourceUsage_TemporaryUsage)) 2666 d [1] = NULL; 2667 2668 for (unsigned i = 0; i < ELEMENTS (d); ++ i) 2669 { 2670 if (d [i] && 2671 d [i]->mDriveState == DriveState_ImageMounted) 2672 { 2673 Guid id; 2674 HRESULT rc = d [i]->mDVDImage->COMGETTER(Id) (id.asOutParam()); 2675 AssertComRC (rc); 2676 if (id == aId) 2677 return true; 2678 } 2679 } 2680 } 2681 2682 /* then, check snapshots if any */ 2683 if (aUsage & ResourceUsage_PermanentUsage) 2684 { 2685 if (!mData->mFirstSnapshot.isNull() && 2686 mData->mFirstSnapshot->isDVDImageUsed (aId)) 2687 return true; 2688 } 2689 2690 return false; 2691 } 2692 2693 /** 2694 * Returns @c true if the given Floppy image is attached to this machine either 2695 * in the current state or in any of the snapshots. 2696 * 2697 * @param aId Image ID to check. 2698 * @param aUsage Type of the check. 2699 * 2700 * @note Locks this object + Floppy object for reading. 2701 */ 2702 bool Machine::isFloppyImageUsed (const Guid &aId, ResourceUsage_T aUsage) 2703 { 2704 AutoCaller autoCaller (this); 2705 AssertComRCReturn (autoCaller.rc() || autoCaller.state() == Limited, false); 2706 2707 /* answer 'not attached' if the VM is limited */ 2708 if (autoCaller.state() == Limited) 2709 return false; 2710 2711 AutoReaderLock alock (this); 2712 2713 Machine *m = this; 2714 2715 /* take the session machine when appropriate */ 2716 if (!mData->mSession.mMachine.isNull()) 2717 m = mData->mSession.mMachine; 2718 2719 /* first, check the current state */ 2720 { 2721 const ComObjPtr <FloppyDrive> &floppy = m->floppyDrive(); 2722 AssertReturn (!floppy.isNull(), false); 2723 2724 AutoReaderLock floppyLock (floppy); 2725 2726 /* loop over the backed up (permanent) and current (temporary) Floppy data */ 2727 FloppyDrive::Data *d [2]; 2728 if (floppy->data().isBackedUp()) 2729 { 2730 d [0] = floppy->data().backedUpData(); 2731 d [1] = floppy->data().data(); 2732 } 2733 else 2734 { 2735 d [0] = floppy->data().data(); 2736 d [1] = NULL; 2737 } 2738 2739 if (!(aUsage & ResourceUsage_PermanentUsage)) 2740 d [0] = NULL; 2741 if (!(aUsage & ResourceUsage_TemporaryUsage)) 2742 d [1] = NULL; 2743 2744 for (unsigned i = 0; i < ELEMENTS (d); ++ i) 2745 { 2746 if (d [i] && 2747 d [i]->mDriveState == DriveState_ImageMounted) 2748 { 2749 Guid id; 2750 HRESULT rc = d [i]->mFloppyImage->COMGETTER(Id) (id.asOutParam()); 2751 AssertComRC (rc); 2752 if (id == aId) 2753 return true; 2754 } 2755 } 2756 } 2757 2758 /* then, check snapshots if any */ 2759 if (aUsage & ResourceUsage_PermanentUsage) 2760 { 2761 if (!mData->mFirstSnapshot.isNull() && 2762 mData->mFirstSnapshot->isFloppyImageUsed (aId)) 2763 return true; 2764 } 2765 2766 return false; 2767 } 2768 2769 /** 2618 2770 * @note Locks mParent and this object for writing, 2619 2771 * calls the client process (outside the lock). -
trunk/src/VBox/Main/SnapshotImpl.cpp
r4071 r5218 396 396 397 397 /** 398 * Returns @c true if the given DVD image is attached to this snapshot or any 399 * of its children, recursively. 400 * 401 * @param aId Image ID to check. 402 * 403 * @note Locks this object for reading. 404 */ 405 bool Snapshot::isDVDImageUsed (const Guid &aId) 406 { 407 AutoReaderLock alock (this); 408 AssertReturn (isReady(), false); 409 410 AssertReturn (!mData.mMachine.isNull(), false); 411 AssertReturn (!mData.mMachine->dvdDrive().isNull(), false); 412 413 DVDDrive::Data *d = mData.mMachine->dvdDrive()->data().data(); 414 415 if (d && 416 d->mDriveState == DriveState_ImageMounted) 417 { 418 Guid id; 419 HRESULT rc = d->mDVDImage->COMGETTER(Id) (id.asOutParam()); 420 AssertComRC (rc); 421 if (id == aId) 422 return true; 423 } 424 425 AutoReaderLock chLock (childrenLock()); 426 for (SnapshotList::const_iterator it = children().begin(); 427 it != children().end(); ++ it) 428 { 429 if ((*it)->isDVDImageUsed (aId)) 430 return true; 431 } 432 433 return false; 434 } 435 436 /** 437 * Returns @c true if the given Floppy image is attached to this snapshot or any 438 * of its children, recursively. 439 * 440 * @param aId Image ID to check. 441 * 442 * @note Locks this object for reading. 443 */ 444 bool Snapshot::isFloppyImageUsed (const Guid &aId) 445 { 446 AutoReaderLock alock (this); 447 AssertReturn (isReady(), false); 448 449 AssertReturn (!mData.mMachine.isNull(), false); 450 AssertReturn (!mData.mMachine->dvdDrive().isNull(), false); 451 452 FloppyDrive::Data *d = mData.mMachine->floppyDrive()->data().data(); 453 454 if (d && 455 d->mDriveState == DriveState_ImageMounted) 456 { 457 Guid id; 458 HRESULT rc = d->mFloppyImage->COMGETTER(Id) (id.asOutParam()); 459 AssertComRC (rc); 460 if (id == aId) 461 return true; 462 } 463 464 AutoReaderLock chLock (childrenLock()); 465 for (SnapshotList::const_iterator it = children().begin(); 466 it != children().end(); ++ it) 467 { 468 if ((*it)->isFloppyImageUsed (aId)) 469 return true; 470 } 471 472 return false; 473 } 474 475 /** 398 476 * Checks if the specified path change affects the saved state file path of 399 477 * this snapshot or any of its (grand-)children and updates it accordingly. -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r5101 r5218 2729 2729 * Helper to find machines that use the given DVD image. 2730 2730 * 2731 * @param machineIDs string where to store the list (can be NULL) 2732 * @return TRUE if at least one machine found and false otherwise 2731 * This method also checks whether an existing snapshot refers to the given 2732 * image. However, only the machine ID is returned in this case, not IDs of 2733 * individual snapshots. 2734 * 2735 * @param aId Image ID to get usage for. 2736 * @param aUsage Type of the check. 2737 * @param aMachineIDs Where to store the list of machine IDs (can be NULL) 2738 * 2739 * @return @c true if at least one machine or its snapshot found and @c false 2740 * otherwise. 2733 2741 * 2734 2742 * @note For now, we just scan all the machines. We can optimize this later … … 2738 2746 * @note Locks objects for reading. 2739 2747 */ 2740 BOOL VirtualBox::getDVDImageUsage (const Guid &id,2741 ResourceUsage_T usage,2742 Bstr * machineIDs)2748 bool VirtualBox::getDVDImageUsage (const Guid &aId, 2749 ResourceUsage_T aUsage, 2750 Bstr *aMachineIDs) 2743 2751 { 2744 2752 AutoCaller autoCaller (this); … … 2755 2763 ++ mit) 2756 2764 { 2757 /// @todo (dmik) move this part to Machine for better incapsulation2758 2759 2765 ComObjPtr <Machine> m = *mit; 2760 AutoReaderLock malock (m); 2761 2762 /* take the session machine when appropriate */ 2763 if (!m->data()->mSession.mMachine.isNull()) 2764 m = m->data()->mSession.mMachine; 2765 2766 const ComObjPtr <DVDDrive> &dvd = m->dvdDrive(); 2767 AutoReaderLock dalock (dvd); 2768 2769 /* loop over the backed up (permanent) and current (temporary) dvd data */ 2770 DVDDrive::Data *dvdData [2]; 2771 if (dvd->data().isBackedUp()) 2766 if (m->isDVDImageUsed (aId, aUsage)) 2772 2767 { 2773 dvdData [0] = dvd->data().backedUpData(); 2774 dvdData [1] = dvd->data().data(); 2768 /* if not interested in the list, return shortly */ 2769 if (aMachineIDs == NULL) 2770 return true; 2771 2772 idSet.insert (m->data()->mUuid); 2775 2773 } 2776 else 2777 { 2778 dvdData [0] = dvd->data().data(); 2779 dvdData [1] = NULL; 2780 } 2781 2782 if (!(usage & ResourceUsage_PermanentUsage)) 2783 dvdData [0] = NULL; 2784 if (!(usage & ResourceUsage_TemporaryUsage)) 2785 dvdData [1] = NULL; 2786 2787 for (unsigned i = 0; i < ELEMENTS (dvdData); i++) 2788 { 2789 if (dvdData [i]) 2790 { 2791 if (dvdData [i]->mDriveState == DriveState_ImageMounted) 2792 { 2793 Guid iid; 2794 dvdData [i]->mDVDImage->COMGETTER(Id) (iid.asOutParam()); 2795 if (iid == id) 2796 idSet.insert (m->data()->mUuid); 2797 } 2798 } 2799 } 2800 } 2801 } 2802 2803 if (machineIDs) 2774 } 2775 } 2776 2777 if (aMachineIDs) 2804 2778 { 2805 2779 if (!idSet.empty()) … … 2819 2793 *(-- idListPtr) = 0; 2820 2794 /* copy the string */ 2821 * machineIDs = idList;2795 *aMachineIDs = idList; 2822 2796 RTMemTmpFree (idList); 2823 2797 } 2824 2798 else 2825 2799 { 2826 (* machineIDs).setNull();2800 (*aMachineIDs).setNull(); 2827 2801 } 2828 2802 } … … 2832 2806 2833 2807 /** 2834 * Helper to find machines that use the given floppy image. 2835 * 2836 * @param machineIDs string where to store the list (can be NULL) 2837 * @return TRUE if at least one machine found and false otherwise 2808 * Helper to find machines that use the given Floppy image. 2809 * 2810 * This method also checks whether an existing snapshot refers to the given 2811 * image. However, only the machine ID is returned in this case, not IDs of 2812 * individual snapshots. 2813 * 2814 * @param aId Image ID to get usage for. 2815 * @param aUsage Type of the check. 2816 * @param aMachineIDs Where to store the list of machine IDs (can be NULL) 2817 * 2818 * @return @c true if at least one machine or its snapshot found and @c false 2819 * otherwise. 2838 2820 * 2839 2821 * @note For now, we just scan all the machines. We can optimize this later 2840 2822 * if required by adding the corresponding field to FloppyImage and requiring all 2841 * IFloppyImage instances to be FloppyImage objects.2823 * FloppyImage instances to be FloppyImage objects. 2842 2824 * 2843 2825 * @note Locks objects for reading. 2844 2826 */ 2845 BOOL VirtualBox::getFloppyImageUsage (const Guid &id,2846 ResourceUsage_T usage,2847 Bstr * machineIDs)2827 bool VirtualBox::getFloppyImageUsage (const Guid &aId, 2828 ResourceUsage_T aUsage, 2829 Bstr *aMachineIDs) 2848 2830 { 2849 2831 AutoCaller autoCaller (this); … … 2860 2842 ++ mit) 2861 2843 { 2862 /// @todo (dmik) move this part to Machine for better incapsulation2863 2864 2844 ComObjPtr <Machine> m = *mit; 2865 AutoReaderLock malock (m); 2866 2867 /* take the session machine when appropriate */ 2868 if (!m->data()->mSession.mMachine.isNull()) 2869 m = m->data()->mSession.mMachine; 2870 2871 const ComObjPtr <FloppyDrive> &drv = m->floppyDrive(); 2872 AutoReaderLock dalock (drv); 2873 2874 /* loop over the backed up (permanent) and current (temporary) floppy data */ 2875 FloppyDrive::Data *data [2]; 2876 if (drv->data().isBackedUp()) 2845 if (m->isFloppyImageUsed (aId, aUsage)) 2877 2846 { 2878 data [0] = drv->data().backedUpData(); 2879 data [1] = drv->data().data(); 2847 /* if not interested in the list, return shortly */ 2848 if (aMachineIDs == NULL) 2849 return true; 2850 2851 idSet.insert (m->data()->mUuid); 2880 2852 } 2881 else 2882 { 2883 data [0] = drv->data().data(); 2884 data [1] = NULL; 2885 } 2886 2887 if (!(usage & ResourceUsage_PermanentUsage)) 2888 data [0] = NULL; 2889 if (!(usage & ResourceUsage_TemporaryUsage)) 2890 data [1] = NULL; 2891 2892 for (unsigned i = 0; i < ELEMENTS (data); i++) 2893 { 2894 if (data [i]) 2895 { 2896 if (data [i]->mDriveState == DriveState_ImageMounted) 2897 { 2898 Guid iid; 2899 data [i]->mFloppyImage->COMGETTER(Id) (iid.asOutParam()); 2900 if (iid == id) 2901 idSet.insert (m->data()->mUuid); 2902 } 2903 } 2904 } 2905 } 2906 } 2907 2908 if (machineIDs) 2853 } 2854 } 2855 2856 if (aMachineIDs) 2909 2857 { 2910 2858 if (!idSet.empty()) … … 2924 2872 *(-- idListPtr) = 0; 2925 2873 /* copy the string */ 2926 * machineIDs = idList;2874 *aMachineIDs = idList; 2927 2875 RTMemTmpFree (idList); 2928 2876 } 2929 2877 else 2930 2878 { 2931 (* machineIDs).setNull();2879 (*aMachineIDs).setNull(); 2932 2880 } 2933 2881 } -
trunk/src/VBox/Main/include/MachineImpl.h
r5118 r5218 543 543 void getLogFolder (Utf8Str &aLogFolder); 544 544 545 bool isDVDImageUsed (const Guid &aId, ResourceUsage_T aUsage); 546 bool isFloppyImageUsed (const Guid &aId, ResourceUsage_T aUsage); 547 545 548 HRESULT openSession (IInternalSessionControl *aControl); 546 549 HRESULT openRemoteSession (IInternalSessionControl *aControl, -
trunk/src/VBox/Main/include/SnapshotImpl.h
r4071 r5218 107 107 ComObjPtr <Snapshot> findChildOrSelf (INPTR BSTR aName); 108 108 109 bool isDVDImageUsed (const Guid &aId); 110 bool isFloppyImageUsed (const Guid &aId); 111 109 112 void updateSavedStatePaths (const char *aOldPath, const char *aNewPath); 110 113 -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r4071 r5218 231 231 } 232 232 233 BOOL getDVDImageUsage (const Guid &id, ResourceUsage_T usage,234 Bstr * machineIDs = NULL);235 BOOL getFloppyImageUsage (const Guid &id, ResourceUsage_T usage,236 Bstr * machineIDs = NULL);233 bool getDVDImageUsage (const Guid &aId, ResourceUsage_T aUsage, 234 Bstr *aMachineIDs = NULL); 235 bool getFloppyImageUsage (const Guid &aId, ResourceUsage_T aUsage, 236 Bstr *aMachineIDs = NULL); 237 237 238 238 const ComObjPtr <Host> &host() { return mData.mHost; }
Note:
See TracChangeset
for help on using the changeset viewer.