18c2ecf20Sopenharmony_ci.. _cn_process_howto:
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci.. include:: ../disclaimer-zh_CN.rst
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci:Original: :ref:`Documentation/process/howto.rst <process_howto>`
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci译者::
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci    英文版维护者: Greg Kroah-Hartman <greg@kroah.com>
108c2ecf20Sopenharmony_ci    中文版维护者: 李阳  Li Yang <leoyang.li@nxp.com>
118c2ecf20Sopenharmony_ci    中文版翻译者: 李阳  Li Yang <leoyang.li@nxp.com>
128c2ecf20Sopenharmony_ci                   时奎亮 Alex Shi <alex.shi@linux.alibaba.com>
138c2ecf20Sopenharmony_ci    中文版校译者:
148c2ecf20Sopenharmony_ci                   钟宇  TripleX Chung <xxx.phy@gmail.com>
158c2ecf20Sopenharmony_ci                   陈琦  Maggie Chen <chenqi@beyondsoft.com>
168c2ecf20Sopenharmony_ci                   王聪  Wang Cong <xiyou.wangcong@gmail.com>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci如何参与Linux内核开发
198c2ecf20Sopenharmony_ci=====================
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci这是一篇将如何参与Linux内核开发的相关问题一网打尽的终极秘笈。它将指导你
228c2ecf20Sopenharmony_ci成为一名Linux内核开发者,并且学会如何同Linux内核开发社区合作。它尽可能不
238c2ecf20Sopenharmony_ci包括任何关于内核编程的技术细节,但会给你指引一条获得这些知识的正确途径。
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci如果这篇文章中的任何内容不再适用,请给文末列出的文件维护者发送补丁。
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci入门
298c2ecf20Sopenharmony_ci----
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci你想了解如何成为一名Linux内核开发者?或者老板吩咐你“给这个设备写个Linux
328c2ecf20Sopenharmony_ci驱动程序”?这篇文章的目的就是教会你达成这些目标的全部诀窍,它将描述你需
338c2ecf20Sopenharmony_ci要经过的流程以及给出如何同内核社区合作的一些提示。它还将试图解释内核社区
348c2ecf20Sopenharmony_ci为何这样运作。
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciLinux内核大部分是由C语言写成的,一些体系结构相关的代码用到了汇编语言。要
378c2ecf20Sopenharmony_ci参与内核开发,你必须精通C语言。除非你想为某个架构开发底层代码,否则你并
388c2ecf20Sopenharmony_ci不需要了解(任何体系结构的)汇编语言。下面列举的书籍虽然不能替代扎实的C
398c2ecf20Sopenharmony_ci语言教育和多年的开发经验,但如果需要的话,做为参考还是不错的:
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci - "The C Programming Language" by Kernighan and Ritchie [Prentice Hall]
428c2ecf20Sopenharmony_ci   《C程序设计语言(第2版·新版)》(徐宝文 李志 译)[机械工业出版社]
438c2ecf20Sopenharmony_ci - "Practical C Programming" by Steve Oualline [O'Reilly]
448c2ecf20Sopenharmony_ci   《实用C语言编程(第三版)》(郭大海 译)[中国电力出版社]
458c2ecf20Sopenharmony_ci - "C:  A Reference Manual" by Harbison and Steele [Prentice Hall]
468c2ecf20Sopenharmony_ci   《C语言参考手册(原书第5版)》(邱仲潘 等译)[机械工业出版社]
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciLinux内核使用GNU C和GNU工具链开发。虽然它遵循ISO C89标准,但也用到了一些
498c2ecf20Sopenharmony_ci标准中没有定义的扩展。内核是自给自足的C环境,不依赖于标准C库的支持,所以
508c2ecf20Sopenharmony_ci并不支持C标准中的部分定义。比如long long类型的大数除法和浮点运算就不允许
518c2ecf20Sopenharmony_ci使用。有时候确实很难弄清楚内核对工具链的要求和它所使用的扩展,不幸的是目
528c2ecf20Sopenharmony_ci前还没有明确的参考资料可以解释它们。请查阅gcc信息页(使用“info gcc”命令
538c2ecf20Sopenharmony_ci显示)获得一些这方面信息。
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci请记住你是在学习怎么和已经存在的开发社区打交道。它由一群形形色色的人组成,
568c2ecf20Sopenharmony_ci他们对代码、风格和过程有着很高的标准。这些标准是在长期实践中总结出来的,
578c2ecf20Sopenharmony_ci适应于地理上分散的大型开发团队。它们已经被很好得整理成档,建议你在开发
588c2ecf20Sopenharmony_ci之前尽可能多的学习这些标准,而不要期望别人来适应你或者你公司的行为方式。
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci法律问题
628c2ecf20Sopenharmony_ci--------
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciLinux内核源代码都是在GPL(通用公共许可证)的保护下发布的。要了解这种许可
658c2ecf20Sopenharmony_ci的细节请查看源代码主目录下的COPYING文件。Linux内核许可准则和如何使用
668c2ecf20Sopenharmony_ci`SPDX <https://spdx.org/>` 标志符说明在这个文件中
678c2ecf20Sopenharmony_ci:ref:`Documentation/translations/zh_CN/process/license-rules.rst <cn_kernel_licensing>`
688c2ecf20Sopenharmony_ci如果你对它还有更深入问题请联系律师,而不要在Linux内核邮件组上提问。因为
698c2ecf20Sopenharmony_ci邮件组里的人并不是律师,不要期望他们的话有法律效力。
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci对于GPL的常见问题和解答,请访问以下链接:
728c2ecf20Sopenharmony_ci	https://www.gnu.org/licenses/gpl-faq.html
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci文档
768c2ecf20Sopenharmony_ci----
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciLinux内核代码中包含有大量的文档。这些文档对于学习如何与内核社区互动有着
798c2ecf20Sopenharmony_ci不可估量的价值。当一个新的功能被加入内核,最好把解释如何使用这个功能的文
808c2ecf20Sopenharmony_ci档也放进内核。当内核的改动导致面向用户空间的接口发生变化时,最好将相关信
818c2ecf20Sopenharmony_ci息或手册页(manpages)的补丁发到mtk.manpages@gmail.com,以向手册页(manpages)
828c2ecf20Sopenharmony_ci的维护者解释这些变化。
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci以下是内核代码中需要阅读的文档:
858c2ecf20Sopenharmony_ci  :ref:`Documentation/admin-guide/README.rst <readme>`
868c2ecf20Sopenharmony_ci    文件简要介绍了Linux内核的背景,并且描述了如何配置和编译内核。内核的
878c2ecf20Sopenharmony_ci    新用户应该从这里开始。
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci  :ref:`Documentation/process/changes.rst <changes>`
918c2ecf20Sopenharmony_ci    文件给出了用来编译和使用内核所需要的最小软件包列表。
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci  :ref:`Documentation/translations/zh_CN/process/coding-style.rst <cn_codingstyle>`
948c2ecf20Sopenharmony_ci    描述Linux内核的代码风格和理由。所有新代码需要遵守这篇文档中定义的规
958c2ecf20Sopenharmony_ci    范。大多数维护者只会接收符合规定的补丁,很多人也只会帮忙检查符合风格
968c2ecf20Sopenharmony_ci    的代码。
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci  :ref:`Documentation/translations/zh_CN/process/submitting-patches.rst <cn_submittingpatches>`
998c2ecf20Sopenharmony_ci  :ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci    这两份文档明确描述如何创建和发送补丁,其中包括(但不仅限于):
1028c2ecf20Sopenharmony_ci       - 邮件内容
1038c2ecf20Sopenharmony_ci       - 邮件格式
1048c2ecf20Sopenharmony_ci       - 选择收件人
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci    遵守这些规定并不能保证提交成功(因为所有补丁需要通过严格的内容和风格
1078c2ecf20Sopenharmony_ci    审查),但是忽视他们几乎就意味着失败。
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci    其他关于如何正确地生成补丁的优秀文档包括:
1108c2ecf20Sopenharmony_ci    "The Perfect Patch"
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci        https://www.ozlabs.org/~akpm/stuff/tpp.txt
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci    "Linux kernel patch submission format"
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci        https://web.archive.org/web/20180829112450/http://linux.yyz.us/patch-format.html
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci  :ref:`Documentation/translations/zh_CN/process/stable-api-nonsense.rst <cn_stable_api_nonsense>`
1198c2ecf20Sopenharmony_ci    论证内核为什么特意不包括稳定的内核内部API,也就是说不包括像这样的特
1208c2ecf20Sopenharmony_ci    性:
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci       - 子系统中间层(为了兼容性?)
1238c2ecf20Sopenharmony_ci       - 在不同操作系统间易于移植的驱动程序
1248c2ecf20Sopenharmony_ci       - 减缓(甚至阻止)内核代码的快速变化
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci    这篇文档对于理解Linux的开发哲学至关重要。对于将开发平台从其他操作系
1278c2ecf20Sopenharmony_ci    统转移到Linux的人来说也很重要。
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci  :ref:`Documentation/admin-guide/security-bugs.rst <securitybugs>`
1308c2ecf20Sopenharmony_ci    如果你认为自己发现了Linux内核的安全性问题,请根据这篇文档中的步骤来
1318c2ecf20Sopenharmony_ci    提醒其他内核开发者并帮助解决这个问题。
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci  :ref:`Documentation/translations/zh_CN/process/management-style.rst <cn_managementstyle>`
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci    描述内核维护者的工作方法及其共有特点。这对于刚刚接触内核开发(或者对
1368c2ecf20Sopenharmony_ci    它感到好奇)的人来说很重要,因为它解释了很多对于内核维护者独特行为的
1378c2ecf20Sopenharmony_ci    普遍误解与迷惑。
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci  :ref:`Documentation/process/stable-kernel-rules.rst <stable_kernel_rules>`
1408c2ecf20Sopenharmony_ci    解释了稳定版内核发布的规则,以及如何将改动放入这些版本的步骤。
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci  :ref:`Documentation/process/kernel-docs.rst <kernel_docs>`
1438c2ecf20Sopenharmony_ci    有助于内核开发的外部文档列表。如果你在内核自带的文档中没有找到你想找
1448c2ecf20Sopenharmony_ci    的内容,可以查看这些文档。
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci  :ref:`Documentation/process/applying-patches.rst <applying_patches>`
1478c2ecf20Sopenharmony_ci    关于补丁是什么以及如何将它打在不同内核开发分支上的好介绍
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci内核还拥有大量从代码自动生成或者从 ReStructuredText(ReST) 标记生成的文档,
1508c2ecf20Sopenharmony_ci比如这个文档,它包含内核内部API的全面介绍以及如何妥善处理加锁的规则。所有
1518c2ecf20Sopenharmony_ci这些文档都可以通过运行以下命令从内核代码中生成为PDF或HTML文档::
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci    make pdfdocs
1548c2ecf20Sopenharmony_ci    make htmldocs
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ciReST格式的文档会生成在 Documentation/output. 目录中。
1578c2ecf20Sopenharmony_ci它们也可以用下列命令生成 LaTeX 和 ePub 格式文档::
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci    make latexdocs
1608c2ecf20Sopenharmony_ci    make epubdocs
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci如何成为内核开发者
1638c2ecf20Sopenharmony_ci------------------
1648c2ecf20Sopenharmony_ci如果你对Linux内核开发一无所知,你应该访问“Linux内核新手”计划:
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	https://kernelnewbies.org
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci它拥有一个可以问各种最基本的内核开发问题的邮件列表(在提问之前一定要记得
1698c2ecf20Sopenharmony_ci查找已往的邮件,确认是否有人已经回答过相同的问题)。它还拥有一个可以获得
1708c2ecf20Sopenharmony_ci实时反馈的IRC聊天频道,以及大量对于学习Linux内核开发相当有帮助的文档。
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci网站简要介绍了源代码组织结构、子系统划分以及目前正在进行的项目(包括内核
1738c2ecf20Sopenharmony_ci中的和单独维护的)。它还提供了一些基本的帮助信息,比如如何编译内核和打补
1748c2ecf20Sopenharmony_ci丁。
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci如果你想加入内核开发社区并协助完成一些任务,却找不到从哪里开始,可以访问
1778c2ecf20Sopenharmony_ci“Linux内核房管员”计划:
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	https://kernelnewbies.org/KernelJanitors
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci这是极佳的起点。它提供一个相对简单的任务列表,列出内核代码中需要被重新
1828c2ecf20Sopenharmony_ci整理或者改正的地方。通过和负责这个计划的开发者们一同工作,你会学到将补丁
1838c2ecf20Sopenharmony_ci集成进内核的基本原理。如果还没有决定下一步要做什么的话,你还可能会得到方
1848c2ecf20Sopenharmony_ci向性的指点。
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci在真正动手修改内核代码之前,理解要修改的代码如何运作是必需的。要达到这个
1878c2ecf20Sopenharmony_ci目的,没什么办法比直接读代码更有效了(大多数花招都会有相应的注释),而且
1888c2ecf20Sopenharmony_ci一些特制的工具还可以提供帮助。例如,“Linux代码交叉引用”项目就是一个值得
1898c2ecf20Sopenharmony_ci特别推荐的帮助工具,它将源代码显示在有编目和索引的网页上。其中一个更新及
1908c2ecf20Sopenharmony_ci时的内核源码库,可以通过以下地址访问:
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci        https://elixir.bootlin.com/
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci开发流程
1968c2ecf20Sopenharmony_ci--------
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci目前Linux内核开发流程包括几个“主内核分支”和很多子系统相关的内核分支。这
1998c2ecf20Sopenharmony_ci些分支包括:
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci  - Linus 的内核源码树
2028c2ecf20Sopenharmony_ci  - 多个主要版本的稳定版内核树
2038c2ecf20Sopenharmony_ci  - 子系统相关的内核树
2048c2ecf20Sopenharmony_ci  - linux-next 集成测试树
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci主线树
2088c2ecf20Sopenharmony_ci------
2098c2ecf20Sopenharmony_ci主线树是由Linus Torvalds 维护的。你可以在https://kernel.org 网站或者代码
2108c2ecf20Sopenharmony_ci库中下找到它。它的开发遵循以下步骤:
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci  - 每当一个新版本的内核被发布,为期两周的集成窗口将被打开。在这段时间里
2138c2ecf20Sopenharmony_ci    维护者可以向Linus提交大段的修改,通常这些修改已经被放到-mm内核中几个
2148c2ecf20Sopenharmony_ci    星期了。提交大量修改的首选方式是使用git工具(内核的代码版本管理工具
2158c2ecf20Sopenharmony_ci    ,更多的信息可以在 https://git-scm.com/ 获取),不过使用普通补丁也是
2168c2ecf20Sopenharmony_ci    可以的。
2178c2ecf20Sopenharmony_ci  - 两个星期以后-rc1版本内核发布。之后只有不包含可能影响整个内核稳定性的
2188c2ecf20Sopenharmony_ci    新功能的补丁才可能被接受。请注意一个全新的驱动程序(或者文件系统)有
2198c2ecf20Sopenharmony_ci    可能在-rc1后被接受是因为这样的修改完全独立,不会影响其他的代码,所以
2208c2ecf20Sopenharmony_ci    没有造成内核退步的风险。在-rc1以后也可以用git向Linus提交补丁,不过所
2218c2ecf20Sopenharmony_ci    有的补丁需要同时被发送到相应的公众邮件列表以征询意见。
2228c2ecf20Sopenharmony_ci  - 当Linus认为当前的git源码树已经达到一个合理健全的状态足以发布供人测试
2238c2ecf20Sopenharmony_ci    时,一个新的-rc版本就会被发布。计划是每周都发布新的-rc版本。
2248c2ecf20Sopenharmony_ci  - 这个过程一直持续下去直到内核被认为达到足够稳定的状态,持续时间大概是
2258c2ecf20Sopenharmony_ci    6个星期。
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci关于内核发布,值得一提的是Andrew Morton在linux-kernel邮件列表中如是说:
2288c2ecf20Sopenharmony_ci	“没有人知道新内核何时会被发布,因为发布是根据已知bug的情况来决定
2298c2ecf20Sopenharmony_ci	的,而不是根据一个事先制定好的时间表。”
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci子系统特定树
2328c2ecf20Sopenharmony_ci------------
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci各种内核子系统的维护者——以及许多内核子系统开发人员——在源代码库中公开了他们
2358c2ecf20Sopenharmony_ci当前的开发状态。这样,其他人就可以看到内核的不同区域发生了什么。在开发速度
2368c2ecf20Sopenharmony_ci很快的领域,可能会要求开发人员将提交的内容建立在这样的子系统内核树上,这样
2378c2ecf20Sopenharmony_ci就避免了提交与其他已经进行的工作之间的冲突。
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci这些存储库中的大多数都是Git树,但是也有其他的scm在使用,或者补丁队列被发布
2408c2ecf20Sopenharmony_ci为Quilt系列。这些子系统存储库的地址列在MAINTAINERS文件中。其中许多可以在
2418c2ecf20Sopenharmony_cihttps://git.kernel.org/上浏览。
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci在将一个建议的补丁提交到这样的子系统树之前,需要对它进行审查,审查主要发生
2448c2ecf20Sopenharmony_ci在邮件列表上(请参见下面相应的部分)。对于几个内核子系统,这个审查过程是通
2458c2ecf20Sopenharmony_ci过工具补丁跟踪的。Patchwork提供了一个Web界面,显示补丁发布、对补丁的任何评
2468c2ecf20Sopenharmony_ci论或修订,维护人员可以将补丁标记为正在审查、接受或拒绝。大多数补丁网站都列
2478c2ecf20Sopenharmony_cihttps://patchwork.kernel.org/
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ciLinux-next 集成测试树
2508c2ecf20Sopenharmony_ci---------------------
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci在将子系统树的更新合并到主线树之前,需要对它们进行集成测试。为此,存在一个
2538c2ecf20Sopenharmony_ci特殊的测试存储库,其中几乎每天都会提取所有子系统树:
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci        https://git.kernel.org/?p=linux/kernel/git/next/linux-next.git
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci通过这种方式,Linux-next 对下一个合并阶段将进入主线内核的内容给出了一个概要
2588c2ecf20Sopenharmony_ci展望。非常欢冒险的测试者运行测试Linux-next。
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci多个主要版本的稳定版内核树
2618c2ecf20Sopenharmony_ci-----------------------------------
2628c2ecf20Sopenharmony_ci由3个数字组成的内核版本号说明此内核是-stable版本。它们包含内核的相对较小且
2638c2ecf20Sopenharmony_ci至关重要的修补,这些修补针对安全性问题或者严重的内核退步。
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci这种版本的内核适用于那些期望获得最新的稳定版内核并且不想参与测试开发版或
2668c2ecf20Sopenharmony_ci者实验版的用户。
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci稳定版内核树版本由“稳定版”小组(邮件地址<stable@vger.kernel.org>)维护,一般
2698c2ecf20Sopenharmony_ci隔周发布新版本。
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci内核源码中的 :ref:`Documentation/process/stable-kernel-rules.rst <stable_kernel_rules>`
2728c2ecf20Sopenharmony_ci文件具体描述了可被稳定版内核接受的修改类型以及发布的流程。
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci报告bug
2768c2ecf20Sopenharmony_ci-------
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_cibugzilla.kernel.org是Linux内核开发者们用来跟踪内核Bug的网站。我们鼓励用
2798c2ecf20Sopenharmony_ci户在这个工具中报告找到的所有bug。如何使用内核bugzilla的细节请访问:
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	http://test.kernel.org/bugzilla/faq.html
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci内核源码主目录中的:ref:`admin-guide/reporting-bugs.rst <reportingbugs>`
2848c2ecf20Sopenharmony_ci文件里有一个很好的模板。它指导用户如何报告可能的内核bug以及需要提供哪些信息
2858c2ecf20Sopenharmony_ci来帮助内核开发者们找到问题的根源。
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci利用bug报告
2898c2ecf20Sopenharmony_ci-----------
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci练习内核开发技能的最好办法就是修改其他人报告的bug。你不光可以帮助内核变
2928c2ecf20Sopenharmony_ci得更加稳定,还可以学会如何解决实际问题从而提高自己的技能,并且让其他开发
2938c2ecf20Sopenharmony_ci者感受到你的存在。修改bug是赢得其他开发者赞誉的最好办法,因为并不是很多
2948c2ecf20Sopenharmony_ci人都喜欢浪费时间去修改别人报告的bug。
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci要尝试修改已知的bug,请访问 http://bugzilla.kernel.org 网址。
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci邮件列表
3008c2ecf20Sopenharmony_ci--------
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci正如上面的文档所描述,大多数的骨干内核开发者都加入了Linux Kernel邮件列
3038c2ecf20Sopenharmony_ci表。如何订阅和退订列表的细节可以在这里找到:
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	http://vger.kernel.org/vger-lists.html#linux-kernel
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci网上很多地方都有这个邮件列表的存档(archive)。可以使用搜索引擎来找到这些
3088c2ecf20Sopenharmony_ci存档。比如:
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	http://dir.gmane.org/gmane.linux.kernel
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci在发信之前,我们强烈建议你先在存档中搜索你想要讨论的问题。很多已经被详细
3138c2ecf20Sopenharmony_ci讨论过的问题只在邮件列表的存档中可以找到。
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci大多数内核子系统也有自己独立的邮件列表来协调各自的开发工作。从
3168c2ecf20Sopenharmony_ciMAINTAINERS文件中可以找到不同话题对应的邮件列表。
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci很多邮件列表架设在kernel.org服务器上。这些列表的信息可以在这里找到:
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	http://vger.kernel.org/vger-lists.html
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci在使用这些邮件列表时,请记住保持良好的行为习惯。下面的链接提供了与这些列
3238c2ecf20Sopenharmony_ci表(或任何其它邮件列表)交流的一些简单规则,虽然内容有点滥竽充数。
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	http://www.albion.com/netiquette/
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci当有很多人回复你的邮件时,邮件的抄送列表会变得很长。请不要将任何人从抄送
3288c2ecf20Sopenharmony_ci列表中删除,除非你有足够的理由这么做。也不要只回复到邮件列表。请习惯于同
3298c2ecf20Sopenharmony_ci一封邮件接收两次(一封来自发送者一封来自邮件列表),而不要试图通过添加一
3308c2ecf20Sopenharmony_ci些奇特的邮件头来解决这个问题,人们不会喜欢的。
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci记住保留你所回复内容的上下文和源头。在你回复邮件的顶部保留“某某某说到……”
3338c2ecf20Sopenharmony_ci这几行。将你的评论加在被引用的段落之间而不要放在邮件的顶部。
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci如果你在邮件中附带补丁,请确认它们是可以直接阅读的纯文本(如
3368c2ecf20Sopenharmony_ci:ref:`Documentation/translations/zh_CN/process/submitting-patches.rst <cn_submittingpatches>`
3378c2ecf20Sopenharmony_ci文档中所述)。内核开发者们不希望遇到附件或者被压缩了的补丁。只有这样才能
3388c2ecf20Sopenharmony_ci保证他们可以直接评论你的每行代码。请确保你使用的邮件发送程序不会修改空格
3398c2ecf20Sopenharmony_ci和制表符。一个防范性的测试方法是先将邮件发送给自己,然后自己尝试是否可以
3408c2ecf20Sopenharmony_ci顺利地打上收到的补丁。如果测试不成功,请调整或者更换你的邮件发送程序直到
3418c2ecf20Sopenharmony_ci它正确工作为止。
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci总而言之,请尊重其他的邮件列表订阅者。
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci同内核社区合作
3478c2ecf20Sopenharmony_ci----------------
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci内核社区的目标就是提供尽善尽美的内核。所以当你提交补丁期望被接受进内核的
3508c2ecf20Sopenharmony_ci时候,它的技术价值以及其他方面都将被评审。那么你可能会得到什么呢?
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci  - 批评
3538c2ecf20Sopenharmony_ci  - 评论
3548c2ecf20Sopenharmony_ci  - 要求修改
3558c2ecf20Sopenharmony_ci  - 要求证明修改的必要性
3568c2ecf20Sopenharmony_ci  - 沉默
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci要记住,这些是把补丁放进内核的正常情况。你必须学会听取对补丁的批评和评论,
3598c2ecf20Sopenharmony_ci从技术层面评估它们,然后要么重写你的补丁要么简明扼要地论证修改是不必要
3608c2ecf20Sopenharmony_ci的。如果你发的邮件没有得到任何回应,请过几天后再试一次,因为有时信件会湮
3618c2ecf20Sopenharmony_ci没在茫茫信海中。
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci你不应该做的事情:
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci  - 期望自己的补丁不受任何质疑就直接被接受
3668c2ecf20Sopenharmony_ci  - 翻脸
3678c2ecf20Sopenharmony_ci  - 忽略别人的评论
3688c2ecf20Sopenharmony_ci  - 没有按照别人的要求做任何修改就重新提交
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci在一个努力追寻最好技术方案的社区里,对于一个补丁有多少好处总会有不同的见
3718c2ecf20Sopenharmony_ci解。你必须要抱着合作的态度,愿意改变自己的观点来适应内核的风格。或者至少
3728c2ecf20Sopenharmony_ci愿意去证明你的想法是有价值的。记住,犯错误是允许的,只要你愿意朝着正确的
3738c2ecf20Sopenharmony_ci方案去努力。
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci如果你的第一个补丁换来的是一堆修改建议,这是很正常的。这并不代表你的补丁
3768c2ecf20Sopenharmony_ci不会被接受,也不意味着有人和你作对。你只需要改正所有提出的问题然后重新发
3778c2ecf20Sopenharmony_ci送你的补丁。
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci内核社区和公司文化的差异
3808c2ecf20Sopenharmony_ci------------------------
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci内核社区的工作模式同大多数传统公司开发队伍的工作模式并不相同。下面这些例
3838c2ecf20Sopenharmony_ci子,可以帮助你避免某些可能发生问题:
3848c2ecf20Sopenharmony_ci用这些话介绍你的修改提案会有好处:
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci    - 它同时解决了多个问题
3878c2ecf20Sopenharmony_ci    - 它删除了2000行代码
3888c2ecf20Sopenharmony_ci    - 这是补丁,它已经解释了我想要说明的
3898c2ecf20Sopenharmony_ci    - 我在5种不同的体系结构上测试过它……
3908c2ecf20Sopenharmony_ci    - 这是一系列小补丁用来……
3918c2ecf20Sopenharmony_ci    - 这个修改提高了普通机器的性能……
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci应该避免如下的说法:
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci    - 我们在AIX/ptx/Solaris就是这么做的,所以这么做肯定是好的……
3968c2ecf20Sopenharmony_ci    - 我做这行已经20年了,所以……
3978c2ecf20Sopenharmony_ci    - 为了我们公司赚钱考虑必须这么做
3988c2ecf20Sopenharmony_ci    - 这是我们的企业产品线所需要的
3998c2ecf20Sopenharmony_ci    - 这里是描述我观点的1000页设计文档
4008c2ecf20Sopenharmony_ci    - 这是一个5000行的补丁用来……
4018c2ecf20Sopenharmony_ci    - 我重写了现在乱七八糟的代码,这就是……
4028c2ecf20Sopenharmony_ci    - 我被规定了最后期限,所以这个补丁需要立刻被接受
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci另外一个内核社区与大部分传统公司的软件开发队伍不同的地方是无法面对面地交
4058c2ecf20Sopenharmony_ci流。使用电子邮件和IRC聊天工具做为主要沟通工具的一个好处是性别和种族歧视
4068c2ecf20Sopenharmony_ci将会更少。Linux内核的工作环境更能接受妇女和少数族群,因为每个人在别人眼
4078c2ecf20Sopenharmony_ci里只是一个邮件地址。国际化也帮助了公平的实现,因为你无法通过姓名来判断人
4088c2ecf20Sopenharmony_ci的性别。男人有可能叫李丽,女人也有可能叫王刚。大多数在Linux内核上工作过
4098c2ecf20Sopenharmony_ci并表达过看法的女性对在linux上工作的经历都给出了正面的评价。
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci对于一些不习惯使用英语的人来说,语言可能是一个引起问题的障碍。在邮件列表
4128c2ecf20Sopenharmony_ci中要正确地表达想法必需良好地掌握语言,所以建议你在发送邮件之前最好检查一
4138c2ecf20Sopenharmony_ci下英文写得是否正确。
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci拆分修改
4178c2ecf20Sopenharmony_ci--------
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ciLinux内核社区并不喜欢一下接收大段的代码。修改需要被恰当地介绍、讨论并且
4208c2ecf20Sopenharmony_ci拆分成独立的小段。这几乎完全和公司中的习惯背道而驰。你的想法应该在开发最
4218c2ecf20Sopenharmony_ci开始的阶段就让大家知道,这样你就可以及时获得对你正在进行的开发的反馈。这
4228c2ecf20Sopenharmony_ci样也会让社区觉得你是在和他们协作,而不是仅仅把他们当作倾销新功能的对象。
4238c2ecf20Sopenharmony_ci无论如何,你不要一次性地向邮件列表发送50封信,你的补丁序列应该永远用不到
4248c2ecf20Sopenharmony_ci这么多。
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci将补丁拆开的原因如下:
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci1) 小的补丁更有可能被接受,因为它们不需要太多的时间和精力去验证其正确性。
4298c2ecf20Sopenharmony_ci   一个5行的补丁,可能在维护者看了一眼以后就会被接受。而500行的补丁则
4308c2ecf20Sopenharmony_ci   需要数个小时来审查其正确性(所需时间随补丁大小增加大约呈指数级增长)。
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci   当出了问题的时候,小的补丁也会让调试变得非常容易。一个一个补丁地回溯
4338c2ecf20Sopenharmony_ci   将会比仔细剖析一个被打上的大补丁(这个补丁破坏了其他东西)容易得多。
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci2)不光发送小的补丁很重要,在提交之前重新编排、化简(或者仅仅重新排列)
4368c2ecf20Sopenharmony_ci   补丁也是很重要的。
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci这里有内核开发者Al Viro打的一个比方:
4398c2ecf20Sopenharmony_ci	“想象一个老师正在给学生批改数学作业。老师并不希望看到学生为了得
4408c2ecf20Sopenharmony_ci	到正确解法所进行的尝试和产生的错误。他希望看到的是最干净最优雅的
4418c2ecf20Sopenharmony_ci	解答。好学生了解这点,绝不会把最终解决之前的中间方案提交上去。”
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	内核开发也是这样。维护者和评审者不希望看到一个人在解决问题时的思
4448c2ecf20Sopenharmony_ci	考过程。他们只希望看到简单和优雅的解决方案。
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci直接给出一流的解决方案,和社区一起协作讨论尚未完成的工作,这两者之间似乎
4478c2ecf20Sopenharmony_ci很难找到一个平衡点。所以最好尽早开始收集有利于你进行改进的反馈;同时也要
4488c2ecf20Sopenharmony_ci保证修改分成很多小块,这样在整个项目都准备好被包含进内核之前,其中的一部
4498c2ecf20Sopenharmony_ci分可能会先被接收。
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci必须了解这样做是不可接受的:试图将未完成的工作提交进内核,然后再找时间修
4528c2ecf20Sopenharmony_ci复。
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci证明修改的必要性
4568c2ecf20Sopenharmony_ci----------------
4578c2ecf20Sopenharmony_ci除了将补丁拆成小块,很重要的一点是让Linux社区了解他们为什么需要这样修改。
4588c2ecf20Sopenharmony_ci你必须证明新功能是有人需要的并且是有用的。
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci记录修改
4628c2ecf20Sopenharmony_ci--------
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci当你发送补丁的时候,需要特别留意邮件正文的内容。因为这里的信息将会做为补
4658c2ecf20Sopenharmony_ci丁的修改记录(ChangeLog),会被一直保留以备大家查阅。它需要完全地描述补丁,
4668c2ecf20Sopenharmony_ci包括:
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci  - 为什么需要这个修改
4698c2ecf20Sopenharmony_ci  - 补丁的总体设计
4708c2ecf20Sopenharmony_ci  - 实现细节
4718c2ecf20Sopenharmony_ci  - 测试结果
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci想了解它具体应该看起来像什么,请查阅以下文档中的“ChangeLog”章节:
4748c2ecf20Sopenharmony_ci  “The Perfect Patch”
4758c2ecf20Sopenharmony_ci  	 https://www.ozlabs.org/~akpm/stuff/tpp.txt
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci这些事情有时候做起来很难。要在任何方面都做到完美可能需要好几年时间。这是
4798c2ecf20Sopenharmony_ci一个持续提高的过程,它需要大量的耐心和决心。只要不放弃,你一定可以做到。
4808c2ecf20Sopenharmony_ci很多人已经做到了,而他们都曾经和现在的你站在同样的起点上。
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci感谢
4848c2ecf20Sopenharmony_ci----
4858c2ecf20Sopenharmony_ci感谢Paolo Ciarrocchi允许“开发流程”部分基于他所写的文章
4868c2ecf20Sopenharmony_ci(http://www.kerneltravel.net/newbie/2.6-development_process),感谢Randy
4878c2ecf20Sopenharmony_ciDunlap和Gerrit Huizenga完善了应该说和不该说的列表。感谢Pat Mochel, Hanna
4888c2ecf20Sopenharmony_ciLinder, Randy Dunlap, Kay Sievers, Vojtech Pavlik, Jan Kara, Josh Boyer,
4898c2ecf20Sopenharmony_ciKees Cook, Andrew Morton, Andi Kleen, Vadim Lobanov, Jesper Juhl, Adrian
4908c2ecf20Sopenharmony_ciBunk, Keri Harris, Frans Pop, David A. Wheeler, Junio Hamano, Michael
4918c2ecf20Sopenharmony_ciKerrisk和Alex Shepard的评审、建议和贡献。没有他们的帮助,这篇文档是不可
4928c2ecf20Sopenharmony_ci能完成的。
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci英文版维护者: Greg Kroah-Hartman <greg@kroah.com>
497