cregit-Linux how code gets into the kernel

Release 4.18 fs/ceph/cache.c

Directory: fs/ceph
/*
 * Ceph cache definitions.
 *
 *  Copyright (C) 2013 by Adfin Solutions, Inc. All Rights Reserved.
 *  Written by Milosz Tanski (milosz@adfin.com)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to:
 *  Free Software Foundation
 *  51 Franklin Street, Fifth Floor
 *  Boston, MA  02111-1301  USA
 *
 */

#include "super.h"
#include "cache.h"


struct ceph_aux_inode {
	
u64 		version;
	
struct timespec	mtime;
};


struct fscache_netfs ceph_cache_netfs = {
	.name		= "ceph",
	.version	= 0,
};

static DEFINE_MUTEX(ceph_fscache_lock);
static LIST_HEAD(ceph_fscache_list);


struct ceph_fscache_entry {
	
struct list_head list;
	
struct fscache_cookie *fscache;
	
size_t uniq_len;
	/* The following members must be last */
	
struct ceph_fsid fsid;
	
char uniquifier[0];
};


static const struct fscache_cookie_def ceph_fscache_fsid_object_def = {
	.name		= "CEPH.fsid",
	.type		= FSCACHE_COOKIE_TYPE_INDEX,
};


int __init ceph_fscache_register(void) { return fscache_register_netfs(&ceph_cache_netfs); }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski1493.33%266.67%
Chengguang Xu16.67%133.33%
Total15100.00%3100.00%


void ceph_fscache_unregister(void) { fscache_unregister_netfs(&ceph_cache_netfs); }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski13100.00%2100.00%
Total13100.00%2100.00%


int ceph_fscache_register_fs(struct ceph_fs_client* fsc) { const struct ceph_fsid *fsid = &fsc->client->fsid; const char *fscache_uniq = fsc->mount_options->fscache_uniq; size_t uniq_len = fscache_uniq ? strlen(fscache_uniq) : 0; struct ceph_fscache_entry *ent; int err = 0; mutex_lock(&ceph_fscache_lock); list_for_each_entry(ent, &ceph_fscache_list, list) { if (memcmp(&ent->fsid, fsid, sizeof(*fsid))) continue; if (ent->uniq_len != uniq_len) continue; if (uniq_len && memcmp(ent->uniquifier, fscache_uniq, uniq_len)) continue; pr_err("fscache cookie already registered for fsid %pU\n", fsid); pr_err(" use fsc=%%s mount option to specify a uniquifier\n"); err = -EBUSY; goto out_unlock; } ent = kzalloc(sizeof(*ent) + uniq_len, GFP_KERNEL); if (!ent) { err = -ENOMEM; goto out_unlock; } memcpy(&ent->fsid, fsid, sizeof(*fsid)); if (uniq_len > 0) { memcpy(&ent->uniquifier, fscache_uniq, uniq_len); ent->uniq_len = uniq_len; } fsc->fscache = fscache_acquire_cookie(ceph_cache_netfs.primary_index, &ceph_fscache_fsid_object_def, &ent->fsid, sizeof(ent->fsid) + uniq_len, NULL, 0, fsc, 0, true); if (fsc->fscache) { ent->fscache = fsc->fscache; list_add_tail(&ent->list, &ceph_fscache_list); } else { kfree(ent); pr_err("unable to register fscache cookie for fsid %pU\n", fsid); /* all other fs ignore this error */ } out_unlock: mutex_unlock(&ceph_fscache_lock); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Yan, Zheng23879.33%125.00%
David Howells4515.00%250.00%
Milosz Tanski175.67%125.00%
Total300100.00%4100.00%


static enum fscache_checkaux ceph_fscache_inode_check_aux( void *cookie_netfs_data, const void *data, uint16_t dlen, loff_t object_size) { struct ceph_aux_inode aux; struct ceph_inode_info* ci = cookie_netfs_data; struct inode* inode = &ci->vfs_inode; if (dlen != sizeof(aux) || i_size_read(inode) != object_size) return FSCACHE_CHECKAUX_OBSOLETE; memset(&aux, 0, sizeof(aux)); aux.version = ci->i_version; aux.mtime = timespec64_to_timespec(inode->i_mtime); if (memcmp(data, &aux, sizeof(aux)) != 0) return FSCACHE_CHECKAUX_OBSOLETE; dout("ceph inode 0x%p cached okay\n", ci); return FSCACHE_CHECKAUX_OKAY; }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski10282.26%120.00%
David Howells108.06%120.00%
Yan, Zheng86.45%120.00%
Deepa Dinamani32.42%120.00%
Chengguang Xu10.81%120.00%
Total124100.00%5100.00%

static const struct fscache_cookie_def ceph_fscache_inode_object_def = { .name = "CEPH.inode", .type = FSCACHE_COOKIE_TYPE_DATAFILE, .check_aux = ceph_fscache_inode_check_aux, };
void ceph_fscache_register_inode_cookie(struct inode *inode) { struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_aux_inode aux; /* No caching for filesystem */ if (!fsc->fscache) return; /* Only cache for regular files that are read only */ if (!S_ISREG(inode->i_mode)) return; inode_lock_nested(inode, I_MUTEX_CHILD); if (!ci->fscache) { memset(&aux, 0, sizeof(aux)); aux.version = ci->i_version; aux.mtime = timespec64_to_timespec(inode->i_mtime); ci->fscache = fscache_acquire_cookie(fsc->fscache, &ceph_fscache_inode_object_def, &ci->i_vino, sizeof(ci->i_vino), &aux, sizeof(aux), ci, i_size_read(inode), false); } inode_unlock(inode); }

Contributors

PersonTokensPropCommitsCommitProp
David Howells5939.07%337.50%
Milosz Tanski5939.07%112.50%
Yan, Zheng2818.54%112.50%
Deepa Dinamani31.99%112.50%
Al Viro10.66%112.50%
SF Markus Elfring10.66%112.50%
Total151100.00%8100.00%


void ceph_fscache_unregister_inode_cookie(struct ceph_inode_info* ci) { struct fscache_cookie* cookie; if ((cookie = ci->fscache) == NULL) return; ci->fscache = NULL; fscache_uncache_all_inode_pages(cookie, &ci->vfs_inode); fscache_relinquish_cookie(cookie, &ci->i_vino, false); }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski5089.29%150.00%
David Howells610.71%150.00%
Total56100.00%2100.00%


static bool ceph_fscache_can_enable(void *data) { struct inode *inode = data; return !inode_is_open_for_write(inode); }

Contributors

PersonTokensPropCommitsCommitProp
Yan, Zheng24100.00%1100.00%
Total24100.00%1100.00%


void ceph_fscache_file_set_cookie(struct inode *inode, struct file *filp) { struct ceph_inode_info *ci = ceph_inode(inode); if (!fscache_cookie_valid(ci->fscache)) return; if (inode_is_open_for_write(inode)) { dout("fscache_file_set_cookie %p %p disabling cache\n", inode, filp); fscache_disable_cookie(ci->fscache, &ci->i_vino, false); fscache_uncache_all_inode_pages(ci->fscache, inode); } else { fscache_enable_cookie(ci->fscache, &ci->i_vino, i_size_read(inode), ceph_fscache_can_enable, inode); if (fscache_cookie_enabled(ci->fscache)) { dout("fscache_file_set_cookie %p %p enabling cache\n", inode, filp); } } }

Contributors

PersonTokensPropCommitsCommitProp
Yan, Zheng10586.78%125.00%
David Howells1512.40%250.00%
Colin Ian King10.83%125.00%
Total121100.00%4100.00%


static void ceph_readpage_from_fscache_complete(struct page *page, void *data, int error) { if (!error) SetPageUptodate(page); unlock_page(page); }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski3296.97%150.00%
Yan, Zheng13.03%150.00%
Total33100.00%2100.00%


static inline bool cache_valid(struct ceph_inode_info *ci) { return ci->i_fscache_gen == ci->i_rdcache_gen; }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski2095.24%150.00%
Zhang Zhuoyu14.76%150.00%
Total21100.00%2100.00%

/* Atempt to read from the fscache, * * This function is called from the readpage_nounlock context. DO NOT attempt to * unlock the page here (or in the callback). */
int ceph_readpage_from_fscache(struct inode *inode, struct page *page) { struct ceph_inode_info *ci = ceph_inode(inode); int ret; if (!cache_valid(ci)) return -ENOBUFS; ret = fscache_read_or_alloc_page(ci->fscache, page, ceph_readpage_from_fscache_complete, NULL, GFP_KERNEL); switch (ret) { case 0: /* Page found */ dout("page read submitted\n"); return 0; case -ENOBUFS: /* Pages were not found, and can't be */ case -ENODATA: /* Pages were not found */ dout("page/inode not in cache\n"); return ret; default: dout("%s: unknown error ret = %i\n", __func__, ret); return ret; } }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski10599.06%150.00%
Yan, Zheng10.94%150.00%
Total106100.00%2100.00%


int ceph_readpages_from_fscache(struct inode *inode, struct address_space *mapping, struct list_head *pages, unsigned *nr_pages) { struct ceph_inode_info *ci = ceph_inode(inode); int ret; if (!cache_valid(ci)) return -ENOBUFS; ret = fscache_read_or_alloc_pages(ci->fscache, mapping, pages, nr_pages, ceph_readpage_from_fscache_complete, NULL, mapping_gfp_mask(mapping)); switch (ret) { case 0: /* All pages found */ dout("all-page read submitted\n"); return 0; case -ENOBUFS: /* Some pages were not found, and can't be */ case -ENODATA: /* some pages were not found */ dout("page/inode not in cache\n"); return ret; default: dout("%s: unknown error ret = %i\n", __func__, ret); return ret; } }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski12199.18%150.00%
Yan, Zheng10.82%150.00%
Total122100.00%2100.00%


void ceph_readpage_to_fscache(struct inode *inode, struct page *page) { struct ceph_inode_info *ci = ceph_inode(inode); int ret; if (!PageFsCache(page)) return; if (!cache_valid(ci)) return; ret = fscache_write_page(ci->fscache, page, i_size_read(inode), GFP_KERNEL); if (ret) fscache_uncache_page(ci->fscache, page); }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski7293.51%266.67%
David Howells56.49%133.33%
Total77100.00%3100.00%


void ceph_invalidate_fscache_page(struct inode* inode, struct page *page) { struct ceph_inode_info *ci = ceph_inode(inode); if (!PageFsCache(page)) return; fscache_wait_on_page_write(ci->fscache, page); fscache_uncache_page(ci->fscache, page); }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski52100.00%2100.00%
Total52100.00%2100.00%


void ceph_fscache_unregister_fs(struct ceph_fs_client* fsc) { if (fscache_cookie_valid(fsc->fscache)) { struct ceph_fscache_entry *ent; bool found = false; mutex_lock(&ceph_fscache_lock); list_for_each_entry(ent, &ceph_fscache_list, list) { if (ent->fscache == fsc->fscache) { list_del(&ent->list); kfree(ent); found = true; break; } } WARN_ON_ONCE(!found); mutex_unlock(&ceph_fscache_lock); __fscache_relinquish_cookie(fsc->fscache, NULL, false); } fsc->fscache = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Yan, Zheng8075.47%133.33%
Milosz Tanski2321.70%133.33%
David Howells32.83%133.33%
Total106100.00%3100.00%

/* * caller should hold CEPH_CAP_FILE_{RD,CACHE} */
void ceph_fscache_revalidate_cookie(struct ceph_inode_info *ci) { if (cache_valid(ci)) return; /* resue i_truncate_mutex. There should be no pending * truncate while the caller holds CEPH_CAP_FILE_RD */ mutex_lock(&ci->i_truncate_mutex); if (!cache_valid(ci)) { if (fscache_check_consistency(ci->fscache, &ci->i_vino)) fscache_invalidate(ci->fscache); spin_lock(&ci->i_ceph_lock); ci->i_fscache_gen = ci->i_rdcache_gen; spin_unlock(&ci->i_ceph_lock); } mutex_unlock(&ci->i_truncate_mutex); }

Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski6673.33%133.33%
Yan, Zheng1921.11%133.33%
David Howells55.56%133.33%
Total90100.00%3100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Milosz Tanski82053.63%421.05%
Yan, Zheng54535.64%526.32%
David Howells1529.94%315.79%
Deepa Dinamani60.39%15.26%
Chengguang Xu20.13%210.53%
Colin Ian King10.07%15.26%
Al Viro10.07%15.26%
Zhang Zhuoyu10.07%15.26%
SF Markus Elfring10.07%15.26%
Total1529100.00%19100.00%
Directory: fs/ceph
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.