summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-05-14 10:45:59 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-05-26 17:19:30 +0200
commit12d8fff3efef35aa61777f82133e627030bc0b27 (patch)
tree9ee62c732703f84cd565d55b68a809466fce1a45 /src
parent10c9559dfc46afd5710b2d49fb61fe5ccafc87d0 (diff)
#1037 Add disk type
Add ogServer support for parsing and storing in the DB disk type data from ogClient refresh response. See also commits with #1037 in ogClient and WebConsole repo.
Diffstat (limited to 'src')
-rw-r--r--src/client.c4
-rw-r--r--src/json.c3
-rw-r--r--src/json.h2
-rw-r--r--src/ogAdmServer.c18
-rw-r--r--src/schema.c38
5 files changed, 57 insertions, 8 deletions
diff --git a/src/client.c b/src/client.c
index 0a2c33e..44e7c1b 100644
--- a/src/client.c
+++ b/src/client.c
@@ -321,11 +321,11 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
continue;
snprintf(cfg + strlen(cfg), sizeof(cfg) - strlen(cfg),
- "disk=%s\tpar=%s\tcpt=%s\tfsi=%s\tsoi=%s\ttam=%s\tuso=%s\n",
+ "disk=%s\tpar=%s\tcpt=%s\tfsi=%s\tsoi=%s\ttam=%s\tuso=%s\tdtype=%s\n",
disks[i].disk, disks[i].number,
disks[i].code, disks[i].filesystem,
disks[i].os, disks[i].size,
- disks[i].used_size);
+ disks[i].used_size, disks[i].disk_type);
}
for (i = 0; i < OG_PARTITION_MAX; i++) {
diff --git a/src/json.c b/src/json.c
index 7a849cb..a2b300f 100644
--- a/src/json.c
+++ b/src/json.c
@@ -120,6 +120,9 @@ int og_json_parse_partition(json_t *element, struct og_partition *part,
} else if (!strcmp(key, "disk")) {
err = og_json_parse_string(value, &part->disk);
flags |= OG_PARAM_PART_DISK;
+ } else if (!strcmp(key, "disk_type")) {
+ err = og_json_parse_string(value, &part->disk_type);
+ flags |= OG_PARAM_PART_DISK_TYPE;
} else if (!strcmp(key, "os")) {
err = og_json_parse_string(value, &part->os);
flags |= OG_PARAM_PART_OS;
diff --git a/src/json.h b/src/json.h
index d7bc072..193544a 100644
--- a/src/json.h
+++ b/src/json.h
@@ -18,9 +18,11 @@ int og_json_parse_bool(json_t *element, bool *value);
#define OG_PARAM_PART_DISK (1UL << 5)
#define OG_PARAM_PART_OS (1UL << 6)
#define OG_PARAM_PART_USED_SIZE (1UL << 7)
+#define OG_PARAM_PART_DISK_TYPE (1UL << 8)
struct og_partition {
const char *disk;
+ const char *disk_type;
const char *number;
const char *code;
const char *size;
diff --git a/src/ogAdmServer.c b/src/ogAdmServer.c
index 77ddff8..5d46765 100644
--- a/src/ogAdmServer.c
+++ b/src/ogAdmServer.c
@@ -47,8 +47,8 @@
bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
{
int lon, p, c,i, dato, swu, idsoi, idsfi,k;
- char *ptrPar[MAXPAR], *ptrCfg[7], *ptrDual[2], tbPar[LONSTD];
- char *ser, *disk, *par, *cpt, *sfi, *soi, *tam, *uso; // Parametros de configuración.
+ char *ptrPar[MAXPAR], *ptrCfg[8], *ptrDual[2], tbPar[LONSTD];
+ char *ser, *disk, *disk_type, *par, *cpt, *sfi, *soi, *tam, *uso; // Parametros de configuración.
dbi_result result, result_update;
const char *msglog;
@@ -79,7 +79,7 @@ bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
}
// Distribución de particionado.
- disk = par = cpt = sfi = soi = tam = uso = NULL;
+ disk = disk_type = par = cpt = sfi = soi = tam = uso = NULL;
splitCadena(ptrDual, ptrCfg[0], '=');
disk = ptrDual[1]; // Número de disco
@@ -118,6 +118,12 @@ bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
splitCadena(ptrDual, ptrCfg[6], '=');
uso = ptrDual[1]; // Porcentaje de uso del S.F.
+ k = splitCadena(ptrDual, ptrCfg[7], '=');
+ if (k == 2)
+ disk_type = ptrDual[1];
+ else
+ disk_type = NULL;
+
lon += sprintf(tbPar + lon, "(%s, %s),", disk, par);
result = dbi_conn_queryf(dbi->conn,
@@ -133,9 +139,9 @@ bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
}
if (!dbi_result_next_row(result)) {
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%s,%s,%s,%d,%d,0)",
- ido, disk, par, cpt, tam, uso, idsfi, idsoi);
+ "INSERT INTO ordenadores_particiones(idordenador,numdisk,disk_type,numpar,codpar,tamano,uso,idsistemafichero,idnombreso,idimagen)"
+ " VALUES(%d,%s,'%s',%s,0x%s,%s,%s,%d,%d,0)",
+ ido, disk, disk_type, par, cpt, tam, uso, idsfi, idsoi);
if (!result_update) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
diff --git a/src/schema.c b/src/schema.c
index efd8339..68c481f 100644
--- a/src/schema.c
+++ b/src/schema.c
@@ -178,12 +178,50 @@ err_no_trans:
return -1;
}
+static int og_dbi_schema_v3(struct og_dbi *dbi)
+{
+ const char *msglog, *command;
+ dbi_result result, result_alter;
+
+ result = dbi_conn_query(dbi->conn,
+ "ALTER TABLE ordenadores_particiones "
+ "ADD disk_type VARCHAR(32) DEFAULT NULL "
+ "AFTER numdisk;");
+
+ while (dbi_result_next_row(result)) {
+ command = dbi_result_get_string(result, "cmd");
+
+ syslog(LOG_DEBUG, "Adding disk type: %s\n", command);
+ result_alter = dbi_conn_query(dbi->conn, command);
+ if (!result_alter) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_INFO, "Error when adding disk type (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+ dbi_result_free(result_alter);
+ }
+ dbi_result_free(result);
+
+ result = dbi_conn_query(dbi->conn, "UPDATE version SET version = 3");
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_INFO, "Could not update version row (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+ dbi_result_free(result);
+
+ return 0;
+}
+
static struct og_schema_version {
int version;
int (*update)(struct og_dbi *dbi);
} schema_version[] = {
{ .version = 1, .update = og_dbi_schema_v1 },
{ .version = 2, .update = og_dbi_schema_v2 },
+ { .version = 3, .update = og_dbi_schema_v3 },
{ 0, NULL },
};