History

block: create the request_queue debugfs_dir on registration

We were only creating the request_queue debugfs_dir only for make_request block drivers (multiqueue), but never for request-based block drivers. We did this as we were only creating non-blktrace additional debugfs files on that directory for make_request drivers. However, since blktrace *always* creates that directory anyway, we special-case the use of that directory on blktrace. Other than this being an eye-sore, this exposes request-based block drivers to the same debugfs fragile race that used to exist with make_request block drivers where if we start adding files onto that directory we can later run a race with a double removal of dentries on the directory if we don't deal with this carefully on blktrace. Instead, just simplify things by always creating the request_queue debugfs_dir on request_queue registration. Rename the mutex also to reflect the fact that this is used outside of the blktrace context.

Luis Chamberlain committed 6 years ago

Commit 85e0cbb1 parent b431ef86 files · +39 −48Browse files

Unified · Split

6 files
  1. block/blk-core.c +1 −7
  2. block/blk-mq-debugfs.c +0 −5
  3. block/blk-sysfs.c +9 −0
  4. block/blk.h +0 −2
  5. include/linux/blkdev.h +3 −2
  6. kernel/trace/blktrace.c +26 −32
block/blk-core.c+1−7
@@ -51,9 +51,7 @@ · 50 unmodified lines
51#include "blk-pm.h"51#include "blk-pm.h"
52#include "blk-rq-qos.h"52#include "blk-rq-qos.h"
53 53
54#ifdef CONFIG_DEBUG_FS
55struct dentry *blk_debugfs_root;54struct dentry *blk_debugfs_root;
56#endif
57 55
58EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);56EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
59EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);57EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
@@ -555,9 +553,7 @@ struct request_queue *__blk_alloc_queue(int node_id) · 495 unmodified lines
555 553
556 kobject_init(&q->kobj, &blk_queue_ktype);554 kobject_init(&q->kobj, &blk_queue_ktype);
557 555
558#ifdef CONFIG_BLK_DEV_IO_TRACE556 mutex_init(&q->debugfs_mutex);
559 mutex_init(&q->blk_trace_mutex);
560#endif
561 mutex_init(&q->sysfs_lock);557 mutex_init(&q->sysfs_lock);
562 mutex_init(&q->sysfs_dir_lock);558 mutex_init(&q->sysfs_dir_lock);
563 spin_lock_init(&q->queue_lock);559 spin_lock_init(&q->queue_lock);
@@ -1931,9 +1927,7 @@ int __init blk_dev_init(void) · 1367 unmodified lines
1931 blk_requestq_cachep = kmem_cache_create("request_queue",1927 blk_requestq_cachep = kmem_cache_create("request_queue",
1932 sizeof(struct request_queue), 0, SLAB_PANIC, NULL);1928 sizeof(struct request_queue), 0, SLAB_PANIC, NULL);
1933 1929
1934#ifdef CONFIG_DEBUG_FS
1935 blk_debugfs_root = debugfs_create_dir("block", NULL);1930 blk_debugfs_root = debugfs_create_dir("block", NULL);
1936#endif
1937 1931
1938 return 0;1932 return 0;
1939}1933}
block/blk-mq-debugfs.c+0−5
@@ -824,9 +824,6 @@ void blk_mq_debugfs_register(struct request_queue *q) · 823 unmodified lines
824 struct blk_mq_hw_ctx *hctx;824 struct blk_mq_hw_ctx *hctx;
825 int i;825 int i;
826 826
827 q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
828 blk_debugfs_root);
829
830 debugfs_create_files(q->debugfs_dir, q, blk_mq_debugfs_queue_attrs);827 debugfs_create_files(q->debugfs_dir, q, blk_mq_debugfs_queue_attrs);
831 828
832 /*829 /*
@@ -857,9 +854,7 @@ void blk_mq_debugfs_register(struct request_queue *q) · 24 unmodified lines
857 854
858void blk_mq_debugfs_unregister(struct request_queue *q)855void blk_mq_debugfs_unregister(struct request_queue *q)
859{856{
860 debugfs_remove_recursive(q->debugfs_dir);
861 q->sched_debugfs_dir = NULL;857 q->sched_debugfs_dir = NULL;
862 q->debugfs_dir = NULL;
863}858}
864 859
865static void blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,860static void blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,
block/blk-sysfs.c+9−0
@@ -11,6 +11,7 @@ · 10 unmodified lines
11#include <linux/blktrace_api.h>11#include <linux/blktrace_api.h>
12#include <linux/blk-mq.h>12#include <linux/blk-mq.h>
13#include <linux/blk-cgroup.h>13#include <linux/blk-cgroup.h>
14#include <linux/debugfs.h>
14 15
15#include "blk.h"16#include "blk.h"
16#include "blk-mq.h"17#include "blk-mq.h"
@@ -917,6 +918,9 @@ static void blk_release_queue(struct kobject *kobj) · 900 unmodified lines
917 blk_mq_release(q);918 blk_mq_release(q);
918 919
919 blk_trace_shutdown(q);920 blk_trace_shutdown(q);
921 mutex_lock(&q->debugfs_mutex);
922 debugfs_remove_recursive(q->debugfs_dir);
923 mutex_unlock(&q->debugfs_mutex);
920 924
921 if (queue_is_mq(q))925 if (queue_is_mq(q))
922 blk_mq_debugfs_unregister(q);926 blk_mq_debugfs_unregister(q);
@@ -989,6 +993,11 @@ int blk_register_queue(struct gendisk *disk) · 66 unmodified lines
989 goto unlock;993 goto unlock;
990 }994 }
991 995
996 mutex_lock(&q->debugfs_mutex);
997 q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
998 blk_debugfs_root);
999 mutex_unlock(&q->debugfs_mutex);
1000
992 if (queue_is_mq(q)) {1001 if (queue_is_mq(q)) {
993 __blk_mq_register_dev(dev, q);1002 __blk_mq_register_dev(dev, q);
994 blk_mq_debugfs_register(q);1003 blk_mq_debugfs_register(q);
block/blk.h+0−2
@@ -14,9 +14,7 @@ · 13 unmodified lines
14/* Max future timer expiry for timeouts */14/* Max future timer expiry for timeouts */
15#define BLK_MAX_TIMEOUT (5 * HZ)15#define BLK_MAX_TIMEOUT (5 * HZ)
16 16
17#ifdef CONFIG_DEBUG_FS
18extern struct dentry *blk_debugfs_root;17extern struct dentry *blk_debugfs_root;
19#endif
20 18
21struct blk_flush_queue {19struct blk_flush_queue {
22 unsigned int flush_pending_idx:1;20 unsigned int flush_pending_idx:1;
include/linux/blkdev.h+3−2
@@ -528,9 +528,9 @@ struct request_queue { · 527 unmodified lines
528 unsigned int sg_timeout;528 unsigned int sg_timeout;
529 unsigned int sg_reserved_size;529 unsigned int sg_reserved_size;
530 int node;530 int node;
531 struct mutex debugfs_mutex;
531#ifdef CONFIG_BLK_DEV_IO_TRACE532#ifdef CONFIG_BLK_DEV_IO_TRACE
532 struct blk_trace __rcu *blk_trace;533 struct blk_trace __rcu *blk_trace;
533 struct mutex blk_trace_mutex;
534#endif534#endif
535 /*535 /*
536 * for flush operations536 * for flush operations
@@ -574,8 +574,9 @@ struct request_queue { · 37 unmodified lines
574 struct list_head tag_set_list;574 struct list_head tag_set_list;
575 struct bio_set bio_split;575 struct bio_set bio_split;
576 576
577#ifdef CONFIG_BLK_DEBUG_FS
578 struct dentry *debugfs_dir;577 struct dentry *debugfs_dir;
578
579#ifdef CONFIG_BLK_DEBUG_FS
579 struct dentry *sched_debugfs_dir;580 struct dentry *sched_debugfs_dir;
580 struct dentry *rqos_debugfs_dir;581 struct dentry *rqos_debugfs_dir;
581#endif582#endif
kernel/trace/blktrace.c+26−32
@@ -348,7 +348,7 @@ static int __blk_trace_remove(struct request_queue *q) · 347 unmodified lines
348 struct blk_trace *bt;348 struct blk_trace *bt;
349 349
350 bt = rcu_replace_pointer(q->blk_trace, NULL,350 bt = rcu_replace_pointer(q->blk_trace, NULL,
351 lockdep_is_held(&q->blk_trace_mutex));351 lockdep_is_held(&q->debugfs_mutex));
352 if (!bt)352 if (!bt)
353 return -EINVAL;353 return -EINVAL;
354 354
@@ -362,9 +362,9 @@ int blk_trace_remove(struct request_queue *q) · 7 unmodified lines
362{362{
363 int ret;363 int ret;
364 364
365 mutex_lock(&q->blk_trace_mutex);365 mutex_lock(&q->debugfs_mutex);
366 ret = __blk_trace_remove(q);366 ret = __blk_trace_remove(q);
367 mutex_unlock(&q->blk_trace_mutex);367 mutex_unlock(&q->debugfs_mutex);
368 368
369 return ret;369 return ret;
370}370}
@@ -483,14 +483,11 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, · 112 unmodified lines
483 struct dentry *dir = NULL;483 struct dentry *dir = NULL;
484 int ret;484 int ret;
485 485
486 lockdep_assert_held(&q->blk_trace_mutex);486 lockdep_assert_held(&q->debugfs_mutex);
487 487
488 if (!buts->buf_size || !buts->buf_nr)488 if (!buts->buf_size || !buts->buf_nr)
489 return -EINVAL;489 return -EINVAL;
490 490
491 if (!blk_debugfs_root)
492 return -ENOENT;
493
494 strncpy(buts->name, name, BLKTRACE_BDEV_SIZE);491 strncpy(buts->name, name, BLKTRACE_BDEV_SIZE);
495 buts->name[BLKTRACE_BDEV_SIZE - 1] = '\0';492 buts->name[BLKTRACE_BDEV_SIZE - 1] = '\0';
496 493
@@ -505,7 +502,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, · 8 unmodified lines
505 * we can be.502 * we can be.
506 */503 */
507 if (rcu_dereference_protected(q->blk_trace,504 if (rcu_dereference_protected(q->blk_trace,
508 lockdep_is_held(&q->blk_trace_mutex))) {505 lockdep_is_held(&q->debugfs_mutex))) {
509 pr_warn("Concurrent blktraces are not allowed on %s\n",506 pr_warn("Concurrent blktraces are not allowed on %s\n",
510 buts->name);507 buts->name);
511 return -EBUSY;508 return -EBUSY;
@@ -524,18 +521,15 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, · 12 unmodified lines
524 if (!bt->msg_data)521 if (!bt->msg_data)
525 goto err;522 goto err;
526 523
527#ifdef CONFIG_BLK_DEBUG_FS
528 /*524 /*
529 * When tracing whole make_request drivers (multiqueue) block devices,525 * When tracing the whole disk reuse the existing debugfs directory
530 * reuse the existing debugfs directory created by the block layer on526 * created by the block layer on init. For partitions block devices,
531 * init. For request-based block devices, all partitions block devices,
532 * and scsi-generic block devices we create a temporary new debugfs527 * and scsi-generic block devices we create a temporary new debugfs
533 * directory that will be removed once the trace ends.528 * directory that will be removed once the trace ends.
534 */529 */
535 if (queue_is_mq(q) && bdev && bdev == bdev->bd_contains)530 if (bdev && bdev == bdev->bd_contains)
536 dir = q->debugfs_dir;531 dir = q->debugfs_dir;
537 else532 else
538#endif
539 bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root);533 bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root);
540 534
541 /*535 /*
@@ -617,9 +611,9 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev, · 75 unmodified lines
617{611{
618 int ret;612 int ret;
619 613
620 mutex_lock(&q->blk_trace_mutex);614 mutex_lock(&q->debugfs_mutex);
621 ret = __blk_trace_setup(q, name, dev, bdev, arg);615 ret = __blk_trace_setup(q, name, dev, bdev, arg);
622 mutex_unlock(&q->blk_trace_mutex);616 mutex_unlock(&q->debugfs_mutex);
623 617
624 return ret;618 return ret;
625}619}
@@ -665,7 +659,7 @@ static int __blk_trace_startstop(struct request_queue *q, int start) · 39 unmodified lines
665 struct blk_trace *bt;659 struct blk_trace *bt;
666 660
667 bt = rcu_dereference_protected(q->blk_trace,661 bt = rcu_dereference_protected(q->blk_trace,
668 lockdep_is_held(&q->blk_trace_mutex));662 lockdep_is_held(&q->debugfs_mutex));
669 if (bt == NULL)663 if (bt == NULL)
670 return -EINVAL;664 return -EINVAL;
671 665
@@ -705,9 +699,9 @@ int blk_trace_startstop(struct request_queue *q, int start) · 33 unmodified lines
705{699{
706 int ret;700 int ret;
707 701
708 mutex_lock(&q->blk_trace_mutex);702 mutex_lock(&q->debugfs_mutex);
709 ret = __blk_trace_startstop(q, start);703 ret = __blk_trace_startstop(q, start);
710 mutex_unlock(&q->blk_trace_mutex);704 mutex_unlock(&q->debugfs_mutex);
711 705
712 return ret;706 return ret;
713}707}
@@ -736,7 +730,7 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg) · 22 unmodified lines
736 if (!q)730 if (!q)
737 return -ENXIO;731 return -ENXIO;
738 732
739 mutex_lock(&q->blk_trace_mutex);733 mutex_lock(&q->debugfs_mutex);
740 734
741 switch (cmd) {735 switch (cmd) {
742 case BLKTRACESETUP:736 case BLKTRACESETUP:
@@ -763,7 +757,7 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg) · 20 unmodified lines
763 break;757 break;
764 }758 }
765 759
766 mutex_unlock(&q->blk_trace_mutex);760 mutex_unlock(&q->debugfs_mutex);
767 return ret;761 return ret;
768}762}
769 763
@@ -774,14 +768,14 @@ int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg) · 4 unmodified lines
774 **/768 **/
775void blk_trace_shutdown(struct request_queue *q)769void blk_trace_shutdown(struct request_queue *q)
776{770{
777 mutex_lock(&q->blk_trace_mutex);771 mutex_lock(&q->debugfs_mutex);
778 if (rcu_dereference_protected(q->blk_trace,772 if (rcu_dereference_protected(q->blk_trace,
779 lockdep_is_held(&q->blk_trace_mutex))) {773 lockdep_is_held(&q->debugfs_mutex))) {
780 __blk_trace_startstop(q, 0);774 __blk_trace_startstop(q, 0);
781 __blk_trace_remove(q);775 __blk_trace_remove(q);
782 }776 }
783 777
784 mutex_unlock(&q->blk_trace_mutex);778 mutex_unlock(&q->debugfs_mutex);
785}779}
786 780
787#ifdef CONFIG_BLK_CGROUP781#ifdef CONFIG_BLK_CGROUP
@@ -1662,7 +1656,7 @@ static int blk_trace_remove_queue(struct request_queue *q) · 874 unmodified lines
1662 struct blk_trace *bt;1656 struct blk_trace *bt;
1663 1657
1664 bt = rcu_replace_pointer(q->blk_trace, NULL,1658 bt = rcu_replace_pointer(q->blk_trace, NULL,
1665 lockdep_is_held(&q->blk_trace_mutex));1659 lockdep_is_held(&q->debugfs_mutex));
1666 if (bt == NULL)1660 if (bt == NULL)
1667 return -EINVAL;1661 return -EINVAL;
1668 1662
@@ -1837,10 +1831,10 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev, · 168 unmodified lines
1837 if (q == NULL)1831 if (q == NULL)
1838 goto out_bdput;1832 goto out_bdput;
1839 1833
1840 mutex_lock(&q->blk_trace_mutex);1834 mutex_lock(&q->debugfs_mutex);
1841 1835
1842 bt = rcu_dereference_protected(q->blk_trace,1836 bt = rcu_dereference_protected(q->blk_trace,
1843 lockdep_is_held(&q->blk_trace_mutex));1837 lockdep_is_held(&q->debugfs_mutex));
1844 if (attr == &dev_attr_enable) {1838 if (attr == &dev_attr_enable) {
1845 ret = sprintf(buf, "%u\n", !!bt);1839 ret = sprintf(buf, "%u\n", !!bt);
1846 goto out_unlock_bdev;1840 goto out_unlock_bdev;
@@ -1858,7 +1852,7 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev, · 11 unmodified lines
1858 ret = sprintf(buf, "%llu\n", bt->end_lba);1852 ret = sprintf(buf, "%llu\n", bt->end_lba);
1859 1853
1860out_unlock_bdev:1854out_unlock_bdev:
1861 mutex_unlock(&q->blk_trace_mutex);1855 mutex_unlock(&q->debugfs_mutex);
1862out_bdput:1856out_bdput:
1863 bdput(bdev);1857 bdput(bdev);
1864out:1858out:
@@ -1901,10 +1895,10 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, · 36 unmodified lines
1901 if (q == NULL)1895 if (q == NULL)
1902 goto out_bdput;1896 goto out_bdput;
1903 1897
1904 mutex_lock(&q->blk_trace_mutex);1898 mutex_lock(&q->debugfs_mutex);
1905 1899
1906 bt = rcu_dereference_protected(q->blk_trace,1900 bt = rcu_dereference_protected(q->blk_trace,
1907 lockdep_is_held(&q->blk_trace_mutex));1901 lockdep_is_held(&q->debugfs_mutex));
1908 if (attr == &dev_attr_enable) {1902 if (attr == &dev_attr_enable) {
1909 if (!!value == !!bt) {1903 if (!!value == !!bt) {
1910 ret = 0;1904 ret = 0;
@@ -1921,7 +1915,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, · 10 unmodified lines
1921 if (bt == NULL) {1915 if (bt == NULL) {
1922 ret = blk_trace_setup_queue(q, bdev);1916 ret = blk_trace_setup_queue(q, bdev);
1923 bt = rcu_dereference_protected(q->blk_trace,1917 bt = rcu_dereference_protected(q->blk_trace,
1924 lockdep_is_held(&q->blk_trace_mutex));1918 lockdep_is_held(&q->debugfs_mutex));
1925 }1919 }
1926 1920
1927 if (ret == 0) {1921 if (ret == 0) {
@@ -1936,7 +1930,7 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev, · 8 unmodified lines
1936 }1930 }
1937 1931
1938out_unlock_bdev:1932out_unlock_bdev:
1939 mutex_unlock(&q->blk_trace_mutex);1933 mutex_unlock(&q->debugfs_mutex);
1940out_bdput:1934out_bdput:
1941 bdput(bdev);1935 bdput(bdev);
1942out:1936out: