VirtualBox

Changeset 15529 in vbox


Ignore:
Timestamp:
Dec 15, 2008 6:23:42 PM (16 years ago)
Author:
vboxsync
Message:

Storage/VBoxHDD-new: implement UUID handling in VDCreate. Remove very broken code for handling move/shrink/grow, it would have done more harm than good. Lucky that these cases aren't used yet.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxHDD-new.h

    r15366 r15529  
    12571257 * @param   fMoveByRename   If true, attempt to perform a move by renaming (if successful the new size is ignored).
    12581258 * @param   cbSize          New image size (0 means leave unchanged).
     1259 * @param   pDstUuid        New UUID of the destination image. If NULL, a new UUID is created.
     1260 *                          This parameter is used if and only if a true copy is created.
     1261 *                          In all rename/move cases the UUIDs are copied over.
    12591262 * @param   pVDIfsOperation Pointer to the per-operation VD interface list.
    12601263 * @param   pDstVDIfsImage  Pointer to the per-image VD interface list, for the
     
    12651268VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
    12661269                         const char *pszBackend, const char *pszFilename,
    1267                          bool fMoveByRename, uint64_t cbSize,
     1270                         bool fMoveByRename, uint64_t cbSize, PRTUUID pDstUuid,
    12681271                         PVDINTERFACE pVDIfsOperation,
    12691272                         PVDINTERFACE pDstVDIfsImage,
  • trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp

    r15366 r15529  
    18651865 * @param   fMoveByRename   If true, attempt to perform a move by renaming (if successful the new size is ignored).
    18661866 * @param   cbSize          New image size (0 means leave unchanged).
     1867 * @param   pDstUuid        New UUID of the destination image. If NULL, a new UUID is created.
     1868 *                          This parameter is used if and only if a true copy is created.
     1869 *                          In all rename/move cases the UUIDs are copied over.
    18671870 * @param   pVDIfsOperation Pointer to the per-operation VD interface list.
    18681871 * @param   pDstVDIfsImage  Pointer to the per-image VD interface list, for the
     
    18731876VBOXDDU_DECL(int) VDCopy(PVBOXHDD pDiskFrom, unsigned nImage, PVBOXHDD pDiskTo,
    18741877                         const char *pszBackend, const char *pszFilename,
    1875                          bool fMoveByRename, uint64_t cbSize,
     1878                         bool fMoveByRename, uint64_t cbSize, PRTUUID pDstUuid,
    18761879                         PVDINTERFACE pVDIfsOperation,
    18771880                         PVDINTERFACE pDstVDIfsImage,
     
    19111914                  ("u32Signature=%08x\n", pDiskTo->u32Signature));
    19121915
    1913         /* If the containers are equal and the backend is the same, rename the image. */
    1914         if (   (pDiskFrom == pDiskTo)
    1915             && (!RTStrICmp(pszBackend, pImageFrom->Backend->pszBackendName)))
    1916         {
    1917             /* Rename the image. */
    1918             rc = pImageFrom->Backend->pfnRename(pImageFrom->pvBackendData, pszFilename ? pszFilename : pImageFrom->pszFilename);
    1919             break;
    1920         }
    1921 
    1922         /* If the fMoveByRename flag is set and the backend is the same, rename the image. */
    1923         if (   (fMoveByRename == true)
    1924             && (!RTStrICmp(pszBackend, pImageFrom->Backend->pszBackendName)))
    1925         {
    1926             /* Close the source image. */
    1927             rc = pImageFrom->Backend->pfnClose(pImageFrom->pvBackendData, false);
    1928             if (RT_FAILURE(rc))
     1916        /* Move the image. */
     1917        if (pDiskFrom == pDiskTo)
     1918        {
     1919            /* Rename only works when backends are the same. */
     1920            if (    fMoveByRename
     1921                &&  !RTStrICmp(pszBackend, pImageFrom->Backend->pszBackendName))
     1922            {
     1923                rc = pImageFrom->Backend->pfnRename(pImageFrom->pvBackendData, pszFilename ? pszFilename : pImageFrom->pszFilename);
    19291924                break;
    1930 
    1931             /* Open the source image in the destination container. */
    1932             /** @todo fix open flags - the flags in pImageFrom are not the right info, the info from the image format backend is relevant */
    1933             rc = VDOpen(pDiskTo, pImageFrom->Backend->pszBackendName, pImageFrom->pszFilename, pImageFrom->uOpenFlags, pDstVDIfsImage);
    1934             if (RT_FAILURE(rc))
    1935                 goto movefail;
    1936 
    1937             pImageTo = pDiskTo->pLast;
    1938 
    1939             /* Rename the image. */
    1940             rc = pImageTo->Backend->pfnRename(pImageTo->pvBackendData, pszFilename ? pszFilename : pImageTo->pszFilename);
    1941             if (RT_FAILURE(rc))
    1942                 goto movefail;
    1943 
    1944             /* Cleanup the leftovers. */
    1945             vdRemoveImageFromList(pDiskFrom, pImageFrom);
    1946             pImageFrom->pvBackendData = NULL;
    1947 
    1948             if (pImageFrom->pszFilename)
    1949                 RTStrFree(pImageFrom->pszFilename);
    1950 
    1951             RTMemFree(pImageFrom);
    1952 
    1953             break;
    1954 movefail:
    1955             /* In case of failure, re-open the source image in the source container. */
    1956             rc2 = VDOpen(pDiskFrom, pImageFrom->Backend->pszBackendName, pImageFrom->pszFilename, pImageFrom->uOpenFlags, pImageFrom->pVDIfsImage);
    1957             if (RT_FAILURE(rc2))
    1958                 /** @todo Uncertain what to do on error. If this happens pImageFrom and pImageTo are both closed. */
    1959                 rc = rc2;
    1960             break;
    1961         }
    1962 
    1963         /* If fMoveByRename is set pszFilename is allowed to be NULL, so do the parameter check here. */
     1925            }
     1926
     1927            /** @todo Moving (including shrinking/growing) of the image is
     1928             * requested, but the rename attempt failed or it wasn't possible.
     1929             * Must now copy image to temp location. */
     1930            AssertReleaseMsgFailed(("VDCopy: moving by copy/delete not implemented\n"));
     1931        }
     1932
     1933        /* When moving an image pszFilename is allowed to be NULL, so do the parameter check here. */
    19641934        AssertMsgBreakStmt(VALID_PTR(pszFilename) && *pszFilename,
    19651935                           ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
     
    19831953        uImageFlagsFrom = pImageFrom->Backend->pfnGetImageFlags(pImageFrom->pvBackendData);
    19841954
    1985         /** @todo Get this from the source image. */
    19861955        PDMMEDIAGEOMETRY PCHSGeometryFrom = {0, 0, 0};
    19871956        PDMMEDIAGEOMETRY LCHSGeometryFrom = {0, 0, 0};
     1957        pImageFrom->Backend->pfnGetPCHSGeometry(pImageFrom->pvBackendData, &PCHSGeometryFrom);
     1958        pImageFrom->Backend->pfnGetLCHSGeometry(pImageFrom->pvBackendData, &LCHSGeometryFrom);
     1959
     1960        RTUUID ImageUuid, ImageModificationUuid;
     1961        RTUUID ParentUuid, ParentModificationUuid;
     1962        if (pDiskFrom != pDiskTo)
     1963        {
     1964            if (pDstUuid)
     1965                ImageUuid = *pDstUuid;
     1966            else
     1967                RTUuidCreate(&ImageUuid);
     1968        }
     1969        else
     1970        {
     1971            rc = pImageFrom->Backend->pfnGetUuid(pImageFrom->pvBackendData, &ImageUuid);
     1972            if (RT_FAILURE(rc))
     1973                RTUuidClear(&ImageUuid);
     1974        }
     1975        rc = pImageFrom->Backend->pfnGetModificationUuid(pImageFrom->pvBackendData, &ImageModificationUuid);
     1976        if (RT_FAILURE(rc))
     1977            RTUuidClear(&ImageModificationUuid);
     1978        rc = pImageFrom->Backend->pfnGetParentUuid(pImageFrom->pvBackendData, &ParentUuid);
     1979        if (RT_FAILURE(rc))
     1980            RTUuidClear(&ParentUuid);
     1981        rc = pImageFrom->Backend->pfnGetParentModificationUuid(pImageFrom->pvBackendData, &ParentModificationUuid);
     1982        if (RT_FAILURE(rc))
     1983            RTUuidClear(&ParentModificationUuid);
     1984
     1985        char szComment[1024];
     1986        rc = pImageFrom->Backend->pfnGetComment(pImageFrom->pvBackendData, szComment, sizeof(szComment));
     1987        if (RT_FAILURE(rc))
     1988            szComment[0] = '\0';
     1989        else
     1990            szComment[sizeof(szComment) - 1] = '\0';
    19881991
    19891992        unsigned uOpenFlagsFrom;
     
    19911994
    19921995        /* Create destination image with the properties of the source image. */
    1993         /** @todo Copy the comment. */
    19941996        /** @todo replace the VDCreateDiff/VDCreateBase calls by direct
    19951997         * calls to the backend. Unifies the code and reduces the API
     
    19982000        {
    19992001            rc = VDCreateDiff(pDiskTo, pszBackend, pszFilename, uImageFlagsFrom,
    2000                               "", NULL, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
     2002                              szComment, &ImageUuid, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
    20012003        } else {
    20022004            rc = VDCreateBase(pDiskTo, pszBackend, pszFilename, enmTypeFrom,
    2003                               cbSize, uImageFlagsFrom, "",
     2005                              cbSize, uImageFlagsFrom, szComment,
    20042006                              &PCHSGeometryFrom, &LCHSGeometryFrom,
    20052007                              NULL, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
     2008            if (!RTUuidIsNull(&ImageUuid))
     2009                 pImageFrom->Backend->pfnSetUuid(pImageFrom->pvBackendData, &ImageUuid);
    20062010        }
    20072011        if (RT_FAILURE(rc))
     
    20582062        } while (uOffset < cbSize);
    20592063
    2060         /* If fMoveByRename is set but the backend is different, close and delete pImageFrom. */
    2061         if (   (fMoveByRename == true)
    2062             && (RTStrICmp(pszBackend, pImageFrom->Backend->pszBackendName)))
    2063         {
    2064             vdRemoveImageFromList(pDiskFrom, pImageFrom);
    2065 
    2066             /* Close and delete image. */
    2067             rc2 = pImageFrom->Backend->pfnClose(pImageFrom->pvBackendData, true);
    2068             AssertRC(rc2);
    2069             pImageFrom->pvBackendData = NULL;
    2070 
    2071             /* Free remaining resources. */
    2072             if (pImageFrom->pszFilename)
    2073                 RTStrFree(pImageFrom->pszFilename);
    2074 
    2075             RTMemFree(pImageFrom);
     2064        if (RT_SUCCESS(rc))
     2065        {
     2066            pImageFrom->Backend->pfnSetModificationUuid(pImageFrom->pvBackendData, &ImageModificationUuid);
     2067            pImageFrom->Backend->pfnGetParentUuid(pImageFrom->pvBackendData, &ParentUuid);
     2068            pImageFrom->Backend->pfnGetParentModificationUuid(pImageFrom->pvBackendData, &ParentModificationUuid);
    20762069        }
    20772070    } while (0);
  • trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp

    r14855 r15529  
    735735    rc = VDOpen(pVD, "VMDK", src, VD_OPEN_FLAGS_NORMAL, NULL);
    736736    CHECK("VDOpen()");
    737     rc = VDCopy(pVD, 0, pVD, "VMDK", dst, true, 0, NULL, NULL, NULL);
     737    rc = VDCopy(pVD, 0, pVD, "VMDK", dst, true, 0, NULL, NULL, NULL, NULL);
    738738    CHECK("VDCopy()");
    739739
  • trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp

    r15366 r15529  
    13151315        else
    13161316        {
    1317             vrc = VDCopy(pDisk, 0, pDisk, "VMDK", Utf8Str(dst).raw(), true, 0, NULL, NULL, NULL);
     1317            vrc = VDCopy(pDisk, 0, pDisk, "VMDK", Utf8Str(dst).raw(), true, 0, NULL, NULL, NULL, NULL);
    13181318            if (RT_FAILURE(vrc))
    13191319            {
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r15516 r15529  
    469469        /* Create the output image */
    470470        vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, Utf8Str(dstformat).raw(),
    471                      Utf8Str(dst).raw(), false, 0, NULL, NULL, NULL);
     471                     Utf8Str(dst).raw(), false, 0, NULL, NULL, NULL, NULL);
    472472        if (RT_FAILURE(vrc))
    473473        {
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