# Create a target
<target iqn.2007-03:virtual-tape:hostname>

# Create a tape drive and give it a nice name
# The tape starts out without a backing store file, i.e. no tape loaded
  <backing-store NONE:0>
    lun 1
    device-type tape
    vendor_id   IBM
    product_id  ULT3580-TD8
    product_rev 2160
    scsi_sn     XYZZY_1
    removable   1
  </backing-store>

  <backing-store NONE:1>
    lun 2
    device-type tape
    vendor_id   IBM
    product_id  ULT3580-TD8
    product_rev 2160
    scsi_sn     XYZZY_2
    removable   1
  </backing-store>

# We need a backing store file for the media changer
#dd if=/dev/zero of=$HOME/smc bs=1k count=1

# Create the SMC device and give it a nice name
  <backing-store /root/smc>
    lun 3
    device-type changer
    vendor_id   STK
    product_id  L700
    product_rev 0010
    scsi_sn     XYZZY_0
    removable   1

# Add a Data Transfer devices (2 drives)
    params element_type=4,start_address=1,quantity=2

# Specify that the TAPEs above (LUN 1/2) are the data transfer devices we created
    params element_type=4,address=1,tid=${tid},lun=1
    params element_type=4,address=2,tid=${tid},lun=2

# Medium Transport Elements (robot arm / picker)
    params element_type=1,start_address=16,quantity=1

# define path to virtual media
    params media_home=/root/media

# Storage Elements - 8 starting at addr 1024
    params element_type=2,start_address=1024,quantity=8

# Add 'media' to slots 1-3 and leave the other 5 slots empty
# slot 1
    params element_type=2,address=1024,barcode=tape001
# slot 2
    params element_type=2,address=1025,barcode=tape002
# slot 3
    params element_type=2,address=1026,barcode=tape003

  </backing-store>

</target>

# VTL=${HOME}/media
# mkdir -p ${VTL}
# Create empty writeable virtual tape media
# Note that despite the parameter names, barcode above that adds the media must match the filename here, not the barcode.
# tgtimg --op new --device-type tape --type data --barcode A000001 --size 100M --file ${VTL}/tape001
# tgtimg --op new --device-type tape --type data --barcode A000002 --size 100M --file ${VTL}/tape002
# tgtimg --op new --device-type tape --type data --barcode A000003 --size 100M --file ${VTL}/tape003

# This must exist but isn't otherwise used.
# dd if=/dev/zero of=$HOME/smc bs=1k count=1

# iscsiadm --mode discovery --type sendtargets --portal ${iscsi_host} --op update
# iscsiadm --mode node --targetname iqn.2007-03:virtual-tape:hostname --portal ${iscsi_host} --login

# changer=$( readlink -f /dev/tape/by-path/*-iscsi-iqn.2007-03:virtual-tape:hostname-lun-3-changer )
# tape0=$( readlink -f /dev/tape/by-path/*-iscsi-iqn.2007-03:virtual-tape:hostname-lun-1 )
# tape1=$( readlink -f /dev/tape/by-path/*-iscsi-iqn.2007-03:virtual-tape:hostname-lun-2 )

# mtx -f "$changer" status

# Load tape from storage bay 1 into drive 0
# mtx -f "$changer" load 1 0

# Write 4 x 1K blocks to the rewinding device
# dd if=/dev/zero of="$tape0" bs=1k count=4

# Unload tape from drive 0 into storage bay 4 and then load it into drive 1
# mtx -f "$changer" unload 4 0
# mtx -f "$changer" load 4 1

# Read 7 x 4k blocks from the rewinding device (Reads the 4x1K blocks that we wrote)
# dd if="$tape1" bs=4k count=7

# iscsiadm --mode node --targetname iqn.2007-03:virtual-tape:hostname --portal ${iscsi_host} --logout
