@@ -500,6 +500,7 @@ static int srpt_refresh_port(struct srpt_port *sport)
500
500
struct ib_mad_reg_req reg_req ;
501
501
struct ib_port_modify port_modify ;
502
502
struct ib_port_attr port_attr ;
503
+ __be16 * guid ;
503
504
int ret ;
504
505
505
506
memset (& port_modify , 0 , sizeof (port_modify ));
@@ -522,10 +523,17 @@ static int srpt_refresh_port(struct srpt_port *sport)
522
523
if (ret )
523
524
goto err_query_port ;
524
525
526
+ sport -> port_guid_wwn .priv = sport ;
527
+ guid = (__be16 * )& sport -> gid .global .interface_id ;
525
528
snprintf (sport -> port_guid , sizeof (sport -> port_guid ),
526
- "0x%016llx%016llx" ,
527
- be64_to_cpu (sport -> gid .global .subnet_prefix ),
528
- be64_to_cpu (sport -> gid .global .interface_id ));
529
+ "%04x:%04x:%04x:%04x" ,
530
+ be16_to_cpu (guid [0 ]), be16_to_cpu (guid [1 ]),
531
+ be16_to_cpu (guid [2 ]), be16_to_cpu (guid [3 ]));
532
+ sport -> port_gid_wwn .priv = sport ;
533
+ snprintf (sport -> port_gid , sizeof (sport -> port_gid ),
534
+ "0x%016llx%016llx" ,
535
+ be64_to_cpu (sport -> gid .global .subnet_prefix ),
536
+ be64_to_cpu (sport -> gid .global .interface_id ));
529
537
530
538
if (!sport -> mad_agent ) {
531
539
memset (& reg_req , 0 , sizeof (reg_req ));
@@ -1838,6 +1846,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
1838
1846
struct srp_login_rej * rej ;
1839
1847
struct ib_cm_rep_param * rep_param ;
1840
1848
struct srpt_rdma_ch * ch , * tmp_ch ;
1849
+ __be16 * guid ;
1841
1850
u32 it_iu_len ;
1842
1851
int i , ret = 0 ;
1843
1852
@@ -1983,26 +1992,30 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
1983
1992
goto destroy_ib ;
1984
1993
}
1985
1994
1986
- /*
1987
- * Use the initator port identifier as the session name, when
1988
- * checking against se_node_acl->initiatorname[] this can be
1989
- * with or without preceeding '0x'.
1990
- */
1995
+ guid = (__be16 * )& param -> primary_path -> sgid .global .interface_id ;
1996
+ snprintf (ch -> ini_guid , sizeof (ch -> ini_guid ), "%04x:%04x:%04x:%04x" ,
1997
+ be16_to_cpu (guid [0 ]), be16_to_cpu (guid [1 ]),
1998
+ be16_to_cpu (guid [2 ]), be16_to_cpu (guid [3 ]));
1991
1999
snprintf (ch -> sess_name , sizeof (ch -> sess_name ), "0x%016llx%016llx" ,
1992
2000
be64_to_cpu (* (__be64 * )ch -> i_port_id ),
1993
2001
be64_to_cpu (* (__be64 * )(ch -> i_port_id + 8 )));
1994
2002
1995
2003
pr_debug ("registering session %s\n" , ch -> sess_name );
1996
2004
1997
- ch -> sess = target_alloc_session (& sport -> port_tpg_1 , 0 , 0 ,
2005
+ if (sport -> port_guid_tpg .se_tpg_wwn )
2006
+ ch -> sess = target_alloc_session (& sport -> port_guid_tpg , 0 , 0 ,
2007
+ TARGET_PROT_NORMAL ,
2008
+ ch -> ini_guid , ch , NULL );
2009
+ if (sport -> port_gid_tpg .se_tpg_wwn && IS_ERR_OR_NULL (ch -> sess ))
2010
+ ch -> sess = target_alloc_session (& sport -> port_gid_tpg , 0 , 0 ,
1998
2011
TARGET_PROT_NORMAL , ch -> sess_name , ch ,
1999
2012
NULL );
2000
2013
/* Retry without leading "0x" */
2001
- if (IS_ERR (ch -> sess ))
2002
- ch -> sess = target_alloc_session (& sport -> port_tpg_1 , 0 , 0 ,
2014
+ if (sport -> port_gid_tpg . se_tpg_wwn && IS_ERR_OR_NULL (ch -> sess ))
2015
+ ch -> sess = target_alloc_session (& sport -> port_gid_tpg , 0 , 0 ,
2003
2016
TARGET_PROT_NORMAL ,
2004
2017
ch -> sess_name + 2 , ch , NULL );
2005
- if (IS_ERR (ch -> sess )) {
2018
+ if (IS_ERR_OR_NULL (ch -> sess )) {
2006
2019
pr_info ("Rejected login because no ACL has been configured yet for initiator %s.\n" ,
2007
2020
ch -> sess_name );
2008
2021
rej -> reason = cpu_to_be32 ((PTR_ERR (ch -> sess ) == - ENOMEM ) ?
@@ -2420,7 +2433,7 @@ static int srpt_release_sdev(struct srpt_device *sdev)
2420
2433
return 0 ;
2421
2434
}
2422
2435
2423
- static struct srpt_port * __srpt_lookup_port (const char * name )
2436
+ static struct se_wwn * __srpt_lookup_wwn (const char * name )
2424
2437
{
2425
2438
struct ib_device * dev ;
2426
2439
struct srpt_device * sdev ;
@@ -2435,23 +2448,25 @@ static struct srpt_port *__srpt_lookup_port(const char *name)
2435
2448
for (i = 0 ; i < dev -> phys_port_cnt ; i ++ ) {
2436
2449
sport = & sdev -> port [i ];
2437
2450
2438
- if (!strcmp (sport -> port_guid , name ))
2439
- return sport ;
2451
+ if (strcmp (sport -> port_guid , name ) == 0 )
2452
+ return & sport -> port_guid_wwn ;
2453
+ if (strcmp (sport -> port_gid , name ) == 0 )
2454
+ return & sport -> port_gid_wwn ;
2440
2455
}
2441
2456
}
2442
2457
2443
2458
return NULL ;
2444
2459
}
2445
2460
2446
- static struct srpt_port * srpt_lookup_port (const char * name )
2461
+ static struct se_wwn * srpt_lookup_wwn (const char * name )
2447
2462
{
2448
- struct srpt_port * sport ;
2463
+ struct se_wwn * wwn ;
2449
2464
2450
2465
spin_lock (& srpt_dev_lock );
2451
- sport = __srpt_lookup_port (name );
2466
+ wwn = __srpt_lookup_wwn (name );
2452
2467
spin_unlock (& srpt_dev_lock );
2453
2468
2454
- return sport ;
2469
+ return wwn ;
2455
2470
}
2456
2471
2457
2472
/**
@@ -2643,11 +2658,19 @@ static char *srpt_get_fabric_name(void)
2643
2658
return "srpt" ;
2644
2659
}
2645
2660
2661
+ static struct srpt_port * srpt_tpg_to_sport (struct se_portal_group * tpg )
2662
+ {
2663
+ return tpg -> se_tpg_wwn -> priv ;
2664
+ }
2665
+
2646
2666
static char * srpt_get_fabric_wwn (struct se_portal_group * tpg )
2647
2667
{
2648
- struct srpt_port * sport = container_of (tpg , struct srpt_port , port_tpg_1 );
2668
+ struct srpt_port * sport = srpt_tpg_to_sport (tpg );
2649
2669
2650
- return sport -> port_guid ;
2670
+ WARN_ON_ONCE (tpg != & sport -> port_guid_tpg &&
2671
+ tpg != & sport -> port_gid_tpg );
2672
+ return tpg == & sport -> port_guid_tpg ? sport -> port_guid :
2673
+ sport -> port_gid ;
2651
2674
}
2652
2675
2653
2676
static u16 srpt_get_tag (struct se_portal_group * tpg )
@@ -2737,6 +2760,19 @@ static int srpt_get_tcm_cmd_state(struct se_cmd *se_cmd)
2737
2760
return srpt_get_cmd_state (ioctx );
2738
2761
}
2739
2762
2763
+ static int srpt_parse_guid (u64 * guid , const char * name )
2764
+ {
2765
+ u16 w [4 ];
2766
+ int ret = - EINVAL ;
2767
+
2768
+ if (sscanf (name , "%hx:%hx:%hx:%hx" , & w [0 ], & w [1 ], & w [2 ], & w [3 ]) != 4 )
2769
+ goto out ;
2770
+ * guid = get_unaligned_be64 (w );
2771
+ ret = 0 ;
2772
+ out :
2773
+ return ret ;
2774
+ }
2775
+
2740
2776
/**
2741
2777
* srpt_parse_i_port_id() - Parse an initiator port ID.
2742
2778
* @name: ASCII representation of a 128-bit initiator port ID.
@@ -2772,20 +2808,23 @@ static int srpt_parse_i_port_id(u8 i_port_id[16], const char *name)
2772
2808
*/
2773
2809
static int srpt_init_nodeacl (struct se_node_acl * se_nacl , const char * name )
2774
2810
{
2811
+ u64 guid ;
2775
2812
u8 i_port_id [16 ];
2813
+ int ret ;
2776
2814
2777
- if (srpt_parse_i_port_id (i_port_id , name ) < 0 ) {
2815
+ ret = srpt_parse_guid (& guid , name );
2816
+ if (ret < 0 )
2817
+ ret = srpt_parse_i_port_id (i_port_id , name );
2818
+ if (ret < 0 )
2778
2819
pr_err ("invalid initiator port ID %s\n" , name );
2779
- return - EINVAL ;
2780
- }
2781
- return 0 ;
2820
+ return ret ;
2782
2821
}
2783
2822
2784
2823
static ssize_t srpt_tpg_attrib_srp_max_rdma_size_show (struct config_item * item ,
2785
2824
char * page )
2786
2825
{
2787
2826
struct se_portal_group * se_tpg = attrib_to_tpg (item );
2788
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2827
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2789
2828
2790
2829
return sprintf (page , "%u\n" , sport -> port_attrib .srp_max_rdma_size );
2791
2830
}
@@ -2794,7 +2833,7 @@ static ssize_t srpt_tpg_attrib_srp_max_rdma_size_store(struct config_item *item,
2794
2833
const char * page , size_t count )
2795
2834
{
2796
2835
struct se_portal_group * se_tpg = attrib_to_tpg (item );
2797
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2836
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2798
2837
unsigned long val ;
2799
2838
int ret ;
2800
2839
@@ -2822,7 +2861,7 @@ static ssize_t srpt_tpg_attrib_srp_max_rsp_size_show(struct config_item *item,
2822
2861
char * page )
2823
2862
{
2824
2863
struct se_portal_group * se_tpg = attrib_to_tpg (item );
2825
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2864
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2826
2865
2827
2866
return sprintf (page , "%u\n" , sport -> port_attrib .srp_max_rsp_size );
2828
2867
}
@@ -2831,7 +2870,7 @@ static ssize_t srpt_tpg_attrib_srp_max_rsp_size_store(struct config_item *item,
2831
2870
const char * page , size_t count )
2832
2871
{
2833
2872
struct se_portal_group * se_tpg = attrib_to_tpg (item );
2834
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2873
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2835
2874
unsigned long val ;
2836
2875
int ret ;
2837
2876
@@ -2859,7 +2898,7 @@ static ssize_t srpt_tpg_attrib_srp_sq_size_show(struct config_item *item,
2859
2898
char * page )
2860
2899
{
2861
2900
struct se_portal_group * se_tpg = attrib_to_tpg (item );
2862
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2901
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2863
2902
2864
2903
return sprintf (page , "%u\n" , sport -> port_attrib .srp_sq_size );
2865
2904
}
@@ -2868,7 +2907,7 @@ static ssize_t srpt_tpg_attrib_srp_sq_size_store(struct config_item *item,
2868
2907
const char * page , size_t count )
2869
2908
{
2870
2909
struct se_portal_group * se_tpg = attrib_to_tpg (item );
2871
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2910
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2872
2911
unsigned long val ;
2873
2912
int ret ;
2874
2913
@@ -2906,7 +2945,7 @@ static struct configfs_attribute *srpt_tpg_attrib_attrs[] = {
2906
2945
static ssize_t srpt_tpg_enable_show (struct config_item * item , char * page )
2907
2946
{
2908
2947
struct se_portal_group * se_tpg = to_tpg (item );
2909
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2948
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2910
2949
2911
2950
return snprintf (page , PAGE_SIZE , "%d\n" , (sport -> enabled ) ? 1 : 0 );
2912
2951
}
@@ -2915,7 +2954,7 @@ static ssize_t srpt_tpg_enable_store(struct config_item *item,
2915
2954
const char * page , size_t count )
2916
2955
{
2917
2956
struct se_portal_group * se_tpg = to_tpg (item );
2918
- struct srpt_port * sport = container_of (se_tpg , struct srpt_port , port_tpg_1 );
2957
+ struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
2919
2958
struct srpt_device * sdev = sport -> sdev ;
2920
2959
struct srpt_rdma_ch * ch ;
2921
2960
unsigned long tmp ;
@@ -2967,15 +3006,19 @@ static struct se_portal_group *srpt_make_tpg(struct se_wwn *wwn,
2967
3006
struct config_group * group ,
2968
3007
const char * name )
2969
3008
{
2970
- struct srpt_port * sport = container_of (wwn , struct srpt_port , port_wwn );
3009
+ struct srpt_port * sport = wwn -> priv ;
3010
+ static struct se_portal_group * tpg ;
2971
3011
int res ;
2972
3012
2973
- /* Initialize sport->port_wwn and sport->port_tpg_1 */
2974
- res = core_tpg_register (& sport -> port_wwn , & sport -> port_tpg_1 , SCSI_PROTOCOL_SRP );
3013
+ WARN_ON_ONCE (wwn != & sport -> port_guid_wwn &&
3014
+ wwn != & sport -> port_gid_wwn );
3015
+ tpg = wwn == & sport -> port_guid_wwn ? & sport -> port_guid_tpg :
3016
+ & sport -> port_gid_tpg ;
3017
+ res = core_tpg_register (wwn , tpg , SCSI_PROTOCOL_SRP );
2975
3018
if (res )
2976
3019
return ERR_PTR (res );
2977
3020
2978
- return & sport -> port_tpg_1 ;
3021
+ return tpg ;
2979
3022
}
2980
3023
2981
3024
/**
@@ -2984,11 +3027,10 @@ static struct se_portal_group *srpt_make_tpg(struct se_wwn *wwn,
2984
3027
*/
2985
3028
static void srpt_drop_tpg (struct se_portal_group * tpg )
2986
3029
{
2987
- struct srpt_port * sport = container_of (tpg ,
2988
- struct srpt_port , port_tpg_1 );
3030
+ struct srpt_port * sport = srpt_tpg_to_sport (tpg );
2989
3031
2990
3032
sport -> enabled = false;
2991
- core_tpg_deregister (& sport -> port_tpg_1 );
3033
+ core_tpg_deregister (tpg );
2992
3034
}
2993
3035
2994
3036
/**
@@ -2999,19 +3041,7 @@ static struct se_wwn *srpt_make_tport(struct target_fabric_configfs *tf,
2999
3041
struct config_group * group ,
3000
3042
const char * name )
3001
3043
{
3002
- struct srpt_port * sport ;
3003
- int ret ;
3004
-
3005
- sport = srpt_lookup_port (name );
3006
- pr_debug ("make_tport(%s)\n" , name );
3007
- ret = - EINVAL ;
3008
- if (!sport )
3009
- goto err ;
3010
-
3011
- return & sport -> port_wwn ;
3012
-
3013
- err :
3014
- return ERR_PTR (ret );
3044
+ return srpt_lookup_wwn (name ) ? : ERR_PTR (- EINVAL );
3015
3045
}
3016
3046
3017
3047
/**
@@ -3020,9 +3050,6 @@ static struct se_wwn *srpt_make_tport(struct target_fabric_configfs *tf,
3020
3050
*/
3021
3051
static void srpt_drop_tport (struct se_wwn * wwn )
3022
3052
{
3023
- struct srpt_port * sport = container_of (wwn , struct srpt_port , port_wwn );
3024
-
3025
- pr_debug ("drop_tport(%s\n" , config_item_name (& sport -> port_wwn .wwn_group .cg_item ));
3026
3053
}
3027
3054
3028
3055
static ssize_t srpt_wwn_version_show (struct config_item * item , char * buf )
0 commit comments