diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-01-02 21:45:35 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:21 -0400 |
commit | eacb2574f09f5b71acc468d44e7a1633847fd08d (patch) | |
tree | 75687f60a2545798197e1821fc526d9c7bf464dd /fs | |
parent | d8601afca840d36203d0cf2da94ce4f92003956e (diff) | |
download | lwn-eacb2574f09f5b71acc468d44e7a1633847fd08d.tar.gz lwn-eacb2574f09f5b71acc468d44e7a1633847fd08d.zip |
bcachefs: bch_dev->dev
Add a field to bch_dev for the dev_t of the underlying block device -
this fixes a null ptr deref in tracepoints.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bcachefs/bcachefs.h | 1 | ||||
-rw-r--r-- | fs/bcachefs/chardev.c | 5 | ||||
-rw-r--r-- | fs/bcachefs/super.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/trace.h | 6 |
4 files changed, 11 insertions, 5 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 7771b4a4bb87..7c48ebed1d35 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -432,6 +432,7 @@ struct bch_dev { struct bch_sb_handle disk_sb; struct bch_sb *sb_read_scratch; int sb_write_error; + dev_t dev; struct bch_devs_mask self; diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c index aae9a2db8b0d..6cd0a2739ce5 100644 --- a/fs/bcachefs/chardev.c +++ b/fs/bcachefs/chardev.c @@ -568,8 +568,11 @@ static long bch2_ioctl_disk_get_idx(struct bch_fs *c, if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (!dev) + return -EINVAL; + for_each_online_member(ca, c, i) - if (ca->disk_sb.bdev->bd_dev == dev) { + if (ca->dev == dev) { percpu_ref_put(&ca->io_ref); return i; } diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index d92bb50d0960..b0c2a8b847ef 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -1257,6 +1257,8 @@ static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb) ca->disk_sb = *sb; memset(sb, 0, sizeof(*sb)); + ca->dev = ca->disk_sb.bdev->bd_dev; + percpu_ref_reinit(&ca->io_ref); return 0; @@ -1875,7 +1877,7 @@ struct bch_dev *bch2_dev_lookup(struct bch_fs *c, const char *path) rcu_read_lock(); for_each_member_device_rcu(ca, c, i, NULL) - if (ca->disk_sb.bdev->bd_dev == dev) + if (ca->dev == dev) goto found; ca = ERR_PTR(-ENOENT); found: diff --git a/fs/bcachefs/trace.h b/fs/bcachefs/trace.h index a1122fa3ccc6..ff67e8572ea4 100644 --- a/fs/bcachefs/trace.h +++ b/fs/bcachefs/trace.h @@ -387,7 +387,7 @@ TRACE_EVENT(alloc_scan, ), TP_fast_assign( - __entry->dev = ca->disk_sb.bdev->bd_dev; + __entry->dev = ca->dev; __entry->found = found; __entry->inc_gen = inc_gen; __entry->inc_gen_skipped = inc_gen_skipped; @@ -409,7 +409,7 @@ TRACE_EVENT(invalidate, ), TP_fast_assign( - __entry->dev = ca->disk_sb.bdev->bd_dev; + __entry->dev = ca->dev; __entry->offset = offset, __entry->sectors = sectors; ), @@ -431,7 +431,7 @@ DECLARE_EVENT_CLASS(bucket_alloc, ), TP_fast_assign( - __entry->dev = ca->disk_sb.bdev->bd_dev; + __entry->dev = ca->dev; __entry->reserve = reserve; ), |