hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/target/target_core_spc.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * SCSI Primary Commands (SPC) parsing and emulation.
34 *
45 * (c) Copyright 2002-2013 Datera, Inc.
56 *
67 * Nicholas A. Bellinger <nab@kernel.org>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
218 */
229
2310 #include <linux/kernel.h>
....@@ -113,12 +100,14 @@
113100 * unused bytes at the end of the field (i.e., highest offset) and the
114101 * unused bytes shall be filled with ASCII space characters (20h).
115102 */
116
- memset(&buf[8], 0x20, 8 + 16 + 4);
117
- memcpy(&buf[8], "LIO-ORG", sizeof("LIO-ORG") - 1);
103
+ memset(&buf[8], 0x20,
104
+ INQUIRY_VENDOR_LEN + INQUIRY_MODEL_LEN + INQUIRY_REVISION_LEN);
105
+ memcpy(&buf[8], dev->t10_wwn.vendor,
106
+ strnlen(dev->t10_wwn.vendor, INQUIRY_VENDOR_LEN));
118107 memcpy(&buf[16], dev->t10_wwn.model,
119
- strnlen(dev->t10_wwn.model, 16));
108
+ strnlen(dev->t10_wwn.model, INQUIRY_MODEL_LEN));
120109 memcpy(&buf[32], dev->t10_wwn.revision,
121
- strnlen(dev->t10_wwn.revision, 4));
110
+ strnlen(dev->t10_wwn.revision, INQUIRY_REVISION_LEN));
122111 buf[4] = 31; /* Set additional length to 31 */
123112
124113 return 0;
....@@ -257,8 +246,9 @@
257246 buf[off+1] = 0x1; /* T10 Vendor ID */
258247 buf[off+2] = 0x0;
259248 /* left align Vendor ID and pad with spaces */
260
- memset(&buf[off+4], 0x20, 8);
261
- memcpy(&buf[off+4], "LIO-ORG", sizeof("LIO-ORG") - 1);
249
+ memset(&buf[off+4], 0x20, INQUIRY_VENDOR_LEN);
250
+ memcpy(&buf[off+4], dev->t10_wwn.vendor,
251
+ strnlen(dev->t10_wwn.vendor, INQUIRY_VENDOR_LEN));
262252 /* Extra Byte for NULL Terminator */
263253 id_len++;
264254 /* Identifier Length */
....@@ -643,9 +633,9 @@
643633
644634 /*
645635 * The unmap_zeroes_data set means that the underlying device supports
646
- * REQ_DISCARD and has the discard_zeroes_data bit set. This satisfies
647
- * the SBC requirements for LBPRZ, meaning that a subsequent read
648
- * will return zeroes after an UNMAP or WRITE SAME (16) to an LBA
636
+ * REQ_OP_DISCARD and has the discard_zeroes_data bit set. This
637
+ * satisfies the SBC requirements for LBPRZ, meaning that a subsequent
638
+ * read will return zeroes after an UNMAP or WRITE SAME (16) to an LBA
649639 * See sbc4r36 6.6.4.
650640 */
651641 if (((dev->dev_attrib.emulate_tpu != 0) ||
....@@ -857,8 +847,17 @@
857847 * for a BUSY, TASK SET FULL, or RESERVATION CONFLICT status regardless
858848 * to the number of commands completed with one of those status codes.
859849 */
860
- p[4] = (dev->dev_attrib.emulate_ua_intlck_ctrl == 2) ? 0x30 :
861
- (dev->dev_attrib.emulate_ua_intlck_ctrl == 1) ? 0x20 : 0x00;
850
+ switch (dev->dev_attrib.emulate_ua_intlck_ctrl) {
851
+ case TARGET_UA_INTLCK_CTRL_ESTABLISH_UA:
852
+ p[4] = 0x30;
853
+ break;
854
+ case TARGET_UA_INTLCK_CTRL_NO_CLEAR:
855
+ p[4] = 0x20;
856
+ break;
857
+ default: /* TARGET_UA_INTLCK_CTRL_CLEAR */
858
+ p[4] = 0x00;
859
+ break;
860
+ }
862861 /*
863862 * From spc4r17, section 7.4.6 Control mode Page
864863 *
....@@ -1288,6 +1287,14 @@
12881287 struct se_device *dev = cmd->se_dev;
12891288 unsigned char *cdb = cmd->t_task_cdb;
12901289
1290
+ if (!dev->dev_attrib.emulate_pr &&
1291
+ ((cdb[0] == PERSISTENT_RESERVE_IN) ||
1292
+ (cdb[0] == PERSISTENT_RESERVE_OUT) ||
1293
+ (cdb[0] == RELEASE || cdb[0] == RELEASE_10) ||
1294
+ (cdb[0] == RESERVE || cdb[0] == RESERVE_10))) {
1295
+ return TCM_UNSUPPORTED_SCSI_OPCODE;
1296
+ }
1297
+
12911298 switch (cdb[0]) {
12921299 case MODE_SELECT:
12931300 *size = cdb[4];