blk-core.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright (C) 1994, Karl Keyte: Added support for disk statistics
  5. * Elevator latency, (C) 2000 Andrea Arcangeli <[email protected]> SuSE
  6. * Queue request tables / lock, selectable elevator, Jens Axboe <[email protected]>
  7. * kernel-doc documentation started by NeilBrown <[email protected]>
  8. * - July2000
  9. * bio rewrite, highmem i/o, etc, Jens Axboe <[email protected]> - may 2001
  10. */
  11. /*
  12. * This handles all read/write requests to block devices
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/bio.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/blk-pm.h>
  19. #include <linux/blk-integrity.h>
  20. #include <linux/highmem.h>
  21. #include <linux/mm.h>
  22. #include <linux/pagemap.h>
  23. #include <linux/kernel_stat.h>
  24. #include <linux/string.h>
  25. #include <linux/init.h>
  26. #include <linux/completion.h>
  27. #include <linux/slab.h>
  28. #include <linux/swap.h>
  29. #include <linux/writeback.h>
  30. #include <linux/task_io_accounting_ops.h>
  31. #include <linux/fault-inject.h>
  32. #include <linux/list_sort.h>
  33. #include <linux/delay.h>
  34. #include <linux/ratelimit.h>
  35. #include <linux/pm_runtime.h>
  36. #include <linux/t10-pi.h>
  37. #include <linux/debugfs.h>
  38. #include <linux/bpf.h>
  39. #include <linux/part_stat.h>
  40. #include <linux/sched/sysctl.h>
  41. #include <linux/blk-crypto.h>
  42. #define CREATE_TRACE_POINTS
  43. #include <trace/events/block.h>
  44. #include "blk.h"
  45. #include "blk-mq-sched.h"
  46. #include "blk-pm.h"
  47. #include "blk-cgroup.h"
  48. #include "blk-throttle.h"
  49. struct dentry *blk_debugfs_root;
  50. EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
  51. EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
  52. EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete);
  53. EXPORT_TRACEPOINT_SYMBOL_GPL(block_split);
  54. EXPORT_TRACEPOINT_SYMBOL_GPL(block_unplug);
  55. EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_insert);
  56. EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_queue);
  57. EXPORT_TRACEPOINT_SYMBOL_GPL(block_getrq);
  58. EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_issue);
  59. EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_merge);
  60. EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_requeue);
  61. EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_complete);
  62. DEFINE_IDA(blk_queue_ida);
  63. /*
  64. * For queue allocation
  65. */
  66. struct kmem_cache *blk_requestq_cachep;
  67. struct kmem_cache *blk_requestq_srcu_cachep;
  68. /*
  69. * Controlling structure to kblockd
  70. */
  71. static struct workqueue_struct *kblockd_workqueue;
  72. /**
  73. * blk_queue_flag_set - atomically set a queue flag
  74. * @flag: flag to be set
  75. * @q: request queue
  76. */
  77. void blk_queue_flag_set(unsigned int flag, struct request_queue *q)
  78. {
  79. set_bit(flag, &q->queue_flags);
  80. }
  81. EXPORT_SYMBOL(blk_queue_flag_set);
  82. /**
  83. * blk_queue_flag_clear - atomically clear a queue flag
  84. * @flag: flag to be cleared
  85. * @q: request queue
  86. */
  87. void blk_queue_flag_clear(unsigned int flag, struct request_queue *q)
  88. {
  89. clear_bit(flag, &q->queue_flags);
  90. }
  91. EXPORT_SYMBOL(blk_queue_flag_clear);
  92. /**
  93. * blk_queue_flag_test_and_set - atomically test and set a queue flag
  94. * @flag: flag to be set
  95. * @q: request queue
  96. *
  97. * Returns the previous value of @flag - 0 if the flag was not set and 1 if
  98. * the flag was already set.
  99. */
  100. bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q)
  101. {
  102. return test_and_set_bit(flag, &q->queue_flags);
  103. }
  104. EXPORT_SYMBOL_GPL(blk_queue_flag_test_and_set);
  105. #define REQ_OP_NAME(name) [REQ_OP_##name] = #name
  106. static const char *const blk_op_name[] = {
  107. REQ_OP_NAME(READ),
  108. REQ_OP_NAME(WRITE),
  109. REQ_OP_NAME(FLUSH),
  110. REQ_OP_NAME(DISCARD),
  111. REQ_OP_NAME(SECURE_ERASE),
  112. REQ_OP_NAME(ZONE_RESET),
  113. REQ_OP_NAME(ZONE_RESET_ALL),
  114. REQ_OP_NAME(ZONE_OPEN),
  115. REQ_OP_NAME(ZONE_CLOSE),
  116. REQ_OP_NAME(ZONE_FINISH),
  117. REQ_OP_NAME(ZONE_APPEND),
  118. REQ_OP_NAME(WRITE_ZEROES),
  119. REQ_OP_NAME(DRV_IN),
  120. REQ_OP_NAME(DRV_OUT),
  121. };
  122. #undef REQ_OP_NAME
  123. /**
  124. * blk_op_str - Return string XXX in the REQ_OP_XXX.
  125. * @op: REQ_OP_XXX.
  126. *
  127. * Description: Centralize block layer function to convert REQ_OP_XXX into
  128. * string format. Useful in the debugging and tracing bio or request. For
  129. * invalid REQ_OP_XXX it returns string "UNKNOWN".
  130. */
  131. inline const char *blk_op_str(enum req_op op)
  132. {
  133. const char *op_str = "UNKNOWN";
  134. if (op < ARRAY_SIZE(blk_op_name) && blk_op_name[op])
  135. op_str = blk_op_name[op];
  136. return op_str;
  137. }
  138. EXPORT_SYMBOL_GPL(blk_op_str);
  139. static const struct {
  140. int errno;
  141. const char *name;
  142. } blk_errors[] = {
  143. [BLK_STS_OK] = { 0, "" },
  144. [BLK_STS_NOTSUPP] = { -EOPNOTSUPP, "operation not supported" },
  145. [BLK_STS_TIMEOUT] = { -ETIMEDOUT, "timeout" },
  146. [BLK_STS_NOSPC] = { -ENOSPC, "critical space allocation" },
  147. [BLK_STS_TRANSPORT] = { -ENOLINK, "recoverable transport" },
  148. [BLK_STS_TARGET] = { -EREMOTEIO, "critical target" },
  149. [BLK_STS_NEXUS] = { -EBADE, "critical nexus" },
  150. [BLK_STS_MEDIUM] = { -ENODATA, "critical medium" },
  151. [BLK_STS_PROTECTION] = { -EILSEQ, "protection" },
  152. [BLK_STS_RESOURCE] = { -ENOMEM, "kernel resource" },
  153. [BLK_STS_DEV_RESOURCE] = { -EBUSY, "device resource" },
  154. [BLK_STS_AGAIN] = { -EAGAIN, "nonblocking retry" },
  155. [BLK_STS_OFFLINE] = { -ENODEV, "device offline" },
  156. /* device mapper special case, should not leak out: */
  157. [BLK_STS_DM_REQUEUE] = { -EREMCHG, "dm internal retry" },
  158. /* zone device specific errors */
  159. [BLK_STS_ZONE_OPEN_RESOURCE] = { -ETOOMANYREFS, "open zones exceeded" },
  160. [BLK_STS_ZONE_ACTIVE_RESOURCE] = { -EOVERFLOW, "active zones exceeded" },
  161. /* everything else not covered above: */
  162. [BLK_STS_IOERR] = { -EIO, "I/O" },
  163. };
  164. blk_status_t errno_to_blk_status(int errno)
  165. {
  166. int i;
  167. for (i = 0; i < ARRAY_SIZE(blk_errors); i++) {
  168. if (blk_errors[i].errno == errno)
  169. return (__force blk_status_t)i;
  170. }
  171. return BLK_STS_IOERR;
  172. }
  173. EXPORT_SYMBOL_GPL(errno_to_blk_status);
  174. int blk_status_to_errno(blk_status_t status)
  175. {
  176. int idx = (__force int)status;
  177. if (WARN_ON_ONCE(idx >= ARRAY_SIZE(blk_errors)))
  178. return -EIO;
  179. return blk_errors[idx].errno;
  180. }
  181. EXPORT_SYMBOL_GPL(blk_status_to_errno);
  182. const char *blk_status_to_str(blk_status_t status)
  183. {
  184. int idx = (__force int)status;
  185. if (WARN_ON_ONCE(idx >= ARRAY_SIZE(blk_errors)))
  186. return "<null>";
  187. return blk_errors[idx].name;
  188. }
  189. /**
  190. * blk_sync_queue - cancel any pending callbacks on a queue
  191. * @q: the queue
  192. *
  193. * Description:
  194. * The block layer may perform asynchronous callback activity
  195. * on a queue, such as calling the unplug function after a timeout.
  196. * A block device may call blk_sync_queue to ensure that any
  197. * such activity is cancelled, thus allowing it to release resources
  198. * that the callbacks might use. The caller must already have made sure
  199. * that its ->submit_bio will not re-add plugging prior to calling
  200. * this function.
  201. *
  202. * This function does not cancel any asynchronous activity arising
  203. * out of elevator or throttling code. That would require elevator_exit()
  204. * and blkcg_exit_queue() to be called with queue lock initialized.
  205. *
  206. */
  207. void blk_sync_queue(struct request_queue *q)
  208. {
  209. del_timer_sync(&q->timeout);
  210. cancel_work_sync(&q->timeout_work);
  211. }
  212. EXPORT_SYMBOL(blk_sync_queue);
  213. /**
  214. * blk_set_pm_only - increment pm_only counter
  215. * @q: request queue pointer
  216. */
  217. void blk_set_pm_only(struct request_queue *q)
  218. {
  219. atomic_inc(&q->pm_only);
  220. }
  221. EXPORT_SYMBOL_GPL(blk_set_pm_only);
  222. void blk_clear_pm_only(struct request_queue *q)
  223. {
  224. int pm_only;
  225. pm_only = atomic_dec_return(&q->pm_only);
  226. WARN_ON_ONCE(pm_only < 0);
  227. if (pm_only == 0)
  228. wake_up_all(&q->mq_freeze_wq);
  229. }
  230. EXPORT_SYMBOL_GPL(blk_clear_pm_only);
  231. /**
  232. * blk_put_queue - decrement the request_queue refcount
  233. * @q: the request_queue structure to decrement the refcount for
  234. *
  235. * Decrements the refcount of the request_queue kobject. When this reaches 0
  236. * we'll have blk_release_queue() called.
  237. *
  238. * Context: Any context, but the last reference must not be dropped from
  239. * atomic context.
  240. */
  241. void blk_put_queue(struct request_queue *q)
  242. {
  243. kobject_put(&q->kobj);
  244. }
  245. EXPORT_SYMBOL(blk_put_queue);
  246. void blk_queue_start_drain(struct request_queue *q)
  247. {
  248. /*
  249. * When queue DYING flag is set, we need to block new req
  250. * entering queue, so we call blk_freeze_queue_start() to
  251. * prevent I/O from crossing blk_queue_enter().
  252. */
  253. blk_freeze_queue_start(q);
  254. if (queue_is_mq(q))
  255. blk_mq_wake_waiters(q);
  256. /* Make blk_queue_enter() reexamine the DYING flag. */
  257. wake_up_all(&q->mq_freeze_wq);
  258. }
  259. /**
  260. * blk_queue_enter() - try to increase q->q_usage_counter
  261. * @q: request queue pointer
  262. * @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PM
  263. */
  264. int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)
  265. {
  266. const bool pm = flags & BLK_MQ_REQ_PM;
  267. while (!blk_try_enter_queue(q, pm)) {
  268. if (flags & BLK_MQ_REQ_NOWAIT)
  269. return -EAGAIN;
  270. /*
  271. * read pair of barrier in blk_freeze_queue_start(), we need to
  272. * order reading __PERCPU_REF_DEAD flag of .q_usage_counter and
  273. * reading .mq_freeze_depth or queue dying flag, otherwise the
  274. * following wait may never return if the two reads are
  275. * reordered.
  276. */
  277. smp_rmb();
  278. wait_event(q->mq_freeze_wq,
  279. (!q->mq_freeze_depth &&
  280. blk_pm_resume_queue(pm, q)) ||
  281. blk_queue_dying(q));
  282. if (blk_queue_dying(q))
  283. return -ENODEV;
  284. }
  285. return 0;
  286. }
  287. int __bio_queue_enter(struct request_queue *q, struct bio *bio)
  288. {
  289. while (!blk_try_enter_queue(q, false)) {
  290. struct gendisk *disk = bio->bi_bdev->bd_disk;
  291. if (bio->bi_opf & REQ_NOWAIT) {
  292. if (test_bit(GD_DEAD, &disk->state))
  293. goto dead;
  294. bio_wouldblock_error(bio);
  295. return -EAGAIN;
  296. }
  297. /*
  298. * read pair of barrier in blk_freeze_queue_start(), we need to
  299. * order reading __PERCPU_REF_DEAD flag of .q_usage_counter and
  300. * reading .mq_freeze_depth or queue dying flag, otherwise the
  301. * following wait may never return if the two reads are
  302. * reordered.
  303. */
  304. smp_rmb();
  305. wait_event(q->mq_freeze_wq,
  306. (!q->mq_freeze_depth &&
  307. blk_pm_resume_queue(false, q)) ||
  308. test_bit(GD_DEAD, &disk->state));
  309. if (test_bit(GD_DEAD, &disk->state))
  310. goto dead;
  311. }
  312. return 0;
  313. dead:
  314. bio_io_error(bio);
  315. return -ENODEV;
  316. }
  317. void blk_queue_exit(struct request_queue *q)
  318. {
  319. percpu_ref_put(&q->q_usage_counter);
  320. }
  321. static void blk_queue_usage_counter_release(struct percpu_ref *ref)
  322. {
  323. struct request_queue *q =
  324. container_of(ref, struct request_queue, q_usage_counter);
  325. wake_up_all(&q->mq_freeze_wq);
  326. }
  327. static void blk_rq_timed_out_timer(struct timer_list *t)
  328. {
  329. struct request_queue *q = from_timer(q, t, timeout);
  330. kblockd_schedule_work(&q->timeout_work);
  331. }
  332. static void blk_timeout_work(struct work_struct *work)
  333. {
  334. }
  335. struct request_queue *blk_alloc_queue(int node_id, bool alloc_srcu)
  336. {
  337. struct request_queue *q;
  338. q = kmem_cache_alloc_node(blk_get_queue_kmem_cache(alloc_srcu),
  339. GFP_KERNEL | __GFP_ZERO, node_id);
  340. if (!q)
  341. return NULL;
  342. if (alloc_srcu) {
  343. blk_queue_flag_set(QUEUE_FLAG_HAS_SRCU, q);
  344. if (init_srcu_struct(q->srcu) != 0)
  345. goto fail_q;
  346. }
  347. q->last_merge = NULL;
  348. q->id = ida_alloc(&blk_queue_ida, GFP_KERNEL);
  349. if (q->id < 0)
  350. goto fail_srcu;
  351. q->stats = blk_alloc_queue_stats();
  352. if (!q->stats)
  353. goto fail_id;
  354. q->node = node_id;
  355. atomic_set(&q->nr_active_requests_shared_tags, 0);
  356. timer_setup(&q->timeout, blk_rq_timed_out_timer, 0);
  357. INIT_WORK(&q->timeout_work, blk_timeout_work);
  358. INIT_LIST_HEAD(&q->icq_list);
  359. kobject_init(&q->kobj, &blk_queue_ktype);
  360. mutex_init(&q->debugfs_mutex);
  361. mutex_init(&q->sysfs_lock);
  362. mutex_init(&q->sysfs_dir_lock);
  363. spin_lock_init(&q->queue_lock);
  364. init_waitqueue_head(&q->mq_freeze_wq);
  365. mutex_init(&q->mq_freeze_lock);
  366. /*
  367. * Init percpu_ref in atomic mode so that it's faster to shutdown.
  368. * See blk_register_queue() for details.
  369. */
  370. if (percpu_ref_init(&q->q_usage_counter,
  371. blk_queue_usage_counter_release,
  372. PERCPU_REF_INIT_ATOMIC, GFP_KERNEL))
  373. goto fail_stats;
  374. blk_set_default_limits(&q->limits);
  375. q->nr_requests = BLKDEV_DEFAULT_RQ;
  376. return q;
  377. fail_stats:
  378. blk_free_queue_stats(q->stats);
  379. fail_id:
  380. ida_free(&blk_queue_ida, q->id);
  381. fail_srcu:
  382. if (alloc_srcu)
  383. cleanup_srcu_struct(q->srcu);
  384. fail_q:
  385. kmem_cache_free(blk_get_queue_kmem_cache(alloc_srcu), q);
  386. return NULL;
  387. }
  388. /**
  389. * blk_get_queue - increment the request_queue refcount
  390. * @q: the request_queue structure to increment the refcount for
  391. *
  392. * Increment the refcount of the request_queue kobject.
  393. *
  394. * Context: Any context.
  395. */
  396. bool blk_get_queue(struct request_queue *q)
  397. {
  398. if (unlikely(blk_queue_dying(q)))
  399. return false;
  400. kobject_get(&q->kobj);
  401. return true;
  402. }
  403. EXPORT_SYMBOL(blk_get_queue);
  404. #ifdef CONFIG_FAIL_MAKE_REQUEST
  405. static DECLARE_FAULT_ATTR(fail_make_request);
  406. static int __init setup_fail_make_request(char *str)
  407. {
  408. return setup_fault_attr(&fail_make_request, str);
  409. }
  410. __setup("fail_make_request=", setup_fail_make_request);
  411. bool should_fail_request(struct block_device *part, unsigned int bytes)
  412. {
  413. return part->bd_make_it_fail && should_fail(&fail_make_request, bytes);
  414. }
  415. static int __init fail_make_request_debugfs(void)
  416. {
  417. struct dentry *dir = fault_create_debugfs_attr("fail_make_request",
  418. NULL, &fail_make_request);
  419. return PTR_ERR_OR_ZERO(dir);
  420. }
  421. late_initcall(fail_make_request_debugfs);
  422. #endif /* CONFIG_FAIL_MAKE_REQUEST */
  423. static inline void bio_check_ro(struct bio *bio)
  424. {
  425. if (op_is_write(bio_op(bio)) && bdev_read_only(bio->bi_bdev)) {
  426. if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
  427. return;
  428. pr_warn_ratelimited("Trying to write to read-only block-device %pg\n",
  429. bio->bi_bdev);
  430. /* Older lvm-tools actually trigger this */
  431. }
  432. }
  433. static noinline int should_fail_bio(struct bio *bio)
  434. {
  435. if (should_fail_request(bdev_whole(bio->bi_bdev), bio->bi_iter.bi_size))
  436. return -EIO;
  437. return 0;
  438. }
  439. ALLOW_ERROR_INJECTION(should_fail_bio, ERRNO);
  440. /*
  441. * Check whether this bio extends beyond the end of the device or partition.
  442. * This may well happen - the kernel calls bread() without checking the size of
  443. * the device, e.g., when mounting a file system.
  444. */
  445. static inline int bio_check_eod(struct bio *bio)
  446. {
  447. sector_t maxsector = bdev_nr_sectors(bio->bi_bdev);
  448. unsigned int nr_sectors = bio_sectors(bio);
  449. if (nr_sectors && maxsector &&
  450. (nr_sectors > maxsector ||
  451. bio->bi_iter.bi_sector > maxsector - nr_sectors)) {
  452. pr_info_ratelimited("%s: attempt to access beyond end of device\n"
  453. "%pg: rw=%d, sector=%llu, nr_sectors = %u limit=%llu\n",
  454. current->comm, bio->bi_bdev, bio->bi_opf,
  455. bio->bi_iter.bi_sector, nr_sectors, maxsector);
  456. return -EIO;
  457. }
  458. return 0;
  459. }
  460. /*
  461. * Remap block n of partition p to block n+start(p) of the disk.
  462. */
  463. static int blk_partition_remap(struct bio *bio)
  464. {
  465. struct block_device *p = bio->bi_bdev;
  466. if (unlikely(should_fail_request(p, bio->bi_iter.bi_size)))
  467. return -EIO;
  468. if (bio_sectors(bio)) {
  469. bio->bi_iter.bi_sector += p->bd_start_sect;
  470. trace_block_bio_remap(bio, p->bd_dev,
  471. bio->bi_iter.bi_sector -
  472. p->bd_start_sect);
  473. }
  474. bio_set_flag(bio, BIO_REMAPPED);
  475. return 0;
  476. }
  477. /*
  478. * Check write append to a zoned block device.
  479. */
  480. static inline blk_status_t blk_check_zone_append(struct request_queue *q,
  481. struct bio *bio)
  482. {
  483. int nr_sectors = bio_sectors(bio);
  484. /* Only applicable to zoned block devices */
  485. if (!bdev_is_zoned(bio->bi_bdev))
  486. return BLK_STS_NOTSUPP;
  487. /* The bio sector must point to the start of a sequential zone */
  488. if (bio->bi_iter.bi_sector & (bdev_zone_sectors(bio->bi_bdev) - 1) ||
  489. !bio_zone_is_seq(bio))
  490. return BLK_STS_IOERR;
  491. /*
  492. * Not allowed to cross zone boundaries. Otherwise, the BIO will be
  493. * split and could result in non-contiguous sectors being written in
  494. * different zones.
  495. */
  496. if (nr_sectors > q->limits.chunk_sectors)
  497. return BLK_STS_IOERR;
  498. /* Make sure the BIO is small enough and will not get split */
  499. if (nr_sectors > q->limits.max_zone_append_sectors)
  500. return BLK_STS_IOERR;
  501. bio->bi_opf |= REQ_NOMERGE;
  502. return BLK_STS_OK;
  503. }
  504. static void __submit_bio(struct bio *bio)
  505. {
  506. struct gendisk *disk = bio->bi_bdev->bd_disk;
  507. if (unlikely(!blk_crypto_bio_prep(&bio)))
  508. return;
  509. if (!disk->fops->submit_bio) {
  510. blk_mq_submit_bio(bio);
  511. } else if (likely(bio_queue_enter(bio) == 0)) {
  512. disk->fops->submit_bio(bio);
  513. blk_queue_exit(disk->queue);
  514. }
  515. }
  516. /*
  517. * The loop in this function may be a bit non-obvious, and so deserves some
  518. * explanation:
  519. *
  520. * - Before entering the loop, bio->bi_next is NULL (as all callers ensure
  521. * that), so we have a list with a single bio.
  522. * - We pretend that we have just taken it off a longer list, so we assign
  523. * bio_list to a pointer to the bio_list_on_stack, thus initialising the
  524. * bio_list of new bios to be added. ->submit_bio() may indeed add some more
  525. * bios through a recursive call to submit_bio_noacct. If it did, we find a
  526. * non-NULL value in bio_list and re-enter the loop from the top.
  527. * - In this case we really did just take the bio of the top of the list (no
  528. * pretending) and so remove it from bio_list, and call into ->submit_bio()
  529. * again.
  530. *
  531. * bio_list_on_stack[0] contains bios submitted by the current ->submit_bio.
  532. * bio_list_on_stack[1] contains bios that were submitted before the current
  533. * ->submit_bio, but that haven't been processed yet.
  534. */
  535. static void __submit_bio_noacct(struct bio *bio)
  536. {
  537. struct bio_list bio_list_on_stack[2];
  538. BUG_ON(bio->bi_next);
  539. bio_list_init(&bio_list_on_stack[0]);
  540. current->bio_list = bio_list_on_stack;
  541. do {
  542. struct request_queue *q = bdev_get_queue(bio->bi_bdev);
  543. struct bio_list lower, same;
  544. /*
  545. * Create a fresh bio_list for all subordinate requests.
  546. */
  547. bio_list_on_stack[1] = bio_list_on_stack[0];
  548. bio_list_init(&bio_list_on_stack[0]);
  549. __submit_bio(bio);
  550. /*
  551. * Sort new bios into those for a lower level and those for the
  552. * same level.
  553. */
  554. bio_list_init(&lower);
  555. bio_list_init(&same);
  556. while ((bio = bio_list_pop(&bio_list_on_stack[0])) != NULL)
  557. if (q == bdev_get_queue(bio->bi_bdev))
  558. bio_list_add(&same, bio);
  559. else
  560. bio_list_add(&lower, bio);
  561. /*
  562. * Now assemble so we handle the lowest level first.
  563. */
  564. bio_list_merge(&bio_list_on_stack[0], &lower);
  565. bio_list_merge(&bio_list_on_stack[0], &same);
  566. bio_list_merge(&bio_list_on_stack[0], &bio_list_on_stack[1]);
  567. } while ((bio = bio_list_pop(&bio_list_on_stack[0])));
  568. current->bio_list = NULL;
  569. }
  570. static void __submit_bio_noacct_mq(struct bio *bio)
  571. {
  572. struct bio_list bio_list[2] = { };
  573. current->bio_list = bio_list;
  574. do {
  575. __submit_bio(bio);
  576. } while ((bio = bio_list_pop(&bio_list[0])));
  577. current->bio_list = NULL;
  578. }
  579. void submit_bio_noacct_nocheck(struct bio *bio)
  580. {
  581. blk_cgroup_bio_start(bio);
  582. blkcg_bio_issue_init(bio);
  583. if (!bio_flagged(bio, BIO_TRACE_COMPLETION)) {
  584. trace_block_bio_queue(bio);
  585. /*
  586. * Now that enqueuing has been traced, we need to trace
  587. * completion as well.
  588. */
  589. bio_set_flag(bio, BIO_TRACE_COMPLETION);
  590. }
  591. /*
  592. * We only want one ->submit_bio to be active at a time, else stack
  593. * usage with stacked devices could be a problem. Use current->bio_list
  594. * to collect a list of requests submited by a ->submit_bio method while
  595. * it is active, and then process them after it returned.
  596. */
  597. if (current->bio_list)
  598. bio_list_add(&current->bio_list[0], bio);
  599. else if (!bio->bi_bdev->bd_disk->fops->submit_bio)
  600. __submit_bio_noacct_mq(bio);
  601. else
  602. __submit_bio_noacct(bio);
  603. }
  604. /**
  605. * submit_bio_noacct - re-submit a bio to the block device layer for I/O
  606. * @bio: The bio describing the location in memory and on the device.
  607. *
  608. * This is a version of submit_bio() that shall only be used for I/O that is
  609. * resubmitted to lower level drivers by stacking block drivers. All file
  610. * systems and other upper level users of the block layer should use
  611. * submit_bio() instead.
  612. */
  613. void submit_bio_noacct(struct bio *bio)
  614. {
  615. struct block_device *bdev = bio->bi_bdev;
  616. struct request_queue *q = bdev_get_queue(bdev);
  617. blk_status_t status = BLK_STS_IOERR;
  618. struct blk_plug *plug;
  619. might_sleep();
  620. plug = blk_mq_plug(bio);
  621. if (plug && plug->nowait)
  622. bio->bi_opf |= REQ_NOWAIT;
  623. /*
  624. * For a REQ_NOWAIT based request, return -EOPNOTSUPP
  625. * if queue does not support NOWAIT.
  626. */
  627. if ((bio->bi_opf & REQ_NOWAIT) && !bdev_nowait(bdev))
  628. goto not_supported;
  629. if (should_fail_bio(bio))
  630. goto end_io;
  631. bio_check_ro(bio);
  632. if (!bio_flagged(bio, BIO_REMAPPED)) {
  633. if (unlikely(bio_check_eod(bio)))
  634. goto end_io;
  635. if (bdev->bd_partno && unlikely(blk_partition_remap(bio)))
  636. goto end_io;
  637. }
  638. /*
  639. * Filter flush bio's early so that bio based drivers without flush
  640. * support don't have to worry about them.
  641. */
  642. if (op_is_flush(bio->bi_opf) &&
  643. !test_bit(QUEUE_FLAG_WC, &q->queue_flags)) {
  644. bio->bi_opf &= ~(REQ_PREFLUSH | REQ_FUA);
  645. if (!bio_sectors(bio)) {
  646. status = BLK_STS_OK;
  647. goto end_io;
  648. }
  649. }
  650. if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
  651. bio_clear_polled(bio);
  652. switch (bio_op(bio)) {
  653. case REQ_OP_DISCARD:
  654. if (!bdev_max_discard_sectors(bdev))
  655. goto not_supported;
  656. break;
  657. case REQ_OP_SECURE_ERASE:
  658. if (!bdev_max_secure_erase_sectors(bdev))
  659. goto not_supported;
  660. break;
  661. case REQ_OP_ZONE_APPEND:
  662. status = blk_check_zone_append(q, bio);
  663. if (status != BLK_STS_OK)
  664. goto end_io;
  665. break;
  666. case REQ_OP_ZONE_RESET:
  667. case REQ_OP_ZONE_OPEN:
  668. case REQ_OP_ZONE_CLOSE:
  669. case REQ_OP_ZONE_FINISH:
  670. if (!bdev_is_zoned(bio->bi_bdev))
  671. goto not_supported;
  672. break;
  673. case REQ_OP_ZONE_RESET_ALL:
  674. if (!bdev_is_zoned(bio->bi_bdev) || !blk_queue_zone_resetall(q))
  675. goto not_supported;
  676. break;
  677. case REQ_OP_WRITE_ZEROES:
  678. if (!q->limits.max_write_zeroes_sectors)
  679. goto not_supported;
  680. break;
  681. default:
  682. break;
  683. }
  684. if (blk_throtl_bio(bio))
  685. return;
  686. submit_bio_noacct_nocheck(bio);
  687. return;
  688. not_supported:
  689. status = BLK_STS_NOTSUPP;
  690. end_io:
  691. bio->bi_status = status;
  692. bio_endio(bio);
  693. }
  694. EXPORT_SYMBOL(submit_bio_noacct);
  695. /**
  696. * submit_bio - submit a bio to the block device layer for I/O
  697. * @bio: The &struct bio which describes the I/O
  698. *
  699. * submit_bio() is used to submit I/O requests to block devices. It is passed a
  700. * fully set up &struct bio that describes the I/O that needs to be done. The
  701. * bio will be send to the device described by the bi_bdev field.
  702. *
  703. * The success/failure status of the request, along with notification of
  704. * completion, is delivered asynchronously through the ->bi_end_io() callback
  705. * in @bio. The bio must NOT be touched by the caller until ->bi_end_io() has
  706. * been called.
  707. */
  708. void submit_bio(struct bio *bio)
  709. {
  710. if (blkcg_punt_bio_submit(bio))
  711. return;
  712. if (bio_op(bio) == REQ_OP_READ) {
  713. task_io_account_read(bio->bi_iter.bi_size);
  714. count_vm_events(PGPGIN, bio_sectors(bio));
  715. } else if (bio_op(bio) == REQ_OP_WRITE) {
  716. count_vm_events(PGPGOUT, bio_sectors(bio));
  717. }
  718. submit_bio_noacct(bio);
  719. }
  720. EXPORT_SYMBOL(submit_bio);
  721. /**
  722. * bio_poll - poll for BIO completions
  723. * @bio: bio to poll for
  724. * @iob: batches of IO
  725. * @flags: BLK_POLL_* flags that control the behavior
  726. *
  727. * Poll for completions on queue associated with the bio. Returns number of
  728. * completed entries found.
  729. *
  730. * Note: the caller must either be the context that submitted @bio, or
  731. * be in a RCU critical section to prevent freeing of @bio.
  732. */
  733. int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
  734. {
  735. blk_qc_t cookie = READ_ONCE(bio->bi_cookie);
  736. struct block_device *bdev;
  737. struct request_queue *q;
  738. int ret = 0;
  739. bdev = READ_ONCE(bio->bi_bdev);
  740. if (!bdev)
  741. return 0;
  742. q = bdev_get_queue(bdev);
  743. if (cookie == BLK_QC_T_NONE ||
  744. !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
  745. return 0;
  746. /*
  747. * As the requests that require a zone lock are not plugged in the
  748. * first place, directly accessing the plug instead of using
  749. * blk_mq_plug() should not have any consequences during flushing for
  750. * zoned devices.
  751. */
  752. blk_flush_plug(current->plug, false);
  753. if (bio_queue_enter(bio))
  754. return 0;
  755. if (queue_is_mq(q)) {
  756. ret = blk_mq_poll(q, cookie, iob, flags);
  757. } else {
  758. struct gendisk *disk = q->disk;
  759. if (disk && disk->fops->poll_bio)
  760. ret = disk->fops->poll_bio(bio, iob, flags);
  761. }
  762. blk_queue_exit(q);
  763. return ret;
  764. }
  765. EXPORT_SYMBOL_GPL(bio_poll);
  766. /*
  767. * Helper to implement file_operations.iopoll. Requires the bio to be stored
  768. * in iocb->private, and cleared before freeing the bio.
  769. */
  770. int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob,
  771. unsigned int flags)
  772. {
  773. struct bio *bio;
  774. int ret = 0;
  775. /*
  776. * Note: the bio cache only uses SLAB_TYPESAFE_BY_RCU, so bio can
  777. * point to a freshly allocated bio at this point. If that happens
  778. * we have a few cases to consider:
  779. *
  780. * 1) the bio is beeing initialized and bi_bdev is NULL. We can just
  781. * simply nothing in this case
  782. * 2) the bio points to a not poll enabled device. bio_poll will catch
  783. * this and return 0
  784. * 3) the bio points to a poll capable device, including but not
  785. * limited to the one that the original bio pointed to. In this
  786. * case we will call into the actual poll method and poll for I/O,
  787. * even if we don't need to, but it won't cause harm either.
  788. *
  789. * For cases 2) and 3) above the RCU grace period ensures that bi_bdev
  790. * is still allocated. Because partitions hold a reference to the whole
  791. * device bdev and thus disk, the disk is also still valid. Grabbing
  792. * a reference to the queue in bio_poll() ensures the hctxs and requests
  793. * are still valid as well.
  794. */
  795. rcu_read_lock();
  796. bio = READ_ONCE(kiocb->private);
  797. if (bio)
  798. ret = bio_poll(bio, iob, flags);
  799. rcu_read_unlock();
  800. return ret;
  801. }
  802. EXPORT_SYMBOL_GPL(iocb_bio_iopoll);
  803. void update_io_ticks(struct block_device *part, unsigned long now, bool end)
  804. {
  805. unsigned long stamp;
  806. again:
  807. stamp = READ_ONCE(part->bd_stamp);
  808. if (unlikely(time_after(now, stamp))) {
  809. if (likely(try_cmpxchg(&part->bd_stamp, &stamp, now)))
  810. __part_stat_add(part, io_ticks, end ? now - stamp : 1);
  811. }
  812. if (part->bd_partno) {
  813. part = bdev_whole(part);
  814. goto again;
  815. }
  816. }
  817. unsigned long bdev_start_io_acct(struct block_device *bdev,
  818. unsigned int sectors, enum req_op op,
  819. unsigned long start_time)
  820. {
  821. const int sgrp = op_stat_group(op);
  822. part_stat_lock();
  823. update_io_ticks(bdev, start_time, false);
  824. part_stat_inc(bdev, ios[sgrp]);
  825. part_stat_add(bdev, sectors[sgrp], sectors);
  826. part_stat_local_inc(bdev, in_flight[op_is_write(op)]);
  827. part_stat_unlock();
  828. return start_time;
  829. }
  830. EXPORT_SYMBOL(bdev_start_io_acct);
  831. /**
  832. * bio_start_io_acct_time - start I/O accounting for bio based drivers
  833. * @bio: bio to start account for
  834. * @start_time: start time that should be passed back to bio_end_io_acct().
  835. */
  836. void bio_start_io_acct_time(struct bio *bio, unsigned long start_time)
  837. {
  838. bdev_start_io_acct(bio->bi_bdev, bio_sectors(bio),
  839. bio_op(bio), start_time);
  840. }
  841. EXPORT_SYMBOL_GPL(bio_start_io_acct_time);
  842. /**
  843. * bio_start_io_acct - start I/O accounting for bio based drivers
  844. * @bio: bio to start account for
  845. *
  846. * Returns the start time that should be passed back to bio_end_io_acct().
  847. */
  848. unsigned long bio_start_io_acct(struct bio *bio)
  849. {
  850. return bdev_start_io_acct(bio->bi_bdev, bio_sectors(bio),
  851. bio_op(bio), jiffies);
  852. }
  853. EXPORT_SYMBOL_GPL(bio_start_io_acct);
  854. void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
  855. unsigned long start_time)
  856. {
  857. const int sgrp = op_stat_group(op);
  858. unsigned long now = READ_ONCE(jiffies);
  859. unsigned long duration = now - start_time;
  860. part_stat_lock();
  861. update_io_ticks(bdev, now, true);
  862. part_stat_add(bdev, nsecs[sgrp], jiffies_to_nsecs(duration));
  863. part_stat_local_dec(bdev, in_flight[op_is_write(op)]);
  864. part_stat_unlock();
  865. }
  866. EXPORT_SYMBOL(bdev_end_io_acct);
  867. void bio_end_io_acct_remapped(struct bio *bio, unsigned long start_time,
  868. struct block_device *orig_bdev)
  869. {
  870. bdev_end_io_acct(orig_bdev, bio_op(bio), start_time);
  871. }
  872. EXPORT_SYMBOL_GPL(bio_end_io_acct_remapped);
  873. /**
  874. * blk_lld_busy - Check if underlying low-level drivers of a device are busy
  875. * @q : the queue of the device being checked
  876. *
  877. * Description:
  878. * Check if underlying low-level drivers of a device are busy.
  879. * If the drivers want to export their busy state, they must set own
  880. * exporting function using blk_queue_lld_busy() first.
  881. *
  882. * Basically, this function is used only by request stacking drivers
  883. * to stop dispatching requests to underlying devices when underlying
  884. * devices are busy. This behavior helps more I/O merging on the queue
  885. * of the request stacking driver and prevents I/O throughput regression
  886. * on burst I/O load.
  887. *
  888. * Return:
  889. * 0 - Not busy (The request stacking driver should dispatch request)
  890. * 1 - Busy (The request stacking driver should stop dispatching request)
  891. */
  892. int blk_lld_busy(struct request_queue *q)
  893. {
  894. if (queue_is_mq(q) && q->mq_ops->busy)
  895. return q->mq_ops->busy(q);
  896. return 0;
  897. }
  898. EXPORT_SYMBOL_GPL(blk_lld_busy);
  899. int kblockd_schedule_work(struct work_struct *work)
  900. {
  901. return queue_work(kblockd_workqueue, work);
  902. }
  903. EXPORT_SYMBOL(kblockd_schedule_work);
  904. int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork,
  905. unsigned long delay)
  906. {
  907. return mod_delayed_work_on(cpu, kblockd_workqueue, dwork, delay);
  908. }
  909. EXPORT_SYMBOL(kblockd_mod_delayed_work_on);
  910. void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned short nr_ios)
  911. {
  912. struct task_struct *tsk = current;
  913. /*
  914. * If this is a nested plug, don't actually assign it.
  915. */
  916. if (tsk->plug)
  917. return;
  918. plug->mq_list = NULL;
  919. plug->cached_rq = NULL;
  920. plug->nr_ios = min_t(unsigned short, nr_ios, BLK_MAX_REQUEST_COUNT);
  921. plug->rq_count = 0;
  922. plug->multiple_queues = false;
  923. plug->has_elevator = false;
  924. plug->nowait = false;
  925. INIT_LIST_HEAD(&plug->cb_list);
  926. /*
  927. * Store ordering should not be needed here, since a potential
  928. * preempt will imply a full memory barrier
  929. */
  930. tsk->plug = plug;
  931. }
  932. /**
  933. * blk_start_plug - initialize blk_plug and track it inside the task_struct
  934. * @plug: The &struct blk_plug that needs to be initialized
  935. *
  936. * Description:
  937. * blk_start_plug() indicates to the block layer an intent by the caller
  938. * to submit multiple I/O requests in a batch. The block layer may use
  939. * this hint to defer submitting I/Os from the caller until blk_finish_plug()
  940. * is called. However, the block layer may choose to submit requests
  941. * before a call to blk_finish_plug() if the number of queued I/Os
  942. * exceeds %BLK_MAX_REQUEST_COUNT, or if the size of the I/O is larger than
  943. * %BLK_PLUG_FLUSH_SIZE. The queued I/Os may also be submitted early if
  944. * the task schedules (see below).
  945. *
  946. * Tracking blk_plug inside the task_struct will help with auto-flushing the
  947. * pending I/O should the task end up blocking between blk_start_plug() and
  948. * blk_finish_plug(). This is important from a performance perspective, but
  949. * also ensures that we don't deadlock. For instance, if the task is blocking
  950. * for a memory allocation, memory reclaim could end up wanting to free a
  951. * page belonging to that request that is currently residing in our private
  952. * plug. By flushing the pending I/O when the process goes to sleep, we avoid
  953. * this kind of deadlock.
  954. */
  955. void blk_start_plug(struct blk_plug *plug)
  956. {
  957. blk_start_plug_nr_ios(plug, 1);
  958. }
  959. EXPORT_SYMBOL(blk_start_plug);
  960. static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
  961. {
  962. LIST_HEAD(callbacks);
  963. while (!list_empty(&plug->cb_list)) {
  964. list_splice_init(&plug->cb_list, &callbacks);
  965. while (!list_empty(&callbacks)) {
  966. struct blk_plug_cb *cb = list_first_entry(&callbacks,
  967. struct blk_plug_cb,
  968. list);
  969. list_del(&cb->list);
  970. cb->callback(cb, from_schedule);
  971. }
  972. }
  973. }
  974. struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data,
  975. int size)
  976. {
  977. struct blk_plug *plug = current->plug;
  978. struct blk_plug_cb *cb;
  979. if (!plug)
  980. return NULL;
  981. list_for_each_entry(cb, &plug->cb_list, list)
  982. if (cb->callback == unplug && cb->data == data)
  983. return cb;
  984. /* Not currently on the callback list */
  985. BUG_ON(size < sizeof(*cb));
  986. cb = kzalloc(size, GFP_ATOMIC);
  987. if (cb) {
  988. cb->data = data;
  989. cb->callback = unplug;
  990. list_add(&cb->list, &plug->cb_list);
  991. }
  992. return cb;
  993. }
  994. EXPORT_SYMBOL(blk_check_plugged);
  995. void __blk_flush_plug(struct blk_plug *plug, bool from_schedule)
  996. {
  997. if (!list_empty(&plug->cb_list))
  998. flush_plug_callbacks(plug, from_schedule);
  999. blk_mq_flush_plug_list(plug, from_schedule);
  1000. /*
  1001. * Unconditionally flush out cached requests, even if the unplug
  1002. * event came from schedule. Since we know hold references to the
  1003. * queue for cached requests, we don't want a blocked task holding
  1004. * up a queue freeze/quiesce event.
  1005. */
  1006. if (unlikely(!rq_list_empty(plug->cached_rq)))
  1007. blk_mq_free_plug_rqs(plug);
  1008. }
  1009. /**
  1010. * blk_finish_plug - mark the end of a batch of submitted I/O
  1011. * @plug: The &struct blk_plug passed to blk_start_plug()
  1012. *
  1013. * Description:
  1014. * Indicate that a batch of I/O submissions is complete. This function
  1015. * must be paired with an initial call to blk_start_plug(). The intent
  1016. * is to allow the block layer to optimize I/O submission. See the
  1017. * documentation for blk_start_plug() for more information.
  1018. */
  1019. void blk_finish_plug(struct blk_plug *plug)
  1020. {
  1021. if (plug == current->plug) {
  1022. __blk_flush_plug(plug, false);
  1023. current->plug = NULL;
  1024. }
  1025. }
  1026. EXPORT_SYMBOL(blk_finish_plug);
  1027. void blk_io_schedule(void)
  1028. {
  1029. /* Prevent hang_check timer from firing at us during very long I/O */
  1030. unsigned long timeout = sysctl_hung_task_timeout_secs * HZ / 2;
  1031. if (timeout)
  1032. io_schedule_timeout(timeout);
  1033. else
  1034. io_schedule();
  1035. }
  1036. EXPORT_SYMBOL_GPL(blk_io_schedule);
  1037. int __init blk_dev_init(void)
  1038. {
  1039. BUILD_BUG_ON((__force u32)REQ_OP_LAST >= (1 << REQ_OP_BITS));
  1040. BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
  1041. sizeof_field(struct request, cmd_flags));
  1042. BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
  1043. sizeof_field(struct bio, bi_opf));
  1044. BUILD_BUG_ON(ALIGN(offsetof(struct request_queue, srcu),
  1045. __alignof__(struct request_queue)) !=
  1046. sizeof(struct request_queue));
  1047. /* used for unplugging and affects IO latency/throughput - HIGHPRI */
  1048. kblockd_workqueue = alloc_workqueue("kblockd",
  1049. WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
  1050. if (!kblockd_workqueue)
  1051. panic("Failed to create kblockd\n");
  1052. blk_requestq_cachep = kmem_cache_create("request_queue",
  1053. sizeof(struct request_queue), 0, SLAB_PANIC, NULL);
  1054. blk_requestq_srcu_cachep = kmem_cache_create("request_queue_srcu",
  1055. sizeof(struct request_queue) +
  1056. sizeof(struct srcu_struct), 0, SLAB_PANIC, NULL);
  1057. blk_debugfs_root = debugfs_create_dir("block", NULL);
  1058. return 0;
  1059. }