summaryrefslogtreecommitdiffstats
path: root/src/server/image.c
diff options
context:
space:
mode:
authorSimon Rettberg2015-05-08 10:53:06 +0200
committerSimon Rettberg2015-05-08 10:53:06 +0200
commit2ab53f3a518dcd8b703e515ffd123adce181044c (patch)
tree96e52eddf2c9808ace02cfc5d4bb0457e8153ae0 /src/server/image.c
parent[SERVER] Fix premature connection close for RPC replies (diff)
downloaddnbd3-2ab53f3a518dcd8b703e515ffd123adce181044c.tar.gz
dnbd3-2ab53f3a518dcd8b703e515ffd123adce181044c.tar.xz
dnbd3-2ab53f3a518dcd8b703e515ffd123adce181044c.zip
[SERVER] Add image ID for easier handling in RPC, export RID via RPC, make names of the byte count fields in RPC consistent
Diffstat (limited to 'src/server/image.c')
-rw-r--r--src/server/image.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/server/image.c b/src/server/image.c
index 920f15d..1b2ce07 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -500,6 +500,7 @@ static bool image_load_all_internal(char *base, char *path)
static bool image_load(char *base, char *path, int withUplink)
{
+ static int imgIdCounter = 0; // Used to assign unique numeric IDs to images
int i, revision;
struct stat st;
uint8_t *cache_map = NULL;
@@ -682,6 +683,8 @@ static bool image_load(char *base, char *path, int withUplink)
// ### Reaching this point means loading succeeded
// Add to images array
spin_lock( &_images_lock );
+ // Now we're locked, assign unique ID to image (unique for this running server instance!)
+ image->id = ++imgIdCounter;
for (i = 0; i < _num_images; ++i) {
if ( _images[i] != NULL ) continue;
_images[i] = image;
@@ -1144,8 +1147,8 @@ json_t* image_fillJson()
for (i = 0; i < _num_images; ++i) {
if ( _images[i] == NULL ) continue;
spin_lock( &_images[i]->lock );
- image = json_pack( "{sssIsI}", "image", _images[i]->lower_name, "users", (json_int_t) _images[i]->users,
- "complete", (json_int_t) image_getCompletenessEstimate( _images[i] ) );
+ image = json_pack( "{sisssisIsi}", "id", _images[i]->id, "image", _images[i]->lower_name, "rid", (int) _images[i]->rid, "users", (json_int_t) _images[i]->users,
+ "complete", image_getCompletenessEstimate( _images[i] ) );
if ( _images[i]->uplink != NULL ) {
host_to_string( &_images[i]->uplink->currentServer, buffer, sizeof(buffer) );
json_object_set_new( image, "uplinkServer", json_string( buffer ) );