VirtualBox

Changeset 46613 in vbox for trunk/src/VBox/Storage


Ignore:
Timestamp:
Jun 18, 2013 10:27:13 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86497
Message:

Storage: Propagate errors when closing a file but free everything nevertheless (see @bugref{6791})

Location:
trunk/src/VBox/Storage
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/DMG.cpp

    r44529 r46613  
    741741                dmgFlushImage(pThis);
    742742
    743             vdIfIoIntFileClose(pThis->pIfIo, pThis->pStorage);
     743            rc = vdIfIoIntFileClose(pThis->pIfIo, pThis->pStorage);
    744744            pThis->pStorage = NULL;
    745745        }
     
    14961496                 pszFilename, pVDIfsDisk, pVDIfsImage, penmType));
    14971497    int rc;
    1498     PVDIOSTORAGE pStorage;
     1498    PVDIOSTORAGE pStorage = NULL;
    14991499    uint64_t cbFile, offFtr = 0;
    15001500    DMGUDIF Ftr;
     
    15181518    }
    15191519    else
    1520     {
    1521         vdIfIoIntFileClose(pIfIo, pStorage);
    15221520        rc = VERR_VD_DMG_INVALID_HEADER;
    1523     }
    15241521
    15251522    if (RT_SUCCESS(rc))
     
    15481545    }
    15491546
    1550     vdIfIoIntFileClose(pIfIo, pStorage);
     1547    if (pStorage)
     1548        vdIfIoIntFileClose(pIfIo, pStorage);
    15511549
    15521550    LogFlowFunc(("returns %Rrc\n", rc));
  • trunk/src/VBox/Storage/Parallels.cpp

    r46170 r46613  
    158158                parallelsFlushImage(pImage);
    159159
    160             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     160            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    161161            pImage->pStorage = NULL;
    162162        }
  • trunk/src/VBox/Storage/QCOW.cpp

    r44940 r46613  
    996996                qcowFlushImage(pImage);
    997997
    998             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     998            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    999999            pImage->pStorage = NULL;
    10001000        }
  • trunk/src/VBox/Storage/QED.cpp

    r44940 r46613  
    11421142                qedFlushImage(pImage);
    11431143
    1144             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     1144            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    11451145            pImage->pStorage = NULL;
    11461146        }
  • trunk/src/VBox/Storage/RAW.cpp

    r44528 r46613  
    160160            }
    161161
    162             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     162            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    163163            pImage->pStorage = NULL;
    164164        }
  • trunk/src/VBox/Storage/VD.cpp

    r46112 r46613  
    21222122            /* Read the source data. */
    21232123            rc = pImageFrom->Backend->pfnRead(pImageFrom->pBackendData,
    2124                                                    uOffset, cbThisRead, &IoCtx,
    2125                                                    &cbThisRead);
     2124                                              uOffset, cbThisRead, &IoCtx,
     2125                                              &cbThisRead);
    21262126
    21272127            if (   rc == VERR_VD_BLOCK_FREE
     
    39443944static int vdIOIntClose(void *pvUser, PVDIOSTORAGE pIoStorage)
    39453945{
    3946     PVDIO pVDIo             = (PVDIO)pvUser;
    3947 
    3948     int rc = pVDIo->pInterfaceIo->pfnClose(pVDIo->pInterfaceIo->Core.pvUser,
    3949                                            pIoStorage->pStorage);
    3950     AssertRC(rc);
    3951 
     3946    int rc = VINF_SUCCESS;
     3947    PVDIO pVDIo = (PVDIO)pvUser;
     3948
     3949    /* We free everything here, even if closing the file failed for some reason. */
     3950    rc = pVDIo->pInterfaceIo->pfnClose(pVDIo->pInterfaceIo->Core.pvUser, pIoStorage->pStorage);
    39523951    RTAvlrFileOffsetDestroy(pIoStorage->pTreeMetaXfers, vdIOIntTreeMetaXferDestroy, NULL);
    39533952    RTMemFree(pIoStorage->pTreeMetaXfers);
    39543953    RTMemFree(pIoStorage);
    3955     return VINF_SUCCESS;
     3954    return rc;
    39563955}
    39573956
     
    46904689    PVDINTERFACEIO pInterfaceIo = (PVDINTERFACEIO)pvUser;
    46914690    int rc = pInterfaceIo->pfnClose(NULL, pIoStorage->pStorage);
    4692     AssertRC(rc);
    46934691
    46944692    RTMemFree(pIoStorage);
    4695     return VINF_SUCCESS;
     4693    return rc;
    46964694}
    46974695
     
    67636761
    67646762                rc = pImageTo->Backend->pfnRead(pImageTo->pBackendData,
    6765                                                      uOffset, cbThisRead,
    6766                                                      &IoCtx, &cbThisRead);
     6763                                                uOffset, cbThisRead,
     6764                                                &IoCtx, &cbThisRead);
    67676765                if (rc == VERR_VD_BLOCK_FREE)
    67686766                {
     
    67766774                    {
    67776775                        rc = pCurrImage->Backend->pfnRead(pCurrImage->pBackendData,
    6778                                                                uOffset, cbThisRead,
    6779                                                                &IoCtx, &cbThisRead);
     6776                                                          uOffset, cbThisRead,
     6777                                                          &IoCtx, &cbThisRead);
    67806778                    }
    67816779
  • trunk/src/VBox/Storage/VDI.cpp

    r46612 r46613  
    225225                vdiFlushImage(pImage);
    226226
    227             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     227            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    228228            pImage->pStorage = NULL;
    229229        }
     
    15061506
    15071507    /* Close the image. */
    1508     vdiFreeImage(pImage, false);
    1509 
    1510     /* Rename the file. */
    1511     rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
    1512     if (RT_FAILURE(rc))
    1513     {
    1514         /* The move failed, try to reopen the original image. */
    1515         int rc2 = vdiOpenImage(pImage, pImage->uOpenFlags);
    1516         if (RT_FAILURE(rc2))
    1517             rc = rc2;
    1518 
    1519         goto out;
    1520     }
    1521 
    1522     /* Update pImage with the new information. */
    1523     pImage->pszFilename = pszFilename;
    1524 
    1525     /* Open the new image. */
    1526     rc = vdiOpenImage(pImage, pImage->uOpenFlags);
    1527     if (RT_FAILURE(rc))
    1528         goto out;
     1508    rc = vdiFreeImage(pImage, false);
     1509    if (RT_SUCCESS(rc))
     1510    {
     1511        /* Rename the file. */
     1512        rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
     1513        if (RT_FAILURE(rc))
     1514        {
     1515            /* The move failed, try to reopen the original image. */
     1516            int rc2 = vdiOpenImage(pImage, pImage->uOpenFlags);
     1517            if (RT_FAILURE(rc2))
     1518                rc = rc2;
     1519
     1520            goto out;
     1521        }
     1522
     1523        /* Update pImage with the new information. */
     1524        pImage->pszFilename = pszFilename;
     1525
     1526        /* Open the new image. */
     1527        rc = vdiOpenImage(pImage, pImage->uOpenFlags);
     1528        if (RT_FAILURE(rc))
     1529            goto out;
     1530    }
    15291531
    15301532out:
     
    31653167
    31663168    if (pStorage)
    3167         vdIfIoIntFileClose(pIfIo, pStorage);
     3169    {
     3170        int rc2 = vdIfIoIntFileClose(pIfIo, pStorage);
     3171        if (RT_SUCCESS(rc))
     3172            rc = rc2; /* Propagate error code only if repairing was successful. */
     3173    }
    31683174
    31693175    LogFlowFunc(("returns %Rrc\n", rc));
  • trunk/src/VBox/Storage/VHD.cpp

    r44786 r46613  
    560560                vhdFlushImage(pImage);
    561561
    562             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     562            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    563563            pImage->pStorage = NULL;
    564564        }
     
    581581
    582582        if (fDelete && pImage->pszFilename)
    583             rc = vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename);
     583            vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename);
    584584    }
    585585
     
    31603160
    31613161    if (pStorage)
    3162         vdIfIoIntFileClose(pIfIo, pStorage);
     3162    {
     3163        int rc2 = vdIfIoIntFileClose(pIfIo, pStorage);
     3164        if (RT_SUCCESS(rc))
     3165            rc = rc2; /* Propagate status code only when repairing the image was successful. */
     3166    }
    31633167
    31643168    LogFlowFunc(("returns %Rrc\n", rc));
  • trunk/src/VBox/Storage/VHDX.cpp

    r46029 r46613  
    971971        if (pImage->pStorage)
    972972        {
    973             vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
     973            rc = vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage);
    974974            pImage->pStorage = NULL;
    975975        }
  • trunk/src/VBox/Storage/VMDK.cpp

    r44528 r46613  
    524524
    525525static void vmdkFreeStreamBuffers(PVMDKEXTENT pExtent);
    526 static void vmdkFreeExtentData(PVMDKIMAGE pImage, PVMDKEXTENT pExtent,
    527                                bool fDelete);
     526static int vmdkFreeExtentData(PVMDKIMAGE pImage, PVMDKEXTENT pExtent,
     527                              bool fDelete);
    528528
    529529static int vmdkCreateExtents(PVMDKIMAGE pImage, unsigned cExtents);
     
    28622862 * Internal: free the memory used by the extent data structure, optionally
    28632863 * deleting the referenced files.
     2864 *
     2865 * @returns VBox status code.
     2866 * @param   pImage    Pointer to the image instance data.
     2867 * @param   pExtent   The extent to free.
     2868 * @param   fDelete   Flag whether to delete the backing storage.
    28642869 */
    2865 static void vmdkFreeExtentData(PVMDKIMAGE pImage, PVMDKEXTENT pExtent,
    2866                                bool fDelete)
    2867 {
     2870static int vmdkFreeExtentData(PVMDKIMAGE pImage, PVMDKEXTENT pExtent,
     2871                              bool fDelete)
     2872{
     2873    int rc = VINF_SUCCESS;
     2874
    28682875    vmdkFreeGrainDirectory(pExtent);
    28692876    if (pExtent->pDescData)
     
    28752882    {
    28762883        /* Do not delete raw extents, these have full and base names equal. */
    2877         vmdkFileClose(pImage, &pExtent->pFile,
    2878                          fDelete
    2879                       && pExtent->pszFullname
    2880                       && strcmp(pExtent->pszFullname, pExtent->pszBasename));
     2884        rc =vmdkFileClose(pImage, &pExtent->pFile,
     2885                             fDelete
     2886                          && pExtent->pszFullname
     2887                          && strcmp(pExtent->pszFullname, pExtent->pszBasename));
    28812888    }
    28822889    if (pExtent->pszBasename)
     
    28912898    }
    28922899    vmdkFreeStreamBuffers(pExtent);
     2900
     2901    return rc;
    28932902}
    28942903
     
    43214330        {
    43224331            for (unsigned i = 0 ; i < pImage->cExtents; i++)
    4323                 vmdkFreeExtentData(pImage, &pImage->pExtents[i], fDelete);
     4332            {
     4333                int rc2 = vmdkFreeExtentData(pImage, &pImage->pExtents[i], fDelete);
     4334                if (RT_SUCCESS(rc))
     4335                    rc = rc2; /* Propogate any error when closing the file. */
     4336            }
    43244337            RTMemFree(pImage->pExtents);
    43254338            pImage->pExtents = NULL;
     
    43274340        pImage->cExtents = 0;
    43284341        if (pImage->pFile != NULL)
    4329             vmdkFileClose(pImage, &pImage->pFile, fDelete);
    4330         vmdkFileCheckAllClose(pImage);
     4342        {
     4343            int rc2 = vmdkFileClose(pImage, &pImage->pFile, fDelete);
     4344            if (RT_SUCCESS(rc))
     4345                rc = rc2; /* Propogate any error when closing the file. */
     4346        }
     4347        int rc2 = vmdkFileCheckAllClose(pImage);
     4348        if (RT_SUCCESS(rc))
     4349            rc = rc2; /* Propogate any error when closing the file. */
    43314350
    43324351        if (pImage->pGTCache)
     
    55175536            goto rollback;
    55185537        /* Close the extent file. */
    5519         vmdkFileClose(pImage, &pExtent->pFile, false);
     5538        rc = vmdkFileClose(pImage, &pExtent->pFile, false);
     5539        if (RT_FAILURE(rc))
     5540            goto rollback;
     5541
    55205542        /* Rename the extent file. */
    55215543        rc = vdIfIoIntFileMove(pImage->pIfIo, pExtent->pszFullname, apszNewName[i], 0);
     
    55265548    }
    55275549    /* Release all old stuff. */
    5528     vmdkFreeImage(pImage, false);
     5550    rc = vmdkFreeImage(pImage, false);
     5551    if (RT_FAILURE(rc))
     5552        goto rollback;
    55295553
    55305554    fImageFreed = true;
Note: See TracChangeset for help on using the changeset viewer.

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