: Add bs_sg struct device_type_template sg_template and struct backingstore_template->bs_init()
PATCH 2/3 : Add bs_sg struct device_type_template sg_template and struct backingstore_template->bs_init()
From: Nicholas Bellinger <[email protected]>
This patch adds struct device_type_template sg_template to usr/bs_sg.c used for STGT LUN passthrough with the new bs_sg_lu_init() and bs_sg_rw() functions following usr/sbc.c code for TYPE_DISK, but should work for any device type.
It also adds struct bs_sg_init() that is called from existing usr/target.c:tgt_device_create() code via struct backingstore_template->bs_init() in order to setup the passthrough specific queue and completion handlers for struct scsi_lu->cmd_perform() and ->cmd_done().
--- usr/bs_sg.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 69 insertions(+), 0 deletions(-)
usr/bs_sg.c +69 -0
@@ -38,9 +38,12 @@#include "util.h" #include "tgtd.h" #include "scsi.h" +#include "spc.h" +#include "tgtadm_error.h" #define BS_SG_RESVD_SZ (512 * 1024)#define BS_SG_TIMEOUT 2000 +#define BS_SG_SHIFT 9static int graceful_read (int fd,void *p_read,int to_read) {
@@ -82,6 +85,32 @@ static int graceful_write(int fd, void *p_write, int to_write)return 0 ; } +static int bs_sg_rw (int host_no,struct scsi_cmd *cmd) +{ +int ret; +unsigned char key =ILLEGAL_REQUEST ; +uint16_t asc =ASC_LUN_NOT_SUPPORTED ; + + cmd->scsi_cmd_done = target_cmd_io_done; + + cmd->offset = (scsi_rw_offset (cmd->scb) <<BS_SG_SHIFT ); + ret = cmd->dev->bst->bs_cmd_submit (cmd); +if (ret) { + key =HARDWARE_ERROR ; + asc =ASC_INTERNAL_TGT_FAILURE ; + }else { +set_cmd_mmapio (cmd); +return SAM_STAT_GOOD ; + } + + cmd->offset =0 ; +scsi_set_in_resid_by_actual (cmd,0 ); +scsi_set_out_resid_by_actual (cmd,0 ); + +sense_data_build (cmd, key, asc); +return SAM_STAT_CHECK_CONDITION ; +} +static void set_cmd_failed (struct scsi_cmd *cmd) {int result =SAM_STAT_CHECK_CONDITION ;
@@ -192,6 +221,25 @@ static int init_sg_device(int fd)return 0 ; } +static int bs_sg_init (struct scsi_lu *lu) +{ +/* +* Setup struct scsi_lu->cmd_perform() passthrough pointer +* (if available) for the underlying device type. +*/ + lu->cmd_perform = &target_cmd_perform_passthrough; +if (!(lu->cmd_perform)) { +eprintf ("Unable to locate lu->cmd_perform() for bs_sg\n" ); +return -1 ; + } +/* +* Setup struct scsi_lu->cmd_done() passthrough pointer using +* usr/target.c:__cmd_done_passthrough(). +*/ + lu->cmd_done = &__cmd_done_passthrough; +return 0 ; +} +static int bs_sg_open (struct scsi_lu *lu,char *path,int *fd,uint64_t *size) {int sg_fd, err;
@@ -235,16 +283,37 @@ static int bs_sg_cmd_done(struct scsi_cmd *cmd)return 0 ; } +static int bs_sg_lu_init (struct scsi_lu *lu) +{ +if (spc_lu_init (lu)) +return TGTADM_NOMEM ; + +return 0 ; +} +static struct backingstore_template sg_bst = { .bs_name ="sg" , .bs_datasize =0 , + .bs_passthrough =1 , + .bs_init = bs_sg_init, .bs_open = bs_sg_open, .bs_close = bs_sg_close, .bs_cmd_submit = bs_sg_cmd_submit, .bs_cmd_done = bs_sg_cmd_done, }; +static struct device_type_template sg_template = { + .type =0 , + .lu_init = bs_sg_lu_init, + .lu_config = spc_lu_config, + .lu_online = spc_lu_online, + .lu_offline = spc_lu_offline, + .lu_exit = spc_lu_exit, + .cmd_passthrough = bs_sg_rw, +}; + __attribute__((constructor))static void bs_sg_constructor (void ) {register_backingstore_template (&sg_bst); +device_type_register (&sg_template); }
Signature · 1 line
1.5.6.5
Quoted 35 lines · On Sun, 6 Jun 2010 20:50:32 -0700 "Nicholas A. Bellinger"…
From: Nicholas Bellinger <[email protected]>
This patch adds struct
device_type_templatesg_templatetousr/bs_sg.cused for STGT LUN passthrough with the newbs_sg_lu_init()andbs_sg_rw()functions followingusr/sbc.ccode forTYPE_DISK, but should work for any device type.It also adds struct
bs_sg_init()that is called from existing usr/target.c:tgt_device_create() code via structbackingstore_template->bs_init()in order to setup the passthrough specific queue and completion handlers for structscsi_lu->cmd_perform()and ->cmd_done().Signed-off-by Nicholas A. Bellinger <[email protected]>--- usr/bs_sg.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 69 insertions(+), 0 deletions(-)usr/bs_sg.c +3
-0@@ -38,9 +38,12 @@#include "util.h" #include "tgtd.h" #include "scsi.h" +#include "spc.h" +#include "tgtadm_error.h" #define BS_SG_RESVD_SZ (512 * 1024)#define BS_SG_TIMEOUT 2000 +#define BS_SG_SHIFT 9static int graceful_read (int fd,void *p_read,int to_read) {@@ -82,6 +85,32 @@ static int graceful_write(int fd, void *p_write, int to_write)return 0 ; }
usr/bs_sg.c static int graceful_write(int fd, void *p_write, int to_write) · line 96
Quoted 10 lines
usr/bs_sg.c +9
-0+static int bs_sg_rw (int host_no,struct scsi_cmd *cmd) +{ +int ret; +unsigned char key =ILLEGAL_REQUEST ; +uint16_t asc =ASC_LUN_NOT_SUPPORTED ; + + cmd->scsi_cmd_done = target_cmd_io_done; + + cmd->offset = (scsi_rw_offset (cmd->scb) <<BS_SG_SHIFT );
No need for passthough, I think.
usr/bs_sg.c static int graceful_write(int fd, void *p_write, int to_write) · line 102
Quoted 6 lines
usr/bs_sg.c +6
-0+ ret = cmd->dev->bst->bs_cmd_submit (cmd); +if (ret) { + key =HARDWARE_ERROR ; + asc =ASC_INTERNAL_TGT_FAILURE ; + }else { +set_cmd_mmapio (cmd);
This is wrong since this code doesn't mmap io. We can just remove this.
Quoted 55 lines
usr/bs_sg.c +38
-0+return SAM_STAT_GOOD ; + } + + cmd->offset =0 ; +scsi_set_in_resid_by_actual (cmd,0 ); +scsi_set_out_resid_by_actual (cmd,0 ); + +sense_data_build (cmd, key, asc); +return SAM_STAT_CHECK_CONDITION ; +} +static void set_cmd_failed (struct scsi_cmd *cmd) {int result =SAM_STAT_CHECK_CONDITION ;@@ -192,6 +221,25 @@ static int init_sg_device(int fd)return 0 ; } +static int bs_sg_init (struct scsi_lu *lu) +{ +/* +* Setup struct scsi_lu->cmd_perform() passthrough pointer +* (if available) for the underlying device type. +*/ + lu->cmd_perform = &target_cmd_perform_passthrough; +if (!(lu->cmd_perform)) { +eprintf ("Unable to locate lu->cmd_perform() for bs_sg\n" ); +return -1 ; + } +/* +* Setup struct scsi_lu->cmd_done() passthrough pointer using +* usr/target.c:__cmd_done_passthrough(). +*/ + lu->cmd_done = &__cmd_done_passthrough; +return 0 ; +} +static int bs_sg_open (struct scsi_lu *lu,char *path,int *fd,uint64_t *size) {int sg_fd, err;@@ -235,16 +283,37 @@ static int bs_sg_cmd_done(struct scsi_cmd *cmd)return 0 ; } +static int bs_sg_lu_init (struct scsi_lu *lu) +{ +if (spc_lu_init (lu)) +return TGTADM_NOMEM ; + +return 0 ; +} +static struct backingstore_template sg_bst = { .bs_name ="sg" , .bs_datasize =0 ,
usr/bs_sg.c static int bs_sg_cmd_done(struct scsi_cmd *cmd) · line 306
Quoted 10 lines
usr/bs_sg.c +4
-0+ .bs_passthrough = 1, + .bs_init = bs_sg_init, .bs_open = bs_sg_open, .bs_close = bs_sg_close, .bs_cmd_submit = bs_sg_cmd_submit, .bs_cmd_done = bs_sg_cmd_done, }; +static struct device_type_template sg_template = { + .type =0 ,
Let's create a new type to simplify things (e.g. we can avoid adding sg_bst->bs_passthrough).