-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netfs: Move pinning-for-writeback from fscache to netfs
Move the resource pinning-for-writeback from fscache code to netfslib code. This is used to keep a cache backing object pinned whilst we have dirty pages on the netfs inode in the pagecache such that VM writeback will be able to reach it. Whilst we're at it, switch the parameters of netfs_unpin_writeback() to match ->write_inode() so that it can be used for that directly. Note that this mechanism could be more generically useful than that for network filesystems. Quite often they have to keep around other resources (e.g. authentication tokens or network connections) until the writeback is complete. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org
- Loading branch information
David Howells
committed
Dec 24, 2023
1 parent
7eb5b3e
commit c9c4ff1
Showing
20 changed files
with
124 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ netfs-y := \ | |
io.o \ | ||
iterator.o \ | ||
main.o \ | ||
misc.o \ | ||
objects.o | ||
|
||
netfs-$(CONFIG_NETFS_STATS) += stats.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* Miscellaneous routines. | ||
* | ||
* Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. | ||
* Written by David Howells (dhowells@redhat.com) | ||
*/ | ||
|
||
#include <linux/swap.h> | ||
#include "internal.h" | ||
|
||
/** | ||
* netfs_dirty_folio - Mark folio dirty and pin a cache object for writeback | ||
* @mapping: The mapping the folio belongs to. | ||
* @folio: The folio being dirtied. | ||
* | ||
* Set the dirty flag on a folio and pin an in-use cache object in memory so | ||
* that writeback can later write to it. This is intended to be called from | ||
* the filesystem's ->dirty_folio() method. | ||
* | ||
* Return: true if the dirty flag was set on the folio, false otherwise. | ||
*/ | ||
bool netfs_dirty_folio(struct address_space *mapping, struct folio *folio) | ||
{ | ||
struct inode *inode = mapping->host; | ||
struct netfs_inode *ictx = netfs_inode(inode); | ||
struct fscache_cookie *cookie = netfs_i_cookie(ictx); | ||
bool need_use = false; | ||
|
||
_enter(""); | ||
|
||
if (!filemap_dirty_folio(mapping, folio)) | ||
return false; | ||
if (!fscache_cookie_valid(cookie)) | ||
return true; | ||
|
||
if (!(inode->i_state & I_PINNING_NETFS_WB)) { | ||
spin_lock(&inode->i_lock); | ||
if (!(inode->i_state & I_PINNING_NETFS_WB)) { | ||
inode->i_state |= I_PINNING_NETFS_WB; | ||
need_use = true; | ||
} | ||
spin_unlock(&inode->i_lock); | ||
|
||
if (need_use) | ||
fscache_use_cookie(cookie, true); | ||
} | ||
return true; | ||
} | ||
EXPORT_SYMBOL(netfs_dirty_folio); | ||
|
||
/** | ||
* netfs_unpin_writeback - Unpin writeback resources | ||
* @inode: The inode on which the cookie resides | ||
* @wbc: The writeback control | ||
* | ||
* Unpin the writeback resources pinned by netfs_dirty_folio(). This is | ||
* intended to be called as/by the netfs's ->write_inode() method. | ||
*/ | ||
int netfs_unpin_writeback(struct inode *inode, struct writeback_control *wbc) | ||
{ | ||
struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode)); | ||
|
||
if (wbc->unpinned_netfs_wb) | ||
fscache_unuse_cookie(cookie, NULL, NULL); | ||
return 0; | ||
} | ||
EXPORT_SYMBOL(netfs_unpin_writeback); | ||
|
||
/** | ||
* netfs_clear_inode_writeback - Clear writeback resources pinned by an inode | ||
* @inode: The inode to clean up | ||
* @aux: Auxiliary data to apply to the inode | ||
* | ||
* Clear any writeback resources held by an inode when the inode is evicted. | ||
* This must be called before clear_inode() is called. | ||
*/ | ||
void netfs_clear_inode_writeback(struct inode *inode, const void *aux) | ||
{ | ||
struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode)); | ||
|
||
if (inode->i_state & I_PINNING_NETFS_WB) { | ||
loff_t i_size = i_size_read(inode); | ||
fscache_unuse_cookie(cookie, aux, &i_size); | ||
} | ||
} | ||
EXPORT_SYMBOL(netfs_clear_inode_writeback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.