···138138 struct gfs2_inum_host *inum)139139{140140 struct gfs2_sbd *sdp = sb->s_fs_info;141141- struct gfs2_holder i_gh;142141 struct inode *inode;143142 struct dentry *dentry;144144- int error;145143146144 inode = gfs2_ilookup(sb, inum->no_addr);147145 if (inode) {···150152 goto out_inode;151153 }152154153153- error = gfs2_glock_nq_num(sdp, inum->no_addr, &gfs2_inode_glops,154154- LM_ST_SHARED, LM_FLAG_ANY, &i_gh);155155- if (error)156156- return ERR_PTR(error);157157-158158- error = gfs2_check_blk_type(sdp, inum->no_addr, GFS2_BLKST_DINODE);159159- if (error)160160- goto fail;161161-162162- inode = gfs2_inode_lookup(sb, DT_UNKNOWN, inum->no_addr, 0);163163- if (IS_ERR(inode)) {164164- error = PTR_ERR(inode);165165- goto fail;166166- }167167-168168- error = gfs2_inode_refresh(GFS2_I(inode));169169- if (error) {170170- iput(inode);171171- goto fail;172172- }173173-174174- /* Pick up the works we bypass in gfs2_inode_lookup */175175- if (inode->i_state & I_NEW) 176176- gfs2_set_iop(inode);177177-178178- if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) {179179- iput(inode);180180- goto fail;181181- }182182-183183- error = -EIO;184184- if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM) {185185- iput(inode);186186- goto fail;187187- }188188-189189- gfs2_glock_dq_uninit(&i_gh);155155+ inode = gfs2_lookup_by_inum(sdp, inum->no_addr, &inum->no_formal_ino,156156+ GFS2_BLKST_DINODE);157157+ if (IS_ERR(inode))158158+ return ERR_CAST(inode);190159191160out_inode:192161 dentry = d_obtain_alias(inode);193162 if (!IS_ERR(dentry))194163 dentry->d_op = &gfs2_dops;195164 return dentry;196196-fail:197197- gfs2_glock_dq_uninit(&i_gh);198198- return ERR_PTR(error);199165}200166201167static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid,
+10-11
fs/gfs2/glock.c
···686686{687687 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete);688688 struct gfs2_sbd *sdp = gl->gl_sbd;689689- struct gfs2_inode *ip = NULL;689689+ struct gfs2_inode *ip;690690 struct inode *inode;691691- u64 no_addr = 0;691691+ u64 no_addr = gl->gl_name.ln_number;692692693693- spin_lock(&gl->gl_spin);694694- ip = (struct gfs2_inode *)gl->gl_object;693693+ ip = gl->gl_object;694694+ /* Note: Unsafe to dereference ip as we don't hold right refs/locks */695695+695696 if (ip)696696- no_addr = ip->i_no_addr;697697- spin_unlock(&gl->gl_spin);698698- if (ip) {699697 inode = gfs2_ilookup(sdp->sd_vfs, no_addr);700700- if (inode) {701701- d_prune_aliases(inode);702702- iput(inode);703703- }698698+ else699699+ inode = gfs2_lookup_by_inum(sdp, no_addr, NULL, GFS2_BLKST_UNLINKED);700700+ if (inode && !IS_ERR(inode)) {701701+ d_prune_aliases(inode);702702+ iput(inode);704703 }705704 gfs2_glock_put(gl);706705}
+40-122
fs/gfs2/inode.c
···7373 return iget5_locked(sb, hash, iget_test, iget_set, &no_addr);7474}75757676-struct gfs2_skip_data {7777- u64 no_addr;7878- int skipped;7979-};8080-8181-static int iget_skip_test(struct inode *inode, void *opaque)8282-{8383- struct gfs2_inode *ip = GFS2_I(inode);8484- struct gfs2_skip_data *data = opaque;8585-8686- if (ip->i_no_addr == data->no_addr) {8787- if (inode->i_state & (I_FREEING|I_WILL_FREE)){8888- data->skipped = 1;8989- return 0;9090- }9191- return 1;9292- }9393- return 0;9494-}9595-9696-static int iget_skip_set(struct inode *inode, void *opaque)9797-{9898- struct gfs2_inode *ip = GFS2_I(inode);9999- struct gfs2_skip_data *data = opaque;100100-101101- if (data->skipped)102102- return 1;103103- inode->i_ino = (unsigned long)(data->no_addr);104104- ip->i_no_addr = data->no_addr;105105- return 0;106106-}107107-108108-static struct inode *gfs2_iget_skip(struct super_block *sb,109109- u64 no_addr)110110-{111111- struct gfs2_skip_data data;112112- unsigned long hash = (unsigned long)no_addr;113113-114114- data.no_addr = no_addr;115115- data.skipped = 0;116116- return iget5_locked(sb, hash, iget_skip_test, iget_skip_set, &data);117117-}118118-11976/**12077 * GFS2 lookup code fills in vfs inode contents based on info obtained12178 * from directory entry inside gfs2_inode_lookup(). This has caused issues···200243 return ERR_PTR(error);201244}202245203203-/**204204- * gfs2_process_unlinked_inode - Lookup an unlinked inode for reclamation205205- * and try to reclaim it by doing iput.206206- *207207- * This function assumes no rgrp locks are currently held.208208- *209209- * @sb: The super block210210- * no_addr: The inode number211211- *212212- */213213-214214-void gfs2_process_unlinked_inode(struct super_block *sb, u64 no_addr)246246+struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,247247+ u64 *no_formal_ino, unsigned int blktype)215248{216216- struct gfs2_sbd *sdp;217217- struct gfs2_inode *ip;218218- struct gfs2_glock *io_gl = NULL;219219- int error;220220- struct gfs2_holder gh;249249+ struct super_block *sb = sdp->sd_vfs;250250+ struct gfs2_holder i_gh;221251 struct inode *inode;252252+ int error;222253223223- inode = gfs2_iget_skip(sb, no_addr);254254+ error = gfs2_glock_nq_num(sdp, no_addr, &gfs2_inode_glops,255255+ LM_ST_SHARED, LM_FLAG_ANY, &i_gh);256256+ if (error)257257+ return ERR_PTR(error);224258225225- if (!inode)226226- return;259259+ error = gfs2_check_blk_type(sdp, no_addr, blktype);260260+ if (error)261261+ goto fail;227262228228- /* If it's not a new inode, someone's using it, so leave it alone. */229229- if (!(inode->i_state & I_NEW)) {230230- iput(inode);231231- return;263263+ inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0);264264+ if (IS_ERR(inode))265265+ goto fail;266266+267267+ error = gfs2_inode_refresh(GFS2_I(inode));268268+ if (error)269269+ goto fail_iput;270270+271271+ /* Pick up the works we bypass in gfs2_inode_lookup */272272+ if (inode->i_state & I_NEW) 273273+ gfs2_set_iop(inode);274274+275275+ /* Two extra checks for NFS only */276276+ if (no_formal_ino) {277277+ error = -ESTALE;278278+ if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino)279279+ goto fail_iput;280280+281281+ error = -EIO;282282+ if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)283283+ goto fail_iput;284284+285285+ error = 0;232286 }233287234234- ip = GFS2_I(inode);235235- sdp = GFS2_SB(inode);236236- ip->i_no_formal_ino = -1;237237-238238- error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);239239- if (unlikely(error))240240- goto fail;241241- ip->i_gl->gl_object = ip;242242-243243- error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);244244- if (unlikely(error))245245- goto fail_put;246246-247247- set_bit(GIF_INVALID, &ip->i_flags);248248- error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, LM_FLAG_TRY | GL_EXACT,249249- &ip->i_iopen_gh);250250- if (unlikely(error))251251- goto fail_iopen;252252-253253- ip->i_iopen_gh.gh_gl->gl_object = ip;254254- gfs2_glock_put(io_gl);255255- io_gl = NULL;256256-257257- inode->i_mode = DT2IF(DT_UNKNOWN);258258-259259- /*260260- * We must read the inode in order to work out its type in261261- * this case. Note that this doesn't happen often as we normally262262- * know the type beforehand. This code path only occurs during263263- * unlinked inode recovery (where it is safe to do this glock,264264- * which is not true in the general case).265265- */266266- error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, LM_FLAG_TRY,267267- &gh);268268- if (unlikely(error))269269- goto fail_glock;270270-271271- /* Inode is now uptodate */272272- gfs2_glock_dq_uninit(&gh);273273- gfs2_set_iop(inode);274274-275275- /* The iput will cause it to be deleted. */276276- iput(inode);277277- return;278278-279279-fail_glock:280280- gfs2_glock_dq(&ip->i_iopen_gh);281281-fail_iopen:282282- if (io_gl)283283- gfs2_glock_put(io_gl);284284-fail_put:285285- ip->i_gl->gl_object = NULL;286286- gfs2_glock_put(ip->i_gl);287288fail:288288- iget_failed(inode);289289- return;289289+ gfs2_glock_dq_uninit(&i_gh);290290+ return error ? ERR_PTR(error) : inode;291291+fail_iput:292292+ iput(inode);293293+ goto fail;290294}291295292296static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
···963963 * The inode, if one has been found, in inode.964964 */965965966966-static u64 try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked,967967- u64 skip)966966+static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip)968967{969968 u32 goal = 0, block;970969 u64 no_addr;971970 struct gfs2_sbd *sdp = rgd->rd_sbd;972971 unsigned int n;972972+ struct gfs2_glock *gl;973973+ struct gfs2_inode *ip;974974+ int error;975975+ int found = 0;973976974974- for(;;) {975975- if (goal >= rgd->rd_data)976976- break;977977+ while (goal < rgd->rd_data) {977978 down_write(&sdp->sd_log_flush_lock);978979 n = 1;979980 block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED,···991990 if (no_addr == skip)992991 continue;993992 *last_unlinked = no_addr;994994- return no_addr;993993+994994+ error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &gl);995995+ if (error)996996+ continue;997997+998998+ /* If the inode is already in cache, we can ignore it here999999+ * because the existing inode disposal code will deal with10001000+ * it when all refs have gone away. Accessing gl_object like10011001+ * this is not safe in general. Here it is ok because we do10021002+ * not dereference the pointer, and we only need an approx10031003+ * answer to whether it is NULL or not.10041004+ */10051005+ ip = gl->gl_object;10061006+10071007+ if (ip || queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)10081008+ gfs2_glock_put(gl);10091009+ else10101010+ found++;10111011+10121012+ /* Limit reclaim to sensible number of tasks */10131013+ if (found > 2*NR_CPUS)10141014+ return;9951015 }99610169971017 rgd->rd_flags &= ~GFS2_RDF_CHECK;998998- return 0;10181018+ return;9991019}1000102010011021/**···10971075 * Try to acquire rgrp in way which avoids contending with others.10981076 *10991077 * Returns: errno11001100- * unlinked: the block address of an unlinked block to be reclaimed11011078 */1102107911031103-static int get_local_rgrp(struct gfs2_inode *ip, u64 *unlinked,11041104- u64 *last_unlinked)10801080+static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)11051081{11061082 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);11071083 struct gfs2_rgrpd *rgd, *begin = NULL;···11091089 int loops = 0;11101090 int error, rg_locked;1111109111121112- *unlinked = 0;11131092 rgd = gfs2_blk2rgrpd(sdp, ip->i_goal);1114109311151094 while (rgd) {···11251106 case 0:11261107 if (try_rgrp_fit(rgd, al))11271108 goto out;11281128- /* If the rg came in already locked, there's no11291129- way we can recover from a failed try_rgrp_unlink11301130- because that would require an iput which can only11311131- happen after the rgrp is unlocked. */11321132- if (!rg_locked && rgd->rd_flags & GFS2_RDF_CHECK)11331133- *unlinked = try_rgrp_unlink(rgd, last_unlinked,11341134- ip->i_no_addr);11091109+ if (rgd->rd_flags & GFS2_RDF_CHECK)11101110+ try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr);11351111 if (!rg_locked)11361112 gfs2_glock_dq_uninit(&al->al_rgd_gh);11371137- if (*unlinked)11381138- return -EAGAIN;11391113 /* fall through */11401114 case GLR_TRYFAILED:11411115 rgd = recent_rgrp_next(rgd);···11571145 case 0:11581146 if (try_rgrp_fit(rgd, al))11591147 goto out;11601160- if (!rg_locked && rgd->rd_flags & GFS2_RDF_CHECK)11611161- *unlinked = try_rgrp_unlink(rgd, last_unlinked,11621162- ip->i_no_addr);11481148+ if (rgd->rd_flags & GFS2_RDF_CHECK)11491149+ try_rgrp_unlink(rgd, last_unlinked, ip->i_no_addr);11631150 if (!rg_locked)11641151 gfs2_glock_dq_uninit(&al->al_rgd_gh);11651165- if (*unlinked)11661166- return -EAGAIN;11671152 break;1168115311691154 case GLR_TRYFAILED:···12131204 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);12141205 struct gfs2_alloc *al = ip->i_alloc;12151206 int error = 0;12161216- u64 last_unlinked = NO_BLOCK, unlinked;12071207+ u64 last_unlinked = NO_BLOCK;12081208+ int tries = 0;1217120912181210 if (gfs2_assert_warn(sdp, al->al_requested))12191211 return -EINVAL;1220121212211221-try_again:12221213 if (hold_rindex) {12231214 /* We need to hold the rindex unless the inode we're using is12241215 the rindex itself, in which case it's already held. */···12271218 else if (!sdp->sd_rgrps) /* We may not have the rindex read12281219 in, so: */12291220 error = gfs2_ri_update_special(ip);12211221+ if (error)12221222+ return error;12301223 }1231122412321232- if (error)12331233- return error;12251225+ do {12261226+ error = get_local_rgrp(ip, &last_unlinked);12271227+ /* If there is no space, flushing the log may release some */12281228+ if (error)12291229+ gfs2_log_flush(sdp, NULL);12301230+ } while (error && tries++ < 3);1234123112351235- /* Find an rgrp suitable for allocation. If it encounters any unlinked12361236- dinodes along the way, error will equal -EAGAIN and unlinked will12371237- contains it block address. We then need to look up that inode and12381238- try to free it, and try the allocation again. */12391239- error = get_local_rgrp(ip, &unlinked, &last_unlinked);12401232 if (error) {12411233 if (hold_rindex && ip != GFS2_I(sdp->sd_rindex))12421234 gfs2_glock_dq_uninit(&al->al_ri_gh);12431243- if (error != -EAGAIN)12441244- return error;12451245-12461246- gfs2_process_unlinked_inode(ip->i_inode.i_sb, unlinked);12471247- /* regardless of whether or not gfs2_process_unlinked_inode12481248- was successful, we don't want to repeat it again. */12491249- last_unlinked = unlinked;12501250- gfs2_log_flush(sdp, NULL);12511251- error = 0;12521252-12531253- goto try_again;12351235+ return error;12541236 }12371237+12551238 /* no error, so we have the rgrp set in the inode's allocation. */12561239 al->al_file = file;12571240 al->al_line = line;