From 16994b4f9bbc480d3882dfe83578305db4145bfe Mon Sep 17 00:00:00 2001 From: Xiehengzhong <10927831@qq.com> Date: Fri, 19 Jan 2018 09:59:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor:using=20the=20fast=20return=20approach?= =?UTF-8?q?=EF=BC=8Cmake=20the=20code=20less=20indentation.=20(#611)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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: 谢恒忠@运维小盆友 <10927831@qq.com> --- volume/modules/ceph/map.go | 66 +++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/volume/modules/ceph/map.go b/volume/modules/ceph/map.go index 717c82f56..1fc7d4450 100644 --- a/volume/modules/ceph/map.go +++ b/volume/modules/ceph/map.go @@ -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 }