|
@@ -1360,6 +1360,10 @@ static int iscsi_parse_lun ( struct iscsi_session *iscsi,
|
1360
|
1360
|
} lun;
|
1361
|
1361
|
int i;
|
1362
|
1362
|
|
|
1363
|
+ /* Empty LUN; assume LUN 0 */
|
|
1364
|
+ if ( ! *lun_string )
|
|
1365
|
+ return 0;
|
|
1366
|
+
|
1363
|
1367
|
for ( i = 0 ; i < 4 ; i++ ) {
|
1364
|
1368
|
lun.u16[i] = strtoul ( p, &p, 16 );
|
1365
|
1369
|
if ( *p != '-' )
|
|
@@ -1382,48 +1386,43 @@ static int iscsi_parse_lun ( struct iscsi_session *iscsi,
|
1382
|
1386
|
*/
|
1383
|
1387
|
static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
|
1384
|
1388
|
const char *root_path ) {
|
1385
|
|
- const char *p = root_path;
|
1386
|
|
- char *fragment;
|
1387
|
|
- size_t len;
|
1388
|
|
- enum iscsi_root_path_component i;
|
|
1389
|
+ char rp_copy[ strlen ( root_path ) + 1 ];
|
|
1390
|
+ char *rp_comp[NUM_RP_COMPONENTS];
|
|
1391
|
+ char *rp = rp_copy;
|
|
1392
|
+ int i = 0;
|
1389
|
1393
|
int rc;
|
1390
|
1394
|
|
1391
|
|
- for ( i = 0 ; i < NUM_RP_COMPONENTS ; i++ ) {
|
1392
|
|
- len = strcspn ( p, ":" );
|
1393
|
|
- fragment = strndup ( p, len );
|
1394
|
|
- if ( ! fragment ) {
|
1395
|
|
- DBGC ( iscsi, "iSCSI %p could not duplicate root "
|
1396
|
|
- "path component at %s\n", iscsi, p );
|
1397
|
|
- return -ENOMEM;
|
1398
|
|
- }
|
1399
|
|
- switch ( i ) {
|
1400
|
|
- case RP_SERVERNAME:
|
1401
|
|
- iscsi->target_address = fragment;
|
1402
|
|
- break;
|
1403
|
|
- case RP_PORT:
|
1404
|
|
- iscsi->target_port = strtoul ( fragment, NULL, 10 );
|
1405
|
|
- if ( ! iscsi->target_port )
|
1406
|
|
- iscsi->target_port = ISCSI_PORT;
|
1407
|
|
- free ( fragment );
|
|
1395
|
+ /* Split root path into component parts */
|
|
1396
|
+ strcpy ( rp_copy, root_path );
|
|
1397
|
+ while ( 1 ) {
|
|
1398
|
+ rp_comp[i++] = rp;
|
|
1399
|
+ if ( i == NUM_RP_COMPONENTS )
|
1408
|
1400
|
break;
|
1409
|
|
- case RP_LUN:
|
1410
|
|
- rc = iscsi_parse_lun ( iscsi, fragment );
|
1411
|
|
- free ( fragment );
|
1412
|
|
- if ( rc != 0 ) {
|
1413
|
|
- DBGC ( iscsi, "iSCSI %p invalid LUN %s\n",
|
1414
|
|
- iscsi, fragment );
|
1415
|
|
- return rc;
|
|
1401
|
+ for ( ; *rp != ':' ; rp++ ) {
|
|
1402
|
+ if ( ! *rp ) {
|
|
1403
|
+ DBGC ( iscsi, "iSCSI %p root path \"%s\" "
|
|
1404
|
+ "too short\n", iscsi, root_path );
|
|
1405
|
+ return -EINVAL;
|
1416
|
1406
|
}
|
1417
|
|
- break;
|
1418
|
|
- case RP_TARGETNAME:
|
1419
|
|
- iscsi->target_iqn = fragment;
|
1420
|
|
- break;
|
1421
|
|
- default:
|
1422
|
|
- free ( fragment );
|
1423
|
|
- break;
|
1424
|
1407
|
}
|
1425
|
|
- p += len;
|
|
1408
|
+ *(rp++) = '\0';
|
|
1409
|
+ }
|
|
1410
|
+
|
|
1411
|
+ /* Use root path components to configure iSCSI session */
|
|
1412
|
+ iscsi->target_address = strdup ( rp_comp[RP_SERVERNAME] );
|
|
1413
|
+ if ( ! iscsi->target_address )
|
|
1414
|
+ return -ENOMEM;
|
|
1415
|
+ iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
|
|
1416
|
+ if ( ! iscsi->target_port )
|
|
1417
|
+ iscsi->target_port = ISCSI_PORT;
|
|
1418
|
+ if ( ( rc = iscsi_parse_lun ( iscsi, rp_comp[RP_LUN] ) ) != 0 ) {
|
|
1419
|
+ DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
|
|
1420
|
+ iscsi, rp_comp[RP_LUN] );
|
|
1421
|
+ return rc;
|
1426
|
1422
|
}
|
|
1423
|
+ iscsi->target_iqn = strdup ( rp_comp[RP_TARGETNAME] );
|
|
1424
|
+ if ( ! iscsi->target_iqn )
|
|
1425
|
+ return -ENOMEM;
|
1427
|
1426
|
|
1428
|
1427
|
return 0;
|
1429
|
1428
|
}
|