summaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c72
1 files changed, 51 insertions, 21 deletions
diff --git a/src/client.c b/src/client.c
index e3d8dec..bbe4c15 100644
--- a/src/client.c
+++ b/src/client.c
@@ -381,7 +381,8 @@ static int og_resp_software(json_t *data, struct og_client *cli)
OG_PARAM_PART_FILESYSTEM | \
OG_PARAM_PART_OS | \
OG_PARAM_PART_SIZE | \
- OG_PARAM_PART_USED_SIZE)
+ OG_PARAM_PART_USED_SIZE | \
+ OG_PARAM_PART_FREE_SIZE)
static int og_json_parse_partition_array(json_t *value,
struct og_partition *partitions,
@@ -406,7 +407,7 @@ static int og_json_parse_partition_array(json_t *value,
return 0;
}
-static int og_update_cache_info(struct og_dbi *dbi, struct list_head *cache_list, int clientid)
+static int og_update_cache_info(struct og_dbi *dbi, struct og_cache_data *cache_data, struct list_head *cache_list, int clientid)
{
struct og_cache_image *cache_image;
const char *msglog;
@@ -443,6 +444,23 @@ static int og_update_cache_info(struct og_dbi *dbi, struct list_head *cache_list
dbi_result_free(result);
}
+ /* Update partition sizes */
+ result = dbi_conn_queryf(dbi->conn,
+ "UPDATE ordenadores_particiones SET used_size = %lu, free_size = %lu"
+ " WHERE idordenador = %d AND codpar = %d",
+ cache_data->used_size,
+ cache_data->free_size,
+ clientid,
+ 202);
+
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return false;
+ }
+ dbi_result_free(result);
+
return 0;
}
@@ -487,6 +505,7 @@ static int og_update_boot_entries(struct og_dbi *dbi, struct list_head *boot_ent
static int og_resp_update_cache(json_t *data, struct og_client *cli)
{
+ struct og_cache_data cache_data = {};
struct og_computer computer = {};
json_t *value, *cache = NULL;
LIST_HEAD(cache_list);
@@ -501,9 +520,14 @@ static int og_resp_update_cache(json_t *data, struct og_client *cli)
json_object_foreach(data, key, value) {
if (!strcmp(key, "cache")) {
- err = og_json_parse_cache(value, &cache_list);
+ err = og_json_parse_cache(value, &cache_data, &cache_list);
cache = value;
}
+
+ if (err < 0) {
+ og_cache_image_free(&cache_list);
+ return err;
+ }
}
if (!cache) {
@@ -526,7 +550,7 @@ static int og_resp_update_cache(json_t *data, struct og_client *cli)
return -1;
}
- err = og_update_cache_info(dbi, &cache_list, computer.id);
+ err = og_update_cache_info(dbi, &cache_data, &cache_list, computer.id);
if (err < 0) {
og_cache_image_free(&cache_list);
og_dbi_close(dbi);
@@ -548,6 +572,7 @@ struct og_part {
uint32_t code;
uint64_t size;
uint64_t used_size;
+ uint64_t free_size;
};
static bool og_update_client_disk_info(struct og_dbi *dbi,
@@ -602,8 +627,9 @@ static bool og_update_client_disk_info(struct og_dbi *dbi,
result_update = dbi_conn_queryf(dbi->conn,
"INSERT INTO ordenadores_particiones("
"idordenador, numdisk, numpar, codpar, tamano, uso, "
- "idsistemafichero, idnombreso, disk_type, idimagen)"
- " VALUES(%d,%s,0,0x%s,%s,0,0,0,'%s',0)",
+ "idsistemafichero, idnombreso, disk_type, idimagen,"
+ "used_size, free_size)"
+ " VALUES(%d,%s,0,0x%s,%s,0,0,0,'%s',0,0,0)",
computer_id,
disks[i].disk,
disks[i].code,
@@ -656,7 +682,8 @@ static bool og_update_client_disk_info(struct og_dbi *dbi,
partitions[i].disk, partitions[i].number);
result = dbi_conn_queryf(dbi->conn,
- "SELECT numdisk, numpar, tamano, uso, idsistemafichero, idnombreso, codpar"
+ "SELECT numdisk, numpar, tamano, idsistemafichero, idnombreso, "
+ " codpar, used_size, free_size"
" FROM ordenadores_particiones"
" WHERE idordenador=%d AND numdisk=%s AND numpar=%s",
computer_id, partitions[i].disk, partitions[i].number);
@@ -668,9 +695,10 @@ static bool og_update_client_disk_info(struct og_dbi *dbi,
}
reported_part.size = strtoull(partitions[i].size, NULL, 0);
- reported_part.used_size = strtoull(partitions[i].used_size, NULL, 0);
reported_part.code = strtoul(partitions[i].code, NULL, 16);
reported_part.filesystem = get_filesystem_id(partitions[i].filesystem);
+ reported_part.used_size = partitions[i].used_size;
+ reported_part.free_size = partitions[i].free_size;
if (og_dbi_get_os_id(dbi, partitions[i].os, &reported_part.os) < 0) {
return false;
@@ -680,16 +708,18 @@ static bool og_update_client_disk_info(struct og_dbi *dbi,
result_update = dbi_conn_queryf(dbi->conn,
"INSERT INTO ordenadores_particiones("
"idordenador, numdisk, numpar, codpar, tamano, uso, "
- "idsistemafichero, idnombreso, idimagen)"
- " VALUES(%d,%s,%s,0x%d,%s,%d,%d,%d,0)",
+ "idsistemafichero, idnombreso, idimagen, "
+ "used_size, free_size)"
+ " VALUES(%d,%s,%s,0x%d,%s,0,%d,%d,0,%lu,%lu)",
computer_id,
partitions[i].disk,
partitions[i].number,
reported_part.code,
partitions[i].size,
- reported_part.used_size,
reported_part.filesystem,
- reported_part.os);
+ reported_part.os,
+ partitions[i].used_size,
+ partitions[i].free_size);
if (!result_update) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
@@ -706,10 +736,11 @@ static bool og_update_client_disk_info(struct og_dbi *dbi,
}
cur_part.size = dbi_result_get_longlong(result, "tamano");
- cur_part.used_size = dbi_result_get_longlong(result, "uso");
cur_part.code = dbi_result_get_int(result, "codpar");
cur_part.filesystem = dbi_result_get_uint(result, "idsistemafichero");
cur_part.os = dbi_result_get_uint(result, "idnombreso");
+ cur_part.used_size = dbi_result_get_longlong(result, "used_size");
+ cur_part.free_size = dbi_result_get_longlong(result, "free_size");
dbi_result_free(result);
if (cur_part.size != reported_part.size ||
@@ -720,14 +751,13 @@ static bool og_update_client_disk_info(struct og_dbi *dbi,
"UPDATE ordenadores_particiones SET "
" codpar=0x%s,"
" tamano=%s,"
- " uso=%d,"
" idsistemafichero=%d,"
" idnombreso=%d,"
" idimagen=0,"
" idperfilsoft=0,"
" fechadespliegue=NULL"
" WHERE idordenador=%d AND numdisk=%s AND numpar=%s",
- partitions[i].code, partitions[i].size, reported_part.used_size,
+ partitions[i].code, partitions[i].size,
reported_part.filesystem, reported_part.os, computer_id,
partitions[i].disk, partitions[i].number);
@@ -751,9 +781,9 @@ static bool og_update_client_disk_info(struct og_dbi *dbi,
result_update = dbi_conn_queryf(dbi->conn,
"UPDATE ordenadores_particiones SET "
- " uso=%d"
+ " uso=0, used_size=%lu, free_size=%lu"
" WHERE idordenador=%d AND numdisk=%s AND numpar=%s",
- reported_part.used_size, computer_id,
+ partitions[i].used_size, partitions[i].free_size, computer_id,
partitions[i].disk, partitions[i].number);
if (!result_update) {
dbi_conn_error(dbi->conn, &msglog);
@@ -788,12 +818,13 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
struct og_partition partitions[OG_PARTITION_MAX] = {};
struct og_partition disks[OG_DISK_MAX] = {};
uint32_t num_disks = 0, num_partitions = 0;
+ struct og_cache_data cache_data = {};
const char *serial_number = NULL;
struct og_computer computer = {};
- json_t *value, *cache = NULL;
const char *status = NULL;
LIST_HEAD(boot_entry_list);
LIST_HEAD(cache_list);
+ json_t *value = NULL;
struct og_dbi *dbi;
uint32_t link = 0;
const char *key;
@@ -819,8 +850,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
} else if (!strcmp(key, "efi")) {
err = og_json_parse_efi(value, &boot_entry_list);
} else if (!strcmp(key, "cache")) {
- err = og_json_parse_cache(value, &cache_list);
- cache = value;
+ err = og_json_parse_cache(value, &cache_data, &cache_list);
}
if (err < 0)
@@ -856,7 +886,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
goto err_out;
}
- if (cache && og_update_cache_info(dbi, &cache_list, computer.id) < 0) {
+ if (og_update_cache_info(dbi, &cache_data, &cache_list, computer.id) < 0) {
og_dbi_close(dbi);
goto err_out;
}