VirtualBox

Changeset 32001 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Aug 26, 2010 2:13:09 PM (14 years ago)
Author:
vboxsync
Message:

FT updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/FTM.cpp

    r31953 r32001  
    5858    uint32_t    cb;
    5959} FTMTCPHDR;
    60 /** Magic value for TELEPORTERTCPHDR::u32Magic. (Egberto Gismonti Amin) */
     60/** Magic value for FTMTCPHDR::u32Magic. (Egberto Gismonti Amin) */
    6161#define FTMTCPHDR_MAGIC       UINT32_C(0x19471205)
    6262/** The max block size. */
    6363#define FTMTCPHDR_MAX_SIZE    UINT32_C(0x00fffff8)
     64
     65/**
     66 * TCP stream header.
     67 *
     68 * This is an extra layer for fixing the problem with figuring out when the SSM
     69 * stream ends.
     70 */
     71typedef struct FTMTCPHDRMEM
     72{
     73    /** Magic value. */
     74    uint32_t    u32Magic;
     75    /** Size (Uncompressed) of the pages following the header. */
     76    uint32_t    cbPageRange;
     77    /** GC Physical address of the page(s) to sync. */
     78    RTGCPHYS    GCPhys;
     79    /** The size of the data block following this header.
     80     * 0 indicates the end of the stream, while UINT32_MAX indicates
     81     * cancelation. */
     82    uint32_t    cb;
     83} FTMTCPHDRMEM;
    6484
    6585/*******************************************************************************
     
    603623static DECLCALLBACK(int) ftmR3SyncDirtyPage(PVM pVM, RTGCPHYS GCPhys, uint8_t *pRange, unsigned cbRange, void *pvUser)
    604624{
     625    FTMTCPHDRMEM Hdr;
     626    Hdr.u32Magic    = FTMTCPHDR_MAGIC;
     627    Hdr.GCPhys      = GCPhys;
     628    Hdr.cbPageRange = cbRange;
     629    Hdr.cb          = cbRange;
     630    /** @todo compress page(s). */
     631    int rc = RTTcpSgWriteL(pVM->ftm.s.hSocket, 2, &Hdr, sizeof(Hdr), pRange, (size_t)Hdr.cb);
     632    if (RT_FAILURE(rc))
     633    {
     634        LogRel(("FTSync/TCP: Write error (ftmR3SyncDirtyPage): %Rrc (cb=%#x)\n", rc, Hdr.cb));
     635        return rc;
     636    }
    605637    return VINF_SUCCESS;
    606638}
     
    682714            AssertMsg(rc == VINF_SUCCESS, ("%Rrc\n", rc));
    683715
     716            rc = ftmR3TcpSubmitCommand(pVM, "mem-sync");
     717            AssertRC(rc);
     718
    684719            /* sync the changed memory with the standby node. */
    685720            rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)ftmR3PerformSync, 2, pVM, FTMSYNCSTATE_DELTA_MEMORY);
    686721            AssertRC(rc);
    687722
     723            /* Enumerate all dirty pages and send them to the standby VM. */
    688724            rc = PGMR3PhysEnumDirtyFTPages(pVM, ftmR3SyncDirtyPage, NULL /* pvUser */);
     725            AssertRC(rc);
     726
     727            /* Send last memory header to signal the end. */
     728            FTMTCPHDRMEM Hdr;
     729            Hdr.u32Magic    = FTMTCPHDR_MAGIC;
     730            Hdr.GCPhys      = 0;
     731            Hdr.cbPageRange = 0;
     732            Hdr.cb          = 0;
     733            int rc = RTTcpSgWriteL(pVM->ftm.s.hSocket, 1, &Hdr, sizeof(Hdr));
     734            if (RT_FAILURE(rc))
     735                LogRel(("FTSync/TCP: Write error (ftmR3MasterThread): %Rrc (cb=%#x)\n", rc, Hdr.cb));
     736
     737            rc = ftmR3TcpReadACK(pVM, "mem-sync-complete");
    689738            AssertRC(rc);
    690739
     
    771820        if (!strcmp(szCmd, "mem-sync"))
    772821        {
     822            rc = ftmR3TcpWriteACK(pVM);
     823            AssertRC(rc);
     824            if (RT_FAILURE(rc))
     825                continue;
     826
     827            while (true)
     828            {
     829                FTMTCPHDRMEM Hdr;
     830                void *pPage;
     831
     832                /* Read memory header. */
     833                rc = RTTcpRead(pVM->ftm.s.hSocket, &Hdr, sizeof(Hdr), NULL);
     834                if (RT_FAILURE(rc))
     835                {
     836                    Log(("RTTcpRead failed with %Rrc\n", rc));
     837                    break;
     838                }
     839
     840                if (Hdr.cb == 0)
     841                    break;  /* end of sync. */
     842
     843                Assert(Hdr.cb == Hdr.cbPageRange);  /** @todo uncompress */
     844
     845                /* Allocate memory to hold the page(s). */
     846                pPage = RTMemAlloc(Hdr.cbPageRange);
     847                AssertBreak(pPage);
     848
     849                /* Fetch the page(s). */
     850                rc = RTTcpRead(pVM->ftm.s.hSocket, pPage, Hdr.cb, NULL);
     851                if (RT_FAILURE(rc))
     852                {
     853                    Log(("RTTcpRead page data (%d bytes) failed with %Rrc\n", Hdr.cb, rc));
     854                    break;
     855                }
     856
     857                /* Update the guest memory of the standby VM. */
     858                rc = PGMPhysWrite(pVM, Hdr.GCPhys, pPage, Hdr.cbPageRange);
     859                AssertRC(rc);
     860
     861                RTMemFree(pPage);
     862            }
     863
     864            rc = ftmR3TcpWriteACK(pVM);
     865            AssertRC(rc);
    773866        }
    774867        else
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