Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* General netfs cache on cache files internal defs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #ifdef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define pr_fmt(fmt) "CacheFiles: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fscache-cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/wait_bit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct cachefiles_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct cachefiles_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) extern unsigned cachefiles_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define CACHEFILES_DEBUG_KENTER	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define CACHEFILES_DEBUG_KLEAVE	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define CACHEFILES_DEBUG_KDEBUG	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define cachefiles_gfp (__GFP_RECLAIM | __GFP_NORETRY | __GFP_NOMEMALLOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * node records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct cachefiles_object {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct fscache_object		fscache;	/* fscache handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct cachefiles_lookup_data	*lookup_data;	/* cached lookup data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct dentry			*dentry;	/* the file/dir representing this object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct dentry			*backer;	/* backing file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	loff_t				i_size;		/* object size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	unsigned long			flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define CACHEFILES_OBJECT_ACTIVE	0		/* T if marked active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	atomic_t			usage;		/* object usage count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	uint8_t				type;		/* object type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	uint8_t				new;		/* T if object new */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	spinlock_t			work_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct rb_node			active_node;	/* link in active tree (dentry is key) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) extern struct kmem_cache *cachefiles_object_jar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Cache files cache definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct cachefiles_cache {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct fscache_cache		cache;		/* FS-Cache record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct vfsmount			*mnt;		/* mountpoint holding the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct dentry			*graveyard;	/* directory into which dead objects go */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct file			*cachefilesd;	/* manager daemon handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	const struct cred		*cache_cred;	/* security override for accessing cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct mutex			daemon_mutex;	/* command serialisation mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	wait_queue_head_t		daemon_pollwq;	/* poll waitqueue for daemon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct rb_root			active_nodes;	/* active nodes (can't be culled) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	rwlock_t			active_lock;	/* lock for active_nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	atomic_t			gravecounter;	/* graveyard uniquifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	atomic_t			f_released;	/* number of objects released lately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	atomic_long_t			b_released;	/* number of blocks released lately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned			frun_percent;	/* when to stop culling (% files) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned			fcull_percent;	/* when to start culling (% files) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned			fstop_percent;	/* when to stop allocating (% files) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned			brun_percent;	/* when to stop culling (% blocks) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned			bcull_percent;	/* when to start culling (% blocks) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	unsigned			bstop_percent;	/* when to stop allocating (% blocks) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	unsigned			bsize;		/* cache's block size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	unsigned			bshift;		/* min(ilog2(PAGE_SIZE / bsize), 0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	uint64_t			frun;		/* when to stop culling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	uint64_t			fcull;		/* when to start culling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	uint64_t			fstop;		/* when to stop allocating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	sector_t			brun;		/* when to stop culling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	sector_t			bcull;		/* when to start culling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	sector_t			bstop;		/* when to stop allocating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	unsigned long			flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define CACHEFILES_READY		0	/* T if cache prepared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define CACHEFILES_DEAD			1	/* T if cache dead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define CACHEFILES_CULLING		2	/* T if cull engaged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define CACHEFILES_STATE_CHANGED	3	/* T if state changed (poll trigger) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	char				*rootdirname;	/* name of cache root directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	char				*secctx;	/* LSM security context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	char				*tag;		/* cache binding tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * backing file read tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) struct cachefiles_one_read {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	wait_queue_entry_t			monitor;	/* link into monitored waitqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct page			*back_page;	/* backing file page we're waiting for */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct page			*netfs_page;	/* netfs page we're going to fill */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct fscache_retrieval	*op;		/* retrieval op covering this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct list_head		op_link;	/* link in op's todo list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * backing file write tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct cachefiles_one_write {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct page			*netfs_page;	/* netfs page to copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct cachefiles_object	*object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct list_head		obj_link;	/* link in object's lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	fscache_rw_complete_t		end_io_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	void				*context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * auxiliary data xattr buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct cachefiles_xattr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	uint16_t			len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	uint8_t				type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	uint8_t				data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #include <trace/events/cachefiles.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * note change of state for daemon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static inline void cachefiles_state_changed(struct cachefiles_cache *cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	set_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	wake_up_all(&cache->daemon_pollwq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * bind.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) extern int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) extern void cachefiles_daemon_unbind(struct cachefiles_cache *cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * daemon.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) extern const struct file_operations cachefiles_daemon_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) extern int cachefiles_has_space(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				unsigned fnr, unsigned bnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * interface.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) extern const struct fscache_cache_ops cachefiles_cache_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * key.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) extern char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) extern void cachefiles_mark_object_inactive(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 					    struct cachefiles_object *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 					    blkcnt_t i_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) extern int cachefiles_delete_object(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				    struct cachefiles_object *object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) extern int cachefiles_walk_to_object(struct cachefiles_object *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				     struct cachefiles_object *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				     const char *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				     struct cachefiles_xattr *auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) extern struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					       struct dentry *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					       const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) extern int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			   char *filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				   struct dentry *dir, char *filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * proc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #ifdef CONFIG_CACHEFILES_HISTOGRAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) extern atomic_t cachefiles_lookup_histogram[HZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) extern atomic_t cachefiles_mkdir_histogram[HZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) extern atomic_t cachefiles_create_histogram[HZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) extern int __init cachefiles_proc_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) extern void cachefiles_proc_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	unsigned long jif = jiffies - start_jif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (jif >= HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		jif = HZ - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	atomic_inc(&histogram[jif]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define cachefiles_proc_init()		(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define cachefiles_proc_cleanup()	do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define cachefiles_hist(hist, start_jif) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * rdwr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) extern int cachefiles_read_or_alloc_page(struct fscache_retrieval *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 					 struct page *, gfp_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) extern int cachefiles_read_or_alloc_pages(struct fscache_retrieval *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 					  struct list_head *, unsigned *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 					  gfp_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) extern int cachefiles_allocate_page(struct fscache_retrieval *, struct page *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 				    gfp_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) extern int cachefiles_allocate_pages(struct fscache_retrieval *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				     struct list_head *, unsigned *, gfp_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) extern int cachefiles_write_page(struct fscache_storage *, struct page *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) extern void cachefiles_uncache_page(struct fscache_object *, struct page *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * security.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) extern int cachefiles_get_security_ID(struct cachefiles_cache *cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) extern int cachefiles_determine_cache_security(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					       struct dentry *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 					       const struct cred **_saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static inline void cachefiles_begin_secure(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 					   const struct cred **_saved_cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	*_saved_cred = override_creds(cache->cache_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static inline void cachefiles_end_secure(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 					 const struct cred *saved_cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	revert_creds(saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * xattr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) extern int cachefiles_check_object_type(struct cachefiles_object *object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) extern int cachefiles_set_object_xattr(struct cachefiles_object *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				       struct cachefiles_xattr *auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) extern int cachefiles_update_object_xattr(struct cachefiles_object *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 					  struct cachefiles_xattr *auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) extern int cachefiles_check_auxdata(struct cachefiles_object *object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) extern int cachefiles_check_object_xattr(struct cachefiles_object *object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 					 struct cachefiles_xattr *auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) extern int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 					  struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * error handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #define cachefiles_io_error(___cache, FMT, ...)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	pr_err("I/O Error: " FMT"\n", ##__VA_ARGS__);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	fscache_io_error(&(___cache)->cache);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	set_bit(CACHEFILES_DEAD, &(___cache)->flags);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #define cachefiles_io_error_obj(object, FMT, ...)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct cachefiles_cache *___cache;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	___cache = container_of((object)->fscache.cache,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				struct cachefiles_cache, cache);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	cachefiles_io_error(___cache, FMT, ##__VA_ARGS__);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * debug tracing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define dbgprintk(FMT, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #if defined(__KDEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #elif defined(CONFIG_CACHEFILES_DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #define _enter(FMT, ...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (cachefiles_debug & CACHEFILES_DEBUG_KENTER)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		kenter(FMT, ##__VA_ARGS__);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #define _leave(FMT, ...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (cachefiles_debug & CACHEFILES_DEBUG_KLEAVE)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		kleave(FMT, ##__VA_ARGS__);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #define _debug(FMT, ...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) do {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (cachefiles_debug & CACHEFILES_DEBUG_KDEBUG)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		kdebug(FMT, ##__VA_ARGS__);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #if 1 /* defined(__KDEBUGALL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #define ASSERT(X)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (unlikely(!(X))) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		pr_err("\n");						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		pr_err("Assertion failed\n");		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		BUG();							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #define ASSERTCMP(X, OP, Y)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (unlikely(!((X) OP (Y)))) {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		pr_err("\n");						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		pr_err("Assertion failed\n");		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		pr_err("%lx " #OP " %lx is false\n",			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		       (unsigned long)(X), (unsigned long)(Y));		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		BUG();							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) #define ASSERTIF(C, X)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (unlikely((C) && !(X))) {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		pr_err("\n");						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		pr_err("Assertion failed\n");		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		BUG();							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #define ASSERTIFCMP(C, X, OP, Y)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (unlikely((C) && !((X) OP (Y)))) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		pr_err("\n");						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		pr_err("Assertion failed\n");		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		pr_err("%lx " #OP " %lx is false\n",			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		       (unsigned long)(X), (unsigned long)(Y));		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		BUG();							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) #define ASSERT(X)			do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #define ASSERTCMP(X, OP, Y)		do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) #define ASSERTIF(C, X)			do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #define ASSERTIFCMP(C, X, OP, Y)	do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) #endif