18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* Filesystem index definition 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved. 58c2ecf20Sopenharmony_ci * Written by David Howells (dhowells@redhat.com) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#define FSCACHE_DEBUG_LEVEL CACHE 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include "internal.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistatic 138c2ecf20Sopenharmony_cienum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data, 148c2ecf20Sopenharmony_ci const void *data, 158c2ecf20Sopenharmony_ci uint16_t datalen, 168c2ecf20Sopenharmony_ci loff_t object_size); 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* 198c2ecf20Sopenharmony_ci * The root index is owned by FS-Cache itself. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * When a netfs requests caching facilities, FS-Cache will, if one doesn't 228c2ecf20Sopenharmony_ci * already exist, create an entry in the root index with the key being the name 238c2ecf20Sopenharmony_ci * of the netfs ("AFS" for example), and the auxiliary data holding the index 248c2ecf20Sopenharmony_ci * structure version supplied by the netfs: 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * FSDEF 278c2ecf20Sopenharmony_ci * | 288c2ecf20Sopenharmony_ci * +-----------+ 298c2ecf20Sopenharmony_ci * | | 308c2ecf20Sopenharmony_ci * NFS AFS 318c2ecf20Sopenharmony_ci * [v=1] [v=1] 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci * If an entry with the appropriate name does already exist, the version is 348c2ecf20Sopenharmony_ci * compared. If the version is different, the entire subtree from that entry 358c2ecf20Sopenharmony_ci * will be discarded and a new entry created. 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * The new entry will be an index, and a cookie referring to it will be passed 388c2ecf20Sopenharmony_ci * to the netfs. This is then the root handle by which the netfs accesses the 398c2ecf20Sopenharmony_ci * cache. It can create whatever objects it likes in that index, including 408c2ecf20Sopenharmony_ci * further indices. 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_cistatic struct fscache_cookie_def fscache_fsdef_index_def = { 438c2ecf20Sopenharmony_ci .name = ".FS-Cache", 448c2ecf20Sopenharmony_ci .type = FSCACHE_COOKIE_TYPE_INDEX, 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistruct fscache_cookie fscache_fsdef_index = { 488c2ecf20Sopenharmony_ci .usage = ATOMIC_INIT(1), 498c2ecf20Sopenharmony_ci .n_active = ATOMIC_INIT(1), 508c2ecf20Sopenharmony_ci .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock), 518c2ecf20Sopenharmony_ci .backing_objects = HLIST_HEAD_INIT, 528c2ecf20Sopenharmony_ci .def = &fscache_fsdef_index_def, 538c2ecf20Sopenharmony_ci .flags = 1 << FSCACHE_COOKIE_ENABLED, 548c2ecf20Sopenharmony_ci .type = FSCACHE_COOKIE_TYPE_INDEX, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ciEXPORT_SYMBOL(fscache_fsdef_index); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * Definition of an entry in the root index. Each entry is an index, keyed to 608c2ecf20Sopenharmony_ci * a specific netfs and only applicable to a particular version of the index 618c2ecf20Sopenharmony_ci * structure used by that netfs. 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_cistruct fscache_cookie_def fscache_fsdef_netfs_def = { 648c2ecf20Sopenharmony_ci .name = "FSDEF.netfs", 658c2ecf20Sopenharmony_ci .type = FSCACHE_COOKIE_TYPE_INDEX, 668c2ecf20Sopenharmony_ci .check_aux = fscache_fsdef_netfs_check_aux, 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* 708c2ecf20Sopenharmony_ci * check that the index structure version number stored in the auxiliary data 718c2ecf20Sopenharmony_ci * matches the one the netfs gave us 728c2ecf20Sopenharmony_ci */ 738c2ecf20Sopenharmony_cistatic enum fscache_checkaux fscache_fsdef_netfs_check_aux( 748c2ecf20Sopenharmony_ci void *cookie_netfs_data, 758c2ecf20Sopenharmony_ci const void *data, 768c2ecf20Sopenharmony_ci uint16_t datalen, 778c2ecf20Sopenharmony_ci loff_t object_size) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci struct fscache_netfs *netfs = cookie_netfs_data; 808c2ecf20Sopenharmony_ci uint32_t version; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci _enter("{%s},,%hu", netfs->name, datalen); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci if (datalen != sizeof(version)) { 858c2ecf20Sopenharmony_ci _leave(" = OBSOLETE [dl=%d v=%zu]", datalen, sizeof(version)); 868c2ecf20Sopenharmony_ci return FSCACHE_CHECKAUX_OBSOLETE; 878c2ecf20Sopenharmony_ci } 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci memcpy(&version, data, sizeof(version)); 908c2ecf20Sopenharmony_ci if (version != netfs->version) { 918c2ecf20Sopenharmony_ci _leave(" = OBSOLETE [ver=%x net=%x]", version, netfs->version); 928c2ecf20Sopenharmony_ci return FSCACHE_CHECKAUX_OBSOLETE; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci _leave(" = OKAY"); 968c2ecf20Sopenharmony_ci return FSCACHE_CHECKAUX_OKAY; 978c2ecf20Sopenharmony_ci} 98