fs: introduce f_op->mmap_capabilities for nommu mmap support
Since "BDI: Provide backing device capability information [try #3]" the backing_dev_info structure also provides flags for the kind of mmap operation available in a nommu environment, which is entirely unrelated to it's original purpose. Introduce a new nommu-only file operation to provide this information to the nommu mmap code instead. Splitting this from the backing_dev_info structure allows to remove lots of backing_dev_info instance that aren't otherwise needed, and entirely gets rid of the concept of providing a backing_dev_info for a character device. It also removes the need for the mtd_inodefs filesystem. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Tejun Heo <tj@kernel.org> Acked-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Jens Axboe <axboe@fb.com>
This commit is contained in:

committed by
Jens Axboe

parent
97b713ba3e
commit
b4caecd480
@@ -43,33 +43,7 @@
|
||||
|
||||
#include "mtdcore.h"
|
||||
|
||||
/*
|
||||
* backing device capabilities for non-mappable devices (such as NAND flash)
|
||||
* - permits private mappings, copies are taken of the data
|
||||
*/
|
||||
static struct backing_dev_info mtd_bdi_unmappable = {
|
||||
.capabilities = BDI_CAP_MAP_COPY,
|
||||
};
|
||||
|
||||
/*
|
||||
* backing device capabilities for R/O mappable devices (such as ROM)
|
||||
* - permits private mappings, copies are taken of the data
|
||||
* - permits non-writable shared mappings
|
||||
*/
|
||||
static struct backing_dev_info mtd_bdi_ro_mappable = {
|
||||
.capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
|
||||
BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
|
||||
};
|
||||
|
||||
/*
|
||||
* backing device capabilities for writable mappable devices (such as RAM)
|
||||
* - permits private mappings, copies are taken of the data
|
||||
* - permits non-writable shared mappings
|
||||
*/
|
||||
static struct backing_dev_info mtd_bdi_rw_mappable = {
|
||||
.capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
|
||||
BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
|
||||
BDI_CAP_WRITE_MAP),
|
||||
static struct backing_dev_info mtd_bdi = {
|
||||
};
|
||||
|
||||
static int mtd_cls_suspend(struct device *dev, pm_message_t state);
|
||||
@@ -365,6 +339,22 @@ static struct device_type mtd_devtype = {
|
||||
.release = mtd_release,
|
||||
};
|
||||
|
||||
#ifndef CONFIG_MMU
|
||||
unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
|
||||
{
|
||||
switch (mtd->type) {
|
||||
case MTD_RAM:
|
||||
return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
|
||||
NOMMU_MAP_READ | NOMMU_MAP_WRITE;
|
||||
case MTD_ROM:
|
||||
return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
|
||||
NOMMU_MAP_READ;
|
||||
default:
|
||||
return NOMMU_MAP_COPY;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* add_mtd_device - register an MTD device
|
||||
* @mtd: pointer to new MTD device info structure
|
||||
@@ -380,19 +370,7 @@ int add_mtd_device(struct mtd_info *mtd)
|
||||
struct mtd_notifier *not;
|
||||
int i, error;
|
||||
|
||||
if (!mtd->backing_dev_info) {
|
||||
switch (mtd->type) {
|
||||
case MTD_RAM:
|
||||
mtd->backing_dev_info = &mtd_bdi_rw_mappable;
|
||||
break;
|
||||
case MTD_ROM:
|
||||
mtd->backing_dev_info = &mtd_bdi_ro_mappable;
|
||||
break;
|
||||
default:
|
||||
mtd->backing_dev_info = &mtd_bdi_unmappable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mtd->backing_dev_info = &mtd_bdi;
|
||||
|
||||
BUG_ON(mtd->writesize == 0);
|
||||
mutex_lock(&mtd_table_mutex);
|
||||
@@ -1237,17 +1215,9 @@ static int __init init_mtd(void)
|
||||
if (ret)
|
||||
goto err_reg;
|
||||
|
||||
ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap");
|
||||
ret = mtd_bdi_init(&mtd_bdi, "mtd");
|
||||
if (ret)
|
||||
goto err_bdi1;
|
||||
|
||||
ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap");
|
||||
if (ret)
|
||||
goto err_bdi2;
|
||||
|
||||
ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap");
|
||||
if (ret)
|
||||
goto err_bdi3;
|
||||
goto err_bdi;
|
||||
|
||||
proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
|
||||
|
||||
@@ -1260,11 +1230,7 @@ static int __init init_mtd(void)
|
||||
out_procfs:
|
||||
if (proc_mtd)
|
||||
remove_proc_entry("mtd", NULL);
|
||||
err_bdi3:
|
||||
bdi_destroy(&mtd_bdi_ro_mappable);
|
||||
err_bdi2:
|
||||
bdi_destroy(&mtd_bdi_unmappable);
|
||||
err_bdi1:
|
||||
err_bdi:
|
||||
class_unregister(&mtd_class);
|
||||
err_reg:
|
||||
pr_err("Error registering mtd class or bdi: %d\n", ret);
|
||||
@@ -1277,9 +1243,7 @@ static void __exit cleanup_mtd(void)
|
||||
if (proc_mtd)
|
||||
remove_proc_entry("mtd", NULL);
|
||||
class_unregister(&mtd_class);
|
||||
bdi_destroy(&mtd_bdi_unmappable);
|
||||
bdi_destroy(&mtd_bdi_ro_mappable);
|
||||
bdi_destroy(&mtd_bdi_rw_mappable);
|
||||
bdi_destroy(&mtd_bdi);
|
||||
}
|
||||
|
||||
module_init(init_mtd);
|
||||
|
Reference in New Issue
Block a user