Add metadata version support

This commit is contained in:
Rodrigo Arias 2022-06-07 11:00:15 +02:00
parent 6fd2b51621
commit 6180235b50
3 changed files with 41 additions and 0 deletions

14
ovni.c
View File

@ -167,6 +167,19 @@ proc_set_app(int appid)
die("json_object_set_number for app_id failed\n"); die("json_object_set_number for app_id failed\n");
} }
static void
proc_set_version(void)
{
JSON_Object *meta = json_value_get_object(rproc.meta);
if(meta == NULL)
die("json_value_get_object failed\n");
if(json_object_set_number(meta, "version", OVNI_METADATA_VERSION) != 0)
die("json_object_set_number for app_id failed\n");
}
void void
ovni_proc_set_rank(int rank, int nranks) ovni_proc_set_rank(int rank, int nranks)
{ {
@ -246,6 +259,7 @@ ovni_proc_init(int app, const char *loom, int pid)
rproc.ready = 1; rproc.ready = 1;
proc_set_version();
proc_set_app(app); proc_set_app(app);
} }

2
ovni.h
View File

@ -40,6 +40,8 @@ extern "C" {
/* Hardcode the JSON_Value to avoid a dependency with janson */ /* Hardcode the JSON_Value to avoid a dependency with janson */
typedef struct json_value_t JSON_Value; typedef struct json_value_t JSON_Value;
#define OVNI_METADATA_VERSION 1
#define OVNI_TRACEDIR "ovni" #define OVNI_TRACEDIR "ovni"
#define OVNI_MAX_HOSTNAME 512 #define OVNI_MAX_HOSTNAME 512

25
trace.c
View File

@ -124,6 +124,29 @@ load_proc_metadata(struct ovni_eproc *proc, int *rank_enabled)
} }
} }
static void
check_metadata_version(struct ovni_eproc *proc)
{
JSON_Object *meta = json_value_get_object(proc->meta);
if(meta == NULL)
die("check_metadata_version: json_value_get_object() failed\n");
JSON_Value *version_val = json_object_get_value(meta, "version");
if(version_val == NULL)
{
die("process %d is missing attribute \"version\" in metadata\n",
proc->pid);
}
int version = (int) json_number(version_val);
if(version != OVNI_METADATA_VERSION)
{
die("pid %d: metadata version mismatch %d (expected %d)\n",
proc->pid, version,
OVNI_METADATA_VERSION);
}
}
static int static int
load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, char *procdir) load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, char *procdir)
@ -156,6 +179,8 @@ load_proc(struct ovni_eproc *proc, struct ovni_loom *loom, int index, int pid, c
return -1; return -1;
} }
check_metadata_version(proc);
/* The appid is populated from the metadata */ /* The appid is populated from the metadata */
load_proc_metadata(proc, &loom->rank_enabled); load_proc_metadata(proc, &loom->rank_enabled);