Whamcloud - gitweb
LU-5243 utils: use goto rather than GOTO() 91/10791/5
authorJohn L. Hammond <john.hammond@intel.com>
Mon, 23 Jun 2014 21:04:12 +0000 (16:04 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 15 Jul 2014 03:51:43 +0000 (03:51 +0000)
In lfs.c, liblustreapi.c, nidstrings.c and lustre_rsync.c use
return, assignments and goto statements rather than the GOTO()
and RETURN() macros.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I5e5b5e9e73baadacfbad06ed9eefa1e0d4b9e612
Reviewed-on: http://review.whamcloud.com/10791
Tested-by: Jenkins
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/libcfs/nidstrings.c
lustre/utils/lfs.c
lustre/utils/liblustreapi.c
lustre/utils/lustre_rsync.c

index 3c1b88e..d5830f3 100644 (file)
@@ -894,7 +894,6 @@ cfs_parse_nidlist(char *str, int len, struct list_head *nidlist)
        struct cfs_lstr src;
        struct cfs_lstr res;
        int rc;
-       ENTRY;
 
        src.ls_str = str;
        src.ls_len = len;
@@ -903,15 +902,15 @@ cfs_parse_nidlist(char *str, int len, struct list_head *nidlist)
                rc = cfs_gettok(&src, ' ', &res);
                if (rc == 0) {
                        cfs_free_nidlist(nidlist);
-                       RETURN(0);
+                       return 0;
                }
                rc = parse_nidrange(&res, nidlist);
                if (rc == 0) {
                        cfs_free_nidlist(nidlist);
-                       RETURN(0);
+                       return 0;
                }
        }
-       RETURN(1);
+       return 1;
 }
 
 /*
@@ -943,7 +942,6 @@ int cfs_match_nid(lnet_nid_t nid, struct list_head *nidlist)
 {
        struct nidrange *nr;
        struct addrrange *ar;
-       ENTRY;
 
        list_for_each_entry(nr, nidlist, nr_link) {
                if (nr->nr_netstrfns->nf_type != LNET_NETTYP(LNET_NIDNET(nid)))
@@ -951,13 +949,13 @@ int cfs_match_nid(lnet_nid_t nid, struct list_head *nidlist)
                if (nr->nr_netnum != LNET_NETNUM(LNET_NIDNET(nid)))
                        continue;
                if (nr->nr_all)
-                       RETURN(1);
+                       return 1;
                list_for_each_entry(ar, &nr->nr_addrranges, ar_link)
                        if (nr->nr_netstrfns->nf_match_addr(LNET_NIDADDR(nid),
                                                        &ar->ar_numaddr_ranges))
-                               RETURN(1);
+                               return 1;
        }
-       RETURN(0);
+       return 0;
 }
 
 static int
@@ -1043,10 +1041,9 @@ int cfs_print_nidlist(char *buffer, int count, struct list_head *nidlist)
 {
        int i = 0;
        struct nidrange *nr;
-       ENTRY;
 
        if (count <= 0)
-               RETURN(0);
+               return 0;
 
        list_for_each_entry(nr, nidlist, nr_link) {
                if (i != 0)
@@ -1061,7 +1058,7 @@ int cfs_print_nidlist(char *buffer, int count, struct list_head *nidlist)
                                                  &nr->nr_addrranges, nr);
                }
        }
-       RETURN(i);
+       return i;
 }
 
 /**
index 9c69498..512d770 100644 (file)
@@ -1115,8 +1115,11 @@ static int lfs_find(int argc, char **argv)
                                 tmp = realloc(param.mdtuuid,
                                               param.num_alloc_mdts *
                                               sizeof(*param.mdtuuid));
-                                if (tmp == NULL)
-                                        GOTO(err_free, ret = -ENOMEM);
+                               if (tmp == NULL) {
+                                       ret = -ENOMEM;
+                                       goto err_free;
+                               }
+
                                 param.mdtuuid = tmp;
                         } else {
                                 param.exclude_obd = !!neg_opt;
@@ -1124,8 +1127,11 @@ static int lfs_find(int argc, char **argv)
                                 tmp = realloc(param.obduuid,
                                               param.num_alloc_obds *
                                               sizeof(*param.obduuid));
-                                if (tmp == NULL)
-                                        GOTO(err_free, ret = -ENOMEM);
+                               if (tmp == NULL) {
+                                       ret = -ENOMEM;
+                                       goto err_free;
+                               }
+
                                 param.obduuid = tmp;
                         }
                         for (token = buf; token && *token; token = next) {
@@ -1143,8 +1149,12 @@ static int lfs_find(int argc, char **argv)
                                         *p = 0;
                                         next = p+1;
                                 }
-                               if (strlen(token) > sizeof(puuid->uuid)-1)
-                                       GOTO(err_free, ret = -E2BIG);
+
+                               if (strlen(token) > sizeof(puuid->uuid) - 1) {
+                                       ret = -E2BIG;
+                                       goto err_free;
+                               }
+
                                strncpy(puuid->uuid, token,
                                        sizeof(puuid->uuid));
                         }
index b4e7729..936ddc8 100644 (file)
@@ -436,7 +436,7 @@ static int get_param_obdvar(const char *fsname, const char *file_path,
        if (fp == NULL) {
                rc = -errno;
                llapi_error(LLAPI_MSG_ERROR, rc, "error: opening "DEVICES_LIST);
-               GOTO(out, rc);
+               goto out;
        }
 
        if (fsname == NULL && file_path != NULL) {
@@ -445,12 +445,14 @@ static int get_param_obdvar(const char *fsname, const char *file_path,
                        llapi_error(LLAPI_MSG_ERROR, rc,
                                    "'%s' is not on a Lustre filesystem",
                                    file_path);
-                       GOTO(out, rc);
+                       goto out;
                }
        } else if (fsname != NULL) {
                rc = strlcpy(fs, fsname, sizeof(fs));
-               if (rc >= sizeof(fs))
-                       GOTO(out, rc = -E2BIG);
+               if (rc >= sizeof(fs)) {
+                       rc = -E2BIG;
+                       goto out;
+               }
        }
 
        while (fgets(devices, sizeof(devices) - 1, fp) != NULL) {
@@ -466,8 +468,11 @@ static int get_param_obdvar(const char *fsname, const char *file_path,
                        if (strcmp(tmp, fs))
                                continue;
                        rc = strlcpy(dev, tmp, sizeof(dev));
-                       if (rc >= sizeof(dev))
-                               GOTO(out, rc = -E2BIG);
+                       if (rc >= sizeof(dev)) {
+                               rc = -E2BIG;
+                               goto out;
+                       }
+
                        tmp = strchr(dev, ' ');
                        if (tmp != NULL)
                                *tmp = '\0';
@@ -477,13 +482,18 @@ static int get_param_obdvar(const char *fsname, const char *file_path,
 
        if (dev[0] == '*' && strlen(fs)) {
                rc = snprintf(dev, sizeof(dev), "%s-*", fs);
-               if (rc >= sizeof(dev))
-                       GOTO(out, rc = -E2BIG);
+               if (rc >= sizeof(dev)) {
+                       rc = -E2BIG;
+                       goto out;
+               }
        }
        rc = snprintf(devices, sizeof(devices), "%s/%s/%s", obd_type, dev,
                      param_name);
-       if (rc >= sizeof(devices))
-               GOTO(out, rc = -E2BIG);
+       if (rc >= sizeof(devices)) {
+               rc = -E2BIG;
+               goto out;
+       }
+
        fclose(fp);
        return get_param(devices, value, val_len);
 out:
index dee27b0..b167afa 100644 (file)
@@ -1235,31 +1235,50 @@ int lr_read_log()
                 return 0;
 
         s = calloc(1, read_size);
-        if (s == NULL)
-                GOTO(out, rc = -ENOMEM);
-
-        fd = open(statuslog, O_RDONLY);
-        if (fd == -1)
-                GOTO(out, rc = -errno);
-        size = read(fd, s, read_size);
-        if (size != read_size)
-                GOTO(out, rc = -EINVAL);
-        if (read_size < s->ls_size) {
-                read_size = s->ls_size;
-                s = lr_grow_buf(s, read_size);
-                if (s == NULL)
-                        GOTO(out, rc = -ENOMEM);
-                if (lseek(fd, 0, SEEK_SET) == -1)
-                        GOTO(out, rc = -errno);
-                size = read(fd, s, read_size);
-                if (size != read_size)
-                        GOTO(out, rc = -EINVAL);
-        }
+       if (s == NULL) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       fd = open(statuslog, O_RDONLY);
+       if (fd == -1) {
+               rc = -errno;
+               goto out;
+       }
+
+       size = read(fd, s, read_size);
+       if (size != read_size) {
+               rc = -EINVAL;
+               goto out;
+       }
+
+       if (read_size < s->ls_size) {
+               read_size = s->ls_size;
+               s = lr_grow_buf(s, read_size);
+               if (s == NULL) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
+
+               if (lseek(fd, 0, SEEK_SET) == -1) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
+
+               size = read(fd, s, read_size);
+               if (size != read_size) {
+                       rc = -EINVAL;
+                       goto out;
+               }
+       }
+
+       while (read(fd, &rec, sizeof(rec)) != 0) {
+               tmp = calloc(1, sizeof(*tmp));
+               if (!tmp) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
 
-        while (read(fd, &rec, sizeof(rec)) != 0) {
-                tmp = calloc(1, sizeof(*tmp));
-                if (!tmp)
-                        GOTO(out, rc = -ENOMEM);
                 tmp->pc_log = rec;
                 tmp->pc_next = parents;
                 parents = tmp;
@@ -1269,8 +1288,11 @@ int lr_read_log()
         if (status->ls_num_targets == 0) {
                 if (status->ls_size != s->ls_size) {
                         status = lr_grow_buf(status, s->ls_size);
-                        if (status == NULL)
-                                GOTO(out, rc = -ENOMEM);
+                       if (status == NULL) {
+                               rc = -ENOMEM;
+                               goto out;
+                       }
+
                         status->ls_size = s->ls_size;
                 }
                 status->ls_num_targets = s->ls_num_targets;