]> Git Repo - linux.git/commit
mm: make sendfile(2) killable
authorJan Kara <[email protected]>
Thu, 22 Oct 2015 20:32:21 +0000 (13:32 -0700)
committerLinus Torvalds <[email protected]>
Fri, 23 Oct 2015 08:55:10 +0000 (17:55 +0900)
commit296291cdd1629c308114504b850dc343eabc2782
tree1d5dad81ebed5a6cc5ccb0d41c9c493894fa8bb8
parent47aee4d8e314384807e98b67ade07f6da476aa75
mm: make sendfile(2) killable

Currently a simple program below issues a sendfile(2) system call which
takes about 62 days to complete in my test KVM instance.

        int fd;
        off_t off = 0;

        fd = open("file", O_RDWR | O_TRUNC | O_SYNC | O_CREAT, 0644);
        ftruncate(fd, 2);
        lseek(fd, 0, SEEK_END);
        sendfile(fd, fd, &off, 0xfffffff);

Now you should not ask kernel to do a stupid stuff like copying 256MB in
2-byte chunks and call fsync(2) after each chunk but if you do, sysadmin
should have a way to stop you.

We actually do have a check for fatal_signal_pending() in
generic_perform_write() which triggers in this path however because we
always succeed in writing something before the check is done, we return
value > 0 from generic_perform_write() and thus the information about
signal gets lost.

Fix the problem by doing the signal check before writing anything.  That
way generic_perform_write() returns -EINTR, the error gets propagated up
and the sendfile loop terminates early.

Signed-off-by: Jan Kara <[email protected]>
Reported-by: Dmitry Vyukov <[email protected]>
Cc: Al Viro <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/filemap.c
This page took 0.053417 seconds and 4 git commands to generate.