summaryrefslogtreecommitdiffstats
path: root/contrib/iscsi-destroy/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/iscsi-destroy/main.go')
-rw-r--r--contrib/iscsi-destroy/main.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/contrib/iscsi-destroy/main.go b/contrib/iscsi-destroy/main.go
new file mode 100644
index 0000000..0227c9d
--- /dev/null
+++ b/contrib/iscsi-destroy/main.go
@@ -0,0 +1,39 @@
+// Source: https://github.com/open-iscsi/open-iscsi/issues/228#issuecomment-715770988
+
+package main
+
+import (
+ "os"
+ "fmt"
+ "strconv"
+ "github.com/u-root/iscsinl"
+)
+
+func main() {
+ ipc, err := iscsinl.ConnectNetlink()
+
+ if err != nil {
+ fmt.Printf("Error connecting to netlink: %s\n", err)
+ return
+ }
+
+ sid, _ := strconv.Atoi(os.Args[1])
+
+ err = ipc.StopConnection(uint32(sid), 0)
+
+ if err != nil {
+ fmt.Printf("Error stopping connection: %s\n", err)
+ }
+
+ err = ipc.DestroyConnection(uint32(sid), 0)
+
+ if err != nil {
+ fmt.Printf("Error destroying connection: %s\n", err)
+ }
+
+ err = ipc.DestroySession(uint32(sid))
+
+ if err != nil {
+ fmt.Printf("Error destroying session: %s\n", err)
+ }
+}