Skip to contentSkip to conversation

GFS: Write vfs inode attributes to disk in gfs_inode_write

PATCH Superseded Benjamin Marzinski 2 participants 2 messages Mar 25, 2014 – Mar 26, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 GFS: Write vfs inode attributes to disk in gfs_inode_write

GFS wasn't ever updating mtime during mmaps to a file. This patch makes gfs_write_inode write the vfs inode attributes out to disk, so that they get updated when the mmap data is written back to disk.

---

gfs-kernel/src/gfs/ops_super.c +39 -2
index c111a2e..0d17735 100644
@@ -39,6 +39,7 @@
 #include "super.h"
 #include "sys.h"
 #include "mount.h"
+#include "trans.h"
 
 /**
  * gfs_write_inode - Make sure the inode is stable on the disk
@@ -51,14 +52,50 @@
 static int
 gfs_write_inode(struct inode *inode, int sync)
 {
+	int ret = 0;
 	struct gfs_inode *ip = get_v2ip(inode);
+	struct buffer_head *dibh;
+	struct gfs_holder i_gh;
+	int need_unlock = 0;
+
+	if (!ip)
+		return 0;
 
 	atomic_inc(&ip->i_sbd->sd_ops_super);
 
-	if (ip && sync)
+	if (current->flags & PF_MEMALLOC)
+		goto do_flush;
+
+	if (!gfs_glock_is_locked_by_me(ip->i_gl)) {
+		ret = gfs_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
+		if (ret)
+			goto do_flush;
+		need_unlock = 1;
+	}
+	/* Trans may require:
+	   one dinode block. */
+	ret = gfs_trans_begin(ip->i_sbd, 1, 0);
+	if (ret)
+		goto do_unlock;
+
+	ret = gfs_get_inode_buffer(ip, &dibh);
+	if (ret == 0) {
+		gfs_inode_attr_out(ip);
+		gfs_trans_add_bh(ip->i_gl, dibh);
+		gfs_dinode_out(&ip->i_di, dibh->b_data);
+		brelse(dibh);
+	}
+
+	gfs_trans_end(ip->i_sbd);
+
+do_unlock:
+	if (need_unlock)
+		gfs_glock_dq_uninit(&i_gh);
+do_flush:
+	if (sync)
 		gfs_log_flush_glock(ip->i_gl, 0);
 
-	return 0;
+	return ret;
 }
 
 /**
#1 lore raw

PATCH 1/1 GFS: Write vfs inode attributes to disk in gfs_inode_write

Hi,

Quoted 5 lines · Benjamin Marzinski

GFS wasn't ever updating mtime during mmaps to a file. This patch makes gfs_write_inode write the vfs inode attributes out to disk, so that they get updated when the mmap data is written back to disk.

Looks good to me. ACK,

Steve.

Quoted 67 lines

---

gfs-kernel/src/gfs/ops_super.c +39 -2
index c111a2e..0d17735 100644
@@ -39,6 +39,7 @@
 #include "super.h"
 #include "sys.h"
 #include "mount.h"
+#include "trans.h"
 
 /**
  * gfs_write_inode - Make sure the inode is stable on the disk
@@ -51,14 +52,50 @@
 static int
 gfs_write_inode(struct inode *inode, int sync)
 {
+	int ret = 0;
 	struct gfs_inode *ip = get_v2ip(inode);
+	struct buffer_head *dibh;
+	struct gfs_holder i_gh;
+	int need_unlock = 0;
+
+	if (!ip)
+		return 0;
 
 	atomic_inc(&ip->i_sbd->sd_ops_super);
 
-	if (ip && sync)
+	if (current->flags & PF_MEMALLOC)
+		goto do_flush;
+
+	if (!gfs_glock_is_locked_by_me(ip->i_gl)) {
+		ret = gfs_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
+		if (ret)
+			goto do_flush;
+		need_unlock = 1;
+	}
+	/* Trans may require:
+	   one dinode block. */
+	ret = gfs_trans_begin(ip->i_sbd, 1, 0);
+	if (ret)
+		goto do_unlock;
+
+	ret = gfs_get_inode_buffer(ip, &dibh);
+	if (ret == 0) {
+		gfs_inode_attr_out(ip);
+		gfs_trans_add_bh(ip->i_gl, dibh);
+		gfs_dinode_out(&ip->i_di, dibh->b_data);
+		brelse(dibh);
+	}
+
+	gfs_trans_end(ip->i_sbd);
+
+do_unlock:
+	if (need_unlock)
+		gfs_glock_dq_uninit(&i_gh);
+do_flush:
+	if (sync)
 		gfs_log_flush_glock(ip->i_gl, 0);
 
-	return 0;
+	return ret;
 }
 
 /**