diff --git a/kmod/src/item.c b/kmod/src/item.c index 45755724..c4dff761 100644 --- a/kmod/src/item.c +++ b/kmod/src/item.c @@ -713,6 +713,27 @@ int scoutfs_item_next_same_min(struct super_block *sb, return ret; } +/* + * Like _next but requires that the found keys be the same length as the + * search key. It treats size mismatches as a sign of corruption. + */ +int scoutfs_item_next_same(struct super_block *sb, struct scoutfs_key_buf *key, + struct scoutfs_key_buf *last, struct kvec *val) +{ + int key_len = key->key_len; + int ret; + + trace_printk("key len %u\n", key_len); + + ret = scoutfs_item_next(sb, key, last, val); + if (ret >= 0 && (key->key_len != key_len)) + ret = -EIO; + + trace_printk("ret %d\n", ret); + + return ret; +} + /* * Create a new dirty item in the cache. Returns -EEXIST if an item * already exists with the given key. diff --git a/kmod/src/item.h b/kmod/src/item.h index 3c7c6057..02afc91c 100644 --- a/kmod/src/item.h +++ b/kmod/src/item.h @@ -17,6 +17,8 @@ int scoutfs_item_next_same_min(struct super_block *sb, struct scoutfs_key_buf *key, struct scoutfs_key_buf *last, struct kvec *val, int len); +int scoutfs_item_next_same(struct super_block *sb, struct scoutfs_key_buf *key, + struct scoutfs_key_buf *last, struct kvec *val); int scoutfs_item_insert(struct super_block *sb, struct scoutfs_key_buf *key, struct kvec *val); int scoutfs_item_create(struct super_block *sb, struct scoutfs_key_buf *key,