From 241b52d55a0c187d68b39efc3dc9ae4660ae13ec Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 28 Feb 2018 12:46:06 -0800 Subject: [PATCH] scoutfs: reserve at least one xattr item value Even when we're setting an xattr with no value we still have a file system item value that contains the xattr value header which tells us that this is the last value. This fixes a warning that would be issued if we tried to set an xattr with a zero length value. We'd try to dirty an item value with the header after having reserved zero bytes for item values. To hit the warning the inode couldn't already be dirty so that the xattr value didn't get to hide in the unsed reservation for dirtying the inode item's value. Signed-off-by: Zach Brown --- kmod/src/count.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kmod/src/count.h b/kmod/src/count.h index fedeba69..1139c4cd 100644 --- a/kmod/src/count.h +++ b/kmod/src/count.h @@ -184,19 +184,22 @@ static inline const struct scoutfs_item_count SIC_RENAME(unsigned old_len, /* * Setting an xattr results in a dirty set of items with values for the - * size of the xattr. Any previously existing items from a larger xattr - * are deleted which dirties their key but removes their value. We - * don't know the size of a possibly existing xattr so we assume max - * parts. + * size of the xattr. There's always at least one item with a value + * header. Any previously existing items from a larger xattr are + * deleted which dirties their key but removes their value. We don't + * know the size of a possibly existing xattr so we assume max parts. */ static inline const struct scoutfs_item_count SIC_XATTR_SET(unsigned name_len, unsigned size) { struct scoutfs_item_count cnt = {0,}; - unsigned val_parts = DIV_ROUND_UP(size, SCOUTFS_XATTR_PART_SIZE); + unsigned val_parts; __count_dirty_inode(&cnt); + val_parts = max_t(unsigned, 1, + DIV_ROUND_UP(size, SCOUTFS_XATTR_PART_SIZE)); + cnt.items += SCOUTFS_XATTR_MAX_PARTS; cnt.keys += SCOUTFS_XATTR_MAX_PARTS * (offsetof(struct scoutfs_xattr_key, name[name_len]) +