pmm  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
pmm_cfgparser.c File Reference

Functions for handling xml data files. More...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include "pmm_model.h"
#include "pmm_cfgparser.h"
#include "pmm_muparse.h"
#include "pmm_interval.h"
#include "pmm_param.h"
#include "pmm_load.h"
#include "pmm_log.h"

Go to the source code of this file.

Macros

#define TIME_STR_SIZE   256

Functions

struct pmm_loadhistoryparse_loadconfig (xmlDocPtr, xmlNodePtr node)
int sync_parent_dir (char *file_path)
int parse_paramdef_set (struct pmm_paramdef_set *pd_set, xmlDocPtr doc, xmlNodePtr node)
int parse_paramdef (struct pmm_paramdef *pd_array, int n_p, xmlDocPtr doc, xmlNodePtr node)
int parse_param_constraint (struct pmm_paramdef_set *pd_set, xmlDocPtr doc, xmlNodePtr node)
int parse_bench_list (struct pmm_model *m, xmlDocPtr doc, xmlNodePtr node)
int parse_routine_construction (struct pmm_routine *r, xmlDocPtr doc, xmlNodePtr node)
struct pmm_routineparse_routine (xmlDocPtr doc, xmlNodePtr node)
int parse_config (struct pmm_config *cfg)
struct timeval * parse_timeval (xmlDocPtr doc, xmlNodePtr node)
int parse_timeval_p (struct timeval *t, xmlDocPtr doc, xmlNodePtr node)
int parse_parameter_array_p (int **p, int *n_p, xmlDocPtr doc, xmlNodePtr node)
struct pmm_benchmarkparse_benchmark (xmlDocPtr doc, xmlNodePtr node)
struct pmm_intervalparse_interval (xmlDocPtr doc, xmlNodePtr node)
struct pmm_loadparse_load (xmlDocPtr doc, xmlNodePtr node)
int parse_history (struct pmm_loadhistory *h)
int parse_interval_list (struct pmm_model *m, xmlDocPtr doc, xmlNodePtr node)
int parse_model (struct pmm_model *m)
int parse_models (struct pmm_config *c)
int write_interval_xtwp (xmlTextWriterPtr writer, struct pmm_interval *i)
int write_loadhistory (struct pmm_loadhistory *h)
int write_loadhistory_xtwp (xmlTextWriterPtr writer, struct pmm_loadhistory *h)
int check_lock (int fd, int type)
int write_models (struct pmm_config *cfg)
int write_model (struct pmm_model *m)
int sync_close_file (int fd)
int write_model_xtwp (xmlTextWriterPtr writer, struct pmm_model *m)
int write_bench_list_xtwp (xmlTextWriterPtr writer, struct pmm_bench_list *bench_list)
int write_paramdef_set_xtwp (xmlTextWriterPtr writer, struct pmm_paramdef_set *pd_set)
int write_paramdef_xtwp (xmlTextWriterPtr writer, struct pmm_paramdef *pd)
int write_parameter_array_xtwp (xmlTextWriterPtr writer, int *p, int n)
int write_benchmark_xtwp (xmlTextWriterPtr writer, struct pmm_benchmark *b)
int write_timeval_xtwp (xmlTextWriterPtr writer, struct timeval *t)
void xmlparser_init ()
void xmlparser_cleanup ()

Detailed Description

Functions for handling xml data files.

This file contains code for parsing and writing xml files which store the various data structures of the program, those being models, load history and the pmm daemon configuration file

Definition in file pmm_cfgparser.c.

Macro Definition Documentation

#define TIME_STR_SIZE   256

size of ISO 8601 time string

Definition at line 2135 of file pmm_cfgparser.c.

Function Documentation

int check_lock ( int  fd,
int  type 
)

Check if a file descriptor is locked

Parameters
fdthe file descriptor to check
typethe type of lock to test FD_WRLCK, FD_RDLCK, FD_RWLCK
Returns
-1 on error, 0 if file is not locked, pid of owning process if file is locked

Definition at line 2255 of file pmm_cfgparser.c.

int parse_bench_list ( struct pmm_model m,
xmlDocPtr  doc,
xmlNodePtr  node 
)

Parse a bench list from an xml document into a model.

Parameters
mpointer to the model
docpointer to the xml document
nodepointer to the node describing the bench list
Returns
0 on success, -1 on failure

Definition at line 1395 of file pmm_cfgparser.c.

struct pmm_benchmark* parse_benchmark ( xmlDocPtr  doc,
xmlNodePtr  node 
)
read

Parse a benchmark from xml document.

Parameters
docpointer to the xml document
nodepointer to the node describing the benchmark
Returns
pointer to a newly allocated benchmark representing the parsed information or NULL on error

Definition at line 979 of file pmm_cfgparser.c.

int parse_config ( struct pmm_config cfg)

Parse xml config file into config structure.

Parameters
cfgpointer to config structure to store parsed data
Returns
0 on success, -1 on failure
Precondition
cfg points to an allocated pmm_config structure
cfg structure member 'configfile' must be set to the config file path or this function will return an error

Definition at line 613 of file pmm_cfgparser.c.

int parse_history ( struct pmm_loadhistory h)

Parse the load history file.

Parameters
hpointer to a load history structure, already populated with config data (i.e. the load history file path)
Returns
0 on success, -1 on failure.

Definition at line 1267 of file pmm_cfgparser.c.

struct pmm_interval* parse_interval ( xmlDocPtr  doc,
xmlNodePtr  node 
)
read

Parse an interval from an xml document.

Parameters
docpointer to the xml document
nodepointer to the node describing the interval
Returns
newly allocated interval or NULL on failure.

Definition at line 1077 of file pmm_cfgparser.c.

int parse_interval_list ( struct pmm_model m,
xmlDocPtr  doc,
xmlNodePtr  node 
)

Parse an interval list from an xml document into a model.

Parameters
mpointer to the model
docpointer to the xml document
nodepointer to the node beginning the description of the interval list
Returns
0 on success, -1 on failure

Definition at line 1478 of file pmm_cfgparser.c.

struct pmm_load* parse_load ( xmlDocPtr  doc,
xmlNodePtr  node 
)
read

Parse a load record from an xml document.

Parameters
docpointer to the xml document
nodepointer to the node describing the load
Returns
pointer to a newly allocated load record or NULL on failure

Definition at line 1181 of file pmm_cfgparser.c.

struct pmm_loadhistory * parse_loadconfig ( xmlDocPtr  doc,
xmlNodePtr  node 
)
read

Parse load history configuration information from an xml document.

Parameters
docpointer to the xml document
nodepointer to the node describing the load history config
Returns
pointer to loadhistory structure or NULL on failure

TODO FIX naming

Definition at line 730 of file pmm_cfgparser.c.

int parse_model ( struct pmm_model m)

Parses a model from an xml file. The model structure is expected to have the path of the file already stored.

Parameters
mpointer to the model
Returns
0 on success, -1 if no model file exists, -2 on other error

Definition at line 1522 of file pmm_cfgparser.c.

int parse_models ( struct pmm_config c)

Parse models of routines listed in the config structure.

Parameters
cpointer to the config with all routine details
Returns
0 on success, -1 on failure

Definition at line 1732 of file pmm_cfgparser.c.

int parse_param_constraint ( struct pmm_paramdef_set pd_set,
xmlDocPtr  doc,
xmlNodePtr  node 
)

parse an xml parameter constraint defintiion into the paramdef set structure

Parameters
pd_setpointer to the paramdef set structure
docpointer to the xml document
nodepointer to the node of the xml document describing the parameter constraints
Returns
0 on success, -1 on failure

Definition at line 366 of file pmm_cfgparser.c.

int parse_paramdef ( struct pmm_paramdef pd_array,
int  n_p,
xmlDocPtr  doc,
xmlNodePtr  node 
)

parse an xml parameter definition into the paramdef array of a routine

Parameters
pd_arraypointer to the parameter definition array
n_pnumber of parameter defintions
docpointer to the xml document
nodepointer to node of xml document describing parameter def
Returns
0 on success, -1 on failure

Definition at line 420 of file pmm_cfgparser.c.

int parse_paramdef_set ( struct pmm_paramdef_set pd_set,
xmlDocPtr  doc,
xmlNodePtr  node 
)

Parse multiple xml parameter definitions into a paramdef array

Parameters
pd_setpointer to parameter definition set structure
docpointer to the xml document to parse
nodepointer to the node of the xml tree describing the parameter definitions
Returns
0 on success, -1 on failure

Definition at line 248 of file pmm_cfgparser.c.

int parse_parameter_array_p ( int **  p,
int *  n_p,
xmlDocPtr  doc,
xmlNodePtr  node 
)

Parse an xml parameter array into a parameter array and size integer

Parameters
ppointer to the parameter array pointer
n_ppointer to the integer to store the size in
docpointer to the xml document
nodepointer to the xml node that describes the param array
Returns
0 on succes, -1 on failure

Definition at line 891 of file pmm_cfgparser.c.

struct pmm_routine* parse_routine ( xmlDocPtr  doc,
xmlNodePtr  node 
)
read

Parse a routine from an xml document

Parameters
docpointer to the xml document
nodepointer to the node describing the routine
Returns
pointer to a routine structure containing the parsed data, or NULL on failure

Definition at line 125 of file pmm_cfgparser.c.

int parse_routine_construction ( struct pmm_routine r,
xmlDocPtr  doc,
xmlNodePtr  node 
)

Parse routine construction information from xml specification.

Parameters
rpointer to the corresponding routine
docpointer to the xml document
nodepointer to the construction information node in the xml doc
Returns
0 on success, -1 on failure

Definition at line 533 of file pmm_cfgparser.c.

struct timeval* parse_timeval ( xmlDocPtr  doc,
xmlNodePtr  node 
)
read

Parse xml description of a timeval into a newly allocated timeval structure

Parameters
docpointer to the xml document
nodepointer to the node describing the timeval
Returns
pointer to a timeval structure or NULL on failure

Definition at line 796 of file pmm_cfgparser.c.

int parse_timeval_p ( struct timeval *  t,
xmlDocPtr  doc,
xmlNodePtr  node 
)

Parse a timeval from an xml doc.

Parameters
tpointer to the timeval structure to store to
docpointer to the xml document
nodepointer to the timeval node in the xml doc.
Returns
0 on success, or -1 on failure

Definition at line 845 of file pmm_cfgparser.c.

int sync_close_file ( int  fd)

attempt to sync and close an open file descriptor.

Parameters
fdfile discriptor
Returns
0 on success, -1 on failure

Definition at line 2500 of file pmm_cfgparser.c.

int sync_parent_dir ( char *  file_path)

attempt to sync the directory contained by a file in a particular path

Parameters
file_pathpointer to character array giving path of file
Returns
0 on success, -1 on failure

Definition at line 2531 of file pmm_cfgparser.c.

int write_bench_list_xtwp ( xmlTextWriterPtr  writer,
struct pmm_bench_list bench_list 
)

Write a benchmark list to an xmlTextWriterPtr object

Parameters
writerxmlTextWriter pointer
bench_listpointer to the benchmark list
Returns
0 on success, -1 on failure

Definition at line 2693 of file pmm_cfgparser.c.

int write_benchmark_xtwp ( xmlTextWriterPtr  writer,
struct pmm_benchmark b 
)

Write a benchmark to an xmlTextWriterPtr object

Parameters
writerxmlTextWriter pointer
bpointer to the benchmark
Returns
0 on success -1 on error

Definition at line 2984 of file pmm_cfgparser.c.

int write_interval_xtwp ( xmlTextWriterPtr  writer,
struct pmm_interval i 
)

write an interval structure to disk in xml

Parameters
writerxmlTextWriterPtr to use to write with
ipointer to interval structure to write to disk
Returns
0 on success, -1 on failure

Definition at line 1776 of file pmm_cfgparser.c.

int write_loadhistory ( struct pmm_loadhistory h)

write the load history to file

opens an xmlTextWriter and writes the history to the file specified in the history structure

Parameters
hpointer to the load history
Returns
0 on success, -1 on failure

Definition at line 1956 of file pmm_cfgparser.c.

int write_loadhistory_xtwp ( xmlTextWriterPtr  writer,
struct pmm_loadhistory h 
)

Write load history to the xmlTextWriterPtr

Parameters
writeran xmlTextWriter pointer
hpointer to load load history structure
Returns
0 on success, -1 on failure

Definition at line 2145 of file pmm_cfgparser.c.

int write_model ( struct pmm_model m)

write an individual model to disk

Parameters
mpointer to the model
Returns
0 on success, -1 on failure

Definition at line 2315 of file pmm_cfgparser.c.

int write_model_xtwp ( xmlTextWriterPtr  writer,
struct pmm_model m 
)

Write a model list to an xmlTextWriterPtr object

Parameters
writerxmlTextWriter pointer
mpointer to the model
Returns
0 on success, -1 on failure

Definition at line 2591 of file pmm_cfgparser.c.

int write_models ( struct pmm_config cfg)

write all models in the configuration

Parameters
cfgpointer to the configuration
Returns
0 on success, -1 on failure

Definition at line 2288 of file pmm_cfgparser.c.

int write_paramdef_set_xtwp ( xmlTextWriterPtr  writer,
struct pmm_paramdef_set pd_set 
)

Write the parameter definition set to an xmlTextWriterPtr object

Parameters
writerxmlTextWriter pointer
pd_setpointer to the parameter defintion set
Returns
0 on success, -1 on failure

Definition at line 2750 of file pmm_cfgparser.c.

int write_paramdef_xtwp ( xmlTextWriterPtr  writer,
struct pmm_paramdef pd 
)

Write a parameter definition to an xmlTextWriterPtr object

Parameters
writerxmlTextWriter pointer
pdpointer to the parameter definition to write
Returns
0 on success -1 on error

Definition at line 2837 of file pmm_cfgparser.c.

int write_parameter_array_xtwp ( xmlTextWriterPtr  writer,
int *  p,
int  n 
)

Write a parameter array to an xmlTextWriterPtr object

In the form:

<parameter_array> <n_p>n</n_p> <parameter>p[0]</parameter> <parameter> .... </parameter_array>

Parameters
writerwriter to use
pparameter array
nnumber of parameters in array
Returns
0 on succes, -1 on failure

Definition at line 2933 of file pmm_cfgparser.c.

int write_timeval_xtwp ( xmlTextWriterPtr  writer,
struct timeval *  t 
)

Write a timeval to an xmlTextWriterPtr object

Parameters
writerxmlTextWriter pointer
tpointer to the timeval
Returns
0 on success -1 on error

Definition at line 3076 of file pmm_cfgparser.c.

void xmlparser_cleanup ( )

clean up libxml parser

Definition at line 3113 of file pmm_cfgparser.c.

void xmlparser_init ( )

initialized libxml2 parser

Definition at line 3104 of file pmm_cfgparser.c.