From d5b4677e7f35bcefe03bae21b9989483346c6818 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 13 Jul 2017 10:37:01 -0700 Subject: [PATCH] scoutfs: add end to _dirty, _delete_many, _update These transformations are mechanical and there aren't many callers of these so we combine them into one commit. Signed-off-by: Zach Brown --- kmod/src/dir.c | 2 +- kmod/src/inode.c | 4 ++-- kmod/src/item.c | 31 ++++++++----------------------- kmod/src/item.h | 8 +++++--- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/kmod/src/dir.c b/kmod/src/dir.c index 55909f8f..eab2afe7 100644 --- a/kmod/src/dir.c +++ b/kmod/src/dir.c @@ -600,7 +600,7 @@ static int scoutfs_unlink(struct inode *dir, struct dentry *dentry) goto out; } - ret = scoutfs_item_delete_many(sb, keys, ARRAY_SIZE(keys)); + ret = scoutfs_item_delete_many(sb, keys, ARRAY_SIZE(keys), NULL); if (ret) goto out; diff --git a/kmod/src/inode.c b/kmod/src/inode.c index 176bc306..57d5e23d 100644 --- a/kmod/src/inode.c +++ b/kmod/src/inode.c @@ -428,7 +428,7 @@ int scoutfs_dirty_inode_item(struct inode *inode) scoutfs_inode_init_key(&key, &ikey, scoutfs_ino(inode)); - ret = scoutfs_item_dirty(sb, &key); + ret = scoutfs_item_dirty(sb, &key, NULL); if (!ret) trace_scoutfs_dirty_inode(inode); return ret; @@ -551,7 +551,7 @@ void scoutfs_update_inode_item(struct inode *inode) scoutfs_inode_init_key(&key, &ikey, scoutfs_ino(inode)); scoutfs_kvec_init(val, &sinode, sizeof(sinode)); - err = scoutfs_item_update(sb, &key, val); + err = scoutfs_item_update(sb, &key, val, NULL); if (err) { scoutfs_err(sb, "inode %llu update err %d", scoutfs_ino(inode), err); diff --git a/kmod/src/item.c b/kmod/src/item.c index a1fa214e..8824c945 100644 --- a/kmod/src/item.c +++ b/kmod/src/item.c @@ -1257,21 +1257,15 @@ void scoutfs_item_free_batch(struct super_block *sb, struct list_head *list) * If the item exists make sure it's dirty and pinned. It can be read * if it wasn't cached. -ENOENT is returned if the item doesn't exist. */ -int scoutfs_item_dirty(struct super_block *sb, struct scoutfs_key_buf *key) +int scoutfs_item_dirty(struct super_block *sb, struct scoutfs_key_buf *key, + struct scoutfs_key_buf *end) { struct scoutfs_sb_info *sbi = SCOUTFS_SB(sb); struct item_cache *cac = sbi->item_cache; - struct scoutfs_key_buf *end; struct cached_item *item; unsigned long flags; int ret; - end = scoutfs_key_alloc(sb, SCOUTFS_MAX_KEY_SIZE); - if (!end) { - ret = -ENOMEM; - goto out; - } - do { spin_lock_irqsave(&cac->lock, flags); @@ -1279,7 +1273,7 @@ int scoutfs_item_dirty(struct super_block *sb, struct scoutfs_key_buf *key) if (item) { mark_item_dirty(sb, cac, item); ret = 0; - } else if (check_range(sb, &cac->ranges, key, end)) { + } else if (check_range(sb, &cac->ranges, key, NULL)) { ret = -ENOENT; } else { ret = -ENODATA; @@ -1290,8 +1284,6 @@ int scoutfs_item_dirty(struct super_block *sb, struct scoutfs_key_buf *key) } while (ret == -ENODATA && (ret = scoutfs_manifest_read_items(sb, key, end)) == 0); - scoutfs_key_free(sb, end); -out: trace_printk("ret %d\n", ret); return ret; } @@ -1303,11 +1295,10 @@ out: * Returns -ENOENT if the item doesn't exist. */ int scoutfs_item_update(struct super_block *sb, struct scoutfs_key_buf *key, - struct kvec *val) + struct kvec *val, struct scoutfs_key_buf *end) { struct scoutfs_sb_info *sbi = SCOUTFS_SB(sb); struct item_cache *cac = sbi->item_cache; - struct scoutfs_key_buf *end; SCOUTFS_DECLARE_KVEC(up_val); struct cached_item *item; unsigned long flags; @@ -1316,12 +1307,6 @@ int scoutfs_item_update(struct super_block *sb, struct scoutfs_key_buf *key, if (invalid_key_val(key, val)) return -EINVAL; - end = scoutfs_key_alloc(sb, SCOUTFS_MAX_KEY_SIZE); - if (!end) { - ret = -ENOMEM; - goto out; - } - if (val) { ret = scoutfs_kvec_dup_flatten(up_val, val); if (ret) @@ -1339,7 +1324,7 @@ int scoutfs_item_update(struct super_block *sb, struct scoutfs_key_buf *key, scoutfs_kvec_swap(up_val, item->val); mark_item_dirty(sb, cac, item); ret = 0; - } else if (check_range(sb, &cac->ranges, key, end)) { + } else if (check_range(sb, &cac->ranges, key, NULL)) { ret = -ENOENT; } else { ret = -ENODATA; @@ -1350,7 +1335,6 @@ int scoutfs_item_update(struct super_block *sb, struct scoutfs_key_buf *key, } while (ret == -ENODATA && (ret = scoutfs_manifest_read_items(sb, key, end)) == 0); out: - scoutfs_key_free(sb, end); scoutfs_kvec_kfree(up_val); trace_printk("ret %d\n", ret); @@ -1449,13 +1433,14 @@ void scoutfs_item_delete_dirty(struct super_block *sb, * searches if we remembered the items we dirtied. */ int scoutfs_item_delete_many(struct super_block *sb, - struct scoutfs_key_buf **keys, unsigned nr) + struct scoutfs_key_buf **keys, unsigned nr, + struct scoutfs_key_buf *end) { int ret = 0; int i; for (i = 0; i < nr; i++) { - ret = scoutfs_item_dirty(sb, keys[i]); + ret = scoutfs_item_dirty(sb, keys[i], end); if (ret) goto out; } diff --git a/kmod/src/item.h b/kmod/src/item.h index ef751a95..33f13d35 100644 --- a/kmod/src/item.h +++ b/kmod/src/item.h @@ -30,13 +30,15 @@ int scoutfs_item_next_same(struct super_block *sb, struct scoutfs_key_buf *key, struct scoutfs_key_buf *end); int scoutfs_item_create(struct super_block *sb, struct scoutfs_key_buf *key, struct kvec *val); -int scoutfs_item_dirty(struct super_block *sb, struct scoutfs_key_buf *key); +int scoutfs_item_dirty(struct super_block *sb, struct scoutfs_key_buf *key, + struct scoutfs_key_buf *end); int scoutfs_item_update(struct super_block *sb, struct scoutfs_key_buf *key, - struct kvec *val); + struct kvec *val, struct scoutfs_key_buf *end); void scoutfs_item_delete_dirty(struct super_block *sb, struct scoutfs_key_buf *key); int scoutfs_item_delete_many(struct super_block *sb, - struct scoutfs_key_buf **keys, unsigned nr); + struct scoutfs_key_buf **keys, unsigned nr, + struct scoutfs_key_buf *end); int scoutfs_item_delete(struct super_block *sb, struct scoutfs_key_buf *key); int scoutfs_item_add_batch(struct super_block *sb, struct list_head *list,