From 592c513b839a4cb23334a1fa026781d2fb6fb856 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 4 May 2020 13:10:43 +0200 Subject: [PATCH] Fix up state bypass get code --- apps/cli/cli_show.c | 5 +++++ example/main/example_backend.c | 11 +++++++++++ include/clixon_custom.h | 2 +- lib/src/clixon_proto_client.c | 20 +++++++++++--------- lib/src/clixon_xml_map.c | 2 +- test/test_perf_state_only.sh | 3 +-- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 6d6f9c9f..65867dc3 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -630,8 +630,13 @@ show_conf_xpath(clicon_handle h, namespace = cv_string_get(cv); if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL) goto done; +#if 0 /* Use state get intead of config (XXX: better use this but test_cli.sh fails) */ + if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, &xt) < 0) + goto done; +#else if (clicon_rpc_get_config(h, NULL, str, xpath, nsc, &xt) < 0) goto done; +#endif if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){ clixon_netconf_error(xerr, "Get configuration", NULL); goto done; diff --git a/example/main/example_backend.c b/example/main/example_backend.c index ba2d2891..571446db 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -344,8 +344,19 @@ example_statedata(clicon_handle h, /* If -S is set, then read state data from file, otherwise construct it programmatically */ if (_state_file){ if (_state_file_init){ +#if 0 /* This is just for a zero-copy version (only works once) */ + { + cxobj *xx = NULL; + while (xml_child_nr(_state_xstate)){ + xx = xml_child_i(_state_xstate,0); + if (xml_addsub(xstate, xx) < 0) + goto done; + } + } +#else if (xml_copy(_state_xstate, xstate) < 0) goto done; +#endif } else{ if ((fd = open(_state_file, O_RDONLY)) < 0){ diff --git a/include/clixon_custom.h b/include/clixon_custom.h index 3bae6d1f..fde0bb04 100644 --- a/include/clixon_custom.h +++ b/include/clixon_custom.h @@ -132,5 +132,5 @@ * This is a temporary option which will go away in future releases, therefore * marked as obsolete."; */ -#undef USE_STATE_PATH_KLUDGE +#define USE_STATE_PATH_KLUDGE diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 785e72e3..9b4f717d 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -734,19 +734,21 @@ clicon_rpc_get(clicon_handle h, (kpath = clicon_option_str(h, "CLICON_STATE_PATH_KLUDGE")) != NULL && strncmp(xpath, kpath, strlen(kpath)) == 0){ } - else + else{ #endif /* USE_STATE_PATH_KLUDGE */ - if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0) - goto done; + if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0) + goto done; + if (ret == 0){ + assert(xerr != NULL); + if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){ + clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)"); + goto done; + } + } #ifdef USE_STATE_PATH_KLUDGE - } -#endif - if (ret == 0){ - if ((xd = xpath_first(xerr, NULL, "rpc-error")) == NULL){ - clicon_err(OE_XML, ENOENT, "Expected rpc-error tag but none found(internal)"); - goto done; } } +#endif } if (xt){ if (xml_rm(xd) < 0) diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 202620fd..af9f4afc 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1603,7 +1603,7 @@ xml_merge(cxobj *x0, /* See if there is a corresponding node (x1c) in the base tree (x0) */ if (yc && match_base_child(x0, x1c, yc, &x0c) < 0) goto done; - /* Save x0c, x1c, yc and merge in second wave, so that x1c entries dont "interfer" + /* Save x0c, x1c, yc and merge in second wave, so that x1c entries don't "interfere" * with itself, ie that later searches are among earlier objects already added * to x0 */ twophase[i].mt_x0c = x0c; diff --git a/test/test_perf_state_only.sh b/test/test_perf_state_only.sh index 7356f271..726b11b8 100755 --- a/test/test_perf_state_only.sh +++ b/test/test_perf_state_only.sh @@ -117,9 +117,8 @@ new "waiting" wait_restconf new "cli get large config" -echo "$clixon_cli -1f $cfg show state xml" # baseline on thinkpad i5-3320M CPU @ 2.60GHz and 500K entries: 39.71s -$TIMEFN $clixon_cli -1f $cfg show state xml 2>&1 | awk '/real/ {print $2}' +$TIMEFN $clixon_cli -1f $cfg show xpath /interfaces urn:example:clixon 2>&1 | awk '/real/ {print $2}' # START actual tests # Having a large db, get single entries many times