diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-07-21 22:12:17 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2021-07-21 22:12:17 +0000 |
commit | 02486d457def273db80d36c2370fd663511cb82b (patch) | |
tree | ae27839e90e13b1b3f84cc535c3689da89c5cac0 /src | |
parent | 53d7f0de3feeb8ad93bb8c319c3f0f314c7d31cf (diff) | |
download | s6-rc-02486d457def273db80d36c2370fd663511cb82b.tar.xz |
Get rid of s6rc_id_t
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/include/s6-rc/db.h | 6 | ||||
-rw-r--r-- | src/libs6rc/s6rc_db_load.c | 2 | ||||
-rw-r--r-- | src/server/deps.c | 47 | ||||
-rw-r--r-- | src/server/deps.h | 2 | ||||
-rw-r--r-- | src/server/event.h | 2 | ||||
-rw-r--r-- | src/server/state.h | 4 |
6 files changed, 43 insertions, 20 deletions
diff --git a/src/include/s6-rc/db.h b/src/include/s6-rc/db.h index be2c46c..416d920 100644 --- a/src/include/s6-rc/db.h +++ b/src/include/s6-rc/db.h @@ -52,7 +52,7 @@ struct s6rc_longrun_s s6rc_atomic_t satomic ; uint32_t nproducers ; uint32_t producers ; - s6rc_id_t consumer ; + uint32_t consumer ; } ; typedef struct s6rc_oneshot_s s6rc_oneshot_t, *s6rc_oneshot_t_ref ; @@ -87,9 +87,9 @@ struct s6rc_db_s s6rc_external_t const *externals ; s6rc_bundle_t const *bundles ; s6rc_bundle_t const *virtuals ; - s6rc_id_t const *deps[2] ; + uint32_t const *deps[2] ; uint8_t const *deptypes[2] ; - s6rc_id_t const *producers ; + uint32_t const *producers ; char const *storage ; char const **argvs ; /* alloced */ } ; diff --git a/src/libs6rc/s6rc_db_load.c b/src/libs6rc/s6rc_db_load.c index 8463e55..bcc5f2f 100644 --- a/src/libs6rc/s6rc_db_load.c +++ b/src/libs6rc/s6rc_db_load.c @@ -104,7 +104,7 @@ int s6rc_db_load (char const *dir, s6rc_db_t *db, cdb_t *c) db->externals = (s6rc_external_t const *)(db->oneshots + db->n[S6RC_STYPE_ONESHOT] + db->n[S6RC_STYPE_N + S6RC_STYPE_ONESHOT]) ; db->bundles = (s6rc_bundle_t const *)(db->externals + db->n[S6RC_STYPE_EXTERNAL] + db->n[S6RC_STYPE_N + S6RC_STYPE_EXTERNAL]) ; db->virtuals = (s6rc_bundle_t const *)(db->bundles + db->n[S6RC_STYPE_BUNDLE] + db->n[S6RC_STYPE_N + S6RC_STYPE_BUNDLE]) ; - db->deps[0] = (s6rc_id_t const *)(db->virtuals + db->n[S6RC_STYPE_VIRTUAL] + db->n[S6RC_STYPE_N + S6RC_STYPE_VIRTUAL]) ; + db->deps[0] = (uint32_t const *)(db->virtuals + db->n[S6RC_STYPE_VIRTUAL] + db->n[S6RC_STYPE_N + S6RC_STYPE_VIRTUAL]) ; db->deps[1] = db->deps[0] + ndeps ; db->producers = db->deps[1] + ndeps ; db->deptypes[0] = (uint8_t const *)(db->producers + nproducers) ; diff --git a/src/server/deps.c b/src/server/deps.c index fc8028d..12e0fb6 100644 --- a/src/server/deps.c +++ b/src/server/deps.c @@ -4,22 +4,45 @@ #include <sys/uio.h> #include <errno.h> -#include "db.h" +#include <s6-rc/db.h> #include "state.h" -int deps_fulfilled (s6rc_db_t const *db, mstate_t const *m, s6rc_id_t id, char const *param, int h) +static int state_allownext (sstate_t const *st, uint8_t deptype, uint8_t subtype, int h) { - s6rc_common_t const *common = s6rc_service_common(db, id) ; + return !(st->bits & SSTATE_WANTED) == h && subtype != S6RC_STYPE_EXTERNAL && subtype != S6RC_STYPE_N + S6RC_STYPE_EXTERNAL ? 0 : + (!(st->bits & SSTATE_CURRENT) != h && !(st->bits & SSTATE_TRANSITIONING)) + || (s6rc_deptype_soft(deptype) && st->bits & SSTATE_FAILED) + || (s6rc_deptype_loose(deptype) && !(st->bits & SSTATE_TRANSITIONING)) +} + +static int instances_alldown (mstate_t const *m, uint8_t deptype, uint8_t type, uint32_t num) +{ + instance_t const *ins = genalloc_s(instance_t, m->dyn[type] + num) ; + size_t n = genalloc_len(instance_t, m->dyn[type] + num) ; + for (size_t i = 0 ; i < n ; i++) + if (!state_allownext(&ins[i].sstate, deptype, subtype, 0)) return 0 ; + return 1 ; +} + +int deps_fulfilled (s6rc_db_t const *db, mstate_t const *m, uint32_t id, char const *param, int h) +{ + s6rc_common_t const *common ; + uint32_t num ; + uint8_t type ; + s6rc_service_typenum(db->n, id, &type, &num) ; + common = s6rc_service_common_tn(db, type, num) ; for (uint32_t i = 0 ; i < common->ndeps[h] ; i++) { - s6rc_id_t depid = db->deps[h][common->deps[h] + i] ; - sstate_t *st = sstate(m, depid, param) ; + uint32_t subnum ; + uint8_t subtype ; uint8_t deptype = db->deptypes[h][common->deps[h] + i] ; - if (!(st->bits & SSTATE_WANTED) == h && stype(depid) != S6RC_STYPE_EXTERNAL && stype(depid) != S6RC_STYPE_N + S6RC_STYPE_EXTERNAL) return 0 ; - if (!(st->bits & SSTATE_CURRENT) != h && !(st->bits & SSTATE_TRANSITIONING)) continue ; - if (s6rc_deptype_soft(deptype) && st->bits & SSTATE_FAILED) continue ; - if (s6rc_deptype_loose(deptype) && !(st->bits & SSTATE_TRANSITIONING)) continue ; - return 0 ; + s6rc_service_typenum(db->n, db->deps[h][common->deps[h] + i], &subtype, &subnum) ; + if (!h && type < S6RC_STYPE_N && subtype >= S6RC_STYPE_N) + return instances_alldown(m, deptype, subtype, subnum) ; + if (h && type >= S6RC_STYPE_N && subtype < S6RC_STYPE_N) + param = 0 ; + if (!state_allownext(sstate_tn(m, subtype, subnum, param), deptype, subtype, h)) + return 0 ; } return 1 ; } @@ -45,7 +68,7 @@ struct recinfo_s uint8_t h : 1 ; } -static int mstate_dep_closure_rec (recinfo_t *recinfo, s6rc_id_t id) +static int mstate_dep_closure_rec (recinfo_t *recinfo, uint32_t id) { sstate_t *st = sstate(recinfo->db, recinfo->m, id, recinfo->param) ; if (!st) @@ -71,7 +94,7 @@ int mstate_change_wanted (s6rc_db_t const *db, cdb_t *c, mstate_t *m, char const for (size_t i = 0 ; i < n ; n++) { sstate_t *st ; - s6rc_id_t id ; + uint32_t id ; char const *param ; int r = s6rc_service_resolve(c, args[i], &id, ¶m) ; if (r < 0) return -1 ; diff --git a/src/server/deps.h b/src/server/deps.h index f8321dd..e089061 100644 --- a/src/server/deps.h +++ b/src/server/deps.h @@ -14,6 +14,6 @@ #define deptype_soft(dt) ((dt) & 0x02u) #define deptype_loose(dt) ((dt) & 0x04u) -extern int deps_fulfilled (s6rc_db_t const *, mstate_t const *, s6rc_id_t, char const *, int) ; +extern int deps_fulfilled (s6rc_db_t const *, mstate_t const *, uint32_t, char const *, int) ; #endif diff --git a/src/server/event.h b/src/server/event.h index b2faac4..0f10020 100644 --- a/src/server/event.h +++ b/src/server/event.h @@ -8,7 +8,7 @@ typedef event_s event_t, *event_t_ref ; struct event_s { - s6rc_id_t id ; + uint32_t id ; char const *param ; uint8_t wanted : 1 ; uint8_t up : 1 ; diff --git a/src/server/state.h b/src/server/state.h index 9831115..2decb80 100644 --- a/src/server/state.h +++ b/src/server/state.h @@ -56,8 +56,8 @@ typedef instance_func *instance_func_ref ; extern instancelen_func_ref const instancelen_nop ; -extern sstate_t *instance_create (mstate_t *, s6rc_id_t, char const *) ; -extern void instance_remove (mstate_t *, s6rc_id_t, char const *) ; +extern sstate_t *instance_create (mstate_t *, uint32_t, char const *) ; +extern void instance_remove (mstate_t *, uint32_t, char const *) ; extern void mstate_free (mstate_t *, uint32_t const *) ; extern int mstate_init (mstate_t *, uint32_t const *) ; |