Whamcloud - gitweb
LU-17000 misc: Fix Unused Value error(0)
[fs/lustre-release.git] / lustre / utils / lsnapshot.c
index 3700eef..00716e9 100644 (file)
@@ -559,7 +559,7 @@ static int snapshot_load_conf(struct snapshot_instance *si, int lock_mode)
                        "Can't fdopen the snapshot config file %s: %s\n",
                        conf_name, strerror(errno));
                rc = -1;
-               goto out;
+               goto out_fd;
        }
 
        while (snapshot_fgets(fp, buf, MAX_BUF_SIZE) != NULL) {
@@ -608,14 +608,18 @@ static int snapshot_load_conf(struct snapshot_instance *si, int lock_mode)
 
 out:
        if (fd >= 0) {
-               if (rc < 0) {
+               if (rc < 0)
                        flock(fd, LOCK_UN);
-                       close(fd);
-               } else {
+               else
                        si->si_conf_fd = fd;
-               }
        }
-
+       /* fclose() closes any associated underlying file descriptor.
+        * explicit close(fd) not required
+        */
+       fclose(fp);
+       return rc;
+out_fd:
+       close(fd);
        return rc;
 }
 
@@ -624,8 +628,8 @@ static void snapshot_unload_conf(struct snapshot_instance *si)
        struct snapshot_target *st;
 
        while (!list_empty(&si->si_mdts_list)) {
-               st = list_entry(si->si_mdts_list.next,
-                               struct snapshot_target, st_list);
+               st = list_first_entry(&si->si_mdts_list,
+                                     struct snapshot_target, st_list);
                list_del(&st->st_list);
                free(st->st_host);
                free(st->st_fhost);
@@ -636,8 +640,8 @@ static void snapshot_unload_conf(struct snapshot_instance *si)
        }
 
        while (!list_empty(&si->si_osts_list)) {
-               st = list_entry(si->si_osts_list.next,
-                               struct snapshot_target, st_list);
+               st = list_first_entry(&si->si_osts_list,
+                                     struct snapshot_target, st_list);
                list_del(&st->st_list);
                free(st->st_host);
                free(st->st_fhost);
@@ -1062,8 +1066,8 @@ static int snapshot_get_mgsnode(struct snapshot_instance *si,
        int rc;
        int foreign = 0;
 
-       st = list_entry(si->si_osts_list.next, struct snapshot_target,
-                       st_list);
+       st = list_first_entry(&si->si_osts_list, struct snapshot_target,
+                             st_list);
 again:
        rc = 0;
        memset(buf, 0, sizeof(buf));
@@ -1242,8 +1246,10 @@ again:
 
                rc = scnprintf(cmd + len, size - len - 1,
                               "-o %s=\"%s\" ", buf, ptr);
-               if (rc <= 0)
+               if (rc <= 0) {
+                       pclose(fp);
                        return -EOVERFLOW;
+               }
 
                len += rc;
        }
@@ -2210,8 +2216,8 @@ again:
                goto again;
        }
        while (!list_empty(&list_sub_items)) {
-               lsi = list_entry(list_sub_items.next,
-                                struct list_sub_item, lsi_list);
+               lsi = list_first_entry(&list_sub_items,
+                                      struct list_sub_item, lsi_list);
                list_del(&lsi->lsi_list);
                if (!rc) {
                        si->si_ssname = lsi->lsi_ssname;