[Devel] [PATCH rh7 10/38] ploop: reverse order of fdatawait and fsync fop

Andrey Smetanin asmetanin at virtuozzo.com
Fri May 15 09:48:11 PDT 2015


dio_fsync_thread must call filemap_fdatawrite() before file->f_op->fsync().
Otherwise:

  8,0    6       82     0.003095587 12328  D  WS 441706496 + 512 [ploop19054]
  8,0    6       83     0.003103726 12328  D  WS 441707008 + 512 [ploop19054]
  8,0    6       84     0.003108627 12328  D  WS 441707520 + 512 [ploop19054]
  8,0    6       85     0.003113176 12328  D  WS 441708032 + 512 [ploop19054]
  ...
  8,0    6      102     0.003149386  1299  D  WS 3950526248 + 24 [jbd2/dm-1-8]
  ...
  8,0    6      103     0.003305550     0  C  WS 441706496 + 512 [0]
  8,0    6      104     0.003458057     0  C  WS 441707008 + 512 [0]
  8,0    6      105     0.003608325     0  C  WS 441707520 + 512 [0]
  8,0    6      106     0.003758297     0  C  WS 441708032 + 512 [0]
  8,0    6      107     0.003794543     0  C  WS 3950526248 + 24 [0]

And if the node crashes (or reboot happens) after last dispatch, journal data
may come to the disk while user bulk data -- not. The result would be ploop
image corruption.

The patch re-arranges the sequence of calls to make it safe and natural (the
same way as in vfs_fsync_range()).

Signed-off-by: Maxim Patlasov <MPatlasov at parallels.com>
---
 drivers/block/ploop/io_direct.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index babc940..c18d2f0 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -735,14 +735,13 @@ static int dio_fsync_thread(void * data)
 		spin_unlock_irq(&plo->lock);
 
 		/* filemap_fdatawrite() has been made already */
+		filemap_fdatawait(io->files.mapping);
 
 		err = 0;
 		if (io->files.file->f_op->fsync)
 			err = io->files.file->f_op->FOP_FSYNC(io->files.file,
 							      0);
 
-		filemap_fdatawait(io->files.mapping);
-
 		/* Do we need to invalidate page cache? Not really,
 		 * because we use it only to create full new pages,
 		 * which we overwrite completely. Probably, we should
-- 
1.9.3




More information about the Devel mailing list