Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: work around copy_file_range() cephfs bug #3123

Closed
wants to merge 2 commits into from

Conversation

bnoordhuis
Copy link
Member

Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from
command when it shouldn't. Fall back to a regular file copy.

Fixes: #3117
Refs: torvalds/linux@6f9718f

cc @kakaroto - can you confirm that it fixes the issue you're seeing?

Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from
command when it shouldn't. Fall back to a regular file copy.

Fixes: libuv#3117
Refs: torvalds/linux@6f9718f
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

src/unix/fs.c Outdated
Comment on lines 909 to 922
static unsigned uv__kernel_version(void) {
struct utsname u;
unsigned major;
unsigned minor;
unsigned patch;

if (-1 == uname(&u))
return 0;

if (3 != sscanf(u.release, "%u.%u.%u", &major, &minor, &patch))
return 0;

return major * 65536 + minor * 256 + patch;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense caching the kernel version in a static variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can hurt - updated.

@@ -926,6 +974,9 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) {
/* ENOSYS - it will never work */
errno = 0;
copy_file_range_support = 0;
} else if (r == -1 && errno == EACCES && uv__is_buggy_cephfs(in_fd)) {
errno = 0;
copy_file_range_support = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a small aside: these should use uv__store_relaxed() rather than assign directly. I'll do that in a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a PR to use those functions in #3124. Will update it again once this gets landed. :)

@RaisinTen
Copy link
Contributor

@bnoordhuis Another issue has been reported at nodejs/node#37763 that seems to involve the same bug except, this time it's not cephfs.

@vtjnash
Copy link
Member

vtjnash commented Mar 18, 2021

Might be useful to be aware of the various copy_file_range bugs described in https://lwn.net/Articles/846403/ and comments about them (however, that is about as far as my knowledge goes on this, so I may not be of any further help).

@bnoordhuis
Copy link
Member Author

@RaisinTen What file system was the reporter using?

@kakaroto
Copy link

@RaisinTen What file system was the reporter using?

They don't seem to mention it in the nodejs bug report, but when I was testing to report my own experience with cephfs, I tested with NFS to see if I could reproduce the bug on it and I could, so I think NFS has a similar issue with the copy_file_range use.

@RaisinTen
Copy link
Contributor

@RaisinTen What file system was the reporter using?

cc @joeheyming

@bnoordhuis
Copy link
Member Author

various copy_file_range bugs described in https://lwn.net/Articles/846403/

I'm aware of the issues with procfs and I'm not too surprised nfs is affected.

Probably the best course of action is to switch to an allowlist of known-good file systems: btrfs, cephfs, ext4, jfs, xfs - any others?

santigimeno pushed a commit to santigimeno/libuv that referenced this pull request Apr 4, 2021
Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from
command when it shouldn't. Fall back to a regular file copy.

Fixes: libuv#3117
Refs: torvalds/linux@6f9718f
PR-URL: libuv#3123
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
@santigimeno
Copy link
Member

@santigimeno
Copy link
Member

Landed in 9737baf. Thanks!

@santigimeno santigimeno closed this Apr 4, 2021
@bnoordhuis bnoordhuis deleted the fix3117 branch October 9, 2021 23:08
JeffroMF pushed a commit to JeffroMF/libuv that referenced this pull request May 16, 2022
Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from
command when it shouldn't. Fall back to a regular file copy.

Fixes: libuv#3117
Refs: torvalds/linux@6f9718f
PR-URL: libuv#3123
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs.copyFile fails with permission denied when source is read-only
6 participants