VirtualBox

Changeset 14784 in vbox for trunk/src/VBox/Frontends


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

VBoxManage: Resurrected addiscsidisk command (note that iSCSI hard disks are still unavailable for VMs yet).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r14696 r14784  
    12061206                              ComPtr <IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
    12071207{
    1208 #if 1
    1209     RTPrintf("Error: Create iSCSI hard disk operation is temporarily unavailable!\n");
    1210     return 1;
    1211 #else
    12121208    HRESULT rc;
    12131209    Bstr server;
    12141210    Bstr target;
    1215     uint16_t port = UINT16_MAX;
    1216     uint64_t lun = UINT64_MAX;
     1211    Bstr port;
     1212    Bstr lun;
    12171213    Bstr username;
    12181214    Bstr password;
     
    12451241                return errorArgument("Missing argument to '%s'", argv[i]);
    12461242            i++;
    1247             port = RTStrToUInt16(argv[i]);
     1243            port = argv[i];
    12481244        }
    12491245        else if (strcmp(argv[i], "-lun") == 0)
    12501246        {
     1247            /// @todo is the below todo still relevant? Note that we do a
     1248            /// strange string->int->string conversion here.
     1249
    12511250            /** @todo move the LUN encoding algorithm into IISCSIHardDisk, add decoding */
     1251
    12521252            if (argc <= i + 1)
    12531253                return errorArgument("Missing argument to '%s'", argv[i]);
    12541254            i++;
    12551255            char *pszNext;
    1256             int rc = RTStrToUInt64Ex(argv[i], &pszNext, 0, &lun);
    1257             if (RT_FAILURE(rc) || *pszNext != '\0' || lun >= 16384)
     1256            uint64_t lunNum;
     1257            int rc = RTStrToUInt64Ex(argv[i], &pszNext, 0, &lunNum);
     1258            if (RT_FAILURE(rc) || *pszNext != '\0' || lunNum >= 16384)
    12581259                return errorArgument("Invalid LUN number '%s'", argv[i]);
    1259             if (lun <= 255)
     1260            if (lunNum <= 255)
    12601261            {
    12611262                /* Assume bus identifier = 0. */
    1262                 lun = (lun << 48); /* uses peripheral device addressing method */
     1263                lunNum = (lunNum << 48); /* uses peripheral device addressing method */
    12631264            }
    12641265            else
    12651266            {
    12661267                /* Check above already limited the LUN to 14 bits. */
    1267                 lun = (lun << 48) | RT_BIT_64(62); /* uses flat space addressing method */
    1268             }
     1268                lunNum = (lunNum << 48) | RT_BIT_64(62); /* uses flat space addressing method */
     1269            }
     1270
     1271            lun = BstrFmt ("%llu", lunNum);
    12691272        }
    12701273        else if (strcmp(argv[i], "-encodedlun") == 0)
     
    12731276                return errorArgument("Missing argument to '%s'", argv[i]);
    12741277            i++;
    1275             char *pszNext;
    1276             int rc = RTStrToUInt64Ex(argv[i], &pszNext, 0, &lun);
    1277             if (RT_FAILURE(rc) || *pszNext != '\0')
    1278                 return errorArgument("Invalid encoded LUN number '%s'", argv[i]);
     1278            lun = argv[i];
    12791279        }
    12801280        else if (strcmp(argv[i], "-username") == 0)
     
    13071307        return errorSyntax(USAGE_ADDISCSIDISK, "Parameters -server and -target are required");
    13081308
    1309     ComPtr<IHardDisk> hardDisk;
    1310     CHECK_ERROR(aVirtualBox, CreateHardDisk(HardDiskStorageType_ISCSIHardDisk, hardDisk.asOutParam()));
    1311     if (SUCCEEDED(rc) && hardDisk)
    1312     {
    1313         CHECK_ERROR(hardDisk, COMSETTER(Description)(comment));
    1314         ComPtr<IISCSIHardDisk> iSCSIDisk = hardDisk;
    1315         CHECK_ERROR(iSCSIDisk, COMSETTER(Server)(server));
    1316         if (port != UINT16_MAX)
    1317             CHECK_ERROR(iSCSIDisk, COMSETTER(Port)(port));
    1318         CHECK_ERROR(iSCSIDisk, COMSETTER(Target)(target));
    1319         if (lun != UINT64_MAX)
    1320             CHECK_ERROR(iSCSIDisk, COMSETTER(Lun)(lun));
    1321         CHECK_ERROR(iSCSIDisk, COMSETTER(UserName)(username));
    1322         CHECK_ERROR(iSCSIDisk, COMSETTER(Password)(password));
    1323 
    1324         if (SUCCEEDED(rc))
    1325         {
    1326             CHECK_ERROR(aVirtualBox, RegisterHardDisk(hardDisk));
    1327         }
    1328 
    1329         if (SUCCEEDED(rc))
    1330         {
    1331             Guid guid;
    1332             CHECK_ERROR(hardDisk, COMGETTER(Id)(guid.asOutParam()));
    1333             RTPrintf("iSCSI disk created. UUID: %s\n", guid.toString().raw());
    1334         }
    1335     }
     1309    do
     1310    {
     1311        ComPtr<IHardDisk2> hardDisk;
     1312        CHECK_ERROR_BREAK (aVirtualBox,
     1313            CreateHardDisk2(Bstr ("iSCSI"),
     1314                            BstrFmt ("%ls/%ls", server.raw(), target.raw()),
     1315                            hardDisk.asOutParam()));
     1316        CheckComRCBreakRC (rc);
     1317
     1318        if (!comment.isNull())
     1319            CHECK_ERROR_BREAK(hardDisk, COMSETTER(Description)(comment));
     1320
     1321        if (!port.isNull())
     1322            server = BstrFmt ("%ls:%ls", server.raw(), port.raw());
     1323        CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("TargetAddress"), server));
     1324        CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("TargetName"), target));
     1325
     1326        if (!lun.isNull())
     1327            CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("LUN"), lun));
     1328        if (!username.isNull())
     1329            CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("InitiatorUsername"), username));
     1330        if (!password.isNull())
     1331            CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("InitiatorSecret"), password));
     1332
     1333        /// @todo add -initiator option
     1334        CHECK_ERROR_BREAK(hardDisk,
     1335            SetProperty(Bstr("InitiatorName"),
     1336                        Bstr("iqn.2008-04.com.sun.virtualbox.initiator")));
     1337
     1338        /// @todo add -targetName and -targetPassword options
     1339
     1340        Guid guid;
     1341        CHECK_ERROR(hardDisk, COMGETTER(Id)(guid.asOutParam()));
     1342        RTPrintf("iSCSI disk created. UUID: %s\n", guid.toString().raw());
     1343    }
     1344    while (0);
    13361345
    13371346    return SUCCEEDED(rc) ? 0 : 1;
    1338 #endif
    13391347}
    13401348
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