tcmur:fix number of logical blocks is zero in caw command
@@ -1707,6 +1707,19 @@ static int handle_caw(struct tcmu_device *dev, struct tcmulib_cmd *cmd)
struct tcmulib_cmd *readcmd;
size_t half = (tcmu_iovec_length(cmd->iovec, cmd->iov_cnt)) / 2;
struct tcmur_device *rdev = tcmu_get_daemon_dev_private(dev);
+ uint8_t sectors = cmd->cdb[13];
+
+ /* From sbc4r12a section 5.3 COMPARE AND WRITE command
+ * A NUMBER OF LOGICAL BLOCKS field set to zero specifies that no
+ * read operations shall be performed, no logical block data shall
+ * be transferred from the Data-Out Buffer, no compare operations
+ * shall be performed, and no write operations shall be performed.
+ * This condition shall not be considered an error.
+ */
+ if (!sectors) {
+ tcmu_dev_dbg(dev, "NUMBER OF LOGICAL BLOCKS is zero, just return ok.\n");
+ return TCMU_STS_OK;
+ }
ret = handle_caw_check(dev, cmd);
if (ret)
@@ -1748,6 +1761,19 @@ int tcmur_handle_caw(struct tcmu_device *dev, struct tcmulib_cmd *cmd,
tcmur_caw_fn_t caw_fn)
{
int ret;
+ uint8_t sectors = cmd->cdb[13];
+
+ /* From sbc4r12a section 5.3 COMPARE AND WRITE command
+ * A NUMBER OF LOGICAL BLOCKS field set to zero specifies that no
+ * read operations shall be performed, no logical block data shall
+ * be transferred from the Data-Out Buffer, no compare operations
+ * shall be performed, and no write operations shall be performed.
+ * This condition shall not be considered an error.
+ */
+ if (!sectors) {
+ tcmu_dev_dbg(dev, "NUMBER OF LOGICAL BLOCKS is zero, just return ok.\n");
+ return TCMU_STS_OK;
+ }
ret = alua_check_state(dev, cmd);
if (ret)
