From 9d6d70bd891d6afa97887040bb1119681572ffe7 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 24 Jan 2017 14:46:04 -0800 Subject: [PATCH] Add an item next for key len ignoring val Add scoutfs_item_next_same() which requires that the key lengths be identical but which allows any values, including no value by way of a null kvec. Signed-off-by: Zach Brown --- kmod/src/item.c | 21 +++++++++++++++++++++ kmod/src/item.h | 2 ++ 2 files changed, 23 insertions(+) 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,