Skip to content

Commit 456c2eb

Browse files
client (Win): including WSL disk image in BOINC disk usage
If using boinc-buda-runner, find its disk image size and count as BOINC client disk usage.
1 parent 8bd4ceb commit 456c2eb

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

client/client_state.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void CLIENT_STATE::show_host_info() {
258258
}
259259
} else {
260260
msg_printf(NULL, MSG_INFO, "Usable WSL distros:");
261-
for (auto& wsl : host_info.wsl_distros.distros) {
261+
for (WSL_DISTRO &wsl : host_info.wsl_distros.distros) {
262262
msg_printf(NULL, MSG_INFO,
263263
"- %s (WSL %d)%s",
264264
wsl.distro_name.c_str(),
@@ -290,6 +290,13 @@ void CLIENT_STATE::show_host_info() {
290290
msg_printf(NULL, MSG_INFO, "- BOINC WSL distro version %d",
291291
wsl.boinc_buda_runner_version
292292
);
293+
double size;
294+
int retval = dir_size_alloc(wd.base_path.c_str(), size);
295+
if (!retval) {
296+
char buf[256];
297+
nbytes_to_string(size, 0, buf, sizeof(buf));
298+
msg_printf(NULL, MSG_INFO, "- Disk usage: %s", buf);
299+
}
293300
}
294301
}
295302
}

client/cs_prefs.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,17 @@ int CLIENT_STATE::get_disk_usages() {
8686

8787
client_disk_usage = 0;
8888
total_disk_usage = 0;
89+
90+
// disk usage in project directories
91+
//
8992
for (PROJECT *p: projects) {
9093
p->disk_usage = 0;
9194
retval = dir_size_alloc(p->project_dir(), size);
9295
if (!retval) p->disk_usage = size;
9396
}
9497

98+
// disk usage in slot directories
99+
//
95100
for (i=0; i<active_tasks.active_tasks.size(); i++) {
96101
ACTIVE_TASK* atp = active_tasks.active_tasks[i];
97102
get_slot_dir(atp->slot, buf, sizeof(buf));
@@ -102,11 +107,29 @@ int CLIENT_STATE::get_disk_usages() {
102107
for (PROJECT *p: projects) {
103108
total_disk_usage += p->disk_usage;
104109
}
110+
111+
// disk usage top level of BOINC data dir: XML and log files
112+
//
105113
retval = dir_size_alloc(".", size, false);
106114
if (!retval) {
107115
client_disk_usage = size;
108116
total_disk_usage += size;
109117
}
118+
119+
#ifdef _WIN64
120+
// Win: if using boinc-buda-runner WSL distro,
121+
// include its disk image size
122+
//
123+
WSL_DISTRO *wd = host_info.wsl_distros.find_docker();
124+
if (wd) {
125+
retval = dir_size_alloc(wd.base_path.c_str(), size);
126+
if (!retval) {
127+
client_disk_usage = size;
128+
total_disk_usage += size;
129+
}
130+
}
131+
#endif
132+
110133
return 0;
111134
}
112135

client/hostinfo_wsl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ int get_all_distros(WSL_DISTROS& distros) {
127127
if (!strcmp(wsl_guid, default_wsl_guid)) {
128128
distro.is_default = true;
129129
}
130+
131+
// if BOINC distro, get its data dir so we can find disk usage
132+
//
133+
if (distro.distro_name == BOINC_WSL_DISTRO_NAME) {
134+
ret = RegQueryValueEx(hSubKey, "BasePath", NULL, NULL,
135+
(LPBYTE)wsl_name, &wsl_name_len
136+
);
137+
if (ret == ERROR_SUCCESS) {
138+
distro.base_path = wsl_name;
139+
}
140+
}
141+
130142
distros.distros.push_back(distro);
131143
}
132144
RegCloseKey(hSubKey);

lib/wslinfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ struct WSL_DISTRO {
5656
DOCKER_TYPE docker_compose_type;
5757
int boinc_buda_runner_version;
5858
// if this distro is boinc_buda_runner, the version
59+
std::string base_path;
60+
// the dir where the disk image (.vhdx file) is stored
5961

6062
WSL_DISTRO(){
6163
clear();

0 commit comments

Comments
 (0)