Skip to content

Commit 70431bf

Browse files
dhowellsSteve French
authored andcommitted
cifs: Support fscache indexing rewrite
Change the cifs filesystem to take account of the changes to fscache's indexing rewrite and reenable caching in cifs. The following changes have been made: (1) The fscache_netfs struct is no more, and there's no need to register the filesystem as a whole. (2) The session cookie is now an fscache_volume cookie, allocated with fscache_acquire_volume(). That takes three parameters: a string representing the "volume" in the index, a string naming the cache to use (or NULL) and a u64 that conveys coherency metadata for the volume. For cifs, I've made it render the volume name string as: "cifs,<ipaddress>,<sharename>" where the sharename has '/' characters replaced with ';'. This probably needs rethinking a bit as the total name could exceed the maximum filename component length. Further, the coherency data is currently just set to 0. It needs something else doing with it - I wonder if it would suffice simply to sum the resource_id, vol_create_time and vol_serial_number or maybe hash them. (3) The fscache_cookie_def is no more and needed information is passed directly to fscache_acquire_cookie(). The cache no longer calls back into the filesystem, but rather metadata changes are indicated at other times. fscache_acquire_cookie() is passed the same keying and coherency information as before. (4) The functions to set/reset cookies are removed and fscache_use_cookie() and fscache_unuse_cookie() are used instead. fscache_use_cookie() is passed a flag to indicate if the cookie is opened for writing. fscache_unuse_cookie() is passed updates for the metadata if we changed it (ie. if the file was opened for writing). These are called when the file is opened or closed. (5) cifs_setattr_*() are made to call fscache_resize() to change the size of the cache object. (6) The functions to read and write data are stubbed out pending a conversion to use netfslib. Changes ======= ver #8: - Abstract cache invalidation into a helper function. - Fix some checkpatch warnings[3]. ver #7: - Removed the accidentally added-back call to get the super cookie in cifs_root_iget(). - Fixed the right call to cifs_fscache_get_super_cookie() to take account of the "-o fsc" mount flag. ver #6: - Moved the change of gfpflags_allow_blocking() to current_is_kswapd() for cifs here. - Fixed one of the error paths in cifs_atomic_open() to jump around the call to use the cookie. - Fixed an additional successful return in the middle of cifs_open() to use the cookie on the way out. - Only get a volume cookie (and thus inode cookies) when "-o fsc" is supplied to mount. ver #5: - Fixed a couple of bits of cookie handling[2]: - The cookie should be released in cifs_evict_inode(), not cifsFileInfo_put_final(). The cookie needs to persist beyond file closure so that writepages will be able to write to it. - fscache_use_cookie() needs to be called in cifs_atomic_open() as it is for cifs_open(). ver #4: - Fixed the use of sizeof with memset. - tcon->vol_create_time is __le64 so doesn't need cpu_to_le64(). ver #3: - Canonicalise the cifs coherency data to make the cache portable. - Set volume coherency data. ver #2: - Use gfpflags_allow_blocking() rather than using flag directly. - Upgraded to -rc4 to allow for upstream changes[1]. - fscache_acquire_volume() now returns errors. Signed-off-by: David Howells <[email protected]> Acked-by: Jeff Layton <[email protected]> cc: Steve French <[email protected]> cc: Shyam Prasad N <[email protected]> cc: [email protected] cc: [email protected] Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=23b55d673d7527b093cd97b7c217c82e70cd1af0 [1] Link: https://lore.kernel.org/r/[email protected]/ [2] Link: https://lore.kernel.org/r/CAH2r5muTanw9pJqzAHd01d9A8keeChkzGsCEH6=0rHutVLAF-A@mail.gmail.com/ [3] Link: https://lore.kernel.org/r/163819671009.215744.11230627184193298714.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906982979.143852.10672081929614953210.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967187187.1823006.247415138444991444.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021579335.640689.2681324337038770579.stgit@warthog.procyon.org.uk/ # v4 Link: https://lore.kernel.org/r/[email protected]/ # v5 Link: https://lore.kernel.org/r/[email protected]/ # v6 Signed-off-by: Steve French <[email protected]>
1 parent ba978e8 commit 70431bf

File tree

11 files changed

+199
-500
lines changed

11 files changed

+199
-500
lines changed

fs/cifs/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ config CIFS_SMB_DIRECT
188188

189189
config CIFS_FSCACHE
190190
bool "Provide CIFS client caching support"
191-
depends on CIFS=m && FSCACHE_OLD_API || CIFS=y && FSCACHE_OLD_API=y
191+
depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y
192192
help
193193
Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data
194194
to be cached locally on disk through the general filesystem cache

fs/cifs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cifs-$(CONFIG_CIFS_DFS_UPCALL) += cifs_dfs_ref.o dfs_cache.o
2525

2626
cifs-$(CONFIG_CIFS_SWN_UPCALL) += netlink.o cifs_swn.o
2727

28-
cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o
28+
cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o
2929

3030
cifs-$(CONFIG_CIFS_SMB_DIRECT) += smbdirect.o
3131

fs/cifs/cache.c

Lines changed: 0 additions & 105 deletions
This file was deleted.

fs/cifs/cifsfs.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ static void
397397
cifs_evict_inode(struct inode *inode)
398398
{
399399
truncate_inode_pages_final(&inode->i_data);
400+
if (inode->i_state & I_PINNING_FSCACHE_WB)
401+
cifs_fscache_unuse_inode_cookie(inode, true);
402+
cifs_fscache_release_inode_cookie(inode);
400403
clear_inode(inode);
401404
}
402405

@@ -721,6 +724,12 @@ static int cifs_show_stats(struct seq_file *s, struct dentry *root)
721724
}
722725
#endif
723726

727+
static int cifs_write_inode(struct inode *inode, struct writeback_control *wbc)
728+
{
729+
fscache_unpin_writeback(wbc, cifs_inode_cookie(inode));
730+
return 0;
731+
}
732+
724733
static int cifs_drop_inode(struct inode *inode)
725734
{
726735
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
@@ -733,6 +742,7 @@ static int cifs_drop_inode(struct inode *inode)
733742
static const struct super_operations cifs_super_ops = {
734743
.statfs = cifs_statfs,
735744
.alloc_inode = cifs_alloc_inode,
745+
.write_inode = cifs_write_inode,
736746
.free_inode = cifs_free_inode,
737747
.drop_inode = cifs_drop_inode,
738748
.evict_inode = cifs_evict_inode,
@@ -1625,13 +1635,9 @@ init_cifs(void)
16251635
goto out_destroy_cifsoplockd_wq;
16261636
}
16271637

1628-
rc = cifs_fscache_register();
1629-
if (rc)
1630-
goto out_destroy_deferredclose_wq;
1631-
16321638
rc = cifs_init_inodecache();
16331639
if (rc)
1634-
goto out_unreg_fscache;
1640+
goto out_destroy_deferredclose_wq;
16351641

16361642
rc = cifs_init_mids();
16371643
if (rc)
@@ -1693,8 +1699,6 @@ init_cifs(void)
16931699
cifs_destroy_mids();
16941700
out_destroy_inodecache:
16951701
cifs_destroy_inodecache();
1696-
out_unreg_fscache:
1697-
cifs_fscache_unregister();
16981702
out_destroy_deferredclose_wq:
16991703
destroy_workqueue(deferredclose_wq);
17001704
out_destroy_cifsoplockd_wq:
@@ -1730,7 +1734,6 @@ exit_cifs(void)
17301734
cifs_destroy_request_bufs();
17311735
cifs_destroy_mids();
17321736
cifs_destroy_inodecache();
1733-
cifs_fscache_unregister();
17341737
destroy_workqueue(deferredclose_wq);
17351738
destroy_workqueue(cifsoplockd_wq);
17361739
destroy_workqueue(decrypt_wq);

fs/cifs/cifsglob.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,6 @@ struct TCP_Server_Info {
668668
unsigned int total_read; /* total amount of data read in this pass */
669669
atomic_t in_send; /* requests trying to send */
670670
atomic_t num_waiters; /* blocked waiting to get in sendrecv */
671-
#ifdef CONFIG_CIFS_FSCACHE
672-
struct fscache_cookie *fscache; /* client index cache cookie */
673-
#endif
674671
#ifdef CONFIG_CIFS_STATS2
675672
atomic_t num_cmds[NUMBER_OF_SMB2_COMMANDS]; /* total requests by cmd */
676673
atomic_t smb2slowcmd[NUMBER_OF_SMB2_COMMANDS]; /* count resps > 1 sec */
@@ -1112,7 +1109,7 @@ struct cifs_tcon {
11121109
__u32 max_bytes_copy;
11131110
#ifdef CONFIG_CIFS_FSCACHE
11141111
u64 resource_id; /* server resource id */
1115-
struct fscache_cookie *fscache; /* cookie for share */
1112+
struct fscache_volume *fscache; /* cookie for share */
11161113
#endif
11171114
struct list_head pending_opens; /* list of incomplete opens */
11181115
struct cached_fid crfid; /* Cached root fid */

fs/cifs/connect.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,10 +1444,6 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
14441444

14451445
cifs_crypto_secmech_release(server);
14461446

1447-
/* fscache server cookies are based on primary channel only */
1448-
if (!CIFS_SERVER_IS_CHAN(server))
1449-
cifs_fscache_release_client_cookie(server);
1450-
14511447
kfree(server->session_key.response);
14521448
server->session_key.response = NULL;
14531449
server->session_key.len = 0;
@@ -1609,14 +1605,6 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
16091605
list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list);
16101606
spin_unlock(&cifs_tcp_ses_lock);
16111607

1612-
/* fscache server cookies are based on primary channel only */
1613-
if (!CIFS_SERVER_IS_CHAN(tcp_ses))
1614-
cifs_fscache_get_client_cookie(tcp_ses);
1615-
#ifdef CONFIG_CIFS_FSCACHE
1616-
else
1617-
tcp_ses->fscache = tcp_ses->primary_server->fscache;
1618-
#endif /* CONFIG_CIFS_FSCACHE */
1619-
16201608
/* queue echo request delayed work */
16211609
queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval);
16221610

@@ -3128,7 +3116,8 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx)
31283116
* Inside cifs_fscache_get_super_cookie it checks
31293117
* that we do not get super cookie twice.
31303118
*/
3131-
cifs_fscache_get_super_cookie(tcon);
3119+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
3120+
cifs_fscache_get_super_cookie(tcon);
31323121

31333122
out:
31343123
mnt_ctx->server = server;

fs/cifs/dir.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "cifs_unicode.h"
2323
#include "fs_context.h"
2424
#include "cifs_ioctl.h"
25+
#include "fscache.h"
2526

2627
static void
2728
renew_parental_timestamps(struct dentry *direntry)
@@ -507,8 +508,12 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
507508
server->ops->close(xid, tcon, &fid);
508509
cifs_del_pending_open(&open);
509510
rc = -ENOMEM;
511+
goto out;
510512
}
511513

514+
fscache_use_cookie(cifs_inode_cookie(file_inode(file)),
515+
file->f_mode & FMODE_WRITE);
516+
512517
out:
513518
cifs_put_tlink(tlink);
514519
out_free_xid:

0 commit comments

Comments
 (0)