Skip to contentSkip to conversation

ensure file size is logged on synchronous writes

PATCH In review Lachlan McIlroy 2 participants 2 messages Sep 3, 2007 – Sep 10, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ensure file size is logged on synchronous writes

Synchronous writes currently log inode changes before syncing pages to disk. Since the file size is updated on I/O completion we wont be writing out the updated file size and if we crash the file will have the wrong size. This change moves the logging after the syncing of the pages to ensure we log the correct file size.

Lachlan

xfs/linux-2.6/xfs_lrw.c renamed from xfs/linux-2.6/xfs_lrw.c_1.266 +6 -7
@@ -895,20 +895,19 @@ retry:
 
 	/* Handle various SYNC-type writes */
 	if ((file->f_flags & O_SYNC) || IS_SYNC(inode)) {
-		error = xfs_write_sync_logforce(mp, xip);
-		if (error)
-			goto out_unlock_internal;
-
+		int error2;
 		xfs_rwunlock(xip, locktype);
 		if (need_i_mutex)
 			mutex_unlock(&inode->i_mutex);
-
-		error = sync_page_range(inode, mapping, pos, ret);
+		error2 = sync_page_range(inode, mapping, pos, ret);
 		if (!error)
-			error = -ret;
+			error = error2;
 		if (need_i_mutex)
 			mutex_lock(&inode->i_mutex);
 		xfs_rwlock(xip, locktype);
+		error2 = xfs_write_sync_logforce(mp, xip);
+		if (!error)
+			error = error2;
 	}
 
  out_unlock_internal:
#1 lore raw
Quoted 6 lines · Lachlan McIlroy

Synchronous writes currently log inode changes before syncing pages to disk. Since the file size is updated on I/O completion we wont be writing out the updated file size and if we crash the file will have the wrong size. This change moves the logging after the syncing of the pages to ensure we log the correct file size.

Looks good to me.