Repository: cockpit-project/cockpit (language: javascript)

Issue:
storage: incorrect (0) usage information for unmounted btrfs subvolume
Page: Storage

Before mounting:
![127 0 0 2_9091_cockpit_@localhost_anaconda-webui_index html](https://github.com/user-attachments/assets/6c124017-3730-49d0-b057-8843920922b6)

After mounting:
![127 0 0 2_9091_cockpit_@localhost_anaconda-webui_index html (1)](https://github.com/user-attachments/assets/2633a676-80ee-4095-8f7e-8479558cf9a6)

Since we can't get this info before mounting maybe we should not show that at all? 



Discussion / hints:
It'd be great to have the usage without mounting, but if we can't do that, I agree that we shouldn't show it. We already have size.

Aside: Oddly, size and usage have different amounts. Size has 12.8 GB and usage shows 13 GB. Where does the 0.2 GB come from? Are there rounding-related errors?
In general it's quite problematic for Anaconda that Cockpit Storage requires to mount volume before it can start working with subvolumes.
The issue is that volume is not really usable when mounted (at least not recommended) so forcing user to set mount point and everything is confusing. This is especially true in Anaconda where we are taking these mount points for installation and (correctly) skipping the volume mount.
> In general it's quite problematic for Anaconda that Cockpit Storage requires to mount volume before it can start working with subvolumes. The issue is that volume is not really usable when mounted (at least not recommended) so forcing user to set mount point and everything is confusing. This is especially true in Anaconda where we are taking these mount points for installation and (correctly) skipping the volume mount.

Filed more generally about having to mount to perform operations @ https://github.com/cockpit-project/cockpit/issues/20855

(I consider this particular issue as different, as it would be solved by removing the usage when we can't show it. And the other is the more general case for all explicit actions that require mounting.)

Fix patch:
diff --git a/pkg/storaged/btrfs/btrfs-tool.py b/pkg/storaged/btrfs/btrfs-tool.py
index 5d77c7167e1a..e900c6c5be8f 100755
--- a/pkg/storaged/btrfs/btrfs-tool.py
+++ b/pkg/storaged/btrfs/btrfs-tool.py
@@ -139,15 +139,24 @@ def poll(opt_mount):
     info = {}
     for fs in filesystems.values():
         mp = get_mount_point(fs, opt_mount)
-        if mp:
-            try:
-                info[fs['uuid']] = {
-                    'subvolumes': get_subvolume_info(mp),
-                    'default_subvolume': get_default_subvolume(mp),
-                    'usages': get_usages(fs['uuid']),
-                }
-            except Exception as err:
-                info[fs['uuid']] = {'error': str(err)}
+        try:
+            usages = get_usages(fs['uuid'])
+
+            if mp:
+                subvolumes = get_subvolume_info(mp)
+                default_subvolume = get_default_subvolume(mp)
+            else:
+                subvolumes = None
+                default_subvolume = None
+
+            info[fs['uuid']] = {
+                'subvolumes': subvolumes,
+                'default_subvolume': default_subvolume,
+                'usages': usages,
+            }
+        except Exception as err:
+            info[fs['uuid']] = {'error': str(err)}
+
     return info
 
 
diff --git a/pkg/storaged/client.js b/pkg/storaged/client.js
index 09b53be44a50..c639b1e222f4 100644
--- a/pkg/storaged/client.js
+++ b/pkg/storaged/client.js
@@ -308,9 +308,15 @@ function btrfs_update(data) {
         if (data[uuid].error) {
             console.warn("Error polling btrfs", uuid, data[uuid].error);
         } else {
-            uuids_subvols[uuid] = [{ pathname: "/", id: 5, parent: null }].concat(data[uuid].subvolumes);
-            uuids_usage[uuid] = data[uuid].usages;
-            default_subvol[uuid] = data[uuid].default_subvolume;
+            if (data[uuid].subvolumes) {
+                uuids_subvols[uuid] = [{ pathname: "/", id: 5, parent: null }].concat(data[uuid].subvolumes);
+            }
+            if (data[uuid].usages) {
+                uuids_usage[uuid] = data[uuid].usages;
+            }
+            if (data[uuid].default_subvolume) {
+                default_subvol[uuid] = data[uuid].default_subvolume;
+            }
         }
     }
 


Test patch: