Re-optimized yang cardinality

Misc rearrangements
This commit is contained in:
Olof hagsand 2024-05-02 13:29:59 +02:00
parent d2f3405ab6
commit fcdfbd23cc
6 changed files with 46 additions and 56 deletions

View file

@ -661,12 +661,12 @@ candidate_validate(clixon_handle h,
* @retval -1 Error - or validation failed * @retval -1 Error - or validation failed
*/ */
int int
candidate_commit(clixon_handle h, candidate_commit(clixon_handle h,
cxobj *xe, cxobj *xe,
char *db, char *db,
uint32_t myid, uint32_t myid,
validate_level vlev, // obsolete validate_level vlev, // obsolete
cbuf *cbret) cbuf *cbret)
{ {
int retval = -1; int retval = -1;
transaction_data_t *td = NULL; transaction_data_t *td = NULL;
@ -674,6 +674,7 @@ candidate_commit(clixon_handle h,
cxobj *xret = NULL; cxobj *xret = NULL;
yang_stmt *yspec; yang_stmt *yspec;
clixon_debug(CLIXON_DBG_DATASTORE, "db: %s", db);
/* 1. Start transaction */ /* 1. Start transaction */
if ((td = transaction_new()) == NULL) if ((td = transaction_new()) == NULL)
goto done; goto done;
@ -698,7 +699,6 @@ candidate_commit(clixon_handle h,
clixon_err(OE_YANG, ENOENT, "No yang spec"); clixon_err(OE_YANG, ENOENT, "No yang spec");
goto done; goto done;
} }
if (if_feature(yspec, "ietf-netconf", "confirmed-commit") if (if_feature(yspec, "ietf-netconf", "confirmed-commit")
&& confirmed_commit_state_get(h) != ROLLBACK && confirmed_commit_state_get(h) != ROLLBACK
&& xe != NULL){ && xe != NULL){

View file

@ -267,14 +267,18 @@ xmldb_copy(clixon_handle h,
const char *from, const char *from,
const char *to) const char *to)
{ {
int retval = -1; int retval = -1;
char *fromfile = NULL; char *fromfile = NULL;
char *tofile = NULL; char *tofile = NULL;
db_elmnt *de1 = NULL; /* from */ db_elmnt *de1 = NULL; /* from */
db_elmnt *de2 = NULL; /* to */ db_elmnt *de2 = NULL; /* to */
db_elmnt de0 = {0,}; db_elmnt de0 = {0,};
cxobj *x1 = NULL; /* from */ cxobj *x1 = NULL; /* from */
cxobj *x2 = NULL; /* to */ cxobj *x2 = NULL; /* to */
char *fromdir = NULL;
char *todir = NULL;
char *subdir = NULL;
struct stat st = {0,};
clixon_debug(CLIXON_DBG_DATASTORE, "%s %s", from, to); clixon_debug(CLIXON_DBG_DATASTORE, "%s %s", from, to);
/* XXX lock */ /* XXX lock */
@ -313,9 +317,6 @@ xmldb_copy(clixon_handle h,
de0 = *de2; de0 = *de2;
de0.de_xml = x2; /* The new tree */ de0.de_xml = x2; /* The new tree */
if (clicon_option_bool(h, "CLICON_XMLDB_MULTI")){ if (clicon_option_bool(h, "CLICON_XMLDB_MULTI")){
char *subdir = NULL;
struct stat st = {0,};
if (xmldb_db2subdir(h, to, &subdir) < 0) if (xmldb_db2subdir(h, to, &subdir) < 0)
goto done; goto done;
if (stat(subdir, &st) < 0){ if (stat(subdir, &st) < 0){
@ -324,11 +325,11 @@ xmldb_copy(clixon_handle h,
goto done; goto done;
} }
} }
if (subdir)
free(subdir);
} }
clicon_db_elmnt_set(h, to, &de0); clicon_db_elmnt_set(h, to, &de0);
/* Copy the files themselves (above only in-memory cache) */ /* Copy the files themselves (above only in-memory cache)
* Alt, dump the cache to file
*/
if (xmldb_db2file(h, from, &fromfile) < 0) if (xmldb_db2file(h, from, &fromfile) < 0)
goto done; goto done;
if (xmldb_db2file(h, to, &tofile) < 0) if (xmldb_db2file(h, to, &tofile) < 0)
@ -336,8 +337,7 @@ xmldb_copy(clixon_handle h,
if (clicon_file_copy(fromfile, tofile) < 0) if (clicon_file_copy(fromfile, tofile) < 0)
goto done; goto done;
if (clicon_option_bool(h, "CLICON_XMLDB_MULTI")) { if (clicon_option_bool(h, "CLICON_XMLDB_MULTI")) {
char *fromdir = NULL;
char *todir = NULL;
if (xmldb_db2subdir(h, from, &fromdir) < 0) if (xmldb_db2subdir(h, from, &fromdir) < 0)
goto done; goto done;
@ -345,14 +345,16 @@ xmldb_copy(clixon_handle h,
goto done; goto done;
if (clicon_dir_copy(fromdir, todir) < 0) if (clicon_dir_copy(fromdir, todir) < 0)
goto done; goto done;
if (fromdir)
free(fromdir);
if (todir)
free(todir);
} }
retval = 0; retval = 0;
done: done:
clixon_debug(CLIXON_DBG_DATASTORE, "retval:%d", retval); clixon_debug(CLIXON_DBG_DATASTORE, "retval:%d", retval);
if (subdir)
free(subdir);
if (fromdir)
free(fromdir);
if (todir)
free(todir);
if (fromfile) if (fromfile)
free(fromfile); free(fromfile);
if (tofile) if (tofile)

View file

@ -501,7 +501,7 @@ clixon_err_restore(void* handle)
if ((es = (struct err_state *)handle) != NULL){ if ((es = (struct err_state *)handle) != NULL){
_err_category = es->es_category; _err_category = es->es_category;
_err_subnr = es->es_subnr; _err_subnr = es->es_subnr;
strncpy(_err_reason, es->es_reason, ERR_STRLEN-1); strcpy(_err_reason, es->es_reason);
free(es); free(es);
} }
return 0; return 0;

View file

@ -468,7 +468,7 @@ static const struct ycard *_yc_search[Y_SPEC][Y_SPEC] = {{0,},{0,}};
* and = 0 in the following vector. * and = 0 in the following vector.
* Example: Y_REFINE * Example: Y_REFINE
*/ */
static int _yc_exist[Y_SPEC] = {0,}; static const struct ycard *_yc_exist[Y_SPEC] = {NULL,}; /* First */
/*! Check cardinality, ie if each yang node has the expected nr of children /*! Check cardinality, ie if each yang node has the expected nr of children
* *
@ -492,7 +492,7 @@ yang_cardinality(clixon_handle h,
yang_stmt *ys = NULL; yang_stmt *ys = NULL;
int pk; int pk;
int ck; int ck;
int i; const struct ycard *yc0;
const struct ycard *yc; const struct ycard *yc;
int order; int order;
yang_stmt *yprev = NULL; yang_stmt *yprev = NULL;
@ -500,7 +500,7 @@ yang_cardinality(clixon_handle h,
int yc_count[Y_SPEC] = {0,}; int yc_count[Y_SPEC] = {0,};
pk = yang_keyword_get(yt); pk = yang_keyword_get(yt);
if (_yc_exist[pk] == 0) if ((yc0 = _yc_exist[pk]) == NULL)
goto ok; goto ok;
/* 1) For all children, if neither in 0..n, 0..1, 1 or 1..n ->ERROR /* 1) For all children, if neither in 0..n, 0..1, 1 or 1..n ->ERROR
* Also: check monotonically increasing order * Also: check monotonically increasing order
@ -534,18 +534,15 @@ yang_cardinality(clixon_handle h,
} }
if (order < yc->yc_order) if (order < yc->yc_order)
order = yc->yc_order; order = yc->yc_order;
yc_count[yang_keyword_get(ys)]++; /* used in loop (2) */
/* 4) Recurse */
if (yang_cardinality(h, ys, modname) < 0)
goto done;
yprev = ys; yprev = ys;
} }
/* 2) For all in 1 and 1..n list, if 0 such children -> ERROR /* 2) For all in 1 and 1..n list, if 0 such children -> ERROR
*/ */
ys = NULL; for (yc = yc0; (int)yc->yc_parent && yc->yc_parent == pk; yc++){
while ((ys = yn_each(yt, ys)) != NULL) {
yc_count[yang_keyword_get(ys)]++;
}
for (i=0; i<Y_SPEC; i++){
yc = _yc_search[pk][i];
if (yc == NULL)
continue;
if (yc->yc_min && if (yc->yc_min &&
yang_find(yt, yc->yc_child, NULL) == NULL){ yang_find(yt, yc->yc_child, NULL) == NULL){
clixon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"", clixon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"",
@ -565,13 +562,6 @@ yang_cardinality(clixon_handle h,
} }
} }
} }
/* 4) Recurse */
i = 0;
while (i < yang_len_get(yt)){ /* Note, children may be removed cant use yn_each */
ys = yang_child_i(yt, i++);
if (yang_cardinality(h, ys, modname) < 0)
goto done;
}
ok: ok:
retval = 0; retval = 0;
done: done:
@ -620,7 +610,8 @@ yang_cardinality_init(clixon_handle h)
const struct ycard *yc; const struct ycard *yc;
for (yc = &_yclist[0]; (int)yc->yc_parent; yc++){ for (yc = &_yclist[0]; (int)yc->yc_parent; yc++){
_yc_exist[yc->yc_parent] = 1; if (_yc_exist[yc->yc_parent] == NULL)
_yc_exist[yc->yc_parent] = yc;
_yc_search[yc->yc_parent][yc->yc_child] = yc; _yc_search[yc->yc_parent][yc->yc_child] = yc;
} }
return 0; return 0;

View file

@ -898,16 +898,11 @@ yang_lib2yspec(clixon_handle h,
} }
else if (yang_parse_module(h, "ietf-yang-library", "2019-01-04", yspec, NULL) < 0) else if (yang_parse_module(h, "ietf-yang-library", "2019-01-04", yspec, NULL) < 0)
goto fail; goto fail;
if ((modmin = yang_len_get(yspec) - (1+veclen - modmin)) < 0)
goto fail;
if (yang_parse_post(h, yspec, modmin) < 0)
goto done;
#else
if ((modmin = yang_len_get(yspec) - (1+veclen - modmin)) < 0)
goto fail;
if (yang_parse_post(h, yspec, modmin) < 0)
goto done;
#endif #endif
if ((modmin = yang_len_get(yspec) - (1+veclen - modmin)) < 0)
goto fail;
if (yang_parse_post(h, yspec, modmin) < 0)
goto done;
retval = 1; retval = 1;
done: done:
if (vec) if (vec)

View file

@ -84,7 +84,9 @@ module clixon-example{
yangmnt:mount-point "mylabel"{ yangmnt:mount-point "mylabel"{
description "Root for other yang models"; description "Root for other yang models";
} }
cl:xmldb-split; /* Multi-XMLDB: split datastore here */ cl:xmldb-split{
description "Multi-XMLDB: split datastore here";
}
} }
} }
} }