- Timestamp:
- May 20, 2015 4:52:25 PM (10 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r55923 r55977 519 519 RTStrmPrintf(pStrm, 520 520 "%s snapshot %s <uuid|vmname>\n" 521 " take <name> [--description <desc>] [--live] |\n" 521 " take <name> [--description <desc>] [--live]\n" 522 " [--uniquename Number,Timestamp,Space,Force] |\n" 522 523 " delete <uuid|snapname> |\n" 523 524 " restore <uuid|snapname> |\n" -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageSnapshot.cpp
r55234 r55977 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 29 29 #include <iprt/stream.h> 30 30 #include <iprt/getopt.h> 31 #include <iprt/time.h> 31 32 32 33 #include "VBoxManage.h" … … 260 261 } 261 262 263 typedef enum SnapshotUniqueFlags 264 { 265 SnapshotUniqueFlags_Null = 0, 266 SnapshotUniqueFlags_Number = RT_BIT(1), 267 SnapshotUniqueFlags_Timestamp = RT_BIT(2), 268 SnapshotUniqueFlags_Space = RT_BIT(16), 269 SnapshotUniqueFlags_Force = RT_BIT(30) 270 } SnapshotUniqueFlags; 271 272 static int parseSnapshotUniqueFlags(const char *psz, SnapshotUniqueFlags *pUnique) 273 { 274 int rc = VINF_SUCCESS; 275 unsigned uUnique = 0; 276 while (psz && *psz && RT_SUCCESS(rc)) 277 { 278 size_t len; 279 const char *pszComma = strchr(psz, ','); 280 if (pszComma) 281 len = pszComma - psz; 282 else 283 len = strlen(psz); 284 if (len > 0) 285 { 286 if (!RTStrNICmp(psz, "number", len)) 287 uUnique |= SnapshotUniqueFlags_Number; 288 else if (!RTStrNICmp(psz, "timestamp", len)) 289 uUnique |= SnapshotUniqueFlags_Timestamp; 290 else if (!RTStrNICmp(psz, "space", len)) 291 uUnique |= SnapshotUniqueFlags_Space; 292 else if (!RTStrNICmp(psz, "force", len)) 293 uUnique |= SnapshotUniqueFlags_Force; 294 else 295 rc = VERR_PARSE_ERROR; 296 } 297 if (pszComma) 298 psz += len + 1; 299 else 300 psz += len; 301 } 302 303 if (RT_SUCCESS(rc)) 304 *pUnique = (SnapshotUniqueFlags)uUnique; 305 return rc; 306 } 307 262 308 /** 263 309 * Implementation for all VBoxManage snapshot ... subcommands. … … 308 354 Bstr desc; 309 355 bool fPause = true; /* default is NO live snapshot */ 356 SnapshotUniqueFlags enmUnique = SnapshotUniqueFlags_Null; 310 357 static const RTGETOPTDEF s_aTakeOptions[] = 311 358 { … … 314 361 { "-desc", 'd', RTGETOPT_REQ_STRING }, 315 362 { "--pause", 'p', RTGETOPT_REQ_NOTHING }, 316 { "--live", 'l', RTGETOPT_REQ_NOTHING } 363 { "--live", 'l', RTGETOPT_REQ_NOTHING }, 364 { "--uniquename", 'u', RTGETOPT_REQ_STRING } 317 365 }; 318 366 RTGETOPTSTATE GetOptState; … … 321 369 int ch; 322 370 RTGETOPTUNION Value; 371 int vrc; 323 372 while ( SUCCEEDED(rc) 324 373 && (ch = RTGetOpt(&GetOptState, &Value))) … … 338 387 break; 339 388 389 case 'u': 390 vrc = parseSnapshotUniqueFlags(Value.psz, &enmUnique); 391 if (RT_FAILURE(vrc)) 392 return errorArgument("Invalid unique name description '%s'", Value.psz); 393 break; 394 340 395 default: 341 396 errorGetOpt(USAGE_SNAPSHOT, ch, &Value); … … 347 402 break; 348 403 404 if (enmUnique & (SnapshotUniqueFlags_Number | SnapshotUniqueFlags_Timestamp)) 405 { 406 ComPtr<ISnapshot> pSnapshot; 407 rc = sessionMachine->FindSnapshot(name.raw(), 408 pSnapshot.asOutParam()); 409 if (SUCCEEDED(rc) || (enmUnique & SnapshotUniqueFlags_Force)) 410 { 411 /* there is a duplicate, need to create a unique name */ 412 uint32_t count = 0; 413 RTTIMESPEC now; 414 415 if (enmUnique & SnapshotUniqueFlags_Number) 416 { 417 if (enmUnique & SnapshotUniqueFlags_Force) 418 count = 1; 419 else 420 count = 2; 421 } 422 else 423 RTTimeNow(&now); 424 425 while (count < 500) 426 { 427 Utf8Str suffix; 428 if (enmUnique & SnapshotUniqueFlags_Number) 429 suffix = Utf8StrFmt("%u", count); 430 else 431 { 432 RTTIMESPEC nowplus = now; 433 RTTimeSpecAddSeconds(&nowplus, count); 434 RTTIME stamp; 435 RTTimeExplode(&stamp, &nowplus); 436 suffix = Utf8StrFmt("%04u-%02u-%02uT%02u:%02u:%02uZ", stamp.i32Year, stamp.u8Month, stamp.u8MonthDay, stamp.u8Hour, stamp.u8Minute, stamp.u8Second); 437 } 438 Bstr tryName = name; 439 if (enmUnique & SnapshotUniqueFlags_Space) 440 tryName = BstrFmt("%ls %s", name.raw(), suffix.c_str()); 441 else 442 tryName = BstrFmt("%ls%s", name.raw(), suffix.c_str()); 443 count++; 444 rc = sessionMachine->FindSnapshot(tryName.raw(), 445 pSnapshot.asOutParam()); 446 if (FAILED(rc)) 447 { 448 name = tryName; 449 break; 450 } 451 } 452 if (SUCCEEDED(rc)) 453 { 454 errorArgument("Failed to generate a unique snapshot name"); 455 rc = E_FAIL; 456 break; 457 } 458 } 459 rc = S_OK; 460 } 461 349 462 ComPtr<IProgress> progress; 463 Bstr snapId; 350 464 CHECK_ERROR_BREAK(sessionMachine, TakeSnapshot(name.raw(), desc.raw(), 351 fPause, 465 fPause, snapId.asOutParam(), 352 466 progress.asOutParam())); 353 467 354 468 rc = showProgress(progress); 355 CHECK_PROGRESS_ERROR(progress, ("Failed to take snapshot")); 469 if (SUCCEEDED(rc)) 470 RTPrintf("Snapshot taken. UUID: %ls\n", snapId.raw()); 471 else 472 CHECK_PROGRESS_ERROR(progress, ("Failed to take snapshot")); 356 473 } 357 474 else if ( (fDelete = !strcmp(a->argv[1], "delete")) … … 389 506 // restore or delete snapshot: then resolve cmd line argument to snapshot instance 390 507 CHECK_ERROR_BREAK(sessionMachine, FindSnapshot(Bstr(a->argv[2]).raw(), 391 pSnapshot.asOutParam()));508 pSnapshot.asOutParam())); 392 509 } 393 510 … … 397 514 { 398 515 CHECK_ERROR_BREAK(sessionMachine, DeleteSnapshot(bstrSnapGuid.raw(), 399 pProgress.asOutParam()));516 pProgress.asOutParam())); 400 517 } 401 518 else … … 428 545 { 429 546 CHECK_ERROR_BREAK(sessionMachine, FindSnapshot(Bstr(a->argv[2]).raw(), 430 pSnapshot.asOutParam()));547 pSnapshot.asOutParam())); 431 548 } 432 549 -
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r55800 r55977 4958 4958 gpProgress = NULL; 4959 4959 HRESULT rc; 4960 Bstr snapId; 4960 4961 CHECK_ERROR(gpMachine, TakeSnapshot(Bstr(pszSnapshotName).raw(), 4961 4962 Bstr("Taken by VBoxSDL").raw(), 4962 TRUE,4963 TRUE, snapId.asOutParam(), 4963 4964 gpProgress.asOutParam())); 4964 4965 if (FAILED(rc)) -
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r55214 r55977 2635 2635 else: 2636 2636 desc = "" 2637 cmdAnyVm(ctx, mach, lambda ctx, mach, console, args: progressBar(ctx, mach.takeSnapshot(name, desc, true) ))2637 cmdAnyVm(ctx, mach, lambda ctx, mach, console, args: progressBar(ctx, mach.takeSnapshot(name, desc, true)[-1])) 2638 2638 return 0 2639 2639 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
r55750 r55977 5 5 6 6 /* 7 * Copyright (C) 2010-201 4Oracle Corporation7 * Copyright (C) 2010-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 1424 1424 if (fDialogAccepted) 1425 1425 { 1426 QString strSnapshotId; 1426 1427 /* Prepare the take-snapshot progress: */ 1427 CProgress progress = machine().TakeSnapshot(strSnapshotName, strSnapshotDescription, true );1428 CProgress progress = machine().TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotId); 1428 1429 if (machine().isOk()) 1429 1430 { -
trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp
r55934 r55977 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 889 889 if (fDialogAccepted) 890 890 { 891 QString strSnapshotId; 891 892 /* Prepare the take-snapshot progress: */ 892 CProgress progress = machine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true );893 CProgress progress = machine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotId); 893 894 if (machine.isOk()) 894 895 { -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVM.cpp
r55214 r55977 5 5 6 6 /* 7 * Copyright (C) 2011-201 4Oracle Corporation7 * Copyright (C) 2011-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 84 84 /* Take the snapshot: */ 85 85 QString strSnapshotName = tr("Linked Base for %1 and %2").arg(m_machine.GetName()).arg(strName); 86 CProgress progress = machine.TakeSnapshot(strSnapshotName, "", true); 86 QString strSnapshotId; 87 CProgress progress = machine.TakeSnapshot(strSnapshotName, "", true, strSnapshotId); 87 88 88 89 if (machine.isOk()) … … 107 108 108 109 /* Get the new snapshot and the snapshot machine. */ 109 const CSnapshot &newSnapshot = m_machine.FindSnapshot(strSnapshot Name);110 const CSnapshot &newSnapshot = m_machine.FindSnapshot(strSnapshotId); 110 111 if (newSnapshot.isNull()) 111 112 { -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r55885 r55977 4170 4170 <interface 4171 4171 name="IMachine" extends="$unknown" 4172 uuid=" feb138aa-dbce-4a89-8ec0-380fc7ec4913"4172 uuid="520a0c22-8dbc-458d-b637-31eb078b5526" 4173 4173 wsmap="managed" 4174 4174 wrap-hint-server-addinterfaces="IInternalMachineControl" … … 7392 7392 (@c true) and live (@c false) snapshots. When the VM is not running 7393 7393 the result is always an offline snapshot.</desc> 7394 </param> 7395 <param name="id" type="uuid" mod="string" dir="out"> 7396 <desc>UUID of the snapshot which will be created. Useful for follow-up 7397 operations after the snapshot has been created.</desc> 7394 7398 </param> 7395 7399 <param name="progress" type="IProgress" dir="return"> -
trunk/src/VBox/Main/include/MachineImpl.h
r55854 r55977 1193 1193 const com::Utf8Str &aDescription, 1194 1194 BOOL aPause, 1195 com::Guid &aId, 1195 1196 ComPtr<IProgress> &aProgress); 1196 1197 HRESULT deleteSnapshot(const com::Guid &aId, … … 1439 1440 const com::Utf8Str &aDescription, 1440 1441 BOOL aPause, 1442 com::Guid &aId, 1441 1443 ComPtr<IProgress> &aProgress); 1442 1444 HRESULT deleteSnapshot(const com::Guid &aId, -
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r55749 r55977 1332 1332 const Utf8Str &strName, 1333 1333 const Utf8Str &strDescription, 1334 const Guid &uuidSnapshot, 1334 1335 bool fPause, 1335 1336 uint32_t uMemSize, … … 1338 1339 m_strName(strName), 1339 1340 m_strDescription(strDescription), 1341 m_uuidSnapshot(uuidSnapshot), 1340 1342 m_fPause(fPause), 1341 1343 m_uMemSize(uMemSize), … … 1357 1359 Utf8Str m_strName; 1358 1360 Utf8Str m_strDescription; 1361 Guid m_uuidSnapshot; 1359 1362 Utf8Str m_strStateFilePath; 1360 1363 ComPtr<IInternalSessionControl> m_pDirectControl; … … 1412 1415 const com::Utf8Str &aDescription, 1413 1416 BOOL fPause, 1417 com::Guid &aId, 1414 1418 ComPtr<IProgress> &aProgress) 1415 1419 { … … 1417 1421 NOREF(aDescription); 1418 1422 NOREF(fPause); 1423 NOREF(aId); 1419 1424 NOREF(aProgress); 1420 1425 ReturnComNotImplemented(); … … 1424 1429 const com::Utf8Str &aDescription, 1425 1430 BOOL fPause, 1431 com::Guid &aId, 1426 1432 ComPtr<IProgress> &aProgress) 1427 1433 { … … 1482 1488 return rc; 1483 1489 1490 /* create an ID for the snapshot */ 1491 Guid snapshotId; 1492 snapshotId.create(); 1493 1484 1494 /* create and start the task on a separate thread (note that it will not 1485 1495 * start working until we release alock) */ … … 1490 1500 aName, 1491 1501 aDescription, 1502 snapshotId, 1492 1503 !!fPause, 1493 1504 mHWData->mMemorySize, … … 1509 1520 i_setMachineState(MachineState_Snapshotting); 1510 1521 1522 aId = snapshotId; 1511 1523 pTask->m_pProgress.queryInterfaceTo(aProgress.asOutParam()); 1512 1524 … … 1555 1567 bool fBeganTakingSnapshot = false; 1556 1568 BOOL fSuspendedBySave = FALSE; 1557 Guid snapshotId;1558 1569 1559 1570 try … … 1606 1617 /* STEP 1: create the snapshot object */ 1607 1618 1608 /* create an ID for the snapshot */1609 snapshotId.create();1610 1611 1619 /* create a snapshot machine object */ 1612 1620 ComObjPtr<SnapshotMachine> pSnapshotMachine; 1613 1621 pSnapshotMachine.createObject(); 1614 rc = pSnapshotMachine->init(this, snapshotId.ref(), task.m_strStateFilePath);1622 rc = pSnapshotMachine->init(this, task.m_uuidSnapshot.ref(), task.m_strStateFilePath); 1615 1623 AssertComRCThrowRC(rc); 1616 1624 … … 1620 1628 task.m_pSnapshot.createObject(); 1621 1629 rc = task.m_pSnapshot->init(mParent, 1622 snapshotId,1630 task.m_uuidSnapshot, 1623 1631 task.m_strName, 1624 1632 task.m_strDescription, … … 1797 1805 1798 1806 if (SUCCEEDED(rc)) 1799 mParent->i_onSnapshotTaken(mData->mUuid, snapshotId);1807 mParent->i_onSnapshotTaken(mData->mUuid, task.m_uuidSnapshot); 1800 1808 LogFlowThisFuncLeave(); 1801 1809 } -
trunk/src/VBox/ValidationKit/testdriver/vboxwrappers.py
r55760 r55977 2250 2250 self.o.console.pause(); 2251 2251 if self.fpApiVer >= 5.0: 2252 oProgressCom= self.o.machine.takeSnapshot(sName, sDescription, True);2252 (sSnapId, oProgressCom) = self.o.machine.takeSnapshot(sName, sDescription, True); 2253 2253 else: 2254 2254 oProgressCom = self.o.console.takeSnapshot(sName, sDescription);
Note:
See TracChangeset
for help on using the changeset viewer.