Skip to content

Commit 5f24162

Browse files
committed
netfs: Update i_blocks when write committed to pagecache
Update i_blocks when i_size is updated when we finish making a write to the pagecache to reflect the amount of space we think will be consumed. This maintains cifs commit dbfdff4 ("smb3: update allocation size more accurately on write completion") which would otherwise be removed by the cifs part of the netfs writeback rewrite. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> cc: Steve French <sfrench@samba.org> cc: Shyam Prasad N <nspmangalore@gmail.com> cc: Rohith Surabattula <rohiths.msft@gmail.com> cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org
1 parent e67572c commit 5f24162

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

fs/netfs/buffered_write.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,37 @@ static struct folio *netfs_grab_folio_for_write(struct address_space *mapping,
130130
mapping_gfp_mask(mapping));
131131
}
132132

133+
/*
134+
* Update i_size and estimate the update to i_blocks to reflect the additional
135+
* data written into the pagecache until we can find out from the server what
136+
* the values actually are.
137+
*/
138+
static void netfs_update_i_size(struct netfs_inode *ctx, struct inode *inode,
139+
loff_t i_size, loff_t pos, size_t copied)
140+
{
141+
blkcnt_t add;
142+
size_t gap;
143+
144+
if (ctx->ops->update_i_size) {
145+
ctx->ops->update_i_size(inode, pos);
146+
return;
147+
}
148+
149+
i_size_write(inode, pos);
150+
#if IS_ENABLED(CONFIG_FSCACHE)
151+
fscache_update_cookie(ctx->cache, NULL, &pos);
152+
#endif
153+
154+
gap = SECTOR_SIZE - (i_size & (SECTOR_SIZE - 1));
155+
if (copied > gap) {
156+
add = DIV_ROUND_UP(copied - gap, SECTOR_SIZE);
157+
158+
inode->i_blocks = min_t(blkcnt_t,
159+
DIV_ROUND_UP(pos, SECTOR_SIZE),
160+
inode->i_blocks + add);
161+
}
162+
}
163+
133164
/**
134165
* netfs_perform_write - Copy data into the pagecache.
135166
* @iocb: The operation parameters
@@ -351,18 +382,10 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,
351382
trace_netfs_folio(folio, trace);
352383

353384
/* Update the inode size if we moved the EOF marker */
354-
i_size = i_size_read(inode);
355385
pos += copied;
356-
if (pos > i_size) {
357-
if (ctx->ops->update_i_size) {
358-
ctx->ops->update_i_size(inode, pos);
359-
} else {
360-
i_size_write(inode, pos);
361-
#if IS_ENABLED(CONFIG_FSCACHE)
362-
fscache_update_cookie(ctx->cache, NULL, &pos);
363-
#endif
364-
}
365-
}
386+
i_size = i_size_read(inode);
387+
if (pos > i_size)
388+
netfs_update_i_size(ctx, inode, i_size, pos, copied);
366389
written += copied;
367390

368391
if (likely(!wreq)) {

0 commit comments

Comments
 (0)