[Stgt-devel] [PATCH] Make changes so that VTL stuff works properly ...
Mark Harvey
markh794
Tue Jul 29 04:49:27 CEST 2008
Richard Sharpe wrote:
>>From a16d368a29298170df2c21fd19d8490c248f06b1 Mon Sep 17 00:00:00 2001
> From: Richard Sharpe <realrichardsharpe at gmail.com>
> Date: Mon, 28 Jul 2008 14:34:12 -0700
> Subject: [PATCH] Make changes so that VTL stuff works properly ...
> Signed-off-by: Richard Sharpe <realrichardsharpe at gmail.com>
>
> There are three changes here.
>
> In target.h I expose device_lookup for use by the smc.c code.
>
> In target.h I modify tgt_device_path_update so that we can call it to
> both open and close a file that has been allocated to a
> data_transfer_station.
>
> In smc.c I modified set_slot_full and set_slot_empty to call the
> modified tgt_device_path_update to achieve my goals. We call
> device_lookup to figure out the device we are interested in.
>
> I have tested this by loading and unloading tapes and DVDs, doing tar
> to the drive and using cdrecord on the device, and verifying with lsof
> that the tgtd has the files open when they are in the transfer station
> and does not have them open when the station has been unloaded.
>
> It all seems to work. I have attached the patch as well because gmail
> seems to kill patches ... I hope the attached patch is OK.
Sorry, I don't quite understand the reason for this patch.
The smc already calls a non-static dtd_load_unload() which performs a similar function to tgt_device_path_update() but with different args.
int dtd_load_unload(int tid, uint64_t lun, int load, char *file)
vs
int tgt_device_path_update(struct target *target, struct scsi_lu *lu, char *path)
i.e. dtd_load_unload calls __device_lookup() and then opens/closes the backing store.
All this patch seems to do is call the 'open' or 'close' backing store twice.
Perhaps 'fixing' dtd_load_unload() so it then calls tgt_device_path_update() if this function is not correct.
FWIW: dtd_load_unload == Data Transfer Device load/unload
At the time this function was added, the tgt_device_path_update() did not exist.
Cheers
Mark
>
> ---
> usr/smc.c | 34 ++++++++++++++++++++++++----------
> usr/target.c | 15 ++++++++++-----
> usr/target.h | 2 ++
> 3 files changed, 36 insertions(+), 15 deletions(-)
>
> diff --git a/usr/smc.c b/usr/smc.c
> index 9d7f681..0848101 100644
> --- a/usr/smc.c
> +++ b/usr/smc.c
> @@ -47,12 +47,18 @@
> #include "smc.h"
> #include "media.h"
>
> -static int set_slot_full(struct slot *s, uint16_t src, char *path)
> +static int set_slot_full(struct target *target, struct slot *s, uint16_t src, c
> har *path)
> {
> int err = 0;
>
> - if (path)
> - err = dtd_load_unload(s->drive_tid, s->drive_lun, LOAD, path);
> + if (path) {
> + struct scsi_lu *lu = device_lookup(target, s->drive_lun);
> +
> + if (!lu)
> + return 1; /* we could not find the LU ... */
> +
> + err = tgt_device_path_update(target, lu, path);
> + }
> if (err)
> return err;
>
> @@ -62,13 +68,20 @@ static int set_slot_full(struct slot *s, uint16_t src, char
> *path)
> return err;
> }
>
> -static void set_slot_empty(struct slot *s)
> +static void set_slot_empty(struct target *target, struct slot *s)
> {
> s->status &= 0xfe;
> s->last_addr = 0;
> memset(s->barcode, ' ', sizeof(s->barcode));
> - if (s->element_type == ELEMENT_DATA_TRANSFER)
> - dtd_load_unload(s->drive_tid, s->drive_lun, UNLOAD, NULL);
> +
> + if (s->element_type == ELEMENT_DATA_TRANSFER) {
> + struct scsi_lu *lu = device_lookup(target, s->drive_lun);
> +
> + if (!lu)
> + return 1; /* we could not find the LU ... */
> +
> + (void)tgt_device_path_update(target, lu, NULL);
> + }
> }
>
> static int test_slot_full(struct slot *s)
> @@ -355,6 +368,7 @@ sense:
> static int smc_move_medium(int host_no, struct scsi_cmd *cmd)
> {
> struct smc_info *smc = dtype_priv(cmd->dev);
> + struct target *tgt = cmd->c_target;
> uint8_t *scb;
> uint16_t src;
> uint16_t dest;
> @@ -410,15 +424,15 @@ static int smc_move_medium(int host_no, struct scsi_cmd *c
> md)
> goto sense;
> }
>
> - if (set_slot_full(dest_slot, src, path)) {
> + if (set_slot_full(tgt, dest_slot, src, path)) {
> key = HARDWARE_ERROR;
> asc = ASC_MECHANICAL_POSITIONING_ERROR;
> goto sense;
> }
> } else
> - set_slot_full(dest_slot, src, NULL);
> + set_slot_full(tgt, dest_slot, src, NULL);
>
> - set_slot_empty(src_slot);
> + set_slot_empty(tgt, src_slot);
>
> scsi_set_in_resid_by_actual(cmd, 0);
> return SAM_STAT_GOOD;
> @@ -626,7 +640,7 @@ static int config_slot(struct scsi_lu *lu, struct tmp_param
> *tmp)
> if (!s)
> break; // Slot not found..
> strncpy(s->barcode, tmp->barcode, sizeof(s->barcode));
> - set_slot_full(s, 0, NULL);
> + set_slot_full(lu->tgt, s, 0, NULL);
> ret = TGTADM_SUCCESS;
> break;
> case ELEMENT_DATA_TRANSFER:
> diff --git a/usr/target.c b/usr/target.c
> index 7abaa54..863ec9b 100644
> --- a/usr/target.c
> +++ b/usr/target.c
> @@ -297,7 +297,7 @@ int it_nexus_destroy(int tid, uint64_t itn_id)
> return 0;
> }
>
> -static struct scsi_lu *device_lookup(struct target *target, uint64_t lun)
> +struct scsi_lu *device_lookup(struct target *target, uint64_t lun)
> {
> struct scsi_lu *lu;
>
> @@ -347,7 +347,7 @@ int tgt_device_path_update(struct target *target, struct scs
> i_lu *lu, char *path
> uint64_t size;
>
> if (lu->path) {
> - if (lu->attrs.online)
> + if (path && lu->attrs.online)
> return TGTADM_INVALID_REQUEST;
>
> lu->dev_type_template.lu_offline(lu);
> @@ -359,6 +359,10 @@ int tgt_device_path_update(struct target *target, struct sc
> si_lu *lu, char *path
> lu->path = NULL;
> }
>
> + /* Were we called to close the file? */
> + if (!path)
> + return 0;
> +
> path = strdup(path);
> if (!path)
> return TGTADM_NOMEM;
> @@ -418,7 +422,7 @@ int tgt_device_create(int tid, int dev_type, uint64_t lun, c
> har *params,
> struct it_nexus_lu_info *itn_lu;
> struct it_nexus *itn;
>
> - dprintf("%d %" PRIu64 "\n", tid, lun);
> + eprintf("%d %" PRIu64 " params: %s\n", tid, lun, params);
>
> while ((p = strsep(¶ms, ",")) != NULL) {
> substring_t args[MAX_OPT_ARGS];
> @@ -452,8 +456,9 @@ int tgt_device_create(int tid, int dev_type, uint64_t lun, c
> har *params,
> }
>
> bst = target->bst;
> - if (backing) {
> + /*if (backing) {*/
> if (bstype) {
> + eprintf("backing store trying: %s\n", bstype);
> bst = get_backingstore_template(bstype);
> if (!bst) {
> eprintf("failed to find bstype, %s\n", bstype);
> @@ -461,7 +466,7 @@ int tgt_device_create(int tid, int dev_type, uint64_t lun, c
> har *params,
> goto out;
> }
> }
> - }
> + /*}*/
>
> t = device_type_lookup(dev_type);
> if (!t) {
> diff --git a/usr/target.h b/usr/target.h
> index 8fe30aa..4d4768a 100644
> --- a/usr/target.h
> +++ b/usr/target.h
> @@ -87,4 +87,6 @@ static inline int queue_active(const struct tgt_cmd_queue *q)
> \
> QUEUE_FNS(BLOCKED, blocked)
> QUEUE_FNS(DELETED, deleted)
>
> +struct scsi_lu *device_lookup(struct target *target, uint64_t lun);
> +
> #endif
> --
> 1.5.5.1
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Stgt-devel mailing list
> Stgt-devel at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/stgt-devel
More information about the stgt
mailing list