如何为自己编写的内核模块禁用rmmod? [英] How to disable rmmod for my own written kernel module?

查看:112
本文介绍了如何为自己编写的内核模块禁用rmmod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户进程正在使用内核模块,我希望另一个进程不能为该模块触发rmmod. 如何实现这种功能?

-Linux内核编程的入门者.

当引用计数为零时,

解决方案

rmmod只能 卸载模块.

如果在连接用户进程时引用计数增加(而在断开连接时递减),则可以.

如果该模块公开了设备,或者已作为文件系统安装,则应该自然处理-如果不是,我想这将取决于用户空间界面,但这是从哪里开始寻找的.

顺便说一句,lsmod将显示您的模块引用计数.您可以检查在用户空间进程连接后它是否增加.

If a user process is working with kernel module, I want that another process can't fire rmmod for that module. How to achieve this type of functionality?

-beginner in Linux kernel programming.

解决方案

rmmod can only unload a module when the refcount is zero.

If the reference count is incremented when a user process is connected (and decremented when it disconnects), you'll be fine.

If the module exposes a device, or is mounted as a filesystem, this should be handled naturally - if not, I guess it'll depend on the userspace interface, but this where to start looking.

By the way, lsmod will show your module refcount. You can check whether it's incremented when the userspace process connects.

这篇关于如何为自己编写的内核模块禁用rmmod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆