Add datastore-specific logging

This commit is contained in:
Philip Prindeville 2024-01-18 11:54:34 -07:00 committed by Olof Hagsand
parent 42a92f262a
commit 23b538e7dc
3 changed files with 22 additions and 20 deletions

View file

@ -56,13 +56,14 @@
/* Subject area */
#define CLIXON_DBG_DEFAULT 0x000001 /* Default logs */
#define CLIXON_DBG_MSG 0x000002 /* In/out messages and datastore reads */
#define CLIXON_DBG_MSG 0x000002 /* In/out messages */
#define CLIXON_DBG_XML 0x000004 /* XML processing */
#define CLIXON_DBG_XPATH 0x000008 /* XPath processing */
#define CLIXON_DBG_YANG 0x000010 /* YANG processing */
#define CLIXON_DBG_CLIENT 0x000020 /* App-specific */
#define CLIXON_DBG_NACM 0x000040 /* NACM processing */
#define CLIXON_DBG_PROC 0x000080 /* Process handling */
#define CLIXON_DBG_DATASTORE 0x000100 /* Datastore management */
#define CLIXON_DBG_SMASK 0x00ffff /* Subject mask */
/*

View file

@ -188,7 +188,7 @@ xmldb_copy(clixon_handle h,
cxobj *x1 = NULL; /* from */
cxobj *x2 = NULL; /* to */
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", from, to);
clixon_debug(CLIXON_DBG_DATASTORE, "%s %s", from, to);
/* XXX lock */
if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){
/* Copy in-memory cache */
@ -237,6 +237,7 @@ xmldb_copy(clixon_handle h,
goto done;
retval = 0;
done:
clixon_debug(CLIXON_DBG_DATASTORE, "retval:%d", retval);
if (fromfile)
free(fromfile);
if (tofile)
@ -265,7 +266,7 @@ xmldb_lock(clixon_handle h,
de0.de_id = id;
gettimeofday(&de0.de_tv, NULL);
clicon_db_elmnt_set(h, db, &de0);
clixon_debug(CLIXON_DBG_DEFAULT, "%s: locked by %u", db, id);
clixon_debug(CLIXON_DBG_DATASTORE, "%s: locked by %u", db, id);
return 0;
}
@ -384,7 +385,7 @@ xmldb_exists(clixon_handle h,
char *filename = NULL;
struct stat sb;
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "%s", db);
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "%s", db);
if (xmldb_db2file(h, db, &filename) < 0)
goto done;
if (lstat(filename, &sb) < 0)
@ -397,6 +398,7 @@ xmldb_exists(clixon_handle h,
retval = 1;
}
done:
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (filename)
free(filename);
return retval;
@ -442,7 +444,7 @@ xmldb_delete(clixon_handle h,
char *filename = NULL;
struct stat sb;
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "%s", db);
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "%s", db);
if (xmldb_clear(h, db) < 0)
goto done;
if (xmldb_db2file(h, db, &filename) < 0)
@ -454,6 +456,7 @@ xmldb_delete(clixon_handle h,
}
retval = 0;
done:
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (filename)
free(filename);
return retval;
@ -476,7 +479,7 @@ xmldb_create(clixon_handle h,
db_elmnt *de = NULL;
cxobj *xt = NULL;
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "%s", db);
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "%s", db);
if ((de = clicon_db_elmnt_get(h, db)) != NULL){
if ((xt = de->de_xml) != NULL){
xml_free(xt);
@ -489,8 +492,9 @@ xmldb_create(clixon_handle h,
clixon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
}
retval = 0;
retval = 0;
done:
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (filename)
free(filename);
if (fd != -1)

View file

@ -500,7 +500,7 @@ xmldb_readfile(clixon_handle h,
clixon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
goto done;
}
clixon_debug(CLIXON_DBG_DEFAULT, "Reading datastore %s using %s", dbfile, format);
clixon_debug(CLIXON_DBG_DATASTORE, "Reading datastore %s using %s", dbfile, format);
/* Parse file into internal XML tree from different formats */
if ((fp = fopen(dbfile, "r")) == NULL) {
clixon_err(OE_UNIX, errno, "open(%s)", dbfile);
@ -796,14 +796,12 @@ xmldb_get_nocache(clixon_handle h,
if (disable_nacm_on_empty(xt, yspec) < 0)
goto done;
}
if (clixon_debug_isset(CLIXON_DBG_DEFAULT))
if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0)
goto done;
clixon_debug_xml(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, xt, "");
*xtop = xt;
xt = NULL;
retval = 1;
done:
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (xt)
xml_free(xt);
if (xvec)
@ -860,6 +858,8 @@ xmldb_get_cache(clixon_handle h,
db_elmnt de0 = {0,};
int ret;
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "db %s", db);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done;
@ -991,11 +991,11 @@ xmldb_get_cache(clixon_handle h,
if (disable_nacm_on_empty(x1t, yspec) < 0)
goto done;
}
clixon_debug_xml(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, x1t, "");
clixon_debug_xml(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, x1t, "");
*xtop = x1t;
retval = 1;
done:
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (xvec)
free(xvec);
return retval;
@ -1040,7 +1040,6 @@ xmldb_get_zerocopy(clixon_handle h,
cxobj **xvec = NULL;
size_t xlen;
int i;
cxobj *x0;
db_elmnt *de = NULL;
db_elmnt de0 = {0,};
int ret;
@ -1075,7 +1074,7 @@ xmldb_get_zerocopy(clixon_handle h,
* For every node found in x0, mark the tree up to t1
*/
for (i=0; i<xlen; i++){
x0 = xvec[i];
cxobj *x0 = xvec[i];
xml_flag_set(x0, XML_FLAG_MARK);
xml_apply_ancestor(x0, (xml_applyfn_t*)xml_flag_set, (void*)XML_FLAG_CHANGE);
}
@ -1140,13 +1139,11 @@ xmldb_get_zerocopy(clixon_handle h,
if (disable_nacm_on_empty(x0t, yspec) < 0)
goto done;
}
if (clixon_debug_isset(CLIXON_DBG_DEFAULT))
if (clixon_xml2file(stderr, x0t, 0, 1, NULL, fprintf, 0, 0) < 0)
goto done;
clixon_debug_xml(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, x0t, "");
*xtop = x0t;
retval = 1;
done:
clixon_debug(CLIXON_DBG_DEFAULT | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_debug(CLIXON_DBG_DATASTORE | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (xvec)
free(xvec);
return retval;