@@ -243,26 +243,10 @@ void v9fs_destroy_inode(struct inode *inode)
243243}
244244#endif
245245
246- /**
247- * v9fs_get_inode - helper function to setup an inode
248- * @sb: superblock
249- * @mode: mode to setup inode with
250- *
251- */
252-
253- struct inode * v9fs_get_inode (struct super_block * sb , int mode )
246+ int v9fs_init_inode (struct v9fs_session_info * v9ses ,
247+ struct inode * inode , int mode )
254248{
255- int err ;
256- struct inode * inode ;
257- struct v9fs_session_info * v9ses = sb -> s_fs_info ;
258-
259- P9_DPRINTK (P9_DEBUG_VFS , "super block: %p mode: %o\n" , sb , mode );
260-
261- inode = new_inode (sb );
262- if (!inode ) {
263- P9_EPRINTK (KERN_WARNING , "Problem allocating inode\n" );
264- return ERR_PTR (- ENOMEM );
265- }
249+ int err = 0 ;
266250
267251 inode_init_owner (inode , NULL , mode );
268252 inode -> i_blocks = 0 ;
@@ -306,7 +290,6 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
306290 }
307291
308292 break ;
309-
310293 case S_IFLNK :
311294 if (!v9fs_proto_dotu (v9ses ) && !v9fs_proto_dotl (v9ses )) {
312295 P9_DPRINTK (P9_DEBUG_ERROR , "extended modes used with "
@@ -342,12 +325,37 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
342325 err = - EINVAL ;
343326 goto error ;
344327 }
328+ error :
329+ return err ;
345330
346- return inode ;
331+ }
347332
348- error :
349- iput (inode );
350- return ERR_PTR (err );
333+ /**
334+ * v9fs_get_inode - helper function to setup an inode
335+ * @sb: superblock
336+ * @mode: mode to setup inode with
337+ *
338+ */
339+
340+ struct inode * v9fs_get_inode (struct super_block * sb , int mode )
341+ {
342+ int err ;
343+ struct inode * inode ;
344+ struct v9fs_session_info * v9ses = sb -> s_fs_info ;
345+
346+ P9_DPRINTK (P9_DEBUG_VFS , "super block: %p mode: %o\n" , sb , mode );
347+
348+ inode = new_inode (sb );
349+ if (!inode ) {
350+ P9_EPRINTK (KERN_WARNING , "Problem allocating inode\n" );
351+ return ERR_PTR (- ENOMEM );
352+ }
353+ err = v9fs_init_inode (v9ses , inode , mode );
354+ if (err ) {
355+ iput (inode );
356+ return ERR_PTR (err );
357+ }
358+ return inode ;
351359}
352360
353361/*
@@ -424,39 +432,60 @@ void v9fs_evict_inode(struct inode *inode)
424432 }
425433}
426434
427- struct inode *
428- v9fs_inode ( struct v9fs_session_info * v9ses , struct p9_fid * fid ,
429- struct super_block * sb )
435+ static struct inode * v9fs_qid_iget ( struct super_block * sb ,
436+ struct p9_qid * qid ,
437+ struct p9_wstat * st )
430438{
431- int err , umode ;
432- struct inode * ret = NULL ;
433- struct p9_wstat * st ;
434-
435- st = p9_client_stat (fid );
436- if (IS_ERR (st ))
437- return ERR_CAST (st );
439+ int retval , umode ;
440+ unsigned long i_ino ;
441+ struct inode * inode ;
442+ struct v9fs_session_info * v9ses = sb -> s_fs_info ;
438443
444+ i_ino = v9fs_qid2ino (qid );
445+ inode = iget_locked (sb , i_ino );
446+ if (!inode )
447+ return ERR_PTR (- ENOMEM );
448+ if (!(inode -> i_state & I_NEW ))
449+ return inode ;
450+ /*
451+ * initialize the inode with the stat info
452+ * FIXME!! we may need support for stale inodes
453+ * later.
454+ */
439455 umode = p9mode2unixmode (v9ses , st -> mode );
440- ret = v9fs_get_inode (sb , umode );
441- if (IS_ERR (ret )) {
442- err = PTR_ERR (ret );
456+ retval = v9fs_init_inode (v9ses , inode , umode );
457+ if (retval )
443458 goto error ;
444- }
445-
446- v9fs_stat2inode (st , ret , sb );
447- ret -> i_ino = v9fs_qid2ino (& st -> qid );
448459
460+ v9fs_stat2inode (st , inode , sb );
449461#ifdef CONFIG_9P_FSCACHE
450462 v9fs_vcookie_set_qid (ret , & st -> qid );
451- v9fs_cache_inode_get_cookie (ret );
463+ v9fs_cache_inode_get_cookie (inode );
452464#endif
453- p9stat_free (st );
454- kfree (st );
455- return ret ;
465+ unlock_new_inode (inode );
466+ return inode ;
456467error :
468+ unlock_new_inode (inode );
469+ iput (inode );
470+ return ERR_PTR (retval );
471+
472+ }
473+
474+ struct inode *
475+ v9fs_inode (struct v9fs_session_info * v9ses , struct p9_fid * fid ,
476+ struct super_block * sb )
477+ {
478+ struct p9_wstat * st ;
479+ struct inode * inode = NULL ;
480+
481+ st = p9_client_stat (fid );
482+ if (IS_ERR (st ))
483+ return ERR_CAST (st );
484+
485+ inode = v9fs_qid_iget (sb , & st -> qid , st );
457486 p9stat_free (st );
458487 kfree (st );
459- return ERR_PTR ( err ) ;
488+ return inode ;
460489}
461490
462491/**
0 commit comments