Message ID | 20220916085155.33750-2-shaozhengchao@huawei.com (mailing list archive) |
---|---|
State | RFC |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | refactor the module and net init/exit functions in tc_action | expand |
On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote: > Helper macro for tcf_action that don't do anything special in module > and net init/exit. This eliminates a lot of boilerplate. Each module > may only use this macro once, and calling it replaces module/net_init() > and module/net_exit(). > This looks over engineering to me. I don't think this reduces any code size or help any readability. Thanks.
On 2022/9/18 3:03, Cong Wang wrote: > On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote: >> Helper macro for tcf_action that don't do anything special in module >> and net init/exit. This eliminates a lot of boilerplate. Each module >> may only use this macro once, and calling it replaces module/net_init() >> and module/net_exit(). >> > > This looks over engineering to me. I don't think this reduces any code > size or help any readability. > > Thanks. Hi Wang: Thank you for your review. I think this macro can simplify repeated code when adding action modules later. Zhengchao Shao
On Mon, Sep 19, 2022 at 07:07:22PM +0800, shaozhengchao wrote: > > > On 2022/9/18 3:03, Cong Wang wrote: > > On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote: > > > Helper macro for tcf_action that don't do anything special in module > > > and net init/exit. This eliminates a lot of boilerplate. Each module > > > may only use this macro once, and calling it replaces module/net_init() > > > and module/net_exit(). > > > > > > > This looks over engineering to me. I don't think this reduces any code > > size or help any readability. > > > > Thanks. > Hi Wang: > Thank you for your review. I think this macro can simplify > repeated code when adding action modules later. > I don't think so, it hides the actual code in a less readable way. I'd like to read the non-macro code. Thanks.
diff --git a/include/net/act_api.h b/include/net/act_api.h index 61f2ceb3939e..dac8c6475efc 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -292,5 +292,31 @@ static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes, #endif } +#define module_net_tcf_action(__mod, __act_ops) \ +static __net_init int __mod##_init_net(struct net *net) \ +{ \ + struct tc_action_net *tn = net_generic(net, __act_ops.net_id);\ + return tc_action_net_init(net, tn, &__act_ops);\ +} \ +static void __net_exit __mod##_exit_net(struct list_head *net_list) \ +{ \ + tc_action_net_exit(net_list, __act_ops.net_id); \ +} \ +static struct pernet_operations __mod##_net_ops = { \ + .init = __mod##_init_net, \ + .exit_batch = __mod##_exit_net, \ + .id = &__act_ops.net_id, \ + .size = sizeof(struct tc_action_net), \ +}; \ +static int __init __mod##_init_module(void) \ +{ \ + return tcf_register_action(&__act_ops, &(__mod##_net_ops)); \ +} \ +module_init(__mod##_init_module); \ +static void __exit __mod##_cleanup_module(void) \ +{ \ + tcf_unregister_action(&__act_ops, &(__mod##_net_ops)); \ +} \ +module_exit(__mod##_cleanup_module) #endif
Helper macro for tcf_action that don't do anything special in module and net init/exit. This eliminates a lot of boilerplate. Each module may only use this macro once, and calling it replaces module/net_init() and module/net_exit(). Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com> --- include/net/act_api.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)