ubi notifications
Subsystems (2)
PATCH 1/1 ubi notifications
Hi all,
UBI volume notifications is intended to create the API to get clients notified about volume creation/deletion, renaming and changing(actually, resizing). A client can subscribe to these notifications using ubi_volume_register and cancel the subsription using ubi_volume_unregister. When UBI volume change occurs, the atomic notifier will be called. Client also can request "added" event on all volumes that existed before client subscribed to the notifications.
Using notifications instead of calling functions ubi_gluebi_xxx allows MTD emulation layer to be more flexible; say, now is it possible to build it as a module and load/unload it on demand.
Thanks Artem Bityutskiy for reviewing the patch and many very valuable comments.
--- drivers/mtd/ubi/build.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- drivers/mtd/ubi/cdev.c | 2 + drivers/mtd/ubi/kapi.c | 46 ++++++++++++++++++++++++++++++ drivers/mtd/ubi/ubi.h | 37 ++++++++++++++++++++++++ drivers/mtd/ubi/vmt.c | 7 ++++ include/linux/mtd/ubi.h | 36 +++++++++++++++++++++++ 6 files changed, 198 insertions(+), 3 deletions(-)
drivers/mtd/ubi/build.c +70 -3
@@ -122,6 +122,69 @@ static struct device_attribute dev_mtd_n__ATTR (mtd_num,S_IRUGO , dev_attribute_show,NULL );/** +* ubi_enum_volumes - enumerate volumes on device and send notification. +* @t: notification type to send +* @ubi: UBI device +* @nb: notifier to be called, or %NULL to send to system-wide notification +* +* Walk on the list of volumes that are created on device @ubi and send the +* notification specified by @t. +* +* Returns number of volumes processed. +*/ +int ubi_enum_volumes (enum ubi_volume_notification_type t, +struct ubi_device *ubi,struct notifier_block *nb) +{ +int i, count =0 ; +struct ubi_volume_notification nt; + + nt.ubi_num = ubi->ubi_num; + +spin_lock (&ubi->volumes_lock); +for (i =0 ; i < ubi->vtbl_slots; i++) { +if (!ubi->volumes[i]) +continue ; + nt.vol_id = ubi->volumes[i]->vol_id; +spin_unlock (&ubi->volumes_lock); +if (nb) + nb->notifier_call (nb, t, &nt); +else +blocking_notifier_call_chain (&ubi_notifiers, + t, &nt); + count++; +spin_lock (&ubi->volumes_lock); + } +spin_unlock (&ubi->volumes_lock); +return count; +} + +/** +* ubi_enum_all_volumes - enumerate all existing volumes and send notification. +* @t: notification type to send. +* @nb: notifier to be called, or %NULL to send to system-wide notification +* +* Using ubi_enum_volumes to enumerate volumes on the UBI device, enumerate +* all existing UBI devices. +*/ +int ubi_enum_all_volumes (enum ubi_volume_notification_type t, +struct notifier_block *nb) +{ +int n; +struct ubi_device *ubi; +int count =0 ; + +spin_lock (&ubi_devices_lock); +for (n =0 ; n <UBI_MAX_DEVICES ; n++) { + ubi = ubi_devices[n]; +spin_unlock (&ubi_devices_lock); +if (ubi) + count +=ubi_enum_volumes (t, ubi, nb); +spin_lock (&ubi_devices_lock); + } +spin_unlock (&ubi_devices_lock); +return count; +} +/** * ubi_get_device - get UBI device. * @ubi_num: UBI device number *
@@ -877,6 +940,7 @@ int ubi_attach_mtd_dev(struct mtd_info *wake_up_process (ubi->bgt_thread); ubi_devices[ubi_num] = ubi; +ubi_enum_volumes (UBI_VOLUME_ADDED , ubi,NULL );return ubi_num; out_uif:
@@ -921,14 +985,17 @@ int ubi_detach_mtd_dev(int ubi_num, intspin_lock (&ubi_devices_lock); ubi = ubi_devices[ubi_num]; -if (!ubi) { -spin_unlock (&ubi_devices_lock); +spin_unlock (&ubi_devices_lock); + +if (!ubi)return -EINVAL ; - } +ubi_enum_volumes (UBI_VOLUME_DELETED , ubi,NULL ); +spin_lock (&ubi_devices_lock);if (ubi->ref_count) {if (!anyway) {spin_unlock (&ubi_devices_lock); +ubi_enum_volumes (UBI_VOLUME_ADDED , ubi,NULL );return -EBUSY ; }/* This may only happen if there is a bug */
drivers/mtd/ubi/cdev.c +2 -0
@@ -394,6 +394,8 @@ static ssize_t vol_cdev_write(struct fil } vol->checked =1 ;ubi_gluebi_updated (vol); +ubi_volume_notify (UBI_VOLUME_CHANGED , + ubi->ubi_num, vol->vol_id);revoke_exclusive (desc,UBI_READWRITE ); }
drivers/mtd/ubi/kapi.c +46 -0
49 lines not on this page · raw message
drivers/mtd/ubi/ubi.h +37 -0
@@ -38,6 +38,7 @@#include <linux/vmalloc.h> #include <linux/mtd/mtd.h> #include <linux/mtd/ubi.h> +#include <linux/notifier.h> #include "ubi-media.h" #include "scan.h"
@@ -457,6 +458,7 @@ extern const struct file_operations ubi_extern const struct file_operations ubi_vol_cdev_operations;extern struct class *ubi_class;extern struct mutex ubi_devices_mutex; +extern struct blocking_notifier_head ubi_notifiers;/* vtbl.c */ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
@@ -550,6 +552,41 @@ void ubi_put_device(struct ubi_device *ustruct ubi_device *ubi_get_by_major (int major);int ubi_major2num (int major); +int ubi_enum_volumes (enum ubi_volume_notification_type t, +struct ubi_device *ubi,struct notifier_block *nb); +int ubi_enum_all_volumes (enum ubi_volume_notification_type t, +struct notifier_block *nb); + +static inline char *ubi_notification (enum ubi_volume_notification_type t) +{ +static char *nstr[] = { + [UBI_VOLUME_ADDED ] ="Added" , + [UBI_VOLUME_DELETED ] ="Deleted" , + [UBI_VOLUME_RENAMED ] ="Renamed" , + [UBI_VOLUME_CHANGED ] ="Changed" , + }; +return nstr[t]; +} +/** +* ubi_volume_notify - notify all registered clients about volume changes. +* @t: notification type +* @ubi_num: device number +* @volume_name: name of created/removed/changed volume +*/ +static inline int ubi_volume_notify (enum ubi_volume_notification_type t, +int ubi_num,int volume_id) +{ +struct ubi_volume_notification nt; + + nt.ubi_num = ubi_num; + nt.vol_id = volume_id; +dbg_gen ("%s: %s volume id %d on device %d\n" , + __func__, +ubi_notification (t), + volume_id, + ubi_num); +return blocking_notifier_call_chain (&ubi_notifiers, t, &nt); +}/* * ubi_rb_for_each_entry - walk an RB-tree. * @rb: a pointer to type 'struct rb_node' to to use as a loop counter
drivers/mtd/ubi/vmt.c +7 -0
@@ -358,6 +358,7 @@ int ubi_create_volume(struct ubi_device ubi->vol_count +=1 ;spin_unlock (&ubi->volumes_lock); +ubi_volume_notify (UBI_VOLUME_ADDED , ubi->ubi_num, vol->vol_id); err =paranoid_check_volumes (ubi);return err;
@@ -419,6 +420,8 @@ int ubi_remove_volume(struct ubi_volume_if (ubi->ro_mode)return -EROFS ; +ubi_volume_notify (UBI_VOLUME_DELETED , ubi->ubi_num, vol_id); +spin_lock (&ubi->volumes_lock);if (vol->ref_count >1 ) {/*
@@ -475,6 +478,7 @@ out_err: ubi->volumes[vol_id] = vol; out_unlock:spin_unlock (&ubi->volumes_lock); +ubi_volume_notify (UBI_VOLUME_ADDED , ubi->ubi_num, vol_id);return err; }
@@ -587,6 +591,7 @@ int ubi_resize_volume(struct ubi_volume_ (long long )vol->used_ebs * vol->usable_leb_size; } +ubi_volume_notify (UBI_VOLUME_CHANGED , ubi->ubi_num, vol->vol_id); err =paranoid_check_volumes (ubi);return err;
@@ -632,6 +637,8 @@ int ubi_rename_volumes(struct ubi_device vol->name_len = re->new_name_len;memcpy (vol->name, re->new_name, re->new_name_len +1 );spin_unlock (&ubi->volumes_lock); +ubi_volume_notify (UBI_VOLUME_RENAMED , + ubi->ubi_num, vol->vol_id); } }
include/linux/mtd/ubi.h +36 -0
@@ -184,4 +184,40 @@ static inline int ubi_change(struct ubi_ return ubi_leb_change(desc, lnum, buf, len, UBI_UNKNOWN); } +int ubi_register_volume_notifier (struct notifier_block *nb, +int ignore_existing); +int ubi_unregister_volume_notifier (struct notifier_block *nb); + +/** +* struct ubi_volume_notification - information about changed volume. +* @ubi_num: UBI device number where the changed volume persists +* @vol_id: changed volume id +* +* Each notification about changed volume takes two parameters - first one +* is of type &enum ubi_volume_notification_type and indicates the type of +* volume change, and the second parameter is a pointer to the &struct +* ubi_volume_notification and describes the subject of change. +*/ +struct ubi_volume_notification { +int ubi_num; +int vol_id; +}; + +/** +* enum ubi_volume_notification_type - type of volume_change. +* @UBI_VOLUME_ADDED: volume has been added +* @UBI_VOLUME_DELETED: volume has been deleted +* @UBI_VOLUME_CHANGED: volume size has been changed +* @UBI_VOLUME_RENAMED: volume name has been changed +* +* Varialble of this type is passed as the first parameter to the notification +* function. +*/ +enum ubi_volume_notification_type { +UBI_VOLUME_ADDED , +UBI_VOLUME_DELETED , +UBI_VOLUME_CHANGED , +UBI_VOLUME_RENAMED , +}; +#endif /* !__LINUX_UBI_H__ */
Quoted 10 lines · dmitry pervushin
Hi all,
UBI volume notifications is intended to create the API to get clients notified about volume creation/deletion, renaming and
changing(actually, resizing). A client can subscribe to these notifications usingubi_volume_registerand cancel the subsription usingubi_volume_unregister. When UBI volume change occurs, the atomic notifier will be called. Client also can request "added" event on all volumes that existed before client subscribed to the notifications.
Quoted 8 lines
Using notifications instead of calling functions
ubi_gluebi_xxxallows MTD emulation layer to be more flexible; say, now is it possible to build it as a module and load/unload it on demand.Thanks Artem Bityutskiy for reviewing the patch and many very valuable comments.
Signed-off-by dmitry pervushin <[email protected]>
Hi,
thanks for the patch. Is it possible to submit it together with a user? E.g., AFAIR you separated out gluebi, could this be also submitted? I would be much happier to see a new interface functions + a user, not just the interface functions alone.
I've inlined a slightly midified version of your patch for you, because I found it easier to fix minor things rather than request you about this.
I've changed the following:
1. Moved definitions in include/linux/mtd/ubi.h to different positions.
2. Removed '/**' for enums, because last time I tried kerneldoc it did not accept enums.
3. Made your ubi_volume_notification_type enums anonymous, because named enums make few sense in C - there is no strict type checking for them anyway, and they just hurt readability.
4. Renamed "t" to "ntype".
5. Removed:
dbg_gen("%s: %s volume id %d on device %d\n",
i __func__,
ubi_notification(t),
volume_id,
ubi_num); If you want it, look how dbg_gen() is defined, and add proper print.
6. Since the print was the only user of 'ubi_notification()', I killed that too. I did not like it because it is inline, with static local variable as well. If you want it, please re-add it. Make it non-inline, make it debug-only, because it is used only from gen_dbg().
Some other minor changes in comments.
Anyway, I am going to be unavailable next week. Please, try to send both API add and the user. Also, there is a note below.
Quoted 31 lines
--- drivers/mtd/ubi/build.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- drivers/mtd/ubi/cdev.c | 2 + drivers/mtd/ubi/kapi.c | 46 ++++++++++++++++++++++++++++++ drivers/mtd/ubi/ubi.h | 37 ++++++++++++++++++++++++ drivers/mtd/ubi/vmt.c | 7 ++++ include/linux/mtd/ubi.h | 36 +++++++++++++++++++++++ 6 files changed, 198 insertions(+), 3 deletions(-)Index:
linux-2.6/drivers/mtd/ubi/build.c
===================================================================drivers/mtd/ubi/build.c +14
-0@@ -122,6 +122,69 @@ static struct device_attribute dev_mtd_n__ATTR (mtd_num,S_IRUGO , dev_attribute_show,NULL );/** +* ubi_enum_volumes - enumerate volumes on device and send notification. +* @t: notification type to send +* @ubi: UBI device +* @nb: notifier to be called, or %NULL to send to system-wide notification +* +* Walk on the list of volumes that are created on device @ubi and send the +* notification specified by @t. +* +* Returns number of volumes processed. +*/ +int ubi_enum_volumes (enum ubi_volume_notification_type t, +struct ubi_device *ubi,struct notifier_block *nb) +{ +int i, count =0 ;
drivers/mtd/ubi/build.c static struct device_attribute dev_mtd_n · line 148
Quoted 10 lines
drivers/mtd/ubi/build.c +10
-0+struct ubi_volume_notification nt; + + nt.ubi_num = ubi->ubi_num; + +spin_lock (&ubi->volumes_lock); +for (i =0 ; i < ubi->vtbl_slots; i++) { +if (!ubi->volumes[i]) +continue ; + nt.vol_id = ubi->volumes[i]->vol_id; +spin_unlock (&ubi->volumes_lock);
What prevents the volume to be removed at this point? Shouldn't you get a volume reference? Like in 'ubi_open_volume()'? Or like in 'vol_attribute_show()' ?
get_device(&vol->dev);
vol->ref_count += 1;drivers/mtd/ubi/build.c static struct device_attribute dev_mtd_n · line 154
Quoted 6 lines
drivers/mtd/ubi/build.c +6
-0+if (nb) + nb->notifier_call (nb, t, &nt); +else +blocking_notifier_call_chain (&ubi_notifiers, + t, &nt); + count++;
And of course then release the reference here...
Quoted 7 lines
drivers/mtd/ubi/build.c +6
-0+spin_lock (&ubi->volumes_lock); + } +spin_unlock (&ubi->volumes_lock); +return count; +} +int ubi_enum_all_volumes(enum ubi_volume_notification_type t,
drivers/mtd/ubi/build.c static struct device_attribute dev_mtd_n · line 171
Quoted 10 lines
drivers/mtd/ubi/build.c +10
-0+ struct notifier_block *nb) +{ +int n; +struct ubi_device *ubi; +int count =0 ; + +spin_lock (&ubi_devices_lock); +for (n =0 ; n <UBI_MAX_DEVICES ; n++) { + ubi = ubi_devices[n]; +spin_unlock (&ubi_devices_lock);
You got the pointer. You dropped the lock. Now you are preempted and whole UBI device is removed (e.g., by 'ubi_detach_mtd_dev()' ioctl). Then what happens?
Shouldn't you take a reference to the device before releasing the lock? Something similar to what 'ubi_get_device()' does:
ubi->ref_count += 1;get_device(&ubi->dev);
drivers/mtd/ubi/build.c static struct device_attribute dev_mtd_n · line 174
Quoted 3 lines
drivers/mtd/ubi/build.c +3
-0+if (ubi) + count +=ubi_enum_volumes (t, ubi, nb); +spin_lock (&ubi_devices_lock);
And release the reference here...
drivers/mtd/ubi/build.c static struct device_attribute dev_mtd_n · line 178
Quoted 4 lines
drivers/mtd/ubi/build.c +4
-0+ } +spin_unlock (&ubi_devices_lock); +return count; +}
Your patch with my nicifications. I did not have time to look nicify everything, though, just some stuff.
From: Dmitry Pervushin <[email protected]>
Subject: [PATCH] UBI: add notifiers notifications
UBI volume notifications are intended to create the API to get clients notified about volume creation/deletion, renaming and changing(actually, resizing). A client can subscribe to these notifications using ubi_volume_register and cancel the subscription using ubi_volume_unregister. When UBI volume change occurs, the atomic notifier will be called. Client also can request "added" event on all volumes that existed before client subscribed to the notifications.
Using notifications instead of calling functions ubi_gluebi_xxx allows MTD emulation layer to be more flexible; say, now is it possible to build it as a module and load/unload it on demand.
Thanks Artem Bityutskiy for reviewing the patch and many very valuable comments.
--- drivers/mtd/ubi/build.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-- drivers/mtd/ubi/cdev.c | 2 + drivers/mtd/ubi/kapi.c | 46 ++++++++++++++++++++++++++++++ drivers/mtd/ubi/ubi.h | 24 ++++++++++++++++ drivers/mtd/ubi/vmt.c | 7 ++++ include/linux/mtd/ubi.h | 36 ++++++++++++++++++++++++ 6 files changed, 183 insertions(+), 3 deletions(-)
drivers/mtd/ubi/build.c +68 -3
@@ -122,6 +122,67 @@ static struct device_attribute dev_mtd_num =__ATTR (mtd_num,S_IRUGO , dev_attribute_show,NULL );/** +* ubi_enum_volumes - "enumerate" volumes. +* @ntype: notification type to send (%UBI_VOLUME_ADDED, etc) +* @ubi: UBI device description object +* @nb: notifier to be called or %NULL to send to system-wide notification +* +* This function walks all volumes of UBI device @ubi and sends the +* notification specified by @ntype. Returns number of sent notifications. +*/ +int ubi_enum_volumes (int ntype,struct ubi_device *ubi, +struct notifier_block *nb) +{ +struct ubi_volume_notification nt; +int i, count =0 ; + + nt.ubi_num = ubi->ubi_num; + +spin_lock (&ubi->volumes_lock); +for (i =0 ; i < ubi->vtbl_slots; i++) { +if (!ubi->volumes[i]) +continue ; + nt.vol_id = ubi->volumes[i]->vol_id; +spin_unlock (&ubi->volumes_lock); +if (nb) + nb->notifier_call (nb, ntype, &nt); +else +blocking_notifier_call_chain (&ubi_notifiers, + ntype, &nt); + count++; +spin_lock (&ubi->volumes_lock); + } +spin_unlock (&ubi->volumes_lock); + +return count; +} + +/** +* ubi_enum_all_volumes - enumerate all existing volumes and send notification. +* @ntype: notification type to send (%UBI_VOLUME_ADDED, etc) +* @nb: notifier to be called, or %NULL to send to system-wide notification +* +* This function walks all UBI devices and all volumes on the device, and sends +* the notification specified by @ntype. Returns number of sent notifications. +*/ +int ubi_enum_all_volumes (int ntype,struct notifier_block *nb) +{ +struct ubi_device *ubi; +int i, count =0 ; + +spin_lock (&ubi_devices_lock); +for (i =0 ; i <UBI_MAX_DEVICES ; i++) { + ubi = ubi_devices[i]; +spin_unlock (&ubi_devices_lock); +if (ubi) + count +=ubi_enum_volumes (ntype, ubi, nb); +spin_lock (&ubi_devices_lock); + } +spin_unlock (&ubi_devices_lock); +return count; +} + +/** * ubi_get_device - get UBI device. * @ubi_num: UBI device number *
@@ -877,6 +938,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)wake_up_process (ubi->bgt_thread); ubi_devices[ubi_num] = ubi; +ubi_enum_volumes (UBI_VOLUME_ADDED , ubi,NULL );return ubi_num; out_uif:
@@ -921,14 +983,17 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)spin_lock (&ubi_devices_lock); ubi = ubi_devices[ubi_num]; -if (!ubi) { -spin_unlock (&ubi_devices_lock); +spin_unlock (&ubi_devices_lock); + +if (!ubi)return -EINVAL ; - } +ubi_enum_volumes (UBI_VOLUME_DELETED , ubi,NULL ); +spin_lock (&ubi_devices_lock);if (ubi->ref_count) {if (!anyway) {spin_unlock (&ubi_devices_lock); +ubi_enum_volumes (UBI_VOLUME_ADDED , ubi,NULL );return -EBUSY ; }/* This may only happen if there is a bug */
drivers/mtd/ubi/cdev.c +2 -0
@@ -394,6 +394,8 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf, } vol->checked =1 ;ubi_gluebi_updated (vol); +ubi_volume_notify (UBI_VOLUME_CHANGED , + ubi->ubi_num, vol->vol_id);revoke_exclusive (desc,UBI_READWRITE ); }
drivers/mtd/ubi/kapi.c +46 -0
49 lines not on this page · raw message
drivers/mtd/ubi/ubi.h +24 -0
@@ -38,6 +38,7 @@#include <linux/vmalloc.h> #include <linux/mtd/mtd.h> #include <linux/mtd/ubi.h> +#include <linux/notifier.h> #include "ubi-media.h" #include "scan.h"
@@ -457,6 +458,7 @@ extern const struct file_operations ubi_cdev_operations;extern const struct file_operations ubi_vol_cdev_operations;extern struct class *ubi_class;extern struct mutex ubi_devices_mutex; +extern struct blocking_notifier_head ubi_notifiers;/* vtbl.c */ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
@@ -549,6 +551,9 @@ struct ubi_device *ubi_get_device(int ubi_num);void ubi_put_device (struct ubi_device *ubi);struct ubi_device *ubi_get_by_major (int major);int ubi_major2num (int major); +int ubi_enum_volumes (int ntype,struct ubi_device *ubi, +struct notifier_block *nb); +int ubi_enum_all_volumes (int ntype,struct notifier_block *nb);/* * ubi_rb_for_each_entry - walk an RB-tree.
@@ -564,6 +569,25 @@ int ubi_major2num(int major); rb = rb_next(rb), pos = container_of(rb, typeof(*pos), member))/** +* ubi_volume_notify - notify all registered clients about volume changes. +* @ntype: notification type to send (%UBI_VOLUME_ADDED, etc) +* @ubi_num: UBI device number +* @vol_id: ID of the created/removed/changed volume +* +* This is a helper function which notifies all subscribers about a volume +* change event. Returns zero in case of success and a negative error code in +* case of failure. +*/ +static inline int ubi_volume_notify (int ntype,int ubi_num,int vol_id) +{ +struct ubi_volume_notification nt; + + nt.ubi_num = ubi_num; + nt.vol_id = vol_id; +return blocking_notifier_call_chain (&ubi_notifiers, ntype, &nt); +} + +/** * ubi_zalloc_vid_hdr - allocate a volume identifier header object. * @ubi: UBI device description object * @gfp_flags: GFP flags to allocate with
drivers/mtd/ubi/vmt.c +7 -0
@@ -358,6 +358,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) ubi->vol_count +=1 ;spin_unlock (&ubi->volumes_lock); +ubi_volume_notify (UBI_VOLUME_ADDED , ubi->ubi_num, vol->vol_id); err =paranoid_check_volumes (ubi);return err;
@@ -419,6 +420,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)if (ubi->ro_mode)return -EROFS ; +ubi_volume_notify (UBI_VOLUME_DELETED , ubi->ubi_num, vol_id); +spin_lock (&ubi->volumes_lock);if (vol->ref_count >1 ) {/*
@@ -475,6 +478,7 @@ out_err: ubi->volumes[vol_id] = vol; out_unlock:spin_unlock (&ubi->volumes_lock); +ubi_volume_notify (UBI_VOLUME_ADDED , ubi->ubi_num, vol_id);return err; }
@@ -587,6 +591,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) (long long )vol->used_ebs * vol->usable_leb_size; } +ubi_volume_notify (UBI_VOLUME_CHANGED , ubi->ubi_num, vol->vol_id); err =paranoid_check_volumes (ubi);return err;
@@ -632,6 +637,8 @@ int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list) vol->name_len = re->new_name_len;memcpy (vol->name, re->new_name, re->new_name_len +1 );spin_unlock (&ubi->volumes_lock); +ubi_volume_notify (UBI_VOLUME_RENAMED , + ubi->ubi_num, vol->vol_id); } }
include/linux/mtd/ubi.h +36 -0
@@ -132,6 +132,38 @@ struct ubi_device_info {dev_t cdev; }; +/* +* struct ubi_volume_notification - information about changed volume. +* @ubi_num: UBI device number where the changed volume persists +* @vol_id: changed volume id +* +* Each notification about changed volume takes two parameters - first one +* is of type &enum ubi_volume_notification_type and indicates the type of +* volume change, and the second parameter is a pointer to the &struct +* ubi_volume_notification and describes the subject of change. +*/ +struct ubi_volume_notification { +int ubi_num; +int vol_id; +}; + +/* +* enum - type of volume_change. +* @UBI_VOLUME_ADDED: volume has been added +* @UBI_VOLUME_DELETED: volume has been deleted +* @UBI_VOLUME_CHANGED: volume size has been changed +* @UBI_VOLUME_RENAMED: volume name has been changed +* +* Variable of this type is passed as the first parameter to the notification +* function. +*/ +enum { +UBI_VOLUME_ADDED , +UBI_VOLUME_DELETED , +UBI_VOLUME_CHANGED , +UBI_VOLUME_RENAMED , +}; +/* UBI descriptor given to users when they open UBI volumes */ struct ubi_volume_desc ;
@@ -141,6 +173,10 @@ void ubi_get_volume_info(struct ubi_volume_desc *desc,struct ubi_volume_desc *ubi_open_volume (int ubi_num,int vol_id,int mode);struct ubi_volume_desc *ubi_open_volume_nm (int ubi_num,const char *name,int mode); +int ubi_register_volume_notifier (struct notifier_block *nb, +int ignore_existing); +int ubi_unregister_volume_notifier (struct notifier_block *nb); +void ubi_close_volume (struct ubi_volume_desc *desc);int ubi_leb_read (struct ubi_volume_desc *desc,int lnum,char *buf,int offset,int len,int check);
Signature · 5 lines
1.6.0.6 -- Best regards, Artem Bityutskiy (Битюцкий Артём)
The patchset is in next three messages
Quoted 29 lines · Artem Bityutskiy
Quoted 8 lines · dmitry pervushin
UBI volume notifications is intended to create the API to get clients notified about volume creation/deletion, renaming and
changing(actually, resizing). A client can subscribe to these notifications usingubi_volume_registerand cancel the subsription usingubi_volume_unregister. When UBI volume change occurs, the atomic notifier will be called. Client also can request "added" event on all volumes that existed before client subscribed to the notifications.Quoted 8 lines
Using notifications instead of calling functions
ubi_gluebi_xxxallows MTD emulation layer to be more flexible; say, now is it possible to build it as a module and load/unload it on demand.Thanks Artem Bityutskiy for reviewing the patch and many very valuable comments.
Signed-off-by dmitry pervushin <[email protected]>Hi,
thanks for the patch. Is it possible to submit it together with a user? E.g., AFAIR you separated out gluebi, could this be also submitted? I would be much happier to see a new interface functions + a user, not just the interface functions alone.
I've inlined a slightly midified version of your patch for you, because I found it easier to fix minor things rather than request you about this.
[skipped]