/* * Returns TCM_NO_SENSE upon success or a sense code != TCM_NO_SENSE if parsing * fails. */ static sense_reason_t target_parse_xcopy_cmd(struct xcopy_op *xop) { struct se_cmd *se_cmd = xop->xop_se_cmd; unsigned char *p = NULL, *seg_desc; unsigned int list_id, list_id_usage, sdll, inline_dl; sense_reason_t ret = TCM_INVALID_PARAMETER_LIST; int rc; unsigned short tdll; p = transport_kmap_data_sg(se_cmd); if (!p) { pr_err("transport_kmap_data_sg() failed in target_do_xcopy\n"); return TCM_OUT_OF_RESOURCES; } list_id = p[0]; list_id_usage = (p[1] & 0x18) >> 3; /* * Determine TARGET DESCRIPTOR LIST LENGTH + SEGMENT DESCRIPTOR LIST LENGTH */ tdll = get_unaligned_be16(&p[2]); sdll = get_unaligned_be32(&p[8]); if (tdll + sdll > RCR_OP_MAX_DESC_LIST_LEN) { pr_err("XCOPY descriptor list length %u exceeds maximum %u\n", tdll + sdll, RCR_OP_MAX_DESC_LIST_LEN); ret = TCM_PARAMETER_LIST_LENGTH_ERROR; goto out; } inline_dl = get_unaligned_be32(&p[12]); if (inline_dl != 0) { pr_err("XCOPY with non zero inline data length\n"); goto out; } if (se_cmd->data_length < (XCOPY_HDR_LEN + tdll + sdll + inline_dl)) { pr_err("XCOPY parameter truncation: data length %u too small " "for tdll: %hu sdll: %u inline_dl: %u\n", se_cmd->data_length, tdll, sdll, inline_dl); ret = TCM_PARAMETER_LIST_LENGTH_ERROR; goto out; } pr_debug("Processing XCOPY with list_id: 0x%02x list_id_usage: 0x%02x" " tdll: %hu sdll: %u inline_dl: %u\n", list_id, list_id_usage, tdll, sdll, inline_dl); /* * skip over the target descriptors until segment descriptors * have been passed - CSCD ids are needed to determine src and dest. */ seg_desc = &p[16] + tdll; rc = target_xcopy_parse_segment_descriptors(se_cmd, xop, seg_desc, sdll, &ret); if (rc <= 0) goto out; pr_debug("XCOPY: Processed %d segment descriptors, length: %u\n", rc, rc * XCOPY_SEGMENT_DESC_LEN); rc = target_xcopy_parse_target_descriptors(se_cmd, xop, &p[16], tdll, &ret); if (rc <= 0) goto out; if (xop->src_dev->dev_attrib.block_size != xop->dst_dev->dev_attrib.block_size) { pr_err("XCOPY: Non matching src_dev block_size: %u + dst_dev" " block_size: %u currently unsupported\n", xop->src_dev->dev_attrib.block_size, xop->dst_dev->dev_attrib.block_size); xcopy_pt_undepend_remotedev(xop); ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; goto out; } pr_debug("XCOPY: Processed %d target descriptors, length: %u\n", rc, rc * XCOPY_TARGET_DESC_LEN); transport_kunmap_data_sg(se_cmd); return TCM_NO_SENSE; out: if (p) transport_kunmap_data_sg(se_cmd); return ret; }
static int iblock_execute_unmap(struct se_cmd *cmd) { struct se_device *dev = cmd->se_dev; struct iblock_dev *ibd = dev->dev_ptr; unsigned char *buf, *ptr = NULL; sector_t lba; int size; u32 range; int ret = 0; int dl, bd_dl; if (cmd->data_length < 8) { pr_warn("UNMAP parameter list length %u too small\n", cmd->data_length); cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST; return -EINVAL; } buf = transport_kmap_data_sg(cmd); dl = get_unaligned_be16(&buf[0]); bd_dl = get_unaligned_be16(&buf[2]); size = cmd->data_length - 8; if (bd_dl > size) pr_warn("UNMAP parameter list length %u too small, ignoring bd_dl %u\n", cmd->data_length, bd_dl); else size = bd_dl; if (size / 16 > dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count) { cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST; ret = -EINVAL; goto err; } /* First UNMAP block descriptor starts at 8 byte offset */ ptr = &buf[8]; pr_debug("UNMAP: Sub: %s Using dl: %u bd_dl: %u size: %u" " ptr: %p\n", dev->transport->name, dl, bd_dl, size, ptr); while (size >= 16) { lba = get_unaligned_be64(&ptr[0]); range = get_unaligned_be32(&ptr[8]); pr_debug("UNMAP: Using lba: %llu and range: %u\n", (unsigned long long)lba, range); if (range > dev->se_sub_dev->se_dev_attrib.max_unmap_lba_count) { cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST; ret = -EINVAL; goto err; } if (lba + range > dev->transport->get_blocks(dev) + 1) { cmd->scsi_sense_reason = TCM_ADDRESS_OUT_OF_RANGE; ret = -EINVAL; goto err; } ret = blkdev_issue_discard(ibd->ibd_bd, lba, range, GFP_KERNEL, 0); if (ret < 0) { pr_err("blkdev_issue_discard() failed: %d\n", ret); goto err; } ptr += 16; size -= 16; } err: transport_kunmap_data_sg(cmd); if (!ret) target_complete_cmd(cmd, GOOD); return ret; }
static sense_reason_t target_rcr_operating_parameters(struct se_cmd *se_cmd) { unsigned char *p; p = transport_kmap_data_sg(se_cmd); if (!p) { pr_err("transport_kmap_data_sg failed in" " target_rcr_operating_parameters\n"); return TCM_OUT_OF_RESOURCES; } if (se_cmd->data_length < 54) { pr_err("Receive Copy Results Op Parameters length" " too small: %u\n", se_cmd->data_length); transport_kunmap_data_sg(se_cmd); return TCM_INVALID_CDB_FIELD; } /* * Set SNLID=1 (Supports no List ID) */ p[4] = 0x1; /* * MAXIMUM TARGET DESCRIPTOR COUNT */ put_unaligned_be16(RCR_OP_MAX_TARGET_DESC_COUNT, &p[8]); /* * MAXIMUM SEGMENT DESCRIPTOR COUNT */ put_unaligned_be16(RCR_OP_MAX_SG_DESC_COUNT, &p[10]); /* * MAXIMUM DESCRIPTOR LIST LENGTH */ put_unaligned_be32(RCR_OP_MAX_DESC_LIST_LEN, &p[12]); /* * MAXIMUM SEGMENT LENGTH */ put_unaligned_be32(RCR_OP_MAX_SEGMENT_LEN, &p[16]); /* * MAXIMUM INLINE DATA LENGTH for SA 0x04 (NOT SUPPORTED) */ put_unaligned_be32(0x0, &p[20]); /* * HELD DATA LIMIT */ put_unaligned_be32(0x0, &p[24]); /* * MAXIMUM STREAM DEVICE TRANSFER SIZE */ put_unaligned_be32(0x0, &p[28]); /* * TOTAL CONCURRENT COPIES */ put_unaligned_be16(RCR_OP_TOTAL_CONCURR_COPIES, &p[34]); /* * MAXIMUM CONCURRENT COPIES */ p[36] = RCR_OP_MAX_CONCURR_COPIES; /* * DATA SEGMENT GRANULARITY (log 2) */ p[37] = RCR_OP_DATA_SEG_GRAN_LOG2; /* * INLINE DATA GRANULARITY log 2) */ p[38] = RCR_OP_INLINE_DATA_GRAN_LOG2; /* * HELD DATA GRANULARITY */ p[39] = RCR_OP_HELD_DATA_GRAN_LOG2; /* * IMPLEMENTED DESCRIPTOR LIST LENGTH */ p[43] = 0x2; /* * List of implemented descriptor type codes (ordered) */ p[44] = 0x02; /* Copy Block to Block device */ p[45] = 0xe4; /* Identification descriptor target descriptor */ /* * AVAILABLE DATA (n-3) */ put_unaligned_be32(42, &p[0]); transport_kunmap_data_sg(se_cmd); target_complete_cmd(se_cmd, GOOD); return TCM_NO_SENSE; }