* New state callback signature (ca_statedata2)

* The new callback contains parameters for paging
   * Goal is to replace ca_statedata callback
* New plugin callback when lock/unlock occurs
  * Add `ca_lockdb` tro plugin init to use it.
* Fixed: Typing 'q' in CLI more paging did not properly quit output
  * Output continued but was not shown, for a very large file this could cause considerable delay
* Fixed: Lock was broken in first get get access
  * if the first netconf operation to a backend was lock;get;unlock, the lock was broken in the first get access.
This commit is contained in:
Olof hagsand 2021-09-04 11:35:27 +02:00
parent aaf9a89183
commit caabfd464e
15 changed files with 487 additions and 233 deletions

View file

@ -239,6 +239,7 @@ clixon_plugin_daemon_all(clicon_handle h)
* @param[in] h clicon handle
* @param[in] nsc namespace context for xpath
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] pagingstatus List pagination status
* @param[in] offset Offset, for list pagination
* @param[in] limit Limit, for list pagination
* @param[out] xp If retval=1, state tree created and returned: <config>...
@ -251,6 +252,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
clicon_handle h,
cvec *nsc,
char *xpath,
enum paging_status pagingstatus,
uint32_t offset,
uint32_t limit,
cxobj **xp)
@ -262,9 +264,9 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
clicon_debug(1, "%s %s", __FUNCTION__, clixon_plugin_name_get(cp));
if ((fn2 = clixon_plugin_api_get(cp)->ca_statedata2) != NULL){
if ((x = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
if (fn2(h, nsc, xpath, offset, limit, x) < 0){
if (fn2(h, nsc, xpath, pagingstatus, offset, limit, x) < 0){
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));
@ -272,7 +274,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
}
}
else if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){
if ((x = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
if (fn(h, nsc, xpath, x) < 0){
if (clicon_errno < 0)
@ -298,6 +300,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
* @param[in] yspec Yang spec
* @param[in] nsc Namespace context
* @param[in] xpath String with XPATH syntax. or NULL for all
* @param[in] pagination List pagination
* @param[in] offset Offset, for list pagination
* @param[in] limit Limit, for list pagination
* @param[in,out] xret State XML tree is merged with existing tree.
@ -307,13 +310,14 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
* @note xret can be replaced in this function
*/
int
clixon_plugin_statedata_all(clicon_handle h,
yang_stmt *yspec,
cvec *nsc,
char *xpath,
uint32_t offset,
uint32_t limit,
cxobj **xret)
clixon_plugin_statedata_all(clicon_handle h,
yang_stmt *yspec,
cvec *nsc,
char *xpath,
enum paging_status pagingstatus,
uint32_t offset,
uint32_t limit,
cxobj **xret)
{
int retval = -1;
int ret;
@ -324,7 +328,8 @@ clixon_plugin_statedata_all(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, offset, limit, &x)) < 0)
if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, pagingstatus,
offset, limit, &x)) < 0)
goto done;
if (ret == 0){
if ((cberr = cbuf_new()) == NULL){
@ -399,6 +404,64 @@ clixon_plugin_statedata_all(clicon_handle h,
goto done;
}
/*! Lock database status has changed status
* @param[in] cp Plugin handle
* @param[in] h Clixon handle
* @param[in] db Database name (eg "running")
* @param[in] lock Lock status: 0: unlocked, 1: locked
* @param[in] id Session id (of locker/unlocker)
* @retval -1 Fatal error
* @retval 0 OK
*/
static int
clixon_plugin_lockdb_one(clixon_plugin_t *cp,
clicon_handle h,
char *db,
int lock,
int id)
{
int retval = -1;
plglockdb_t *fn; /* Plugin statedata fn */
clicon_debug(1, "%s %s", __FUNCTION__, clixon_plugin_name_get(cp));
if ((fn = clixon_plugin_api_get(cp)->ca_lockdb) != NULL){
if (fn(h, db, lock, id) < 0)
goto done;
}
retval = 0;
done:
return retval;
}
/*! Lock database status has changed status
* @param[in] h Clixon handle
* @param[in] db Database name (eg "running")
* @param[in] lock Lock status: 0: unlocked, 1: locked
* @param[in] id Session id (of locker/unlocker)
* @retval -1 Fatal error
* @retval 0 OK
*/
int
clixon_plugin_lockdb_all(clicon_handle h,
char *db,
int lock,
int id
)
{
int retval = -1;
clixon_plugin_t *cp = NULL;
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (clixon_plugin_lockdb_one(cp, h, db, lock, id) < 0)
goto done;
}
retval = 0;
done:
return retval;
}
/*! Create and initialize a validate/commit transaction
* @retval td New alloced transaction,
* @retval NULL Error