orangefs: adjust counting code to recover from 665575cf
authorMike Marshall <hubcap@omnibond.com>
Wed, 14 May 2025 00:17:45 +0000 (20:17 -0400)
committerMike Marshall <hubcap@omnibond.com>
Tue, 20 May 2025 15:07:00 +0000 (11:07 -0400)
A late commit to 6.14-rc7! broke orangefs. 665575cf seems like a
good change, but maybe should have been introduced during the merge
window. This patch adjusts the counting code associated with
writing out pages so that orangefs works in a 665575cf world.

Signed-off-by: Mike Marshall <hubcap@omnibond.com>
fs/orangefs/inode.c

index 5ac743c..08a6f37 100644 (file)
@@ -32,12 +32,13 @@ static int orangefs_writepage_locked(struct folio *folio,
        len = i_size_read(inode);
        if (folio->private) {
                wr = folio->private;
-               WARN_ON(wr->pos >= len);
                off = wr->pos;
-               if (off + wr->len > len)
+               if ((off + wr->len > len) && (off <= len))
                        wlen = len - off;
                else
                        wlen = wr->len;
+               if (wlen == 0)
+                       wlen = wr->len;
        } else {
                WARN_ON(1);
                off = folio_pos(folio);
@@ -46,8 +47,6 @@ static int orangefs_writepage_locked(struct folio *folio,
                if (wlen > len - off)
                        wlen = len - off;
        }
-       /* Should've been handled in orangefs_invalidate_folio. */
-       WARN_ON(off == len || off + wlen > len);
 
        WARN_ON(wlen == 0);
        bvec_set_folio(&bv, folio, wlen, offset_in_folio(folio, off));
@@ -320,6 +319,8 @@ static int orangefs_write_begin(struct file *file,
                        wr->len += len;
                        goto okay;
                } else {
+                       wr->pos = pos;
+                       wr->len = len;
                        ret = orangefs_launder_folio(folio);
                        if (ret)
                                return ret;