Skip to content

Commit 5a09e39

Browse files
hreineckeJames Bottomley
authored andcommitted
[SCSI] scsi_debug: support REPORT TARGET PORT GROUPS
This patch adds support for REPORT TARGET PORT GROUPS. This is used eg for the multipathing priority callout to determine the path priority. With this patch multipath-tools can use the existing mpath_prio_alua callout to exercise the path priority grouping. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Douglas Gilbert <dougg@torque.net> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
1 parent cd00b7f commit 5a09e39

2 files changed

Lines changed: 130 additions & 14 deletions

File tree

‎drivers/scsi/scsi_debug.c‎

Lines changed: 127 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include "scsi_debug.h"
5353

5454
#define SCSI_DEBUG_VERSION "1.80"
55-
static const char * scsi_debug_version_date = "20060914";
55+
static const char * scsi_debug_version_date = "20061018";
5656

5757
/* Additional Sense Code (ASC) used */
5858
#define NO_ADDITIONAL_SENSE 0x0
@@ -254,6 +254,8 @@ static int resp_requests(struct scsi_cmnd * SCpnt,
254254
struct sdebug_dev_info * devip);
255255
static int resp_start_stop(struct scsi_cmnd * scp,
256256
struct sdebug_dev_info * devip);
257+
static int resp_report_tgtpgs(struct scsi_cmnd * scp,
258+
struct sdebug_dev_info * devip);
257259
static int resp_readcap(struct scsi_cmnd * SCpnt,
258260
struct sdebug_dev_info * devip);
259261
static int resp_readcap16(struct scsi_cmnd * SCpnt,
@@ -287,9 +289,9 @@ static void __init sdebug_build_parts(unsigned char * ramp);
287289
static void __init init_all_queued(void);
288290
static void stop_all_queued(void);
289291
static int stop_queued_cmnd(struct scsi_cmnd * cmnd);
290-
static int inquiry_evpd_83(unsigned char * arr, int target_dev_id,
291-
int dev_id_num, const char * dev_id_str,
292-
int dev_id_str_len);
292+
static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
293+
int target_dev_id, int dev_id_num,
294+
const char * dev_id_str, int dev_id_str_len);
293295
static int inquiry_evpd_88(unsigned char * arr, int target_dev_id);
294296
static int do_create_driverfs_files(void);
295297
static void do_remove_driverfs_files(void);
@@ -422,6 +424,15 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
422424
}
423425
errsts = resp_readcap16(SCpnt, devip);
424426
break;
427+
case MAINTENANCE_IN:
428+
if (MI_REPORT_TARGET_PGS != cmd[1]) {
429+
mk_sense_buffer(devip, ILLEGAL_REQUEST,
430+
INVALID_OPCODE, 0);
431+
errsts = check_condition_result;
432+
break;
433+
}
434+
errsts = resp_report_tgtpgs(SCpnt, devip);
435+
break;
425436
case READ_16:
426437
case READ_12:
427438
case READ_10:
@@ -665,8 +676,9 @@ static const char * inq_vendor_id = "Linux ";
665676
static const char * inq_product_id = "scsi_debug ";
666677
static const char * inq_product_rev = "0004";
667678

668-
static int inquiry_evpd_83(unsigned char * arr, int target_dev_id,
669-
int dev_id_num, const char * dev_id_str,
679+
static int inquiry_evpd_83(unsigned char * arr, int port_group_id,
680+
int target_dev_id, int dev_id_num,
681+
const char * dev_id_str,
670682
int dev_id_str_len)
671683
{
672684
int num, port_a;
@@ -720,6 +732,15 @@ static int inquiry_evpd_83(unsigned char * arr, int target_dev_id,
720732
arr[num++] = (port_a >> 16) & 0xff;
721733
arr[num++] = (port_a >> 8) & 0xff;
722734
arr[num++] = port_a & 0xff;
735+
/* NAA-5, Target port group identifier */
736+
arr[num++] = 0x61; /* proto=sas, binary */
737+
arr[num++] = 0x95; /* piv=1, target port group id */
738+
arr[num++] = 0x0;
739+
arr[num++] = 0x4;
740+
arr[num++] = 0;
741+
arr[num++] = 0;
742+
arr[num++] = (port_group_id >> 8) & 0xff;
743+
arr[num++] = port_group_id & 0xff;
723744
/* NAA-5, Target device identifier */
724745
arr[num++] = 0x61; /* proto=sas, binary */
725746
arr[num++] = 0xa3; /* piv=1, target device, naa */
@@ -928,12 +949,12 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
928949
struct sdebug_dev_info * devip)
929950
{
930951
unsigned char pq_pdt;
931-
unsigned char arr[SDEBUG_MAX_INQ_ARR_SZ];
952+
unsigned char * arr;
932953
unsigned char *cmd = (unsigned char *)scp->cmnd;
933-
int alloc_len, n;
954+
int alloc_len, n, ret;
934955

935956
alloc_len = (cmd[3] << 8) + cmd[4];
936-
memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ);
957+
arr = kzalloc(SDEBUG_MAX_INQ_ARR_SZ, GFP_KERNEL);
937958
if (devip->wlun)
938959
pq_pdt = 0x1e; /* present, wlun */
939960
else if (scsi_debug_no_lun_0 && (0 == devip->lun))
@@ -944,12 +965,15 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
944965
if (0x2 & cmd[1]) { /* CMDDT bit set */
945966
mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
946967
0);
968+
kfree(arr);
947969
return check_condition_result;
948970
} else if (0x1 & cmd[1]) { /* EVPD bit set */
949-
int lu_id_num, target_dev_id, len;
971+
int lu_id_num, port_group_id, target_dev_id, len;
950972
char lu_id_str[6];
951973
int host_no = devip->sdbg_host->shost->host_no;
952974

975+
port_group_id = (((host_no + 1) & 0x7f) << 8) +
976+
(devip->channel & 0x7f);
953977
if (0 == scsi_debug_vpd_use_hostno)
954978
host_no = 0;
955979
lu_id_num = devip->wlun ? -1 : (((host_no + 1) * 2000) +
@@ -977,8 +1001,9 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
9771001
memcpy(&arr[4], lu_id_str, len);
9781002
} else if (0x83 == cmd[2]) { /* device identification */
9791003
arr[1] = cmd[2]; /*sanity */
980-
arr[3] = inquiry_evpd_83(&arr[4], target_dev_id,
981-
lu_id_num, lu_id_str, len);
1004+
arr[3] = inquiry_evpd_83(&arr[4], port_group_id,
1005+
target_dev_id, lu_id_num,
1006+
lu_id_str, len);
9821007
} else if (0x84 == cmd[2]) { /* Software interface ident. */
9831008
arr[1] = cmd[2]; /*sanity */
9841009
arr[3] = inquiry_evpd_84(&arr[4]);
@@ -1012,17 +1037,22 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
10121037
/* Illegal request, invalid field in cdb */
10131038
mk_sense_buffer(devip, ILLEGAL_REQUEST,
10141039
INVALID_FIELD_IN_CDB, 0);
1040+
kfree(arr);
10151041
return check_condition_result;
10161042
}
10171043
len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len);
1018-
return fill_from_dev_buffer(scp, arr,
1044+
ret = fill_from_dev_buffer(scp, arr,
10191045
min(len, SDEBUG_MAX_INQ_ARR_SZ));
1046+
kfree(arr);
1047+
return ret;
10201048
}
10211049
/* drops through here for a standard inquiry */
10221050
arr[1] = DEV_REMOVEABLE(target) ? 0x80 : 0; /* Removable disk */
10231051
arr[2] = scsi_debug_scsi_level;
10241052
arr[3] = 2; /* response_data_format==2 */
10251053
arr[4] = SDEBUG_LONG_INQ_SZ - 5;
1054+
if (0 == scsi_debug_vpd_use_hostno)
1055+
arr[5] = 0x10; /* claim: implicit TGPS */
10261056
arr[6] = 0x10; /* claim: MultiP */
10271057
/* arr[6] |= 0x40; ... claim: EncServ (enclosure services) */
10281058
arr[7] = 0xa; /* claim: LINKED + CMDQUE */
@@ -1039,8 +1069,10 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
10391069
arr[n++] = 0x3; arr[n++] = 0x60; /* SSC-2 no version */
10401070
}
10411071
arr[n++] = 0xc; arr[n++] = 0xf; /* SAS-1.1 rev 10 */
1042-
return fill_from_dev_buffer(scp, arr,
1072+
ret = fill_from_dev_buffer(scp, arr,
10431073
min(alloc_len, SDEBUG_LONG_INQ_SZ));
1074+
kfree(arr);
1075+
return ret;
10441076
}
10451077

10461078
static int resp_requests(struct scsi_cmnd * scp,
@@ -1171,6 +1203,87 @@ static int resp_readcap16(struct scsi_cmnd * scp,
11711203
min(alloc_len, SDEBUG_READCAP16_ARR_SZ));
11721204
}
11731205

1206+
#define SDEBUG_MAX_TGTPGS_ARR_SZ 1412
1207+
1208+
static int resp_report_tgtpgs(struct scsi_cmnd * scp,
1209+
struct sdebug_dev_info * devip)
1210+
{
1211+
unsigned char *cmd = (unsigned char *)scp->cmnd;
1212+
unsigned char * arr;
1213+
int host_no = devip->sdbg_host->shost->host_no;
1214+
int n, ret, alen, rlen;
1215+
int port_group_a, port_group_b, port_a, port_b;
1216+
1217+
alen = ((cmd[6] << 24) + (cmd[7] << 16) + (cmd[8] << 8)
1218+
+ cmd[9]);
1219+
1220+
arr = kzalloc(SDEBUG_MAX_TGTPGS_ARR_SZ, GFP_KERNEL);
1221+
/*
1222+
* EVPD page 0x88 states we have two ports, one
1223+
* real and a fake port with no device connected.
1224+
* So we create two port groups with one port each
1225+
* and set the group with port B to unavailable.
1226+
*/
1227+
port_a = 0x1; /* relative port A */
1228+
port_b = 0x2; /* relative port B */
1229+
port_group_a = (((host_no + 1) & 0x7f) << 8) +
1230+
(devip->channel & 0x7f);
1231+
port_group_b = (((host_no + 1) & 0x7f) << 8) +
1232+
(devip->channel & 0x7f) + 0x80;
1233+
1234+
/*
1235+
* The asymmetric access state is cycled according to the host_id.
1236+
*/
1237+
n = 4;
1238+
if (0 == scsi_debug_vpd_use_hostno) {
1239+
arr[n++] = host_no % 3; /* Asymm access state */
1240+
arr[n++] = 0x0F; /* claim: all states are supported */
1241+
} else {
1242+
arr[n++] = 0x0; /* Active/Optimized path */
1243+
arr[n++] = 0x01; /* claim: only support active/optimized paths */
1244+
}
1245+
arr[n++] = (port_group_a >> 8) & 0xff;
1246+
arr[n++] = port_group_a & 0xff;
1247+
arr[n++] = 0; /* Reserved */
1248+
arr[n++] = 0; /* Status code */
1249+
arr[n++] = 0; /* Vendor unique */
1250+
arr[n++] = 0x1; /* One port per group */
1251+
arr[n++] = 0; /* Reserved */
1252+
arr[n++] = 0; /* Reserved */
1253+
arr[n++] = (port_a >> 8) & 0xff;
1254+
arr[n++] = port_a & 0xff;
1255+
arr[n++] = 3; /* Port unavailable */
1256+
arr[n++] = 0x08; /* claim: only unavailalbe paths are supported */
1257+
arr[n++] = (port_group_b >> 8) & 0xff;
1258+
arr[n++] = port_group_b & 0xff;
1259+
arr[n++] = 0; /* Reserved */
1260+
arr[n++] = 0; /* Status code */
1261+
arr[n++] = 0; /* Vendor unique */
1262+
arr[n++] = 0x1; /* One port per group */
1263+
arr[n++] = 0; /* Reserved */
1264+
arr[n++] = 0; /* Reserved */
1265+
arr[n++] = (port_b >> 8) & 0xff;
1266+
arr[n++] = port_b & 0xff;
1267+
1268+
rlen = n - 4;
1269+
arr[0] = (rlen >> 24) & 0xff;
1270+
arr[1] = (rlen >> 16) & 0xff;
1271+
arr[2] = (rlen >> 8) & 0xff;
1272+
arr[3] = rlen & 0xff;
1273+
1274+
/*
1275+
* Return the smallest value of either
1276+
* - The allocated length
1277+
* - The constructed command length
1278+
* - The maximum array size
1279+
*/
1280+
rlen = min(alen,n);
1281+
ret = fill_from_dev_buffer(scp, arr,
1282+
min(rlen, SDEBUG_MAX_TGTPGS_ARR_SZ));
1283+
kfree(arr);
1284+
return ret;
1285+
}
1286+
11741287
/* <<Following mode page info copied from ST318451LW>> */
11751288

11761289
static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target)

‎include/scsi/scsi.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern const unsigned char scsi_command_size[8];
9797
#define PERSISTENT_RESERVE_IN 0x5e
9898
#define PERSISTENT_RESERVE_OUT 0x5f
9999
#define REPORT_LUNS 0xa0
100+
#define MAINTENANCE_IN 0xa3
100101
#define MOVE_MEDIUM 0xa5
101102
#define EXCHANGE_MEDIUM 0xa6
102103
#define READ_12 0xa8
@@ -114,6 +115,8 @@ extern const unsigned char scsi_command_size[8];
114115
#define SERVICE_ACTION_IN 0x9e
115116
/* values for service action in */
116117
#define SAI_READ_CAPACITY_16 0x10
118+
/* values for maintenance in */
119+
#define MI_REPORT_TARGET_PGS 0x0a
117120

118121
/* Values for T10/04-262r7 */
119122
#define ATA_16 0x85 /* 16-byte pass-thru */

0 commit comments

Comments
 (0)