Skip to content

Commit

Permalink
Re-add yang ref-count for obsolete yangs in readfile
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Oct 22, 2024
1 parent fa93364 commit fd4e694
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/clixon/clixon_yang.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ 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_cvec_rm(yang_stmt *ys, 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);
Expand Down
5 changes: 2 additions & 3 deletions lib/src/clixon_datastore_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ xmldb_readfile(clixon_handle h,
* Same ymodules are inserted into yspec1, ie pointers only
*/
if (needclone && xmodfile){
if ((yspec1 = yspec_new1(h, YANG_DOMAIN_TOP, "tmp")) == NULL)
if ((yspec1 = yspec_new1(h, YANG_DOMAIN_TOP, "prevyang")) == NULL)
goto done;
xmsd = NULL;
while ((xmsd = xml_child_each(xmodfile, xmsd, CX_ELMNT)) != NULL) {
Expand All @@ -722,6 +722,7 @@ xmldb_readfile(clixon_handle h,
continue; // XXX error?
if (yn_insert1(yspec1, ymod) < 0)
goto done;
yang_ref_inc(ymod);
}
}
} /* if msdiff */
Expand All @@ -747,8 +748,6 @@ xmldb_readfile(clixon_handle h,
done:
if (mr.mr_subdir)
free(mr.mr_subdir);
if (yspec1)
ys_free1(yspec1, 1);
if (xmodfile)
xml_free(xmodfile);
if (msdiff)
Expand Down
50 changes: 48 additions & 2 deletions lib/src/clixon_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,47 @@ yang_cvec_rm(yang_stmt *ys,
return 0;
}

/*! Get yang object reference count
*
* @param[in] ys Yang statement
* @retval ref Reference coun t
*/
int
yang_ref_get(yang_stmt *ys)
{
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)
{
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;

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
Expand Down Expand Up @@ -1154,8 +1195,13 @@ ys_freechildren(yang_stmt *ys)
int
ys_free(yang_stmt *ys)
{
ys_freechildren(ys);
ys_free1(ys, 1);
if (yang_ref_get(ys) > 0){
yang_ref_dec(ys);
}
else {
ys_freechildren(ys);
ys_free1(ys, 1);
}
return 0;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/src/clixon_yang_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ typedef struct yang_type_cache yang_type_cache;
*/
struct yang_stmt {
/* On x86_64, the following three fields take 8 bytes */
enum rfc_6020 ys_keyword:16; /* YANG keyword */
enum rfc_6020 ys_keyword:8; /* YANG keyword */
uint8_t ys_ref; /* Reference count for free: 0 means
* no sharing, 1: two references */
uint16_t ys_flags; /* Flags according to YANG_FLAG_MARK and others */
uint32_t ys_len; /* Number of children */
#ifdef YANG_SPEC_LINENR
Expand Down Expand Up @@ -112,6 +114,7 @@ struct yang_stmt {
rpc_callback_t *ysu_action_cb; /* Y_ACTION: Action callback list*/
char *ysu_filename; /* Y_MODULE/Y_SUBMODULE: For debug/errors: filename */
yang_type_cache *ysu_typecache; /* Y_TYPE: cache all typedef data except unions */

} u;
};

Expand Down
5 changes: 3 additions & 2 deletions test/test_confirmed_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ rpc "<cancel-commit><persist-id>ab</persist-id></cancel-commit>" "<ok/>"
new "6. netconf persistent confirmed-commit with timeout"
reset
edit_config "candidate" "$CONFIGB"
commit "<confirmed/><confirm-timeout>3</confirm-timeout><persist>abcd</persist>"
# need 5 for valgrind netconf that takes a couple of seconds to finish
commit "<confirmed/><confirm-timeout>5</confirm-timeout><persist>abcd</persist>"
assert_config_equals "running" "$CONFIGB"
sleep 3
sleep 5
assert_config_equals "running" ""

################################################################################
Expand Down

0 comments on commit fd4e694

Please sign in to comment.