sockfs: the most simple file system in linux kernel

本文探讨了socket作为特殊文件系统的特点与实现,通过对比socket与普通文件系统的操作,揭示了其在VFS(虚拟文件系统)中的简化实现方式,并深入分析了socket在文件系统层面的独特之处。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

几年前做windows 网络的时候,就一直很好奇,为什么对一个socket既可以使用recv,send等socket API,同时又可以使用writefile和readfile?转到Linux下后,受Everything is file的熏陶,越发对VFS实现产生兴趣,便想结合sockfs对VFS做一个具体的分析。

然而,实践证明,把诸多元素混杂在一起,试图一劳永逸的做法有时候反而会让分析过程更加拖沓和反复,试图使用sockfs来了解整个VFS的实现也是不现实的,因为各个文件系统的使用场景是不相同的。

在明确了上述两点之后,从socket使用场景来入手,会更好一些,这里,只考虑与VFS相关内容,不在考虑诸如accept,listen以及地址域等网络相关的操作。

从文件系统角度来看,socket的几个特殊之处在于:

  • socket fd只能通过socket()函数获取,open()无法获取socket的fd
  • 虽然socket是一个文件系统,但是它是一个特殊的文件系统,不允许用户mount sockfs
  • sockfs 不支持路径查找

由于种种的限制,决定了sockfs的实现比其他文件系统实现要简单的多。我们可以从sockfs的dentry_operations和super_operations中看出来sockfs在偷工减料,尤其是dentry_operations,仅仅实现了一个d_dname.

static const struct dentry_operations sockfs_dentry_operations = {
	.d_dname  = sockfs_dname,
};

static const struct super_operations sockfs_ops = {
	.alloc_inode	= sock_alloc_inode,
	.destroy_inode	= sock_destroy_inode,
	.statfs		= simple_statfs,
};



Traceback (most recent call last): File "D:\ie浏览器下载\python\Lib\site-packages\cupy\cuda\compiler.py", line 737, in compile nvrtc.compileProgram(self.ptr, options) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "cupy_backends\\cuda\\libs\\nvrtc.pyx", line 125, in cupy_backends.cuda.libs.nvrtc.compileProgram File "cupy_backends\\cuda\\libs\\nvrtc.pyx", line 138, in cupy_backends.cuda.libs.nvrtc.compileProgram File "cupy_backends\\cuda\\libs\\nvrtc.pyx", line 53, in cupy_backends.cuda.libs.nvrtc.check_status cupy_backends.cuda.libs.nvrtc.NVRTCError: NVRTC_ERROR_COMPILATION (6) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\admin\Desktop\dql\AAA猞猁培训\T4\T4.py", line 16, in <module> gpu_result = cp.add(matrix_a_gpu, matrix_b_gpu) File "cupy\\_core\\_kernel.pyx", line 1374, in cupy._core._kernel.ufunc.__call__ File "cupy\\_core\\_kernel.pyx", line 1401, in cupy._core._kernel.ufunc._get_ufunc_kernel File "cupy\\_core\\_kernel.pyx", line 1082, in cupy._core._kernel._get_ufunc_kernel File "cupy\\_core\\_kernel.pyx", line 94, in cupy._core._kernel._get_simple_elementwise_kernel File "cupy\\_core\\_kernel.pyx", line 82, in cupy._core._kernel._get_simple_elementwise_kernel_from_code File "cupy\\_core\\core.pyx", line 2330, in cupy._core.core.compile_with_cache File "D:\ie浏览器下载\python\Lib\site-packages\cupy\cuda\compiler.py", line 542, in _compile_module_with_cache return _compile_with_cache_cuda( source, options, arch, cache_dir, extra_source, backend, enable_cooperative_groups, name_expressions, log_stream, cache_in_memory, jitify) File "D:\ie浏览器下载\python\Lib\site-packages\cupy\cuda\compiler.py", line 622, in _compile_with_cache_cuda ptx, mapping = compile_using_nvrtc( ~~~~~~~~~~~~~~~~~~~^ source, options, arch, cu_name, name_expressions, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ log_stream, cache_in_memory, jitify) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\ie浏览器下载\python\Lib\site-packages\cupy\cuda\compiler.py", line 377, in compile_using_nvrtc return _compile(source, options, cu_path, name_expressions, log_stream, jitify) File "D:\ie浏览器下载\python\Lib\site-packages\cupy\cuda\compiler.py", line 361, in _compile compiled_obj, mapping = prog.compile(options, log_stream) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^ File "D:\ie浏览器下载\python\Lib\site-packages\cupy\cuda\compiler.py", line 756, in compile raise CompileException(log, self.src, self.name, options, 'nvrtc' if not runtime.is_hip else 'hiprtc') cupy.cuda.compiler.CompileException: C:\Users\admin\AppData\Local\Temp\tmp0fnl03t8\311b0807260629cae0fa9bc0539f56cc1d00577e.cubin.cu(1): catastrophic error: cannot open source file "cupy/complex.cuh" #include <cupy/complex.cuh> ^ 1 catastrophic error detected in the compilation of "C:\Users\admin\AppData\Local\Temp\tmp0fnl03t8\311b0807260629cae0fa9bc0539f56cc1d00577e.cubin.cu". Compilation terminated.
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值