diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 767d53222f3153ff39f24b3f50d5b53a062f2f65..1eb625fdcb1e6257e001ee002a66184ef239a6a6 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -531,8 +531,19 @@ xfs_submit_ioend( { /* Convert CoW extents to regular */ if (!status && ioend->io_type == XFS_IO_COW) { + /* + * Yuk. This can do memory allocation, but is not a + * transactional operation so everything is done in GFP_KERNEL + * context. That can deadlock, because we hold pages in + * writeback state and GFP_KERNEL allocations can block on them. + * Hence we must operate in nofs conditions here. + */ + unsigned nofs_flag; + + nofs_flag = memalloc_nofs_save(); status = xfs_reflink_convert_cow(XFS_I(ioend->io_inode), ioend->io_offset, ioend->io_size); + memalloc_nofs_restore(nofs_flag); } /* Reserve log space if we might write beyond the on-disk inode size. */ diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 980bc48979e9b47aeb780e233ffbe848ac0957b4..e9c058e3761ca032fbaa10e5952e4d867a00b2b2 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -21,7 +21,6 @@ #include #include #include -#include #include "xfs_format.h" #include "xfs_log_format.h" diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index ae1e66fa3f615c117996f7032d4aad710a1c7223..1631cf4546f268ce27233da6fc2fd2a65aefe59b 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -26,6 +26,7 @@ typedef __u32 xfs_nlink_t; #include #include +#include #include #include #include