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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Assorted bcache debug code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright 2012 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "bcache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "extents.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct dentry *bcache_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #ifdef CONFIG_BCACHE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define for_each_written_bset(b, start, i)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	for (i = (start);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	     (void *) i < (void *) (start) + (KEY_SIZE(&b->key) << 9) &&\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	     i->seq == (start)->seq;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	     i = (void *) i + set_blocks(i, block_bytes(b->c->cache)) *	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		 block_bytes(b->c->cache))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) void bch_btree_verify(struct btree *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct btree *v = b->c->verify_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct bset *ondisk, *sorted, *inmemory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (!b->c->verify || !b->c->verify_ondisk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	down(&b->io_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	mutex_lock(&b->c->verify_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	ondisk = b->c->verify_ondisk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	sorted = b->c->verify_data->keys.set->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	inmemory = b->keys.set->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	bkey_copy(&v->key, &b->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	v->written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	v->level = b->level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	v->keys.ops = b->keys.ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	bio = bch_bbio_alloc(b->c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	bio_set_dev(bio, PTR_CACHE(b->c, &b->key, 0)->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	bio->bi_iter.bi_sector	= PTR_OFFSET(&b->key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	bio->bi_iter.bi_size	= KEY_SIZE(&v->key) << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	bio->bi_opf		= REQ_OP_READ | REQ_META;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	bch_bio_map(bio, sorted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	submit_bio_wait(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	bch_bbio_free(bio, b->c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	memcpy(ondisk, sorted, KEY_SIZE(&v->key) << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	bch_btree_node_read_done(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	sorted = v->keys.set->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (inmemory->keys != sorted->keys ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	    memcmp(inmemory->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		   sorted->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		   (void *) bset_bkey_last(inmemory) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		   (void *) inmemory->start)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		struct bset *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		unsigned int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		console_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		pr_err("*** in memory:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		bch_dump_bset(&b->keys, inmemory, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		pr_err("*** read back in:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		bch_dump_bset(&v->keys, sorted, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		for_each_written_bset(b, ondisk, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			unsigned int block = ((void *) i - (void *) ondisk) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				block_bytes(b->c->cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			pr_err("*** on disk block %u:\n", block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			bch_dump_bset(&b->keys, i, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		pr_err("*** block %zu not written\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		       ((void *) i - (void *) ondisk) / block_bytes(b->c->cache));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		for (j = 0; j < inmemory->keys; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			if (inmemory->d[j] != sorted->d[j])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		pr_err("b->written %u\n", b->written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		console_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		panic("verify failed at %u\n", j);
^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) 	mutex_unlock(&b->c->verify_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	up(&b->io_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void bch_data_verify(struct cached_dev *dc, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct bio *check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct bio_vec bv, cbv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct bvec_iter iter, citer = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	check = bio_kmalloc(GFP_NOIO, bio_segments(bio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	check->bi_disk = bio->bi_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	check->bi_opf = REQ_OP_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	check->bi_iter.bi_sector = bio->bi_iter.bi_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	check->bi_iter.bi_size = bio->bi_iter.bi_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	bch_bio_map(check, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (bch_bio_alloc_pages(check, GFP_NOIO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	submit_bio_wait(check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	citer.bi_size = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	bio_for_each_segment(bv, bio, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		void *p1 = kmap_atomic(bv.bv_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		void *p2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		cbv = bio_iter_iovec(check, citer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		p2 = page_address(cbv.bv_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		cache_set_err_on(memcmp(p1 + bv.bv_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 					p2 + bv.bv_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 					bv.bv_len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				 dc->disk.c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				 "verify failed at dev %s sector %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				 dc->backing_dev_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				 (uint64_t) bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		kunmap_atomic(p1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		bio_advance_iter(check, &citer, bv.bv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	bio_free_pages(check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	bio_put(check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* XXX: cache set refcounting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct dump_iterator {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	char			buf[PAGE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	size_t			bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct cache_set	*c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct keybuf		keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static bool dump_pred(struct keybuf *buf, struct bkey *k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static ssize_t bch_dump_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			     size_t size, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct dump_iterator *i = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	char kbuf[80];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	while (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		struct keybuf_key *w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		unsigned int bytes = min(i->bytes, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		if (copy_to_user(buf, i->buf, bytes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		ret	 += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		buf	 += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		size	 -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		i->bytes -= bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		memmove(i->buf, i->buf + bytes, i->bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (i->bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		w = bch_keybuf_next_rescan(i->c, &i->keys, &MAX_KEY, dump_pred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (!w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		bch_extent_to_text(kbuf, sizeof(kbuf), &w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		i->bytes = snprintf(i->buf, PAGE_SIZE, "%s\n", kbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		bch_keybuf_del(&i->keys, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return ret;
^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) static int bch_dump_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct cache_set *c = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct dump_iterator *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	i = kzalloc(sizeof(struct dump_iterator), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	file->private_data = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	i->c = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	bch_keybuf_init(&i->keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	i->keys.last_scanned = KEY(0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int bch_dump_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	kfree(file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static const struct file_operations cache_set_debug_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	.open		= bch_dump_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	.read		= bch_dump_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	.release	= bch_dump_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) void bch_debug_init_cache_set(struct cache_set *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (!IS_ERR_OR_NULL(bcache_debug)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		char name[50];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		snprintf(name, 50, "bcache-%pU", c->set_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		c->debug = debugfs_create_file(name, 0400, bcache_debug, c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 					       &cache_set_debug_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) void bch_debug_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	debugfs_remove_recursive(bcache_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void __init bch_debug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	 * it is unnecessary to check return value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	 * debugfs_create_file(), we should not care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	 * about this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	bcache_debug = debugfs_create_dir("bcache", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }