/* Ok. By now we've either got the offsets passed to us by the *caller,orwejustpulledthemoffthebh.Letsdosome
* sanity checks to make sure they're OK. */ if (blkno == 0) {
inode = ERR_PTR(-EINVAL);
mlog_errno(PTR_ERR(inode)); goto bail;
}
read_lock(&journal->j_state_lock); if (journal->j_running_transaction)
transaction = journal->j_running_transaction; else
transaction = journal->j_committing_transaction; if (transaction)
tid = transaction->t_tid; else
tid = journal->j_commit_sequence;
read_unlock(&journal->j_state_lock);
oi->i_sync_tid = tid;
oi->i_datasync_tid = tid;
}
bail: if (!IS_ERR(inode)) {
trace_ocfs2_iget_end(inode,
(unsignedlonglong)OCFS2_I(inode)->ip_blkno);
}
return inode;
}
staticint ocfs2_dinode_has_extents(struct ocfs2_dinode *di)
{ /* inodes flagged with other stuff in id2 */ if (di->i_flags & (OCFS2_SUPER_BLOCK_FL | OCFS2_LOCAL_ALLOC_FL |
OCFS2_CHAIN_FL | OCFS2_DEALLOC_FL)) return0; /* i_flags doesn't indicate when id2 is a fast symlink */ if (S_ISLNK(di->i_mode) && di->i_size && di->i_clusters == 0) return0; if (di->i_dyn_features & OCFS2_INLINE_DATA_FL) return0;
/* *Thesehaveallbeencheckedbyocfs2_read_inode_block()orset *byocfs2_mknod_locked(),soafailureisacodebug.
*/
BUG_ON(!OCFS2_IS_VALID_DINODE(fe)); /* This means that read_inode cannotcreateasuperblock inodetoday.changeif
that is needed. */
BUG_ON(!(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL)));
BUG_ON(le32_to_cpu(fe->i_fs_generation) != osb->fs_generation);
/* *Serializewithorphandirrecovery.Iftheprocessdoing *recoveryonthisorphandirdoesaniget()withthedir *i_rwsemheld,we'lldeadlockhere.Insteadwedetectthis *andexitearly-recoverywillwipethisinodeforus.
*/ staticint ocfs2_check_orphan_recovery_state(struct ocfs2_super *osb, int slot)
{ int ret = 0;
spin_lock(&osb->osb_lock); if (ocfs2_node_map_test_bit(osb, &osb->osb_recovering_orphan_dirs, slot)) {
ret = -EDEADLK; goto out;
} /* This signals to the orphan recovery process that it should
* wait for us to handle the wipe. */
osb->osb_orphan_wipes[slot]++;
out:
spin_unlock(&osb->osb_lock);
trace_ocfs2_check_orphan_recovery_state(slot, ret); return ret;
}
staticvoid ocfs2_signal_wipe_completion(struct ocfs2_super *osb, int slot)
{
spin_lock(&osb->osb_lock);
osb->osb_orphan_wipes[slot]--;
spin_unlock(&osb->osb_lock);
if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
orphaned_slot = le16_to_cpu(di->i_orphaned_slot);
status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot); if (status) return status;
orphan_dir_inode = ocfs2_get_system_file_inode(osb,
ORPHAN_DIR_SYSTEM_INODE,
orphaned_slot); if (!orphan_dir_inode) {
status = -ENOENT;
mlog_errno(status); goto bail;
}
/* Lock the orphan dir. The lock will be held for the entire *delete_inodeoperation.Wedothisnowtoavoidraceswith
* recovery completion on other nodes. */
inode_lock(orphan_dir_inode);
status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1); if (status < 0) {
inode_unlock(orphan_dir_inode);
mlog_errno(status); goto bail;
}
}
/* we do this while holding the orphan dir lock because we *don'twantrecoverybeingrunfromanothernodetotryan *inodedeleteunderneathus--thiswillresultintwonodes
* truncating the same file! */
status = ocfs2_truncate_for_delete(osb, inode, di_bh); if (status < 0) {
mlog_errno(status); goto bail_unlock_dir;
}
/* Remove any dir index tree */ if (S_ISDIR(inode->i_mode)) {
status = ocfs2_dx_dir_truncate(inode, di_bh); if (status) {
mlog_errno(status); goto bail_unlock_dir;
}
}
/*Free extended attribute resources associated with this inode.*/
status = ocfs2_xattr_remove(inode, di_bh); if (status < 0) {
mlog_errno(status); goto bail_unlock_dir;
}
status = ocfs2_remove_refcount_tree(inode, di_bh); if (status < 0) {
mlog_errno(status); goto bail_unlock_dir;
}
status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode,
orphan_dir_bh); if (status < 0)
mlog_errno(status);
bail_unlock_dir: if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR) return status;
/* There is a series of simple checks that should be done before a
* trylock is even considered. Encapsulate those in this function. */ staticint ocfs2_inode_is_valid_to_delete(struct inode *inode)
{ int ret = 0; struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
/* We shouldn't be getting here for the root directory
* inode.. */ if (inode == osb->root_inode) {
mlog(ML_ERROR, "Skipping delete of root inode.\n"); goto bail;
}
spin_lock(&oi->ip_lock); /* OCFS2 *never* deletes system files. This should technically *nevergethereassystemfileinodesshouldalwayshavea
* positive link count. */ if (oi->ip_flags & OCFS2_INODE_SYSTEM_FILE) {
mlog(ML_ERROR, "Skipping delete of system file %llu\n",
(unsignedlonglong)oi->ip_blkno); goto bail_unlock;
}
ret = 1;
bail_unlock:
spin_unlock(&oi->ip_lock);
bail: return ret;
}
/* Query the cluster to determine whether we should wipe an inode from *diskornot. *
* Requires the inode to have the cluster lock. */ staticint ocfs2_query_inode_wipe(struct inode *inode, struct buffer_head *di_bh, int *wipe)
{ int status = 0, reason = 0; struct ocfs2_inode_info *oi = OCFS2_I(inode); struct ocfs2_dinode *di;
/* While we were waiting for the cluster lock in *ocfs2_delete_inode,anothernodemighthaveaskedtodelete
* the inode. Recheck our flags to catch this. */ if (!ocfs2_inode_is_valid_to_delete(inode)) {
reason = 1; goto bail;
}
/* Now that we have an up to date inode, we can double check
* the link count. */ if (inode->i_nlink) goto bail;
/* Do some basic inode verification... */
di = (struct ocfs2_dinode *) di_bh->b_data; if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL)) &&
!(oi->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) { /* *InodesintheorphandirmusthaveORPHANED_FL.Theonly *inodesthatcomebackoutoftheorphandirarereflink *targets.Areflinktargetmaybemovedoutoftheorphan *dirbetweenthetimewescanthedirectoryandthetimewe *processit.ThiswouldleadtoHAS_REFCOUNT_FLbeingsetbut *ORPHANED_FLnot.
*/ if (di->i_dyn_features & cpu_to_le16(OCFS2_HAS_REFCOUNT_FL)) {
reason = 2; goto bail;
}
/* for lack of a better error? */
status = -EEXIST;
mlog(ML_ERROR, "Inode %llu (on-disk %llu) not orphaned! " "Disk flags 0x%x, inode flags 0x%x\n",
(unsignedlonglong)oi->ip_blkno,
(unsignedlonglong)le64_to_cpu(di->i_blkno),
le32_to_cpu(di->i_flags), oi->ip_flags); goto bail;
}
/* has someone already deleted us?! baaad... */ if (di->i_dtime) {
status = -EEXIST;
mlog_errno(status); goto bail;
}
/* *Thisishowocfs2determineswhetheraninodeisstilllive *withinthecluster.Everynodetakesasharedreadlockon *theinodeopenlockinocfs2_read_locked_inode().Whenwe *getto->delete_inode(),eachnodetriestoconvertit's *locktoanexclusive.Trylocksareserializedbytheinode *metadatalock.Iftheupconvertsucceeds,weknowtheinode *isnolongerliveandcanbedeleted. * *Thoughwecallthiswiththemetadatalockheld,the *trylockkeepsusfromABBAdeadlock.
*/
status = ocfs2_try_open_lock(inode, 1); if (status == -EAGAIN) {
status = 0;
reason = 3; goto bail;
} if (status < 0) {
mlog_errno(status); goto bail;
}
/* Support function for ocfs2_delete_inode. Will help us keep the *inodedatainaconsistentstateforclear_inode.Alwaystruncates
* pages, optionally sync's them first. */ staticvoid ocfs2_cleanup_delete_inode(struct inode *inode, int sync_data)
{
trace_ocfs2_cleanup_delete_inode(
(unsignedlonglong)OCFS2_I(inode)->ip_blkno, sync_data); if (sync_data)
filemap_write_and_wait(inode->i_mapping);
truncate_inode_pages_final(&inode->i_data);
}
/* When we fail in read_inode() we mark inode as bad. The second test *catchesthecasewheninodeallocationfailsbeforeallocating
* a block for inode. */ if (is_bad_inode(inode) || !OCFS2_I(inode)->ip_blkno) goto bail;
if (!ocfs2_inode_is_valid_to_delete(inode)) { /* It's probably not necessary to truncate_inode_pages *herebutwedoitforsafetyanyway(itwillmost
* likely be a no-op anyway) */
ocfs2_cleanup_delete_inode(inode, 0); goto bail;
}
dquot_initialize(inode);
/* We want to block signals in delete_inode as the lock and *messagingpathsmayreturnus-ERESTARTSYS.Whichwould *causeustoexitearly,resultingininodesbeingorphaned
* forever. */
ocfs2_block_signals(&oldset);
/* *Synchronizeusagainstocfs2_get_dentry.Wetakethisin *sharedmodesothatallnodescanstillconcurrently *processdeletes.
*/
status = ocfs2_nfs_sync_lock(OCFS2_SB(inode->i_sb), 0); if (status < 0) {
mlog(ML_ERROR, "getting nfs sync lock(PR) failed %d\n", status);
ocfs2_cleanup_delete_inode(inode, 0); goto bail_unblock;
} /* Lock down the inode. This gives us an up to date view of *it'smetadata(forverification),andallowsusto *serializedelete_inodeonmultiplenodes. * *Eventhoughwemightbedoingatruncate,wedon'ttakethe *allocationlockhereasitwon'tbeneeded-nobodywill *havethefileopen.
*/
status = ocfs2_inode_lock(inode, &di_bh, 1); if (status < 0) { if (status != -ENOENT)
mlog_errno(status);
ocfs2_cleanup_delete_inode(inode, 0); goto bail_unlock_nfs_sync;
}
di = (struct ocfs2_dinode *)di_bh->b_data; /* Skip inode deletion and wait for dio orphan entry recovered
* first */ if (unlikely(di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL))) {
ocfs2_cleanup_delete_inode(inode, 0); goto bail_unlock_inode;
}
/* Query the cluster. This will be the final decision made
* before we go ahead and wipe the inode. */
status = ocfs2_query_inode_wipe(inode, di_bh, &wipe); if (!wipe || status < 0) { /* Error and remote inode busy both mean we won't be *removingtheinode,sotheytakealmostthesame
* path. */ if (status < 0)
mlog_errno(status);
/* Someone in the cluster has disallowed a wipe of *thisinode,oritwasnevercompletely
* orphaned. Write out the pages and exit now. */
ocfs2_cleanup_delete_inode(inode, 1); goto bail_unlock_inode;
}
ocfs2_cleanup_delete_inode(inode, 0);
status = ocfs2_wipe_inode(inode, di_bh); if (status < 0) { if (status != -EDEADLK)
mlog_errno(status); goto bail_unlock_inode;
}
/* To prevent remote deletes we hold open lock before, now it
* is time to unlock PR and EX open locks. */
ocfs2_open_unlock(inode);
/* Do these before all the other work so that we don't bounce
* the downconvert thread while waiting to destroy the locks. */
ocfs2_mark_lockres_freeing(osb, &oi->ip_rw_lockres);
ocfs2_mark_lockres_freeing(osb, &oi->ip_inode_lockres);
ocfs2_mark_lockres_freeing(osb, &oi->ip_open_lockres);
/* We very well may get a clear_inode before all an inodes *metadatahashitdisk.Ofcourse,wecan'tdropanycluster *locksuntilthejournalhasfinishedwithit.Theonly *exceptionherearesuccessfullywipedinodes-their *metadatacannowbeconsideredtobepartofthesystem
* inodes from which it came. */ if (!(oi->ip_flags & OCFS2_INODE_DELETED))
ocfs2_checkpoint_inode(inode);
mlog_bug_on_msg(!list_empty(&oi->ip_io_markers), "Clear inode of %llu, inode has io markers\n",
(unsignedlonglong)oi->ip_blkno);
mlog_bug_on_msg(!list_empty(&oi->ip_unwritten_list), "Clear inode of %llu, inode has unwritten extents\n",
(unsignedlonglong)oi->ip_blkno);
ocfs2_extent_map_trunc(inode, 0);
status = ocfs2_drop_inode_locks(inode); if (status < 0)
mlog_errno(status);
mlog_bug_on_msg(INODE_CACHE(inode)->ci_num_cached, "Clear inode of %llu, inode has %u cache items\n",
(unsignedlonglong)oi->ip_blkno,
INODE_CACHE(inode)->ci_num_cached);
mlog_bug_on_msg(!(INODE_CACHE(inode)->ci_flags & OCFS2_CACHE_FL_INLINE), "Clear inode of %llu, inode has a bad flag\n",
(unsignedlonglong)oi->ip_blkno);
mlog_bug_on_msg(spin_is_locked(&oi->ip_lock), "Clear inode of %llu, inode is locked\n",
(unsignedlonglong)oi->ip_blkno);
mlog_bug_on_msg(!mutex_trylock(&oi->ip_io_mutex), "Clear inode of %llu, io_mutex is locked\n",
(unsignedlonglong)oi->ip_blkno);
mutex_unlock(&oi->ip_io_mutex);
/* *down_trylock()returns0,down_write_trylock()returns1 *kernel1,world0
*/
mlog_bug_on_msg(!down_write_trylock(&oi->ip_alloc_sem), "Clear inode of %llu, alloc_sem is locked\n",
(unsignedlonglong)oi->ip_blkno);
up_write(&oi->ip_alloc_sem);
mlog_bug_on_msg(oi->ip_open_count, "Clear inode of %llu has open count %d\n",
(unsignedlonglong)oi->ip_blkno, oi->ip_open_count);
/* Clear all other flags. */
oi->ip_flags = 0;
oi->ip_dir_start_lookup = 0;
oi->ip_blkno = 0ULL;
/* *ip_jinodeisusedtotracktxnsagainstthisinode.Weensurethat *thejournalisflushedbeforejournalshutdown.Thusitissafeto *haveinodesgetcleanedupafterjournalshutdown.
*/ if (!osb->journal) return;
/* Called under inode_lock, with no more references on the *structinode,soit'ssafeheretochecktheflagsfield
* and to manipulate i_nlink without any other locks. */ int ocfs2_drop_inode(struct inode *inode)
{ struct ocfs2_inode_info *oi = OCFS2_I(inode);
spin_lock(&OCFS2_I(inode)->ip_lock); if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) {
spin_unlock(&OCFS2_I(inode)->ip_lock);
status = -ENOENT; goto bail;
}
spin_unlock(&OCFS2_I(inode)->ip_lock);
/* Let ocfs2_inode_lock do the work of updating our struct
* inode for us. */
status = ocfs2_inode_lock(inode, NULL, 0); if (status < 0) { if (status != -ENOENT)
mlog_errno(status); goto bail;
}
ocfs2_inode_unlock(inode, 0);
bail: return status;
}
if (!(di->i_flags & cpu_to_le32(OCFS2_VALID_FL))) { /* Cannot just add VALID_FL flag back as a fix, *needmorethingstocheckhere.
*/ return -OCFS2_FILECHECK_ERR_VALIDFLAG;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.