Skip to content

Commit 9e23bca

Browse files
committed
confd: Remove core hooks
Not needed anymore, the configuration change is sequential in change_cb.
1 parent a142c8d commit 9e23bca

File tree

2 files changed

+17
-97
lines changed

2 files changed

+17
-97
lines changed

src/confd/src/core.c

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
struct confd confd;
88

99

10-
uint32_t core_hook_prio(void)
11-
{
12-
static uint32_t hook_prio = CB_PRIO_PASSIVE;
13-
14-
return hook_prio--;
15-
}
16-
1710
int core_startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
1811
const char *xpath, sr_event_t event, unsigned request_id, void *priv)
1912
{
13+
sr_event_t last_event = -1;
14+
static unsigned int last_request = -1;
15+
if (last_event == event && last_request == request_id)
16+
return SR_ERR_OK;
17+
last_event = event;
18+
last_request = request_id;
19+
2020
/* skip in bootstrap, triggered by load script to initialize startup datastore */
2121
if (systemf("runlevel >/dev/null 2>&1"))
2222
return SR_ERR_OK;
@@ -27,59 +27,6 @@ int core_startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *mo
2727
return SR_ERR_OK;
2828
}
2929

30-
static const char *ev2str(sr_event_t ev)
31-
{
32-
switch (ev) {
33-
case SR_EV_UPDATE: return "UPDATE";
34-
case SR_EV_CHANGE: return "CHANGE";
35-
case SR_EV_DONE: return "DONE";
36-
case SR_EV_ABORT: return "ABORT";
37-
case SR_EV_ENABLED: return "ENABLED";
38-
case SR_EV_RPC: return "ABORT";
39-
default:
40-
break;
41-
}
42-
43-
return "UNKNOWN";
44-
}
45-
46-
int core_pre_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
47-
const char *xpath, sr_event_t event, unsigned request_id, void *priv)
48-
{
49-
return 0;
50-
}
51-
52-
/*
53-
* Run on UPDATE to see how many modules have changes in the inbound changeset
54-
* Run on DONE, after the last module callback has run, to activate changes.
55-
* For details, see https://github.com/sysrepo/sysrepo/issues/2188
56-
*/
57-
int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
58-
const char *xpath, sr_event_t event, unsigned request_id, void *priv)
59-
{
60-
static size_t num_changes = 0;
61-
62-
switch (event) {
63-
case SR_EV_CHANGE:
64-
num_changes++;
65-
return SR_ERR_OK;
66-
case SR_EV_ABORT:
67-
num_changes = 0;
68-
return SR_ERR_OK;
69-
case SR_EV_DONE:
70-
num_changes--;
71-
if (num_changes > 0)
72-
return SR_ERR_OK;
73-
break;
74-
default:
75-
ERROR("core_post_hook() should not be called with event %s", ev2str(event));
76-
return SR_ERR_SYS;
77-
}
78-
79-
80-
return SR_ERR_OK;
81-
}
82-
8330
static confd_dependency_t add_dependencies(struct lyd_node **diff, const char *xpath, const char *value)
8431
{
8532
struct lyd_node *new_node = NULL;
@@ -203,17 +150,17 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
203150
const char *xpath, sr_event_t event, uint32_t request_id, void *_confd)
204151
{
205152
struct lyd_node *diff = NULL, *config = NULL;
206-
static uint32_t last_event = -1;
153+
static sr_event_t last_event = -1;
207154
struct confd *confd = _confd;
208-
static uint32_t last_id = 0;
155+
static uint32_t last_request = 0;
209156
confd_dependency_t result;
210157
sr_data_t *cfg = NULL;
211158
int rc = SR_ERR_OK;
212159
int max_dep = 10;
213160

214-
if (request_id == last_id && last_event == event)
161+
if (request_id == last_request && last_event == event)
215162
return SR_ERR_OK;
216-
last_id = request_id;
163+
last_request = request_id;
217164
last_event = event;
218165

219166
if (event == SR_EV_CHANGE || event == SR_EV_DONE) {
@@ -304,8 +251,11 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
304251
return rc;
305252
}
306253

307-
static int subscribe_module(char *model, struct confd *confd, int flags) {
308-
return sr_module_change_subscribe(confd->session, model, "//.", change_cb, confd, CB_PRIO_PRIMARY, SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags, &confd->sub);
254+
static inline int subscribe_module(char *model, struct confd *confd, int flags) {
255+
return sr_module_change_subscribe(confd->session, model, "//.", change_cb, confd,
256+
CB_PRIO_PRIMARY, SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags, &confd->sub) &&
257+
sr_module_change_subscribe(confd->startup, model, "//.", core_startup_save, NULL,
258+
CB_PRIO_PASSIVE, SR_SUBSCR_PASSIVE | SR_SUBSCR_CHANGE_ALL_MODULES, &confd->sub);
309259
}
310260

311261
int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)

src/confd/src/core.h

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,48 +136,18 @@ struct confd {
136136
struct dagger netdag;
137137
};
138138

139-
uint32_t core_hook_prio (void);
140-
int core_pre_hook (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
141-
int core_post_hook (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
142139
int core_startup_save (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
143-
int core_wait_change (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
144140

145141
static inline int register_change(sr_session_ctx_t *session, const char *module, const char *xpath,
146142
int flags, sr_module_change_cb cb, void *arg, sr_subscription_ctx_t **sub)
147143
{
148-
struct confd *ptr = (struct confd *)arg;
149-
bool need_core_hooks;
150-
int rc;
151-
152-
/*
153-
* For standard subscribtions we hook into the callback chain
154-
* for all modules to figure out, per changeset, which of the
155-
* callbacks is the last one. This is where we want to call the
156-
* global commit-done hook for candidate -> running changes and
157-
* the startup-save hook for running -> startup copying.
158-
*/
159-
160-
need_core_hooks = !(flags & SR_SUBSCR_UPDATE);
161-
162-
if (need_core_hooks) {
163-
sr_module_change_subscribe(ptr->session, module, xpath, core_pre_hook, NULL,
164-
0, SR_SUBSCR_PASSIVE, sub);
165-
}
166-
167-
rc = sr_module_change_subscribe(session, module, xpath, cb, arg,
144+
int rc = sr_module_change_subscribe(session, module, xpath, cb, arg,
168145
CB_PRIO_PRIMARY, flags | SR_SUBSCR_DEFAULT, sub);
169146
if (rc) {
170147
ERROR("failed subscribing to changes of %s: %s", xpath, sr_strerror(rc));
171148
return rc;
172149
}
173150

174-
if (need_core_hooks) {
175-
sr_module_change_subscribe(ptr->session, module, xpath, core_post_hook, NULL,
176-
core_hook_prio(), SR_SUBSCR_PASSIVE, sub);
177-
sr_module_change_subscribe(ptr->startup, module, xpath, core_startup_save, NULL,
178-
core_hook_prio(), SR_SUBSCR_PASSIVE, sub);
179-
}
180-
181151
return 0;
182152
}
183153

0 commit comments

Comments
 (0)