@@ -158,25 +158,21 @@ void gfs2_set_iop(struct inode *inode)
158158 * @sb: The super block
159159 * @no_addr: The inode number
160160 * @type: The type of the inode
161- * @skip_freeing: set this not return an inode if it is currently being freed.
162161 *
163162 * Returns: A VFS inode, or an error
164163 */
165164
166165struct inode * gfs2_inode_lookup (struct super_block * sb ,
167166 unsigned int type ,
168167 u64 no_addr ,
169- u64 no_formal_ino , int skip_freeing )
168+ u64 no_formal_ino )
170169{
171170 struct inode * inode ;
172171 struct gfs2_inode * ip ;
173172 struct gfs2_glock * io_gl ;
174173 int error ;
175174
176- if (skip_freeing )
177- inode = gfs2_iget_skip (sb , no_addr );
178- else
179- inode = gfs2_iget (sb , no_addr );
175+ inode = gfs2_iget (sb , no_addr );
180176 ip = GFS2_I (inode );
181177
182178 if (!inode )
@@ -234,13 +230,100 @@ struct inode *gfs2_inode_lookup(struct super_block *sb,
234230fail_iopen :
235231 gfs2_glock_put (io_gl );
236232fail_put :
237- ip -> i_gl -> gl_object = NULL ;
233+ if (inode -> i_state & I_NEW )
234+ ip -> i_gl -> gl_object = NULL ;
238235 gfs2_glock_put (ip -> i_gl );
239236fail :
240- iget_failed (inode );
237+ if (inode -> i_state & I_NEW )
238+ iget_failed (inode );
239+ else
240+ iput (inode );
241241 return ERR_PTR (error );
242242}
243243
244+ /**
245+ * gfs2_unlinked_inode_lookup - Lookup an unlinked inode for reclamation
246+ * @sb: The super block
247+ * no_addr: The inode number
248+ * @@inode: A pointer to the inode found, if any
249+ *
250+ * Returns: 0 and *inode if no errors occurred. If an error occurs,
251+ * the resulting *inode may or may not be NULL.
252+ */
253+
254+ int gfs2_unlinked_inode_lookup (struct super_block * sb , u64 no_addr ,
255+ struct inode * * inode )
256+ {
257+ struct gfs2_sbd * sdp ;
258+ struct gfs2_inode * ip ;
259+ struct gfs2_glock * io_gl ;
260+ int error ;
261+ struct gfs2_holder gh ;
262+
263+ * inode = gfs2_iget_skip (sb , no_addr );
264+
265+ if (!(* inode ))
266+ return - ENOBUFS ;
267+
268+ if (!((* inode )-> i_state & I_NEW ))
269+ return - ENOBUFS ;
270+
271+ ip = GFS2_I (* inode );
272+ sdp = GFS2_SB (* inode );
273+ ip -> i_no_formal_ino = -1 ;
274+
275+ error = gfs2_glock_get (sdp , no_addr , & gfs2_inode_glops , CREATE , & ip -> i_gl );
276+ if (unlikely (error ))
277+ goto fail ;
278+ ip -> i_gl -> gl_object = ip ;
279+
280+ error = gfs2_glock_get (sdp , no_addr , & gfs2_iopen_glops , CREATE , & io_gl );
281+ if (unlikely (error ))
282+ goto fail_put ;
283+
284+ set_bit (GIF_INVALID , & ip -> i_flags );
285+ error = gfs2_glock_nq_init (io_gl , LM_ST_SHARED , LM_FLAG_TRY | GL_EXACT ,
286+ & ip -> i_iopen_gh );
287+ if (unlikely (error )) {
288+ if (error == GLR_TRYFAILED )
289+ error = 0 ;
290+ goto fail_iopen ;
291+ }
292+ ip -> i_iopen_gh .gh_gl -> gl_object = ip ;
293+ gfs2_glock_put (io_gl );
294+
295+ (* inode )-> i_mode = DT2IF (DT_UNKNOWN );
296+
297+ /*
298+ * We must read the inode in order to work out its type in
299+ * this case. Note that this doesn't happen often as we normally
300+ * know the type beforehand. This code path only occurs during
301+ * unlinked inode recovery (where it is safe to do this glock,
302+ * which is not true in the general case).
303+ */
304+ error = gfs2_glock_nq_init (ip -> i_gl , LM_ST_EXCLUSIVE , LM_FLAG_TRY ,
305+ & gh );
306+ if (unlikely (error )) {
307+ if (error == GLR_TRYFAILED )
308+ error = 0 ;
309+ goto fail_glock ;
310+ }
311+ /* Inode is now uptodate */
312+ gfs2_glock_dq_uninit (& gh );
313+ gfs2_set_iop (* inode );
314+
315+ return 0 ;
316+ fail_glock :
317+ gfs2_glock_dq (& ip -> i_iopen_gh );
318+ fail_iopen :
319+ gfs2_glock_put (io_gl );
320+ fail_put :
321+ ip -> i_gl -> gl_object = NULL ;
322+ gfs2_glock_put (ip -> i_gl );
323+ fail :
324+ return error ;
325+ }
326+
244327static int gfs2_dinode_in (struct gfs2_inode * ip , const void * buf )
245328{
246329 const struct gfs2_dinode * str = buf ;
@@ -862,7 +945,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
862945 goto fail_gunlock2 ;
863946
864947 inode = gfs2_inode_lookup (dir -> i_sb , IF2DT (mode ), inum .no_addr ,
865- inum .no_formal_ino , 0 );
948+ inum .no_formal_ino );
866949 if (IS_ERR (inode ))
867950 goto fail_gunlock2 ;
868951
0 commit comments