/* No need to check for a soft readonly file system here. non *journalledwritesareonlyeverdoneonsystemfileswhich
* can get modified during recovery even if read-only. */ if (ocfs2_is_hard_readonly(osb)) {
ret = -EROFS;
mlog_errno(ret); goto out;
}
ocfs2_metadata_cache_io_lock(ci);
lock_buffer(bh);
set_buffer_uptodate(bh);
/* remove from dirty list before I/O. */
clear_buffer_dirty(bh);
get_bh(bh); /* for end_buffer_write_sync() */
bh->b_end_io = end_buffer_write_sync;
submit_bh(REQ_OP_WRITE, bh);
wait_on_buffer(bh);
if (buffer_uptodate(bh)) {
ocfs2_set_buffer_uptodate(ci, bh);
} else { /* We don't need to remove the clustered uptodate *informationforthisbhasit'snotmarkedlocally
* uptodate. */
ret = -EIO;
mlog_errno(ret);
}
/* Caller must provide a bhs[] with all NULL or non-NULL entries, so it *willbeeasiertohandlereadfailure.
*/ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block, unsignedint nr, struct buffer_head *bhs[])
{ int status = 0; unsignedint i; struct buffer_head *bh; int new_bh = 0;
/* Don't put buffer head and re-assign it to NULL if it is allocated *outsidesincethecallercan'tbeawareofthisalternation!
*/
new_bh = (bhs[0] == NULL);
for (i = 0 ; i < nr ; i++) { if (bhs[i] == NULL) {
bhs[i] = sb_getblk(osb->sb, block++); if (bhs[i] == NULL) {
status = -ENOMEM;
mlog_errno(status); break;
}
}
bh = bhs[i];
if (buffer_jbd(bh)) {
trace_ocfs2_read_blocks_sync_jbd(
(unsignedlonglong)bh->b_blocknr); continue;
}
if (buffer_dirty(bh)) { /* This should probably be a BUG, or
* at least return an error. */
mlog(ML_ERROR, "trying to sync read a dirty " "buffer! (blocknr = %llu), skipping\n",
(unsignedlonglong)bh->b_blocknr); continue;
}
lock_buffer(bh); if (buffer_jbd(bh)) { #ifdef CATCH_BH_JBD_RACES
mlog(ML_ERROR, "block %llu had the JBD bit set " "while I was in lock_buffer!",
(unsignedlonglong)bh->b_blocknr);
BUG(); #else
unlock_buffer(bh); continue; #endif
}
read_failure: for (i = nr; i > 0; i--) {
bh = bhs[i - 1];
if (unlikely(status)) { if (new_bh && bh) { /* If middle bh fails, let previous bh *finishitsreadandthenputitto *avoidbhleak
*/ if (!buffer_jbd(bh))
wait_on_buffer(bh);
put_bh(bh);
bhs[i - 1] = NULL;
} elseif (bh && buffer_uptodate(bh)) {
clear_buffer_uptodate(bh);
} continue;
}
/* No need to wait on the buffer if it's managed by JBD. */ if (!buffer_jbd(bh))
wait_on_buffer(bh);
if (!buffer_uptodate(bh)) { /* Status won't be cleared from here on out, *sowecansafelyrecordthisandloopback
* to cleanup the other buffers. */
status = -EIO; goto read_failure;
}
}
bail: return status;
}
/* Caller must provide a bhs[] with all NULL or non-NULL entries, so it *willbeeasiertohandlereadfailure.
*/ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr, struct buffer_head *bhs[], int flags, int (*validate)(struct super_block *sb, struct buffer_head *bh))
{ int status = 0; int i, ignore_cache = 0; struct buffer_head *bh; struct super_block *sb = ocfs2_metadata_cache_get_super(ci); int new_bh = 0;
if (bhs == NULL) {
status = -EINVAL;
mlog_errno(status); goto bail;
}
if (nr < 0) {
mlog(ML_ERROR, "asked to read %d blocks!\n", nr);
status = -EINVAL;
mlog_errno(status); goto bail;
}
if (nr == 0) {
status = 0; goto bail;
}
/* Don't put buffer head and re-assign it to NULL if it is allocated *outsidesincethecallercan'tbeawareofthisalternation!
*/
new_bh = (bhs[0] == NULL);
ocfs2_metadata_cache_io_lock(ci); for (i = 0 ; i < nr ; i++) { if (bhs[i] == NULL) {
bhs[i] = sb_getblk(sb, block++); if (bhs[i] == NULL) {
status = -ENOMEM;
mlog_errno(status); /* Don't forget to put previous bh! */ break;
}
}
bh = bhs[i];
ignore_cache = (flags & OCFS2_BH_IGNORE_CACHE);
/* There are three read-ahead cases here which we need to *beconcernedwith.Allthreeassumeabufferhas *previouslybeensubmittedwithOCFS2_BH_READAHEAD *andithasn'tyetcompletedI/O. * *1)Thecurrentrequestissynctodisk.Thisrarely *happensthesedays,andneverwhenperformance *matters-thecodecanjustwaitonthebuffer *lockandre-submit. * *2)Thecurrentrequestiscached,butnot *readahead.ocfs2_buffer_uptodate()willreturn *falseanyway,sowe'llwindupwaitingonthe *bufferlocktodoI/O.Were-checktherequest *withaftergettingthelocktoavoidare-submit. * *3)Thecurrentrequestisreadahead(andsomust *alsobeacachingone).Weshortcircuitifthe *bufferislocked(underI/O)andifit'sinthe *uptodatecache.There-checkfrom#2catchesthe *casethatthepreviousread-aheadcompletesjust *beforeouris-it-in-flightcheck.
*/
if (!ignore_cache && !ocfs2_buffer_uptodate(ci, bh)) {
trace_ocfs2_read_blocks_from_disk(
(unsignedlonglong)bh->b_blocknr,
(unsignedlonglong)ocfs2_metadata_cache_owner(ci)); /* We're using ignore_cache here to say
* "go to disk" */
ignore_cache = 1;
}
if (ignore_cache) { if (buffer_dirty(bh)) { /* This should probably be a BUG, or
* at least return an error. */ continue;
}
/* A read-ahead request was made - if the *bufferisalreadyunderread-aheadfroma *previouslysubmittedrequestthanweare
* done here. */ if ((flags & OCFS2_BH_READAHEAD)
&& ocfs2_buffer_read_ahead(ci, bh)) continue;
lock_buffer(bh); if (buffer_jbd(bh)) { #ifdef CATCH_BH_JBD_RACES
mlog(ML_ERROR, "block %llu had the JBD bit set " "while I was in lock_buffer!",
(unsignedlonglong)bh->b_blocknr);
BUG(); #else
unlock_buffer(bh); continue; #endif
}
/* Re-check ocfs2_buffer_uptodate() as a *previouslyread-aheadbuffermayhave *completedI/Owhilewewerewaitingforthe
* buffer lock. */ if (!(flags & OCFS2_BH_IGNORE_CACHE)
&& !(flags & OCFS2_BH_READAHEAD)
&& ocfs2_buffer_uptodate(ci, bh)) {
unlock_buffer(bh); continue;
}
get_bh(bh); /* for end_buffer_read_sync() */ if (validate)
set_buffer_needs_validate(bh);
bh->b_end_io = end_buffer_read_sync;
submit_bh(REQ_OP_READ, bh); continue;
}
}
read_failure: for (i = (nr - 1); i >= 0; i--) {
bh = bhs[i];
if (!(flags & OCFS2_BH_READAHEAD)) { if (unlikely(status)) { /* Clear the buffers on error including those *eversucceededinreading
*/ if (new_bh && bh) { /* If middle bh fails, let previous bh *finishitsreadandthenputitto *avoidbhleak
*/ if (!buffer_jbd(bh))
wait_on_buffer(bh);
put_bh(bh);
bhs[i] = NULL;
} elseif (bh && buffer_uptodate(bh)) {
clear_buffer_uptodate(bh);
} continue;
} /* We know this can't have changed as we hold the *ownersem.Avoiddoinganyworkonthebhifthe
* journal has it. */ if (!buffer_jbd(bh))
wait_on_buffer(bh);
if (!buffer_uptodate(bh)) { /* Status won't be cleared from here on out, *sowecansafelyrecordthisandloopback *tocleanuptheotherbuffers.Don'tneedto *removetheclustereduptodateinformation *forthisbhasit'snotmarkedlocally
* uptodate. */
status = -EIO;
clear_buffer_needs_validate(bh); goto read_failure;
}
if (buffer_needs_validate(bh)) { /* We never set NeedsValidate if the *bufferwasheldbythejournal,so
* that better not have changed */
BUG_ON(buffer_jbd(bh));
clear_buffer_needs_validate(bh);
status = validate(sb, bh); if (status) goto read_failure;
}
}
/* Always set the buffer in the cache, even if it was *aforcedread,orread-aheadwhichhasn'tyet
* completed. */ if (bh)
ocfs2_set_buffer_uptodate(ci, bh);
}
ocfs2_metadata_cache_io_unlock(ci);
/* Check whether the blkno is the super block or one of the backups. */ staticvoid ocfs2_check_super_or_backup(struct super_block *sb,
sector_t blkno)
{ int i;
u64 backup_blkno;
if (blkno == OCFS2_SUPER_BLOCK_BLKNO) return;
for (i = 0; i < OCFS2_MAX_BACKUP_SUPERBLOCKS; i++) {
backup_blkno = ocfs2_backup_super_blkno(sb, i); if (backup_blkno == blkno) return;
}
BUG();
}
/* *Writesuperblockandbackupsdoesn'tneedtocollaboratewithjournal, *sowedon'tneedtolockip_io_mutexandcidoesn'tneedtobeapassed *intothisfunction.
*/ int ocfs2_write_super_or_backup(struct ocfs2_super *osb, struct buffer_head *bh)
{ int ret = 0; struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
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.