]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/types: make numbers a bit nicer when displaying space usage 17126/head
authorxie xingguo <xie.xingguo@zte.com.cn>
Tue, 23 May 2017 01:53:55 +0000 (09:53 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Tue, 22 Aug 2017 04:33:10 +0000 (12:33 +0800)
Was:
----------------------------------------------------------------------------
GLOBAL:
    SIZE       AVAIL      RAW USED     %RAW USED
    30911M     27050M        3861M         12.49
POOLS:
    NAME                  ID     USED        %USED     MAX AVAIL     OBJECTS
    rbd                   0      101216k      1.10         8913M        1178
    cephfs_data_a         1            0         0         8913M           0
    cephfs_metadata_a     2          892         0         8913M          21
----------------------------------------------------------------------------

Now:
----------------------------------------------------------------------------
GLOBAL:
    SIZE      AVAIL     RAW USED     %RAW USED
    30.2G     26.4G        3.77G         12.50
POOLS:
    NAME                  ID     USED      %USED     MAX AVAIL     OBJECTS
    rbd                   0      99.2M      1.10         8.70G        1180
    cephfs_data_a         1          0         0         8.70G           0
    cephfs_metadata_a     2        892         0         8.70G          21
----------------------------------------------------------------------------

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
qa/standalone/mon/test_pool_quota.sh
qa/workunits/cephtool/test.sh
qa/workunits/rbd/cli_generic.sh
qa/workunits/rbd/import_export.sh
src/include/types.h
src/test/cli-integration/rbd/formatted-output.t

index 85941a895f631870062953393b457c10a1be8031..22a924477dccd3a416feb040f2e5e0565a3d9fd6 100755 (executable)
@@ -50,14 +50,14 @@ function TEST_pool_quota() {
 
     objects=`ceph df detail | grep -w $poolname|awk '{print $3}'`
     bytes=`ceph df detail | grep -w $poolname|awk '{print $4}'`
+   
+    if [ $objects != '1000' ] || [ $bytes != '1K' ] ;
+      then
+      return 1
+    fi
 
-     if [ $objects != '1000' ] || [ $bytes != '1024' ] ;
-       then
-       return 1
-     fi
-
-     ceph osd pool delete  $poolname $poolname  --yes-i-really-really-mean-it
-     teardown $dir || return 1
+    ceph osd pool delete  $poolname $poolname  --yes-i-really-really-mean-it
+    teardown $dir || return 1
 }
 
 main testpoolquota
index 9f735a0171fe3405eb43c05b1d7816d3e1c9c84a..584c0677731b729140620e9f0745934382cedc96 100755 (executable)
@@ -1744,7 +1744,7 @@ function test_mon_osd_pool_quota()
   # get quotas
   #
   ceph osd pool get-quota tmp-quota-pool | grep 'max bytes.*10B'
-  ceph osd pool get-quota tmp-quota-pool | grep 'max objects.*10240k objects'
+  ceph osd pool get-quota tmp-quota-pool | grep 'max objects.*10M objects'
   #
   # get quotas in json-pretty format
   #
index f958520842fb4d80796ed84f99c4d68a81221bf8..c409c8c5c045a8d85292dabc22a438d53c150ecf 100755 (executable)
@@ -147,8 +147,8 @@ test_ls() {
     rbd ls | grep test2
     rbd ls | wc -l | grep 2
     # look for fields in output of ls -l without worrying about space
-    rbd ls -l | grep 'test1.*1024k.*1'
-    rbd ls -l | grep 'test2.*1024k.*1'
+    rbd ls -l | grep 'test1.*1M.*1'
+    rbd ls -l | grep 'test2.*1M.*1'
 
     rbd rm test1
     rbd rm test2
@@ -158,8 +158,8 @@ test_ls() {
     rbd ls | grep test1
     rbd ls | grep test2
     rbd ls | wc -l | grep 2
-    rbd ls -l | grep 'test1.*1024k.*2'
-    rbd ls -l | grep 'test2.*1024k.*2'
+    rbd ls -l | grep 'test1.*1M.*2'
+    rbd ls -l | grep 'test2.*1M.*2'
 
     rbd rm test1
     rbd rm test2
@@ -169,8 +169,8 @@ test_ls() {
     rbd ls | grep test1
     rbd ls | grep test2
     rbd ls | wc -l | grep 2
-    rbd ls -l | grep 'test1.*1024k.*2'
-    rbd ls -l | grep 'test2.*1024k.*1'
+    rbd ls -l | grep 'test1.*1M.*2'
+    rbd ls -l | grep 'test2.*1M.*1'
     remove_images
        
     # test that many images can be shown by ls
index 41585f2843b15b495e7fd3f444bc9c01b62e3c89..639f569d0bbed7a64b5f165ec2921570dec604ad 100755 (executable)
@@ -158,7 +158,7 @@ dd if=/dev/urandom bs=1M count=1 of=${TMPDIR}/sparse2; truncate ${TMPDIR}/sparse
 # 1M sparse, 1M data
 rbd rm sparse1 || true
 rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse1
-rbd ls -l | grep sparse1 | grep -i '2048k'
+rbd ls -l | grep sparse1 | grep -i '2M'
 [ $tiered -eq 1 -o "$(objects sparse1)" = '1' ]
 
 # export, compare contents and on-disk size
@@ -170,7 +170,7 @@ rbd rm sparse1
 # 1M data, 1M sparse
 rbd rm sparse2 || true
 rbd import $RBD_CREATE_ARGS --order 20 ${TMPDIR}/sparse2
-rbd ls -l | grep sparse2 | grep -i '2048k'
+rbd ls -l | grep sparse2 | grep -i '2M'
 [ $tiered -eq 1 -o "$(objects sparse2)" = '0' ]
 rbd export sparse2 ${TMPDIR}/sparse2.out
 compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out
@@ -181,7 +181,7 @@ rbd rm sparse2
 truncate ${TMPDIR}/sparse1 -s 10M
 # import from stdin just for fun, verify still sparse
 rbd import $RBD_CREATE_ARGS --order 20 - sparse1 < ${TMPDIR}/sparse1
-rbd ls -l | grep sparse1 | grep -i '10240k'
+rbd ls -l | grep sparse1 | grep -i '10M'
 [ $tiered -eq 1 -o "$(objects sparse1)" = '1' ]
 rbd export sparse1 ${TMPDIR}/sparse1.out
 compare_files_and_ondisk_sizes ${TMPDIR}/sparse1 ${TMPDIR}/sparse1.out
@@ -192,7 +192,7 @@ rbd rm sparse1
 dd if=/dev/urandom bs=2M count=1 of=${TMPDIR}/sparse2 oflag=append conv=notrunc
 # again from stding
 rbd import $RBD_CREATE_ARGS --order 20 - sparse2 < ${TMPDIR}/sparse2
-rbd ls -l | grep sparse2 | grep -i '4096k'
+rbd ls -l | grep sparse2 | grep -i '4M'
 [ $tiered -eq 1 -o "$(objects sparse2)" = '0 2 3' ]
 rbd export sparse2 ${TMPDIR}/sparse2.out
 compare_files_and_ondisk_sizes ${TMPDIR}/sparse2 ${TMPDIR}/sparse2.out
index e904a151d75d800112de1a342a4fb3dec76dc139..6c89691af3552b17417e96ce4ed7044593bc8878 100644 (file)
@@ -345,20 +345,40 @@ struct si_t {
 
 inline ostream& operator<<(ostream& out, const si_t& b)
 {
-  uint64_t bump_after = 100;
-  if (b.v > bump_after << 60)
-    return out << (b.v >> 60) << "E";
-  if (b.v > bump_after << 50)
-    return out << (b.v >> 50) << "P";
-  if (b.v > bump_after << 40)
-    return out << (b.v >> 40) << "T";
-  if (b.v > bump_after << 30)
-    return out << (b.v >> 30) << "G";
-  if (b.v > bump_after << 20)
-    return out << (b.v >> 20) << "M";
-  if (b.v > bump_after << 10)
-    return out << (b.v >> 10) << "k";
-  return out << b.v;
+  char buffer[32];
+  uint64_t n = b.v;
+  int index = 0;
+
+  while (n >= 1024 && index < 6) {
+    n /= 1024;
+    index++;
+  }
+
+  char u = " KMGTPE"[index];
+
+  if (index == 0) {
+    (void) snprintf(buffer, sizeof(buffer), "%" PRId64, n);
+  } else if ((b.v & ((1ULL << 10 * index) - 1)) == 0) {
+    // If this is an even multiple of the base, always display
+    // without any decimal fraction.
+    (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%c", n, u);
+  } else {
+    // We want to choose a precision that reflects the best choice
+    // for fitting in 5 characters.  This can get rather tricky when
+    // we have numbers that are very close to an order of magnitude.
+    // For example, when displaying 10239 (which is really 9.999K),
+    // we want only a single place of precision for 10.0K.  We could
+    // develop some complex heuristics for this, but it's much
+    // easier just to try each combination in turn.
+    int i;
+    for (i = 2; i >= 0; i--) {
+      if (snprintf(buffer, sizeof(buffer), "%.*f%c", i,
+        (double)b.v / (1ULL << 10 * index), u) <= 5)
+        break;
+    }
+  }
+
+  return out << buffer;
 }
 
 struct pretty_si_t {
index 54c63733f25308ea28f0ab1c8e34491cbd8dc3d3..2b05d720d6e40f522fdc2b2df3ef7dd1c876a221 100644 (file)
@@ -550,15 +550,15 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
     <name>quuy</name>
   </images>
   $ rbd list -l
-  NAME       SIZE PARENT FMT PROT LOCK 
-  foo       1024M          1           
-  foo@snap  1024M          1           
-  quux      1024k          1      excl 
-  bar       1024M          2           
-  bar@snap   512M          2 yes       
-  bar@snap2 1024M          2           
-  baz       2048M          2      shr  
-  quuy      2048M          2           
+  NAME      SIZE PARENT FMT PROT LOCK 
+  foo         1G          1           
+  foo@snap    1G          1           
+  quux        1M          1      excl 
+  bar         1G          2           
+  bar@snap  512M          2 yes       
+  bar@snap2   1G          2           
+  baz         2G          2      shr  
+  quuy        2G          2           
   $ rbd list -l --format json | python -mjson.tool | sed 's/,$/, /'
   [
       {
@@ -886,12 +886,12 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
     </snapshot>
   </snapshots>
   $ rbd disk-usage --pool rbd_other 2>/dev/null
-  NAME                    PROVISIONED  USED 
-  child@snap                     512M     
-  child                          512M 4096k 
-  deep-flatten-child@snap        512M     
-  deep-flatten-child             512M     
-  <TOTAL>                       1024M 4096k 
+  NAME                    PROVISIONED USED 
+  child@snap                     512M    0 
+  child                          512M   4M 
+  deep-flatten-child@snap        512M    0 
+  deep-flatten-child             512M    0 
+  <TOTAL>                          1G   4M 
   $ rbd disk-usage --pool rbd_other --format json | python -mjson.tool | sed 's/,$/, /'
   {
       "images": [