Skip to content

Commit b92fcfc

Browse files
ddissmartinkpetersen
authored andcommitted
scsi: target: use the stack for XCOPY passthrough cmds
Reads and writes in the XCOPY loop are synchronous, so needn't be heap allocated / freed with each loop. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: David Disseldorp <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 5f306af commit b92fcfc

File tree

2 files changed

+31
-58
lines changed

2 files changed

+31
-58
lines changed

drivers/target/target_core_xcopy.c

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ static void xcopy_pt_release_cmd(struct se_cmd *se_cmd)
410410
struct xcopy_pt_cmd *xpt_cmd = container_of(se_cmd,
411411
struct xcopy_pt_cmd, se_cmd);
412412

413-
kfree(xpt_cmd);
413+
/* xpt_cmd is on the stack, nothing to free here */
414+
pr_debug("xpt_cmd done: %p\n", xpt_cmd);
414415
}
415416

416417
static int xcopy_pt_check_stop_free(struct se_cmd *se_cmd)
@@ -566,20 +567,15 @@ static int target_xcopy_read_source(
566567
sector_t src_lba,
567568
u32 src_sectors)
568569
{
569-
struct xcopy_pt_cmd *xpt_cmd;
570-
struct se_cmd *se_cmd;
570+
struct xcopy_pt_cmd xpt_cmd;
571+
struct se_cmd *se_cmd = &xpt_cmd.se_cmd;
571572
u32 length = (src_sectors * src_dev->dev_attrib.block_size);
572573
int rc;
573574
unsigned char cdb[16];
574575
bool remote_port = (xop->op_origin == XCOL_DEST_RECV_OP);
575576

576-
xpt_cmd = kzalloc(sizeof(struct xcopy_pt_cmd), GFP_KERNEL);
577-
if (!xpt_cmd) {
578-
pr_err("Unable to allocate xcopy_pt_cmd\n");
579-
return -ENOMEM;
580-
}
581-
init_completion(&xpt_cmd->xpt_passthrough_sem);
582-
se_cmd = &xpt_cmd->se_cmd;
577+
memset(&xpt_cmd, 0, sizeof(xpt_cmd));
578+
init_completion(&xpt_cmd.xpt_passthrough_sem);
583579

584580
memset(&cdb[0], 0, 16);
585581
cdb[0] = READ_16;
@@ -589,28 +585,24 @@ static int target_xcopy_read_source(
589585
(unsigned long long)src_lba, src_sectors, length);
590586

591587
transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, length,
592-
DMA_FROM_DEVICE, 0, &xpt_cmd->sense_buffer[0]);
593-
xop->src_pt_cmd = xpt_cmd;
588+
DMA_FROM_DEVICE, 0, &xpt_cmd.sense_buffer[0]);
594589

595-
rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, src_dev, &cdb[0],
590+
rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, src_dev, &cdb[0],
596591
remote_port);
597592
if (rc < 0) {
598-
ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
599-
transport_generic_free_cmd(se_cmd, 0);
600-
return rc;
593+
ec_cmd->scsi_status = se_cmd->scsi_status;
594+
goto out;
601595
}
602596

603597
pr_debug("XCOPY-READ: Saved xop->xop_data_sg: %p, num: %u for READ"
604598
" memory\n", xop->xop_data_sg, xop->xop_data_nents);
605599

606-
rc = target_xcopy_issue_pt_cmd(xpt_cmd);
607-
if (rc < 0) {
608-
ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
609-
transport_generic_free_cmd(se_cmd, 0);
610-
return rc;
611-
}
612-
613-
return 0;
600+
rc = target_xcopy_issue_pt_cmd(&xpt_cmd);
601+
if (rc < 0)
602+
ec_cmd->scsi_status = se_cmd->scsi_status;
603+
out:
604+
transport_generic_free_cmd(se_cmd, 0);
605+
return rc;
614606
}
615607

616608
static int target_xcopy_write_destination(
@@ -620,20 +612,15 @@ static int target_xcopy_write_destination(
620612
sector_t dst_lba,
621613
u32 dst_sectors)
622614
{
623-
struct xcopy_pt_cmd *xpt_cmd;
624-
struct se_cmd *se_cmd;
615+
struct xcopy_pt_cmd xpt_cmd;
616+
struct se_cmd *se_cmd = &xpt_cmd.se_cmd;
625617
u32 length = (dst_sectors * dst_dev->dev_attrib.block_size);
626618
int rc;
627619
unsigned char cdb[16];
628620
bool remote_port = (xop->op_origin == XCOL_SOURCE_RECV_OP);
629621

630-
xpt_cmd = kzalloc(sizeof(struct xcopy_pt_cmd), GFP_KERNEL);
631-
if (!xpt_cmd) {
632-
pr_err("Unable to allocate xcopy_pt_cmd\n");
633-
return -ENOMEM;
634-
}
635-
init_completion(&xpt_cmd->xpt_passthrough_sem);
636-
se_cmd = &xpt_cmd->se_cmd;
622+
memset(&xpt_cmd, 0, sizeof(xpt_cmd));
623+
init_completion(&xpt_cmd.xpt_passthrough_sem);
637624

638625
memset(&cdb[0], 0, 16);
639626
cdb[0] = WRITE_16;
@@ -643,25 +630,21 @@ static int target_xcopy_write_destination(
643630
(unsigned long long)dst_lba, dst_sectors, length);
644631

645632
transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, length,
646-
DMA_TO_DEVICE, 0, &xpt_cmd->sense_buffer[0]);
647-
xop->dst_pt_cmd = xpt_cmd;
633+
DMA_TO_DEVICE, 0, &xpt_cmd.sense_buffer[0]);
648634

649-
rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, dst_dev, &cdb[0],
635+
rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, dst_dev, &cdb[0],
650636
remote_port);
651637
if (rc < 0) {
652-
ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
653-
transport_generic_free_cmd(se_cmd, 0);
654-
return rc;
655-
}
656-
657-
rc = target_xcopy_issue_pt_cmd(xpt_cmd);
658-
if (rc < 0) {
659-
ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
660-
transport_generic_free_cmd(se_cmd, 0);
661-
return rc;
638+
ec_cmd->scsi_status = se_cmd->scsi_status;
639+
goto out;
662640
}
663641

664-
return 0;
642+
rc = target_xcopy_issue_pt_cmd(&xpt_cmd);
643+
if (rc < 0)
644+
ec_cmd->scsi_status = se_cmd->scsi_status;
645+
out:
646+
transport_generic_free_cmd(se_cmd, 0);
647+
return rc;
665648
}
666649

667650
static void target_xcopy_do_work(struct work_struct *work)
@@ -736,20 +719,15 @@ static void target_xcopy_do_work(struct work_struct *work)
736719

737720
rc = target_xcopy_write_destination(ec_cmd, xop, dst_dev,
738721
dst_lba, cur_nolb);
739-
if (rc < 0) {
740-
transport_generic_free_cmd(&xop->src_pt_cmd->se_cmd, 0);
722+
if (rc < 0)
741723
goto out;
742-
}
743724

744725
dst_lba += cur_nolb;
745726
pr_debug("target_xcopy_do_work: Incremented WRITE dst_lba to %llu\n",
746727
(unsigned long long)dst_lba);
747728

748729
copied_nolb += cur_nolb;
749730
nolb -= cur_nolb;
750-
751-
transport_generic_free_cmd(&xop->src_pt_cmd->se_cmd, 0);
752-
transport_generic_free_cmd(&xop->dst_pt_cmd->se_cmd, 0);
753731
}
754732

755733
xcopy_pt_undepend_remotedev(xop);

drivers/target/target_core_xcopy.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ enum xcopy_origin_list {
1818
XCOL_DEST_RECV_OP = 0x02,
1919
};
2020

21-
struct xcopy_pt_cmd;
22-
2321
struct xcopy_op {
2422
int op_origin;
2523

@@ -36,9 +34,6 @@ struct xcopy_op {
3634
unsigned short dtdi;
3735
unsigned short nolb;
3836

39-
struct xcopy_pt_cmd *src_pt_cmd;
40-
struct xcopy_pt_cmd *dst_pt_cmd;
41-
4237
u32 xop_data_bytes;
4338
u32 xop_data_nents;
4439
struct scatterlist *xop_data_sg;

0 commit comments

Comments
 (0)