From 84b57000a176f676e2b70b29127455524e578f01 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 11 Oct 2017 16:00:00 +0200 Subject: [SERVER] rpc: Support querying storage size + available space --- src/server/rpc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/server/rpc.c') 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 ); -- cgit v1.2.3-55-g7522