summaryrefslogtreecommitdiffstats
path: root/src/server/rpc.c
diff options
context:
space:
mode:
authorSimon Rettberg2017-10-11 16:00:00 +0200
committerSimon Rettberg2017-10-11 16:00:00 +0200
commit84b57000a176f676e2b70b29127455524e578f01 (patch)
tree04f2cd7ab4b867df1f1dce9fcec085c08eeafa4a /src/server/rpc.c
parent[KERNEL] version check to support pointer to backing_dev_info in request_queue (diff)
downloaddnbd3-84b57000a176f676e2b70b29127455524e578f01.tar.gz
dnbd3-84b57000a176f676e2b70b29127455524e578f01.tar.xz
dnbd3-84b57000a176f676e2b70b29127455524e578f01.zip
[SERVER] rpc: Support querying storage size + available space
Diffstat (limited to 'src/server/rpc.c')
-rw-r--r--src/server/rpc.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/server/rpc.c b/src/server/rpc.c
index fef7f85..7f57b0a 100644
--- a/src/server/rpc.c
+++ b/src/server/rpc.c
@@ -105,13 +105,19 @@ void rpc_sendStatsJson(int sock, dnbd3_host_t* host, const void* data, const int
static bool handleStatus(int sock, const char *request, int permissions)
{
bool ok;
- bool stats = false, images = false, clients = false;
+ bool stats = false, images = false, clients = false, space = false;
if ( strstr( request, "stats" ) != NULL ) {
if ( !(permissions & ACL_STATS) ) {
return sendReply( sock, "403 Forbidden", "text/plain", "No permission to access statistics", -1, HTTP_KEEPALIVE );
}
stats = true;
}
+ if ( strstr( request, "space" ) != NULL ) {
+ if ( !(permissions & ACL_STATS) ) {
+ return sendReply( sock, "403 Forbidden", "text/plain", "No permission to access statistics", -1, HTTP_KEEPALIVE );
+ }
+ space = true;
+ }
if ( strstr( request, "images" ) != NULL ) {
if ( !(permissions & ACL_IMAGE_LIST) ) {
return sendReply( sock, "403 Forbidden", "text/plain", "No permission to access image list", -1, HTTP_KEEPALIVE );
@@ -142,6 +148,12 @@ static bool handleStatus(int sock, const char *request, int permissions)
statisticsJson = json_pack( "{sI}",
"runId", randomRunId );
}
+ if ( space ) {
+ uint64_t spaceTotal = 0, spaceAvail = 0;
+ file_freeDiskSpace( _basePath, &spaceTotal, &spaceAvail );
+ json_object_set_new( statisticsJson, "spaceTotal", json_integer( spaceTotal ) );
+ json_object_set_new( statisticsJson, "spaceFree", json_integer( spaceAvail ) );
+ }
if ( jsonClients != NULL ) {
if ( clients ) {
json_object_set_new( statisticsJson, "clients", jsonClients );