Re-optimized yang cardinality
Misc rearrangements
This commit is contained in:
parent
d2f3405ab6
commit
fcdfbd23cc
6 changed files with 46 additions and 56 deletions
|
|
@ -661,12 +661,12 @@ candidate_validate(clixon_handle h,
|
|||
* @retval -1 Error - or validation failed
|
||||
*/
|
||||
int
|
||||
candidate_commit(clixon_handle h,
|
||||
cxobj *xe,
|
||||
char *db,
|
||||
uint32_t myid,
|
||||
candidate_commit(clixon_handle h,
|
||||
cxobj *xe,
|
||||
char *db,
|
||||
uint32_t myid,
|
||||
validate_level vlev, // obsolete
|
||||
cbuf *cbret)
|
||||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
transaction_data_t *td = NULL;
|
||||
|
|
@ -674,6 +674,7 @@ candidate_commit(clixon_handle h,
|
|||
cxobj *xret = NULL;
|
||||
yang_stmt *yspec;
|
||||
|
||||
clixon_debug(CLIXON_DBG_DATASTORE, "db: %s", db);
|
||||
/* 1. Start transaction */
|
||||
if ((td = transaction_new()) == NULL)
|
||||
goto done;
|
||||
|
|
@ -698,7 +699,6 @@ candidate_commit(clixon_handle h,
|
|||
clixon_err(OE_YANG, ENOENT, "No yang spec");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (if_feature(yspec, "ietf-netconf", "confirmed-commit")
|
||||
&& confirmed_commit_state_get(h) != ROLLBACK
|
||||
&& xe != NULL){
|
||||
|
|
|
|||
|
|
@ -267,14 +267,18 @@ xmldb_copy(clixon_handle h,
|
|||
const char *from,
|
||||
const char *to)
|
||||
{
|
||||
int retval = -1;
|
||||
char *fromfile = NULL;
|
||||
char *tofile = NULL;
|
||||
db_elmnt *de1 = NULL; /* from */
|
||||
db_elmnt *de2 = NULL; /* to */
|
||||
db_elmnt de0 = {0,};
|
||||
cxobj *x1 = NULL; /* from */
|
||||
cxobj *x2 = NULL; /* to */
|
||||
int retval = -1;
|
||||
char *fromfile = NULL;
|
||||
char *tofile = NULL;
|
||||
db_elmnt *de1 = NULL; /* from */
|
||||
db_elmnt *de2 = NULL; /* to */
|
||||
db_elmnt de0 = {0,};
|
||||
cxobj *x1 = NULL; /* from */
|
||||
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);
|
||||
/* XXX lock */
|
||||
|
|
@ -313,9 +317,6 @@ xmldb_copy(clixon_handle h,
|
|||
de0 = *de2;
|
||||
de0.de_xml = x2; /* The new tree */
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_MULTI")){
|
||||
char *subdir = NULL;
|
||||
struct stat st = {0,};
|
||||
|
||||
if (xmldb_db2subdir(h, to, &subdir) < 0)
|
||||
goto done;
|
||||
if (stat(subdir, &st) < 0){
|
||||
|
|
@ -324,11 +325,11 @@ xmldb_copy(clixon_handle h,
|
|||
goto done;
|
||||
}
|
||||
}
|
||||
if (subdir)
|
||||
free(subdir);
|
||||
}
|
||||
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)
|
||||
goto done;
|
||||
if (xmldb_db2file(h, to, &tofile) < 0)
|
||||
|
|
@ -336,8 +337,7 @@ xmldb_copy(clixon_handle h,
|
|||
if (clicon_file_copy(fromfile, tofile) < 0)
|
||||
goto done;
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_MULTI")) {
|
||||
char *fromdir = NULL;
|
||||
char *todir = NULL;
|
||||
|
||||
|
||||
if (xmldb_db2subdir(h, from, &fromdir) < 0)
|
||||
goto done;
|
||||
|
|
@ -345,14 +345,16 @@ xmldb_copy(clixon_handle h,
|
|||
goto done;
|
||||
if (clicon_dir_copy(fromdir, todir) < 0)
|
||||
goto done;
|
||||
if (fromdir)
|
||||
free(fromdir);
|
||||
if (todir)
|
||||
free(todir);
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
clixon_debug(CLIXON_DBG_DATASTORE, "retval:%d", retval);
|
||||
if (subdir)
|
||||
free(subdir);
|
||||
if (fromdir)
|
||||
free(fromdir);
|
||||
if (todir)
|
||||
free(todir);
|
||||
if (fromfile)
|
||||
free(fromfile);
|
||||
if (tofile)
|
||||
|
|
|
|||
|
|
@ -501,7 +501,7 @@ clixon_err_restore(void* handle)
|
|||
if ((es = (struct err_state *)handle) != NULL){
|
||||
_err_category = es->es_category;
|
||||
_err_subnr = es->es_subnr;
|
||||
strncpy(_err_reason, es->es_reason, ERR_STRLEN-1);
|
||||
strcpy(_err_reason, es->es_reason);
|
||||
free(es);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -468,7 +468,7 @@ static const struct ycard *_yc_search[Y_SPEC][Y_SPEC] = {{0,},{0,}};
|
|||
* and = 0 in the following vector.
|
||||
* 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
|
||||
*
|
||||
|
|
@ -492,7 +492,7 @@ yang_cardinality(clixon_handle h,
|
|||
yang_stmt *ys = NULL;
|
||||
int pk;
|
||||
int ck;
|
||||
int i;
|
||||
const struct ycard *yc0;
|
||||
const struct ycard *yc;
|
||||
int order;
|
||||
yang_stmt *yprev = NULL;
|
||||
|
|
@ -500,7 +500,7 @@ yang_cardinality(clixon_handle h,
|
|||
int yc_count[Y_SPEC] = {0,};
|
||||
|
||||
pk = yang_keyword_get(yt);
|
||||
if (_yc_exist[pk] == 0)
|
||||
if ((yc0 = _yc_exist[pk]) == NULL)
|
||||
goto ok;
|
||||
/* 1) For all children, if neither in 0..n, 0..1, 1 or 1..n ->ERROR
|
||||
* Also: check monotonically increasing order
|
||||
|
|
@ -534,18 +534,15 @@ yang_cardinality(clixon_handle h,
|
|||
}
|
||||
if (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;
|
||||
}
|
||||
/* 2) For all in 1 and 1..n list, if 0 such children -> ERROR
|
||||
*/
|
||||
ys = NULL;
|
||||
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;
|
||||
for (yc = yc0; (int)yc->yc_parent && yc->yc_parent == pk; yc++){
|
||||
if (yc->yc_min &&
|
||||
yang_find(yt, yc->yc_child, NULL) == NULL){
|
||||
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:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -620,7 +610,8 @@ yang_cardinality_init(clixon_handle h)
|
|||
const struct ycard *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;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -898,16 +898,11 @@ yang_lib2yspec(clixon_handle h,
|
|||
}
|
||||
else if (yang_parse_module(h, "ietf-yang-library", "2019-01-04", yspec, NULL) < 0)
|
||||
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
|
||||
if ((modmin = yang_len_get(yspec) - (1+veclen - modmin)) < 0)
|
||||
goto fail;
|
||||
if (yang_parse_post(h, yspec, modmin) < 0)
|
||||
goto done;
|
||||
retval = 1;
|
||||
done:
|
||||
if (vec)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,9 @@ module clixon-example{
|
|||
yangmnt:mount-point "mylabel"{
|
||||
description "Root for other yang models";
|
||||
}
|
||||
cl:xmldb-split; /* Multi-XMLDB: split datastore here */
|
||||
cl:xmldb-split{
|
||||
description "Multi-XMLDB: split datastore here";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue