Skip to content

Commit acfc0bd

Browse files
committed
lib: drop ff_kernel_coexist_enabled accessor, read ff_global_cfg directly
The accessor only wrapped a single struct member read and required two identical declarations (ff_config.h + ff_host_interface.h) because the host-bridge header intentionally avoids depending on ff_config.h. Remove the accessor entirely; the sole caller (ff_syscall_wrapper.c) now includes ff_config.h and reads ff_global_cfg.stack.kernel_coexist directly. ff_host_interface.h keeps its lightweight host-bridge scope (no ff_config.h pull-in). Unit tests drop the redundant accessor assertions but still assert the underlying global. Spec docs updated to match the implementation.
1 parent 793d9ff commit acfc0bd

9 files changed

Lines changed: 8 additions & 25 deletions

File tree

docs/kernel_event_support_spec/06-milestones.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
## 3. R3 Native ff_api Unified-Event Coexistence (new design, core change)
3939
**Coding work list**:
40-
1. `lib/ff_config.{c,h}`: change the v3 `stack.default_to_kernel`/`default_stack` to `stack.kernel_coexist` (`MATCH("stack","kernel_coexist")`, default 0); sync the `test_ff_config` cases and fixtures, the `config.ini` example section, and the accessor (e.g., `ff_kernel_coexist_enabled()`).
40+
1. `lib/ff_config.{c,h}`: change the v3 `stack.default_to_kernel`/`default_stack` to `stack.kernel_coexist` (`MATCH("stack","kernel_coexist")`, default 0); sync the `test_ff_config` cases and fixtures, the `config.ini` example section; callers read `ff_global_cfg.stack.kernel_coexist` directly (no accessor).
4141
2. `lib/ff_host_interface.{c,h}`: add a **managed kernel-side bridge** (host `socket/bind/listen/accept/connect/close/epoll_create1/epoll_ctl/epoll_wait`) for lib to create managed kernel fds (**not a raw bypass**; lib registers ownership).
4242
3. lib-internal fd-ownership mechanism: an ownership table / encoded offset distinguishes managed kernel fds from F-Stack fds; `ff_socket(SOCK_KERNEL)` (when coexistence enabled) creates a managed kernel fd and registers it; default/`SOCK_FSTACK` go the original `sys_socket` (byte-for-byte zero regression).
4343
4. `ff_bind/ff_listen/ff_accept/ff_connect/ff_close`: route by ownership at the entry (kernel fd → managed host bridge; F-Stack fd → original path).

docs/kernel_event_support_spec/08-review-gate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
### I.1 Code-Change Verification (all PASS)
4141
| ID | Assertion | Result | Evidence |
4242
|---|---|---|---|
43-
| I1 | config coexistence switch (R3.1) | PASS | `ff_config.h` `struct{int kernel_coexist;}stack;`; `ff_config.c` `MATCH("stack","kernel_coexist")`(1/on/true/yes→1), default 0, `ff_kernel_coexist_enabled()` |
43+
| I1 | config coexistence switch (R3.1) | PASS | `ff_config.h` `struct{int kernel_coexist;}stack;`; `ff_config.c` `MATCH("stack","kernel_coexist")`(1/on/true/yes→1), default 0; callers read `ff_global_cfg.stack.kernel_coexist` directly |
4444
| I2 | FD-space scheme (no collision) | PASS | `ff_host_interface.h` `FF_KERNEL_FD_BASE 0x40000000`, `ff_is_kernel_fd/encode/real` (above FreeBSD fd ≤65536, host fds bounded by RLIMIT) |
4545
| I3 | host bridge (managed kernel fd, not a raw bypass) | PASS | `ff_host_interface.c` `ff_host_socket/bind/listen/accept/accept4/connect/close/read/write/recv/send/sendto/recvfrom/setsockopt/getsockopt/fcntl/epoll_create1/ctl/wait`; `_GNU_SOURCE` for accept4/epoll_create1 |
4646
| I4 | socket-side ownership routing (R3.2/3.3) | PASS | `ff_syscall_wrapper.c` `ff_socket`(SOCK_KERNEL+coexist→managed kernel fd) and close/read/write/sendto/recvfrom/accept/accept4/listen/bind/connect/setsockopt/getsockopt/fcntl entries route by `ff_is_kernel_fd` |

docs/kernel_event_support_spec/zh_cn/06-milestones.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
## 3. R3 原生 ff_api 统一事件共存(新设计,核心改造)
4040
**编码工作清单**
41-
1. `lib/ff_config.{c,h}`:将 v3 `stack.default_to_kernel`/`default_stack` 改为 `stack.kernel_coexist``MATCH("stack","kernel_coexist")`,默认 0);同步更新 `test_ff_config` 用例与 fixtures、`config.ini` 示例段、访问器(如 `ff_kernel_coexist_enabled()`
41+
1. `lib/ff_config.{c,h}`:将 v3 `stack.default_to_kernel`/`default_stack` 改为 `stack.kernel_coexist``MATCH("stack","kernel_coexist")`,默认 0);同步更新 `test_ff_config` 用例与 fixtures、`config.ini` 示例段;调用方直接读 `ff_global_cfg.stack.kernel_coexist`,不引入访问器
4242
2. `lib/ff_host_interface.{c,h}`:新增**受管内核侧桥**(宿主 `socket/bind/listen/accept/connect/close/epoll_create1/epoll_ctl/epoll_wait`),供 lib 调用建受管内核 fd(**非裸绕过**,由 lib 登记归属)。
4343
3. lib 内 fd 归属机制:归属表/编码偏移区分受管内核 fd 与 F-Stack fd;`ff_socket(SOCK_KERNEL)`(启用共存时)建受管内核 fd 并登记;默认/`SOCK_FSTACK` 走原 `sys_socket`(逐字节零回归)。
4444
4. `ff_bind/ff_listen/ff_accept/ff_connect/ff_close`:入口按归属路由(内核 fd → 受管宿主桥;F-Stack fd → 原路径)。

docs/kernel_event_support_spec/zh_cn/08-review-gate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
### I.1 代码改动核验(全部 PASS)
4444
| 编号 | 断言 | 结果 | 证据 |
4545
|---|---|---|---|
46-
| I1 | config 共存开关(R3.1) | PASS | `ff_config.h` `struct{int kernel_coexist;}stack;``ff_config.c` `MATCH("stack","kernel_coexist")`(1/on/true/yes→1)、默认 0`ff_kernel_coexist_enabled()` |
46+
| I1 | config 共存开关(R3.1) | PASS | `ff_config.h` `struct{int kernel_coexist;}stack;``ff_config.c` `MATCH("stack","kernel_coexist")`(1/on/true/yes→1)、默认 0;调用方直接读 `ff_global_cfg.stack.kernel_coexist` |
4747
| I2 | FD 空间方案(零冲突) | PASS | `ff_host_interface.h` `FF_KERNEL_FD_BASE 0x40000000``ff_is_kernel_fd/encode/real`(远超 FreeBSD fd≤65536,宿主 fd 受 RLIMIT 限) |
4848
| I3 | 宿主桥(受管内核 fd,非裸绕过) | PASS | `ff_host_interface.c` `ff_host_socket/bind/listen/accept/accept4/connect/close/read/write/recv/send/sendto/recvfrom/setsockopt/getsockopt/fcntl/epoll_create1/ctl/wait``_GNU_SOURCE` for accept4/epoll_create1 |
4949
| I4 | socket 侧归属路由(R3.2/3.3) | PASS | `ff_syscall_wrapper.c` `ff_socket`(SOCK_KERNEL+coexist→受管内核 fd) 及 close/read/write/sendto/recvfrom/accept/accept4/listen/bind/connect/setsockopt/getsockopt/fcntl 入口 `ff_is_kernel_fd` 路由 |

lib/ff_config.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,12 +1376,6 @@ ff_default_config(struct ff_config *cfg)
13761376
cfg->log.dir = strdup(FF_LOG_FILENAME_PREFIX);
13771377
}
13781378

1379-
int
1380-
ff_kernel_coexist_enabled(void)
1381-
{
1382-
return ff_global_cfg.stack.kernel_coexist;
1383-
}
1384-
13851379
int
13861380
ff_load_config(int argc, char *const argv[])
13871381
{

lib/ff_config.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,6 @@ extern struct ff_config ff_global_cfg;
350350

351351
int ff_load_config(int argc, char * const argv[]);
352352

353-
/* Returns non-zero when kernel-stack coexistence is enabled for this process
354-
* (config.ini [stack] kernel_coexist=1). */
355-
int ff_kernel_coexist_enabled(void);
356-
357353
void ff_unload_config(void);
358354

359355
#ifdef __cplusplus

lib/ff_host_interface.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ static inline int ff_kernel_fd_real(int fd)
126126
return fd - FF_KERNEL_FD_BASE;
127127
}
128128

129-
/* Defined in ff_config.c: non-zero when [stack] kernel_coexist=1. */
130-
int ff_kernel_coexist_enabled(void);
131-
132129
/*
133130
* Host kernel-stack bridge (implemented in ff_host_interface.c, host
134131
* namespace). These operate on RAW host fds. sockaddr / epoll_event are

lib/ff_syscall_wrapper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
#include "ff_api.h"
6363
#include "ff_host_interface.h"
64+
#include "ff_config.h"
6465

6566
/* setsockopt/getsockopt define start */
6667

@@ -923,7 +924,7 @@ ff_socket(int domain, int type, int protocol)
923924
* byte-for-byte unchanged (NFR-1 zero regression).
924925
*/
925926
if ((type & SOCK_KERNEL) && !(type & SOCK_FSTACK) &&
926-
ff_kernel_coexist_enabled()) {
927+
ff_global_cfg.stack.kernel_coexist) {
927928
int kfd = ff_host_socket(domain,
928929
type & ~(SOCK_KERNEL | SOCK_FSTACK), protocol);
929930
return kfd < 0 ? -1 : ff_kernel_fd_encode(kfd);

tests/unit/test_ff_config.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,28 +1007,24 @@ test_bond_cfgs_calloc_oom_returns_error(void **state)
10071007
/* ------------------------------------------------------------------------ */
10081008
/* kernel_event_support (coexistence): [stack] kernel_coexist parsing */
10091009
/* ------------------------------------------------------------------------ */
1010-
extern int ff_kernel_coexist_enabled(void);
1011-
1012-
/* kernel_coexist=1 -> stack.kernel_coexist == 1 + accessor agrees */
1010+
/* kernel_coexist=1 -> stack.kernel_coexist == 1 */
10131011
static void
10141012
test_ff_load_config_stack_coexist_enabled(void **state)
10151013
{
10161014
(void)state;
10171015
int rv = load_with_fixture(FIXTURE_PATH("valid_stack_kernel.ini"));
10181016
(void)rv;
10191017
assert_int_equal(ff_global_cfg.stack.kernel_coexist, 1);
1020-
assert_int_equal(ff_kernel_coexist_enabled(), 1);
10211018
}
10221019

1023-
/* [stack] absent -> coexistence disabled (0); accessor returns 0 */
1020+
/* [stack] absent -> coexistence disabled (0) */
10241021
static void
10251022
test_ff_load_config_stack_absent_defaults_disabled(void **state)
10261023
{
10271024
(void)state;
10281025
int rv = load_with_fixture(FIXTURE_PATH("valid_minimal.ini"));
10291026
(void)rv;
10301027
assert_int_equal(ff_global_cfg.stack.kernel_coexist, 0);
1031-
assert_int_equal(ff_kernel_coexist_enabled(), 0);
10321028
}
10331029

10341030
/* kernel_coexist with an unrecognized value -> falls back to disabled (0) */
@@ -1039,7 +1035,6 @@ test_ff_load_config_stack_garbage_defaults_disabled(void **state)
10391035
int rv = load_with_fixture(FIXTURE_PATH("valid_stack_garbage.ini"));
10401036
(void)rv;
10411037
assert_int_equal(ff_global_cfg.stack.kernel_coexist, 0);
1042-
assert_int_equal(ff_kernel_coexist_enabled(), 0);
10431038
}
10441039

10451040
/* explicit kernel_coexist=0 -> 0 (verified via valid_all_sections.ini) */

0 commit comments

Comments
 (0)