mirror of
https://github.com/versity/scoutfs.git
synced 2026-09-06 08:06:56 +00:00
Consistently initialize inode fields
Inode info struct initialization spread out over three places: - once for the memory of a slab obect - when reading an existing inode from items - when initializing a newly allocated inode Over time field initializtion got out of sync with these rules. This makes it more clear which fields get initialized where. In the inode info struct we group fields by where there initialized. We order the fields by size and location in the inode struct. Then we make sure that all the initialization sites have everything covered. Doing everything in consistent struct order makes it easier to audit that we haven't missed anything. What lead to this was realizing that we missed initializing the seqcount when reading existing inodes. It should have been initialized in the slab object constructor. The 'staging' boolean has the same problem. Signed-off-by: Zach Brown <zab@versity.com> Reviewed-by: Mark Fasheh <mfasheh@versity.com>
This commit is contained in:
+7
-2
@@ -49,10 +49,17 @@ struct free_ino_pool {
|
||||
|
||||
static struct kmem_cache *scoutfs_inode_cachep;
|
||||
|
||||
/*
|
||||
* This is called once before all the allocations and frees of a inode
|
||||
* object within a slab. It's for inode fields that don't need to be
|
||||
* initialized for a given instance of an inode.
|
||||
*/
|
||||
static void scoutfs_inode_ctor(void *obj)
|
||||
{
|
||||
struct scoutfs_inode_info *ci = obj;
|
||||
|
||||
seqcount_init(&ci->seqcount);
|
||||
ci->staging = false;
|
||||
init_rwsem(&ci->xattr_rwsem);
|
||||
|
||||
inode_init_once(&ci->inode);
|
||||
@@ -501,10 +508,8 @@ struct inode *scoutfs_new_inode(struct super_block *sb, struct inode *dir,
|
||||
|
||||
ci = SCOUTFS_I(inode);
|
||||
ci->ino = ino;
|
||||
seqcount_init(&ci->seqcount);
|
||||
ci->data_version = 0;
|
||||
ci->next_readdir_pos = SCOUTFS_DIRENT_FIRST_POS;
|
||||
ci->staging = false;
|
||||
|
||||
inode->i_ino = ino; /* XXX overflow */
|
||||
inode_init_owner(inode, dir, mode);
|
||||
|
||||
+4
-5
@@ -4,15 +4,14 @@
|
||||
#include "key.h"
|
||||
|
||||
struct scoutfs_inode_info {
|
||||
/* read or initialized for each inode instance */
|
||||
u64 ino;
|
||||
|
||||
seqcount_t seqcount;
|
||||
u64 data_version;
|
||||
u64 next_readdir_pos;
|
||||
|
||||
/* holder of i_mutex is staging */
|
||||
bool staging;
|
||||
|
||||
/* initialized once for slab object */
|
||||
seqcount_t seqcount;
|
||||
bool staging; /* holder of i_mutex is staging */
|
||||
struct rw_semaphore xattr_rwsem;
|
||||
|
||||
struct inode inode;
|
||||
|
||||
Reference in New Issue
Block a user