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:
Zach Brown
2017-04-18 14:17:55 -07:00
parent 5c54bdbf85
commit 8b82aa7f18
2 changed files with 11 additions and 7 deletions
+7 -2
View File
@@ -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
View File
@@ -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;