Skip to content

Commit fd2421f

Browse files
kvaneeshericvh
authored andcommitted
fs/9p: When doing inode lookup compare qid details and inode mode bits.
This make sure we don't use wrong inode from the inode hash. The inode number of the file deleted is reused by the next file system object created and if we only use inode number for inode hash lookup we could end up with wrong struct inode. Also compare inode generation number. Not all Linux file system provide st_gen in userspace. So it could be 0; Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent 5034990 commit fd2421f

6 files changed

Lines changed: 81 additions & 29 deletions

File tree

‎fs/9p/cache.c‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,10 @@ static uint16_t v9fs_cache_inode_get_key(const void *cookie_netfs_data,
108108
void *buffer, uint16_t bufmax)
109109
{
110110
const struct v9fs_inode *v9inode = cookie_netfs_data;
111-
memcpy(buffer, &v9inode->fscache_key->path,
112-
sizeof(v9inode->fscache_key->path));
111+
memcpy(buffer, &v9inode->qid.path, sizeof(v9inode->qid.path));
113112
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get key %llu", &v9inode->vfs_inode,
114-
v9inode->fscache_key->path);
115-
return sizeof(v9inode->fscache_key->path);
113+
v9inode->qid.path);
114+
return sizeof(v9inode->qid.path);
116115
}
117116

118117
static void v9fs_cache_inode_get_attr(const void *cookie_netfs_data,
@@ -129,11 +128,10 @@ static uint16_t v9fs_cache_inode_get_aux(const void *cookie_netfs_data,
129128
void *buffer, uint16_t buflen)
130129
{
131130
const struct v9fs_inode *v9inode = cookie_netfs_data;
132-
memcpy(buffer, &v9inode->fscache_key->version,
133-
sizeof(v9inode->fscache_key->version));
131+
memcpy(buffer, &v9inode->qid.version, sizeof(v9inode->qid.version));
134132
P9_DPRINTK(P9_DEBUG_FSC, "inode %p get aux %u", &v9inode->vfs_inode,
135-
v9inode->fscache_key->version);
136-
return sizeof(v9inode->fscache_key->version);
133+
v9inode->qid.version);
134+
return sizeof(v9inode->qid.version);
137135
}
138136

139137
static enum
@@ -143,11 +141,11 @@ fscache_checkaux v9fs_cache_inode_check_aux(void *cookie_netfs_data,
143141
{
144142
const struct v9fs_inode *v9inode = cookie_netfs_data;
145143

146-
if (buflen != sizeof(v9inode->fscache_key->version))
144+
if (buflen != sizeof(v9inode->qid.version))
147145
return FSCACHE_CHECKAUX_OBSOLETE;
148146

149-
if (memcmp(buffer, &v9inode->fscache_key->version,
150-
sizeof(v9inode->fscache_key->version)))
147+
if (memcmp(buffer, &v9inode->qid.version,
148+
sizeof(v9inode->qid.version)))
151149
return FSCACHE_CHECKAUX_OBSOLETE;
152150

153151
return FSCACHE_CHECKAUX_OKAY;

‎fs/9p/cache.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
9393
BUG_ON(PageFsCache(page));
9494
}
9595

96-
static inline void v9fs_fscache_set_key(struct inode *inode,
97-
struct p9_qid *qid)
98-
{
99-
struct v9fs_inode *v9inode = V9FS_I(inode);
100-
spin_lock(&v9inode->fscache_lock);
101-
v9inode->fscache_key = qid;
102-
spin_unlock(&v9inode->fscache_lock);
103-
}
104-
10596
static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
10697
struct page *page)
10798
{

‎fs/9p/v9fs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ static void v9fs_inode_init_once(void *foo)
487487
struct v9fs_inode *v9inode = (struct v9fs_inode *)foo;
488488
#ifdef CONFIG_9P_FSCACHE
489489
v9inode->fscache = NULL;
490-
v9inode->fscache_key = NULL;
491490
#endif
491+
memset(&v9inode->qid, 0, sizeof(v9inode->qid));
492492
inode_init_once(&v9inode->vfs_inode);
493493
}
494494

‎fs/9p/v9fs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ struct v9fs_inode {
125125
#ifdef CONFIG_9P_FSCACHE
126126
spinlock_t fscache_lock;
127127
struct fscache_cookie *fscache;
128-
struct p9_qid *fscache_key;
129128
#endif
129+
struct p9_qid qid;
130130
unsigned int cache_validity;
131131
struct p9_fid *writeback_fid;
132132
struct mutex v_mutex;

‎fs/9p/vfs_inode.c‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ struct inode *v9fs_alloc_inode(struct super_block *sb)
216216
return NULL;
217217
#ifdef CONFIG_9P_FSCACHE
218218
v9inode->fscache = NULL;
219-
v9inode->fscache_key = NULL;
220219
spin_lock_init(&v9inode->fscache_lock);
221220
#endif
222221
v9inode->writeback_fid = NULL;
@@ -433,6 +432,37 @@ void v9fs_evict_inode(struct inode *inode)
433432
}
434433
}
435434

435+
static int v9fs_test_inode(struct inode *inode, void *data)
436+
{
437+
int umode;
438+
struct v9fs_inode *v9inode = V9FS_I(inode);
439+
struct p9_wstat *st = (struct p9_wstat *)data;
440+
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
441+
442+
umode = p9mode2unixmode(v9ses, st->mode);
443+
/* don't match inode of different type */
444+
if ((inode->i_mode & S_IFMT) != (umode & S_IFMT))
445+
return 0;
446+
447+
/* compare qid details */
448+
if (memcmp(&v9inode->qid.version,
449+
&st->qid.version, sizeof(v9inode->qid.version)))
450+
return 0;
451+
452+
if (v9inode->qid.type != st->qid.type)
453+
return 0;
454+
return 1;
455+
}
456+
457+
static int v9fs_set_inode(struct inode *inode, void *data)
458+
{
459+
struct v9fs_inode *v9inode = V9FS_I(inode);
460+
struct p9_wstat *st = (struct p9_wstat *)data;
461+
462+
memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
463+
return 0;
464+
}
465+
436466
static struct inode *v9fs_qid_iget(struct super_block *sb,
437467
struct p9_qid *qid,
438468
struct p9_wstat *st)
@@ -443,7 +473,7 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
443473
struct v9fs_session_info *v9ses = sb->s_fs_info;
444474

445475
i_ino = v9fs_qid2ino(qid);
446-
inode = iget_locked(sb, i_ino);
476+
inode = iget5_locked(sb, i_ino, v9fs_test_inode, v9fs_set_inode, st);
447477
if (!inode)
448478
return ERR_PTR(-ENOMEM);
449479
if (!(inode->i_state & I_NEW))
@@ -453,14 +483,14 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
453483
* FIXME!! we may need support for stale inodes
454484
* later.
455485
*/
486+
inode->i_ino = i_ino;
456487
umode = p9mode2unixmode(v9ses, st->mode);
457488
retval = v9fs_init_inode(v9ses, inode, umode);
458489
if (retval)
459490
goto error;
460491

461492
v9fs_stat2inode(st, inode, sb);
462493
#ifdef CONFIG_9P_FSCACHE
463-
v9fs_fscache_set_key(inode, &st->qid);
464494
v9fs_cache_inode_get_cookie(inode);
465495
#endif
466496
unlock_new_inode(inode);

‎fs/9p/vfs_inode_dotl.c‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,38 @@ static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
8686
return dentry;
8787
}
8888

89+
static int v9fs_test_inode_dotl(struct inode *inode, void *data)
90+
{
91+
struct v9fs_inode *v9inode = V9FS_I(inode);
92+
struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
93+
94+
/* don't match inode of different type */
95+
if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT))
96+
return 0;
97+
98+
if (inode->i_generation != st->st_gen)
99+
return 0;
100+
101+
/* compare qid details */
102+
if (memcmp(&v9inode->qid.version,
103+
&st->qid.version, sizeof(v9inode->qid.version)))
104+
return 0;
105+
106+
if (v9inode->qid.type != st->qid.type)
107+
return 0;
108+
return 1;
109+
}
110+
111+
static int v9fs_set_inode_dotl(struct inode *inode, void *data)
112+
{
113+
struct v9fs_inode *v9inode = V9FS_I(inode);
114+
struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
115+
116+
memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
117+
inode->i_generation = st->st_gen;
118+
return 0;
119+
}
120+
89121
static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
90122
struct p9_qid *qid,
91123
struct p9_fid *fid,
@@ -97,7 +129,8 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
97129
struct v9fs_session_info *v9ses = sb->s_fs_info;
98130

99131
i_ino = v9fs_qid2ino(qid);
100-
inode = iget_locked(sb, i_ino);
132+
inode = iget5_locked(sb, i_ino, v9fs_test_inode_dotl,
133+
v9fs_set_inode_dotl, st);
101134
if (!inode)
102135
return ERR_PTR(-ENOMEM);
103136
if (!(inode->i_state & I_NEW))
@@ -107,13 +140,13 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
107140
* FIXME!! we may need support for stale inodes
108141
* later.
109142
*/
143+
inode->i_ino = i_ino;
110144
retval = v9fs_init_inode(v9ses, inode, st->st_mode);
111145
if (retval)
112146
goto error;
113147

114148
v9fs_stat2inode_dotl(st, inode);
115149
#ifdef CONFIG_9P_FSCACHE
116-
v9fs_fscache_set_key(inode, &st->qid);
117150
v9fs_cache_inode_get_cookie(inode);
118151
#endif
119152
retval = v9fs_get_acl(inode, fid);
@@ -136,7 +169,7 @@ v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
136169
struct p9_stat_dotl *st;
137170
struct inode *inode = NULL;
138171

139-
st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
172+
st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
140173
if (IS_ERR(st))
141174
return ERR_CAST(st);
142175

@@ -547,7 +580,7 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
547580
inode->i_blocks = stat->st_blocks;
548581
}
549582
if (stat->st_result_mask & P9_STATS_GEN)
550-
inode->i_generation = stat->st_gen;
583+
inode->i_generation = stat->st_gen;
551584

552585
/* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
553586
* because the inode structure does not have fields for them.

0 commit comments

Comments
 (0)