Commit d928e8f3 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gfs2-v5.18-rc4-fix3' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull gfs2 fixes from Andreas Gruenbacher:
 "We've finally identified commit dc732906 ("gfs2: Introduce flag
  for glock holder auto-demotion") to be the other cause of the
  filesystem corruption we've been seeing. This feature isn't strictly
  necessary anymore, so we've decided to stop using it for now.

  With this and the gfs_iomap_end rounding fix you've already seen
  ("gfs2: Fix filesystem block deallocation for short writes" in this
  pull request), we're corruption free again now.

   - Fix filesystem block deallocation for short writes.

   - Stop using glock holder auto-demotion for now.

   - Get rid of buffered writes inefficiencies due to page faults being
     disabled.

   - Minor other cleanups"

* tag 'gfs2-v5.18-rc4-fix3' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2:
  gfs2: Stop using glock holder auto-demotion for now
  gfs2: buffered write prefaulting
  gfs2: Align read and write chunks to the page cache
  gfs2: Pull return value test out of should_fault_in_pages
  gfs2: Clean up use of fault_in_iov_iter_{read,write}able
  gfs2: Variable rename
  gfs2: Fix filesystem block deallocation for short writes
parents f2dd0074 e1fa9ea8
...@@ -1153,13 +1153,12 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length, ...@@ -1153,13 +1153,12 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
if (length != written && (iomap->flags & IOMAP_F_NEW)) { if (length != written && (iomap->flags & IOMAP_F_NEW)) {
/* Deallocate blocks that were just allocated. */ /* Deallocate blocks that were just allocated. */
loff_t blockmask = i_blocksize(inode) - 1; loff_t hstart = round_up(pos + written, i_blocksize(inode));
loff_t end = (pos + length) & ~blockmask; loff_t hend = iomap->offset + iomap->length;
pos = (pos + written + blockmask) & ~blockmask; if (hstart < hend) {
if (pos < end) { truncate_pagecache_range(inode, hstart, hend - 1);
truncate_pagecache_range(inode, pos, end - 1); punch_hole(ip, hstart, hend - hstart);
punch_hole(ip, pos, end - pos);
} }
} }
......
...@@ -770,30 +770,27 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end, ...@@ -770,30 +770,27 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
return ret ? ret : ret1; return ret ? ret : ret1;
} }
static inline bool should_fault_in_pages(ssize_t ret, struct iov_iter *i, static inline bool should_fault_in_pages(struct iov_iter *i,
struct kiocb *iocb,
size_t *prev_count, size_t *prev_count,
size_t *window_size) size_t *window_size)
{ {
size_t count = iov_iter_count(i); size_t count = iov_iter_count(i);
size_t size, offs; size_t size, offs;
if (likely(!count)) if (!count)
return false;
if (ret <= 0 && ret != -EFAULT)
return false; return false;
if (!iter_is_iovec(i)) if (!iter_is_iovec(i))
return false; return false;
size = PAGE_SIZE; size = PAGE_SIZE;
offs = offset_in_page(i->iov[0].iov_base + i->iov_offset); offs = offset_in_page(iocb->ki_pos);
if (*prev_count != count || !*window_size) { if (*prev_count != count || !*window_size) {
size_t nr_dirtied; size_t nr_dirtied;
size = ALIGN(offs + count, PAGE_SIZE);
size = min_t(size_t, size, SZ_1M);
nr_dirtied = max(current->nr_dirtied_pause - nr_dirtied = max(current->nr_dirtied_pause -
current->nr_dirtied, 8); current->nr_dirtied, 8);
size = min(size, nr_dirtied << PAGE_SHIFT); size = min_t(size_t, SZ_1M, nr_dirtied << PAGE_SHIFT);
} }
*prev_count = count; *prev_count = count;
...@@ -807,7 +804,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to, ...@@ -807,7 +804,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
size_t prev_count = 0, window_size = 0; size_t prev_count = 0, window_size = 0;
size_t written = 0; size_t read = 0;
ssize_t ret; ssize_t ret;
/* /*
...@@ -835,35 +832,31 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to, ...@@ -835,35 +832,31 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
ret = gfs2_glock_nq(gh); ret = gfs2_glock_nq(gh);
if (ret) if (ret)
goto out_uninit; goto out_uninit;
retry_under_glock:
pagefault_disable(); pagefault_disable();
to->nofault = true; to->nofault = true;
ret = iomap_dio_rw(iocb, to, &gfs2_iomap_ops, NULL, ret = iomap_dio_rw(iocb, to, &gfs2_iomap_ops, NULL,
IOMAP_DIO_PARTIAL, written); IOMAP_DIO_PARTIAL, read);
to->nofault = false; to->nofault = false;
pagefault_enable(); pagefault_enable();
if (ret <= 0 && ret != -EFAULT)
goto out_unlock;
if (ret > 0) if (ret > 0)
written = ret; read = ret;
if (should_fault_in_pages(ret, to, &prev_count, &window_size)) {
size_t leftover;
gfs2_holder_allow_demote(gh); if (should_fault_in_pages(to, iocb, &prev_count, &window_size)) {
leftover = fault_in_iov_iter_writeable(to, window_size); gfs2_glock_dq(gh);
gfs2_holder_disallow_demote(gh); window_size -= fault_in_iov_iter_writeable(to, window_size);
if (leftover != window_size) { if (window_size)
if (gfs2_holder_queued(gh))
goto retry_under_glock;
goto retry; goto retry;
}
} }
out_unlock:
if (gfs2_holder_queued(gh)) if (gfs2_holder_queued(gh))
gfs2_glock_dq(gh); gfs2_glock_dq(gh);
out_uninit: out_uninit:
gfs2_holder_uninit(gh); gfs2_holder_uninit(gh);
if (ret < 0) if (ret < 0)
return ret; return ret;
return written; return read;
} }
static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
...@@ -873,7 +866,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, ...@@ -873,7 +866,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
struct inode *inode = file->f_mapping->host; struct inode *inode = file->f_mapping->host;
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
size_t prev_count = 0, window_size = 0; size_t prev_count = 0, window_size = 0;
size_t read = 0; size_t written = 0;
ssize_t ret; ssize_t ret;
/* /*
...@@ -901,39 +894,35 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from, ...@@ -901,39 +894,35 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
goto out_uninit; goto out_uninit;
/* Silently fall back to buffered I/O when writing beyond EOF */ /* Silently fall back to buffered I/O when writing beyond EOF */
if (iocb->ki_pos + iov_iter_count(from) > i_size_read(&ip->i_inode)) if (iocb->ki_pos + iov_iter_count(from) > i_size_read(&ip->i_inode))
goto out; goto out_unlock;
retry_under_glock:
from->nofault = true; from->nofault = true;
ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL, ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL,
IOMAP_DIO_PARTIAL, read); IOMAP_DIO_PARTIAL, written);
from->nofault = false; from->nofault = false;
if (ret <= 0) {
if (ret == -ENOTBLK) if (ret == -ENOTBLK)
ret = 0; ret = 0;
if (ret != -EFAULT)
goto out_unlock;
}
if (ret > 0) if (ret > 0)
read = ret; written = ret;
if (should_fault_in_pages(ret, from, &prev_count, &window_size)) {
size_t leftover;
gfs2_holder_allow_demote(gh); if (should_fault_in_pages(from, iocb, &prev_count, &window_size)) {
leftover = fault_in_iov_iter_readable(from, window_size); gfs2_glock_dq(gh);
gfs2_holder_disallow_demote(gh); window_size -= fault_in_iov_iter_readable(from, window_size);
if (leftover != window_size) { if (window_size)
if (gfs2_holder_queued(gh))
goto retry_under_glock;
goto retry; goto retry;
}
} }
out: out_unlock:
if (gfs2_holder_queued(gh)) if (gfs2_holder_queued(gh))
gfs2_glock_dq(gh); gfs2_glock_dq(gh);
out_uninit: out_uninit:
gfs2_holder_uninit(gh); gfs2_holder_uninit(gh);
if (ret < 0) if (ret < 0)
return ret; return ret;
return read; return written;
} }
static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
...@@ -941,7 +930,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) ...@@ -941,7 +930,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
struct gfs2_inode *ip; struct gfs2_inode *ip;
struct gfs2_holder gh; struct gfs2_holder gh;
size_t prev_count = 0, window_size = 0; size_t prev_count = 0, window_size = 0;
size_t written = 0; size_t read = 0;
ssize_t ret; ssize_t ret;
/* /*
...@@ -962,7 +951,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) ...@@ -962,7 +951,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (ret >= 0) { if (ret >= 0) {
if (!iov_iter_count(to)) if (!iov_iter_count(to))
return ret; return ret;
written = ret; read = ret;
} else if (ret != -EFAULT) { } else if (ret != -EFAULT) {
if (ret != -EAGAIN) if (ret != -EAGAIN)
return ret; return ret;
...@@ -975,30 +964,26 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) ...@@ -975,30 +964,26 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
ret = gfs2_glock_nq(&gh); ret = gfs2_glock_nq(&gh);
if (ret) if (ret)
goto out_uninit; goto out_uninit;
retry_under_glock:
pagefault_disable(); pagefault_disable();
ret = generic_file_read_iter(iocb, to); ret = generic_file_read_iter(iocb, to);
pagefault_enable(); pagefault_enable();
if (ret <= 0 && ret != -EFAULT)
goto out_unlock;
if (ret > 0) if (ret > 0)
written += ret; read += ret;
if (should_fault_in_pages(ret, to, &prev_count, &window_size)) {
size_t leftover;
gfs2_holder_allow_demote(&gh); if (should_fault_in_pages(to, iocb, &prev_count, &window_size)) {
leftover = fault_in_iov_iter_writeable(to, window_size); gfs2_glock_dq(&gh);
gfs2_holder_disallow_demote(&gh); window_size -= fault_in_iov_iter_writeable(to, window_size);
if (leftover != window_size) { if (window_size)
if (gfs2_holder_queued(&gh))
goto retry_under_glock;
goto retry; goto retry;
}
} }
out_unlock:
if (gfs2_holder_queued(&gh)) if (gfs2_holder_queued(&gh))
gfs2_glock_dq(&gh); gfs2_glock_dq(&gh);
out_uninit: out_uninit:
gfs2_holder_uninit(&gh); gfs2_holder_uninit(&gh);
return written ? written : ret; return read ? read : ret;
} }
static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
...@@ -1012,7 +997,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, ...@@ -1012,7 +997,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
struct gfs2_holder *statfs_gh = NULL; struct gfs2_holder *statfs_gh = NULL;
size_t prev_count = 0, window_size = 0; size_t prev_count = 0, window_size = 0;
size_t orig_count = iov_iter_count(from); size_t orig_count = iov_iter_count(from);
size_t read = 0; size_t written = 0;
ssize_t ret; ssize_t ret;
/* /*
...@@ -1030,10 +1015,18 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, ...@@ -1030,10 +1015,18 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, gh); gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, gh);
retry: retry:
if (should_fault_in_pages(from, iocb, &prev_count, &window_size)) {
window_size -= fault_in_iov_iter_readable(from, window_size);
if (!window_size) {
ret = -EFAULT;
goto out_uninit;
}
from->count = min(from->count, window_size);
}
ret = gfs2_glock_nq(gh); ret = gfs2_glock_nq(gh);
if (ret) if (ret)
goto out_uninit; goto out_uninit;
retry_under_glock:
if (inode == sdp->sd_rindex) { if (inode == sdp->sd_rindex) {
struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
...@@ -1050,25 +1043,19 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, ...@@ -1050,25 +1043,19 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
current->backing_dev_info = NULL; current->backing_dev_info = NULL;
if (ret > 0) { if (ret > 0) {
iocb->ki_pos += ret; iocb->ki_pos += ret;
read += ret; written += ret;
} }
if (inode == sdp->sd_rindex) if (inode == sdp->sd_rindex)
gfs2_glock_dq_uninit(statfs_gh); gfs2_glock_dq_uninit(statfs_gh);
from->count = orig_count - read; if (ret <= 0 && ret != -EFAULT)
if (should_fault_in_pages(ret, from, &prev_count, &window_size)) { goto out_unlock;
size_t leftover;
from->count = orig_count - written;
gfs2_holder_allow_demote(gh); if (should_fault_in_pages(from, iocb, &prev_count, &window_size)) {
leftover = fault_in_iov_iter_readable(from, window_size); gfs2_glock_dq(gh);
gfs2_holder_disallow_demote(gh); goto retry;
if (leftover != window_size) {
from->count = min(from->count, window_size - leftover);
if (gfs2_holder_queued(gh))
goto retry_under_glock;
goto retry;
}
} }
out_unlock: out_unlock:
if (gfs2_holder_queued(gh)) if (gfs2_holder_queued(gh))
...@@ -1077,8 +1064,8 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, ...@@ -1077,8 +1064,8 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
gfs2_holder_uninit(gh); gfs2_holder_uninit(gh);
if (statfs_gh) if (statfs_gh)
kfree(statfs_gh); kfree(statfs_gh);
from->count = orig_count - read; from->count = orig_count - written;
return read ? read : ret; return written ? written : ret;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment