Skip to contentSkip to conversation

Pre-pull patch posting (merge window)

PATCH New Bob Peterson 1 participant 7 messages Nov 9, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Pre-pull patch posting (merge window)

Hi,

Here is a list of patches we've accumulated for GFS2 for the current upstream merge window. I added one more patch regarding a serious block size problem. There are only six patches this time:

1. A cleanup patch from Andreas to remove the gl_spin #define in favor of its value for the sake of clarity.
2. A fix from Andy Price to mark the inode dirty during fallocate.
3. A fix from Andy Price to set s_mode on mount failures to prevent a stack trace.
4. A patch from me to prevent a kernel BUG() in trans_add_meta/trans_add_data due to uninitialized storage.
5. A patch from me to protecting our freeing of the in-core directory hash table to prevent double-free.
6. A fix for a page/block rounding problem that resulted in a metadata coherency problem when the block size != page size.

I've got a lot more patches in various stages of review and testing, but I'm afraid they'll have to wait until the next merge window. So next time we're likely to have a lot more.

Regards,

Bob Peterson
Red Hat File Systems

----------------------------------------------------------------

Andreas Gruenbacher (1):
gfs2: Remove gl_spin define

Andrew Price (2):
GFS2: fallocate: do not rely on file_update_time to mark the inode
dirty
GFS2: Set s_mode before parsing mount options

Bob Peterson (3):
gfs2: Add missing else in trans_add_meta/data
GFS2: Protect freeing directory hash table with i_lock spin_lock
GFS2: Fix rgrp end rounding problem for bsize < page size

 Documentation/filesystems/gfs2-glocks.txt |  6 +--
 fs/gfs2/dir.c                             |  7 ++-
 fs/gfs2/file.c                            |  2 +-
 fs/gfs2/glock.c                           | 84 +++++++++++++++----------------
 fs/gfs2/glock.h                           |  4 +-
 fs/gfs2/glops.c                           | 10 ++--
 fs/gfs2/incore.h                          |  3 +-
 fs/gfs2/main.c                            |  2 +-
 fs/gfs2/ops_fstype.c                      |  4 +-
 fs/gfs2/rgrp.c                            |  9 ++--
 fs/gfs2/trans.c                           |  4 ++
 11 files changed, 73 insertions(+), 62 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/6 GFS2: fallocate: do not rely on file_update_time to mark the inode dirty

From: Andrew Price <[email protected]>

Previously __gfs2_fallocate() relied on file_update_time() marking the inode dirty, but that's not a safe assumption as that function doesn't dirty the inode in some cases. Mark the inode dirty explicitly.

---
 fs/gfs2/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/file.c +1 -1
index cf4ab89..71cd138 100644
@@ -897,8 +897,8 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
 
 	if (!(mode & FALLOC_FL_KEEP_SIZE) && (pos + count) > inode->i_size) {
 		i_size_write(inode, pos + count);
-		/* Marks the inode as dirty */
 		file_update_time(file);
+		mark_inode_dirty(inode);
 	}
 
 	return generic_write_sync(file, pos, count);
Signature · 1 line
2.4.3
#2 lore raw

PATCH v2 2/6 GFS2: Set s_mode before parsing mount options

In reply to Bob Peterson

From: Andrew Price <[email protected]>

In the generic mount_bdev() function, deactivate_locked_super() is called after the fill_super() call fails, at which point s_mode has been set. kill_block_super() expects this and dumps a warning when FMODE_EXCL is not set in s_mode.

In gfs2_mount() we call deactivate_locked_super() on failure of gfs2_mount_args(), at which point s_mode has not yet been set. This causes kill_block_super() to dump a stack trace when gfs2 fails to mount with invalid options. Set s_mode earlier in gfs2_mount() to avoid that.

---
 fs/gfs2/ops_fstype.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/ops_fstype.c +3 -1
index 02586e7..baab99b 100644
@@ -1291,6 +1291,9 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
 		up_write(&s->s_umount);
 		blkdev_put(bdev, mode);
 		down_write(&s->s_umount);
+	} else {
+		/* s_mode must be set before deactivate_locked_super calls */
+		s->s_mode = mode;
 	}
 
 	memset(&args, 0, sizeof(args));
@@ -1314,7 +1317,6 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
 	} else {
 		char b[BDEVNAME_SIZE];
 
-		s->s_mode = mode;
 		strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
 		sb_set_blocksize(s, block_size(bdev));
 		error = fill_super(s, &args, flags & MS_SILENT ? 1 : 0);
Signature · 1 line
2.4.3
#3 lore raw

PATCH v2 3/6 gfs2: Add missing else in trans_add_meta/data

In reply to Bob Peterson

This patch fixes a timing window that causes a segfault. The problem is that bd can remain NULL throughout the function and then reference that NULL pointer if the bh->b_private starts out NULL, then someone sets it to non-NULL inside the locking. In that case, bd still needs to be set.

---
 fs/gfs2/trans.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/gfs2/trans.c +4 -0
index b95d0d6..0c1bde3 100644
@@ -176,6 +176,8 @@ void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh)
 		unlock_buffer(bh);
 		if (bh->b_private == NULL)
 			bd = gfs2_alloc_bufdata(gl, bh, &gfs2_databuf_lops);
+		else
+			bd = bh->b_private;
 		lock_buffer(bh);
 		gfs2_log_lock(sdp);
 	}
@@ -236,6 +238,8 @@ void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh)
 		lock_page(bh->b_page);
 		if (bh->b_private == NULL)
 			bd = gfs2_alloc_bufdata(gl, bh, &gfs2_buf_lops);
+		else
+			bd = bh->b_private;
 		unlock_page(bh->b_page);
 		lock_buffer(bh);
 		gfs2_log_lock(sdp);
Signature · 1 line
2.4.3
#4 lore raw

PATCH v2 4/6 gfs2: Remove gl_spin define

In reply to Bob Peterson

From: Andreas Gruenbacher <[email protected]>

Commit e66cf161 replaced the gl_spin spinlock in struct gfs2_glock with a gl_lockref lockref and defined gl_spin as gl_lockref.lock (the spinlock in gl_lockref). Remove that define to make the references to gl_lockref.lock more obvious.

---
 Documentation/filesystems/gfs2-glocks.txt |  6 +--
 fs/gfs2/glock.c                           | 84 +++++++++++++++----------------
 fs/gfs2/glock.h                           |  4 +-
 fs/gfs2/glops.c                           | 10 ++--
 fs/gfs2/incore.h                          |  3 +-
 fs/gfs2/main.c                            |  2 +-
 fs/gfs2/rgrp.c                            |  4 +-
 7 files changed, 56 insertions(+), 57 deletions(-)
Documentation/filesystems/gfs2-glocks.txt +3 -3
index fcc7995..1fb12f9 100644
@@ -5,7 +5,7 @@ This documents the basic principles of the glock state machine
 internals. Each glock (struct gfs2_glock in fs/gfs2/incore.h)
 has two main (internal) locks:
 
- 1. A spinlock (gl_spin) which protects the internal state such
+ 1. A spinlock (gl_lockref.lock) which protects the internal state such
     as gl_state, gl_target and the list of holders (gl_holders)
  2. A non-blocking bit lock, GLF_LOCK, which is used to prevent other
     threads from making calls to the DLM, etc. at the same time. If a
@@ -82,8 +82,8 @@ rather than via the glock.
 
 Locking rules for glock operations:
 
-Operation     |  GLF_LOCK bit lock held |  gl_spin spinlock held
------------------------------------------------------------------
+Operation     |  GLF_LOCK bit lock held |  gl_lockref.lock spinlock held
+-------------------------------------------------------------------------
 go_xmote_th   |       Yes               |       No
 go_xmote_bh   |       Yes               |       No
 go_inval      |       Yes               |       No
fs/gfs2/glock.c +42 -42

275 lines not on this page · raw message

fs/gfs2/glock.h +2 -2
index 32572f7..f7cdaa8 100644
@@ -141,7 +141,7 @@ static inline struct gfs2_holder *gfs2_glock_is_locked_by_me(struct gfs2_glock *
 	struct pid *pid;
 
 	/* Look in glock's list of holders for one with current task as owner */
-	spin_lock(&gl->gl_spin);
+	spin_lock(&gl->gl_lockref.lock);
 	pid = task_pid(current);
 	list_for_each_entry(gh, &gl->gl_holders, gh_list) {
 		if (!test_bit(HIF_HOLDER, &gh->gh_iflags))
@@ -151,7 +151,7 @@ static inline struct gfs2_holder *gfs2_glock_is_locked_by_me(struct gfs2_glock *
 	}
 	gh = NULL;
 out:
-	spin_unlock(&gl->gl_spin);
+	spin_unlock(&gl->gl_lockref.lock);
 
 	return gh;
 }
fs/gfs2/glops.c +5 -5
index 1f6c9c3..f348cfb 100644
@@ -146,11 +146,11 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
 	struct gfs2_rgrpd *rgd;
 	int error;
 
-	spin_lock(&gl->gl_spin);
+	spin_lock(&gl->gl_lockref.lock);
 	rgd = gl->gl_object;
 	if (rgd)
 		gfs2_rgrp_brelse(rgd);
-	spin_unlock(&gl->gl_spin);
+	spin_unlock(&gl->gl_lockref.lock);
 
 	if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
 		return;
@@ -162,11 +162,11 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
 	mapping_set_error(mapping, error);
 	gfs2_ail_empty_gl(gl);
 
-	spin_lock(&gl->gl_spin);
+	spin_lock(&gl->gl_lockref.lock);
 	rgd = gl->gl_object;
 	if (rgd)
 		gfs2_free_clones(rgd);
-	spin_unlock(&gl->gl_spin);
+	spin_unlock(&gl->gl_lockref.lock);
 }
 
 /**
@@ -542,7 +542,7 @@ static int freeze_go_demote_ok(const struct gfs2_glock *gl)
  * iopen_go_callback - schedule the dcache entry for the inode to be deleted
  * @gl: the glock
  *
- * gl_spin lock is held while calling this
+ * gl_lockref.lock lock is held while calling this
  */
 static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
 {
fs/gfs2/incore.h +1 -2
index 121ed08..de7b4f9 100644
@@ -334,9 +334,8 @@ struct gfs2_glock {
 	struct lm_lockname gl_name;
 
 	struct lockref gl_lockref;
-#define gl_spin gl_lockref.lock
 
-	/* State fields protected by gl_spin */
+	/* State fields protected by gl_lockref.lock */
 	unsigned int gl_state:2,	/* Current state */
 		     gl_target:2,	/* Target state */
 		     gl_demote_state:2,	/* State requested by remote node */
fs/gfs2/main.c +1 -1
index 241a399..fb2b42c 100644
@@ -50,7 +50,7 @@ static void gfs2_init_glock_once(void *foo)
 	struct gfs2_glock *gl = foo;
 
 	INIT_HLIST_BL_NODE(&gl->gl_list);
-	spin_lock_init(&gl->gl_spin);
+	spin_lock_init(&gl->gl_lockref.lock);
 	INIT_LIST_HEAD(&gl->gl_holders);
 	INIT_LIST_HEAD(&gl->gl_lru);
 	INIT_LIST_HEAD(&gl->gl_ail_list);
fs/gfs2/rgrp.c +2 -2
index 475985d..d29dd0c 100644
@@ -729,9 +729,9 @@ void gfs2_clear_rgrpd(struct gfs2_sbd *sdp)
 		rb_erase(n, &sdp->sd_rindex_tree);
 
 		if (gl) {
-			spin_lock(&gl->gl_spin);
+			spin_lock(&gl->gl_lockref.lock);
 			gl->gl_object = NULL;
-			spin_unlock(&gl->gl_spin);
+			spin_unlock(&gl->gl_lockref.lock);
 			gfs2_glock_add_to_lru(gl);
 			gfs2_glock_put(gl);
 		}
Signature · 1 line
2.4.3
#5 lore raw

PATCH v2 5/6 GFS2: Protect freeing directory hash table with i_lock spin_lock

In reply to Bob Peterson

This patch changes function gfs2_dir_hash_inval so it uses the i_lock spin_lock to protect the in-core hash table, i_hash_cache. This will prevent double-frees due to a race between gfs2_evict_inode and inode invalidation.

---
 fs/gfs2/dir.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/gfs2/dir.c +6 -1
index 487527b..ad8a5b7 100644
@@ -388,8 +388,13 @@ static __be64 *gfs2_dir_get_hash_table(struct gfs2_inode *ip)
  */
 void gfs2_dir_hash_inval(struct gfs2_inode *ip)
 {
-	__be64 *hc = ip->i_hash_cache;
+	__be64 *hc;
+
+	spin_lock(&ip->i_inode.i_lock);
+	hc = ip->i_hash_cache;
 	ip->i_hash_cache = NULL;
+	spin_unlock(&ip->i_inode.i_lock);
+
 	kvfree(hc);
 }
 
Signature · 1 line
2.4.3
#6 lore raw

PATCH v2 6/6 GFS2: Fix rgrp end rounding problem for bsize < page size

In reply to Bob Peterson

This patch fixes a bug introduced by commit 7005c3e. That patch tries to map a vm range for resource groups, but the calculation breaks down when the block size is less than the page size.

---
 fs/gfs2/rgrp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/gfs2/rgrp.c +3 -2
index d29dd0c..c134c04 100644
@@ -933,8 +933,9 @@ static int read_rindex_entry(struct gfs2_inode *ip)
 		goto fail;
 
 	rgd->rd_gl->gl_object = rgd;
-	rgd->rd_gl->gl_vm.start = rgd->rd_addr * bsize;
-	rgd->rd_gl->gl_vm.end = rgd->rd_gl->gl_vm.start + (rgd->rd_length * bsize) - 1;
+	rgd->rd_gl->gl_vm.start = (rgd->rd_addr * bsize) & PAGE_CACHE_MASK;
+	rgd->rd_gl->gl_vm.end = PAGE_CACHE_ALIGN((rgd->rd_addr +
+						  rgd->rd_length) * bsize) - 1;
 	rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr;
 	rgd->rd_flags &= ~(GFS2_RDF_UPTODATE | GFS2_RDF_PREFERRED);
 	if (rgd->rd_data > sdp->sd_max_rg_data)
Signature · 1 line
2.4.3