From d2d297f12f29f60a6aa92feca750abb29ca2eba3 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Fri, 20 Feb 2009 21:28:56 -0700
Subject: [PATCH] storage: also report space-free-for-root and
 space-free-for-nonroot, since that helps users understand the
 space-left-for-tahoe number better

---
 src/allmydata/storage/server.py        |  8 ++++++--
 src/allmydata/web/storage.py           |  2 ++
 src/allmydata/web/storage_status.xhtml | 12 ++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/allmydata/storage/server.py b/src/allmydata/storage/server.py
index 3b30fe96..b5f83f4e 100644
--- a/src/allmydata/storage/server.py
+++ b/src/allmydata/storage/server.py
@@ -147,11 +147,13 @@ class StorageServer(service.MultiService, Referenceable):
             disk_total = s.f_bsize * s.f_blocks
             disk_used = s.f_bsize * (s.f_blocks - s.f_bfree)
             # spacetime predictors should look at the slope of disk_used.
-            disk_avail = s.f_bsize * s.f_bavail # available to non-root users
+            disk_free_for_root = s.f_bsize * s.f_bfree
+            disk_free_for_nonroot = s.f_bsize * s.f_bavail
+
             # include our local policy here: if we stop accepting shares when
             # the available space drops below 1GB, then include that fact in
             # disk_avail.
-            disk_avail -= self.reserved_space
+            disk_avail = disk_free_for_nonroot - self.reserved_space
             disk_avail = max(disk_avail, 0)
             if self.readonly_storage:
                 disk_avail = 0
@@ -161,6 +163,8 @@ class StorageServer(service.MultiService, Referenceable):
             # spacetime predictors should use disk_avail / (d(disk_used)/dt)
             stats["storage_server.disk_total"] = disk_total
             stats["storage_server.disk_used"] = disk_used
+            stats["storage_server.disk_free_for_root"] = disk_free_for_root
+            stats["storage_server.disk_free_for_nonroot"] = disk_free_for_nonroot
             stats["storage_server.disk_avail"] = disk_avail
         except AttributeError:
             # os.statvfs is available only on unix
diff --git a/src/allmydata/web/storage.py b/src/allmydata/web/storage.py
index fcdcef02..a759fec9 100644
--- a/src/allmydata/web/storage.py
+++ b/src/allmydata/web/storage.py
@@ -57,6 +57,8 @@ class StorageStatus(rend.Page):
                    for k,v in self.storage.get_stats().items() ])
         d.setdefault("disk_total", None)
         d.setdefault("disk_used", None)
+        d.setdefault("disk_free_for_root", None)
+        d.setdefault("disk_free_for_nonroot", None)
         d.setdefault("reserved_space", None)
         d.setdefault("disk_avail", None)
         return d
diff --git a/src/allmydata/web/storage_status.xhtml b/src/allmydata/web/storage_status.xhtml
index c98e6c6e..c5683e17 100644
--- a/src/allmydata/web/storage_status.xhtml
+++ b/src/allmydata/web/storage_status.xhtml
@@ -15,6 +15,14 @@
         <td><span n:render="space" n:data="disk_total" /></td></tr>
     <tr><td>Disk space used:</td>
         <td>- <span n:render="space" n:data="disk_used" /></td></tr>
+    <tr><td />
+        <td>======</td></tr>
+    <tr><td>Disk space free (root):</td>
+        <td><span n:render="space" n:data="disk_free_for_root"/>
+          [see 1]</td></tr>
+    <tr><td>Disk space free (non-root):</td>
+        <td><span n:render="space" n:data="disk_free_for_nonroot" />
+          [see 2]</td></tr>
     <tr><td>Reserved space:</td>
         <td>- <span n:render="space" n:data="reserved_space" /></td></tr>
     <tr><td />
@@ -39,6 +47,10 @@
     </li>
   </ul>
 
+  <p>[1]: Some of this space may be reserved for the superuser.</p>
+  <p>[2]: This reports the space available to non-root users, including the
+  Tahoe node.</p>
+
 </div>
 
 </body>
-- 
2.45.2