History

aio: fix freeze protection of aio writes

Currently we dropped freeze protection of aio writes just after IO was submitted. Thus aio write could be in flight while the filesystem was frozen and that could result in unexpected situation like aio completion wanting to convert extent type on frozen filesystem. Testcase from Dmitry triggering this is like: for ((i=0;i<60;i++));do fsfreeze -f /mnt ;sleep 1;fsfreeze -u /mnt;done & fio --bs=4k --ioengine=libaio --iodepth=128 --size=1g --direct=1 \ --runtime=60 --filename=/mnt/file --name=rand-write --rw=randwrite Fix the problem by dropping freeze protection only once IO is completed in aio_complete().

Jan Kara committed 10 years ago

Commit 70fe2f41 parent 89319d32 files · +19 −1Browse files

Unified · Split

2 files
  1. fs/aio.c +18 −1
  2. include/linux/fs.h +1 −0
fs/aio.c+18−1
@@ -1078,6 +1078,17 @@ static void aio_complete(struct kiocb *kiocb, long res, long res2) · 1077 unmodified lines
10781078 unsigned tail, pos, head;
10791079 unsigned long flags;
10801080
1081+ if (kiocb->ki_flags & IOCB_WRITE) {
1082+ struct file *file = kiocb->ki_filp;
1083+
1084+ /*
1085+ * Tell lockdep we inherited freeze protection from submission
1086+ * thread.
1087+ */
1088+ __sb_writers_acquired(file_inode(file)->i_sb, SB_FREEZE_WRITE);
1089+ file_end_write(file);
1090+ }
1091+
10811092 /*
10821093 * Special case handling for sync iocbs:
10831094 * - events go directly into the iocb for fast handling
@@ -1473,9 +1484,15 @@ static ssize_t aio_write(struct kiocb *req, struct iocb *iocb, bool vectored, · 389 unmodified lines
14731484 return ret;
14741485 ret = rw_verify_area(WRITE, file, &req->ki_pos, iov_iter_count(&iter));
14751486 if (!ret) {
1487+ req->ki_flags |= IOCB_WRITE;
14761488 file_start_write(file);
14771489 ret = aio_ret(req, file->f_op->write_iter(req, &iter));
1478− file_end_write(file);
1490+ /*
1491+ * We release freeze protection in aio_complete(). Fool lockdep
1492+ * by telling it the lock got released so that it doesn't
1493+ * complain about held lock when we return to userspace.
1494+ */
1495+ __sb_writers_release(file_inode(file)->i_sb, SB_FREEZE_WRITE);
14791496 }
14801497 kfree(iovec);
14811498 return ret;
include/linux/fs.h+1−0
@@ -321,6 +321,7 @@ struct writeback_control; · 320 unmodified lines
321321 #define IOCB_HIPRI (1 << 3)
322322 #define IOCB_DSYNC (1 << 4)
323323 #define IOCB_SYNC (1 << 5)
324+#define IOCB_WRITE (1 << 6)
324325
325326 struct kiocb {
326327 struct file *ki_filp;