[Stgt-devel] [RFC] target configuration tool?

Tomasz Chmielewski mangoo
Mon Mar 17 11:40:20 CET 2008


Tomasz Chmielewski schrieb:

> Comments (other than "there is such a tool already", which would be just 
> great)?

I made an initial version of such a tool. It is available, with 
additional info, examples and configuration instructions on 
http://wpkg.org/TGT-admin.


Summary:


Right now, TGT does not have any config file nor a configuration tool.

Below is an attempt to create one.


Configuration instructions

First, create a /etc/stgt/targets.conf file similar to the one below:


include /etc/stgt/xen/*.conf
include /etc/stgt/vmware/*.conf
include /etc/stgt/temp/*.conf
 

<target iqn.2007-04.com.example:san.monitoring>
backing-store /dev/san/monitoring
</target>

<target iqn.2007-02.com.example:san.xen1>
backing-store /dev/san/xen1
</target>

<target iqn.2007-02.com.example:san.xen2>
backing-store /dev/san/xen2
</target>

<target iqn.2007-06.com.example:san.vmware1>
backing-store /dev/san/vmware1
</target>


You can include other config files with i.e. "include /etc/stgt/xen/*.conf".


Currently, only one LUN per target is supported.

Right now, it doesn't make any changes in your tgtd configuration - note 
that all tgtadm invocations are prefixed with print. This means, the 
tool will only print what changes would be done - at this stage, I want 
some discussion on how a config tool for TGT should look like.


Adding targets


For each target which is:

* found in /etc/stgt/targets.conf (or any other included config file),
* not configured already

it will print "Adding target" with this target's name, and three tgtadm 
commands which setup the target. For example:

Adding target: iqn.2007-11.com.example:san.rescue-live
tgtadm --lld iscsi --op new --mode target --tid 46 -T 
iqn.2007-11.com.example:san.rescue-live
tgtadm --lld iscsi --op new --mode logicalunit --tid 46 --lun 1 -b 
backing-store /dev/san/rescue-live
tgtadm --lld iscsi --op bind --mode target --tid 46 -I ALL


Removing targets

It will also try to remove the targets which don't exist in the config 
file (which are in "tgtadm --lld iscsi --op show --mode target" output, 
but not in the config file), for example:

Removing target: iqn.2007-04.com.example:san.monitoring
tgtadm --op update --mode target --tid=9 -n state -v offline
tgtadm --mode target --op delete --tid=9

Note that it will not forcibly remove the target if any initiators are 
still connected to it, as tgtadm does not support this feature yet.


And what happens if a target already exists?

If the target is already configured and the tool is started, it will output:

Target iqn.2006-12.com.example:san.backup1 already exists!
Target iqn.2006-12.com.example:san.kolab1 already exists!
Target iqn.2006-12.com.example:san.mysql2 already exists!
Target iqn.2007-01.com.example:san.file1 already exists!
Target iqn.2007-02.com.example:san.xen1 already exists!
Target iqn.2007-02.com.example:san.xen2 already exists!

This means you can safely add or remove any targets in your config file, 
it will be automatically recognized and a proper action will be taken.


Source code

Available on http://wpkg.org/TGT-admin#Source_code


TO DO

If there is any discussion about this tool, more features could be 
implemented:

* more LUNs per target
* allow other configuration options which are possible with tgtadm
* change target configuration if the target is already online, and its 
config changed
* add a proper /etc/init.d/tgt script


-- 
Tomasz Chmielewski




More information about the stgt mailing list