Skip to content

Instantly share code, notes, and snippets.

@thejhh
Created August 25, 2011 18:56
Show Gist options
  • Save thejhh/1171476 to your computer and use it in GitHub Desktop.
Save thejhh/1171476 to your computer and use it in GitHub Desktop.
Unmake iSCSI targets

This script only prints the commands needed to uninitialize a iSCSI target in OpenSolaris based OS.

Run it like ./unsharedataset.sh storage/iscsi/nor-atlas:

+ test -n storage/iscsi/nor-atlas
+ test -n 600144F06FD5CE0000004DC06C000003
+ test -n iqn.1986-03.com.sun:02:55514a4d-a70c-c4ae-a26d-f9a7a665e8ef
+ test xiqn.1986-03.com.sun:02:55514a4d-a70c-c4ae-a26d-f9a7a665e8ef != x-
----
ds target
storage/iscsi/nor-atlas iqn.1986-03.com.sun:02:55514a4d-a70c-c4ae-a26d-f9a7a665e8ef
----
stmfadm offline-target iqn.1986-03.com.sun:02:55514a4d-a70c-c4ae-a26d-f9a7a665e8ef
itadm delete-target iqn.1986-03.com.sun:02:55514a4d-a70c-c4ae-a26d-f9a7a665e8ef
zfs set fi.f-solutions:iqn=- storage/iscsi/nor-atlas
stmfadm remove-tg-member -g storage/iscsi/nor-atlas iqn.1986-03.com.sun:02:55514a4d-a70c-c4ae-a26d-f9a7a665e8ef
stmfadm delete-lu 600144F06FD5CE0000004DC06C000003
stmfadm delete-tg storage/iscsi/nor-atlas
----
#!/bin/sh
# Source Code: https://gist.github.com/1171476
# Author: JHH
set -e
ds="$1"
lu="$(stmfadm list-lu -v|ggrep -E '(LU Name:|Alias)'|sed -re 's/^[^:]+: *//'|tr '\n' ','|sed -re 's/,([0-9])/,|\1/g'|tr '|' '\n'|tr '\t' ' '|grep -F ",$ds,"|awk -F, '{print $1}')"
target="$(zfs list -H -o name,fi.f-solutions:iqn -S referenced -t volume -r storage/iscsi|tr '\t' ' '|grep -F "$ds "|awk '{print $2}')"
set -x
test -n "$ds"
test -n "$lu"
test -n "$target"
test x"$target" != x-
set +x
echo ----
echo 'ds target'
zfs list -H -o name,fi.f-solutions:iqn -S referenced -t volume -r storage/iscsi|tr '\t' ' '|grep -F "$ds "
echo ----
echo stmfadm offline-target "$target"
echo itadm delete-target "$target"
echo zfs set fi.f-solutions:iqn=- "$ds"
echo stmfadm remove-tg-member -g "$ds" "$target"
echo stmfadm delete-lu "$lu"
echo stmfadm delete-tg "$ds"
echo ----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment