Skip to content

Commit 8fb98fb

Browse files
committed
fix: refresh dm paths and increase attempts and 30s delay plus additional debug
Signed-off-by: Joe Skazinski <joseph.skazinski@seagate.com>
1 parent 61c966f commit 8fb98fb

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

iscsi/iscsi.go

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import (
1616
"time"
1717
)
1818

19-
const defaultPort = "3260"
19+
const (
20+
defaultPort = "3260"
21+
maxMultipathAttempts = 10
22+
multipathDelay = 30
23+
)
2024

2125
var (
2226
debug *log.Logger
@@ -211,37 +215,42 @@ func getMultipathDisk(path string) (string, error) {
211215
// check to see if any have an entry under /sys/block/dm-*/slaves matching
212216
// the device the symlink was pointing at
213217
attempts := 1
214-
dmPaths, err := filepath.Glob("/sys/block/dm-*")
215-
for attempts < 4 {
216-
debug.Printf("[%d] dmPaths=%v", attempts, dmPaths)
217-
if err != nil {
218-
debug.Printf("Glob error: %s", err)
219-
return "", err
220-
}
221-
if len(dmPaths) > 0 {
222-
break
223-
}
224-
time.Sleep(1 * time.Second)
225-
attempts++
218+
var dmPaths []string
219+
220+
for attempts < (maxMultipathAttempts + 1) {
221+
var err error
226222
dmPaths, err = filepath.Glob("/sys/block/dm-*")
227-
}
228-
for _, dmPath := range dmPaths {
229-
sdevices, err := filepath.Glob(filepath.Join(dmPath, "slaves", "*"))
230-
debug.Printf("dmPath=%v/slaves/*, sdevices=%v", dmPath, sdevices)
223+
debug.Printf("[%d] refresh dmPaths [%d] %v", attempts, len(dmPaths), dmPaths)
231224
if err != nil {
232225
debug.Printf("Glob error: %s", err)
226+
return "", err
233227
}
234-
for _, spath := range sdevices {
235-
s := filepath.Base(spath)
236-
debug.Printf("Basepath: %s", s)
237-
if sdevice == s {
238-
// We've found a matching entry, return the path for the
239-
// dm-* device it was found under
240-
p := filepath.Join("/dev", filepath.Base(dmPath))
241-
debug.Printf("Found matching multipath device (%s) under dm-* device path (%s), (%v)", sdevice, dmPath, p)
242-
return p, nil
228+
229+
for _, dmPath := range dmPaths {
230+
sdevices, err := filepath.Glob(filepath.Join(dmPath, "slaves", "*"))
231+
// debug.Printf(".. dmPath=%v, sdevices=[%d]%v", dmPath, len(sdevices), sdevices)
232+
if err != nil {
233+
debug.Printf("Glob error: %s", err)
234+
}
235+
for _, spath := range sdevices {
236+
s := filepath.Base(spath)
237+
// debug.Printf(".. Basepath: %s", s)
238+
if sdevice == s {
239+
// We've found a matching entry, return the path for the
240+
// dm-* device it was found under
241+
p := filepath.Join("/dev", filepath.Base(dmPath))
242+
debug.Printf("Found matching multipath device (%s) under dm-* device path (%s) p (%v)", sdevice, dmPath, p)
243+
return p, nil
244+
}
243245
}
244246
}
247+
248+
// Force a reload of all existing multipath maps
249+
output, err := execCommand("multipath", "-r").CombinedOutput()
250+
debug.Printf("## multipath -r: output=%v, err=%v", output, err)
251+
252+
time.Sleep(multipathDelay * time.Second)
253+
attempts++
245254
}
246255
debug.Printf("Couldn't find dm-* path for path: %s, found non dm-* path: %s", path, devicePath)
247256
return "", fmt.Errorf("couldn't find dm-* path for path: %s, found non dm-* path: %s", path, devicePath)
@@ -350,7 +359,7 @@ func Connect(c *Connector) (string, error) {
350359
}
351360

352361
if lastErr != nil {
353-
debug.Printf("Last error occured during iscsi init: \n%v", lastErr)
362+
debug.Printf("Last error occurred during iscsi init: \n%v", lastErr)
354363
}
355364

356365
for i, path := range devicePaths {
@@ -465,11 +474,14 @@ func PersistConnector(c *Connector, filePath string) error {
465474
//file := path.Join("mnt", c.VolumeName+".json")
466475
f, err := os.Create(filePath)
467476
if err != nil {
477+
debug.Printf("ERROR: creating iscsi persistence file %s: %s\n", filePath, err)
468478
return fmt.Errorf("error creating iscsi persistence file %s: %s", filePath, err)
469479
}
470480
defer f.Close()
471481
encoder := json.NewEncoder(f)
482+
debug.Printf("ConnectorFromFile (write): file=%v, c=%+v\n", filePath, c)
472483
if err = encoder.Encode(c); err != nil {
484+
debug.Printf("ERROR: error encoding connector: %v\n", err)
473485
return fmt.Errorf("error encoding connector: %v", err)
474486
}
475487
return nil
@@ -490,7 +502,7 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
490502
return &Connector{}, err
491503
}
492504

493-
debug.Printf("data: %+v\n", data)
505+
debug.Printf("ConnectorFromFile (read): file=%s, %+v\n", filePath, data)
494506

495507
return &data, nil
496508

iscsi/multipath.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/exec"
99
"path/filepath"
10+
"syscall"
1011
"time"
1112
)
1213

@@ -108,14 +109,21 @@ func RemoveAndClear(device string) error {
108109
debug.Printf("Remove and clear multipath device (%s)\n", device)
109110

110111
// Remove device-mapper logical device
112+
debug.Printf("dmsetup remove -f %s\n", device)
111113
if output, err := execCommand("dmsetup", "remove", "-f", device).CombinedOutput(); err != nil {
114+
exitErr, ok := err.(*exec.ExitError)
115+
if ok && exitErr.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() != 0 {
116+
debug.Printf("ERROR: dmsetup remove -f ExitStatus: %d, err=%v\n", exitErr.ProcessState.Sys().(syscall.WaitStatus).ExitStatus(), err)
117+
}
118+
112119
return fmt.Errorf("device-mapper could not remove device: %s (%v)", output, err)
113120
}
114121

115122
// Clear out device-mapper logical device if it still exists
116123
if _, e := os.Stat(device); os.IsNotExist(e) {
117124
debug.Printf("device-mapper logical device %q was removed\n", device)
118125
} else {
126+
debug.Printf("dmsetup clear %s\n", device)
119127
if output, err := execCommand("dmsetup", "clear", device).CombinedOutput(); err != nil {
120128
return fmt.Errorf("device-mapper could not clear device: %s (%v)", output, err)
121129
}

0 commit comments

Comments
 (0)