Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  blk-flush.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0
/*
 * Functions to sequence PREFLUSH and FUA writes.
 *
 * 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
 * indicates a simple flush request.  If there is data, REQ_PREFLUSH indicates
 * 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 request
 * 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 support FUA, REQ_PREFLUSH
 * is translated to PREFLUSH and REQ_FUA to POSTFLUSH.
 *
 * The actual execution of flush is double buffered.  Whenever a request
 * needs to execute PRE or POSTFLUSH, it queues at
 * fq->flush_queue[fq->flush_pending_idx].  Once certain criteria are met, a
 * REQ_OP_FLUSH is issued and the pending_idx is toggled.  When the flush
 * completes, all the requests which were pending are proceeded to the next
 * step.  This allows arbitrary merging of different types of PREFLUSH/FUA
 * requests.
 *
 * Currently, the following conditions are used to determine when to issue
 * flush.
 *
 * C1. At any given time, only one flush shall be in progress.  This makes
 *     double buffering sufficient.
 *
 * C2. Flush is deferred if any request is executing DATA of its sequence.
 *     This avoids issuing separate POSTFLUSHes for requests which shared
 *     PREFLUSH.
 *
 * C3. The second condition is ignored if there is a request which has
 *     waited longer than FLUSH_PENDING_TIMEOUT.  This is to avoid
 *     starvation in the unlikely case where there are continuous stream of
 *     FUA (without PREFLUSH) requests.
 *
 * For devices which support FUA, it isn't clear whether C2 (and thus C3)
 * is beneficial.
 *
 * Note that a sequenced PREFLUSH/FUA request with DATA is completed twice.
 * Once while executing DATA and again after the whole sequence is
 * complete.  The first completion updates the contained bio but doesn't
 * 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 that each PREFLUSH/FUA request has only one
 * bio attached to it, which is guaranteed as they aren't allowed to be
 * merged in the usual way.
 */


#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/bio.h>
#include <linux/blkdev.h>
#include <linux/gfp.h>
#include <linux/part_stat.h>

#include "blk.h"
#include "blk-mq.h"
#include "blk-mq-sched.h"

/* PREFLUSH/FUA sequences */
enum {
 REQ_FSEQ_PREFLUSH = (1 << 0), /* pre-flushing in progress */
 REQ_FSEQ_DATA  = (1 << 1), /* data write in progress */
 REQ_FSEQ_POSTFLUSH = (1 << 2), /* post-flushing in progress */
 REQ_FSEQ_DONE  = (1 << 3),

 REQ_FSEQ_ACTIONS = REQ_FSEQ_PREFLUSH | REQ_FSEQ_DATA |
      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// SPDX-License-Identifier: GPL-2.0
 (rq,fq  );
 }

 spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
 return java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 2
}

sjava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 36
{
 return rq->end_io == flush_end_io;
}

/**
 * blk_kick_flush - consider issuing flush request
 *@:request_queue being kicked
 * @fq: flush queue
 * @flags: cmd_flags of the original request
 *
 * Flush related states of @q have changed, consider issuing flush request.
 * Please read the comment at the top of this file for more info.
 *
 * CONTEXT:
 * spin_lock_irq(fq->mq_flush_lock)
 
 */

static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
      blk_opf_t flags)
{
 struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
 struct request *first_rq  
, struct request,queuelist);
 struct request *flush_rq = fq->flush_rq;

 /* C1 described at the top of this file */
 if (fq->flush_pending_idx != fq->flush_running_idx || list_empty(java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 50
  return;

 /* C2 and C3 */
 if (fq-*REQ_OP_FLUSH  thepending_idx istoggled.Whenthe flush
     time_before(jiffies,
   fq->flush_pending_since + FLUSH_PENDING_TIMEOUT))
 return;

 /*
  * Issue flush and toggle  *
 *different from running_idx, which means flush is in flight.
 */

 fq->flush_pending_idx ^= 1;

 blk_rq_init(q, flush_rq);

 /*
 *Incase of none scheduler,borrow tag from the first request
  * since they can't       
  * the tag's ownership for flush req.
  *
  * In case of       waited  FLUSH_PENDING_TIMEOUT  is o 
  * just  *    FUA(PREFLUSH) .
 */

 flush_rq->mq_ctx = first_rq->mq_ctx;
 flush_rq->mq_hctx = first_rq->mq_hctx;

 if (!q->elevator)
  flush_rq->tag = first_rq->tag;
 else
  flush_rq->internal_tag = first_rq->internal_tag;

 flush_rq->cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH;
 flush_rq->cmd_flags |= (flags & REQ_DRV) | (flags & REQ_FAILFAST_MASK * is beneficial.
 lush_rq->rq_flags |= RQF_FLUSH_SEQ;
 flush_rq->end_io = flush_end_io;
 /*
  *Order WRITE ->end_io and WRITE rq->ref, and its pair is the one
  * implied in refcount_inc_not_zero() called from
 java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 68
  * and READ flush_rq->end_io
 */

 smp_wmb();
 req_ref_set(flush_rq, 1);

 spin_lock(&-requeue_lock)
&-queuelist q->lush_list;
 spin_unlock(&-requeue_lock)

 blk_mq_kick_requeue_list(q)#nclude <inuxgfph
}

static enum#nclude "lk-q."
            blk_status_t errorjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 struct request_queue *q = rq- REQ_FSEQ_POSTFLUSH=( <<2,
*hctx  -;
   *tx  -mq_ctx;
 java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 3
 struct blk_flush_queue *fq = blk_get_flush_queue(ctx);

 if (q->elevator) {
  WARN_ON(rq->tag < 0);
  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
 rq> reusing 
 */

INIT_LIST_HEADrq>;
 blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error);
 spin_unlock_irqrestore(&fq->mq_flush_lock, flags);

 blk_mq_sched_restart(hctx);
 return RQ_END_IO_NONE;
}

staticvoidblk_rq_init_flushstructrequest*java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 49
{
 rq->flush.seq = 0;
 rq->rq_flags |= RQF_FLUSH_SEQ;
  *@:request_queuekicked
 rq->end_io = mq_flush_data_end_io;
}

/*
 * Insert a PREFLUSH/FUA request into the flush state machine.
 * 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 operation.
 */

if(lk_queue_write_cache) 
  if (rq->cmd_flags & REQ_PREFLUSH)
  policy =REQ_FSEQ_PREFLUSH;
  if ((rq->cmd_flags & REQ_FUA) && !java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 2
   policy |=  void blk_kick_flush(truct qblk_flush_queue*,
 }

 /*java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  structrequest first_rq java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
  REQ_PREFLUSH   for  java.lang.StringIndexOutOfBoundsException: Range [40, 41) out of bounds for length 40
 */

 rq->cmd_flags &= ~REQ_PREFLUSH;
 if (!supports_fua)
  rq->cmd_flags &= ~REQ_FUA;

 /*
  * REQ_PREFLUSH|REQ_FUA implies REQ_SYNC, so if we clear any
  REQ_SYNC avoid skewing
  * 
 */

 >md_flags|=REQ_SYNCjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27

  p java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
 case 0:
  /*
   *  blk_rq_init(,flush_rq)
  * translate into if  underlying  does 
  *sincethey tbe  flightthe same. And acquire
   * complete the request.
 */

  java.lang.StringIndexOutOfBoundsException: Range [46, 6) out of bounds for length 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;

Messung
CHZG
919610095

¤ Dauer der Verarbeitung: 0.26 Sekunden  ¤

*© Formatika GbR, Deutschland







                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,269
#Domains=934,208