2020-06-20 07:20:07

by Christoph Hellwig

[permalink] [raw]
Subject: move block bits out of fs.h

Hi Jens,

this series removes various remaining block bits out of fs.h and cleans
up a few loose ends around that.

Diffstat:
drivers/tty/sysrq.c | 2
fs/adfs/super.c | 1
fs/affs/file.c | 1
fs/befs/linuxvfs.c | 1
fs/block_dev.c | 5 -
fs/efs/super.c | 1
fs/hfs/inode.c | 1
fs/internal.h | 17 +++-
fs/jfs/jfs_mount.c | 1
fs/jfs/resize.c | 1
fs/ntfs/dir.c | 1
fs/proc/devices.c | 1
fs/quota/dquot.c | 1
fs/reiserfs/procfs.c | 1
include/linux/bio.h | 3
include/linux/blk_types.h | 39 +++++++++-
include/linux/blkdev.h | 140 ++++++++++++++++++++++--------------
include/linux/buffer_head.h | 1
include/linux/dasd_mod.h | 2
include/linux/fs.h | 169 --------------------------------------------
include/linux/genhd.h | 39 ++++++++--
include/linux/jbd2.h | 1
security/loadpin/loadpin.c | 1
23 files changed, 192 insertions(+), 238 deletions(-)


2020-06-20 07:20:07

by Christoph Hellwig

[permalink] [raw]
Subject: [PATCH 10/10] block: move struct block_device to blk_types.h

Move the struct block_device definition together with most of the
block layer definitions, as it has nothing to do with the rest of fs.h.

Signed-off-by: Christoph Hellwig <[email protected]>
---
fs/adfs/super.c | 1 +
fs/befs/linuxvfs.c | 1 +
fs/efs/super.c | 1 +
fs/jfs/jfs_mount.c | 1 +
fs/jfs/resize.c | 1 +
include/linux/blk_types.h | 39 ++++++++++++++++++++++++++++++++++++-
include/linux/blkdev.h | 1 +
include/linux/dasd_mod.h | 2 ++
include/linux/fs.h | 41 ---------------------------------------
9 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/fs/adfs/super.c b/fs/adfs/super.c
index a3cc8ecb50da1a..d553bb5bc17abd 100644
--- a/fs/adfs/super.c
+++ b/fs/adfs/super.c
@@ -12,6 +12,7 @@
#include <linux/slab.h>
#include <linux/statfs.h>
#include <linux/user_namespace.h>
+#include <linux/blkdev.h>
#include "adfs.h"
#include "dir_f.h"
#include "dir_fplus.h"
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 64cdf4d8e42451..2482032021cac7 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -22,6 +22,7 @@
#include <linux/cred.h>
#include <linux/exportfs.h>
#include <linux/seq_file.h>
+#include <linux/blkdev.h>

#include "befs.h"
#include "btree.h"
diff --git a/fs/efs/super.c b/fs/efs/super.c
index 4a6ebff2af76f3..a4a945d0ac6a42 100644
--- a/fs/efs/super.c
+++ b/fs/efs/super.c
@@ -13,6 +13,7 @@
#include <linux/slab.h>
#include <linux/buffer_head.h>
#include <linux/vfs.h>
+#include <linux/blkdev.h>

#include "efs.h"
#include <linux/efs_vh.h>
diff --git a/fs/jfs/jfs_mount.c b/fs/jfs/jfs_mount.c
index eb8b9e233d73db..2935d4c776ec75 100644
--- a/fs/jfs/jfs_mount.c
+++ b/fs/jfs/jfs_mount.c
@@ -36,6 +36,7 @@

#include <linux/fs.h>
#include <linux/buffer_head.h>
+#include <linux/blkdev.h>

#include "jfs_incore.h"
#include "jfs_filsys.h"
diff --git a/fs/jfs/resize.c b/fs/jfs/resize.c
index 66acea9d878b97..bde787c354fcc1 100644
--- a/fs/jfs/resize.c
+++ b/fs/jfs/resize.c
@@ -6,6 +6,7 @@
#include <linux/fs.h>
#include <linux/buffer_head.h>
#include <linux/quotaops.h>
+#include <linux/blkdev.h>
#include "jfs_incore.h"
#include "jfs_filsys.h"
#include "jfs_metapage.h"
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index ccb895f911b185..a602132cbe32c2 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -14,12 +14,49 @@ struct bio_set;
struct bio;
struct bio_integrity_payload;
struct page;
-struct block_device;
struct io_context;
struct cgroup_subsys_state;
typedef void (bio_end_io_t) (struct bio *);
struct bio_crypt_ctx;

+struct block_device {
+ dev_t bd_dev; /* not a kdev_t - it's a search key */
+ int bd_openers;
+ struct inode * bd_inode; /* will die */
+ struct super_block * bd_super;
+ struct mutex bd_mutex; /* open/close mutex */
+ void * bd_claiming;
+ void * bd_holder;
+ int bd_holders;
+ bool bd_write_holder;
+#ifdef CONFIG_SYSFS
+ struct list_head bd_holder_disks;
+#endif
+ struct block_device * bd_contains;
+ unsigned bd_block_size;
+ u8 bd_partno;
+ struct hd_struct * bd_part;
+ /* number of times partitions within this device have been opened. */
+ unsigned bd_part_count;
+ int bd_invalidated;
+ struct gendisk * bd_disk;
+ struct request_queue * bd_queue;
+ struct backing_dev_info *bd_bdi;
+ struct list_head bd_list;
+ /*
+ * Private data. You must have bd_claim'ed the block_device
+ * to use this. NOTE: bd_claim allows an owner to claim
+ * the same device multiple times, the owner must take special
+ * care to not mess up bd_private for that case.
+ */
+ unsigned long bd_private;
+
+ /* The counter of freeze processes */
+ int bd_fsfreeze_count;
+ /* Mutex for freeze */
+ struct mutex bd_fsfreeze_mutex;
+} __randomize_layout;
+
/*
* Block error status values. See block/blk-core:blk_errors for the details.
* Alpha cannot write a byte atomically, so we need to use 32-bit value.
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 0f021ee2ce1c3b..60d07e89582bfa 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1932,6 +1932,7 @@ void bd_abort_claiming(struct block_device *bdev, struct block_device *whole,
void *holder);
void blkdev_put(struct block_device *bdev, fmode_t mode);

+struct block_device *I_BDEV(struct inode *inode);
struct block_device *bdget(dev_t);
struct block_device *bdgrab(struct block_device *bdev);
void bdput(struct block_device *);
diff --git a/include/linux/dasd_mod.h b/include/linux/dasd_mod.h
index d39abad2ff6e4c..14e6cf8c62677f 100644
--- a/include/linux/dasd_mod.h
+++ b/include/linux/dasd_mod.h
@@ -4,6 +4,8 @@

#include <asm/dasd.h>

+struct gendisk;
+
extern int dasd_biodasdinfo(struct gendisk *disk, dasd_information2_t *info);

#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index add30c3bdf9a28..1d7c4f7465d24c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -470,45 +470,6 @@ struct address_space {
* must be enforced here for CRIS, to let the least significant bit
* of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
*/
-struct request_queue;
-
-struct block_device {
- dev_t bd_dev; /* not a kdev_t - it's a search key */
- int bd_openers;
- struct inode * bd_inode; /* will die */
- struct super_block * bd_super;
- struct mutex bd_mutex; /* open/close mutex */
- void * bd_claiming;
- void * bd_holder;
- int bd_holders;
- bool bd_write_holder;
-#ifdef CONFIG_SYSFS
- struct list_head bd_holder_disks;
-#endif
- struct block_device * bd_contains;
- unsigned bd_block_size;
- u8 bd_partno;
- struct hd_struct * bd_part;
- /* number of times partitions within this device have been opened. */
- unsigned bd_part_count;
- int bd_invalidated;
- struct gendisk * bd_disk;
- struct request_queue * bd_queue;
- struct backing_dev_info *bd_bdi;
- struct list_head bd_list;
- /*
- * Private data. You must have bd_claim'ed the block_device
- * to use this. NOTE: bd_claim allows an owner to claim
- * the same device multiple times, the owner must take special
- * care to not mess up bd_private for that case.
- */
- unsigned long bd_private;
-
- /* The counter of freeze processes */
- int bd_fsfreeze_count;
- /* Mutex for freeze */
- struct mutex bd_fsfreeze_mutex;
-} __randomize_layout;

/* XArray tags, for tagging dirty and writeback pages in the pagecache. */
#define PAGECACHE_TAG_DIRTY XA_MARK_0
@@ -907,8 +868,6 @@ static inline unsigned imajor(const struct inode *inode)
return MAJOR(inode->i_rdev);
}

-extern struct block_device *I_BDEV(struct inode *inode);
-
struct fown_struct {
rwlock_t lock; /* protects pid, uid, euid fields */
struct pid *pid; /* pid or -pgrp where SIGIO should be sent */
--
2.26.2

2020-06-20 07:20:07

by Christoph Hellwig

[permalink] [raw]
Subject: [PATCH 09/10] block: reduce ifdef CONFIG_BLOCK madness in headers

Large part of bio.h, blkdev.h and genhd.h are under ifdef CONFIG_BLOCK
for no good reason. Only stub out function that are called from
code that is not dependent on CONFIG_BLOCK and leave the harmless
other declarations around.

Signed-off-by: Christoph Hellwig <[email protected]>
---
include/linux/bio.h | 3 --
include/linux/blkdev.h | 92 ++++++++++++++++++------------------------
include/linux/genhd.h | 14 +++----
3 files changed, 46 insertions(+), 63 deletions(-)

diff --git a/include/linux/bio.h b/include/linux/bio.h
index 91676d4b2dfe77..0282f8aa85935c 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -8,8 +8,6 @@
#include <linux/highmem.h>
#include <linux/mempool.h>
#include <linux/ioprio.h>
-
-#ifdef CONFIG_BLOCK
/* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */
#include <linux/blk_types.h>

@@ -824,5 +822,4 @@ static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
bio->bi_opf |= REQ_NOWAIT;
}

-#endif /* CONFIG_BLOCK */
#endif /* __LINUX_BIO_H */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 973253ce202d87..0f021ee2ce1c3b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -4,9 +4,6 @@

#include <linux/sched.h>
#include <linux/sched/clock.h>
-
-#ifdef CONFIG_BLOCK
-
#include <linux/major.h>
#include <linux/genhd.h>
#include <linux/list.h>
@@ -1165,13 +1162,13 @@ static inline int blk_rq_map_sg(struct request_queue *q, struct request *rq,
return __blk_rq_map_sg(q, rq, sglist, &last_sg);
}
extern void blk_dump_rq_flags(struct request *, char *);
-extern long nr_blockdev_pages(void);

bool __must_check blk_get_queue(struct request_queue *);
struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id);
extern void blk_put_queue(struct request_queue *);
extern void blk_set_queue_dying(struct request_queue *);

+#ifdef CONFIG_BLOCK
/*
* blk_plug permits building a queue of related requests by holding the I/O
* fragments for a short period. This allows merging of sequential requests
@@ -1231,9 +1228,47 @@ static inline bool blk_needs_flush_plug(struct task_struct *tsk)
!list_empty(&plug->cb_list));
}

+int blkdev_issue_flush(struct block_device *, gfp_t);
+long nr_blockdev_pages(void);
+#else /* CONFIG_BLOCK */
+struct blk_plug {
+};
+
+static inline void blk_start_plug(struct blk_plug *plug)
+{
+}
+
+static inline void blk_finish_plug(struct blk_plug *plug)
+{
+}
+
+static inline void blk_flush_plug(struct task_struct *task)
+{
+}
+
+static inline void blk_schedule_flush_plug(struct task_struct *task)
+{
+}
+
+
+static inline bool blk_needs_flush_plug(struct task_struct *tsk)
+{
+ return false;
+}
+
+static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask)
+{
+ return 0;
+}
+
+static inline long nr_blockdev_pages(void)
+{
+ return 0;
+}
+#endif /* CONFIG_BLOCK */
+
extern void blk_io_schedule(void);

-int blkdev_issue_flush(struct block_device *, gfp_t);
extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
sector_t nr_sects, gfp_t gfp_mask, struct page *page);

@@ -1833,51 +1868,6 @@ static inline bool blk_req_can_dispatch_to_zone(struct request *rq)
}
#endif /* CONFIG_BLK_DEV_ZONED */

-#else /* CONFIG_BLOCK */
-
-struct block_device;
-
-/*
- * stubs for when the block layer is configured out
- */
-
-static inline long nr_blockdev_pages(void)
-{
- return 0;
-}
-
-struct blk_plug {
-};
-
-static inline void blk_start_plug(struct blk_plug *plug)
-{
-}
-
-static inline void blk_finish_plug(struct blk_plug *plug)
-{
-}
-
-static inline void blk_flush_plug(struct task_struct *task)
-{
-}
-
-static inline void blk_schedule_flush_plug(struct task_struct *task)
-{
-}
-
-
-static inline bool blk_needs_flush_plug(struct task_struct *tsk)
-{
- return false;
-}
-
-static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask)
-{
- return 0;
-}
-
-#endif /* CONFIG_BLOCK */
-
static inline void blk_wake_io_task(struct task_struct *waiter)
{
/*
@@ -1891,7 +1881,6 @@ static inline void blk_wake_io_task(struct task_struct *waiter)
wake_up_process(waiter);
}

-#ifdef CONFIG_BLOCK
unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
unsigned int op);
void disk_end_io_acct(struct gendisk *disk, unsigned int op,
@@ -1917,7 +1906,6 @@ static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
{
return disk_end_io_acct(bio->bi_disk, bio_op(bio), start_time);
}
-#endif /* CONFIG_BLOCK */

int bdev_read_only(struct block_device *bdev);
int set_blocksize(struct block_device *bdev, int size);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 83f8e0d8322836..31a54072ffd653 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -19,8 +19,6 @@
#include <linux/blk_types.h>
#include <asm/local.h>

-#ifdef CONFIG_BLOCK
-
#define dev_to_disk(device) container_of((device), struct gendisk, part0.__dev)
#define dev_to_part(device) container_of((device), struct hd_struct, __dev)
#define disk_to_dev(disk) (&(disk)->part0.__dev)
@@ -337,12 +335,9 @@ static inline void set_capacity(struct gendisk *disk, sector_t size)
disk->part0.nr_sects = size;
}

-extern dev_t blk_lookup_devt(const char *name, int partno);
-
int bdev_disk_changed(struct block_device *bdev, bool invalidate);
int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
int blk_drop_partitions(struct block_device *bdev);
-extern void printk_all_partitions(void);

extern struct gendisk *__alloc_disk_node(int minors, int node_id);
extern struct kobject *get_disk_and_module(struct gendisk *disk);
@@ -400,10 +395,13 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev,
}
#endif /* CONFIG_SYSFS */

+#ifdef CONFIG_BLOCK
+void printk_all_partitions(void);
+dev_t blk_lookup_devt(const char *name, int partno);
#else /* CONFIG_BLOCK */
-
-static inline void printk_all_partitions(void) { }
-
+static inline void printk_all_partitions(void)
+{
+}
static inline dev_t blk_lookup_devt(const char *name, int partno)
{
dev_t devt = MKDEV(0, 0);
--
2.26.2

2020-06-20 07:20:07

by Christoph Hellwig

[permalink] [raw]
Subject: [PATCH 07/10] block: move block-related definitions out of fs.h

Move most of the block related definition out of fs.h into more suitable
headers.

Signed-off-by: Christoph Hellwig <[email protected]>
---
fs/affs/file.c | 1 +
fs/hfs/inode.c | 1 +
fs/internal.h | 17 ++++++-
fs/ntfs/dir.c | 1 +
fs/proc/devices.c | 1 +
fs/quota/dquot.c | 1 +
fs/reiserfs/procfs.c | 1 +
include/linux/blkdev.h | 46 +++++++++++++++++++
include/linux/fs.h | 92 --------------------------------------
include/linux/genhd.h | 27 +++++++++++
include/linux/jbd2.h | 1 +
security/loadpin/loadpin.c | 1 +
12 files changed, 96 insertions(+), 94 deletions(-)

diff --git a/fs/affs/file.c b/fs/affs/file.c
index a85817f54483f7..a26a0f96c1197a 100644
--- a/fs/affs/file.c
+++ b/fs/affs/file.c
@@ -14,6 +14,7 @@
*/

#include <linux/uio.h>
+#include <linux/blkdev.h>
#include "affs.h"

static struct buffer_head *affs_get_extblock_slow(struct inode *inode, u32 ext);
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index 2f224b98ee94a6..f35a37c65e5fff 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -17,6 +17,7 @@
#include <linux/cred.h>
#include <linux/uio.h>
#include <linux/xattr.h>
+#include <linux/blkdev.h>

#include "hfs_fs.h"
#include "btree.h"
diff --git a/fs/internal.h b/fs/internal.h
index 9b863a7bd70892..969988d3d39732 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -23,7 +23,9 @@ struct user_namespace;
extern void __init bdev_cache_init(void);

extern int __sync_blockdev(struct block_device *bdev, int wait);
-
+void iterate_bdevs(void (*)(struct block_device *, void *), void *);
+void emergency_thaw_bdev(struct super_block *sb);
+void bd_forget(struct inode *inode);
#else
static inline void bdev_cache_init(void)
{
@@ -33,7 +35,18 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)
{
return 0;
}
-#endif
+static inline void iterate_bdevs(void (*f)(struct block_device *, void *),
+ void *arg)
+{
+}
+static inline int emergency_thaw_bdev(struct super_block *sb)
+{
+ return 0;
+}
+static inline void bd_forget(struct inode *inode)
+{
+}
+#endif /* CONFIG_BLOCK */

/*
* buffer.c
diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
index 3c4811469ae863..a87d4391e6b55d 100644
--- a/fs/ntfs/dir.c
+++ b/fs/ntfs/dir.c
@@ -8,6 +8,7 @@

#include <linux/buffer_head.h>
#include <linux/slab.h>
+#include <linux/blkdev.h>

#include "dir.h"
#include "aops.h"
diff --git a/fs/proc/devices.c b/fs/proc/devices.c
index 37d38697eaf876..837971e7410978 100644
--- a/fs/proc/devices.c
+++ b/fs/proc/devices.c
@@ -3,6 +3,7 @@
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
+#include <linux/blkdev.h>

static int devinfo_show(struct seq_file *f, void *v)
{
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 7b4bac91146b51..bb02989d92b618 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -78,6 +78,7 @@
#include <linux/namei.h>
#include <linux/capability.h>
#include <linux/quotaops.h>
+#include <linux/blkdev.h>
#include "../internal.h" /* ugh */

#include <linux/uaccess.h>
diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
index ff336513c2544c..155b8287033361 100644
--- a/fs/reiserfs/procfs.c
+++ b/fs/reiserfs/procfs.c
@@ -15,6 +15,7 @@
#include "reiserfs.h"
#include <linux/init.h>
#include <linux/proc_fs.h>
+#include <linux/blkdev.h>

/*
* LOCKING:
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 8fd900998b4e2e..50fccb121b876e 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1920,4 +1920,50 @@ static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
}
#endif /* CONFIG_BLOCK */

+int bdev_read_only(struct block_device *bdev);
+int set_blocksize(struct block_device *bdev, int size);
+
+const char *bdevname(struct block_device *bdev, char *buffer);
+struct block_device *lookup_bdev(const char *);
+
+void blkdev_show(struct seq_file *seqf, off_t offset);
+
+#define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
+#define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */
+#ifdef CONFIG_BLOCK
+#define BLKDEV_MAJOR_MAX 512
+#else
+#define BLKDEV_MAJOR_MAX 0
+#endif
+
+int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
+struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
+ void *holder);
+struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder);
+struct block_device *bd_start_claiming(struct block_device *bdev, void *holder);
+void bd_abort_claiming(struct block_device *bdev, struct block_device *whole,
+ void *holder);
+void blkdev_put(struct block_device *bdev, fmode_t mode);
+
+struct block_device *bdget(dev_t);
+struct block_device *bdgrab(struct block_device *bdev);
+void bdput(struct block_device *);
+
+#ifdef CONFIG_BLOCK
+void invalidate_bdev(struct block_device *bdev);
+int sync_blockdev(struct block_device *bdev);
+#else
+static inline void invalidate_bdev(struct block_device *bdev)
+{
+}
+static inline int sync_blockdev(struct block_device *bdev)
+{
+ return 0;
+}
#endif
+int fsync_bdev(struct block_device *bdev);
+
+struct super_block *freeze_bdev(struct block_device *bdev);
+int thaw_bdev(struct block_device *bdev, struct super_block *sb);
+
+#endif /* _LINUX_BLKDEV_H */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7f3ae38335d4b3..add30c3bdf9a28 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2563,79 +2563,10 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
return IS_ENABLED(CONFIG_BLOCK) && sb == blockdev_superblock;
}

-#ifdef CONFIG_BLOCK
-extern int register_blkdev(unsigned int, const char *);
-extern void unregister_blkdev(unsigned int, const char *);
-extern struct block_device *bdget(dev_t);
-extern struct block_device *bdgrab(struct block_device *bdev);
-extern void bd_set_size(struct block_device *, loff_t size);
-extern void bd_forget(struct inode *inode);
-extern void bdput(struct block_device *);
-extern void invalidate_bdev(struct block_device *);
-extern void iterate_bdevs(void (*)(struct block_device *, void *), void *);
-extern int sync_blockdev(struct block_device *bdev);
-extern struct super_block *freeze_bdev(struct block_device *);
-extern void emergency_thaw_bdev(struct super_block *sb);
-extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
-extern int fsync_bdev(struct block_device *);
-#else
-static inline void bd_forget(struct inode *inode) {}
-static inline int sync_blockdev(struct block_device *bdev) { return 0; }
-static inline void invalidate_bdev(struct block_device *bdev) {}
-
-static inline struct super_block *freeze_bdev(struct block_device *sb)
-{
- return NULL;
-}
-
-static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb)
-{
- return 0;
-}
-
-static inline int emergency_thaw_bdev(struct super_block *sb)
-{
- return 0;
-}
-
-static inline void iterate_bdevs(void (*f)(struct block_device *, void *), void *arg)
-{
-}
-#endif
void emergency_thaw_all(void);
extern int sync_filesystem(struct super_block *);
extern const struct file_operations def_blk_fops;
extern const struct file_operations def_chr_fops;
-#ifdef CONFIG_BLOCK
-extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
-extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
-extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
-extern struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
- void *holder);
-extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
- void *holder);
-extern struct block_device *bd_start_claiming(struct block_device *bdev,
- void *holder);
-extern void bd_abort_claiming(struct block_device *bdev,
- struct block_device *whole, void *holder);
-extern void blkdev_put(struct block_device *bdev, fmode_t mode);
-
-#ifdef CONFIG_SYSFS
-extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
-extern void bd_unlink_disk_holder(struct block_device *bdev,
- struct gendisk *disk);
-#else
-static inline int bd_link_disk_holder(struct block_device *bdev,
- struct gendisk *disk)
-{
- return 0;
-}
-static inline void bd_unlink_disk_holder(struct block_device *bdev,
- struct gendisk *disk)
-{
-}
-#endif
-#endif

/* fs/char_dev.c */
#define CHRDEV_MAJOR_MAX 512
@@ -2666,31 +2597,12 @@ static inline void unregister_chrdev(unsigned int major, const char *name)
__unregister_chrdev(major, 0, 256, name);
}

-/* fs/block_dev.c */
-#define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
-#define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */
-
-#ifdef CONFIG_BLOCK
-#define BLKDEV_MAJOR_MAX 512
-extern const char *bdevname(struct block_device *bdev, char *buffer);
-extern struct block_device *lookup_bdev(const char *);
-extern void blkdev_show(struct seq_file *,off_t);
-
-#else
-#define BLKDEV_MAJOR_MAX 0
-#endif
-
extern void init_special_inode(struct inode *, umode_t, dev_t);

/* Invalid inode operations -- fs/bad_inode.c */
extern void make_bad_inode(struct inode *);
extern bool is_bad_inode(struct inode *);

-#ifdef CONFIG_BLOCK
-extern int revalidate_disk(struct gendisk *);
-extern int check_disk_change(struct block_device *);
-extern int __invalidate_device(struct block_device *, bool);
-#endif
unsigned long invalidate_mapping_pages(struct address_space *mapping,
pgoff_t start, pgoff_t end);

@@ -3090,10 +3002,6 @@ static inline void remove_inode_hash(struct inode *inode)

extern void inode_sb_list_add(struct inode *inode);

-#ifdef CONFIG_BLOCK
-extern int bdev_read_only(struct block_device *);
-#endif
-extern int set_blocksize(struct block_device *, int);
extern int sb_set_blocksize(struct super_block *, int);
extern int sb_min_blocksize(struct super_block *, int);

diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 392aad5e29a231..83f8e0d8322836 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -373,6 +373,33 @@ extern void blk_unregister_region(dev_t devt, unsigned long range);

#define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)

+int register_blkdev(unsigned int major, const char *name);
+void unregister_blkdev(unsigned int major, const char *name);
+
+int revalidate_disk(struct gendisk *disk);
+int check_disk_change(struct block_device *bdev);
+int __invalidate_device(struct block_device *bdev, bool kill_dirty);
+void bd_set_size(struct block_device *bdev, loff_t size);
+
+/* for drivers/char/raw.c: */
+int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
+long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
+
+#ifdef CONFIG_SYSFS
+int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
+void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk);
+#else
+static inline int bd_link_disk_holder(struct block_device *bdev,
+ struct gendisk *disk)
+{
+ return 0;
+}
+static inline void bd_unlink_disk_holder(struct block_device *bdev,
+ struct gendisk *disk)
+{
+}
+#endif /* CONFIG_SYSFS */
+
#else /* CONFIG_BLOCK */

static inline void printk_all_partitions(void) { }
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index f613d8529863f6..ef3f9e1ce8ad2d 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -27,6 +27,7 @@
#include <linux/timer.h>
#include <linux/slab.h>
#include <linux/bit_spinlock.h>
+#include <linux/blkdev.h>
#include <crypto/hash.h>
#endif

diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
index ee5cb944f4ad1b..670a1aebb8a10f 100644
--- a/security/loadpin/loadpin.c
+++ b/security/loadpin/loadpin.c
@@ -13,6 +13,7 @@
#include <linux/fs.h>
#include <linux/lsm_hooks.h>
#include <linux/mount.h>
+#include <linux/blkdev.h>
#include <linux/path.h>
#include <linux/sched.h> /* current */
#include <linux/string_helpers.h>
--
2.26.2

2020-06-20 07:20:21

by Christoph Hellwig

[permalink] [raw]
Subject: [PATCH 08/10] fs: move the buffer_heads_over_limit stub to buffer_head.h

Move the !CONFIG_BLOCK stub to the same place as the non-stub
declaration.

Signed-off-by: Christoph Hellwig <[email protected]>
---
include/linux/blkdev.h | 1 -
include/linux/buffer_head.h | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 50fccb121b876e..973253ce202d87 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1840,7 +1840,6 @@ struct block_device;
/*
* stubs for when the block layer is configured out
*/
-#define buffer_heads_over_limit 0

static inline long nr_blockdev_pages(void)
{
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 22fb11e2d2e04d..6b47f94378c5ad 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -406,6 +406,7 @@ static inline int inode_has_buffers(struct inode *inode) { return 0; }
static inline void invalidate_inode_buffers(struct inode *inode) {}
static inline int remove_inode_buffers(struct inode *inode) { return 1; }
static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; }
+#define buffer_heads_over_limit 0

#endif /* CONFIG_BLOCK */
#endif /* _LINUX_BUFFER_HEAD_H */
--
2.26.2

2020-06-20 07:21:13

by Christoph Hellwig

[permalink] [raw]
Subject: [PATCH 02/10] block: mark bd_finish_claiming static

Signed-off-by: Christoph Hellwig <[email protected]>
---
fs/block_dev.c | 5 ++---
include/linux/fs.h | 2 --
2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 0ae656e022fd57..0e0d43dc27d331 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1187,8 +1187,8 @@ static void bd_clear_claiming(struct block_device *whole, void *holder)
* Finish exclusive open of a block device. Mark the device as exlusively
* open by the holder and wake up all waiters for exclusive open to finish.
*/
-void bd_finish_claiming(struct block_device *bdev, struct block_device *whole,
- void *holder)
+static void bd_finish_claiming(struct block_device *bdev,
+ struct block_device *whole, void *holder)
{
spin_lock(&bdev_lock);
BUG_ON(!bd_may_claim(bdev, whole, holder));
@@ -1203,7 +1203,6 @@ void bd_finish_claiming(struct block_device *bdev, struct block_device *whole,
bd_clear_claiming(whole, holder);
spin_unlock(&bdev_lock);
}
-EXPORT_SYMBOL(bd_finish_claiming);

/**
* bd_abort_claiming - abort claiming of a block device
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7f40dbafbf6d49..b1c960e9b84e3a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2646,8 +2646,6 @@ extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
void *holder);
extern struct block_device *bd_start_claiming(struct block_device *bdev,
void *holder);
-extern void bd_finish_claiming(struct block_device *bdev,
- struct block_device *whole, void *holder);
extern void bd_abort_claiming(struct block_device *bdev,
struct block_device *whole, void *holder);
extern void blkdev_put(struct block_device *bdev, fmode_t mode);
--
2.26.2

2020-06-20 07:21:46

by Christoph Hellwig

[permalink] [raw]
Subject: [PATCH 01/10] tty/sysrq: emergency_thaw_all does not depend on CONFIG_BLOCK

We can also thaw non-block file systems. Remove the CONFIG_BLOCK in
sysrq.c after making the prototype available unconditionally.

Signed-off-by: Christoph Hellwig <[email protected]>
---
drivers/tty/sysrq.c | 2 --
include/linux/fs.h | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 7c95afa905a083..a8e39b2cdd5526 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -403,7 +403,6 @@ static const struct sysrq_key_op sysrq_moom_op = {
.enable_mask = SYSRQ_ENABLE_SIGNAL,
};

-#ifdef CONFIG_BLOCK
static void sysrq_handle_thaw(int key)
{
emergency_thaw_all();
@@ -414,7 +413,6 @@ static const struct sysrq_key_op sysrq_thaw_op = {
.action_msg = "Emergency Thaw of all frozen filesystems",
.enable_mask = SYSRQ_ENABLE_SIGNAL,
};
-#endif

static void sysrq_handle_kill(int key)
{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3f881a892ea746..7f40dbafbf6d49 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2593,7 +2593,6 @@ extern void invalidate_bdev(struct block_device *);
extern void iterate_bdevs(void (*)(struct block_device *, void *), void *);
extern int sync_blockdev(struct block_device *bdev);
extern struct super_block *freeze_bdev(struct block_device *);
-extern void emergency_thaw_all(void);
extern void emergency_thaw_bdev(struct super_block *sb);
extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
extern int fsync_bdev(struct block_device *);
@@ -2633,6 +2632,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
return false;
}
#endif
+void emergency_thaw_all(void);
extern int sync_filesystem(struct super_block *);
extern const struct file_operations def_blk_fops;
extern const struct file_operations def_chr_fops;
--
2.26.2

2020-06-20 07:25:03

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 01/10] tty/sysrq: emergency_thaw_all does not depend on CONFIG_BLOCK

On Sat, Jun 20, 2020 at 09:16:35AM +0200, Christoph Hellwig wrote:
> We can also thaw non-block file systems. Remove the CONFIG_BLOCK in
> sysrq.c after making the prototype available unconditionally.
>
> Signed-off-by: Christoph Hellwig <[email protected]>
> ---
> drivers/tty/sysrq.c | 2 --
> include/linux/fs.h | 2 +-
> 2 files changed, 1 insertion(+), 3 deletions(-)
>

Reviewed-by: Greg Kroah-Hartman <[email protected]>

2020-06-21 02:58:49

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH 01/10] tty/sysrq: emergency_thaw_all does not depend on CONFIG_BLOCK

On 2020-06-20 00:16, Christoph Hellwig wrote:
> We can also thaw non-block file systems. Remove the CONFIG_BLOCK in
> sysrq.c after making the prototype available unconditionally.

Reviewed-by: Bart Van Assche <[email protected]>

2020-06-21 02:58:49

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH 02/10] block: mark bd_finish_claiming static

On 2020-06-20 00:16, Christoph Hellwig wrote:
> [ ... ]

Reviewed-by: Bart Van Assche <[email protected]>

2020-06-21 03:05:53

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH 08/10] fs: move the buffer_heads_over_limit stub to buffer_head.h

On 2020-06-20 00:16, Christoph Hellwig wrote:
> Move the !CONFIG_BLOCK stub to the same place as the non-stub
> declaration.

Reviewed-by: Bart Van Assche <[email protected]>

2020-06-22 08:52:09

by Johannes Thumshirn

[permalink] [raw]
Subject: Re: [PATCH 02/10] block: mark bd_finish_claiming static

Looks good,
Reviewed-by: Johannes Thumshirn <[email protected]>

2020-06-22 09:36:30

by Johannes Thumshirn

[permalink] [raw]

2020-06-22 09:45:56

by Johannes Thumshirn

[permalink] [raw]
Subject: Re: [PATCH 10/10] block: move struct block_device to blk_types.h

Now that I finally remebered where struct block_device lives...

Reviewed-by: Johannes Thumshirn <[email protected]>

2020-06-24 15:12:23

by Jens Axboe

[permalink] [raw]
Subject: Re: move block bits out of fs.h

On 6/20/20 1:16 AM, Christoph Hellwig wrote:
> Hi Jens,
>
> this series removes various remaining block bits out of fs.h and cleans
> up a few loose ends around that.
>
> Diffstat:
> drivers/tty/sysrq.c | 2
> fs/adfs/super.c | 1
> fs/affs/file.c | 1
> fs/befs/linuxvfs.c | 1
> fs/block_dev.c | 5 -
> fs/efs/super.c | 1
> fs/hfs/inode.c | 1
> fs/internal.h | 17 +++-
> fs/jfs/jfs_mount.c | 1
> fs/jfs/resize.c | 1
> fs/ntfs/dir.c | 1
> fs/proc/devices.c | 1
> fs/quota/dquot.c | 1
> fs/reiserfs/procfs.c | 1
> include/linux/bio.h | 3
> include/linux/blk_types.h | 39 +++++++++-
> include/linux/blkdev.h | 140 ++++++++++++++++++++++--------------
> include/linux/buffer_head.h | 1
> include/linux/dasd_mod.h | 2
> include/linux/fs.h | 169 --------------------------------------------
> include/linux/genhd.h | 39 ++++++++--
> include/linux/jbd2.h | 1
> security/loadpin/loadpin.c | 1
> 23 files changed, 192 insertions(+), 238 deletions(-)

Applied for 5.9 - I kept this in a separate topic branch, fwiw. There's the
potential for some annoying issues with this, so would rather have it in
a branch we can modify easily, if we need to.

--
Jens Axboe

2020-06-24 15:13:21

by Christoph Hellwig

[permalink] [raw]
Subject: Re: move block bits out of fs.h

On Wed, Jun 24, 2020 at 09:09:42AM -0600, Jens Axboe wrote:
> Applied for 5.9 - I kept this in a separate topic branch, fwiw. There's the
> potential for some annoying issues with this, so would rather have it in
> a branch we can modify easily, if we need to.

Hmm, I have a bunch of things building on top of this pending, so that
branch split will be interesting to handle.

2020-06-24 15:16:30

by Christoph Hellwig

[permalink] [raw]
Subject: Re: move block bits out of fs.h

On Wed, Jun 24, 2020 at 09:14:11AM -0600, Jens Axboe wrote:
> On 6/24/20 9:12 AM, Christoph Hellwig wrote:
> > On Wed, Jun 24, 2020 at 09:09:42AM -0600, Jens Axboe wrote:
> >> Applied for 5.9 - I kept this in a separate topic branch, fwiw. There's the
> >> potential for some annoying issues with this, so would rather have it in
> >> a branch we can modify easily, if we need to.
> >
> > Hmm, I have a bunch of things building on top of this pending, so that
> > branch split will be interesting to handle.
>
> We can stuff it in for-5.9/block, but then I'd rather just rebase that
> on 5.8-rc2 now since it's still early days. If we don't, we already
> have conflicts...

I'll happily rebase. rc1 also has funny ext4 warnings which are
pretty annoying.

2020-06-24 15:17:17

by Jens Axboe

[permalink] [raw]
Subject: Re: move block bits out of fs.h

On 6/24/20 9:12 AM, Christoph Hellwig wrote:
> On Wed, Jun 24, 2020 at 09:09:42AM -0600, Jens Axboe wrote:
>> Applied for 5.9 - I kept this in a separate topic branch, fwiw. There's the
>> potential for some annoying issues with this, so would rather have it in
>> a branch we can modify easily, if we need to.
>
> Hmm, I have a bunch of things building on top of this pending, so that
> branch split will be interesting to handle.

We can stuff it in for-5.9/block, but then I'd rather just rebase that
on 5.8-rc2 now since it's still early days. If we don't, we already
have conflicts...

--
Jens Axboe

2020-06-24 15:19:09

by Jens Axboe

[permalink] [raw]
Subject: Re: move block bits out of fs.h

On 6/24/20 9:14 AM, Christoph Hellwig wrote:
> On Wed, Jun 24, 2020 at 09:14:11AM -0600, Jens Axboe wrote:
>> On 6/24/20 9:12 AM, Christoph Hellwig wrote:
>>> On Wed, Jun 24, 2020 at 09:09:42AM -0600, Jens Axboe wrote:
>>>> Applied for 5.9 - I kept this in a separate topic branch, fwiw. There's the
>>>> potential for some annoying issues with this, so would rather have it in
>>>> a branch we can modify easily, if we need to.
>>>
>>> Hmm, I have a bunch of things building on top of this pending, so that
>>> branch split will be interesting to handle.
>>
>> We can stuff it in for-5.9/block, but then I'd rather just rebase that
>> on 5.8-rc2 now since it's still early days. If we don't, we already
>> have conflicts...
>
> I'll happily rebase. rc1 also has funny ext4 warnings which are
> pretty annoying.

Done, pushed it out.

--
Jens Axboe