Skip to content

Commit

Permalink
refactor:using the fast return approach,make the code less indentatio…
Browse files Browse the repository at this point in the history
…n. (#611)

* refactor

using the fast return approach, make the code less indentation, in order
to improve the readability of the code.

* gofmt

gofmt

* Signed-off-by: 谢恒忠@运维小盆友 <[email protected]>
  • Loading branch information
DarkForcesX authored and allencloud committed Jan 19, 2018
1 parent 2e4efc3 commit 16994b4
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions volume/modules/ceph/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,44 +122,44 @@ func doUnmap(ctx driver.Context, v *types.Volume, rbdmap RBDMap) error {
name := v.Name

for _, rbd := range rbdmap.MapDevice {
if rbd.Image == name && rbd.Pool == poolName {
ctx.Log.Debugf("Ceph unmapping volume %s/%s at device %q", poolName, name, strings.TrimSpace(rbd.Device))
if rbd.Image != name || rbd.Pool != poolName {
continue
}
ctx.Log.Debugf("Ceph unmapping volume %s/%s at device %q", poolName, name, strings.TrimSpace(rbd.Device))

// Check device is exist or not.
if _, err := os.Stat(rbd.Device); err != nil {
ctx.Log.Errorf("Ceph trying to unmap device %q for %s/%s that does not exist, continuing",
poolName, name, rbd.Device)
continue
}
// Check device is exist or not.
if _, err := os.Stat(rbd.Device); err != nil {
ctx.Log.Errorf("Ceph trying to unmap device %q for %s/%s that does not exist, continuing",
poolName, name, rbd.Device)
continue
}

// Unmap device.
exit, _, stderr, err := exec.Run(defaultTimeout, bin, "unmap", rbd.Device)
if err != nil {
ctx.Log.Errorf("Ceph could not unmap volume %q (device %q): %d (%v) (%s)",
name, rbd.Device, exit, err, stderr)
return err
} else if exit != 0 {
err = fmt.Errorf("Ceph could not unmap volume %q (device %q): %d (%s)",
name, rbd.Device, exit, stderr)
ctx.Log.Error(err)
return err
}
// Unmap device.
exit, _, stderr, err := exec.Run(defaultTimeout, bin, "unmap", rbd.Device)
if err != nil {
ctx.Log.Errorf("Ceph could not unmap volume %q (device %q): %d (%v) (%s)",
name, rbd.Device, exit, err, stderr)
return err
}
if exit != 0 {
err = fmt.Errorf("Ceph could not unmap volume %q (device %q): %d (%s)",
name, rbd.Device, exit, stderr)
ctx.Log.Error(err)
return err
}

// Check have unmapped or not.
rbdmap2, err := showMapped(ctx)
if err != nil {
return err
}
for _, rbd2 := range rbdmap2.MapDevice {
if rbd.Image == rbd2.Image && rbd.Pool == rbd2.Pool {
return fmt.Errorf("could not unmap volume %q, device: %q is exist",
name, rbd.Image)
}
// Check have unmapped or not.
rbdmap2, err := showMapped(ctx)
if err != nil {
return err
}
for _, rbd2 := range rbdmap2.MapDevice {
if rbd.Image == rbd2.Image && rbd.Pool == rbd2.Pool {
return fmt.Errorf("could not unmap volume %q, device: %q is exist",
name, rbd.Image)
}

break
}
break
}

return nil
}

0 comments on commit 16994b4

Please sign in to comment.