VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/StorageControllerImpl.cpp@ 56574

Last change on this file since 56574 was 56477, checked in by vboxsync, 9 years ago

Main/StorageController: Eliminate leftovers from the SATA IDE emulation which are not required anymore for a long time now. To avoid bumping the settings version for older configs when read with VBox 5.0 the default config is hardcoded in the settings code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1/* $Id: StorageControllerImpl.cpp 56477 2015-06-17 14:15:53Z vboxsync $ */
2
3/** @file
4 *
5 * Implementation of IStorageController.
6 */
7
8/*
9 * Copyright (C) 2008-2015 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "StorageControllerImpl.h"
21#include "MachineImpl.h"
22#include "VirtualBoxImpl.h"
23#include "SystemPropertiesImpl.h"
24
25#include <iprt/string.h>
26#include <iprt/cpp/utils.h>
27
28#include <VBox/err.h>
29#include <VBox/settings.h>
30
31#include <algorithm>
32
33#include "AutoStateDep.h"
34#include "AutoCaller.h"
35#include "Logging.h"
36
37// defines
38/////////////////////////////////////////////////////////////////////////////
39//
40//
41DEFINE_EMPTY_CTOR_DTOR(StorageController)
42
43struct BackupableStorageControllerData
44{
45 /* Constructor. */
46 BackupableStorageControllerData()
47 : mStorageBus(StorageBus_IDE),
48 mStorageControllerType(StorageControllerType_PIIX4),
49 mInstance(0),
50 mPortCount(2),
51 fUseHostIOCache(true),
52 fBootable(false)
53 { }
54
55 /** Unique name of the storage controller. */
56 Utf8Str strName;
57 /** The connection type of the storage controller. */
58 StorageBus_T mStorageBus;
59 /** Type of the Storage controller. */
60 StorageControllerType_T mStorageControllerType;
61 /** Instance number of the storage controller. */
62 ULONG mInstance;
63 /** Number of usable ports. */
64 ULONG mPortCount;
65 /** Whether to use the host IO caches. */
66 BOOL fUseHostIOCache;
67 /** Whether it is possible to boot from disks attached to this controller. */
68 BOOL fBootable;
69};
70
71struct StorageController::Data
72{
73 Data(Machine * const aMachine)
74 : pVirtualBox(NULL),
75 pSystemProperties(NULL),
76 pParent(aMachine)
77 {
78 unconst(pVirtualBox) = aMachine->i_getVirtualBox();
79 unconst(pSystemProperties) = pVirtualBox->i_getSystemProperties();
80 }
81
82 VirtualBox * const pVirtualBox;
83 SystemProperties * const pSystemProperties;
84 Machine * const pParent;
85 const ComObjPtr<StorageController> pPeer;
86
87 Backupable<BackupableStorageControllerData> bd;
88};
89
90
91// constructor / destructor
92/////////////////////////////////////////////////////////////////////////////
93
94HRESULT StorageController::FinalConstruct()
95{
96 return BaseFinalConstruct();
97}
98
99void StorageController::FinalRelease()
100{
101 uninit();
102 BaseFinalRelease();
103}
104
105// public initializer/uninitializer for internal purposes only
106/////////////////////////////////////////////////////////////////////////////
107
108/**
109 * Initializes the storage controller object.
110 *
111 * @returns COM result indicator.
112 * @param aParent Pointer to our parent object.
113 * @param aName Name of the storage controller.
114 * @param aInstance Instance number of the storage controller.
115 */
116HRESULT StorageController::init(Machine *aParent,
117 const Utf8Str &aName,
118 StorageBus_T aStorageBus,
119 ULONG aInstance, bool fBootable)
120{
121 LogFlowThisFunc(("aParent=%p aName=\"%s\" aInstance=%u\n",
122 aParent, aName.c_str(), aInstance));
123
124 ComAssertRet(aParent && !aName.isEmpty(), E_INVALIDARG);
125 if ( (aStorageBus <= StorageBus_Null)
126 || (aStorageBus > StorageBus_USB))
127 return setError(E_INVALIDARG,
128 tr("Invalid storage connection type"));
129
130 ULONG maxInstances;
131 ChipsetType_T chipsetType;
132 HRESULT rc = aParent->COMGETTER(ChipsetType)(&chipsetType);
133 if (FAILED(rc))
134 return rc;
135 rc = aParent->i_getVirtualBox()->i_getSystemProperties()->
136 GetMaxInstancesOfStorageBus(chipsetType, aStorageBus, &maxInstances);
137 if (FAILED(rc))
138 return rc;
139 if (aInstance >= maxInstances)
140 return setError(E_INVALIDARG,
141 tr("Too many storage controllers of this type"));
142
143 /* Enclose the state transition NotReady->InInit->Ready */
144 AutoInitSpan autoInitSpan(this);
145 AssertReturn(autoInitSpan.isOk(), E_FAIL);
146
147 m = new Data(aParent);
148
149 /* m->pPeer is left null */
150
151 m->bd.allocate();
152
153 m->bd->strName = aName;
154 m->bd->mInstance = aInstance;
155 m->bd->fBootable = fBootable;
156 m->bd->mStorageBus = aStorageBus;
157 if ( aStorageBus != StorageBus_IDE
158 && aStorageBus != StorageBus_Floppy)
159 m->bd->fUseHostIOCache = false;
160 else
161 m->bd->fUseHostIOCache = true;
162
163 switch (aStorageBus)
164 {
165 case StorageBus_IDE:
166 m->bd->mPortCount = 2;
167 m->bd->mStorageControllerType = StorageControllerType_PIIX4;
168 break;
169 case StorageBus_SATA:
170 m->bd->mPortCount = 30;
171 m->bd->mStorageControllerType = StorageControllerType_IntelAhci;
172 break;
173 case StorageBus_SCSI:
174 m->bd->mPortCount = 16;
175 m->bd->mStorageControllerType = StorageControllerType_LsiLogic;
176 break;
177 case StorageBus_Floppy:
178 m->bd->mPortCount = 1;
179 m->bd->mStorageControllerType = StorageControllerType_I82078;
180 break;
181 case StorageBus_SAS:
182 m->bd->mPortCount = 8;
183 m->bd->mStorageControllerType = StorageControllerType_LsiLogicSas;
184 case StorageBus_USB:
185 m->bd->mPortCount = 8;
186 m->bd->mStorageControllerType = StorageControllerType_USB;
187 break;
188 }
189
190 /* Confirm a successful initialization */
191 autoInitSpan.setSucceeded();
192
193 return S_OK;
194}
195
196/**
197 * Initializes the object given another object
198 * (a kind of copy constructor). This object shares data with
199 * the object passed as an argument.
200 *
201 * @param aReshare
202 * When false, the original object will remain a data owner.
203 * Otherwise, data ownership will be transferred from the original
204 * object to this one.
205 *
206 * @note This object must be destroyed before the original object
207 * it shares data with is destroyed.
208 *
209 * @note Locks @a aThat object for writing if @a aReshare is @c true, or for
210 * reading if @a aReshare is false.
211 */
212HRESULT StorageController::init(Machine *aParent,
213 StorageController *aThat,
214 bool aReshare /* = false */)
215{
216 LogFlowThisFunc(("aParent=%p, aThat=%p, aReshare=%RTbool\n",
217 aParent, aThat, aReshare));
218
219 ComAssertRet(aParent && aThat, E_INVALIDARG);
220
221 /* Enclose the state transition NotReady->InInit->Ready */
222 AutoInitSpan autoInitSpan(this);
223 AssertReturn(autoInitSpan.isOk(), E_FAIL);
224
225 m = new Data(aParent);
226
227 /* sanity */
228 AutoCaller thatCaller(aThat);
229 AssertComRCReturnRC(thatCaller.rc());
230
231 if (aReshare)
232 {
233 AutoWriteLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
234
235 unconst(aThat->m->pPeer) = this;
236 m->bd.attach (aThat->m->bd);
237 }
238 else
239 {
240 unconst(m->pPeer) = aThat;
241
242 AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
243 m->bd.share (aThat->m->bd);
244 }
245
246 /* Confirm successful initialization */
247 autoInitSpan.setSucceeded();
248
249 return S_OK;
250}
251
252/**
253 * Initializes the storage controller object given another guest object
254 * (a kind of copy constructor). This object makes a private copy of data
255 * of the original object passed as an argument.
256 */
257HRESULT StorageController::initCopy(Machine *aParent, StorageController *aThat)
258{
259 LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
260
261 ComAssertRet(aParent && aThat, E_INVALIDARG);
262
263 /* Enclose the state transition NotReady->InInit->Ready */
264 AutoInitSpan autoInitSpan(this);
265 AssertReturn(autoInitSpan.isOk(), E_FAIL);
266
267 m = new Data(aParent);
268 /* m->pPeer is left null */
269
270 AutoCaller thatCaller(aThat);
271 AssertComRCReturnRC(thatCaller.rc());
272
273 AutoReadLock thatlock(aThat COMMA_LOCKVAL_SRC_POS);
274 m->bd.attachCopy(aThat->m->bd);
275
276 /* Confirm a successful initialization */
277 autoInitSpan.setSucceeded();
278
279 return S_OK;
280}
281
282
283/**
284 * Uninitializes the instance and sets the ready flag to FALSE.
285 * Called either from FinalRelease() or by the parent when it gets destroyed.
286 */
287void StorageController::uninit()
288{
289 LogFlowThisFunc(("\n"));
290
291 /* Enclose the state transition Ready->InUninit->NotReady */
292 AutoUninitSpan autoUninitSpan(this);
293 if (autoUninitSpan.uninitDone())
294 return;
295
296 m->bd.free();
297
298 unconst(m->pPeer) = NULL;
299 unconst(m->pParent) = NULL;
300
301 delete m;
302 m = NULL;
303}
304
305
306// IStorageController properties
307HRESULT StorageController::getName(com::Utf8Str &aName)
308{
309 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
310
311 aName = m->bd->strName;
312
313 return S_OK;
314}
315
316HRESULT StorageController::setName(const com::Utf8Str &aName)
317{
318 /* the machine needs to be mutable */
319 AutoMutableStateDependency adep(m->pParent);
320 if (FAILED(adep.rc())) return adep.rc();
321
322 AutoMultiWriteLock2 alock(m->pParent, this COMMA_LOCKVAL_SRC_POS);
323
324 if (m->bd->strName != aName)
325 {
326 ComObjPtr<StorageController> ctrl;
327 HRESULT rc = m->pParent->i_getStorageControllerByName(aName, ctrl, false /* aSetError */);
328 if (SUCCEEDED(rc))
329 return setError(VBOX_E_OBJECT_IN_USE,
330 tr("Storage controller named '%s' already exists"),
331 aName.c_str());
332
333 m->bd.backup();
334 m->bd->strName = aName;
335
336 m->pParent->i_setModified(Machine::IsModified_Storage);
337 alock.release();
338
339 m->pParent->i_onStorageControllerChange();
340 }
341
342 return S_OK;
343}
344
345HRESULT StorageController::getBus(StorageBus_T *aBus)
346{
347 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
348
349 *aBus = m->bd->mStorageBus;
350
351 return S_OK;
352}
353
354HRESULT StorageController::getControllerType(StorageControllerType_T *aControllerType)
355{
356 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
357
358 *aControllerType = m->bd->mStorageControllerType;
359
360 return S_OK;
361}
362
363HRESULT StorageController::setControllerType(StorageControllerType_T aControllerType)
364{
365 /* the machine needs to be mutable */
366 AutoMutableStateDependency adep(m->pParent);
367 if (FAILED(adep.rc())) return adep.rc();
368
369 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
370
371 HRESULT rc = S_OK;
372
373 switch (m->bd->mStorageBus)
374 {
375 case StorageBus_IDE:
376 {
377 if ( (aControllerType != StorageControllerType_PIIX3)
378 && (aControllerType != StorageControllerType_PIIX4)
379 && (aControllerType != StorageControllerType_ICH6))
380 rc = E_INVALIDARG;
381 break;
382 }
383 case StorageBus_SATA:
384 {
385 if (aControllerType != StorageControllerType_IntelAhci)
386 rc = E_INVALIDARG;
387 break;
388 }
389 case StorageBus_SCSI:
390 {
391 if ( (aControllerType != StorageControllerType_LsiLogic)
392 && (aControllerType != StorageControllerType_BusLogic))
393 rc = E_INVALIDARG;
394 break;
395 }
396 case StorageBus_Floppy:
397 {
398 if (aControllerType != StorageControllerType_I82078)
399 rc = E_INVALIDARG;
400 break;
401 }
402 case StorageBus_SAS:
403 {
404 if (aControllerType != StorageControllerType_LsiLogicSas)
405 rc = E_INVALIDARG;
406 break;
407 }
408 case StorageBus_USB:
409 {
410 if (aControllerType != StorageControllerType_USB)
411 rc = E_INVALIDARG;
412 break;
413 }
414 default:
415 AssertMsgFailed(("Invalid controller type %d\n", m->bd->mStorageBus));
416 rc = E_INVALIDARG;
417 }
418
419 if (!SUCCEEDED(rc))
420 return setError(rc,
421 tr ("Invalid controller type %d"),
422 aControllerType);
423
424 if (m->bd->mStorageControllerType != aControllerType)
425 {
426 m->bd.backup();
427 m->bd->mStorageControllerType = aControllerType;
428
429 alock.release();
430 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS); // m->pParent is const, needs no locking
431 m->pParent->i_setModified(Machine::IsModified_Storage);
432 mlock.release();
433
434 m->pParent->i_onStorageControllerChange();
435 }
436
437 return S_OK;
438}
439
440HRESULT StorageController::getMaxDevicesPerPortCount(ULONG *aMaxDevicesPerPortCount)
441{
442 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
443
444 HRESULT rc = m->pSystemProperties->GetMaxDevicesPerPortForStorageBus(m->bd->mStorageBus, aMaxDevicesPerPortCount);
445
446 return rc;
447}
448
449HRESULT StorageController::getMinPortCount(ULONG *aMinPortCount)
450{
451 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
452
453 HRESULT rc = m->pSystemProperties->GetMinPortCountForStorageBus(m->bd->mStorageBus, aMinPortCount);
454 return rc;
455}
456
457HRESULT StorageController::getMaxPortCount(ULONG *aMaxPortCount)
458{
459 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
460 HRESULT rc = m->pSystemProperties->GetMaxPortCountForStorageBus(m->bd->mStorageBus, aMaxPortCount);
461
462 return rc;
463}
464
465HRESULT StorageController::getPortCount(ULONG *aPortCount)
466{
467 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
468
469 *aPortCount = m->bd->mPortCount;
470
471 return S_OK;
472}
473
474HRESULT StorageController::setPortCount(ULONG aPortCount)
475{
476 /* the machine needs to be mutable */
477 AutoMutableStateDependency adep(m->pParent);
478 if (FAILED(adep.rc())) return adep.rc();
479
480 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
481
482 switch (m->bd->mStorageBus)
483 {
484 case StorageBus_SATA:
485 {
486 /* AHCI SATA supports a maximum of 30 ports. */
487 if (aPortCount < 1 || aPortCount > 30)
488 return setError(E_INVALIDARG,
489 tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
490 aPortCount, 1, 30);
491 break;
492 }
493 case StorageBus_SCSI:
494 {
495 /*
496 * SCSI does not support setting different ports.
497 * (doesn't make sense here either).
498 * The maximum and minimum is 16 and unless the callee
499 * tries to set a different value we return an error.
500 */
501 if (aPortCount != 16)
502 return setError(E_INVALIDARG,
503 tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
504 aPortCount, 16, 16);
505 break;
506 }
507 case StorageBus_IDE:
508 {
509 /*
510 * The port count is fixed to 2.
511 */
512 if (aPortCount != 2)
513 return setError(E_INVALIDARG,
514 tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
515 aPortCount, 2, 2);
516 break;
517 }
518 case StorageBus_Floppy:
519 {
520 /*
521 * The port count is fixed to 1.
522 */
523 if (aPortCount != 1)
524 return setError(E_INVALIDARG,
525 tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
526 aPortCount, 1, 1);
527 break;
528 }
529 case StorageBus_SAS:
530 {
531 /* SAS supports a maximum of 255 ports. */
532 if (aPortCount < 1 || aPortCount > 255)
533 return setError(E_INVALIDARG,
534 tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
535 aPortCount, 1, 255);
536 break;
537 }
538 case StorageBus_USB:
539 {
540 /*
541 * The port count is fixed to 8.
542 */
543 if (aPortCount != 8)
544 return setError(E_INVALIDARG,
545 tr("Invalid port count: %lu (must be in range [%lu, %lu])"),
546 aPortCount, 8, 8);
547 break;
548 }
549 default:
550 AssertMsgFailed(("Invalid controller type %d\n", m->bd->mStorageBus));
551 }
552
553 if (m->bd->mPortCount != aPortCount)
554 {
555 m->bd.backup();
556 m->bd->mPortCount = aPortCount;
557
558 alock.release();
559 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS); // m->pParent is const, needs no locking
560 m->pParent->i_setModified(Machine::IsModified_Storage);
561 mlock.release();
562
563 m->pParent->i_onStorageControllerChange();
564 }
565
566 return S_OK;
567}
568
569HRESULT StorageController::getInstance(ULONG *aInstance)
570{
571 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
572
573 *aInstance = m->bd->mInstance;
574
575 return S_OK;
576}
577
578HRESULT StorageController::setInstance(ULONG aInstance)
579{
580 /* the machine needs to be mutable */
581 AutoMutableStateDependency adep(m->pParent);
582 if (FAILED(adep.rc())) return adep.rc();
583
584 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
585
586 if (m->bd->mInstance != aInstance)
587 {
588 m->bd.backup();
589 m->bd->mInstance = aInstance;
590
591 alock.release();
592 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS); // m->pParent is const, needs no locking
593 m->pParent->i_setModified(Machine::IsModified_Storage);
594 mlock.release();
595
596 m->pParent->i_onStorageControllerChange();
597 }
598
599 return S_OK;
600}
601
602HRESULT StorageController::getUseHostIOCache(BOOL *fUseHostIOCache)
603{
604 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
605
606 *fUseHostIOCache = m->bd->fUseHostIOCache;
607
608 return S_OK;
609}
610
611HRESULT StorageController::setUseHostIOCache(BOOL fUseHostIOCache)
612{
613 /* the machine needs to be mutable */
614 AutoMutableStateDependency adep(m->pParent);
615 if (FAILED(adep.rc())) return adep.rc();
616
617 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
618
619 if (m->bd->fUseHostIOCache != !!fUseHostIOCache)
620 {
621 m->bd.backup();
622 m->bd->fUseHostIOCache = !!fUseHostIOCache;
623
624 alock.release();
625 AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS); // m->pParent is const, needs no locking
626 m->pParent->i_setModified(Machine::IsModified_Storage);
627 mlock.release();
628
629 m->pParent->i_onStorageControllerChange();
630 }
631
632 return S_OK;
633}
634
635HRESULT StorageController::getBootable(BOOL *fBootable)
636{
637 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
638
639 *fBootable = m->bd->fBootable;
640
641 return S_OK;
642}
643
644// public methods only for internal purposes
645/////////////////////////////////////////////////////////////////////////////
646
647const Utf8Str& StorageController::i_getName() const
648{
649 return m->bd->strName;
650}
651
652StorageControllerType_T StorageController::i_getControllerType() const
653{
654 return m->bd->mStorageControllerType;
655}
656
657StorageBus_T StorageController::i_getStorageBus() const
658{
659 return m->bd->mStorageBus;
660}
661
662ULONG StorageController::i_getInstance() const
663{
664 return m->bd->mInstance;
665}
666
667bool StorageController::i_getBootable() const
668{
669 return !!m->bd->fBootable;
670}
671
672/**
673 * Returns S_OK if the given port and device numbers are within the range supported
674 * by this controller. If not, it sets an error and returns E_INVALIDARG.
675 * @param ulPort
676 * @param ulDevice
677 * @return
678 */
679HRESULT StorageController::i_checkPortAndDeviceValid(LONG aControllerPort,
680 LONG aDevice)
681{
682 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
683
684 ULONG portCount = m->bd->mPortCount;
685 ULONG devicesPerPort;
686 HRESULT rc = m->pSystemProperties->GetMaxDevicesPerPortForStorageBus(m->bd->mStorageBus, &devicesPerPort);
687 if (FAILED(rc)) return rc;
688
689 if ( aControllerPort < 0
690 || aControllerPort >= (LONG)portCount
691 || aDevice < 0
692 || aDevice >= (LONG)devicesPerPort
693 )
694 return setError(E_INVALIDARG,
695 tr("The port and/or device parameter are out of range: port=%d (must be in range [0, %d]), device=%d (must be in range [0, %d])"),
696 (int)aControllerPort, (int)portCount-1, (int)aDevice, (int)devicesPerPort-1);
697
698 return S_OK;
699}
700
701/** @note Locks objects for writing! */
702void StorageController::i_setBootable(BOOL fBootable)
703{
704 AutoCaller autoCaller(this);
705 AssertComRCReturnVoid(autoCaller.rc());
706
707 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
708
709 m->bd.backup();
710 m->bd->fBootable = fBootable;
711}
712
713/** @note Locks objects for writing! */
714void StorageController::i_rollback()
715{
716 AutoCaller autoCaller(this);
717 AssertComRCReturnVoid(autoCaller.rc());
718
719 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
720
721 m->bd.rollback();
722}
723
724/**
725 * @note Locks this object for writing, together with the peer object (also
726 * for writing) if there is one.
727 */
728void StorageController::i_commit()
729{
730 /* sanity */
731 AutoCaller autoCaller(this);
732 AssertComRCReturnVoid (autoCaller.rc());
733
734 /* sanity too */
735 AutoCaller peerCaller (m->pPeer);
736 AssertComRCReturnVoid (peerCaller.rc());
737
738 /* lock both for writing since we modify both (m->pPeer is "master" so locked
739 * first) */
740 AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS);
741
742 if (m->bd.isBackedUp())
743 {
744 m->bd.commit();
745 if (m->pPeer)
746 {
747 // attach new data to the peer and reshare it
748 m->pPeer->m->bd.attach (m->bd);
749 }
750 }
751}
752
753/**
754 * Cancels sharing (if any) by making an independent copy of data.
755 * This operation also resets this object's peer to NULL.
756 *
757 * @note Locks this object for writing, together with the peer object
758 * represented by @a aThat (locked for reading).
759 */
760void StorageController::i_unshare()
761{
762 /* sanity */
763 AutoCaller autoCaller(this);
764 AssertComRCReturnVoid (autoCaller.rc());
765
766 /* sanity too */
767 AutoCaller peerCaller (m->pPeer);
768 AssertComRCReturnVoid (peerCaller.rc());
769
770 /* peer is not modified, lock it for reading (m->pPeer is "master" so locked
771 * first) */
772 AutoReadLock rl(m->pPeer COMMA_LOCKVAL_SRC_POS);
773 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
774
775 if (m->bd.isShared())
776 {
777 if (!m->bd.isBackedUp())
778 m->bd.backup();
779
780 m->bd.commit();
781 }
782
783 unconst(m->pPeer) = NULL;
784}
785
786Machine* StorageController::i_getMachine()
787{
788 return m->pParent;
789}
790
791ComObjPtr<StorageController> StorageController::i_getPeer()
792{
793 return m->pPeer;
794}
795
796// private methods
797/////////////////////////////////////////////////////////////////////////////
798
799
800/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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