LCOV - code coverage report
Current view: top level - include/linux - blkdev.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 91 46.2 %
Date: 2014-02-18 Functions: 0 0 -
Branches: 100 262 38.2 %

           Branch data     Line data    Source code
       1                 :            : #ifndef _LINUX_BLKDEV_H
       2                 :            : #define _LINUX_BLKDEV_H
       3                 :            : 
       4                 :            : #include <linux/sched.h>
       5                 :            : 
       6                 :            : #ifdef CONFIG_BLOCK
       7                 :            : 
       8                 :            : #include <linux/major.h>
       9                 :            : #include <linux/genhd.h>
      10                 :            : #include <linux/list.h>
      11                 :            : #include <linux/llist.h>
      12                 :            : #include <linux/timer.h>
      13                 :            : #include <linux/workqueue.h>
      14                 :            : #include <linux/pagemap.h>
      15                 :            : #include <linux/backing-dev.h>
      16                 :            : #include <linux/wait.h>
      17                 :            : #include <linux/mempool.h>
      18                 :            : #include <linux/bio.h>
      19                 :            : #include <linux/stringify.h>
      20                 :            : #include <linux/gfp.h>
      21                 :            : #include <linux/bsg.h>
      22                 :            : #include <linux/smp.h>
      23                 :            : #include <linux/rcupdate.h>
      24                 :            : 
      25                 :            : #include <asm/scatterlist.h>
      26                 :            : 
      27                 :            : struct module;
      28                 :            : struct scsi_ioctl_command;
      29                 :            : 
      30                 :            : struct request_queue;
      31                 :            : struct elevator_queue;
      32                 :            : struct request_pm_state;
      33                 :            : struct blk_trace;
      34                 :            : struct request;
      35                 :            : struct sg_io_hdr;
      36                 :            : struct bsg_job;
      37                 :            : struct blkcg_gq;
      38                 :            : 
      39                 :            : #define BLKDEV_MIN_RQ   4
      40                 :            : #define BLKDEV_MAX_RQ   128     /* Default maximum */
      41                 :            : 
      42                 :            : /*
      43                 :            :  * Maximum number of blkcg policies allowed to be registered concurrently.
      44                 :            :  * Defined here to simplify include dependency.
      45                 :            :  */
      46                 :            : #define BLKCG_MAX_POLS          2
      47                 :            : 
      48                 :            : struct request;
      49                 :            : typedef void (rq_end_io_fn)(struct request *, int);
      50                 :            : 
      51                 :            : #define BLK_RL_SYNCFULL         (1U << 0)
      52                 :            : #define BLK_RL_ASYNCFULL        (1U << 1)
      53                 :            : 
      54                 :            : struct request_list {
      55                 :            :         struct request_queue    *q;     /* the queue this rl belongs to */
      56                 :            : #ifdef CONFIG_BLK_CGROUP
      57                 :            :         struct blkcg_gq         *blkg;  /* blkg this request pool belongs to */
      58                 :            : #endif
      59                 :            :         /*
      60                 :            :          * count[], starved[], and wait[] are indexed by
      61                 :            :          * BLK_RW_SYNC/BLK_RW_ASYNC
      62                 :            :          */
      63                 :            :         int                     count[2];
      64                 :            :         int                     starved[2];
      65                 :            :         mempool_t               *rq_pool;
      66                 :            :         wait_queue_head_t       wait[2];
      67                 :            :         unsigned int            flags;
      68                 :            : };
      69                 :            : 
      70                 :            : /*
      71                 :            :  * request command types
      72                 :            :  */
      73                 :            : enum rq_cmd_type_bits {
      74                 :            :         REQ_TYPE_FS             = 1,    /* fs request */
      75                 :            :         REQ_TYPE_BLOCK_PC,              /* scsi command */
      76                 :            :         REQ_TYPE_SENSE,                 /* sense request */
      77                 :            :         REQ_TYPE_PM_SUSPEND,            /* suspend request */
      78                 :            :         REQ_TYPE_PM_RESUME,             /* resume request */
      79                 :            :         REQ_TYPE_PM_SHUTDOWN,           /* shutdown request */
      80                 :            :         REQ_TYPE_SPECIAL,               /* driver defined type */
      81                 :            :         /*
      82                 :            :          * for ATA/ATAPI devices. this really doesn't belong here, ide should
      83                 :            :          * use REQ_TYPE_SPECIAL and use rq->cmd[0] with the range of driver
      84                 :            :          * private REQ_LB opcodes to differentiate what type of request this is
      85                 :            :          */
      86                 :            :         REQ_TYPE_ATA_TASKFILE,
      87                 :            :         REQ_TYPE_ATA_PC,
      88                 :            : };
      89                 :            : 
      90                 :            : #define BLK_MAX_CDB     16
      91                 :            : 
      92                 :            : /*
      93                 :            :  * try to put the fields that are referenced together in the same cacheline.
      94                 :            :  * if you modify this structure, be sure to check block/blk-core.c:blk_rq_init()
      95                 :            :  * as well!
      96                 :            :  */
      97                 :            : struct request {
      98                 :            :         union {
      99                 :            :                 struct list_head queuelist;
     100                 :            :                 struct llist_node ll_list;
     101                 :            :         };
     102                 :            :         union {
     103                 :            :                 struct call_single_data csd;
     104                 :            :                 struct work_struct mq_flush_data;
     105                 :            :         };
     106                 :            : 
     107                 :            :         struct request_queue *q;
     108                 :            :         struct blk_mq_ctx *mq_ctx;
     109                 :            : 
     110                 :            :         u64 cmd_flags;
     111                 :            :         enum rq_cmd_type_bits cmd_type;
     112                 :            :         unsigned long atomic_flags;
     113                 :            : 
     114                 :            :         int cpu;
     115                 :            : 
     116                 :            :         /* the following two fields are internal, NEVER access directly */
     117                 :            :         unsigned int __data_len;        /* total data len */
     118                 :            :         sector_t __sector;              /* sector cursor */
     119                 :            : 
     120                 :            :         struct bio *bio;
     121                 :            :         struct bio *biotail;
     122                 :            : 
     123                 :            :         struct hlist_node hash; /* merge hash */
     124                 :            :         /*
     125                 :            :          * The rb_node is only used inside the io scheduler, requests
     126                 :            :          * are pruned when moved to the dispatch queue. So let the
     127                 :            :          * completion_data share space with the rb_node.
     128                 :            :          */
     129                 :            :         union {
     130                 :            :                 struct rb_node rb_node; /* sort/lookup */
     131                 :            :                 void *completion_data;
     132                 :            :         };
     133                 :            : 
     134                 :            :         /*
     135                 :            :          * Three pointers are available for the IO schedulers, if they need
     136                 :            :          * more they have to dynamically allocate it.  Flush requests are
     137                 :            :          * never put on the IO scheduler. So let the flush fields share
     138                 :            :          * space with the elevator data.
     139                 :            :          */
     140                 :            :         union {
     141                 :            :                 struct {
     142                 :            :                         struct io_cq            *icq;
     143                 :            :                         void                    *priv[2];
     144                 :            :                 } elv;
     145                 :            : 
     146                 :            :                 struct {
     147                 :            :                         unsigned int            seq;
     148                 :            :                         struct list_head        list;
     149                 :            :                         rq_end_io_fn            *saved_end_io;
     150                 :            :                 } flush;
     151                 :            :         };
     152                 :            : 
     153                 :            :         struct gendisk *rq_disk;
     154                 :            :         struct hd_struct *part;
     155                 :            :         unsigned long start_time;
     156                 :            : #ifdef CONFIG_BLK_CGROUP
     157                 :            :         struct request_list *rl;                /* rl this rq is alloced from */
     158                 :            :         unsigned long long start_time_ns;
     159                 :            :         unsigned long long io_start_time_ns;    /* when passed to hardware */
     160                 :            : #endif
     161                 :            :         /* Number of scatter-gather DMA addr+len pairs after
     162                 :            :          * physical address coalescing is performed.
     163                 :            :          */
     164                 :            :         unsigned short nr_phys_segments;
     165                 :            : #if defined(CONFIG_BLK_DEV_INTEGRITY)
     166                 :            :         unsigned short nr_integrity_segments;
     167                 :            : #endif
     168                 :            : 
     169                 :            :         unsigned short ioprio;
     170                 :            : 
     171                 :            :         void *special;          /* opaque pointer available for LLD use */
     172                 :            :         char *buffer;           /* kaddr of the current segment if available */
     173                 :            : 
     174                 :            :         int tag;
     175                 :            :         int errors;
     176                 :            : 
     177                 :            :         /*
     178                 :            :          * when request is used as a packet command carrier
     179                 :            :          */
     180                 :            :         unsigned char __cmd[BLK_MAX_CDB];
     181                 :            :         unsigned char *cmd;
     182                 :            :         unsigned short cmd_len;
     183                 :            : 
     184                 :            :         unsigned int extra_len; /* length of alignment and padding */
     185                 :            :         unsigned int sense_len;
     186                 :            :         unsigned int resid_len; /* residual count */
     187                 :            :         void *sense;
     188                 :            : 
     189                 :            :         unsigned long deadline;
     190                 :            :         struct list_head timeout_list;
     191                 :            :         unsigned int timeout;
     192                 :            :         int retries;
     193                 :            : 
     194                 :            :         /*
     195                 :            :          * completion callback.
     196                 :            :          */
     197                 :            :         rq_end_io_fn *end_io;
     198                 :            :         void *end_io_data;
     199                 :            : 
     200                 :            :         /* for bidi */
     201                 :            :         struct request *next_rq;
     202                 :            : };
     203                 :            : 
     204                 :            : static inline unsigned short req_get_ioprio(struct request *req)
     205                 :            : {
     206                 :            :         return req->ioprio;
     207                 :            : }
     208                 :            : 
     209                 :            : /*
     210                 :            :  * State information carried for REQ_TYPE_PM_SUSPEND and REQ_TYPE_PM_RESUME
     211                 :            :  * requests. Some step values could eventually be made generic.
     212                 :            :  */
     213                 :            : struct request_pm_state
     214                 :            : {
     215                 :            :         /* PM state machine step value, currently driver specific */
     216                 :            :         int     pm_step;
     217                 :            :         /* requested PM state value (S1, S2, S3, S4, ...) */
     218                 :            :         u32     pm_state;
     219                 :            :         void*   data;           /* for driver use */
     220                 :            : };
     221                 :            : 
     222                 :            : #include <linux/elevator.h>
     223                 :            : 
     224                 :            : struct blk_queue_ctx;
     225                 :            : 
     226                 :            : typedef void (request_fn_proc) (struct request_queue *q);
     227                 :            : typedef void (make_request_fn) (struct request_queue *q, struct bio *bio);
     228                 :            : typedef int (prep_rq_fn) (struct request_queue *, struct request *);
     229                 :            : typedef void (unprep_rq_fn) (struct request_queue *, struct request *);
     230                 :            : 
     231                 :            : struct bio_vec;
     232                 :            : struct bvec_merge_data {
     233                 :            :         struct block_device *bi_bdev;
     234                 :            :         sector_t bi_sector;
     235                 :            :         unsigned bi_size;
     236                 :            :         unsigned long bi_rw;
     237                 :            : };
     238                 :            : typedef int (merge_bvec_fn) (struct request_queue *, struct bvec_merge_data *,
     239                 :            :                              struct bio_vec *);
     240                 :            : typedef void (softirq_done_fn)(struct request *);
     241                 :            : typedef int (dma_drain_needed_fn)(struct request *);
     242                 :            : typedef int (lld_busy_fn) (struct request_queue *q);
     243                 :            : typedef int (bsg_job_fn) (struct bsg_job *);
     244                 :            : 
     245                 :            : enum blk_eh_timer_return {
     246                 :            :         BLK_EH_NOT_HANDLED,
     247                 :            :         BLK_EH_HANDLED,
     248                 :            :         BLK_EH_RESET_TIMER,
     249                 :            : };
     250                 :            : 
     251                 :            : typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *);
     252                 :            : 
     253                 :            : enum blk_queue_state {
     254                 :            :         Queue_down,
     255                 :            :         Queue_up,
     256                 :            : };
     257                 :            : 
     258                 :            : struct blk_queue_tag {
     259                 :            :         struct request **tag_index;     /* map of busy tags */
     260                 :            :         unsigned long *tag_map;         /* bit map of free/busy tags */
     261                 :            :         int busy;                       /* current depth */
     262                 :            :         int max_depth;                  /* what we will send to device */
     263                 :            :         int real_max_depth;             /* what the array can hold */
     264                 :            :         atomic_t refcnt;                /* map can be shared */
     265                 :            : };
     266                 :            : 
     267                 :            : #define BLK_SCSI_MAX_CMDS       (256)
     268                 :            : #define BLK_SCSI_CMD_PER_LONG   (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
     269                 :            : 
     270                 :            : struct queue_limits {
     271                 :            :         unsigned long           bounce_pfn;
     272                 :            :         unsigned long           seg_boundary_mask;
     273                 :            : 
     274                 :            :         unsigned int            max_hw_sectors;
     275                 :            :         unsigned int            max_sectors;
     276                 :            :         unsigned int            max_segment_size;
     277                 :            :         unsigned int            physical_block_size;
     278                 :            :         unsigned int            alignment_offset;
     279                 :            :         unsigned int            io_min;
     280                 :            :         unsigned int            io_opt;
     281                 :            :         unsigned int            max_discard_sectors;
     282                 :            :         unsigned int            max_write_same_sectors;
     283                 :            :         unsigned int            discard_granularity;
     284                 :            :         unsigned int            discard_alignment;
     285                 :            : 
     286                 :            :         unsigned short          logical_block_size;
     287                 :            :         unsigned short          max_segments;
     288                 :            :         unsigned short          max_integrity_segments;
     289                 :            : 
     290                 :            :         unsigned char           misaligned;
     291                 :            :         unsigned char           discard_misaligned;
     292                 :            :         unsigned char           cluster;
     293                 :            :         unsigned char           discard_zeroes_data;
     294                 :            : };
     295                 :            : 
     296                 :            : struct request_queue {
     297                 :            :         /*
     298                 :            :          * Together with queue_head for cacheline sharing
     299                 :            :          */
     300                 :            :         struct list_head        queue_head;
     301                 :            :         struct request          *last_merge;
     302                 :            :         struct elevator_queue   *elevator;
     303                 :            :         int                     nr_rqs[2];      /* # allocated [a]sync rqs */
     304                 :            :         int                     nr_rqs_elvpriv; /* # allocated rqs w/ elvpriv */
     305                 :            : 
     306                 :            :         /*
     307                 :            :          * If blkcg is not used, @q->root_rl serves all requests.  If blkcg
     308                 :            :          * is used, root blkg allocates from @q->root_rl and all other
     309                 :            :          * blkgs from their own blkg->rl.  Which one to use should be
     310                 :            :          * determined using bio_request_list().
     311                 :            :          */
     312                 :            :         struct request_list     root_rl;
     313                 :            : 
     314                 :            :         request_fn_proc         *request_fn;
     315                 :            :         make_request_fn         *make_request_fn;
     316                 :            :         prep_rq_fn              *prep_rq_fn;
     317                 :            :         unprep_rq_fn            *unprep_rq_fn;
     318                 :            :         merge_bvec_fn           *merge_bvec_fn;
     319                 :            :         softirq_done_fn         *softirq_done_fn;
     320                 :            :         rq_timed_out_fn         *rq_timed_out_fn;
     321                 :            :         dma_drain_needed_fn     *dma_drain_needed;
     322                 :            :         lld_busy_fn             *lld_busy_fn;
     323                 :            : 
     324                 :            :         struct blk_mq_ops       *mq_ops;
     325                 :            : 
     326                 :            :         unsigned int            *mq_map;
     327                 :            : 
     328                 :            :         /* sw queues */
     329                 :            :         struct blk_mq_ctx       *queue_ctx;
     330                 :            :         unsigned int            nr_queues;
     331                 :            : 
     332                 :            :         /* hw dispatch queues */
     333                 :            :         struct blk_mq_hw_ctx    **queue_hw_ctx;
     334                 :            :         unsigned int            nr_hw_queues;
     335                 :            : 
     336                 :            :         /*
     337                 :            :          * Dispatch queue sorting
     338                 :            :          */
     339                 :            :         sector_t                end_sector;
     340                 :            :         struct request          *boundary_rq;
     341                 :            : 
     342                 :            :         /*
     343                 :            :          * Delayed queue handling
     344                 :            :          */
     345                 :            :         struct delayed_work     delay_work;
     346                 :            : 
     347                 :            :         struct backing_dev_info backing_dev_info;
     348                 :            : 
     349                 :            :         /*
     350                 :            :          * The queue owner gets to use this for whatever they like.
     351                 :            :          * ll_rw_blk doesn't touch it.
     352                 :            :          */
     353                 :            :         void                    *queuedata;
     354                 :            : 
     355                 :            :         /*
     356                 :            :          * various queue flags, see QUEUE_* below
     357                 :            :          */
     358                 :            :         unsigned long           queue_flags;
     359                 :            : 
     360                 :            :         /*
     361                 :            :          * ida allocated id for this queue.  Used to index queues from
     362                 :            :          * ioctx.
     363                 :            :          */
     364                 :            :         int                     id;
     365                 :            : 
     366                 :            :         /*
     367                 :            :          * queue needs bounce pages for pages above this limit
     368                 :            :          */
     369                 :            :         gfp_t                   bounce_gfp;
     370                 :            : 
     371                 :            :         /*
     372                 :            :          * protects queue structures from reentrancy. ->__queue_lock should
     373                 :            :          * _never_ be used directly, it is queue private. always use
     374                 :            :          * ->queue_lock.
     375                 :            :          */
     376                 :            :         spinlock_t              __queue_lock;
     377                 :            :         spinlock_t              *queue_lock;
     378                 :            : 
     379                 :            :         /*
     380                 :            :          * queue kobject
     381                 :            :          */
     382                 :            :         struct kobject kobj;
     383                 :            : 
     384                 :            :         /*
     385                 :            :          * mq queue kobject
     386                 :            :          */
     387                 :            :         struct kobject mq_kobj;
     388                 :            : 
     389                 :            : #ifdef CONFIG_PM_RUNTIME
     390                 :            :         struct device           *dev;
     391                 :            :         int                     rpm_status;
     392                 :            :         unsigned int            nr_pending;
     393                 :            : #endif
     394                 :            : 
     395                 :            :         /*
     396                 :            :          * queue settings
     397                 :            :          */
     398                 :            :         unsigned long           nr_requests;    /* Max # of requests */
     399                 :            :         unsigned int            nr_congestion_on;
     400                 :            :         unsigned int            nr_congestion_off;
     401                 :            :         unsigned int            nr_batching;
     402                 :            : 
     403                 :            :         unsigned int            dma_drain_size;
     404                 :            :         void                    *dma_drain_buffer;
     405                 :            :         unsigned int            dma_pad_mask;
     406                 :            :         unsigned int            dma_alignment;
     407                 :            : 
     408                 :            :         struct blk_queue_tag    *queue_tags;
     409                 :            :         struct list_head        tag_busy_list;
     410                 :            : 
     411                 :            :         unsigned int            nr_sorted;
     412                 :            :         unsigned int            in_flight[2];
     413                 :            :         /*
     414                 :            :          * Number of active block driver functions for which blk_drain_queue()
     415                 :            :          * must wait. Must be incremented around functions that unlock the
     416                 :            :          * queue_lock internally, e.g. scsi_request_fn().
     417                 :            :          */
     418                 :            :         unsigned int            request_fn_active;
     419                 :            : 
     420                 :            :         unsigned int            rq_timeout;
     421                 :            :         struct timer_list       timeout;
     422                 :            :         struct list_head        timeout_list;
     423                 :            : 
     424                 :            :         struct list_head        icq_list;
     425                 :            : #ifdef CONFIG_BLK_CGROUP
     426                 :            :         DECLARE_BITMAP          (blkcg_pols, BLKCG_MAX_POLS);
     427                 :            :         struct blkcg_gq         *root_blkg;
     428                 :            :         struct list_head        blkg_list;
     429                 :            : #endif
     430                 :            : 
     431                 :            :         struct queue_limits     limits;
     432                 :            : 
     433                 :            :         /*
     434                 :            :          * sg stuff
     435                 :            :          */
     436                 :            :         unsigned int            sg_timeout;
     437                 :            :         unsigned int            sg_reserved_size;
     438                 :            :         int                     node;
     439                 :            : #ifdef CONFIG_BLK_DEV_IO_TRACE
     440                 :            :         struct blk_trace        *blk_trace;
     441                 :            : #endif
     442                 :            :         /*
     443                 :            :          * for flush operations
     444                 :            :          */
     445                 :            :         unsigned int            flush_flags;
     446                 :            :         unsigned int            flush_not_queueable:1;
     447                 :            :         unsigned int            flush_queue_delayed:1;
     448                 :            :         unsigned int            flush_pending_idx:1;
     449                 :            :         unsigned int            flush_running_idx:1;
     450                 :            :         unsigned long           flush_pending_since;
     451                 :            :         struct list_head        flush_queue[2];
     452                 :            :         struct list_head        flush_data_in_flight;
     453                 :            :         union {
     454                 :            :                 struct request  flush_rq;
     455                 :            :                 struct {
     456                 :            :                         spinlock_t mq_flush_lock;
     457                 :            :                         struct work_struct mq_flush_work;
     458                 :            :                 };
     459                 :            :         };
     460                 :            : 
     461                 :            :         struct mutex            sysfs_lock;
     462                 :            : 
     463                 :            :         int                     bypass_depth;
     464                 :            : 
     465                 :            : #if defined(CONFIG_BLK_DEV_BSG)
     466                 :            :         bsg_job_fn              *bsg_job_fn;
     467                 :            :         int                     bsg_job_size;
     468                 :            :         struct bsg_class_device bsg_dev;
     469                 :            : #endif
     470                 :            : 
     471                 :            : #ifdef CONFIG_BLK_DEV_THROTTLING
     472                 :            :         /* Throttle data */
     473                 :            :         struct throtl_data *td;
     474                 :            : #endif
     475                 :            :         struct rcu_head         rcu_head;
     476                 :            :         wait_queue_head_t       mq_freeze_wq;
     477                 :            :         struct percpu_counter   mq_usage_counter;
     478                 :            :         struct list_head        all_q_node;
     479                 :            : };
     480                 :            : 
     481                 :            : #define QUEUE_FLAG_QUEUED       1       /* uses generic tag queueing */
     482                 :            : #define QUEUE_FLAG_STOPPED      2       /* queue is stopped */
     483                 :            : #define QUEUE_FLAG_SYNCFULL     3       /* read queue has been filled */
     484                 :            : #define QUEUE_FLAG_ASYNCFULL    4       /* write queue has been filled */
     485                 :            : #define QUEUE_FLAG_DYING        5       /* queue being torn down */
     486                 :            : #define QUEUE_FLAG_BYPASS       6       /* act as dumb FIFO queue */
     487                 :            : #define QUEUE_FLAG_BIDI         7       /* queue supports bidi requests */
     488                 :            : #define QUEUE_FLAG_NOMERGES     8       /* disable merge attempts */
     489                 :            : #define QUEUE_FLAG_SAME_COMP    9       /* complete on same CPU-group */
     490                 :            : #define QUEUE_FLAG_FAIL_IO     10       /* fake timeout */
     491                 :            : #define QUEUE_FLAG_STACKABLE   11       /* supports request stacking */
     492                 :            : #define QUEUE_FLAG_NONROT      12       /* non-rotational device (SSD) */
     493                 :            : #define QUEUE_FLAG_VIRT        QUEUE_FLAG_NONROT /* paravirt device */
     494                 :            : #define QUEUE_FLAG_IO_STAT     13       /* do IO stats */
     495                 :            : #define QUEUE_FLAG_DISCARD     14       /* supports DISCARD */
     496                 :            : #define QUEUE_FLAG_NOXMERGES   15       /* No extended merges */
     497                 :            : #define QUEUE_FLAG_ADD_RANDOM  16       /* Contributes to random pool */
     498                 :            : #define QUEUE_FLAG_SECDISCARD  17       /* supports SECDISCARD */
     499                 :            : #define QUEUE_FLAG_SAME_FORCE  18       /* force complete on same CPU */
     500                 :            : #define QUEUE_FLAG_DEAD        19       /* queue tear-down finished */
     501                 :            : #define QUEUE_FLAG_INIT_DONE   20       /* queue is initialized */
     502                 :            : 
     503                 :            : #define QUEUE_FLAG_DEFAULT      ((1 << QUEUE_FLAG_IO_STAT) |              \
     504                 :            :                                  (1 << QUEUE_FLAG_STACKABLE)      |       \
     505                 :            :                                  (1 << QUEUE_FLAG_SAME_COMP)      |       \
     506                 :            :                                  (1 << QUEUE_FLAG_ADD_RANDOM))
     507                 :            : 
     508                 :            : #define QUEUE_FLAG_MQ_DEFAULT   ((1 << QUEUE_FLAG_IO_STAT) |              \
     509                 :            :                                  (1 << QUEUE_FLAG_SAME_COMP))
     510                 :            : 
     511                 :            : static inline void queue_lockdep_assert_held(struct request_queue *q)
     512                 :            : {
     513                 :            :         if (q->queue_lock)
     514                 :            :                 lockdep_assert_held(q->queue_lock);
     515                 :            : }
     516                 :            : 
     517                 :            : static inline void queue_flag_set_unlocked(unsigned int flag,
     518                 :            :                                            struct request_queue *q)
     519                 :            : {
     520                 :            :         __set_bit(flag, &q->queue_flags);
     521                 :            : }
     522                 :            : 
     523                 :            : static inline int queue_flag_test_and_clear(unsigned int flag,
     524                 :            :                                             struct request_queue *q)
     525                 :            : {
     526                 :            :         queue_lockdep_assert_held(q);
     527                 :            : 
     528                 :            :         if (test_bit(flag, &q->queue_flags)) {
     529                 :            :                 __clear_bit(flag, &q->queue_flags);
     530                 :            :                 return 1;
     531                 :            :         }
     532                 :            : 
     533                 :            :         return 0;
     534                 :            : }
     535                 :            : 
     536                 :            : static inline int queue_flag_test_and_set(unsigned int flag,
     537                 :            :                                           struct request_queue *q)
     538                 :            : {
     539                 :            :         queue_lockdep_assert_held(q);
     540                 :            : 
     541                 :            :         if (!test_bit(flag, &q->queue_flags)) {
     542                 :            :                 __set_bit(flag, &q->queue_flags);
     543                 :            :                 return 0;
     544                 :            :         }
     545                 :            : 
     546                 :            :         return 1;
     547                 :            : }
     548                 :            : 
     549                 :            : static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
     550                 :            : {
     551                 :            :         queue_lockdep_assert_held(q);
     552                 :            :         __set_bit(flag, &q->queue_flags);
     553                 :            : }
     554                 :            : 
     555                 :            : static inline void queue_flag_clear_unlocked(unsigned int flag,
     556                 :            :                                              struct request_queue *q)
     557                 :            : {
     558                 :            :         __clear_bit(flag, &q->queue_flags);
     559                 :            : }
     560                 :            : 
     561                 :            : static inline int queue_in_flight(struct request_queue *q)
     562                 :            : {
     563                 :            :         return q->in_flight[0] + q->in_flight[1];
     564                 :            : }
     565                 :            : 
     566                 :            : static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
     567                 :            : {
     568                 :            :         queue_lockdep_assert_held(q);
     569                 :            :         __clear_bit(flag, &q->queue_flags);
     570                 :            : }
     571                 :            : 
     572                 :            : #define blk_queue_tagged(q)     test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
     573                 :            : #define blk_queue_stopped(q)    test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
     574                 :            : #define blk_queue_dying(q)      test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)
     575                 :            : #define blk_queue_dead(q)       test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags)
     576                 :            : #define blk_queue_bypass(q)     test_bit(QUEUE_FLAG_BYPASS, &(q)->queue_flags)
     577                 :            : #define blk_queue_init_done(q)  test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags)
     578                 :            : #define blk_queue_nomerges(q)   test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
     579                 :            : #define blk_queue_noxmerges(q)  \
     580                 :            :         test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
     581                 :            : #define blk_queue_nonrot(q)     test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
     582                 :            : #define blk_queue_io_stat(q)    test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
     583                 :            : #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
     584                 :            : #define blk_queue_stackable(q)  \
     585                 :            :         test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)
     586                 :            : #define blk_queue_discard(q)    test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)
     587                 :            : #define blk_queue_secdiscard(q) (blk_queue_discard(q) && \
     588                 :            :         test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags))
     589                 :            : 
     590                 :            : #define blk_noretry_request(rq) \
     591                 :            :         ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
     592                 :            :                              REQ_FAILFAST_DRIVER))
     593                 :            : 
     594                 :            : #define blk_account_rq(rq) \
     595                 :            :         (((rq)->cmd_flags & REQ_STARTED) && \
     596                 :            :          ((rq)->cmd_type == REQ_TYPE_FS))
     597                 :            : 
     598                 :            : #define blk_pm_request(rq)      \
     599                 :            :         ((rq)->cmd_type == REQ_TYPE_PM_SUSPEND || \
     600                 :            :          (rq)->cmd_type == REQ_TYPE_PM_RESUME)
     601                 :            : 
     602                 :            : #define blk_rq_cpu_valid(rq)    ((rq)->cpu != -1)
     603                 :            : #define blk_bidi_rq(rq)         ((rq)->next_rq != NULL)
     604                 :            : /* rq->queuelist of dequeued request must be list_empty() */
     605                 :            : #define blk_queued_rq(rq)       (!list_empty(&(rq)->queuelist))
     606                 :            : 
     607                 :            : #define list_entry_rq(ptr)      list_entry((ptr), struct request, queuelist)
     608                 :            : 
     609                 :            : #define rq_data_dir(rq)         (((rq)->cmd_flags & 1) != 0)
     610                 :            : 
     611                 :            : static inline unsigned int blk_queue_cluster(struct request_queue *q)
     612                 :            : {
     613                 :     394901 :         return q->limits.cluster;
     614                 :            : }
     615                 :            : 
     616                 :            : /*
     617                 :            :  * We regard a request as sync, if either a read or a sync write
     618                 :            :  */
     619                 :            : static inline bool rw_is_sync(unsigned int rw_flags)
     620                 :            : {
     621 [ +  + ][ +  + ]:    6113090 :         return !(rw_flags & REQ_WRITE) || (rw_flags & REQ_SYNC);
         [ +  + ][ +  + ]
         [ #  # ][ +  + ]
         [ #  # ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
     622                 :            : }
     623                 :            : 
     624                 :            : static inline bool rq_is_sync(struct request *rq)
     625                 :            : {
     626                 :    4920635 :         return rw_is_sync(rq->cmd_flags);
     627                 :            : }
     628                 :            : 
     629                 :            : static inline bool blk_rl_full(struct request_list *rl, bool sync)
     630                 :            : {
     631         [ +  + ]:      13058 :         unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL;
     632                 :            : 
     633                 :      13058 :         return rl->flags & flag;
     634                 :            : }
     635                 :            : 
     636                 :            : static inline void blk_set_rl_full(struct request_list *rl, bool sync)
     637                 :            : {
     638         [ +  + ]:        763 :         unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL;
     639                 :            : 
     640                 :        763 :         rl->flags |= flag;
     641                 :            : }
     642                 :            : 
     643                 :            : static inline void blk_clear_rl_full(struct request_list *rl, bool sync)
     644                 :            : {
     645         [ +  + ]:     858520 :         unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL;
     646                 :            : 
     647                 :     423455 :         rl->flags &= ~flag;
     648                 :            : }
     649                 :            : 
     650                 :            : static inline bool rq_mergeable(struct request *rq)
     651                 :            : {
     652 [ +  - ][ +  - ]:    1876190 :         if (rq->cmd_type != REQ_TYPE_FS)
                 [ +  - ]
     653                 :            :                 return false;
     654                 :            : 
     655 [ +  + ][ +  + ]:    1876235 :         if (rq->cmd_flags & REQ_NOMERGE_FLAGS)
                 [ +  + ]
     656                 :            :                 return false;
     657                 :            : 
     658                 :            :         return true;
     659                 :            : }
     660                 :            : 
     661                 :            : static inline bool blk_check_merge_flags(unsigned int flags1,
     662                 :            :                                          unsigned int flags2)
     663                 :            : {
     664    [ + ][ +  - ]:    1100520 :         if ((flags1 & REQ_DISCARD) != (flags2 & REQ_DISCARD))
     665                 :            :                 return false;
     666                 :            : 
     667    [ + ][ +  - ]:    1100536 :         if ((flags1 & REQ_SECURE) != (flags2 & REQ_SECURE))
     668                 :            :                 return false;
     669                 :            : 
     670 [ +  + ][ +  - ]:    1100564 :         if ((flags1 & REQ_WRITE_SAME) != (flags2 & REQ_WRITE_SAME))
     671                 :            :                 return false;
     672                 :            : 
     673                 :            :         return true;
     674                 :            : }
     675                 :            : 
     676                 :            : static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)
     677                 :            : {
     678 [ #  # ][ #  # ]:          0 :         if (bio_data(a) == bio_data(b))
     679                 :            :                 return true;
     680                 :            : 
     681                 :            :         return false;
     682                 :            : }
     683                 :            : 
     684                 :            : /*
     685                 :            :  * q->prep_rq_fn return values
     686                 :            :  */
     687                 :            : #define BLKPREP_OK              0       /* serve it */
     688                 :            : #define BLKPREP_KILL            1       /* fatal error, kill */
     689                 :            : #define BLKPREP_DEFER           2       /* leave on queue */
     690                 :            : 
     691                 :            : extern unsigned long blk_max_low_pfn, blk_max_pfn;
     692                 :            : 
     693                 :            : /*
     694                 :            :  * standard bounce addresses:
     695                 :            :  *
     696                 :            :  * BLK_BOUNCE_HIGH      : bounce all highmem pages
     697                 :            :  * BLK_BOUNCE_ANY       : don't bounce anything
     698                 :            :  * BLK_BOUNCE_ISA       : bounce pages above ISA DMA boundary
     699                 :            :  */
     700                 :            : 
     701                 :            : #if BITS_PER_LONG == 32
     702                 :            : #define BLK_BOUNCE_HIGH         ((u64)blk_max_low_pfn << PAGE_SHIFT)
     703                 :            : #else
     704                 :            : #define BLK_BOUNCE_HIGH         -1ULL
     705                 :            : #endif
     706                 :            : #define BLK_BOUNCE_ANY          (-1ULL)
     707                 :            : #define BLK_BOUNCE_ISA          (DMA_BIT_MASK(24))
     708                 :            : 
     709                 :            : /*
     710                 :            :  * default timeout for SG_IO if none specified
     711                 :            :  */
     712                 :            : #define BLK_DEFAULT_SG_TIMEOUT  (60 * HZ)
     713                 :            : #define BLK_MIN_SG_TIMEOUT      (7 * HZ)
     714                 :            : 
     715                 :            : #ifdef CONFIG_BOUNCE
     716                 :            : extern int init_emergency_isa_pool(void);
     717                 :            : extern void blk_queue_bounce(struct request_queue *q, struct bio **bio);
     718                 :            : #else
     719                 :            : static inline int init_emergency_isa_pool(void)
     720                 :            : {
     721                 :            :         return 0;
     722                 :            : }
     723                 :            : static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio)
     724                 :            : {
     725                 :            : }
     726                 :            : #endif /* CONFIG_MMU */
     727                 :            : 
     728                 :            : struct rq_map_data {
     729                 :            :         struct page **pages;
     730                 :            :         int page_order;
     731                 :            :         int nr_entries;
     732                 :            :         unsigned long offset;
     733                 :            :         int null_mapped;
     734                 :            :         int from_user;
     735                 :            : };
     736                 :            : 
     737                 :            : struct req_iterator {
     738                 :            :         int i;
     739                 :            :         struct bio *bio;
     740                 :            : };
     741                 :            : 
     742                 :            : /* This should not be used directly - use rq_for_each_segment */
     743                 :            : #define for_each_bio(_bio)              \
     744                 :            :         for (; _bio; _bio = _bio->bi_next)
     745                 :            : #define __rq_for_each_bio(_bio, rq)     \
     746                 :            :         if ((rq->bio))                       \
     747                 :            :                 for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
     748                 :            : 
     749                 :            : #define rq_for_each_segment(bvl, _rq, _iter)                    \
     750                 :            :         __rq_for_each_bio(_iter.bio, _rq)                       \
     751                 :            :                 bio_for_each_segment(bvl, _iter.bio, _iter.i)
     752                 :            : 
     753                 :            : #define rq_iter_last(rq, _iter)                                 \
     754                 :            :                 (_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
     755                 :            : 
     756                 :            : #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
     757                 :            : # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
     758                 :            : #endif
     759                 :            : #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
     760                 :            : extern void rq_flush_dcache_pages(struct request *rq);
     761                 :            : #else
     762                 :            : static inline void rq_flush_dcache_pages(struct request *rq)
     763                 :            : {
     764                 :            : }
     765                 :            : #endif
     766                 :            : 
     767                 :            : extern int blk_register_queue(struct gendisk *disk);
     768                 :            : extern void blk_unregister_queue(struct gendisk *disk);
     769                 :            : extern void generic_make_request(struct bio *bio);
     770                 :            : extern void blk_rq_init(struct request_queue *q, struct request *rq);
     771                 :            : extern void blk_put_request(struct request *);
     772                 :            : extern void __blk_put_request(struct request_queue *, struct request *);
     773                 :            : extern struct request *blk_get_request(struct request_queue *, int, gfp_t);
     774                 :            : extern struct request *blk_make_request(struct request_queue *, struct bio *,
     775                 :            :                                         gfp_t);
     776                 :            : extern void blk_requeue_request(struct request_queue *, struct request *);
     777                 :            : extern void blk_add_request_payload(struct request *rq, struct page *page,
     778                 :            :                 unsigned int len);
     779                 :            : extern int blk_rq_check_limits(struct request_queue *q, struct request *rq);
     780                 :            : extern int blk_lld_busy(struct request_queue *q);
     781                 :            : extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
     782                 :            :                              struct bio_set *bs, gfp_t gfp_mask,
     783                 :            :                              int (*bio_ctr)(struct bio *, struct bio *, void *),
     784                 :            :                              void *data);
     785                 :            : extern void blk_rq_unprep_clone(struct request *rq);
     786                 :            : extern int blk_insert_cloned_request(struct request_queue *q,
     787                 :            :                                      struct request *rq);
     788                 :            : extern void blk_delay_queue(struct request_queue *, unsigned long);
     789                 :            : extern void blk_recount_segments(struct request_queue *, struct bio *);
     790                 :            : extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int);
     791                 :            : extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t,
     792                 :            :                               unsigned int, void __user *);
     793                 :            : extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
     794                 :            :                           unsigned int, void __user *);
     795                 :            : extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
     796                 :            :                          struct scsi_ioctl_command __user *);
     797                 :            : 
     798                 :            : extern void blk_queue_bio(struct request_queue *q, struct bio *bio);
     799                 :            : 
     800                 :            : /*
     801                 :            :  * A queue has just exitted congestion.  Note this in the global counter of
     802                 :            :  * congested queues, and wake up anyone who was waiting for requests to be
     803                 :            :  * put back.
     804                 :            :  */
     805                 :            : static inline void blk_clear_queue_congested(struct request_queue *q, int sync)
     806                 :            : {
     807                 :     421291 :         clear_bdi_congested(&q->backing_dev_info, sync);
     808                 :            : }
     809                 :            : 
     810                 :            : /*
     811                 :            :  * A queue has just entered congestion.  Flag that in the queue's VM-visible
     812                 :            :  * state flags and increment the global gounter of congested queues.
     813                 :            :  */
     814                 :            : static inline void blk_set_queue_congested(struct request_queue *q, int sync)
     815                 :            : {
     816                 :      13102 :         set_bdi_congested(&q->backing_dev_info, sync);
     817                 :            : }
     818                 :            : 
     819                 :            : extern void blk_start_queue(struct request_queue *q);
     820                 :            : extern void blk_stop_queue(struct request_queue *q);
     821                 :            : extern void blk_sync_queue(struct request_queue *q);
     822                 :            : extern void __blk_stop_queue(struct request_queue *q);
     823                 :            : extern void __blk_run_queue(struct request_queue *q);
     824                 :            : extern void blk_run_queue(struct request_queue *);
     825                 :            : extern void blk_run_queue_async(struct request_queue *q);
     826                 :            : extern int blk_rq_map_user(struct request_queue *, struct request *,
     827                 :            :                            struct rq_map_data *, void __user *, unsigned long,
     828                 :            :                            gfp_t);
     829                 :            : extern int blk_rq_unmap_user(struct bio *);
     830                 :            : extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t);
     831                 :            : extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
     832                 :            :                                struct rq_map_data *, struct sg_iovec *, int,
     833                 :            :                                unsigned int, gfp_t);
     834                 :            : extern int blk_execute_rq(struct request_queue *, struct gendisk *,
     835                 :            :                           struct request *, int);
     836                 :            : extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
     837                 :            :                                   struct request *, int, rq_end_io_fn *);
     838                 :            : 
     839                 :            : static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
     840                 :            : {
     841                 :    3513572 :         return bdev->bd_disk->queue;
     842                 :            : }
     843                 :            : 
     844                 :            : /*
     845                 :            :  * blk_rq_pos()                 : the current sector
     846                 :            :  * blk_rq_bytes()               : bytes left in the entire request
     847                 :            :  * blk_rq_cur_bytes()           : bytes left in the current segment
     848                 :            :  * blk_rq_err_bytes()           : bytes left till the next error boundary
     849                 :            :  * blk_rq_sectors()             : sectors left in the entire request
     850                 :            :  * blk_rq_cur_sectors()         : sectors left in the current segment
     851                 :            :  */
     852                 :            : static inline sector_t blk_rq_pos(const struct request *rq)
     853                 :            : {
     854                 :            :         return rq->__sector;
     855                 :            : }
     856                 :            : 
     857                 :            : static inline unsigned int blk_rq_bytes(const struct request *rq)
     858                 :            : {
     859                 :            :         return rq->__data_len;
     860                 :            : }
     861                 :            : 
     862                 :            : static inline int blk_rq_cur_bytes(const struct request *rq)
     863                 :            : {
     864 [ #  # ][ #  # ]:          0 :         return rq->bio ? bio_cur_bytes(rq->bio) : 0;
         [ #  # ][ #  # ]
                 [ #  # ]
     865                 :            : }
     866                 :            : 
     867                 :            : extern unsigned int blk_rq_err_bytes(const struct request *rq);
     868                 :            : 
     869                 :    4187421 : static inline unsigned int blk_rq_sectors(const struct request *rq)
     870                 :            : {
     871                 :    3574509 :         return blk_rq_bytes(rq) >> 9;
     872                 :            : }
     873                 :            : 
     874                 :          0 : static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
     875                 :            : {
     876                 :          0 :         return blk_rq_cur_bytes(rq) >> 9;
     877                 :            : }
     878                 :            : 
     879                 :            : static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
     880                 :            :                                                      unsigned int cmd_flags)
     881                 :            : {
     882 [ -  + ][ -  + ]:     122098 :         if (unlikely(cmd_flags & REQ_DISCARD))
                 [ -  + ]
     883                 :          0 :                 return min(q->limits.max_discard_sectors, UINT_MAX >> 9);
     884                 :            : 
     885 [ -  + ][ -  + ]:     122098 :         if (unlikely(cmd_flags & REQ_WRITE_SAME))
                 [ -  + ]
     886                 :          0 :                 return q->limits.max_write_same_sectors;
     887                 :            : 
     888                 :     122098 :         return q->limits.max_sectors;
     889                 :            : }
     890                 :            : 
     891                 :            : static inline unsigned int blk_rq_get_max_sectors(struct request *rq)
     892                 :            : {
     893                 :     120551 :         struct request_queue *q = rq->q;
     894                 :            : 
     895 [ -  + ][ -  + ]:     122098 :         if (unlikely(rq->cmd_type == REQ_TYPE_BLOCK_PC))
                 [ -  + ]
     896                 :          0 :                 return q->limits.max_hw_sectors;
     897                 :            : 
     898                 :     122098 :         return blk_queue_get_max_sectors(q, rq->cmd_flags);
     899                 :            : }
     900                 :            : 
     901                 :            : static inline unsigned int blk_rq_count_bios(struct request *rq)
     902                 :            : {
     903                 :            :         unsigned int nr_bios = 0;
     904                 :            :         struct bio *bio;
     905                 :            : 
     906         [ #  # ]:          0 :         __rq_for_each_bio(bio, rq)
           [ #  #  #  # ]
                 [ #  # ]
     907                 :          0 :                 nr_bios++;
     908                 :            : 
     909                 :            :         return nr_bios;
     910                 :            : }
     911                 :            : 
     912                 :            : /*
     913                 :            :  * Request issue related functions.
     914                 :            :  */
     915                 :            : extern struct request *blk_peek_request(struct request_queue *q);
     916                 :            : extern void blk_start_request(struct request *rq);
     917                 :            : extern struct request *blk_fetch_request(struct request_queue *q);
     918                 :            : 
     919                 :            : /*
     920                 :            :  * Request completion related functions.
     921                 :            :  *
     922                 :            :  * blk_update_request() completes given number of bytes and updates
     923                 :            :  * the request without completing it.
     924                 :            :  *
     925                 :            :  * blk_end_request() and friends.  __blk_end_request() must be called
     926                 :            :  * with the request queue spinlock acquired.
     927                 :            :  *
     928                 :            :  * Several drivers define their own end_request and call
     929                 :            :  * blk_end_request() for parts of the original function.
     930                 :            :  * This prevents code duplication in drivers.
     931                 :            :  */
     932                 :            : extern bool blk_update_request(struct request *rq, int error,
     933                 :            :                                unsigned int nr_bytes);
     934                 :            : extern bool blk_end_request(struct request *rq, int error,
     935                 :            :                             unsigned int nr_bytes);
     936                 :            : extern void blk_end_request_all(struct request *rq, int error);
     937                 :            : extern bool blk_end_request_cur(struct request *rq, int error);
     938                 :            : extern bool blk_end_request_err(struct request *rq, int error);
     939                 :            : extern bool __blk_end_request(struct request *rq, int error,
     940                 :            :                               unsigned int nr_bytes);
     941                 :            : extern void __blk_end_request_all(struct request *rq, int error);
     942                 :            : extern bool __blk_end_request_cur(struct request *rq, int error);
     943                 :            : extern bool __blk_end_request_err(struct request *rq, int error);
     944                 :            : 
     945                 :            : extern void blk_complete_request(struct request *);
     946                 :            : extern void __blk_complete_request(struct request *);
     947                 :            : extern void blk_abort_request(struct request *);
     948                 :            : extern void blk_unprep_request(struct request *);
     949                 :            : 
     950                 :            : /*
     951                 :            :  * Access functions for manipulating queue properties
     952                 :            :  */
     953                 :            : extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn,
     954                 :            :                                         spinlock_t *lock, int node_id);
     955                 :            : extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *);
     956                 :            : extern struct request_queue *blk_init_allocated_queue(struct request_queue *,
     957                 :            :                                                       request_fn_proc *, spinlock_t *);
     958                 :            : extern void blk_cleanup_queue(struct request_queue *);
     959                 :            : extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
     960                 :            : extern void blk_queue_bounce_limit(struct request_queue *, u64);
     961                 :            : extern void blk_limits_max_hw_sectors(struct queue_limits *, unsigned int);
     962                 :            : extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
     963                 :            : extern void blk_queue_max_segments(struct request_queue *, unsigned short);
     964                 :            : extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
     965                 :            : extern void blk_queue_max_discard_sectors(struct request_queue *q,
     966                 :            :                 unsigned int max_discard_sectors);
     967                 :            : extern void blk_queue_max_write_same_sectors(struct request_queue *q,
     968                 :            :                 unsigned int max_write_same_sectors);
     969                 :            : extern void blk_queue_logical_block_size(struct request_queue *, unsigned short);
     970                 :            : extern void blk_queue_physical_block_size(struct request_queue *, unsigned int);
     971                 :            : extern void blk_queue_alignment_offset(struct request_queue *q,
     972                 :            :                                        unsigned int alignment);
     973                 :            : extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);
     974                 :            : extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
     975                 :            : extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt);
     976                 :            : extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
     977                 :            : extern void blk_set_default_limits(struct queue_limits *lim);
     978                 :            : extern void blk_set_stacking_limits(struct queue_limits *lim);
     979                 :            : extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
     980                 :            :                             sector_t offset);
     981                 :            : extern int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev,
     982                 :            :                             sector_t offset);
     983                 :            : extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
     984                 :            :                               sector_t offset);
     985                 :            : extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b);
     986                 :            : extern void blk_queue_dma_pad(struct request_queue *, unsigned int);
     987                 :            : extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
     988                 :            : extern int blk_queue_dma_drain(struct request_queue *q,
     989                 :            :                                dma_drain_needed_fn *dma_drain_needed,
     990                 :            :                                void *buf, unsigned int size);
     991                 :            : extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
     992                 :            : extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
     993                 :            : extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
     994                 :            : extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn);
     995                 :            : extern void blk_queue_merge_bvec(struct request_queue *, merge_bvec_fn *);
     996                 :            : extern void blk_queue_dma_alignment(struct request_queue *, int);
     997                 :            : extern void blk_queue_update_dma_alignment(struct request_queue *, int);
     998                 :            : extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *);
     999                 :            : extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *);
    1000                 :            : extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
    1001                 :            : extern void blk_queue_flush(struct request_queue *q, unsigned int flush);
    1002                 :            : extern void blk_queue_flush_queueable(struct request_queue *q, bool queueable);
    1003                 :            : extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev);
    1004                 :            : 
    1005                 :            : extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *);
    1006                 :            : extern int blk_bio_map_sg(struct request_queue *q, struct bio *bio,
    1007                 :            :                           struct scatterlist *sglist);
    1008                 :            : extern void blk_dump_rq_flags(struct request *, char *);
    1009                 :            : extern long nr_blockdev_pages(void);
    1010                 :            : 
    1011                 :            : bool __must_check blk_get_queue(struct request_queue *);
    1012                 :            : struct request_queue *blk_alloc_queue(gfp_t);
    1013                 :            : struct request_queue *blk_alloc_queue_node(gfp_t, int);
    1014                 :            : extern void blk_put_queue(struct request_queue *);
    1015                 :            : 
    1016                 :            : /*
    1017                 :            :  * block layer runtime pm functions
    1018                 :            :  */
    1019                 :            : #ifdef CONFIG_PM_RUNTIME
    1020                 :            : extern void blk_pm_runtime_init(struct request_queue *q, struct device *dev);
    1021                 :            : extern int blk_pre_runtime_suspend(struct request_queue *q);
    1022                 :            : extern void blk_post_runtime_suspend(struct request_queue *q, int err);
    1023                 :            : extern void blk_pre_runtime_resume(struct request_queue *q);
    1024                 :            : extern void blk_post_runtime_resume(struct request_queue *q, int err);
    1025                 :            : #else
    1026                 :            : static inline void blk_pm_runtime_init(struct request_queue *q,
    1027                 :            :         struct device *dev) {}
    1028                 :            : static inline int blk_pre_runtime_suspend(struct request_queue *q)
    1029                 :            : {
    1030                 :            :         return -ENOSYS;
    1031                 :            : }
    1032                 :            : static inline void blk_post_runtime_suspend(struct request_queue *q, int err) {}
    1033                 :            : static inline void blk_pre_runtime_resume(struct request_queue *q) {}
    1034                 :            : static inline void blk_post_runtime_resume(struct request_queue *q, int err) {}
    1035                 :            : #endif
    1036                 :            : 
    1037                 :            : /*
    1038                 :            :  * blk_plug permits building a queue of related requests by holding the I/O
    1039                 :            :  * fragments for a short period. This allows merging of sequential requests
    1040                 :            :  * into single larger request. As the requests are moved from a per-task list to
    1041                 :            :  * the device's request_queue in a batch, this results in improved scalability
    1042                 :            :  * as the lock contention for request_queue lock is reduced.
    1043                 :            :  *
    1044                 :            :  * It is ok not to disable preemption when adding the request to the plug list
    1045                 :            :  * or when attempting a merge, because blk_schedule_flush_list() will only flush
    1046                 :            :  * the plug list when the task sleeps by itself. For details, please see
    1047                 :            :  * schedule() where blk_schedule_flush_plug() is called.
    1048                 :            :  */
    1049                 :            : struct blk_plug {
    1050                 :            :         unsigned long magic; /* detect uninitialized use-cases */
    1051                 :            :         struct list_head list; /* requests */
    1052                 :            :         struct list_head mq_list; /* blk-mq requests */
    1053                 :            :         struct list_head cb_list; /* md requires an unplug callback */
    1054                 :            : };
    1055                 :            : #define BLK_MAX_REQUEST_COUNT 16
    1056                 :            : 
    1057                 :            : struct blk_plug_cb;
    1058                 :            : typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool);
    1059                 :            : struct blk_plug_cb {
    1060                 :            :         struct list_head list;
    1061                 :            :         blk_plug_cb_fn callback;
    1062                 :            :         void *data;
    1063                 :            : };
    1064                 :            : extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug,
    1065                 :            :                                              void *data, int size);
    1066                 :            : extern void blk_start_plug(struct blk_plug *);
    1067                 :            : extern void blk_finish_plug(struct blk_plug *);
    1068                 :            : extern void blk_flush_plug_list(struct blk_plug *, bool);
    1069                 :            : 
    1070                 :            : static inline void blk_flush_plug(struct task_struct *tsk)
    1071                 :            : {
    1072                 :     410762 :         struct blk_plug *plug = tsk->plug;
    1073                 :            : 
    1074   [ +  +  +  + ]:     410762 :         if (plug)
    1075                 :     114327 :                 blk_flush_plug_list(plug, false);
    1076                 :            : }
    1077                 :            : 
    1078                 :            : static inline void blk_schedule_flush_plug(struct task_struct *tsk)
    1079                 :            : {
    1080                 :            :         struct blk_plug *plug = tsk->plug;
    1081                 :            : 
    1082         [ +  - ]:       1175 :         if (plug)
    1083                 :       1175 :                 blk_flush_plug_list(plug, true);
    1084                 :            : }
    1085                 :            : 
    1086                 :            : static inline bool blk_needs_flush_plug(struct task_struct *tsk)
    1087                 :            : {
    1088                 :   12064969 :         struct blk_plug *plug = tsk->plug;
    1089                 :            : 
    1090         [ -  + ]:   12064969 :         return plug &&
           [ #  #  +  + ]
                 [ +  + ]
    1091         [ +  - ]:     114601 :                 (!list_empty(&plug->list) ||
    1092         [ +  + ]:   12063794 :                  !list_empty(&plug->mq_list) ||
    1093                 :     114601 :                  !list_empty(&plug->cb_list));
    1094                 :            : }
    1095                 :            : 
    1096                 :            : /*
    1097                 :            :  * tag stuff
    1098                 :            :  */
    1099                 :            : #define blk_rq_tagged(rq)               ((rq)->cmd_flags & REQ_QUEUED)
    1100                 :            : extern int blk_queue_start_tag(struct request_queue *, struct request *);
    1101                 :            : extern struct request *blk_queue_find_tag(struct request_queue *, int);
    1102                 :            : extern void blk_queue_end_tag(struct request_queue *, struct request *);
    1103                 :            : extern int blk_queue_init_tags(struct request_queue *, int, struct blk_queue_tag *);
    1104                 :            : extern void blk_queue_free_tags(struct request_queue *);
    1105                 :            : extern int blk_queue_resize_tags(struct request_queue *, int);
    1106                 :            : extern void blk_queue_invalidate_tags(struct request_queue *);
    1107                 :            : extern struct blk_queue_tag *blk_init_tags(int);
    1108                 :            : extern void blk_free_tags(struct blk_queue_tag *);
    1109                 :            : 
    1110                 :            : static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
    1111                 :            :                                                 int tag)
    1112                 :            : {
    1113 [ #  # ][ #  # ]:          0 :         if (unlikely(bqt == NULL || tag >= bqt->real_max_depth))
    1114                 :            :                 return NULL;
    1115                 :          0 :         return bqt->tag_index[tag];
    1116                 :            : }
    1117                 :            : 
    1118                 :            : #define BLKDEV_DISCARD_SECURE  0x01    /* secure discard */
    1119                 :            : 
    1120                 :            : extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *);
    1121                 :            : extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
    1122                 :            :                 sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
    1123                 :            : extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
    1124                 :            :                 sector_t nr_sects, gfp_t gfp_mask, struct page *page);
    1125                 :            : extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
    1126                 :            :                         sector_t nr_sects, gfp_t gfp_mask);
    1127                 :            : static inline int sb_issue_discard(struct super_block *sb, sector_t block,
    1128                 :            :                 sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
    1129                 :            : {
    1130                 :          0 :         return blkdev_issue_discard(sb->s_bdev, block << (sb->s_blocksize_bits - 9),
    1131                 :            :                                     nr_blocks << (sb->s_blocksize_bits - 9),
    1132                 :            :                                     gfp_mask, flags);
    1133                 :            : }
    1134                 :            : static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
    1135                 :            :                 sector_t nr_blocks, gfp_t gfp_mask)
    1136                 :            : {
    1137                 :          0 :         return blkdev_issue_zeroout(sb->s_bdev,
    1138                 :          0 :                                     block << (sb->s_blocksize_bits - 9),
    1139                 :            :                                     nr_blocks << (sb->s_blocksize_bits - 9),
    1140                 :            :                                     gfp_mask);
    1141                 :            : }
    1142                 :            : 
    1143                 :            : extern int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm);
    1144                 :            : 
    1145                 :            : enum blk_default_limits {
    1146                 :            :         BLK_MAX_SEGMENTS        = 128,
    1147                 :            :         BLK_SAFE_MAX_SECTORS    = 255,
    1148                 :            :         BLK_DEF_MAX_SECTORS     = 1024,
    1149                 :            :         BLK_MAX_SEGMENT_SIZE    = 65536,
    1150                 :            :         BLK_SEG_BOUNDARY_MASK   = 0xFFFFFFFFUL,
    1151                 :            : };
    1152                 :            : 
    1153                 :            : #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist)
    1154                 :            : 
    1155                 :            : static inline unsigned long queue_bounce_pfn(struct request_queue *q)
    1156                 :            : {
    1157                 :            :         return q->limits.bounce_pfn;
    1158                 :            : }
    1159                 :            : 
    1160                 :            : static inline unsigned long queue_segment_boundary(struct request_queue *q)
    1161                 :            : {
    1162                 :            :         return q->limits.seg_boundary_mask;
    1163                 :            : }
    1164                 :            : 
    1165                 :            : static inline unsigned int queue_max_sectors(struct request_queue *q)
    1166                 :            : {
    1167                 :            :         return q->limits.max_sectors;
    1168                 :            : }
    1169                 :            : 
    1170                 :            : static inline unsigned int queue_max_hw_sectors(struct request_queue *q)
    1171                 :            : {
    1172                 :            :         return q->limits.max_hw_sectors;
    1173                 :            : }
    1174                 :            : 
    1175                 :            : static inline unsigned short queue_max_segments(struct request_queue *q)
    1176                 :            : {
    1177                 :            :         return q->limits.max_segments;
    1178                 :            : }
    1179                 :            : 
    1180                 :            : static inline unsigned int queue_max_segment_size(struct request_queue *q)
    1181                 :            : {
    1182                 :            :         return q->limits.max_segment_size;
    1183                 :            : }
    1184                 :            : 
    1185                 :            : static inline unsigned short queue_logical_block_size(struct request_queue *q)
    1186                 :            : {
    1187                 :            :         int retval = 512;
    1188                 :            : 
    1189 [ +  + ][ +  - ]:      59611 :         if (q && q->limits.logical_block_size)
         [ +  - ][ +  - ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1190                 :      59607 :                 retval = q->limits.logical_block_size;
    1191                 :            : 
    1192                 :      59603 :         return retval;
    1193                 :            : }
    1194                 :            : 
    1195                 :      59603 : static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
    1196                 :            : {
    1197                 :            :         return queue_logical_block_size(bdev_get_queue(bdev));
    1198                 :            : }
    1199                 :            : 
    1200                 :            : static inline unsigned int queue_physical_block_size(struct request_queue *q)
    1201                 :            : {
    1202                 :            :         return q->limits.physical_block_size;
    1203                 :            : }
    1204                 :            : 
    1205                 :            : static inline unsigned int bdev_physical_block_size(struct block_device *bdev)
    1206                 :            : {
    1207                 :          0 :         return queue_physical_block_size(bdev_get_queue(bdev));
    1208                 :            : }
    1209                 :            : 
    1210                 :            : static inline unsigned int queue_io_min(struct request_queue *q)
    1211                 :            : {
    1212                 :            :         return q->limits.io_min;
    1213                 :            : }
    1214                 :            : 
    1215                 :            : static inline int bdev_io_min(struct block_device *bdev)
    1216                 :            : {
    1217                 :          0 :         return queue_io_min(bdev_get_queue(bdev));
    1218                 :            : }
    1219                 :            : 
    1220                 :            : static inline unsigned int queue_io_opt(struct request_queue *q)
    1221                 :            : {
    1222                 :            :         return q->limits.io_opt;
    1223                 :            : }
    1224                 :            : 
    1225                 :            : static inline int bdev_io_opt(struct block_device *bdev)
    1226                 :            : {
    1227                 :          0 :         return queue_io_opt(bdev_get_queue(bdev));
    1228                 :            : }
    1229                 :            : 
    1230                 :            : static inline int queue_alignment_offset(struct request_queue *q)
    1231                 :            : {
    1232         [ #  # ]:          0 :         if (q->limits.misaligned)
    1233                 :            :                 return -1;
    1234                 :            : 
    1235                 :          0 :         return q->limits.alignment_offset;
    1236                 :            : }
    1237                 :            : 
    1238                 :            : static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
    1239                 :            : {
    1240                 :          0 :         unsigned int granularity = max(lim->physical_block_size, lim->io_min);
    1241                 :          0 :         unsigned int alignment = (sector << 9) & (granularity - 1);
    1242                 :            : 
    1243                 :          0 :         return (granularity + lim->alignment_offset - alignment)
    1244                 :          0 :                 & (granularity - 1);
    1245                 :            : }
    1246                 :            : 
    1247                 :            : static inline int bdev_alignment_offset(struct block_device *bdev)
    1248                 :            : {
    1249                 :            :         struct request_queue *q = bdev_get_queue(bdev);
    1250                 :            : 
    1251         [ #  # ]:          0 :         if (q->limits.misaligned)
    1252                 :            :                 return -1;
    1253                 :            : 
    1254         [ #  # ]:          0 :         if (bdev != bdev->bd_contains)
    1255                 :          0 :                 return bdev->bd_part->alignment_offset;
    1256                 :            : 
    1257                 :          0 :         return q->limits.alignment_offset;
    1258                 :            : }
    1259                 :            : 
    1260                 :            : static inline int queue_discard_alignment(struct request_queue *q)
    1261                 :            : {
    1262         [ #  # ]:          0 :         if (q->limits.discard_misaligned)
    1263                 :            :                 return -1;
    1264                 :            : 
    1265                 :          0 :         return q->limits.discard_alignment;
    1266                 :            : }
    1267                 :            : 
    1268                 :            : static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
    1269                 :            : {
    1270                 :            :         unsigned int alignment, granularity, offset;
    1271                 :            : 
    1272         [ #  # ]:          0 :         if (!lim->max_discard_sectors)
    1273                 :            :                 return 0;
    1274                 :            : 
    1275                 :            :         /* Why are these in bytes, not sectors? */
    1276                 :          0 :         alignment = lim->discard_alignment >> 9;
    1277                 :          0 :         granularity = lim->discard_granularity >> 9;
    1278         [ #  # ]:          0 :         if (!granularity)
    1279                 :            :                 return 0;
    1280                 :            : 
    1281                 :            :         /* Offset of the partition start in 'granularity' sectors */
    1282 [ #  # ][ #  # ]:          0 :         offset = sector_div(sector, granularity);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1283                 :            : 
    1284                 :            :         /* And why do we do this modulus *again* in blkdev_issue_discard()? */
    1285                 :          0 :         offset = (granularity + alignment - offset) % granularity;
    1286                 :            : 
    1287                 :            :         /* Turn it back into bytes, gaah */
    1288                 :          0 :         return offset << 9;
    1289                 :            : }
    1290                 :            : 
    1291                 :            : static inline int bdev_discard_alignment(struct block_device *bdev)
    1292                 :            : {
    1293                 :            :         struct request_queue *q = bdev_get_queue(bdev);
    1294                 :            : 
    1295         [ #  # ]:          0 :         if (bdev != bdev->bd_contains)
    1296                 :          0 :                 return bdev->bd_part->discard_alignment;
    1297                 :            : 
    1298                 :          0 :         return q->limits.discard_alignment;
    1299                 :            : }
    1300                 :            : 
    1301                 :            : static inline unsigned int queue_discard_zeroes_data(struct request_queue *q)
    1302                 :            : {
    1303 [ #  # ][ #  # ]:          0 :         if (q->limits.max_discard_sectors && q->limits.discard_zeroes_data == 1)
    1304                 :            :                 return 1;
    1305                 :            : 
    1306                 :            :         return 0;
    1307                 :            : }
    1308                 :            : 
    1309                 :            : static inline unsigned int bdev_discard_zeroes_data(struct block_device *bdev)
    1310                 :            : {
    1311                 :          0 :         return queue_discard_zeroes_data(bdev_get_queue(bdev));
    1312                 :            : }
    1313                 :            : 
    1314                 :          0 : static inline unsigned int bdev_write_same(struct block_device *bdev)
    1315                 :            : {
    1316                 :            :         struct request_queue *q = bdev_get_queue(bdev);
    1317                 :            : 
    1318         [ #  # ]:          0 :         if (q)
    1319                 :          0 :                 return q->limits.max_write_same_sectors;
    1320                 :            : 
    1321                 :            :         return 0;
    1322                 :            : }
    1323                 :            : 
    1324                 :            : static inline int queue_dma_alignment(struct request_queue *q)
    1325                 :            : {
    1326 [ #  # ][ #  # ]:          0 :         return q ? q->dma_alignment : 511;
                 [ #  # ]
    1327                 :            : }
    1328                 :            : 
    1329                 :            : static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,
    1330                 :            :                                  unsigned int len)
    1331                 :            : {
    1332                 :          0 :         unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
    1333 [ #  # ][ #  # ]:          0 :         return !(addr & alignment) && !(len & alignment);
         [ #  # ][ #  # ]
    1334                 :            : }
    1335                 :            : 
    1336                 :            : /* assumes size > 256 */
    1337                 :            : static inline unsigned int blksize_bits(unsigned int size)
    1338                 :            : {
    1339                 :            :         unsigned int bits = 8;
    1340                 :            :         do {
    1341                 :     238392 :                 bits++;
    1342                 :     238392 :                 size >>= 1;
    1343 [ +  + ][ #  # ]:     238392 :         } while (size > 256);
         [ #  # ][ -  + ]
    1344                 :            :         return bits;
    1345                 :            : }
    1346                 :            : 
    1347                 :            : static inline unsigned int block_size(struct block_device *bdev)
    1348                 :            : {
    1349                 :            :         return bdev->bd_block_size;
    1350                 :            : }
    1351                 :            : 
    1352                 :            : static inline bool queue_flush_queueable(struct request_queue *q)
    1353                 :            : {
    1354                 :          0 :         return !q->flush_not_queueable;
    1355                 :            : }
    1356                 :            : 
    1357                 :            : typedef struct {struct page *v;} Sector;
    1358                 :            : 
    1359                 :            : unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *);
    1360                 :            : 
    1361                 :            : static inline void put_dev_sector(Sector p)
    1362                 :            : {
    1363                 :          0 :         page_cache_release(p.v);
    1364                 :            : }
    1365                 :            : 
    1366                 :            : struct work_struct;
    1367                 :            : int kblockd_schedule_work(struct request_queue *q, struct work_struct *work);
    1368                 :            : int kblockd_schedule_delayed_work(struct request_queue *q, struct delayed_work *dwork, unsigned long delay);
    1369                 :            : 
    1370                 :            : #ifdef CONFIG_BLK_CGROUP
    1371                 :            : /*
    1372                 :            :  * This should not be using sched_clock(). A real patch is in progress
    1373                 :            :  * to fix this up, until that is in place we need to disable preemption
    1374                 :            :  * around sched_clock() in this function and set_io_start_time_ns().
    1375                 :            :  */
    1376                 :            : static inline void set_start_time_ns(struct request *req)
    1377                 :            : {
    1378                 :            :         preempt_disable();
    1379                 :            :         req->start_time_ns = sched_clock();
    1380                 :            :         preempt_enable();
    1381                 :            : }
    1382                 :            : 
    1383                 :            : static inline void set_io_start_time_ns(struct request *req)
    1384                 :            : {
    1385                 :            :         preempt_disable();
    1386                 :            :         req->io_start_time_ns = sched_clock();
    1387                 :            :         preempt_enable();
    1388                 :            : }
    1389                 :            : 
    1390                 :            : static inline uint64_t rq_start_time_ns(struct request *req)
    1391                 :            : {
    1392                 :            :         return req->start_time_ns;
    1393                 :            : }
    1394                 :            : 
    1395                 :            : static inline uint64_t rq_io_start_time_ns(struct request *req)
    1396                 :            : {
    1397                 :            :         return req->io_start_time_ns;
    1398                 :            : }
    1399                 :            : #else
    1400                 :            : static inline void set_start_time_ns(struct request *req) {}
    1401                 :            : static inline void set_io_start_time_ns(struct request *req) {}
    1402                 :            : static inline uint64_t rq_start_time_ns(struct request *req)
    1403                 :            : {
    1404                 :            :         return 0;
    1405                 :            : }
    1406                 :            : static inline uint64_t rq_io_start_time_ns(struct request *req)
    1407                 :            : {
    1408                 :            :         return 0;
    1409                 :            : }
    1410                 :            : #endif
    1411                 :            : 
    1412                 :            : #define MODULE_ALIAS_BLOCKDEV(major,minor) \
    1413                 :            :         MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
    1414                 :            : #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
    1415                 :            :         MODULE_ALIAS("block-major-" __stringify(major) "-*")
    1416                 :            : 
    1417                 :            : #if defined(CONFIG_BLK_DEV_INTEGRITY)
    1418                 :            : 
    1419                 :            : #define INTEGRITY_FLAG_READ     2       /* verify data integrity on read */
    1420                 :            : #define INTEGRITY_FLAG_WRITE    4       /* generate data integrity on write */
    1421                 :            : 
    1422                 :            : struct blk_integrity_exchg {
    1423                 :            :         void                    *prot_buf;
    1424                 :            :         void                    *data_buf;
    1425                 :            :         sector_t                sector;
    1426                 :            :         unsigned int            data_size;
    1427                 :            :         unsigned short          sector_size;
    1428                 :            :         const char              *disk_name;
    1429                 :            : };
    1430                 :            : 
    1431                 :            : typedef void (integrity_gen_fn) (struct blk_integrity_exchg *);
    1432                 :            : typedef int (integrity_vrfy_fn) (struct blk_integrity_exchg *);
    1433                 :            : typedef void (integrity_set_tag_fn) (void *, void *, unsigned int);
    1434                 :            : typedef void (integrity_get_tag_fn) (void *, void *, unsigned int);
    1435                 :            : 
    1436                 :            : struct blk_integrity {
    1437                 :            :         integrity_gen_fn        *generate_fn;
    1438                 :            :         integrity_vrfy_fn       *verify_fn;
    1439                 :            :         integrity_set_tag_fn    *set_tag_fn;
    1440                 :            :         integrity_get_tag_fn    *get_tag_fn;
    1441                 :            : 
    1442                 :            :         unsigned short          flags;
    1443                 :            :         unsigned short          tuple_size;
    1444                 :            :         unsigned short          sector_size;
    1445                 :            :         unsigned short          tag_size;
    1446                 :            : 
    1447                 :            :         const char              *name;
    1448                 :            : 
    1449                 :            :         struct kobject          kobj;
    1450                 :            : };
    1451                 :            : 
    1452                 :            : extern bool blk_integrity_is_initialized(struct gendisk *);
    1453                 :            : extern int blk_integrity_register(struct gendisk *, struct blk_integrity *);
    1454                 :            : extern void blk_integrity_unregister(struct gendisk *);
    1455                 :            : extern int blk_integrity_compare(struct gendisk *, struct gendisk *);
    1456                 :            : extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *,
    1457                 :            :                                    struct scatterlist *);
    1458                 :            : extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *);
    1459                 :            : extern int blk_integrity_merge_rq(struct request_queue *, struct request *,
    1460                 :            :                                   struct request *);
    1461                 :            : extern int blk_integrity_merge_bio(struct request_queue *, struct request *,
    1462                 :            :                                    struct bio *);
    1463                 :            : 
    1464                 :            : static inline
    1465                 :            : struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
    1466                 :            : {
    1467                 :            :         return bdev->bd_disk->integrity;
    1468                 :            : }
    1469                 :            : 
    1470                 :            : static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
    1471                 :            : {
    1472                 :            :         return disk->integrity;
    1473                 :            : }
    1474                 :            : 
    1475                 :            : static inline int blk_integrity_rq(struct request *rq)
    1476                 :            : {
    1477                 :            :         if (rq->bio == NULL)
    1478                 :            :                 return 0;
    1479                 :            : 
    1480                 :            :         return bio_integrity(rq->bio);
    1481                 :            : }
    1482                 :            : 
    1483                 :            : static inline void blk_queue_max_integrity_segments(struct request_queue *q,
    1484                 :            :                                                     unsigned int segs)
    1485                 :            : {
    1486                 :            :         q->limits.max_integrity_segments = segs;
    1487                 :            : }
    1488                 :            : 
    1489                 :            : static inline unsigned short
    1490                 :            : queue_max_integrity_segments(struct request_queue *q)
    1491                 :            : {
    1492                 :            :         return q->limits.max_integrity_segments;
    1493                 :            : }
    1494                 :            : 
    1495                 :            : #else /* CONFIG_BLK_DEV_INTEGRITY */
    1496                 :            : 
    1497                 :            : struct bio;
    1498                 :            : struct block_device;
    1499                 :            : struct gendisk;
    1500                 :            : struct blk_integrity;
    1501                 :            : 
    1502                 :            : static inline int blk_integrity_rq(struct request *rq)
    1503                 :            : {
    1504                 :            :         return 0;
    1505                 :            : }
    1506                 :            : static inline int blk_rq_count_integrity_sg(struct request_queue *q,
    1507                 :            :                                             struct bio *b)
    1508                 :            : {
    1509                 :            :         return 0;
    1510                 :            : }
    1511                 :            : static inline int blk_rq_map_integrity_sg(struct request_queue *q,
    1512                 :            :                                           struct bio *b,
    1513                 :            :                                           struct scatterlist *s)
    1514                 :            : {
    1515                 :            :         return 0;
    1516                 :            : }
    1517                 :            : static inline struct blk_integrity *bdev_get_integrity(struct block_device *b)
    1518                 :            : {
    1519                 :            :         return 0;
    1520                 :            : }
    1521                 :            : static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
    1522                 :            : {
    1523                 :            :         return NULL;
    1524                 :            : }
    1525                 :            : static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b)
    1526                 :            : {
    1527                 :            :         return 0;
    1528                 :            : }
    1529                 :            : static inline int blk_integrity_register(struct gendisk *d,
    1530                 :            :                                          struct blk_integrity *b)
    1531                 :            : {
    1532                 :            :         return 0;
    1533                 :            : }
    1534                 :            : static inline void blk_integrity_unregister(struct gendisk *d)
    1535                 :            : {
    1536                 :            : }
    1537                 :            : static inline void blk_queue_max_integrity_segments(struct request_queue *q,
    1538                 :            :                                                     unsigned int segs)
    1539                 :            : {
    1540                 :            : }
    1541                 :            : static inline unsigned short queue_max_integrity_segments(struct request_queue *q)
    1542                 :            : {
    1543                 :            :         return 0;
    1544                 :            : }
    1545                 :            : static inline int blk_integrity_merge_rq(struct request_queue *rq,
    1546                 :            :                                          struct request *r1,
    1547                 :            :                                          struct request *r2)
    1548                 :            : {
    1549                 :            :         return 0;
    1550                 :            : }
    1551                 :            : static inline int blk_integrity_merge_bio(struct request_queue *rq,
    1552                 :            :                                           struct request *r,
    1553                 :            :                                           struct bio *b)
    1554                 :            : {
    1555                 :            :         return 0;
    1556                 :            : }
    1557                 :            : static inline bool blk_integrity_is_initialized(struct gendisk *g)
    1558                 :            : {
    1559                 :            :         return 0;
    1560                 :            : }
    1561                 :            : 
    1562                 :            : #endif /* CONFIG_BLK_DEV_INTEGRITY */
    1563                 :            : 
    1564                 :            : struct block_device_operations {
    1565                 :            :         int (*open) (struct block_device *, fmode_t);
    1566                 :            :         void (*release) (struct gendisk *, fmode_t);
    1567                 :            :         int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
    1568                 :            :         int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
    1569                 :            :         int (*direct_access) (struct block_device *, sector_t,
    1570                 :            :                                                 void **, unsigned long *);
    1571                 :            :         unsigned int (*check_events) (struct gendisk *disk,
    1572                 :            :                                       unsigned int clearing);
    1573                 :            :         /* ->media_changed() is DEPRECATED, use ->check_events() instead */
    1574                 :            :         int (*media_changed) (struct gendisk *);
    1575                 :            :         void (*unlock_native_capacity) (struct gendisk *);
    1576                 :            :         int (*revalidate_disk) (struct gendisk *);
    1577                 :            :         int (*getgeo)(struct block_device *, struct hd_geometry *);
    1578                 :            :         /* this callback is with swap_lock and sometimes page table lock held */
    1579                 :            :         void (*swap_slot_free_notify) (struct block_device *, unsigned long);
    1580                 :            :         struct module *owner;
    1581                 :            : };
    1582                 :            : 
    1583                 :            : extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
    1584                 :            :                                  unsigned long);
    1585                 :            : #else /* CONFIG_BLOCK */
    1586                 :            : /*
    1587                 :            :  * stubs for when the block layer is configured out
    1588                 :            :  */
    1589                 :            : #define buffer_heads_over_limit 0
    1590                 :            : 
    1591                 :            : static inline long nr_blockdev_pages(void)
    1592                 :            : {
    1593                 :            :         return 0;
    1594                 :            : }
    1595                 :            : 
    1596                 :            : struct blk_plug {
    1597                 :            : };
    1598                 :            : 
    1599                 :            : static inline void blk_start_plug(struct blk_plug *plug)
    1600                 :            : {
    1601                 :            : }
    1602                 :            : 
    1603                 :            : static inline void blk_finish_plug(struct blk_plug *plug)
    1604                 :            : {
    1605                 :            : }
    1606                 :            : 
    1607                 :            : static inline void blk_flush_plug(struct task_struct *task)
    1608                 :            : {
    1609                 :            : }
    1610                 :            : 
    1611                 :            : static inline void blk_schedule_flush_plug(struct task_struct *task)
    1612                 :            : {
    1613                 :            : }
    1614                 :            : 
    1615                 :            : 
    1616                 :            : static inline bool blk_needs_flush_plug(struct task_struct *tsk)
    1617                 :            : {
    1618                 :            :         return false;
    1619                 :            : }
    1620                 :            : 
    1621                 :            : #endif /* CONFIG_BLOCK */
    1622                 :            : 
    1623                 :            : #endif

Generated by: LCOV version 1.9