Message ID | 1496418222-23483-5-git-send-email-pali.rohar@gmail.com |
---|---|
State | Rejected |
Delegated to: | Boris Brezillon |
Headers | show |
Pali, On Fri, Jun 2, 2017 at 5:43 PM, Pali Rohár <pali.rohar@gmail.com> wrote: > This patch allows user to delete block2mtd mapping via parameters file > /sys/module/block2mtd/parameters/block2mtd > > Syntax is "del=device", e.g.: > > $ echo -n del=/dev/loop0 > /sys/module/block2mtd/parameters/block2mtd As I wrote in an earlier mail, I hate this interface. I suggest adding a decent ioctl based interface for dynamic block2mtd's.
On Friday 21 July 2017 21:56:41 Richard Weinberger wrote: > Pali, > > On Fri, Jun 2, 2017 at 5:43 PM, Pali Rohár <pali.rohar@gmail.com> wrote: > > This patch allows user to delete block2mtd mapping via parameters file > > /sys/module/block2mtd/parameters/block2mtd > > > > Syntax is "del=device", e.g.: > > > > $ echo -n del=/dev/loop0 > /sys/module/block2mtd/parameters/block2mtd > > As I wrote in an earlier mail, I hate this interface. > I suggest adding a decent ioctl based interface for dynamic block2mtd's. ioctl interface has a problem that cannot be easily used from shell. It needs to have another tool which uses it. On the other hand sysfs interface can be used from bash script which is better. Any idea for better interface without need for ioctl?
Pali, Am 25.07.2017 um 16:24 schrieb Pali Rohár: > On Friday 21 July 2017 21:56:41 Richard Weinberger wrote: >> Pali, >> >> On Fri, Jun 2, 2017 at 5:43 PM, Pali Rohár <pali.rohar@gmail.com> wrote: >>> This patch allows user to delete block2mtd mapping via parameters file >>> /sys/module/block2mtd/parameters/block2mtd >>> >>> Syntax is "del=device", e.g.: >>> >>> $ echo -n del=/dev/loop0 > /sys/module/block2mtd/parameters/block2mtd >> >> As I wrote in an earlier mail, I hate this interface. >> I suggest adding a decent ioctl based interface for dynamic block2mtd's. > > ioctl interface has a problem that cannot be easily used from shell. It > needs to have another tool which uses it. On the other hand sysfs > interface can be used from bash script which is better. > > Any idea for better interface without need for ioctl? No, please use ioctl and add a proper tool to mtd-utils. in MTD we use ioctl for all non-trivial interfaces. :-) Thanks, //richard
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index ad96937..9b6f7b5 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -355,6 +355,19 @@ static struct block2mtd_dev *add_device(char *devname, uint32_t erase_size, return NULL; } +static void del_device(struct block2mtd_dev *dev) +{ + if (!dev->ro_mode) + block2mtd_sync(&dev->mtd); + mtd_device_unregister(&dev->mtd); + mutex_destroy(&dev->write_mutex); + pr_info("mtd%d: [%s] removed\n", + dev->mtd.index, + dev->mtd.name + strlen("block2mtd: ")); + list_del(&dev->list); + block2mtd_free_device(dev); +} + /* This function works similar to reguler strtoul. In addition, it * allows some suffixes for a more human-readable number format: @@ -477,6 +490,19 @@ static int block2mtd_setup2(const char *val) } } + if (strncmp(name, "del=", strlen("del=")) == 0) { + struct list_head *pos, *next; + list_for_each_safe(pos, next, &blkmtd_device_list) { + struct block2mtd_dev *dev = + list_entry(pos, typeof(*dev), list); + if (strcmp(dev->mtd.name + strlen("block2mtd: "), + name + strlen("del=")) != 0) + continue; + del_device(dev); + return 0; + } + } + add_device(name, erase_size, write_size, subpage_sft, timeout); return 0; @@ -536,14 +562,7 @@ static void block2mtd_exit(void) /* Remove the MTD devices */ list_for_each_safe(pos, next, &blkmtd_device_list) { struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list); - block2mtd_sync(&dev->mtd); - mtd_device_unregister(&dev->mtd); - mutex_destroy(&dev->write_mutex); - pr_info("mtd%d: [%s] removed\n", - dev->mtd.index, - dev->mtd.name + strlen("block2mtd: ")); - list_del(&dev->list); - block2mtd_free_device(dev); + del_device(dev); } }
This patch allows user to delete block2mtd mapping via parameters file /sys/module/block2mtd/parameters/block2mtd Syntax is "del=device", e.g.: $ echo -n del=/dev/loop0 > /sys/module/block2mtd/parameters/block2mtd Signed-off-by: Pali Rohár <pali.rohar@gmail.com> --- drivers/mtd/devices/block2mtd.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)