Skip to content

Commit fd926f5

Browse files
committed
confd: Remove core hooks
Not needed anymore, the configuration change is sequential in change_cb.
1 parent 909ee63 commit fd926f5

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
@@ -8,16 +8,16 @@
88
struct confd confd;
99

1010

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

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

215-
if (request_id == last_id && last_event == event)
162+
if (request_id == last_request && last_event == event)
216163
return SR_ERR_OK;
217-
last_id = request_id;
164+
last_request = request_id;
218165
last_event = event;
219166

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

308-
static int subscribe_module(char *model, struct confd *confd, int flags) {
309-
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);
255+
static inline int subscribe_module(char *model, struct confd *confd, int flags) {
256+
return sr_module_change_subscribe(confd->session, model, "//.", change_cb, confd,
257+
CB_PRIO_PRIMARY, SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags, &confd->sub) &&
258+
sr_module_change_subscribe(confd->startup, model, "//.", core_startup_save, NULL,
259+
CB_PRIO_PASSIVE, SR_SUBSCR_PASSIVE | SR_SUBSCR_CHANGE_ALL_MODULES, &confd->sub);
310260
}
311261

312262
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
@@ -135,48 +135,18 @@ struct confd {
135135
struct dagger netdag;
136136
};
137137

138-
uint32_t core_hook_prio (void);
139-
int core_pre_hook (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
140-
int core_post_hook (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
141138
int core_startup_save (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
142-
int core_wait_change (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *);
143139

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

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

0 commit comments

Comments
 (0)