Whamcloud - gitweb
LU-4028 quota: fix output of 'lfs quota'
[fs/lustre-release.git] / lustre / utils / lfs.c
index 5af9305..6e48c4f 100644 (file)
@@ -74,7 +74,6 @@
 
 #include <libcfs/libcfsutil.h>
 #include <obd.h>
-#include <obd_lov.h>
 #include "obdctl.h"
 
 /* all functions */
@@ -2634,13 +2633,13 @@ static void kbytes2str(__u64 num, char *buf, bool h)
                sprintf(buf, LPU64, num);
        } else {
                if (num >> 30)
-                       sprintf(buf, LPU64"%s", num >> 30, "T");
+                       sprintf(buf, "%5.4gT", (double)num / (1 << 30));
                else if (num >> 20)
-                       sprintf(buf, LPU64"%s", num >> 20, "G");
+                       sprintf(buf, "%5.4gG", (double)num / (1 << 20));
                else if (num >> 10)
-                       sprintf(buf, LPU64"%s", num >> 10, "M");
+                       sprintf(buf, "%5.4gM", (double)num / (1 << 10));
                else
-                       sprintf(buf, LPU64"%s", num, "K");
+                       sprintf(buf, LPU64"%s", num, "k");
        }
 }
 
@@ -2931,11 +2930,11 @@ ug_output:
            verbose) {
                char strbuf[32];
 
-               kbytes2str(total_balloc, strbuf, human_readable);
                rc2 = print_obd_quota(mnt, &qctl, 1, human_readable,
                                      &total_ialloc);
                rc3 = print_obd_quota(mnt, &qctl, 0, human_readable,
                                      &total_balloc);
+               kbytes2str(total_balloc, strbuf, human_readable);
                printf("Total allocated inode limit: "LPU64", total "
                       "allocated block limit: %s\n", total_ialloc, strbuf);
        }
@@ -3713,6 +3712,7 @@ static int lfs_hsm_request(int argc, char **argv, int action)
                                                strerror(errno));
                                        hur = oldhur;
                                        rc = -errno;
+                                       fclose(fp);
                                        goto out_free;
                                }
                                memcpy(hur, oldhur, hur_len(oldhur));
@@ -3729,8 +3729,10 @@ static int lfs_hsm_request(int argc, char **argv, int action)
                        rc = lfs_hsm_prepare_file(line, &hui->hui_fid,
                                                  &last_dev);
                        hur->hur_request.hr_itemcount++;
-                       if (rc)
+                       if (rc) {
+                               fclose(fp);
                                goto out_free;
+                       }
 
                        if ((some_file[0] == '\0') &&
                            (strlen(line) < sizeof(some_file)))