Skip to content

Commit 6bec003

Browse files
committed
Merge branch 'for-3.20/bdi' of git://git.kernel.dk/linux-block
Pull backing device changes from Jens Axboe: "This contains a cleanup of how the backing device is handled, in preparation for a rework of the life time rules. In this part, the most important change is to split the unrelated nommu mmap flags from it, but also removing a backing_dev_info pointer from the address_space (and inode), and a cleanup of other various minor bits. Christoph did all the work here, I just fixed an oops with pages that have a swap backing. Arnd fixed a missing export, and Oleg killed the lustre backing_dev_info from staging. Last patch was from Al, unexporting parts that are now no longer needed outside" * 'for-3.20/bdi' of git://git.kernel.dk/linux-block: Make super_blocks and sb_lock static mtd: export new mtd_mmap_capabilities fs: make inode_to_bdi() handle NULL inode staging/lustre/llite: get rid of backing_dev_info fs: remove default_backing_dev_info fs: don't reassign dirty inodes to default_backing_dev_info nfs: don't call bdi_unregister ceph: remove call to bdi_unregister fs: remove mapping->backing_dev_info fs: export inode_to_bdi and use it in favor of mapping->backing_dev_info nilfs2: set up s_bdi like the generic mount_bdev code block_dev: get bdev inode bdi directly from the block device block_dev: only write bdev inode on close fs: introduce f_op->mmap_capabilities for nommu mmap support fs: kill BDI_CAP_SWAP_BACKED fs: deduplicate noop_backing_dev_info
2 parents 5d8e7fb + 15d0f5e commit 6bec003

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+305
-704
lines changed

Documentation/nommu-mmap.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ and it's also much more restricted in the latter case:
4343
even if this was created by another process.
4444

4545
- If possible, the file mapping will be directly on the backing device
46-
if the backing device has the BDI_CAP_MAP_DIRECT capability and
46+
if the backing device has the NOMMU_MAP_DIRECT capability and
4747
appropriate mapping protection capabilities. Ramfs, romfs, cramfs
4848
and mtd might all permit this.
4949

5050
- If the backing device device can't or won't permit direct sharing,
51-
but does have the BDI_CAP_MAP_COPY capability, then a copy of the
51+
but does have the NOMMU_MAP_COPY capability, then a copy of the
5252
appropriate bit of the file will be read into a contiguous bit of
5353
memory and any extraneous space beyond the EOF will be cleared
5454

@@ -220,7 +220,7 @@ directly (can't be copied).
220220

221221
The file->f_op->mmap() operation will be called to actually inaugurate the
222222
mapping. It can be rejected at that point. Returning the ENOSYS error will
223-
cause the mapping to be copied instead if BDI_CAP_MAP_COPY is specified.
223+
cause the mapping to be copied instead if NOMMU_MAP_COPY is specified.
224224

225225
The vm_ops->close() routine will be invoked when the last mapping on a chardev
226226
is removed. An existing mapping will be shared, partially or not, if possible
@@ -232,7 +232,7 @@ want to handle it, despite the fact it's got an operation. For instance, it
232232
might try directing the call to a secondary driver which turns out not to
233233
implement it. Such is the case for the framebuffer driver which attempts to
234234
direct the call to the device-specific driver. Under such circumstances, the
235-
mapping request will be rejected if BDI_CAP_MAP_COPY is not specified, and a
235+
mapping request will be rejected if NOMMU_MAP_COPY is not specified, and a
236236
copy mapped otherwise.
237237

238238
IMPORTANT NOTE:

block/blk-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
607607
q->backing_dev_info.ra_pages =
608608
(VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
609609
q->backing_dev_info.state = 0;
610-
q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY;
610+
q->backing_dev_info.capabilities = 0;
611611
q->backing_dev_info.name = "block";
612612
q->node = node_id;
613613

drivers/char/mem.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,24 @@ static unsigned long get_unmapped_area_mem(struct file *file,
287287
return pgoff << PAGE_SHIFT;
288288
}
289289

290+
/* permit direct mmap, for read, write or exec */
291+
static unsigned memory_mmap_capabilities(struct file *file)
292+
{
293+
return NOMMU_MAP_DIRECT |
294+
NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC;
295+
}
296+
297+
static unsigned zero_mmap_capabilities(struct file *file)
298+
{
299+
return NOMMU_MAP_COPY;
300+
}
301+
290302
/* can't do an in-place private mapping if there's no MMU */
291303
static inline int private_mapping_ok(struct vm_area_struct *vma)
292304
{
293305
return vma->vm_flags & VM_MAYSHARE;
294306
}
295307
#else
296-
#define get_unmapped_area_mem NULL
297308

298309
static inline int private_mapping_ok(struct vm_area_struct *vma)
299310
{
@@ -721,7 +732,10 @@ static const struct file_operations mem_fops = {
721732
.write = write_mem,
722733
.mmap = mmap_mem,
723734
.open = open_mem,
735+
#ifndef CONFIG_MMU
724736
.get_unmapped_area = get_unmapped_area_mem,
737+
.mmap_capabilities = memory_mmap_capabilities,
738+
#endif
725739
};
726740

727741
#ifdef CONFIG_DEVKMEM
@@ -731,7 +745,10 @@ static const struct file_operations kmem_fops = {
731745
.write = write_kmem,
732746
.mmap = mmap_kmem,
733747
.open = open_kmem,
748+
#ifndef CONFIG_MMU
734749
.get_unmapped_area = get_unmapped_area_mem,
750+
.mmap_capabilities = memory_mmap_capabilities,
751+
#endif
735752
};
736753
#endif
737754

@@ -760,16 +777,9 @@ static const struct file_operations zero_fops = {
760777
.read_iter = read_iter_zero,
761778
.aio_write = aio_write_zero,
762779
.mmap = mmap_zero,
763-
};
764-
765-
/*
766-
* capabilities for /dev/zero
767-
* - permits private mappings, "copies" are taken of the source of zeros
768-
* - no writeback happens
769-
*/
770-
static struct backing_dev_info zero_bdi = {
771-
.name = "char/mem",
772-
.capabilities = BDI_CAP_MAP_COPY | BDI_CAP_NO_ACCT_AND_WRITEBACK,
780+
#ifndef CONFIG_MMU
781+
.mmap_capabilities = zero_mmap_capabilities,
782+
#endif
773783
};
774784

775785
static const struct file_operations full_fops = {
@@ -783,22 +793,22 @@ static const struct memdev {
783793
const char *name;
784794
umode_t mode;
785795
const struct file_operations *fops;
786-
struct backing_dev_info *dev_info;
796+
fmode_t fmode;
787797
} devlist[] = {
788-
[1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi },
798+
[1] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
789799
#ifdef CONFIG_DEVKMEM
790-
[2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi },
800+
[2] = { "kmem", 0, &kmem_fops, FMODE_UNSIGNED_OFFSET },
791801
#endif
792-
[3] = { "null", 0666, &null_fops, NULL },
802+
[3] = { "null", 0666, &null_fops, 0 },
793803
#ifdef CONFIG_DEVPORT
794-
[4] = { "port", 0, &port_fops, NULL },
804+
[4] = { "port", 0, &port_fops, 0 },
795805
#endif
796-
[5] = { "zero", 0666, &zero_fops, &zero_bdi },
797-
[7] = { "full", 0666, &full_fops, NULL },
798-
[8] = { "random", 0666, &random_fops, NULL },
799-
[9] = { "urandom", 0666, &urandom_fops, NULL },
806+
[5] = { "zero", 0666, &zero_fops, 0 },
807+
[7] = { "full", 0666, &full_fops, 0 },
808+
[8] = { "random", 0666, &random_fops, 0 },
809+
[9] = { "urandom", 0666, &urandom_fops, 0 },
800810
#ifdef CONFIG_PRINTK
801-
[11] = { "kmsg", 0644, &kmsg_fops, NULL },
811+
[11] = { "kmsg", 0644, &kmsg_fops, 0 },
802812
#endif
803813
};
804814

@@ -816,12 +826,7 @@ static int memory_open(struct inode *inode, struct file *filp)
816826
return -ENXIO;
817827

818828
filp->f_op = dev->fops;
819-
if (dev->dev_info)
820-
filp->f_mapping->backing_dev_info = dev->dev_info;
821-
822-
/* Is /dev/mem or /dev/kmem ? */
823-
if (dev->dev_info == &directly_mappable_cdev_bdi)
824-
filp->f_mode |= FMODE_UNSIGNED_OFFSET;
829+
filp->f_mode |= dev->fmode;
825830

826831
if (dev->fops->open)
827832
return dev->fops->open(inode, filp);
@@ -846,11 +851,6 @@ static struct class *mem_class;
846851
static int __init chr_dev_init(void)
847852
{
848853
int minor;
849-
int err;
850-
851-
err = bdi_init(&zero_bdi);
852-
if (err)
853-
return err;
854854

855855
if (register_chrdev(MEM_MAJOR, "mem", &memory_fops))
856856
printk("unable to get major %d for memory devs\n", MEM_MAJOR);

drivers/char/raw.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,9 @@ static int raw_release(struct inode *inode, struct file *filp)
104104

105105
mutex_lock(&raw_mutex);
106106
bdev = raw_devices[minor].binding;
107-
if (--raw_devices[minor].inuse == 0) {
107+
if (--raw_devices[minor].inuse == 0)
108108
/* Here inode->i_mapping == bdev->bd_inode->i_mapping */
109109
inode->i_mapping = &inode->i_data;
110-
inode->i_mapping->backing_dev_info = &default_backing_dev_info;
111-
}
112110
mutex_unlock(&raw_mutex);
113111

114112
blkdev_put(bdev, filp->f_mode | FMODE_EXCL);

drivers/mtd/mtdchar.c

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static DEFINE_MUTEX(mtd_mutex);
4949
*/
5050
struct mtd_file_info {
5151
struct mtd_info *mtd;
52-
struct inode *ino;
5352
enum mtd_file_modes mode;
5453
};
5554

@@ -59,29 +58,20 @@ static loff_t mtdchar_lseek(struct file *file, loff_t offset, int orig)
5958
return fixed_size_llseek(file, offset, orig, mfi->mtd->size);
6059
}
6160

62-
static int count;
63-
static struct vfsmount *mnt;
64-
static struct file_system_type mtd_inodefs_type;
65-
6661
static int mtdchar_open(struct inode *inode, struct file *file)
6762
{
6863
int minor = iminor(inode);
6964
int devnum = minor >> 1;
7065
int ret = 0;
7166
struct mtd_info *mtd;
7267
struct mtd_file_info *mfi;
73-
struct inode *mtd_ino;
7468

7569
pr_debug("MTD_open\n");
7670

7771
/* You can't open the RO devices RW */
7872
if ((file->f_mode & FMODE_WRITE) && (minor & 1))
7973
return -EACCES;
8074

81-
ret = simple_pin_fs(&mtd_inodefs_type, &mnt, &count);
82-
if (ret)
83-
return ret;
84-
8575
mutex_lock(&mtd_mutex);
8676
mtd = get_mtd_device(NULL, devnum);
8777

@@ -95,43 +85,26 @@ static int mtdchar_open(struct inode *inode, struct file *file)
9585
goto out1;
9686
}
9787

98-
mtd_ino = iget_locked(mnt->mnt_sb, devnum);
99-
if (!mtd_ino) {
100-
ret = -ENOMEM;
101-
goto out1;
102-
}
103-
if (mtd_ino->i_state & I_NEW) {
104-
mtd_ino->i_private = mtd;
105-
mtd_ino->i_mode = S_IFCHR;
106-
mtd_ino->i_data.backing_dev_info = mtd->backing_dev_info;
107-
unlock_new_inode(mtd_ino);
108-
}
109-
file->f_mapping = mtd_ino->i_mapping;
110-
11188
/* You can't open it RW if it's not a writeable device */
11289
if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) {
11390
ret = -EACCES;
114-
goto out2;
91+
goto out1;
11592
}
11693

11794
mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
11895
if (!mfi) {
11996
ret = -ENOMEM;
120-
goto out2;
97+
goto out1;
12198
}
122-
mfi->ino = mtd_ino;
12399
mfi->mtd = mtd;
124100
file->private_data = mfi;
125101
mutex_unlock(&mtd_mutex);
126102
return 0;
127103

128-
out2:
129-
iput(mtd_ino);
130104
out1:
131105
put_mtd_device(mtd);
132106
out:
133107
mutex_unlock(&mtd_mutex);
134-
simple_release_fs(&mnt, &count);
135108
return ret;
136109
} /* mtdchar_open */
137110

@@ -148,12 +121,9 @@ static int mtdchar_close(struct inode *inode, struct file *file)
148121
if ((file->f_mode & FMODE_WRITE))
149122
mtd_sync(mtd);
150123

151-
iput(mfi->ino);
152-
153124
put_mtd_device(mtd);
154125
file->private_data = NULL;
155126
kfree(mfi);
156-
simple_release_fs(&mnt, &count);
157127

158128
return 0;
159129
} /* mtdchar_close */
@@ -1117,6 +1087,13 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file,
11171087
ret = mtd_get_unmapped_area(mtd, len, offset, flags);
11181088
return ret == -EOPNOTSUPP ? -ENODEV : ret;
11191089
}
1090+
1091+
static unsigned mtdchar_mmap_capabilities(struct file *file)
1092+
{
1093+
struct mtd_file_info *mfi = file->private_data;
1094+
1095+
return mtd_mmap_capabilities(mfi->mtd);
1096+
}
11201097
#endif
11211098

11221099
/*
@@ -1160,27 +1137,10 @@ static const struct file_operations mtd_fops = {
11601137
.mmap = mtdchar_mmap,
11611138
#ifndef CONFIG_MMU
11621139
.get_unmapped_area = mtdchar_get_unmapped_area,
1140+
.mmap_capabilities = mtdchar_mmap_capabilities,
11631141
#endif
11641142
};
11651143

1166-
static const struct super_operations mtd_ops = {
1167-
.drop_inode = generic_delete_inode,
1168-
.statfs = simple_statfs,
1169-
};
1170-
1171-
static struct dentry *mtd_inodefs_mount(struct file_system_type *fs_type,
1172-
int flags, const char *dev_name, void *data)
1173-
{
1174-
return mount_pseudo(fs_type, "mtd_inode:", &mtd_ops, NULL, MTD_INODE_FS_MAGIC);
1175-
}
1176-
1177-
static struct file_system_type mtd_inodefs_type = {
1178-
.name = "mtd_inodefs",
1179-
.mount = mtd_inodefs_mount,
1180-
.kill_sb = kill_anon_super,
1181-
};
1182-
MODULE_ALIAS_FS("mtd_inodefs");
1183-
11841144
int __init init_mtdchar(void)
11851145
{
11861146
int ret;
@@ -1193,23 +1153,11 @@ int __init init_mtdchar(void)
11931153
return ret;
11941154
}
11951155

1196-
ret = register_filesystem(&mtd_inodefs_type);
1197-
if (ret) {
1198-
pr_err("Can't register mtd_inodefs filesystem, error %d\n",
1199-
ret);
1200-
goto err_unregister_chdev;
1201-
}
1202-
1203-
return ret;
1204-
1205-
err_unregister_chdev:
1206-
__unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
12071156
return ret;
12081157
}
12091158

12101159
void __exit cleanup_mtdchar(void)
12111160
{
1212-
unregister_filesystem(&mtd_inodefs_type);
12131161
__unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
12141162
}
12151163

drivers/mtd/mtdconcat.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
732732

733733
concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks;
734734

735-
concat->mtd.backing_dev_info = subdev[0]->backing_dev_info;
736-
737735
concat->subdev[0] = subdev[0];
738736

739737
for (i = 1; i < num_devs; i++) {
@@ -761,14 +759,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
761759
subdev[i]->flags & MTD_WRITEABLE;
762760
}
763761

764-
/* only permit direct mapping if the BDIs are all the same
765-
* - copy-mapping is still permitted
766-
*/
767-
if (concat->mtd.backing_dev_info !=
768-
subdev[i]->backing_dev_info)
769-
concat->mtd.backing_dev_info =
770-
&default_backing_dev_info;
771-
772762
concat->mtd.size += subdev[i]->size;
773763
concat->mtd.ecc_stats.badblocks +=
774764
subdev[i]->ecc_stats.badblocks;

0 commit comments

Comments
 (0)