Skip to content

Commit 31ae956

Browse files
authored
Merge pull request #5 from Seagate/fix/device-mapper
fix: Added device-mapper calls to remove and clear dm
2 parents 81cfbd7 + 3718622 commit 31ae956

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

iscsi/iscsi.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func parseSessions(lines string) []iscsiSession {
105105
}
106106

107107
func sessionExists(tgtPortal, tgtIQN string) (bool, error) {
108+
debug.Printf("Begin sessionExists (%s/%s)...\n", tgtIQN, tgtPortal)
108109
sessions, err := getCurrentSessions()
109110
if err != nil {
110111
return false, err
@@ -147,6 +148,7 @@ func waitForPathToExist(devicePath *string, maxRetries, intervalSeconds int, dev
147148
}
148149

149150
func waitForPathToExistImpl(devicePath *string, maxRetries, intervalSeconds int, deviceTransport string, osStat statFunc, filepathGlob globFunc) (bool, error) {
151+
debug.Printf("waitForPathToExistImpl (%v)", *devicePath)
150152
if devicePath == nil || *devicePath == "" {
151153
return false, fmt.Errorf("unable to check nil or unspecified devicePath")
152154
}
@@ -197,6 +199,8 @@ func getMultipathDisk(path string) (string, error) {
197199
return "", err
198200
}
199201
sdevice := filepath.Base(devicePath)
202+
debug.Printf("-- devicePath=%s, sdevice=%s", devicePath, sdevice)
203+
200204
// If destination directory is already identified as a multipath device,
201205
// just return its path
202206
if strings.HasPrefix(sdevice, "dm-") {
@@ -207,13 +211,14 @@ func getMultipathDisk(path string) (string, error) {
207211
// check to see if any have an entry under /sys/block/dm-*/slaves matching
208212
// the device the symlink was pointing at
209213
dmPaths, err := filepath.Glob("/sys/block/dm-*")
214+
debug.Printf("-- dmPaths=%v", dmPaths)
210215
if err != nil {
211216
debug.Printf("Glob error: %s", err)
212217
return "", err
213218
}
214219
for _, dmPath := range dmPaths {
215220
sdevices, err := filepath.Glob(filepath.Join(dmPath, "slaves", "*"))
216-
debug.Printf("dmPath=%v, sdevices=%v", dmPath, sdevices)
221+
debug.Printf("dmPath=%v/slaves/*, sdevices=%v", dmPath, sdevices)
217222
if err != nil {
218223
debug.Printf("Glob error: %s", err)
219224
}
@@ -224,7 +229,7 @@ func getMultipathDisk(path string) (string, error) {
224229
// We've found a matching entry, return the path for the
225230
// dm-* device it was found under
226231
p := filepath.Join("/dev", filepath.Base(dmPath))
227-
debug.Printf("Found matching multipath device: %s under dm-* device path %s", sdevice, dmPath)
232+
debug.Printf("Found matching multipath device (%s) under dm-* device path (%s), (%v)", sdevice, dmPath, p)
228233
return p, nil
229234
}
230235
}
@@ -236,6 +241,7 @@ func getMultipathDisk(path string) (string, error) {
236241
// Connect attempts to connect a volume to this node using the provided Connector info
237242
func Connect(c *Connector) (string, error) {
238243
var lastErr error
244+
debug.Printf("Begin iSCSI Connect (dDoDiscovery=%v)...\n", c.DoDiscovery)
239245
if c.RetryCount == 0 {
240246
c.RetryCount = 10
241247
}

iscsi/iscsiadm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ func ListInterfaces() ([]string, error) {
8383
// ShowInterface retrieves the details for the specified iscsi interface
8484
// caller should inspect r.Err and use r.StdOut for interface details
8585
func ShowInterface(iface string) (string, error) {
86-
debug.Println("Begin ShowInterface...")
86+
debug.Printf("Begin ShowInterface (%s)...\n", iface)
8787
out, err := iscsiCmd("-m", "iface", "-o", "show", "-I", iface)
8888
return out, err
8989
}
9090

9191
// CreateDBEntry sets up a node entry for the specified tgt in the nodes iscsi nodes db
9292
func CreateDBEntry(tgtIQN, portal, iFace string, discoverySecrets, sessionSecrets Secrets) error {
93-
debug.Println("Begin CreateDBEntry...")
93+
debug.Printf("Begin CreateDBEntry (%s)...\n", portal)
9494
baseArgs := []string{"-m", "node", "-T", tgtIQN, "-p", portal}
9595
_, err := iscsiCmd(append(baseArgs, []string{"-I", iFace, "-o", "new"}...)...)
9696
if err != nil {
@@ -197,7 +197,7 @@ func Logout(tgtIQN string, portals []string) error {
197197
debug.Println("Begin Logout...")
198198
baseArgs := []string{"-m", "node", "-T", tgtIQN}
199199
for _, p := range portals {
200-
debug.Printf("attempting logout for portal: %s", p)
200+
debug.Printf("attempting logout (%s) for portal: %s", tgtIQN, p)
201201
args := append(baseArgs, []string{"-p", p, "-u"}...)
202202
iscsiCmd(args...)
203203
}

iscsi/multipath.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@ func GetSysDevicesFromMultipathDevice(device string) ([]string, error) {
7171
func FlushMultipathDevice(device string) error {
7272
debug.Printf("Flushing multipath device %q\n", device)
7373

74-
fullDevice := device
74+
err := RemoveAndClear(device)
75+
if err != nil {
76+
debug.Printf("device-mapper remove and clear device %q error=%v\n", device, err)
77+
}
78+
7579
timeout := 5 * time.Second
76-
_, err := execWithTimeout("multipath", []string{"-f", fullDevice}, timeout)
80+
_, err = execWithTimeout("multipath", []string{"-f", device}, timeout)
7781

7882
if err != nil {
79-
if _, e := os.Stat(fullDevice); os.IsNotExist(e) {
83+
if _, e := os.Stat(device); os.IsNotExist(e) {
8084
debug.Printf("Multipath device %q was deleted\n", device)
8185
} else {
82-
debug.Printf("Command 'multipath -f %v' did not succeed to delete the device: %v\n", fullDevice, err)
86+
debug.Printf("Command 'multipath -f %v' did not succeed to delete the device: %v\n", device, err)
8387
return err
8488
}
8589
}
@@ -98,3 +102,24 @@ func ResizeMultipathDevice(device string) error {
98102

99103
return nil
100104
}
105+
106+
// RemoveAndClear calls 'dmsetup' to remove and clear a device entry
107+
func RemoveAndClear(device string) error {
108+
debug.Printf("Remove and clear multipath device (%s)\n", device)
109+
110+
// Remove device-mapper logical device
111+
if output, err := execCommand("dmsetup", "remove", "-f", device).CombinedOutput(); err != nil {
112+
return fmt.Errorf("device-mapper could not remove device: %s (%v)", output, err)
113+
}
114+
115+
// Clear out device-mapper logical device if it still exists
116+
if _, e := os.Stat(device); os.IsNotExist(e) {
117+
debug.Printf("device-mapper logical device %q was removed\n", device)
118+
} else {
119+
if output, err := execCommand("dmsetup", "clear", device).CombinedOutput(); err != nil {
120+
return fmt.Errorf("device-mapper could not clear device: %s (%v)", output, err)
121+
}
122+
}
123+
124+
return nil
125+
}

0 commit comments

Comments
 (0)