gfs2: Only dereference i->iov when iter_is_iovec(i)
Andreas Gruenbacher
maintainerPATCH 1/5 gfs2: Only dereference i->iov when iter_is_iovec(i)
Only dereference i->iov after establishing that i is of type ITER_IOVEC.
--- fs/gfs2/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/gfs2/file.c +3 -3
@@ -773,8 +773,8 @@ static inline bool should_fault_in_pages(ssize_t ret, struct iov_iter *i,size_t *prev_count, size_t *window_size) { - char __user *p = i->iov[0].iov_base + i->iov_offset; size_t count = iov_iter_count(i); +char __user *p;int pages =1 ;if (likely (!count))
@@ -787,14 +787,14 @@ static inline bool should_fault_in_pages(ssize_t ret, struct iov_iter *i,if (*prev_count != count || !*window_size) {int pages, nr_dirtied; - pages =min_t (int,BIO_MAX_VECS , -DIV_ROUND_UP (iov_iter_count (i),PAGE_SIZE )); + pages =min_t (int,BIO_MAX_VECS ,DIV_ROUND_UP (count,PAGE_SIZE )); nr_dirtied =max (current->nr_dirtied_pause - current->nr_dirtied,1 ); pages =min (pages, nr_dirtied); } *prev_count = count; + p = i->iov[0 ].iov_base + i->iov_offset; *window_size = (size_t )PAGE_SIZE * pages -offset_in_page (p);return true; }
Signature · 1 line
2.31.1
Andreas Gruenbacher
maintainerPATCH 2/5 gfs2: Fix atomic bug in gfs2_instantiate
Replace test_bit() + set_bit() with test_and_set_bit() where we need an atomic operation. Use clear_and_wake_up_bit() instead of open coding it.
--- fs/gfs2/glock.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
fs/gfs2/glock.c +2 -6
@@ -496,7 +496,7 @@ int gfs2_instantiate(struct gfs2_holder *gh)* Since we unlock the lockref lock, we set a flag to indicate * instantiate is in progress. */ -if (test_bit (GLF_INSTANTIATE_IN_PROG , &gl->gl_flags)) { +if (test_and_set_bit (GLF_INSTANTIATE_IN_PROG , &gl->gl_flags)) {wait_on_bit (&gl->gl_flags,GLF_INSTANTIATE_IN_PROG ,TASK_UNINTERRUPTIBLE );/*
@@ -509,14 +509,10 @@ int gfs2_instantiate(struct gfs2_holder *gh) goto again; } -set_bit (GLF_INSTANTIATE_IN_PROG , &gl->gl_flags); - ret = glops->go_instantiate (gh);if (!ret)clear_bit (GLF_INSTANTIATE_NEEDED , &gl->gl_flags); -clear_bit (GLF_INSTANTIATE_IN_PROG , &gl->gl_flags); -smp_mb__after_atomic (); -wake_up_bit (&gl->gl_flags,GLF_INSTANTIATE_IN_PROG ); +clear_and_wake_up_bit (GLF_INSTANTIATE_IN_PROG , &gl->gl_flags);return ret; }
Signature · 1 line
2.31.1
Andreas Gruenbacher
maintainerPATCH 3/5 gfs2: release iopen glock early in evict
In reply to Andreas GruenbacherFrom: Bob Peterson <[email protected]>
Before this patch, evict would clear the iopen glock's gl_object after releasing the inode glock. In the meantime, another process could reuse the same block and thus glocks for a new inode. It would lock the inode glock (exclusively), and then the iopen glock (shared). The shared locking mode doesn't provide any ordering against the evict, so by the time the iopen glock is reused, evict may not have gotten to setting gl_object to NULL.
Fix that by releasing the iopen glock before the inode glock in gfs2_evict_inode.
--- fs/gfs2/super.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
fs/gfs2/super.c +7 -7
@@ -1402,13 +1402,6 @@ static void gfs2_evict_inode(struct inode *inode)gfs2_ordered_del_inode (ip);clear_inode (inode);gfs2_dir_hash_inval (ip); -if (ip->i_gl) { -glock_clear_object (ip->i_gl, ip); -wait_on_bit_io (&ip->i_flags,GIF_GLOP_PENDING ,TASK_UNINTERRUPTIBLE ); -gfs2_glock_add_to_lru (ip->i_gl); -gfs2_glock_put_eventually (ip->i_gl); - ip->i_gl =NULL ; - }if (gfs2_holder_initialized (&ip->i_iopen_gh)) {struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
@@ -1421,6 +1414,13 @@ static void gfs2_evict_inode(struct inode *inode)gfs2_holder_uninit (&ip->i_iopen_gh);gfs2_glock_put_eventually (gl); } +if (ip->i_gl) { +glock_clear_object (ip->i_gl, ip); +wait_on_bit_io (&ip->i_flags,GIF_GLOP_PENDING ,TASK_UNINTERRUPTIBLE ); +gfs2_glock_add_to_lru (ip->i_gl); +gfs2_glock_put_eventually (ip->i_gl); + ip->i_gl =NULL ; + } }static struct inode *gfs2_alloc_inode (struct super_block *sb)
Signature · 1 line
2.31.1
Andreas Gruenbacher
maintainerPATCH 4/5 gfs2: Fix length of holes reported at end-of-file
In reply to Andreas GruenbacherFix the length of holes reported at the end of a file: the length is relative to the beginning of the extent, not the seek position which is rounded down to the filesystem block size.
This bug went unnoticed for some time, but is now caught by the following assertion in iomap_iter_done():
WARN_ON_ONCE(iter->iomap.offset + iter->iomap.length <= iter->pos)
--- fs/gfs2/bmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/bmap.c +1 -1
@@ -940,7 +940,7 @@ static int __gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,else if (height == ip->i_height) ret =gfs2_hole_size (inode, lblock, len, mp, iomap);else - iomap->length = size - pos; + iomap->length = size - iomap->offset; }else if (flags &IOMAP_WRITE ) {u64 alloc_size;
Signature · 1 line
2.31.1
Andreas Gruenbacher
maintainerPATCH 5/5 gfs2: Fix "Introduce flag for glock holder auto-demotion"
In reply to Andreas GruenbacherFunction demote_incompat_holders iterates over the list of glock holders with list_for_each_entry, and it then sometimes removes the current holder from the list. This will get the loop stuck; we must use list_for_each_entry_safe instead.
--- fs/gfs2/glock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/gfs2/glock.c +2 -2
@@ -411,14 +411,14 @@ static void do_error(struct gfs2_glock *gl, const int ret)static void demote_incompat_holders (struct gfs2_glock *gl,struct gfs2_holder *new_gh) { -struct gfs2_holder *gh; +struct gfs2_holder *gh, *tmp;/* * Demote incompatible holders before we make ourselves eligible. * (This holder may or may not allow auto-demoting, but we don't want * to demote the new holder before it's even granted.) */ -list_for_each_entry (gh, &gl->gl_holders, gh_list) { +list_for_each_entry_safe (gh, tmp, &gl->gl_holders, gh_list) {/* * Since holders are at the front of the list, we stop when we * find the first non-holder.
Signature · 1 line
2.31.1