VirtualBox

Changeset 14780 in vbox


Ignore:
Timestamp:
Nov 28, 2008 2:36:22 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
40098
Message:

VBoxHDD: simplify config handling. Treat everything as a string, and do the conversion in the common code. Makes the job of implementing the VBox API (iSCSI in particular) easier.

Location:
trunk
Files:
4 edited

Legend:

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

    r14526 r14780  
    600600}
    601601
    602 /** Configuration node for configuration information interface. */
    603 typedef struct VDCFGNODE *PVDCFGNODE;
    604 
    605 /**
    606  * Configuration value type for configuration information interface.
    607  */
    608 typedef enum VDCFGVALUETYPE
    609 {
    610     /** Integer value. */
    611     VDCFGVALUETYPE_INTEGER = 1,
    612     /** String value. */
    613     VDCFGVALUETYPE_STRING,
    614     /** Bytestring value. */
    615     VDCFGVALUETYPE_BYTES
    616 } VDCFGVALUETYPE;
    617 /** Pointer to configuration value type for configuration information interface. */
    618 typedef VDCFGVALUETYPE *PVDCFGVALUETYPE;
    619 
    620 /**
    621  * Configuration value. This is not identical to CFGMVALUE.
    622  */
    623 typedef union VDCFGVALUE
    624 {
    625     /** Integer value. */
    626     struct VDCFGVALUE_INTEGER
    627     {
    628         /** The integer represented as 64-bit unsigned. */
    629         uint64_t    u64;
    630     } Integer;
    631 
    632     /** String value. (UTF-8 of course) */
    633     struct VDCFGVALUE_STRING
    634     {
    635         /** Pointer to the string. */
    636         char        *psz;
    637     } String;
    638 
    639     /** Byte string value. */
    640     struct VDCFGVALUE_BYTES
    641     {
    642         /** Length of byte string. (in bytes) */
    643         RTUINT      cb;
    644         /** Pointer to the byte string. */
    645         void        *pv;
    646     } Bytes;
    647 } VDCFGVALUE, *PVDCFGVALUE;
    648602
    649603/**
     
    666620
    667621    /**
    668      * Validates that the values are within a set of valid names.
    669      *
    670      * @return  true if all names are found in pszzAllowed.
     622     * Validates that the keys are within a set of valid names.
     623     *
     624     * @return  true if all key names are found in pszzAllowed.
    671625     * @return  false if not.
    672      * @param   pNode           The node which values should be examined.
    673      * @param   pszzValid       List of valid names separated by '\\0' and ending with
     626     * @param   pvUser          The opaque user data associated with this interface.
     627     * @param   pszzValid       List of valid key names separated by '\\0' and ending with
    674628     *                          a double '\\0'.
    675629     */
    676     DECLR3CALLBACKMEMBER(bool, pfnAreValuesValid, (PVDCFGNODE pNode, const char *pszzValid));
    677     DECLR3CALLBACKMEMBER(int, pfnQueryType, (PVDCFGNODE pNode, const char *pszName, PVDCFGVALUETYPE penmType));
    678     DECLR3CALLBACKMEMBER(int, pfnQuerySize, (PVDCFGNODE pNode, const char *pszName, size_t *pcb));
    679     DECLR3CALLBACKMEMBER(int, pfnQueryInteger, (PVDCFGNODE pNode, const char *pszName, uint64_t *pu64));
    680     DECLR3CALLBACKMEMBER(int, pfnQueryIntegerDef, (PVDCFGNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def));
    681     DECLR3CALLBACKMEMBER(int, pfnQueryString, (PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString));
    682     DECLR3CALLBACKMEMBER(int, pfnQueryStringDef, (PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef));
    683     DECLR3CALLBACKMEMBER(int, pfnQueryBytes, (PVDCFGNODE pNode, const char *pszName, void *pvData, size_t cbData));
     630    DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid));
     631
     632    /**
     633     * Retrieves the length of the string value associated with a key.
     634     *
     635     * @return  VBox status code.
     636     *          VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
     637     * @param   pvUser          The opaque user data associated with this interface.
     638     * @param   pszName         Name of the key to query.
     639     * @param   pcbValue        Where to store the value length. Non-NULL.
     640     */
     641    DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue));
     642
     643    /**
     644     * Query the string value associated with a key.
     645     *
     646     * @return  VBox status code.
     647     *          VERR_CFGM_VALUE_NOT_FOUND means that the key is not known.
     648     *          VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough.
     649     * @param   pvUser          The opaque user data associated with this interface.
     650     * @param   pszName         Name of the key to query.
     651     * @param   pszValue        Pointer to buffer where to store value.
     652     * @param   cchValue        Length of value buffer.
     653     */
     654    DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue));
    684655} VDINTERFACECONFIG, *PVDINTERFACECONFIG;
    685656
     
    708679
    709680/**
    710  * Query configuration, validates that the values are within a set of valid names.
    711  *
    712  * @return  true if all names are found in pszzAllowed.
     681 * Query configuration, validates that the keys are within a set of valid names.
     682 *
     683 * @return  true if all key names are found in pszzAllowed.
    713684 * @return  false if not.
    714685 * @param   pCfgIf      Pointer to configuration callback table.
    715  * @param   pNode       The node which values should be examined.
     686 * @param   pvUser      The opaque user data associated with this interface.
    716687 * @param   pszzValid   List of valid names separated by '\\0' and ending with
    717688 *                      a double '\\0'.
    718689 */
    719 DECLINLINE(bool) VDCFGAreValuesValid(PVDINTERFACECONFIG pCfgIf,
    720                                      PVDCFGNODE pNode,
    721                                      const char *pszzValid)
    722 {
    723     return pCfgIf->pfnAreValuesValid(pNode, pszzValid);
     690DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, void *pvUser,
     691                                   const char *pszzValid)
     692{
     693    return pCfgIf->pfnAreKeysValid(pvUser, pszzValid);
    724694}
    725695
     
    729699 * @return  VBox status code.
    730700 * @param   pCfgIf      Pointer to configuration callback table.
    731  * @param   pNode       Which node to search for pszName in.
     701 * @param   pvUser      The opaque user data associated with this interface.
    732702 * @param   pszName     Name of an integer value
    733703 * @param   pu64        Where to store the value. Set to default on failure.
    734704 * @param   u64Def      The default value.
    735705 */
    736 DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,
     706DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
    737707                                 const char *pszName, uint64_t *pu64,
    738708                                 uint64_t u64Def)
    739709{
    740     return pCfgIf->pfnQueryIntegerDef(pNode, pszName, pu64, u64Def);
     710    char aszBuf[32];
     711    int rc = pCfgIf->pfnQuery(pvUser, pszName, aszBuf, sizeof(aszBuf));
     712    if (RT_SUCCESS(rc))
     713    {
     714        rc = RTStrToUInt64Full(aszBuf, 0, pu64);
     715    }
     716    else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     717    {
     718        rc = VINF_SUCCESS;
     719        *pu64 = u64Def;
     720    }
     721    return rc;
    741722}
    742723
     
    746727 * @return  VBox status code.
    747728 * @param   pCfgIf      Pointer to configuration callback table.
    748  * @param   pNode       Which node to search for pszName in.
     729 * @param   pvUser      The opaque user data associated with this interface.
    749730 * @param   pszName     Name of an integer value
    750731 * @param   pu32        Where to store the value. Set to default on failure.
    751732 * @param   u32Def      The default value.
    752733 */
    753 DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,
     734DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, void *pvUser,
    754735                                 const char *pszName, uint32_t *pu32,
    755736                                 uint32_t u32Def)
    756737{
    757738    uint64_t u64;
    758     int rc = pCfgIf->pfnQueryIntegerDef(pNode, pszName, &u64, u32Def);
    759     if (VBOX_SUCCESS(rc))
     739    int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, u32Def);
     740    if (RT_SUCCESS(rc))
    760741    {
    761742        if (!(u64 & UINT64_C(0xffffffff00000000)))
     
    772753 * @return  VBox status code.
    773754 * @param   pCfgIf      Pointer to configuration callback table.
    774  * @param   pNode       Which node to search for pszName in.
     755 * @param   pvUser      The opaque user data associated with this interface.
    775756 * @param   pszName     Name of an integer value
    776757 * @param   pf          Where to store the value. Set to default on failure.
    777758 * @param   fDef        The default value.
    778759 */
    779 DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,
     760DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, void *pvUser,
    780761                                  const char *pszName, bool *pf,
    781762                                  bool fDef)
    782763{
    783764    uint64_t u64;
    784     int rc = pCfgIf->pfnQueryIntegerDef(pNode, pszName, &u64, fDef);
    785     if (VBOX_SUCCESS(rc))
     765    int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, fDef);
     766    if (RT_SUCCESS(rc))
    786767        *pf = u64 ? true : false;
    787768    return rc;
     
    794775 * @return  VBox status code.
    795776 * @param   pCfgIf      Pointer to configuration callback table.
    796  * @param   pNode       Which node to search for pszName in.
     777 * @param   pvUser      The opaque user data associated with this interface.
    797778 * @param   pszName     Name of an zero terminated character value
    798779 * @param   ppszString  Where to store the string pointer. Not set on failure.
     
    800781 */
    801782DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf,
    802                                       PVDCFGNODE pNode,
    803                                       const char *pszName,
     783                                      void *pvUser, const char *pszName,
    804784                                      char **ppszString)
    805785{
    806786    size_t cch;
    807     int rc = pCfgIf->pfnQuerySize(pNode, pszName, &cch);
    808     if (VBOX_SUCCESS(rc))
     787    int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch);
     788    if (RT_SUCCESS(rc))
    809789    {
    810790        char *pszString = (char *)RTMemAlloc(cch);
    811791        if (pszString)
    812792        {
    813             rc = pCfgIf->pfnQueryString(pNode, pszName, pszString, cch);
    814             if (VBOX_SUCCESS(rc))
     793            rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch);
     794            if (RT_SUCCESS(rc))
    815795                *ppszString = pszString;
    816796            else
     
    829809 * @return  VBox status code.
    830810 * @param   pCfgIf      Pointer to configuration callback table.
    831  * @param   pNode       Which node to search for pszName in.
     811 * @param   pvUser      The opaque user data associated with this interface.
    832812 * @param   pszName     Name of an zero terminated character value
    833813 * @param   ppszString  Where to store the string pointer. Not set on failure.
     
    836816 */
    837817DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf,
    838                                          PVDCFGNODE pNode,
    839                                          const char *pszName,
     818                                         void *pvUser, const char *pszName,
    840819                                         char **ppszString,
    841820                                         const char *pszDef)
    842821{
    843822    size_t cch;
    844     int rc = pCfgIf->pfnQuerySize(pNode, pszName, &cch);
     823    int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch);
    845824    if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
    846825    {
     
    848827        rc = VINF_SUCCESS;
    849828    }
    850     if (VBOX_SUCCESS(rc))
     829    if (RT_SUCCESS(rc))
    851830    {
    852831        char *pszString = (char *)RTMemAlloc(cch);
    853832        if (pszString)
    854833        {
    855             rc = pCfgIf->pfnQueryStringDef(pNode, pszName, pszString, cch, pszDef);
    856             if (VBOX_SUCCESS(rc))
     834            rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch);
     835            if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     836            {
     837                memcpy(pszString, pszDef, cch);
     838                rc = VINF_SUCCESS;
     839            }
     840            if (RT_SUCCESS(rc))
    857841                *ppszString = pszString;
    858842            else
     
    870854 * @return  VBox status code.
    871855 * @param   pCfgIf      Pointer to configuration callback table.
    872  * @param   pNode       Which node to search for pszName in.
     856 * @param   pvUser      The opaque user data associated with this interface.
    873857 * @param   pszName     Name of an zero terminated character value
    874858 * @param   ppvData     Where to store the byte string pointer. Not set on failure.
     
    877861 */
    878862DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf,
    879                                      PVDCFGNODE pNode, const char *pszName,
     863                                     void *pvUser, const char *pszName,
    880864                                     void **ppvData, size_t *pcbData)
    881865{
    882866    size_t cb;
    883     int rc = pCfgIf->pfnQuerySize(pNode, pszName, &cb);
    884     if (VBOX_SUCCESS(rc))
     867    int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb);
     868    if (RT_SUCCESS(rc))
    885869    {
    886870        char *pvData = (char *)RTMemAlloc(cb);
    887871        if (pvData)
    888872        {
    889             rc = pCfgIf->pfnQueryBytes(pNode, pszName, pvData, cb);
    890             if (VBOX_SUCCESS(rc))
     873            rc = pCfgIf->pfnQuery(pvUser, pszName, pvData, cb);
     874            if (RT_SUCCESS(rc))
    891875            {
    892876                *ppvData = pvData;
     
    10201004/** @}*/
    10211005
     1006
     1007/**
     1008 * Configuration value type for configuration information interface.
     1009 */
     1010typedef enum VDCFGVALUETYPE
     1011{
     1012    /** Integer value. */
     1013    VDCFGVALUETYPE_INTEGER = 1,
     1014    /** String value. */
     1015    VDCFGVALUETYPE_STRING,
     1016    /** Bytestring value. */
     1017    VDCFGVALUETYPE_BYTES
     1018} VDCFGVALUETYPE;
     1019
     1020
    10221021/**
    10231022 * Structure describing configuration keys required/supported by a backend
     
    10301029    /** Pointer to default value (descriptor). NULL if no useful default value
    10311030     * can be specified. */
    1032     const PVDCFGVALUE pDefaultValue;
     1031    const char *pszDefaultValue;
    10331032    /** Value type for this key. */
    10341033    VDCFGVALUETYPE enmValueType;
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r14538 r14780  
    289289*******************************************************************************/
    290290
    291 static bool drvvdCfgAreValuesValid(PVDCFGNODE pNode, const char *pszzValid)
    292 {
    293     return CFGMR3AreValuesValid((PCFGMNODE)pNode, pszzValid);
    294 }
    295 
    296 static int drvvdCfgQueryType(PVDCFGNODE pNode, const char *pszName, PVDCFGVALUETYPE penmType)
    297 {
    298     Assert(VDCFGVALUETYPE_INTEGER == (VDCFGVALUETYPE)CFGMVALUETYPE_INTEGER);
    299     Assert(VDCFGVALUETYPE_STRING == (VDCFGVALUETYPE)CFGMVALUETYPE_STRING);
    300     Assert(VDCFGVALUETYPE_BYTES == (VDCFGVALUETYPE)CFGMVALUETYPE_BYTES);
    301     return CFGMR3QueryType((PCFGMNODE)pNode, pszName, (PCFGMVALUETYPE)penmType);
    302 }
    303 
    304 static int drvvdCfgQuerySize(PVDCFGNODE pNode, const char *pszName, size_t *pcb)
    305 {
    306     return CFGMR3QuerySize((PCFGMNODE)pNode, pszName, pcb);
    307 }
    308 
    309 static int drvvdCfgQueryInteger(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64)
    310 {
    311     return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64);
    312 }
    313 
    314 static int drvvdCfgQueryIntegerDef(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)
    315 {
    316     return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64);
    317 }
    318 
    319 static int drvvdCfgQueryString(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString)
    320 {
    321     return CFGMR3QueryString((PCFGMNODE)pNode, pszName, pszString, cchString);
    322 }
    323 
    324 static int drvvdCfgQueryStringDef(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)
    325 {
    326     return CFGMR3QueryStringDef((PCFGMNODE)pNode, pszName, pszString, cchString, pszDef);
    327 }
    328 
    329 static int drvvdCfgQueryBytes(PVDCFGNODE pNode, const char *pszName, void *pvData, size_t cbData)
    330 {
    331     return CFGMR3QueryBytes((PCFGMNODE)pNode, pszName, pvData, cbData);
     291static bool drvvdCfgAreKeysValid(void *pvUser, const char *pszzValid)
     292{
     293    return CFGMR3AreValuesValid((PCFGMNODE)pvUser, pszzValid);
     294}
     295
     296static int drvvdCfgQuerySize(void *pvUser, const char *pszName, size_t *pcb)
     297{
     298    return CFGMR3QuerySize((PCFGMNODE)pvUser, pszName, pcb);
     299}
     300
     301static int drvvdCfgQuery(void *pvUser, const char *pszName, char *pszString, size_t cchString)
     302{
     303    return CFGMR3QueryString((PCFGMNODE)pvUser, pszName, pszString, cchString);
    332304}
    333305
     
    790762    pThis->VDIConfigCallbacks.cbSize                = sizeof(VDINTERFACECONFIG);
    791763    pThis->VDIConfigCallbacks.enmInterface          = VDINTERFACETYPE_CONFIG;
    792     pThis->VDIConfigCallbacks.pfnAreValuesValid     = drvvdCfgAreValuesValid;
    793     pThis->VDIConfigCallbacks.pfnQueryType          = drvvdCfgQueryType;
     764    pThis->VDIConfigCallbacks.pfnAreKeysValid       = drvvdCfgAreKeysValid;
    794765    pThis->VDIConfigCallbacks.pfnQuerySize          = drvvdCfgQuerySize;
    795     pThis->VDIConfigCallbacks.pfnQueryInteger       = drvvdCfgQueryInteger;
    796     pThis->VDIConfigCallbacks.pfnQueryIntegerDef    = drvvdCfgQueryIntegerDef;
    797     pThis->VDIConfigCallbacks.pfnQueryString        = drvvdCfgQueryString;
    798     pThis->VDIConfigCallbacks.pfnQueryStringDef     = drvvdCfgQueryStringDef;
    799     pThis->VDIConfigCallbacks.pfnQueryBytes         = drvvdCfgQueryBytes;
     766    pThis->VDIConfigCallbacks.pfnQuery              = drvvdCfgQuery;
    800767
    801768    /* List of images is empty now. */
  • trunk/src/VBox/Devices/Storage/testcase/tstVD-2.cpp

    r13837 r14780  
    8787                {
    8888                    case VDCFGVALUETYPE_INTEGER:
    89                         RTPrintf("integer default=");
    90                         if (pa->pDefaultValue)
    91                             RTPrintf("%RU64", pa->pDefaultValue->Integer.u64);
    92                         else
    93                             RTPrintf("<NONE>");
     89                        RTPrintf("integer");
    9490                        break;
    9591                    case VDCFGVALUETYPE_STRING:
    96                         RTPrintf("string default=");
    97                         if (pa->pDefaultValue)
    98                             RTPrintf("%s", pa->pDefaultValue->String.psz);
    99                         else
    100                             RTPrintf("<NONE>");
     92                        RTPrintf("string");
    10193                        break;
    10294                    case VDCFGVALUETYPE_BYTES:
    103                         RTPrintf("bytes default=");
    104                         if (pa->pDefaultValue)
    105                             RTPrintf("length=%RTuint %.*Rhxs",
    106                                      pa->pDefaultValue->Bytes.cb,
    107                                      pa->pDefaultValue->Bytes.cb,
    108                                      pa->pDefaultValue->Bytes.pv);
    109                         else
    110                             RTPrintf("<NONE>");
     95                        RTPrintf("bytes");
    11196                        break;
    11297                    default:
    11398                        RTPrintf("INVALID!");
    11499                }
     100                if (pa->pszDefaultValue)
     101                    RTPrintf("%s", pa->pszDefaultValue);
     102                else
     103                    RTPrintf("<NONE>");
    115104                RTPrintf(" flags=");
    116105                if (!pa->uKeyFlags)
  • trunk/src/VBox/Main/HardDiskFormatImpl.cpp

    r14772 r14780  
    9595                    dt = DataType_Int32;
    9696                    /* If there is a default value get them in the right format */
    97                     if (pa->pDefaultValue)
    98                         defaultValue =
    99                             Utf8StrFmt ("%d", pa->pDefaultValue->Integer.u64);
     97                    if (pa->pszDefaultValue)
     98                        defaultValue = pa->pszDefaultValue;
    10099                    break;
    101100                }
     
    104103                    dt = DataType_Int8;
    105104                    /* If there is a default value get them in the right format */
    106                     if (pa->pDefaultValue)
     105                    if (pa->pszDefaultValue)
    107106                    {
    108                         /* Copy the bytes over */
    109                         defaultValue.alloc (pa->pDefaultValue->Bytes.cb + 1);
    110                         memcpy (defaultValue.mutableRaw(), pa->pDefaultValue->Bytes.pv,
    111                                 pa->pDefaultValue->Bytes.cb);
    112                         defaultValue.mutableRaw() [defaultValue.length()] = 0;
     107                        /* Copy the bytes over - treated simply as a string */
     108                        defaultValue = pa->pszDefaultValue;
    113109                        flags |= DataFlags_Array;
    114110                    }
     
    119115                    dt = DataType_String;
    120116                    /* If there is a default value get them in the right format */
    121                     if (pa->pDefaultValue)
    122                         defaultValue = pa->pDefaultValue->String.psz;
     117                    if (pa->pszDefaultValue)
     118                        defaultValue = pa->pszDefaultValue;
    123119                    break;
    124120                }
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