{"id":4114,"date":"2012-08-09T21:25:16","date_gmt":"2012-08-09T13:25:16","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=4114"},"modified":"2012-08-17T14:51:43","modified_gmt":"2012-08-17T06:51:43","slug":"%e7%bd%91%e7%bb%9c%e5%8d%8f%e8%ae%ae%e6%a0%88%e5%85%a5%e9%97%a8%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/4114","title":{"rendered":"\u7f51\u7edc\u534f\u8bae\u6808\u5165\u95e8\u77e5\u8bc6"},"content":{"rendered":"<p>Linux\u5185\u6838\u5c06\u4e00\u5207\u90fd\u770b\u4f5c\u4e3a\u6587\u4ef6\uff0c\u56e0\u6b64\u7f51\u7edc\u534f\u8bae\u6808\u4ee5\u6587\u4ef6\u7cfb\u7edfsockfs\u7684\u5f62\u5f0f\u5b58\u5728\u4e8e\u5185\u6838\u4e2d\uff0c\u8be5\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u5219\u662f\u6211\u4eec\u719f\u77e5\u7684\u5957\u63a5\u5b57\u3002\u7a0d\u5fae\u719f\u77e5Linux\u6587\u4ef6\u7cfb\u7edf\u7684\u4eba\u90fd\u4f1a\u77e5\u9053\u5185\u6838\u4e2d\u5c06\u6240\u6709\u6587\u4ef6\u7cfb\u7edf\u8fdb\u884c\u62bd\u8c61\uff0c\u901a\u8fc7\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff08VFS\uff09\u6765\u7edf\u4e00\u7ba1\u7406\u3002\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\u4e5f\u662f\u5982\u6b64\uff0c\u4e5f\u5c31\u662f\u8bf4\u8d85\u7ea7\u5757\uff0c\u7d22\u5f15\u8282\u70b9\uff0c\u76ee\u5f55\u9879\u7b49\u6982\u5ff5\u5728\u7f51\u8def\u6587\u4ef6\u7cfb\u7edf\u4e2d\u4e5f\u5b58\u5728\u3002<\/p>\n<p>\u5728proc\u6587\u4ef6\u7cfb\u7edf\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u65b9\u5f0f\u5f97\u5230\u5185\u6838\u5f53\u524d\u6240\u6709\u6587\u4ef6\u7cfb\u7edf\u7684\u540d\u79f0\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n&#x5B;root@TENCENT64 ~]# cat \/proc\/filesystems\r\nnodev   sysfs\r\nnodev   rootfs\r\nnodev   bdev\r\nnodev   proc\r\nnodev   tmpfs\r\nnodev   debugfs\r\nnodev   sockfs\r\nnodev   pipefs\r\nnodev   anon_inodefs\r\nnodev   rpc_pipefs\r\nnodev   inotifyfs\r\n\u2026\u2026\u2026\u2026\r\n        ext3\r\n        ext2\r\n        ext4\r\n<\/pre>\n<p>\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\u548cext3\u8fd9\u6837\u7684\u6587\u4ef6\u7cfb\u7edf\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u524d\u8005\u53ea\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d\uff0c\u800c\u540e\u8005\u5219\u5b58\u5728\u4e8e\u78c1\u76d8\u4e2d\u3002\u6bd4\u5982\u4e0a\u8ff0\u4fe1\u606f\u4e2d\u7684sockfs\u548ctmpfs\uff0c\u751a\u81f3\u662fproc\uff0c\u5728\u7b2c\u4e00\u5217\u5747\u663e\u793anodev\uff0c\u4e5f\u5c31\u662f\u8bf4\u8fd9\u4e9b\u6587\u4ef6\u7cfb\u7edf\u5e76\u6ca1\u6709\u5b58\u50a8\u5728\u78c1\u76d8\u8fd9\u6837\u7684\u5757\u8bbe\u5907\u4e2d\u3002\u76f8\u53cd\uff0c\u5b83\u4eec\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u5373\u91c7\u7528\u7684\u662f\u4e00\u79cd\u975e\u6301\u4e45\u6027\u7684\u5b58\u50a8\u65b9\u5f0f\u3002<\/p>\n<p>\u8fd9\u91cc\u5e94\u8be5\u6ce8\u610f\u7684\u662fsockfs\u7684\u201c\u865a\u62df\u201d\u548cVFS\u7684\u201c\u865a\u62df\u201d\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u6982\u5ff5\u3002\u524d\u8005\u8868\u793asockfs\u8fd9\u79cd\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u4e0d\u540c\u4e8eext2\u8fd9\u6837\u7684\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b83\u4eec\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u662f\u4e00\u79cd\u975e\u6301\u4e45\u7684\u5b58\u50a8\uff0c\u53ea\u8981\u7cfb\u7edf\u91cd\u542f\u4fe1\u606f\u5168\u90e8\u4e22\u5931\u3002\u800c\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u201c\u865a\u62df\u201d\u8868\u793a\u7684\u662f\u5bf9\u6240\u6709\u6587\u4ef6\u7cfb\u7edf\u7684\u4e00\u79cd\u62bd\u8c61\uff0c\u5b83\u5c06\u6240\u6709\u4e0d\u540c\u79cd\u7c7b\u6587\u4ef6\u7cfb\u7edf\u7684\u5171\u540c\u4fe1\u606f\u653e\u5165\u540c\u4e00\u7ec4\u6570\u636e\u7ed3\u6784\u5f53\u4e2d\uff0c\u4e3a\u4e0a\u5c42\u7528\u6237\u63d0\u4f9b\u4e86\u7edf\u4e00\u7684\u63a5\u53e3\u3002<\/p>\n<p>VFS\u4e2d\u7528\u4e8e\u63cf\u8ff0\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b\u7684\u6570\u636e\u7ed3\u6784\u4e3afile_system_type\uff0c\u6240\u6709\u6587\u4ef6\u7cfb\u7edf\u90fd\u5bf9\u5e94\u8be5\u7c7b\u578b\u7684\u53d8\u91cf\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstatic struct file_system_type sock_fs_type = {\r\n        .name =         &quot;sockfs&quot;,\r\n        .mount =        sockfs_mount,\r\n        .kill_sb =      kill_anon_super,\r\n};\r\n\r\nstatic struct file_system_type proc_fs_type = {\r\n        .name           = &quot;proc&quot;,\r\n        .mount          = proc_mount,\r\n        .kill_sb        = proc_kill_sb,\r\n};\r\n<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\/proc\/filesystem\u4e2d\u7684\u6587\u4ef6\u7cfb\u7edf\u540d\u79f0\u5373\u4ecefile_system_type\u7ed3\u6784\u7684\u5b9e\u4f8b\u4e2d\u83b7\u5f97\u3002<\/p>\n<p><strong>socket\u7ed3\u6784<\/strong><\/p>\n<p>\u5185\u6838\u4e2d\u901a\u8fc7socket\u7ed3\u6784\u4f53\u6765\u8868\u793a\u5957\u63a5\u5b57\u3002\u8be5\u7ed3\u6784\u4e2d\u5305\u542b\u7684\u5b57\u6bb5\u6bd4\u8f83\u5c11\uff0c\u6bd4\u5982\u63cf\u8ff0\u5957\u63a5\u5b57\u72b6\u6001\u7684state\uff0c\u5957\u63a5\u5b57\u6807\u5fd7\u4f4dflags\uff0c\u7b49\u5f85\u961f\u5217wp\u4ee5\u53ca\u4e0e\u8be5\u5957\u63a5\u5b57\u5173\u8054\u7684\u6587\u4ef6\u5bf9\u8c61\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n struct socket {\r\n         socket_state            state;\r\n         kmemcheck_bitfield_begin(type);\r\n         short                   type;\r\n         kmemcheck_bitfield_end(type);\r\n         unsigned long           flags;\r\n         struct socket_wq __rcu  *wq;\r\n         struct file             *file;\r\n         struct sock             *sk;\r\n         const struct proto_ops  *ops;\r\n };\r\n<\/pre>\n<p>\u5728socket\u7ed3\u6784\u4e2d\u5305\u542b\u4e86\u4e00\u4e2a\u4e0e\u5b83\u6bd4\u8f83\u76f8\u4f3c\u7684\u7ed3\u6784sock\uff0c\u8be5\u7ed3\u6784\u4e5f\u662f\u5bf9\u5957\u63a5\u5b57\u8fdb\u884c\u63cf\u8ff0\u7684\u3002<\/p>\n<p><strong>sock\u7ed3\u6784\u4f53<\/strong><\/p>\n<p>sock\u7ed3\u6784\u4e2d\u5305\u542b\u5927\u91cf\u7684\u5b57\u6bb5\uff0c\u8fd9\u4e9b\u5b57\u6bb5\u66f4\u591a\u7684\u662f\u7528\u6765\u63cf\u8ff0\u534f\u8bae\u7684\u901a\u7528\u5c5e\u6027\uff0c\u800csocket\u7ed3\u6784\u5219\u662f\u66f4\u591a\u7684\u63cf\u8ff0\u4e0e\u5e94\u7528\u7a0b\u5e8f\u76f8\u5173\u7684\u90e8\u5206\u3002<\/p>\n<p><strong>sk_buff\u7ed3\u6784\u4f53<\/strong><\/p>\n<p>sk_buff\u7528\u4e8e\u5bf9\u7f51\u7edc\u534f\u8bae\u4e2d\u7684\u6570\u636e\u5305\u8fdb\u884c\u63cf\u8ff0\uff0c\u4e0d\u7ba1\u8be5\u6570\u636e\u5305\u4f4d\u4e8e\u90a3\u4e00\u5c42\u534f\u8bae\uff0c\u90fd\u4f1a\u6709\u4e00\u4e2ask_buff\u7ed3\u6784\u4e0e\u4e4b\u5bf9\u5e94\u3002\u800csk_buff\u7ed3\u6784\u901a\u8fc7\u5176\u5185\u90e8\u7684\u51e0\u4e2a\u6307\u9488\u5b57\u6bb5\u5c31\u53ef\u4ee5\u8f7b\u677e\u5b8c\u6210\u52a0\u5305\u5934\u53bb\u5305\u5934\u7684\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u4e09\u8005\u7684\u5173\u7cfb<\/strong><\/p>\n<p>\u6bcf\u4e2asocket\u7ed3\u6784\u90fd\u6709\u4e00\u4e2ask\u5b57\u6bb5\u6307\u5411sock\u7ed3\u6784\uff0c\u800csock\u7ed3\u6784\u4e2d\u901a\u8fc7sk_socket\u5b57\u6bb5\u53cd\u6307\u5411socket\u7ed3\u6784\u3002sock\u7ed3\u6784\u901a\u8fc7sk_receive_queue\u548csk_write_queue\u7b49\u5b57\u6bb5\u6307\u5411\u6570\u636e\u5305\u5934\u7ed3\u6784\uff08struct sk_buff_head\uff09\uff0c\u800c\u8fd9\u4e2a\u7ed3\u6784\u5185\u90e8\u53c8\u901a\u8fc7prev\u548cnext\u4e24\u4e2a\u5b57\u6bb5\u6307\u5411\u771f\u6b63\u7684\u6570\u636e\u5305\u7ed3\u6784sk_buff\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u5185\u6838\u5c06\u4e00\u5207\u90fd\u770b\u4f5c\u4e3a\u6587\u4ef6\uff0c\u56e0\u6b64\u7f51\u7edc\u534f\u8bae\u6808\u4ee5\u6587\u4ef6\u7cfb\u7edfsockfs\u7684\u5f62\u5f0f\u5b58\u5728\u4e8e\u5185\u6838\u4e2d\uff0c\u8be5\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u5219 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[350],"tags":[242,351,352],"class_list":["post-4114","post","type-post","status-publish","format-standard","hentry","category-350","tag-tcpip","tag-351","tag-352"],"views":9559,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/4114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=4114"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/4114\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=4114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=4114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=4114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}