Skip to content

Commit c07dfcb

Browse files
Tahsin Erdogantytso
authored andcommitted
mbcache: make mbcache naming more generic
Make names more generic so that mbcache usage is not limited to block sharing. In a subsequent patch in the series ("ext4: xattr inode deduplication"), we start using the mbcache code for sharing xattr inodes. With that patch, old mb_cache_entry.e_block field could be holding either a block number or an inode number. Signed-off-by: Tahsin Erdogan <tahsin@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent b6d9029 commit c07dfcb

File tree

4 files changed

+40
-42
lines changed

4 files changed

+40
-42
lines changed

fs/ext2/xattr.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ bad_block: ext2_error(sb, "ext2_xattr_set",
493493
* This must happen under buffer lock for
494494
* ext2_xattr_set2() to reliably detect modified block
495495
*/
496-
mb_cache_entry_delete_block(EXT2_SB(sb)->s_mb_cache,
497-
hash, bh->b_blocknr);
496+
mb_cache_entry_delete(EXT2_SB(sb)->s_mb_cache, hash,
497+
bh->b_blocknr);
498498

499499
/* keep the buffer locked while modifying it. */
500500
} else {
@@ -721,8 +721,8 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
721721
* This must happen under buffer lock for
722722
* ext2_xattr_set2() to reliably detect freed block
723723
*/
724-
mb_cache_entry_delete_block(ext2_mb_cache,
725-
hash, old_bh->b_blocknr);
724+
mb_cache_entry_delete(ext2_mb_cache, hash,
725+
old_bh->b_blocknr);
726726
/* Free the old block. */
727727
ea_bdebug(old_bh, "freeing");
728728
ext2_free_blocks(inode, old_bh->b_blocknr, 1);
@@ -795,8 +795,8 @@ ext2_xattr_delete_inode(struct inode *inode)
795795
* This must happen under buffer lock for ext2_xattr_set2() to
796796
* reliably detect freed block
797797
*/
798-
mb_cache_entry_delete_block(EXT2_SB(inode->i_sb)->s_mb_cache,
799-
hash, bh->b_blocknr);
798+
mb_cache_entry_delete(EXT2_SB(inode->i_sb)->s_mb_cache, hash,
799+
bh->b_blocknr);
800800
ext2_free_blocks(inode, EXT2_I(inode)->i_file_acl, 1);
801801
get_bh(bh);
802802
bforget(bh);
@@ -907,11 +907,11 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
907907
while (ce) {
908908
struct buffer_head *bh;
909909

910-
bh = sb_bread(inode->i_sb, ce->e_block);
910+
bh = sb_bread(inode->i_sb, ce->e_value);
911911
if (!bh) {
912912
ext2_error(inode->i_sb, "ext2_xattr_cache_find",
913913
"inode %ld: block %ld read error",
914-
inode->i_ino, (unsigned long) ce->e_block);
914+
inode->i_ino, (unsigned long) ce->e_value);
915915
} else {
916916
lock_buffer(bh);
917917
/*
@@ -931,7 +931,7 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
931931
} else if (le32_to_cpu(HDR(bh)->h_refcount) >
932932
EXT2_XATTR_REFCOUNT_MAX) {
933933
ea_idebug(inode, "block %ld refcount %d>%d",
934-
(unsigned long) ce->e_block,
934+
(unsigned long) ce->e_value,
935935
le32_to_cpu(HDR(bh)->h_refcount),
936936
EXT2_XATTR_REFCOUNT_MAX);
937937
} else if (!ext2_xattr_cmp(header, HDR(bh))) {

fs/ext4/xattr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
678678
* This must happen under buffer lock for
679679
* ext4_xattr_block_set() to reliably detect freed block
680680
*/
681-
mb_cache_entry_delete_block(ext4_mb_cache, hash, bh->b_blocknr);
681+
mb_cache_entry_delete(ext4_mb_cache, hash, bh->b_blocknr);
682682
get_bh(bh);
683683
unlock_buffer(bh);
684684
ext4_free_blocks(handle, inode, bh, 0, 1,
@@ -1113,8 +1113,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
11131113
* ext4_xattr_block_set() to reliably detect modified
11141114
* block
11151115
*/
1116-
mb_cache_entry_delete_block(ext4_mb_cache, hash,
1117-
bs->bh->b_blocknr);
1116+
mb_cache_entry_delete(ext4_mb_cache, hash,
1117+
bs->bh->b_blocknr);
11181118
ea_bdebug(bs->bh, "modifying in-place");
11191119
error = ext4_xattr_set_entry(i, s, handle, inode);
11201120
if (!error) {
@@ -2236,10 +2236,10 @@ ext4_xattr_cache_find(struct inode *inode, struct ext4_xattr_header *header,
22362236
while (ce) {
22372237
struct buffer_head *bh;
22382238

2239-
bh = sb_bread(inode->i_sb, ce->e_block);
2239+
bh = sb_bread(inode->i_sb, ce->e_value);
22402240
if (!bh) {
22412241
EXT4_ERROR_INODE(inode, "block %lu read error",
2242-
(unsigned long) ce->e_block);
2242+
(unsigned long)ce->e_value);
22432243
} else if (ext4_xattr_cmp(header, BHDR(bh)) == 0) {
22442244
*pce = ce;
22452245
return bh;

fs/mbcache.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/*
1111
* Mbcache is a simple key-value store. Keys need not be unique, however
1212
* key-value pairs are expected to be unique (we use this fact in
13-
* mb_cache_entry_delete_block()).
13+
* mb_cache_entry_delete()).
1414
*
1515
* Ext2 and ext4 use this cache for deduplication of extended attribute blocks.
1616
* They use hash of a block contents as a key and block number as a value.
@@ -62,15 +62,15 @@ static inline struct hlist_bl_head *mb_cache_entry_head(struct mb_cache *cache,
6262
* @cache - cache where the entry should be created
6363
* @mask - gfp mask with which the entry should be allocated
6464
* @key - key of the entry
65-
* @block - block that contains data
66-
* @reusable - is the block reusable by other inodes?
65+
* @value - value of the entry
66+
* @reusable - is the entry reusable by others?
6767
*
68-
* Creates entry in @cache with key @key and records that data is stored in
69-
* block @block. The function returns -EBUSY if entry with the same key
70-
* and for the same block already exists in cache. Otherwise 0 is returned.
68+
* Creates entry in @cache with key @key and value @value. The function returns
69+
* -EBUSY if entry with the same key and value already exists in cache.
70+
* Otherwise 0 is returned.
7171
*/
7272
int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
73-
sector_t block, bool reusable)
73+
u64 value, bool reusable)
7474
{
7575
struct mb_cache_entry *entry, *dup;
7676
struct hlist_bl_node *dup_node;
@@ -91,12 +91,12 @@ int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
9191
/* One ref for hash, one ref returned */
9292
atomic_set(&entry->e_refcnt, 1);
9393
entry->e_key = key;
94-
entry->e_block = block;
94+
entry->e_value = value;
9595
entry->e_reusable = reusable;
9696
head = mb_cache_entry_head(cache, key);
9797
hlist_bl_lock(head);
9898
hlist_bl_for_each_entry(dup, dup_node, head, e_hash_list) {
99-
if (dup->e_key == key && dup->e_block == block) {
99+
if (dup->e_key == key && dup->e_value == value) {
100100
hlist_bl_unlock(head);
101101
kmem_cache_free(mb_entry_cache, entry);
102102
return -EBUSY;
@@ -187,13 +187,13 @@ struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,
187187
EXPORT_SYMBOL(mb_cache_entry_find_next);
188188

189189
/*
190-
* mb_cache_entry_get - get a cache entry by block number (and key)
190+
* mb_cache_entry_get - get a cache entry by value (and key)
191191
* @cache - cache we work with
192-
* @key - key of block number @block
193-
* @block - block number
192+
* @key - key
193+
* @value - value
194194
*/
195195
struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key,
196-
sector_t block)
196+
u64 value)
197197
{
198198
struct hlist_bl_node *node;
199199
struct hlist_bl_head *head;
@@ -202,7 +202,7 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key,
202202
head = mb_cache_entry_head(cache, key);
203203
hlist_bl_lock(head);
204204
hlist_bl_for_each_entry(entry, node, head, e_hash_list) {
205-
if (entry->e_key == key && entry->e_block == block) {
205+
if (entry->e_key == key && entry->e_value == value) {
206206
atomic_inc(&entry->e_refcnt);
207207
goto out;
208208
}
@@ -214,15 +214,14 @@ struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key,
214214
}
215215
EXPORT_SYMBOL(mb_cache_entry_get);
216216

217-
/* mb_cache_entry_delete_block - remove information about block from cache
217+
/* mb_cache_entry_delete - remove a cache entry
218218
* @cache - cache we work with
219-
* @key - key of block @block
220-
* @block - block number
219+
* @key - key
220+
* @value - value
221221
*
222-
* Remove entry from cache @cache with key @key with data stored in @block.
222+
* Remove entry from cache @cache with key @key and value @value.
223223
*/
224-
void mb_cache_entry_delete_block(struct mb_cache *cache, u32 key,
225-
sector_t block)
224+
void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value)
226225
{
227226
struct hlist_bl_node *node;
228227
struct hlist_bl_head *head;
@@ -231,7 +230,7 @@ void mb_cache_entry_delete_block(struct mb_cache *cache, u32 key,
231230
head = mb_cache_entry_head(cache, key);
232231
hlist_bl_lock(head);
233232
hlist_bl_for_each_entry(entry, node, head, e_hash_list) {
234-
if (entry->e_key == key && entry->e_block == block) {
233+
if (entry->e_key == key && entry->e_value == value) {
235234
/* We keep hash list reference to keep entry alive */
236235
hlist_bl_del_init(&entry->e_hash_list);
237236
hlist_bl_unlock(head);
@@ -248,7 +247,7 @@ void mb_cache_entry_delete_block(struct mb_cache *cache, u32 key,
248247
}
249248
hlist_bl_unlock(head);
250249
}
251-
EXPORT_SYMBOL(mb_cache_entry_delete_block);
250+
EXPORT_SYMBOL(mb_cache_entry_delete);
252251

253252
/* mb_cache_entry_touch - cache entry got used
254253
* @cache - cache the entry belongs to

include/linux/mbcache.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ struct mb_cache_entry {
1919
u32 e_key;
2020
u32 e_referenced:1;
2121
u32 e_reusable:1;
22-
/* Block number of hashed block - stable during lifetime of the entry */
23-
sector_t e_block;
22+
/* User provided value - stable during lifetime of the entry */
23+
u64 e_value;
2424
};
2525

2626
struct mb_cache *mb_cache_create(int bucket_bits);
2727
void mb_cache_destroy(struct mb_cache *cache);
2828

2929
int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
30-
sector_t block, bool reusable);
30+
u64 value, bool reusable);
3131
void __mb_cache_entry_free(struct mb_cache_entry *entry);
3232
static inline int mb_cache_entry_put(struct mb_cache *cache,
3333
struct mb_cache_entry *entry)
@@ -38,10 +38,9 @@ static inline int mb_cache_entry_put(struct mb_cache *cache,
3838
return 1;
3939
}
4040

41-
void mb_cache_entry_delete_block(struct mb_cache *cache, u32 key,
42-
sector_t block);
41+
void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value);
4342
struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key,
44-
sector_t block);
43+
u64 value);
4544
struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache,
4645
u32 key);
4746
struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,

0 commit comments

Comments
 (0)