Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:using the fast return approach,make the code less indentation. #611

Merged
merged 3 commits into from
Jan 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}