From: Mike Christie <michael.christie@oracle.com>
To: martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
target-devel@vger.kernel.org
Cc: Mike Christie <michael.christie@oracle.com>
Subject: [PATCH 4/7] scsi: target: Add WRITE_ATOMIC_16 handler
Date: Mon, 7 Oct 2024 21:03:13 -0500 [thread overview]
Message-ID: <20241008020437.78788-5-michael.christie@oracle.com> (raw)
In-Reply-To: <20241008020437.78788-1-michael.christie@oracle.com>
This adds the core LIO code to process the WRITE_ATOMIC_16 command.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
drivers/target/target_core_sbc.c | 48 +++++++++++++++++++++++++++++++
include/target/target_core_base.h | 1 +
2 files changed, 49 insertions(+)
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index fe8beb7dbab1..0ae0d4ec0ac3 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -764,6 +764,46 @@ sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb)
return 0;
}
+static int
+sbc_check_atomic(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb)
+{
+ struct se_dev_attrib *attrib = &dev->dev_attrib;
+ u16 boundary, transfer_len;
+ u32 lba;
+
+ if (!attrib->atomic_supported)
+ return TCM_UNSUPPORTED_SCSI_OPCODE;
+
+ lba = transport_lba_32(cdb);
+ boundary = get_unaligned_be16(&cdb[10]);
+ transfer_len = get_unaligned_be16(&cdb[12]);
+
+ if (!boundary) {
+ if (transfer_len > attrib->atomic_max_len)
+ return TCM_INVALID_CDB_FIELD;
+ } else {
+ if (transfer_len > attrib->atomic_max_with_boundary)
+ return TCM_INVALID_CDB_FIELD;
+
+ if (boundary > attrib->atomic_max_boundary)
+ return TCM_INVALID_CDB_FIELD;
+ }
+
+ if (attrib->atomic_granularity) {
+ if (transfer_len % attrib->atomic_granularity)
+ return TCM_INVALID_CDB_FIELD;
+
+ if (boundary && boundary % attrib->atomic_granularity)
+ return TCM_INVALID_CDB_FIELD;
+ }
+
+ if (dev->dev_attrib.atomic_alignment &&
+ lba % dev->dev_attrib.atomic_alignment)
+ return TCM_INVALID_CDB_FIELD;
+
+ return 0;
+}
+
sense_reason_t
sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops)
{
@@ -861,6 +901,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops)
break;
case WRITE_16:
case WRITE_VERIFY_16:
+ case WRITE_ATOMIC_16:
sectors = transport_get_sectors_16(cdb);
cmd->t_task_lba = transport_lba_64(cdb);
@@ -872,6 +913,13 @@ sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops)
return ret;
cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
+ if (cdb[0] == WRITE_ATOMIC_16) {
+ cmd->se_cmd_flags |= SCF_ATOMIC;
+
+ ret = sbc_check_atomic(dev, cmd, cdb);
+ if (ret)
+ return ret;
+ }
cmd->execute_cmd = sbc_execute_rw;
break;
case VARIABLE_LENGTH_CMD:
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 6c87bd018983..7b8ed21bea03 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -157,6 +157,7 @@ enum se_cmd_flags_table {
SCF_USE_CPUID = (1 << 16),
SCF_TASK_ATTR_SET = (1 << 17),
SCF_TREAT_READ_AS_NORMAL = (1 << 18),
+ SCF_ATOMIC = (1 << 19),
};
/*
--
2.34.1
next prev parent reply other threads:[~2024-10-08 2:04 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 2:03 [PATCH 0/7] scsi: target: Add WRITE_ATOMIC_16 support Mike Christie
2024-10-08 2:03 ` [PATCH 1/7] scsi: target: Rename target_configure_unmap_from_queue Mike Christie
2025-05-14 11:11 ` John Garry
2024-10-08 2:03 ` [PATCH 2/7] scsi: target: Add atomic se_device fields Mike Christie
2025-05-14 10:26 ` John Garry
2025-07-20 22:15 ` Mike Christie
2025-07-23 11:28 ` John Garry
2025-07-23 15:10 ` michael.christie
2025-07-23 15:48 ` michael.christie
2025-07-23 16:21 ` John Garry
2025-07-23 19:38 ` michael.christie
2024-10-08 2:03 ` [PATCH 3/7] scsi: target: Add helper to setup atomic values from block_device Mike Christie
2025-05-14 10:29 ` John Garry
2024-10-08 2:03 ` Mike Christie [this message]
2024-10-09 6:10 ` [PATCH 4/7] scsi: target: Add WRITE_ATOMIC_16 handler kernel test robot
2025-05-14 10:47 ` John Garry
2025-07-20 22:44 ` Mike Christie
2024-10-08 2:03 ` [PATCH 5/7] scsi: target: Report atomic values in INQUIRY Mike Christie
2025-05-14 10:56 ` John Garry
2025-07-20 22:42 ` Mike Christie
2024-10-08 2:03 ` [PATCH 6/7] scsi: target: Add WRITE_ATOMIC_16 support to RSOC Mike Christie
2024-10-08 2:03 ` [PATCH 7/7] scsi: target: Add atomic support to target_core_iblock Mike Christie
2025-05-14 11:01 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241008020437.78788-5-michael.christie@oracle.com \
--to=michael.christie@oracle.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).