Skip to content

Commit 66e9c6a

Browse files
committed
afs: Fix afs_write_end() to handle short writes
Fix afs_write_end() to correctly handle a short copy into the intended write region of the page. Two things are necessary: (1) If the page is not up to date, then we should just return 0 (ie. indicating a zero-length copy). The loop in generic_perform_write() will go around again, possibly breaking up the iterator into discrete chunks[1]. This is analogous to commit b9de313 for ceph. (2) The page should not have been set uptodate if it wasn't completely set up by netfs_write_begin() (this will be fixed in the next patch), so we need to set uptodate here in such a case. Also remove the assertion that was checking that the page was set uptodate since it's now set uptodate if it wasn't already a few lines above. The assertion was from when uptodate was set elsewhere. Changes: v3: Remove the handling of len exceeding the end of the page. Fixes: 3003bbd ("afs: Use the netfs_write_begin() helper") Reported-by: Jeff Layton <[email protected]> Signed-off-by: David Howells <[email protected]> Acked-by: Jeff Layton <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> cc: Al Viro <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/[email protected]/ [1] Link: https://lore.kernel.org/r/162367682522.460125.5652091227576721609.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/162391825688.1173366.3437507255136307904.stgit@warthog.procyon.org.uk/ # v2
1 parent 009c9aa commit 66e9c6a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/afs/write.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ int afs_write_end(struct file *file, struct address_space *mapping,
118118
_enter("{%llx:%llu},{%lx}",
119119
vnode->fid.vid, vnode->fid.vnode, page->index);
120120

121+
if (!PageUptodate(page)) {
122+
if (copied < len) {
123+
copied = 0;
124+
goto out;
125+
}
126+
127+
SetPageUptodate(page);
128+
}
129+
121130
if (copied == 0)
122131
goto out;
123132

@@ -132,8 +141,6 @@ int afs_write_end(struct file *file, struct address_space *mapping,
132141
write_sequnlock(&vnode->cb_lock);
133142
}
134143

135-
ASSERT(PageUptodate(page));
136-
137144
if (PagePrivate(page)) {
138145
priv = page_private(page);
139146
f = afs_page_dirty_from(page, priv);

0 commit comments

Comments
 (0)