了解并尝试为 fuse 文件系统应用 git 补丁

Understanding and trying to apply git patch for fuse filesystem

我有一个基于熔断器的文件系统,为了改进它我需要实现这个方法 https://lwn.net/Articles/674286/

我知道我应该 git apply < patch >,问题是我不明白应该在哪里应用这个补丁?

补丁试图修改几个文件,例如:

a/fs/fuse/Makefile
a/fs/fuse/dev.c
b/fs/fuse/dev.c
a/fs/fuse/dir.c
b/fs/fuse/dir.c
etc..

我用 locate 命令找不到,也尝试丢失 'a' 和 'b' 前缀,只找到了 makefile。

那是 Linux 内核的补丁。如果您还没有 Linux 内核源代码,则需要从一个克隆开始:

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

然后你需要下载补丁。 请勿 尝试从您的网络浏览器复制并粘贴它。您可以从 https://patchwork.kernel.org/; the patch you referenced appears to be https://patchwork.kernel.org/patch/8182901. Download the mbox version of the patch from here 下载内核补丁,这会将其保存到名为 v5-fuse-Add-support-for-passthrough-read-write.patch 的文件中。然后,您可以在 linux 源目录中通过 运行 git am 命令应用此补丁:

$ cd linux
$ git am /path/to/v5-fuse-Add-support-for-passthrough-read-write.patch

但是看看补丁,它是从 2016 年 2 月开始的,所以它可能不会完全适用于当前版本的内核。 "probably",我的意思是 "it doesn't apply";上面的命令导致:

Applying: fuse: Add support for passthrough read/write
error: patch failed: fs/fuse/Makefile:5
error: fs/fuse/Makefile: patch does not apply
error: patch failed: fs/fuse/file.c:252
error: fs/fuse/file.c: patch does not apply
error: patch failed: fs/fuse/fuse_i.h:531
error: fs/fuse/fuse_i.h: patch does not apply
error: fs/fuse/fuse_passthrough.h: already exists in working directory
error: patch failed: fs/fuse/inode.c:898
error: fs/fuse/inode.c: patch does not apply
error: fs/fuse/passthrough.c: already exists in working directory
error: patch failed: include/uapi/linux/fuse.h:250
error: include/uapi/linux/fuse.h: patch does not apply
Patch failed at 0001 fuse: Add support for passthrough read/write
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

所以我们需要做的是将内核源回滚到 2016 年时的样子。首先,我们需要中止正在进行的 git am 操作:

$ git am --abort

然后将源回滚到 2016 年 2 月 1 日或前后:

$ git checkout $(git rev-list -1 --before=2016-02-02 --first-parent master)

现在补丁应用干净了:

$ git am /path/to/v5-fuse-Add-support-for-passthrough-read-write.patch
Applying: fuse: Add support for passthrough read/write

应用补丁后,您需要编译并安装新的内核和模块,这超出了本答案的范围,但有相当详细的文档记录。

问问自己的问题是,考虑到这个补丁已有一年多的历史并且从未被内核接受,您确定需要它吗?从那时起是否有其他变化可能提供类似的改进?