PDMNetShaper.cpp revision 1e80130a8de15c1a537ab0ffcf8999e986217a1a
/* $Id$ */
/** @file
* PDM Network Shaper - Limit network traffic according to bandwidth
* group settings.
*/
/*
* Copyright (C) 2011-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_NET_SHAPER
#include "PDMInternal.h"
#ifdef VBOX_WITH_REM
#endif
#include <iprt/critsect.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Network shaper data. One instance per VM.
*/
typedef struct PDMNETSHAPER
{
/** Pointer to the VM. */
/** Critical section protecting all members below. */
/** Pending TX thread. */
/** Pointer to the first bandwidth group. */
} PDMNETSHAPER;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
{
if (RT_VALID_PTR(pcszId))
{
while ( pBwGroup
}
return pBwGroup;
}
{
}
#if 0
{
else
{
while ( pPrev
}
}
#endif
{
LogFlowFunc(("New rate limit is %llu bytes per second, adjusted bucket size to %d bytes\n",
}
static int pdmNsBwGroupCreate(PPDMNETSHAPER pShaper, const char *pcszBwGroup, uint64_t cbTransferPerSecMax)
{
LogFlowFunc(("pShaper=%#p pcszBwGroup=%#p{%s} cbTransferPerSecMax=%llu\n",
int rc;
if (!pBwGroup)
{
MM_TAG_PDM_NET_SHAPER, (void **)&pBwGroup);
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
{
;
LogFlowFunc(("pcszBwGroup={%s} cbBucketSize=%u\n",
return VINF_SUCCESS;
}
}
}
else
rc = VERR_NO_MEMORY;
}
else
return rc;
}
{
}
{
}
{
}
{
/*
* We don't need to hold the bandwidth group lock to iterate over the list
* of filters since the filters are removed while the shaper lock is being
* held.
*/
//int rc = RTCritSectEnter(&pBwGroup->cs); AssertRC(rc);
/* Check if the group is disabled. */
if (pBwGroup->cbTransferPerSecMax == 0)
return;
while (pFilter)
{
{
}
}
//rc = RTCritSectLeave(&pBwGroup->cs); AssertRC(rc);
}
{
}
{
/*
* We need to make sure we hold the shaper lock since pdmNsBwGroupXmitPending()
* does not hold the bandwidth group lock while iterating over the list
* of group's filters.
*/
else
{
while ( pPrev
}
}
{
if (RT_SUCCESS(rc))
{
if (pcszBwGroup)
{
if (pBwGroupNew)
else
rc = VERR_NOT_FOUND;
}
if (RT_SUCCESS(rc))
{
if (pBwGroupOld)
}
}
return rc;
}
{
if (RT_SUCCESS(rc))
{
if (pBwGroup)
}
return rc;
}
{
}
VMMR3DECL(int) PDMR3NsBwGroupSetLimit(PVM pVM, const char *pcszBwGroup, uint64_t cbTransferPerSecMax)
{
if (RT_SUCCESS(rc))
{
if (pBwGroup)
{
/* Drop extra tokens */
}
}
return rc;
}
/**
* I/O thread for pending TX.
*
* @returns VINF_SUCCESS (ignored).
* @param pVM Pointer to the VM.
* @param pThread The PDM thread data.
*/
{
{
while (pBwGroup)
{
}
}
return VINF_SUCCESS;
}
/**
* @copydoc FNPDMTHREADWAKEUPINT
*/
{
/* Nothing to do */
return VINF_SUCCESS;
}
/**
* Terminate the network shaper.
*
* @returns VBox error code.
* @param pVM Pointer to VM.
*
* @remarks This method destroys all bandwidth group objects.
*/
{
/* Destroy the bandwidth managers. */
while (pBwGroup)
{
}
return VINF_SUCCESS;
}
/**
* Initialize the network shaper.
*
* @returns VBox status code
* @param pVM Pointer to the VM.
*/
{
sizeof(PDMNETSHAPER),
(void **)&pNetShaper);
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/* Create all bandwidth groups. */
if (pCfgBwGrp)
{
{
if (!pszBwGrpId)
{
rc = VERR_NO_MEMORY;
break;
}
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
break;
}
}
if (RT_SUCCESS(rc))
{
("Network shaper was already initialized\n"));
char szDesc[256];
static unsigned iThread;
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
}
}
return rc;
}