YANG mount refactoring: remove set functions
This commit is contained in:
parent
73183c4077
commit
19c11eabb7
7 changed files with 62 additions and 171 deletions
|
|
@ -1888,19 +1888,16 @@ cli_show_statistics(clixon_handle h,
|
|||
size_t tsz0;
|
||||
size_t tsz;
|
||||
yang_stmt *yspec;
|
||||
yang_stmt *yspec1;
|
||||
yang_stmt *yspec2;
|
||||
yang_stmt *ymnt;
|
||||
cvec *cvv1 = NULL;
|
||||
cvec *cvv2;
|
||||
cg_var *cv;
|
||||
cg_var *cv2;
|
||||
cg_var *cv3;
|
||||
cxobj *xp;
|
||||
char *name;
|
||||
cxobj *x;
|
||||
uint64_t u64;
|
||||
char *unit;
|
||||
yang_stmt *ymounts;
|
||||
int inext;
|
||||
int i;
|
||||
|
||||
if (argv == NULL || (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend|all) [detail]]");
|
||||
|
|
@ -1952,53 +1949,47 @@ cli_show_statistics(clixon_handle h,
|
|||
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Top-level", u64, unit);
|
||||
}
|
||||
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")) {
|
||||
if (yang_mount_yspec2ymnt(yspec, &cvv1) < 0)
|
||||
if ((ymounts = clixon_yang_mounts_get(h)) == NULL){
|
||||
clixon_err(OE_YANG, ENOENT, "Top-level yang mounts not found");
|
||||
goto done;
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(cvv1, cv)) != NULL) {
|
||||
ymnt = cv_void_get(cv);
|
||||
if ((cvv2 = yang_cvec_get(ymnt)) != NULL){
|
||||
cv2 = NULL;
|
||||
while ((cv2 = cvec_each(cvv2, cv2)) != NULL) {
|
||||
yspec1 = cv_void_get(cv2);
|
||||
nr = 0; sz = 0;
|
||||
if (yang_stats(yspec1, 0, &nr, &sz) < 0)
|
||||
goto done;
|
||||
/* check if not duplicate */
|
||||
cv3 = cv2;
|
||||
while ((cv3 = cvec_each(cvv2, cv3)) != NULL) {
|
||||
if (cv2 == cv3)
|
||||
continue;
|
||||
yspec2 = cv_void_get(cv3);
|
||||
if (yspec1 == yspec2)
|
||||
break;
|
||||
}
|
||||
if (cv3 != NULL){
|
||||
if (detail){
|
||||
/* Maybe use "0" instead of "shared"? */
|
||||
cligen_output(stdout, "YANG-mount-point-%s-size: shared\n", cv_name_get(cv2));
|
||||
cligen_output(stdout, "YANG-mount-point-%s-nr: shared\n", cv_name_get(cv2));
|
||||
}
|
||||
inext = 0;
|
||||
while ((yspec = yn_iter(ymounts, &inext)) != NULL) {
|
||||
cvv1 = NULL;
|
||||
if (yang_keyword_get(yspec) == Y_SPEC &&
|
||||
yang_flag_get(yspec, YANG_FLAG_SPEC_MOUNT) != 0x0 &&
|
||||
(cvv1 = yang_cvec_get(yspec)) != NULL){
|
||||
nr = 0; sz = 0;
|
||||
if (yang_stats(yspec, 0, &nr, &sz) < 0)
|
||||
goto done;
|
||||
tnr += nr;
|
||||
tsz += sz;
|
||||
i = 0;
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(cvv1, cv)) != NULL) {
|
||||
if (detail){
|
||||
if (i == cvec_len(cvv1)-1) {
|
||||
cligen_output(stdout, "YANG-mount-point-%s-size: %" PRIu64 "\n", cv_name_get(cv), sz);
|
||||
cligen_output(stdout, "YANG-mount-point-%s-nr: %" PRIu64 "\n", cv_name_get(cv), nr);
|
||||
}
|
||||
else {
|
||||
cligen_output(stdout, "YANG-mount-point-%s-size: shared\n", cv_name_get(cv));
|
||||
cligen_output(stdout, "YANG-mount-point-%s-nr: shared\n", cv_name_get(cv));
|
||||
}
|
||||
else
|
||||
cligen_output(stdout, "%s\n", cv_name_get(cv2));
|
||||
}
|
||||
else {
|
||||
tnr += nr;
|
||||
tsz += sz;
|
||||
|
||||
if (detail) {
|
||||
cligen_output(stdout, "YANG-mount-point-%s-size: %" PRIu64 "\n", cv_name_get(cv2), sz);
|
||||
cligen_output(stdout, "YANG-mount-point-%s-nr: %" PRIu64 "\n", cv_name_get(cv2), nr);
|
||||
}
|
||||
else{
|
||||
if (strlen(cv_name_get(cv2)) > 25)
|
||||
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv2), "");
|
||||
if (i == cvec_len(cvv1)-1) {
|
||||
if (strlen(cv_name_get(cv)) > 25)
|
||||
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv), "");
|
||||
else
|
||||
cligen_output(stdout, "%-25s", cv_name_get(cv2));
|
||||
cligen_output(stdout, "%-25s", cv_name_get(cv));
|
||||
translatenumber(sz, &u64, &unit);
|
||||
cligen_output(stdout, "%" PRIu64 "%-10s\n", u64, unit);
|
||||
}
|
||||
else
|
||||
cligen_output(stdout, "%s\n", cv_name_get(cv));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2117,8 +2108,6 @@ cli_show_statistics(clixon_handle h,
|
|||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (cvv1)
|
||||
cvec_free(cvv1);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
if (cb)
|
||||
|
|
|
|||
|
|
@ -90,11 +90,13 @@
|
|||
* Set by yang_mount_set
|
||||
* Read by ys_free1
|
||||
*/
|
||||
#define YANG_FLAG_WHEN 0x400 /* Use external map to access when-info for
|
||||
#define YANG_FLAG_SPEC_MOUNT 0x400 /* Top-level spec is mounted by other top-level tree
|
||||
*/
|
||||
#define YANG_FLAG_WHEN 0x800 /* Use external map to access when-info for
|
||||
* augment/grouping */
|
||||
#define YANG_FLAG_MYMODULE 0x800 /* Use external map to access my-module for
|
||||
#define YANG_FLAG_MYMODULE 0x1000 /* Use external map to access my-module for
|
||||
* UNKNOWNS and augment/grouping */
|
||||
#define YANG_FLAG_REFINE 0x1000 /* In derived trees from grouping and augments, this node
|
||||
#define YANG_FLAG_REFINE 0x2000 /* In derived trees from grouping and augments, this node
|
||||
* may be different from orig, therefore do not use link to
|
||||
* original. May also be due to deviations of derived trees
|
||||
*/
|
||||
|
|
@ -261,9 +263,6 @@ int yang_cv_set(yang_stmt *ys, cg_var *cv);
|
|||
cvec *yang_cvec_get(yang_stmt *ys);
|
||||
int yang_cvec_set(yang_stmt *ys, cvec *cvv);
|
||||
cg_var *yang_cvec_add(yang_stmt *ys, enum cv_type type, char *name);
|
||||
int yang_ref_get(yang_stmt *ys);
|
||||
int yang_ref_inc(yang_stmt *ys);
|
||||
int yang_ref_dec(yang_stmt *ys);
|
||||
uint16_t yang_flag_get(yang_stmt *ys, uint16_t flag);
|
||||
int yang_flag_set(yang_stmt *ys, uint16_t flag);
|
||||
int yang_flag_reset(yang_stmt *ys, uint16_t flag);
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ int yang_mount_get_yspec_any(yang_stmt *y, yang_stmt **yspec);
|
|||
int yang_mount_set(yang_stmt *yu, char *xpath, yang_stmt *yspec);
|
||||
int xml_yang_mount_get(clixon_handle h, cxobj *x, validate_level *vl, yang_stmt **yspec);
|
||||
int xml_yang_mount_set(clixon_handle h, cxobj *x, yang_stmt *yspec);
|
||||
int yang_mount_freeall(yang_stmt *ymnt);
|
||||
int yang_mount_xtop2xmnt(cxobj *xtop, cvec **cvvp);
|
||||
int yang_mount_yspec2ymnt(yang_stmt *yspec, cvec **cvvp);
|
||||
int yang_schema_mount_statedata(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
|
||||
|
|
|
|||
|
|
@ -862,7 +862,7 @@ api_path2xpath_cvv(cvec *api_path,
|
|||
goto done;
|
||||
if (ymtpoint){
|
||||
/* If we cant find a specific mountpoint, we just assign the first.
|
||||
* XXX: note that maybe this may cause later errors?
|
||||
* XXX: Ignore return value: if none are mounted, no change of yspec is made here
|
||||
*/
|
||||
if (yang_mount_get_yspec_any(y, &yspec) < 0)
|
||||
goto done;
|
||||
|
|
@ -1106,6 +1106,7 @@ api_path2xml_vec(char **vec,
|
|||
goto fail;
|
||||
}
|
||||
if (ymtpoint){
|
||||
/* XXX: Ignore return value: if none are mounted, no change of yspec is made here */
|
||||
if (yang_mount_get_yspec_any(y0, &y0) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -395,50 +395,6 @@ yang_cvec_add(yang_stmt *ys,
|
|||
return cv;
|
||||
}
|
||||
|
||||
/*! Get yang object reference count
|
||||
*
|
||||
* @param[in] ys Yang statement
|
||||
* @retval ref Reference coun t
|
||||
*/
|
||||
int
|
||||
yang_ref_get(yang_stmt *ys)
|
||||
{
|
||||
// assert(ys->ys_keyword == Y_SPEC);
|
||||
return ys->ys_ref;
|
||||
}
|
||||
|
||||
/*! Increment yang object reference count with +1
|
||||
*
|
||||
* @param[in] ys Yang statement
|
||||
* @retval 0
|
||||
*/
|
||||
int
|
||||
yang_ref_inc(yang_stmt *ys)
|
||||
{
|
||||
// assert(ys->ys_keyword == Y_SPEC);
|
||||
ys->ys_ref++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Decrement yang object reference count with -1
|
||||
*
|
||||
* @param[in] ys Yang statement
|
||||
* @retval 0 Ok
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_ref_dec(yang_stmt *ys)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
// assert(ys->ys_keyword == Y_SPEC);
|
||||
if (ys->ys_ref > 0)
|
||||
ys->ys_ref--;
|
||||
retval = 0;
|
||||
// done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Get yang stmt flags, used for internal algorithms
|
||||
*
|
||||
* @param[in] ys Yang statement
|
||||
|
|
@ -610,7 +566,6 @@ yang_when_canonical_xpath_get(yang_stmt *ys,
|
|||
const char *
|
||||
yang_filename_get(yang_stmt *ys)
|
||||
{
|
||||
// assert(ys->ys_keyword == Y_MODULE || ys->ys_keyword == Y_SUBMODULE);
|
||||
return ys->ys_filename;
|
||||
}
|
||||
|
||||
|
|
@ -626,7 +581,6 @@ int
|
|||
yang_filename_set(yang_stmt *ys,
|
||||
const char *filename)
|
||||
{
|
||||
// assert(ys->ys_keyword == Y_MODULE || ys->ys_keyword == Y_SUBMODULE);
|
||||
if ((ys->ys_filename = strdup(filename)) == NULL){
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
return -1;
|
||||
|
|
@ -933,15 +887,6 @@ ys_free1(yang_stmt *ys,
|
|||
ys->ys_cv = NULL;
|
||||
cv_free(cv);
|
||||
}
|
||||
if (ys->ys_cvec){
|
||||
/* Schema mount uses cvec in unknown to keep track of all yspecs
|
||||
* Freed here once.
|
||||
*/
|
||||
if (yang_flag_get(ys, YANG_FLAG_MOUNTPOINT))
|
||||
yang_mount_freeall(ys);
|
||||
cvec_free(ys->ys_cvec);
|
||||
ys->ys_cvec = NULL;
|
||||
}
|
||||
if (ys->ys_argument){
|
||||
free(ys->ys_argument);
|
||||
ys->ys_argument = NULL;
|
||||
|
|
@ -1081,14 +1026,8 @@ ys_freechildren(yang_stmt *ys)
|
|||
int
|
||||
ys_free(yang_stmt *ys)
|
||||
{
|
||||
if (yang_keyword_get(ys) == Y_SPEC &&
|
||||
yang_ref_get(ys) > 0){
|
||||
yang_ref_dec(ys);
|
||||
}
|
||||
else {
|
||||
ys_freechildren(ys);
|
||||
ys_free1(ys, 1);
|
||||
}
|
||||
ys_freechildren(ys);
|
||||
ys_free1(ys, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@ struct yang_stmt {
|
|||
Y_ENUM: value
|
||||
*/
|
||||
cvec *ys_cvec; /* List of stmt-specific variables
|
||||
Y_CONTAINER: XXX or U_UNKNOWN?
|
||||
Y_EXTENSION: vector of instantiated UNKNOWNS
|
||||
Y_IDENTITY: store all derived types as <module>:<id> list
|
||||
Y_LENGTH: length_min, length_max
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ yang_schema_mount_point(yang_stmt *y)
|
|||
* @param[in] xpath Key for yspec on y
|
||||
* @param[out] yspec YANG stmt spec
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_mount_get(yang_stmt *ys,
|
||||
|
|
@ -205,9 +206,10 @@ yang_mount_get(yang_stmt *ys,
|
|||
inext = 0;
|
||||
while ((yspec = yn_iter(ymounts, &inext)) != NULL) {
|
||||
if (yang_keyword_get(yspec) != Y_SPEC ||
|
||||
yang_cvec_get(yspec) == NULL)
|
||||
yang_cvec_get(yspec) == NULL ||
|
||||
yang_flag_get(yspec, YANG_FLAG_SPEC_MOUNT) == 0)
|
||||
continue;
|
||||
if (cvec_find(yang_cvec_get(yspec), xpath) != NULL)
|
||||
if (xpath == NULL || cvec_find(yang_cvec_get(yspec), xpath) != NULL)
|
||||
break;
|
||||
}
|
||||
*yspecp = yspec;
|
||||
|
|
@ -221,27 +223,25 @@ yang_mount_get(yang_stmt *ys,
|
|||
* Get (the first) mounted yspec.
|
||||
* A more generic way would be to call plugin_mount to get the yanglib and from that get the
|
||||
* yspec. But there is clixon code that cant call the plugin since h is not available
|
||||
* @param[in] y Yang container/list containing unknown node
|
||||
* @param[in] ys Yang container/list containing unknown node
|
||||
* @param[out] yspec YANG stmt spec
|
||||
* @retval 1 yspec found and set
|
||||
* @retval 0 Not found
|
||||
* @retval -1 Error
|
||||
* XXX Should be in-lined
|
||||
*/
|
||||
int
|
||||
yang_mount_get_yspec_any(yang_stmt *y,
|
||||
yang_stmt **yspec)
|
||||
yang_mount_get_yspec_any(yang_stmt *ys,
|
||||
yang_stmt **yspecp)
|
||||
{
|
||||
cvec *cvv;
|
||||
cg_var *cv;
|
||||
void *p;
|
||||
yang_stmt *yspec = NULL;
|
||||
|
||||
/* Special value in yang unknown node for mount-points: mapping from xpath->mounted yspec */
|
||||
if ((cvv = yang_cvec_get(y)) != NULL &&
|
||||
(cv = cvec_i(cvv, 0)) != NULL &&
|
||||
(p = cv_void_get(cv)) != NULL){
|
||||
*yspec = p;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
if (yang_mount_get(ys, NULL, &yspec) < 0)
|
||||
return -1;
|
||||
if (yspec == NULL)
|
||||
return 0;
|
||||
*yspecp = yspec;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*! Set yangspec mount-point on yang node containing extension
|
||||
|
|
@ -260,20 +260,8 @@ yang_mount_set(yang_stmt *y,
|
|||
yang_stmt *yspec)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec0;
|
||||
cvec *cvv;
|
||||
cg_var *cv;
|
||||
cg_var *cv2;
|
||||
|
||||
clixon_debug(CLIXON_DBG_YANG, "%s %p", xpath, y);
|
||||
if ((cvv = yang_cvec_get(y)) != NULL &&
|
||||
(cv = cvec_find(cvv, xpath)) != NULL &&
|
||||
(yspec0 = cv_void_get(cv)) != NULL){
|
||||
ys_free(yspec0);
|
||||
cv_void_set(cv, NULL);
|
||||
}
|
||||
else if ((cv = yang_cvec_add(y, CGV_VOID, xpath)) == NULL)
|
||||
goto done;
|
||||
if ((cv2 = cv_new(CGV_STRING)) == NULL){
|
||||
clixon_err(OE_YANG, errno, "cv_new");
|
||||
goto done;
|
||||
|
|
@ -284,7 +272,6 @@ yang_mount_set(yang_stmt *y,
|
|||
}
|
||||
/* tag yspec with key/xpath */
|
||||
yang_cv_set(yspec, cv2);
|
||||
cv_void_set(cv, yspec);
|
||||
yang_flag_set(y, YANG_FLAG_MOUNTPOINT); /* Cache value */
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -425,28 +412,6 @@ xml_yang_mount_set(clixon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Free all yspec yang-mounts
|
||||
*
|
||||
* @param[in] ymnt YANG mount-point
|
||||
* @retval 0 OK
|
||||
*/
|
||||
int
|
||||
yang_mount_freeall(yang_stmt *ymnt)
|
||||
{
|
||||
cvec *cvv;
|
||||
cg_var *cv;
|
||||
yang_stmt *ys;
|
||||
|
||||
if ((cvv = yang_cvec_get(ymnt)) != NULL){
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(cvv, cv)) != NULL){
|
||||
if ((ys = cv_void_get(cv)) != NULL)
|
||||
ys_free(ys);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Find schema mounts - callback function for xml_apply
|
||||
*
|
||||
* @param[in] x XML node
|
||||
|
|
@ -935,6 +900,7 @@ yang_schema_yanglib_parse_mount(clixon_handle h,
|
|||
/* Parse it and set mount-point */
|
||||
if ((yspec = yspec_new(h, xpath)) == NULL)
|
||||
goto done;
|
||||
yang_flag_set(yspec, YANG_FLAG_SPEC_MOUNT);
|
||||
clixon_debug(CLIXON_DBG_YANG, "new yang-spec: %p", yspec);
|
||||
if ((ret = yang_lib2yspec(h, xyanglib, xpath, yspec)) < 0)
|
||||
goto done;
|
||||
|
|
@ -948,7 +914,6 @@ yang_schema_yanglib_parse_mount(clixon_handle h,
|
|||
if (shared)
|
||||
if (yang_cvec_add(yspec, CGV_STRING, xpath) < 0)
|
||||
goto done;
|
||||
yang_ref_inc(yspec);
|
||||
yspec = NULL;
|
||||
retval = 1;
|
||||
done:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue