[PATCH] Make changes so that VTL stuff works properly ...

Richard Sharpe realrichardsharpe
Mon Jul 28 23:34:12 CEST 2008


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.

---
 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(&params, ",")) != 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

------=_Part_14668_12538439.1217282277331
Content-Type: application/octet-stream;
 name=0003-Make-changes-so-that-VTL-stuff-works-properly.patch
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fj7mf6pb0
Content-Disposition: attachment;
 filename=0003-Make-changes-so-that-VTL-stuff-works-properly.patch

RnJvbSBhMTZkMzY4YTI5Mjk4MTcwZGYyYzIxZmQxOWQ4NDkwYzI0OGYwNm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