scoutfs: add scoutfs_item_update_dirty()

Add a function for updating the value of a dirty item.  Callers can use
this to make changes without having to worry about failure.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2017-09-19 11:25:38 -07:00
committed by Mark Fasheh
parent 5325aff698
commit c4f3c26343
2 changed files with 30 additions and 0 deletions
+28
View File
@@ -1436,6 +1436,34 @@ void scoutfs_item_delete_dirty(struct super_block *sb,
scoutfs_kvec_kfree(del_val);
}
/*
* Copy the callers value into the dirty item and truncate its value if
* the existing value is longer. The caller must have ensured that the
* item was dirty and had a large enough value.
*/
void scoutfs_item_update_dirty(struct super_block *sb,
struct scoutfs_key_buf *key, struct kvec *val)
{
struct scoutfs_sb_info *sbi = SCOUTFS_SB(sb);
struct item_cache *cac = sbi->item_cache;
struct cached_item *item;
unsigned long flags;
signed delta;
spin_lock_irqsave(&cac->lock, flags);
item = find_item(sb, &cac->items, key);
BUG_ON(!item || !(item->dirty & ITEM_DIRTY) ||
scoutfs_kvec_length(val) > scoutfs_kvec_length(item->val));
delta = scoutfs_kvec_length(val) - scoutfs_kvec_length(item->val);
scoutfs_kvec_memcpy_truncate(item->val, val);
update_dirty_item_counts(sb, 0, 0, delta);
spin_unlock_irqrestore(&cac->lock, flags);
}
/*
* Return the first dirty node in the subtree starting at the given node.
*/
+2
View File
@@ -36,6 +36,8 @@ int scoutfs_item_update(struct super_block *sb, struct scoutfs_key_buf *key,
struct kvec *val, struct scoutfs_key_buf *end);
void scoutfs_item_delete_dirty(struct super_block *sb,
struct scoutfs_key_buf *key);
void scoutfs_item_update_dirty(struct super_block *sb,
struct scoutfs_key_buf *key, struct kvec *val);
int scoutfs_item_delete(struct super_block *sb, struct scoutfs_key_buf *key,
struct scoutfs_key_buf *end);