~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/ceph/cache.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Ceph cache definitions.
  4  *
  5  *  Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
  6  *  Written by Milosz Tanski (milosz@adfin.com)
  7  */
  8 
  9 #include <linux/ceph/ceph_debug.h>
 10 
 11 #include <linux/fs_context.h>
 12 #include "super.h"
 13 #include "cache.h"
 14 
 15 void ceph_fscache_register_inode_cookie(struct inode *inode)
 16 {
 17         struct ceph_inode_info *ci = ceph_inode(inode);
 18         struct ceph_fs_client *fsc = ceph_inode_to_fs_client(inode);
 19 
 20         /* No caching for filesystem? */
 21         if (!fsc->fscache)
 22                 return;
 23 
 24         /* Regular files only */
 25         if (!S_ISREG(inode->i_mode))
 26                 return;
 27 
 28         /* Only new inodes! */
 29         if (!(inode->i_state & I_NEW))
 30                 return;
 31 
 32         WARN_ON_ONCE(ci->netfs.cache);
 33 
 34         ci->netfs.cache =
 35                 fscache_acquire_cookie(fsc->fscache, 0,
 36                                        &ci->i_vino, sizeof(ci->i_vino),
 37                                        &ci->i_version, sizeof(ci->i_version),
 38                                        i_size_read(inode));
 39         if (ci->netfs.cache)
 40                 mapping_set_release_always(inode->i_mapping);
 41 }
 42 
 43 void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info *ci)
 44 {
 45         fscache_relinquish_cookie(ceph_fscache_cookie(ci), false);
 46 }
 47 
 48 void ceph_fscache_use_cookie(struct inode *inode, bool will_modify)
 49 {
 50         struct ceph_inode_info *ci = ceph_inode(inode);
 51 
 52         fscache_use_cookie(ceph_fscache_cookie(ci), will_modify);
 53 }
 54 
 55 void ceph_fscache_unuse_cookie(struct inode *inode, bool update)
 56 {
 57         struct ceph_inode_info *ci = ceph_inode(inode);
 58 
 59         if (update) {
 60                 loff_t i_size = i_size_read(inode);
 61 
 62                 fscache_unuse_cookie(ceph_fscache_cookie(ci),
 63                                      &ci->i_version, &i_size);
 64         } else {
 65                 fscache_unuse_cookie(ceph_fscache_cookie(ci), NULL, NULL);
 66         }
 67 }
 68 
 69 void ceph_fscache_update(struct inode *inode)
 70 {
 71         struct ceph_inode_info *ci = ceph_inode(inode);
 72         loff_t i_size = i_size_read(inode);
 73 
 74         fscache_update_cookie(ceph_fscache_cookie(ci), &ci->i_version, &i_size);
 75 }
 76 
 77 void ceph_fscache_invalidate(struct inode *inode, bool dio_write)
 78 {
 79         struct ceph_inode_info *ci = ceph_inode(inode);
 80 
 81         fscache_invalidate(ceph_fscache_cookie(ci),
 82                            &ci->i_version, i_size_read(inode),
 83                            dio_write ? FSCACHE_INVAL_DIO_WRITE : 0);
 84 }
 85 
 86 int ceph_fscache_register_fs(struct ceph_fs_client* fsc, struct fs_context *fc)
 87 {
 88         const struct ceph_fsid *fsid = &fsc->client->fsid;
 89         const char *fscache_uniq = fsc->mount_options->fscache_uniq;
 90         size_t uniq_len = fscache_uniq ? strlen(fscache_uniq) : 0;
 91         char *name;
 92         int err = 0;
 93 
 94         name = kasprintf(GFP_KERNEL, "ceph,%pU%s%s", fsid, uniq_len ? "," : "",
 95                          uniq_len ? fscache_uniq : "");
 96         if (!name)
 97                 return -ENOMEM;
 98 
 99         fsc->fscache = fscache_acquire_volume(name, NULL, NULL, 0);
100         if (IS_ERR_OR_NULL(fsc->fscache)) {
101                 errorfc(fc, "Unable to register fscache cookie for %s", name);
102                 err = fsc->fscache ? PTR_ERR(fsc->fscache) : -EOPNOTSUPP;
103                 fsc->fscache = NULL;
104         }
105         kfree(name);
106         return err;
107 }
108 
109 void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc)
110 {
111         fscache_relinquish_volume(fsc->fscache, NULL, false);
112 }
113 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php