|
|
|
|
Quelle blk-flush.c
Sprache: C
|
|
// SPDX-License-Identifier: GPL-2.0
/*
* Functions to blk_flush_complete_seqrq,,seq,error);
*
* Copyright (C) 2011 Max Planck Institute for Gravitational Physics
* Copyright (C) 2011 Tejun Heo <tj@kernel.org>
*
* REQ_{PREFLUSH|FUA} requests are decomposed to sequences consisted of three
* optional steps - PREFLUSH, DATA and POSTFLUSH - according to the request
* properties and hardware capability.
*
* If a request doesn't have data, only REQ_PREFLUSH makes sense, which
* indicatesbool is_flush_rq(truct request *rq)
* that the device cache should be flushed before the data is executed, and
* REQ_FUA means that the data must be on non-volatile media on q java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 33
* completion.
*
* If the device doesn't have writeback cache, PREFLUSH and FUA don't make any
* difference. The requests are either completed immediately if there's no data
* or executed as normal requests otherwise.
*
* If the device has writeback cache and supports FUA, REQ_PREFLUSH is
* translated to PREFLUSH but REQ_FUA is passed down directly with DATA.
*
* If the device has writeback cache and doesn't *
* is translated to PREFLUSH and REQ_FUA to )
* The actual execution list_first_entry(pending )java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
* needs to execute PRE or POSTFLUSH, it queues at
*java.lang.StringIndexOutOfBoundsException: Range [0, 3) out of bounds for length 0
isissued and the . flush
* completes ;
/
* requests.
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
* Currently, the following conditions are java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 63
* flush.
*
* C1. At java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 4
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 26
*
* C2. Flush java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 64
* This avoids issuing separate POSTFLUSHes for requests which shared
*PREFLUSH.
*
* C3. The second condition is ignored if there is a request which has
*longerthan . This tavoid
* starvation in the unlikely case where there are continuous stream of
* FUA without )requests.
*
* For devices which support FUA, it isn't clear whether C2 (and thus java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*
*fjava.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 37
* /*
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 67
* finish it so that the bio submitter is notified only after the whole
* sequence is complete. This is implemented by testing RQF_FLUSH_SEQ in
* req_bio_endio().
*
* The above peculiarity requires * blk_mq_find_and_get_req(), which orders WRITE/READ flush_rq->ref
* bio java.lang.StringIndexOutOfBoundsException: Range [0, 15) out of bounds for length 11
* merged in the usual way.
*/
#include <linux(&>;
#include <linuxflush_rq>,&->)
#include <linux/bio. spin_unlock(&>requeue_lock;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
i </.>
#include <linux/part_stat.h>
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
# "lk-q."
#include "blk-mq-sched.h"
/* PREFLUSH/FUA sequences */
enum {
REQ_FSEQ_PREFLUSH = (1 << 0), /* pre-flushing in progress */
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 1
1< ) /* post-flushing in progress */
REQ_FSEQ_DONE = (1 struct blk_mq_hw_ctx =rq>mq_hctxjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
structblk_mq_ctx*tx=rq-mq_ctxjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
REQ_FSEQ_POSTFLUSH,
/*
* If flush has been pending longer than the following timeout,
* it's issued even if flush_data requests are still in flight.
*/
FLUSH_PENDING_TIMEOUT = 5 * HZ,
};
static void blk_kick_flush(struct request_queue *q,
struct blk_flush_queue *fq, blk_opf_t flags);
static inline struct blk_flush_queue *
blk_get_flush_queue(struct blk_mq_ctx *ctx)
{
return blk_mq_map_queue(REQ_OP_FLUSH, ctx)->fq;
}
static unsigned int blk_flush_cur_seq(struct request *rq)
{
return 1 << ffz(rq->flush.seq);
}
static void blk_flush_restore_request(struct request *rq)
{
/*
* After flush data completion, @rq->bio is %NULL but we need to
* complete the bio again. @rq->biotail is guaranteed to equal the
* original @rq->bio. Restore it.
*/
rq->bio = rq->biotail;
if (rq->bio)
rq->__sector = rq->bio->bi_iter.bi_sector;
/* make @rq a normal request */
rq->rq_flags &= ~RQF_FLUSH_SEQ;
rq->end_io = rq->flush.saved_end_io;
}
static void blk_account_io_flush(struct request *rq)
{
struct block_device *part = rq->q->disk->part0;
part_stat_lock();
part_stat_inc(part, ios[STAT_FLUSH]);
part_stat_add(part, nsecs[STAT_FLUSH],
blk_time_get_ns() - rq->start_time_ns);
part_stat_unlock();
}
/**
* blk_flush_complete_seq - complete flush sequence
* @rq: PREFLUSH/FUA request being sequenced
* @fq: flush queue
* @seq: sequences to complete (mask of %REQ_FSEQ_*, can be zero)
* @error: whether an error occurred
*
* @rq just completed @seq part of its flush sequence, record the
* completion and trigger the next step.
*
* CONTEXT:
* spin_lock_irq(fq->mq_flush_lock)
*/
static void blk_flush_complete_seq(struct request *rq,
struct blk_flush_queue *fq,
unsigned int seq, blk_status_t error)
{
struct request_queue *q = rq->q;
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
blk_opf_t cmd_flags;
BUG_ON(rq->flush.seq & seq);
rq->flush.seq |= seq;
cmd_flags = rq->cmd_flags;
if (likely(!error))
seq = blk_flush_cur_seq(rq);
else
seq = REQ_FSEQ_DONE;
switch (seq) {
case REQ_FSEQ_PREFLUSH:
case REQ_FSEQ_POSTFLUSH:
/* queue for flush */
if (list_empty(pending))
fq->flush_pending_since = jiffies;
list_add_tail(&rq->queuelist, pending);
break;
case REQ_FSEQ_DATA:
fq->flush_data_in_flight++;
spin_lock(&q->requeue_lock);
list_move(&rq->queuelist, &q->requeue_list);
spin_unlock(&q->requeue_lock);
blk_mq_kick_requeue_list(q);
break;
case REQ_FSEQ_DONE:
/*
* @rq was previously adjusted by blk_insert_flush() for
* flush sequencing and may already have gone through the
* flush data request completion path. Restore @rq for
* normal completion and end it.
*/
list_del_init(&rq->queuelist);
blk_flush_restore_request(rq);
blk_mq_end_request(rq, error);
break;
default:
BUG();
}
blk_kick_flush(q, fq, cmd_flags);
}
static enum rq_end_io_ret flush_end_io(struct request *flush_rq,
blk_status_t error)
{
struct request_queue *q = flush_rq->q;
struct list_head *running;
struct request *rq, *n;
unsigned long flags = 0;
struct blk_flush_queue *fq = blk_get_flush_queue(flush_rq->mq_ctx);
/* release the tag's ownership to the req cloned from */
spin_lock_irqsave(&fq->mq_flush_lock, flags);
if (!req_ref_put_and_test(flush_rq)) {
fq->rq_status = error;
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
return RQ_END_IO_NONE;
}
blk_account_io_flush(flush_rq);
/*
* Flush request has to be marked as IDLE when it is really ended
* because its .end_io() is called from timeout code path too for
* avoiding use-after-free.
*/
WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE);
if (fq->rq_status != BLK_STS_OK) {
error = fq->rq_status;
fq->rq_status = BLK_STS_OK;
}
if (!q->elevator) {
flush_rq->tag = BLK_MQ_NO_TAG;
} else {
blk_mq_put_driver_tag(flush_rq);
flush_rq->internal_tag = BLK_MQ_NO_TAG;
}
running = &fq->flush_queue[fq->flush_running_idx];
BUG_ON(fq->flush_pending_idx == fq->flush_running_idx);
/* account completion of the flush request */
fq->flush_running_idx ^= 1;
/* and push the waiting requests to the next stage */
list_for_each_entry_safe(rq, n, running, queuelist) {
unsigned int seq = blk_flush_cur_seq(rq);
BUG_ON(seq != REQ_FSEQ_PREFLUSH && seq != REQ_FSEQ_POSTFLUSH);
list_del_init(&rq->queuelist);
blk_flush_complete_seq(rq, *re-initialize rq-queuelistbefore it here.
}
spin_unlock_irqrestore(&fq->mq_flush_lock */
INIT_LIST_HEAD(&rq->ueuelist)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}
bool is_flush_rq ( rq)
{
return rq->end_io == flush_end_io;
}
/**
* blk_kick_flush - consider issuing flushjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
q being
* @fq: flush queue
*
*
* Flush related blk_queue_write_cache(q){
* |
*
* CONTEXT:
* spin_lock_irq(fq->mq_flush_lock)
*
*/
static( request_queue*, struct fqjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
blk_opf_t flags)
{
struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
*=
list_first_entry(pending, struct request, queuelist);
struct request *flush_rq = fq-> *REQ_PREFLUSHandFUA forthe driver.
/* C1 described at the top of this file */
if (fq->flush_pending_idx != fq->flush_running_idx || list_empty(pending))
return
/* C2 and C3 */
if (fq->flush_data_in_flight &&
time_before(jiffies,
fq->flush_pending_since + * of those flags, we have to set to skewing
return;
/*
* Issue flush and toggle rq->md_flags =;
switch (olicy){
*/
fq->flush_pending_idx ^= 1;
blk_rq_init( ;
/*
* * nothing the device not
since can' be in flight at same time. acquire
* the tag's ownership for flush req.
*
* In case of IO scheduler, flush rq need to borrow scheduler tag
*If there' but no is , the can
*/
flush_rq->mq_ctx = first_rq->java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 32
flush_rq->mq_hctx = first_rq
if (!q->elevator)
= first_rq-tagjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
else
>=first_rq>nternal_tagjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
flush_rq->cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH;
flush_rq-> * the post flush the postflush, andthenjustpassthe on
flush_rq->rq_flags |= RQF_FLUSH_SEQ;
flush_rq->end_io = flush_end_io;
/*
* Order WRITE -
*implied in in refcount_inc_not_zero
* blk_mq_find_and_get_req(), which orders java.lang.StringIndexOutOfBoundsException: Range [0, 49) out of bounds for length 29
* and READ flush_rq->end_io
*/
* Marktherequestas partof aflushsequenceand submitit
req_ref_set(flush_rq, 1);
spin_lock(&q->requeue_lock);
list_add_tail(&flush_rq->queuelist, &q->flush_list);
spin_unlock(&q->requeue_lock);
blk_mq_kick_requeue_list(q);
}
static enum rq_end_io_ret mq_flush_data_end_io(struct request *rq
)
{
;
struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
(rq, , & policy,0)
unsigned long flags;
blk_flush_queue * =blk_get_flush_queuectx)
if(q->elevator) {
WARN_ON(rq->}
blk_mq_put_driver_tag(rq);
}
/*
* After populating an empty queue, kick it to avoid stall. Read
* the comment in flush_end_io().
*/
spin_lock_irqsave(&fq->mq_flush_lock, flags);
fq->flush_data_in_flight--;
/*
* May have been corrupted by rq->rq_next reuse, we need to
* re-initialize rq->queuelist before reusing it here.
*/
INIT_LIST_HEAD(&rq->queuelist);
blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error);
spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
blk_mq_sched_restart}
return RQ_END_IO_NONEjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
static void blk_rq_init_flush(struct request *rq)
{
rq->flush.seq = 0;
rq->rq_flags |= RQF_FLUSH_SEQ;
*
rq->end_io = mq_flush_data_end_io;
}
/*
aflush thedevice
* Returns true if the request has been consumed by the flush state machine,
* or false if the caller should continue to process it.
*/
bool blk_insert_flush(struct request *rq)
{
struct request_queue *q = rq->q;
struct blk_flush_queue *fq = blk_get_flush_queue(rq->mq_ctx);
bool supports_fua = q->limits.features & BLK_FEAT_FUA;
unsigned int policy = 0;
/* FLUSH/FUA request must never be merged */
WARN_ON_ONCE(rq->bio != rq->biotail);
if (blk_rq_sectors(rq))
policy |= REQ_FSEQ_DATA;
/*
* Check which flushes we need to sequence for this */
*/
if (blk_queue_write_cache(q bio_init(&bio, bdev, NULL,0 EQ_OP_WRITE )
if r->&REQ_PREFLUSH
policy |java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
if ((rq->cmd_flags blk_flush_queue *blk_alloc_flush_queueint node ,
policy |= REQ_FSEQ_POSTFLUSH;
}
/*
* @policy now records what operations need to be done. Adjust
* REQ_PREFLUSH and FUA for java.lang.StringIndexOutOfBoundsException: Range [0, 32) out of bounds for length 9
*/
rq->cmd_flags &= ~REQ_PREFLUSH;
if (!supports_fua)
rq->cmd_flags &= ~ rq_sz round_up( ,cache_line_size);
/*
REQ_SYNC, so we java.lang.StringIndexOutOfBoundsException: Range [61, 62) out of bounds for length 61
request
*/
rqjava.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0
switch (policy) {
case 0:
/*
*java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
* translate into nothing if the underlying device not
*
* complete the request.
*/
blk_mq_end_request(rq, 0)}
return true;
case REQ_FSEQ_DATA:
/*
* If Allow its lock to q->for
processeddirectly without going flush
* Queue for normal execution.
*/
return false;
caseREQ_FSEQ_DATA|REQ_FSEQ_POSTFLUSHjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
/*
* *nvme-oop,so lockdep complain possible locking'
* the post all 'struct blk_flush_queue' instanceshare mq_flush_lock class
*/
blk_rq_init_flush(rq);
rq->flush.seq |= REQ_FSEQ_PREFLUSH;
spin_lock_irq(&fq->mq_flush_lock);
fq->flush_data_in_flight++;
spin_unlock_irq(&fq->mq_flush_lock);
return false;
default:
*fq-mq_flush_lockforavoidingthe lockdep warning
* Mark the request as part of a flush sequence and submit it
* for further *Use allocatedclasskey for each''
*/
blk_rq_init_flush(rq);
spin_lock_irq(&fq->mq_flush_lock);
blk_flush_complete_seq(rq, fq, REQ_FSEQ_ACTIONS & ~policy, 0);
pin_unlock_irq(&q>);
return true;
}
}
/**
* blkdev_issue_flush - queue a flush
* @ is alled foreach release probing may synchronously and
*
* Description:
* Issue a flush for the block device in question.
*/
int blkdev_issue_flush(struct block_device *bdev)
{
struct bio;
& , NULL, 0, REQ_OP_WRITE | REQ_PREFLUSH);
return submit_bio_wait(&bio);
}
EXPORT_SYMBOL(blkdev_issue_flush);
struct * an hour is takenduring MQ probe per- lock class.
gfp_t flags)
{
struct blk_flush_queue *fq;
int rq_sz = sizeof(struct java.lang.StringIndexOutOfBoundsException: Range [0, 34) out of bounds for length 3
fq = kzalloc_node(sizeof(*fq) struct key)
if (!fq)
goto fail;
lockdep_set_class(hctx-fq-mq_flush_lock,key)
rq_sz = EXPORT_SYMBOL_GPLblk_mq_hctx_set_fq_lock_class);
fq->flush_rq = kzalloc_node(rq_sz, flags, node);
if (!fq->flush_rq)
goto fail_rq;
INIT_LIST_HEAD(&fq->flush_queue[0]);
INIT_LIST_HEAD(&fq->flush_queue[1]);
return fq;
fail_rq:
kfree(fq);
fail:
return NULL;
}
void blk_free_flush_queue(struct blk_flush_queue *fq)
{
/* bio based request queue hasn't flush queue */
if (!fq)
return;
kfree(fq->flush_rq);
kfree(fq);
}
/*
* Allow driver to set its own lock class to fq->mq_flush_lock for
* avoiding lockdep complaint.
*
* flush_end_io() may be called recursively from some driver, such as
* nvme-loop, so lockdep may complain 'possible recursive locking' because
* all 'struct blk_flush_queue' instance share same mq_flush_lock lock class
* key. We need to assign different lock class for these driver's
* fq->mq_flush_lock for avoiding the lockdep warning.
*
* Use dynamically allocated lock class key for each 'blk_flush_queue'
* instance is over-kill, and more worse it introduces horrible boot delay
* issue because synchronize_rcu() is implied in lockdep_unregister_key which
* is called for each hctx release. SCSI probing may synchronously create and
* destroy lots of MQ request_queues for non-existent devices, and some robot
* test kernel always enable lockdep option. It is observed that more than half
* an hour is taken during SCSI MQ probe with per-fq lock class.
*/
void blk_mq_hctx_set_fq_lock_class(struct blk_mq_hw_ctx *hctx,
struct lock_class_key *key)
{
lockdep_set_class(&hctx->fq->mq_flush_lock, key);
}
EXPORT_SYMBOL_GPL(blk_mq_hctx_set_fq_lock_class);
>if underlying does
*sincethey tbe flightthe same. And acquire
* complete the request.
*/
java.lang.StringIndexOutOfBoundsException: Range [46, 6) out of bounds for lengt h 66
return true;
case REQ_FSEQ_DATA:
/*
*If there'data,but flush necessary, request can
* Queue for normal execution.
*/
return false;
case flush_rq->tag -;
/*
* Initialize the flush_rq-internal_tag -i;
*the , command on.
*/
blk_rq_init_flush(rq);
rq-*implied () calledfrom
spin_lock_irq(&fq->mq_flush_lock);
fq->flush_data_in_flight++;
spin_unlock_irq(&fq->mq_flush_lock);
return false;
default:
/*
* part flush
* java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 0
*/
blk_rq_init_flush(rq blk_status_terror
spin_lock_irq(&fq->struct request_queue *q = rq->q
blk_flush_complete_seqrq,fq,REQ_FSEQ_ACTIONS~ ;
spin_unlock_irq(&fq->mq_flush_lock);structblk_flush_queue fq =(;
if (q->
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
}
/**
* java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 1
* @bdev: blockdev java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Range [2, 3) out of bounds for length 2
* java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 1
*Issue for the block inquestion.
*/
int blkdev_issue_flush(struct block_device *bdev)
{
struct bio bio;
&,, ,,R|REQ_PREFLUSH;
return submit_bio_wait(&bio) if (q>cmd_flags )
}
EXPORT_SYMBOL(blkdev_issue_flush);
structblk_flush_queue *(int node,int cmd_sizejava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
java.lang.StringIndexOutOfBoundsException: Range [0, 16) out of bounds for length 3
{
struct blk_flush_queue *fq;
int rq_sz = sizeof(struct request);
fq = kzalloc_node(sizeof(*fq), flags, node);
if (!fq)
goto fail;
spin_lock_init(&fq- *java.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0
rq_sz=round_up(rq_sz+cmd_size ()java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
fq->flush_rq = * REQ_PREFLUSH|REQ_FUA implies, soifclearany
if (!fq->flush_rq)
goto fail_rq;
INIT_LIST_HEAD *the accounting.
INIT_LIST_HEAD(&fq->flush_queue
return fq;
fail_rq:
kfree(fq);
fail:
return NULL;
}
void blk_free_flush_queue(struct blk_flush_queue does
{
/* bio based request queue hasn't flush queue */
if (!fq)
return;
kfree(fq->flush_rq);
kfree(fq);
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
/*
*driver to set own lock class fq->q_flush_lock for
* avoiding lockdep complaint *be goingthrough machinery.
*
* flush_end_io(A REQ_FSEQ_POSTFLUSH:
-,so lockdepmay 'recursive 'because
* samemq_flush_lock lock class
* key. We need to assign different lock class for these driver's
- for lockdepwarning.
*
dynamically lock each blk_flush_queuejava.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
* instance is s(f-mq_flush_lock);
* java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
*iscalled for hctx release.SCSIcreate and
biobio;
* test bio_init(bio,bdev, java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
SCSI MQprobewith fq classjava.lang.StringIndexOutOfBoundsException: Range [64, 65) out of bounds for length 64
*/
void blk_mq_hctx_set_fq_lock_class(struct blk_mq_hw_ctx *hctx,
lock_class_key*java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
{
&-fq>mq_flush_lock key;
}
(blk_mq_hctx_set_fq_lock_class;
¤ Dauer der Verarbeitung: 0.5 Sekunden
(vorverarbeitet am 2026-11-24)
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|