Skip to contentSkip to conversation

1/4 UBI volume notifications - UBI changes

PATCH In review dmitry pervushin 2 participants 7 messages Dec 8, 2008 – Dec 15, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 1/4 UBI volume notifications - UBI changes

---
 drivers/mtd/ubi/build.c |   32 ++++++++++++++++++++++-
 drivers/mtd/ubi/cdev.c  |    2 +-
 drivers/mtd/ubi/kapi.c  |   29 +++++++++++++++++++++
 drivers/mtd/ubi/ubi.h   |   64 +++++++++++++++++++++++++++-------------------
 drivers/mtd/ubi/vmt.c   |   39 +++++++++++-----------------
 include/linux/mtd/ubi.h |   17 ++++++++++++
 6 files changed, 130 insertions(+), 53 deletions(-)
drivers/mtd/ubi/build.c +31 -1
index 634e2e8..fe9e329 100644
@@ -122,6 +122,34 @@ static struct device_attribute dev_mtd_num =
 	__ATTR(mtd_num, S_IRUGO, dev_attribute_show, NULL);
 
 /**
+ * ubi_enum_volumes - enumerate all existing volumes
+ */
+int ubi_enum_volumes(void *context,
+	void (*enumerator)(void *context, int ubi, const char *volume_name))
+{
+	int ubi_num, i, count = 0;
+	struct ubi_device *ubi;
+
+	spin_lock(&ubi_devices_lock);
+	for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) {
+		ubi = ubi_devices[ubi_num];
+		if (!ubi)
+			continue;
+		spin_lock(&ubi->volumes_lock);
+		for (i = 0; i < ubi->vtbl_slots; i++) {
+			if (!ubi->volumes[i])
+				continue;
+			enumerator(context, ubi_num, ubi->volumes[i]->name);
+			count++;
+		}
+		spin_unlock(&ubi->volumes_lock);
+	}
+	spin_unlock(&ubi_devices_lock);
+	return count;
+}
+
+
+/**
  * ubi_get_device - get UBI device.
  * @ubi_num: UBI device number
  *
@@ -842,6 +870,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 			goto out_detach;
 	}
 
+	/* when processing uif_init, we already might want to open the volume */
+	ubi_devices[ubi_num] = ubi;
 	err = uif_init(ubi);
 	if (err)
 		goto out_nofree;
@@ -874,12 +904,12 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 		ubi->thread_enabled = 1;
 	wake_up_process(ubi->bgt_thread);
 
-	ubi_devices[ubi_num] = ubi;
 	return ubi_num;
 
 out_uif:
 	uif_close(ubi);
 out_nofree:
+	ubi_devices[ubi_num] = NULL;
 	do_free = 0;
 out_detach:
 	ubi_wl_close(ubi);
drivers/mtd/ubi/cdev.c +1 -1
index b30a0b8..64a5398 100644
@@ -395,7 +395,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
 			vol->corrupted = 1;
 		}
 		vol->checked = 1;
-		ubi_gluebi_updated(vol);
+		ubi_volume_notify(UBI_VOLUME_CHANGED, ubi->ubi_num, vol->name);
 		revoke_exclusive(desc, UBI_READWRITE);
 	}
 
drivers/mtd/ubi/kapi.c +29 -0
index 5d9bcf1..0f3256b 100644
@@ -656,3 +656,32 @@ int ubi_sync(int ubi_num)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(ubi_sync);
+
+BLOCKING_NOTIFIER_HEAD(ubi_notifiers);
+
+static void do_notify_added(void *context, int ubi, const char *name)
+{
+	struct notifier_block *nb = context;
+	struct ubi_volume_notification nt;
+
+	nt.ubi_device = ubi;
+	nt.volume_name = name;
+	nb->notifier_call(context, UBI_VOLUME_ADDED, &nt);
+}
+
+int ubi_register_volume_notifier(struct notifier_block *nb, int ignore_existing)
+{
+	if (!ignore_existing) {
+	       down_read(&ubi_notifiers.rwsem);
+	       ubi_enum_volumes(nb, do_notify_added);
+	       up_read(&ubi_notifiers.rwsem);
+	}
+	return blocking_notifier_chain_register(&ubi_notifiers, nb);
+}
+EXPORT_SYMBOL_GPL(ubi_register_volume_notifier);
+
+int ubi_unregister_volume_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&ubi_notifiers, nb);
+}
+EXPORT_SYMBOL_GPL(ubi_unregister_volume_notifier);
drivers/mtd/ubi/ubi.h +36 -26

99 lines not on this page · raw message

drivers/mtd/ubi/vmt.c +15 -24
index 3531ca9..e6bedaa 100644
@@ -320,10 +320,6 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
 		goto out_mapping;
 	}
 
-	err = ubi_create_gluebi(ubi, vol);
-	if (err)
-		goto out_cdev;
-
 	vol->dev.release = vol_release;
 	vol->dev.parent = &ubi->dev;
 	vol->dev.devt = dev;
@@ -333,7 +329,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
 	err = device_register(&vol->dev);
 	if (err) {
 		ubi_err("cannot register device");
-		goto out_gluebi;
+		goto out_cdev;
 	}
 
 	err = volume_sysfs_init(ubi, vol);
@@ -361,6 +357,8 @@ 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->name);
+
 	err = paranoid_check_volumes(ubi);
 	return err;
 
@@ -376,10 +374,6 @@ out_sysfs:
 	do_free = 0;
 	get_device(&vol->dev);
 	volume_sysfs_close(vol);
-out_gluebi:
-	if (ubi_destroy_gluebi(vol))
-		dbg_err("cannot destroy gluebi for volume %d:%d",
-			ubi->ubi_num, vol_id);
 out_cdev:
 	cdev_del(&vol->cdev);
 out_mapping:
@@ -431,13 +425,10 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)
 		err = -EBUSY;
 		goto out_unlock;
 	}
+	ubi_volume_notify(UBI_VOLUME_DELETED, ubi->ubi_num, vol->name);
 	ubi->volumes[vol_id] = NULL;
 	spin_unlock(&ubi->volumes_lock);
 
-	err = ubi_destroy_gluebi(vol);
-	if (err)
-		goto out_err;
-
 	if (!no_vtbl) {
 		err = ubi_change_vtbl_record(ubi, vol_id, NULL);
 		if (err)
@@ -473,6 +464,7 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)
 	return err;
 
 out_err:
+	ubi_volume_notify(UBI_VOLUME_ADDED, ubi->ubi_num, vol->name);
 	ubi_err("cannot remove volume %d, error %d", vol_id, err);
 	spin_lock(&ubi->volumes_lock);
 	ubi->volumes[vol_id] = vol;
@@ -590,6 +582,8 @@ 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->name);
+
 	err = paranoid_check_volumes(ubi);
 	return err;
 
@@ -631,10 +625,14 @@ int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list)
 		} else {
 			struct ubi_volume *vol = re->desc->vol;
 
+			ubi_volume_notify(UBI_VOLUME_RENAMING,
+				ubi->ubi_num, vol->name);
 			spin_lock(&ubi->volumes_lock);
 			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->name);
 		}
 	}
 
@@ -670,10 +668,6 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
 		return err;
 	}
 
-	err = ubi_create_gluebi(ubi, vol);
-	if (err)
-		goto out_cdev;
-
 	vol->dev.release = vol_release;
 	vol->dev.parent = &ubi->dev;
 	vol->dev.devt = dev;
@@ -681,21 +675,19 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
 	sprintf(&vol->dev.bus_id[0], "%s_%d", ubi->ubi_name, vol->vol_id);
 	err = device_register(&vol->dev);
 	if (err)
-		goto out_gluebi;
+		goto out_cdev;
 
 	err = volume_sysfs_init(ubi, vol);
 	if (err) {
 		cdev_del(&vol->cdev);
-		err = ubi_destroy_gluebi(vol);
 		volume_sysfs_close(vol);
 		return err;
 	}
 
+	ubi_volume_notify(UBI_VOLUME_ADDED, ubi->ubi_num, vol->name);
 	err = paranoid_check_volumes(ubi);
 	return err;
 
-out_gluebi:
-	err = ubi_destroy_gluebi(vol);
 out_cdev:
 	cdev_del(&vol->cdev);
 	return err;
@@ -711,12 +703,11 @@ out_cdev:
  */
 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
 {
-	int err;
-
 	dbg_gen("free volume %d", vol->vol_id);
 
+	ubi_volume_notify(UBI_VOLUME_DELETED, ubi->ubi_num, vol->name);
+
 	ubi->volumes[vol->vol_id] = NULL;
-	err = ubi_destroy_gluebi(vol);
 	cdev_del(&vol->cdev);
 	volume_sysfs_close(vol);
 }
include/linux/mtd/ubi.h +17 -0
index 6316faf..3eb3997 100644
@@ -184,4 +184,21 @@ static inline int ubi_change(struct ubi_volume_desc *desc, int lnum,
 	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 {
+	int ubi_device;
+	const char *volume_name;
+};
+
+enum ubi_volume_notification_type {
+	UBI_VOLUME_ADDED,
+	UBI_VOLUME_DELETED,
+	UBI_VOLUME_CHANGED,
+	UBI_VOLUME_RENAMING,
+	UBI_VOLUME_RENAMED,
+};
+
 #endif /* !__LINUX_UBI_H__ */
Signature · 1 line
1.5.6
#1 lore raw

On Mon, 2008-12-08 at 20:59 +0300, dmitry pervushin wrote:
<snip>

Quoted 16 lines

/**
+ * ubi_enum_volumes - enumerate all existing volumes
+ */

drivers/mtd/ubi/build.c +13 -0
+int ubi_enum_volumes(void *context,
+	void (*enumerator)(void *context, int ubi, const char *volume_name))
+{
+	int ubi_num, i, count = 0;
+	struct ubi_device *ubi;
+
+	spin_lock(&ubi_devices_lock);
+	for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) {
+		ubi = ubi_devices[ubi_num];
+		if (!ubi)
+			continue;
+		spin_lock(&ubi->volumes_lock);
+		for (i = 0; i < ubi->vtbl_slots; i++) {

drivers/mtd/ubi/build.c static struct device_attribute dev_mtd_num = · line 149

Quoted 10 lines
drivers/mtd/ubi/build.c +10 -0
+			if (!ubi->volumes[i])
+				continue;
+			enumerator(context, ubi_num, ubi->volumes[i]->name);
+			count++;
+		}
+		spin_unlock(&ubi->volumes_lock);
+	}
+	spin_unlock(&ubi_devices_lock);
+	return count;
+}

Could you please initialize 'struct ubi_volume_notification' straight in this function, instead of having 'enumerator' call-back? I think this would be much more readable. I do not see the reason for this complexity.

<snip>

drivers/mtd/ubi/build.c int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) · line 877

Quoted 13 lines
drivers/mtd/ubi/build.c +3 -0
+/**
  * ubi_get_device - get UBI device.
  * @ubi_num: UBI device number
  *
@@ -842,6 +870,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 			goto out_detach;
 	}
 
+	/* when processing uif_init, we already might want to open the volume */
+	ubi_devices[ubi_num] = ubi;
 	err = uif_init(ubi);
 	if (err)
 		goto out_nofree;

I do not understand this change. The point is to prevent anyone from opening the volume before it is completely initialized. What you do - you allow the volume to be opened while it is in the middle of initialization, which is wrong. E.g., what if the initialization fails at some point?

And this change does not seem to be relevant to this patch.

<snip>

drivers/mtd/ubi/cdev.c static ssize_t vol_cdev_write(struct file *file, const char __user *buf, · line 400

Quoted 10 lines
drivers/mtd/ubi/cdev.c +1 -1
@@ -395,7 +395,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
 			vol->corrupted = 1;
 		}
 		vol->checked = 1;
-		ubi_gluebi_updated(vol);
+		ubi_volume_notify(UBI_VOLUME_CHANGED, ubi->ubi_num, vol->name);
 		revoke_exclusive(desc, UBI_READWRITE);
 	}

Could you please remove gluebi as a separate patch?

Quoted 1 line
drivers/mtd/ubi/kapi.c +0 -0

<snip>

drivers/mtd/ubi/kapi.c int ubi_sync(int ubi_num) · line 670

Quoted 10 lines
drivers/mtd/ubi/kapi.c +10 -0
+
+static void do_notify_added(void *context, int ubi, const char *name)
+{
+	struct notifier_block *nb = context;
+	struct ubi_volume_notification nt;
+
+	nt.ubi_device = ubi;
+	nt.volume_name = name;
+	nb->notifier_call(context, UBI_VOLUME_ADDED, &nt);
+}

As I said above, this call-back function does not seem to be reasonable.

Quoted 1 line
drivers/mtd/ubi/ubi.h +0 -0

<snip>

drivers/mtd/ubi/ubi.h struct ubi_volume { · line 242

Quoted 11 lines
drivers/mtd/ubi/ubi.h +0 -10
-#ifdef CONFIG_MTD_UBI_GLUEBI
-	/*
-	 * Gluebi-related stuff may be compiled out.
-	 * Note: this should not be built into UBI but should be a separate
-	 * ubimtd driver which works on top of UBI and emulates MTD devices.
-	 */
-	struct ubi_volume_desc *gluebi_desc;
-	int gluebi_refcount;
-	struct mtd_info gluebi_mtd;
-#endif
 };

Similar. May this stuff be removed in a separate patch please? It'll make things easier to review.

<snip>

drivers/mtd/ubi/ubi.h

Quoted 8 lines
drivers/mtd/ubi/ubi.h +8 -0
+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 {
+	int ubi_device;
+	const char *volume_name;
+};

This should have volume ID instead of name. Indeed, the ID is unique and never changes, while name may change, so ID is better for volume identification purposes.

<snip>

drivers/mtd/ubi/ubi.h

Quoted 7 lines
drivers/mtd/ubi/ubi.h +7 -0
+enum ubi_volume_notification_type {
+	UBI_VOLUME_ADDED,
+	UBI_VOLUME_DELETED,
+	UBI_VOLUME_CHANGED,
+	UBI_VOLUME_RENAMING,
+	UBI_VOLUME_RENAMED,
+};

I do not see a reason for 2 rename notifications. Why? For me it looks like one is enough.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#2 lore raw

On Tue, 2008-12-09 at 12:36 +0200, Artem Bityutskiy wrote:

Thanks for your review, my the only comment is inlined below.

[skipped]

Quoted 21 lines

<snip>

drivers/mtd/ubi/build.c int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) · line 877

Quoted 13 lines
drivers/mtd/ubi/build.c +3 -0
+/**
  * ubi_get_device - get UBI device.
  * @ubi_num: UBI device number
  *
@@ -842,6 +870,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 			goto out_detach;
 	}
 
+	/* when processing uif_init, we already might want to open the volume */
+	ubi_devices[ubi_num] = ubi;
 	err = uif_init(ubi);
 	if (err)
 		goto out_nofree;

I do not understand this change. The point is to prevent anyone from opening the volume before it is completely initialized. What you do - you allow the volume to be opened while it is in the middle of initialization, which is wrong. E.g., what if the initialization fails at some point?

Quoted 1 line

And this change does not seem to be relevant to this patch.

This change is absolutely needed :)
Well, the sequence of steps is as follows:
1. uif_init calls ubi_add_volume
2. ubi_add_volume notifies everyone about volume adding
3. (successful exit is not interested to us)
4. in case of errors reported by uif_init ubi_attach_mtd_dev calls ubi_kill_volumes
5. ubi_kill_volumes calls ubi_free_volume, which notifies everyone about volume deleting.

In current version, "notifies about volume adding" corresponds to ubi_create_gluebi and "...deleting" means ubi_destory_gluebi"

Does this sound right? OK, then I am replacing ubi_create_gluebi with notification, notification function tries to open new (just appeared) volume... and fails, because ubi_open_volume tries to ubi_get_device. It, in turn checks the "ubi_devices[ubi_num]" which is not filled yet.

So, I do insist on the change.

#3 lore raw
Quoted 27 lines · dmitry pervushin

On Tue, 2008-12-09 at 12:36 +0200, Artem Bityutskiy wrote:

Thanks for your review, my the only comment is inlined below.

[skipped]

Quoted 21 lines

<snip>

drivers/mtd/ubi/build.c int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) · line 877

Quoted 13 lines
drivers/mtd/ubi/build.c +3 -0
+/**
  * ubi_get_device - get UBI device.
  * @ubi_num: UBI device number
  *
@@ -842,6 +870,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 			goto out_detach;
 	}
 
+	/* when processing uif_init, we already might want to open the volume */
+	ubi_devices[ubi_num] = ubi;
 	err = uif_init(ubi);
 	if (err)
 		goto out_nofree;

I do not understand this change. The point is to prevent anyone from opening the volume before it is completely initialized. What you do - you allow the volume to be opened while it is in the middle of initialization, which is wrong. E.g., what if the initialization fails at some point?

Quoted 1 line

And this change does not seem to be relevant to this patch.

Quoted 9 lines

This change is absolutely needed :)
Well, the sequence of steps is as follows:
1. uif_init calls ubi_add_volume
2. ubi_add_volume notifies everyone about volume adding
3. (successful exit is not interested to us)
4. in case of errors reported by uif_init ubi_attach_mtd_dev calls ubi_kill_volumes
5. ubi_kill_volumes calls ubi_free_volume, which notifies everyone about volume deleting.

What may happen is

1. You make the UBI device visible by doing 'ubi_devices[ubi_num] = ubi'.
2. You call 'uif_init()' which starts adding volumes. Suppose it added N volumes out of M (M > N).
3. Some other task opens the UBI device, opens volume L (L <= N), and starts utilizing it. E.g., it might mounted by UBIFS.
4. 'uif_init()' fails to add volume S (S > N <= M), and all resources, including the opened volume L will be freed, and the system is in trouble.

Quoted 7 lines

In current version, "notifies about volume adding" corresponds to ubi_create_gluebi and "...deleting" means ubi_destory_gluebi"

Does this sound right? OK, then I am replacing ubi_create_gluebi with notification, notification function tries to open new (just appeared) volume... and fails, because ubi_open_volume tries to ubi_get_device. It, in turn checks the "ubi_devices[ubi_num]" which is not filled yet.

I think the solution is to call notifiers _after_ _everything_ is successfully initialized and has no chances to fail anymore, i.e., at the very end of 'ubi_attach_mtd_dev()' function.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#4 lore raw
Quoted 23 lines · Artem Bityutskiy
Quoted 23 lines

[skipped]

Quoted 22 lines

<snip>

drivers/mtd/ubi/build.c int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) · line 877

Quoted 13 lines
drivers/mtd/ubi/build.c +3 -0
+/**
  * ubi_get_device - get UBI device.
  * @ubi_num: UBI device number
  *
@@ -842,6 +870,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
 			goto out_detach;
 	}
 
+	/* when processing uif_init, we already might want to open the volume */
+	ubi_devices[ubi_num] = ubi;
 	err = uif_init(ubi);
 	if (err)
 		goto out_nofree;

I do not understand this change. The point is to prevent anyone from opening the volume before it is completely initialized. What you do - you allow the volume to be opened while it is in the middle of initialization, which is wrong. E.g., what if the initialization fails at some point?

And this change does not seem to be relevant to this patch.

Quoted 9 lines
Quoted 9 lines

This change is absolutely needed :)
Well, the sequence of steps is as follows:
1. uif_init calls ubi_add_volume
2. ubi_add_volume notifies everyone about volume adding
3. (successful exit is not interested to us)
4. in case of errors reported by uif_init ubi_attach_mtd_dev calls ubi_kill_volumes
5. ubi_kill_volumes calls ubi_free_volume, which notifies everyone about volume deleting.

Isn't it better then to protect the critical section in uif_init and open_volume by mutexes? Now it looks as you are adding volumes on non-existing-yet device.

Quoted 24 lines

What may happen is

1. You make the UBI device visible by doing 'ubi_devices[ubi_num] = ubi'.
2. You call 'uif_init()' which starts adding volumes. Suppose it added N volumes out of M (M > N).
3. Some other task opens the UBI device, opens volume L (L <= N), and starts utilizing it. E.g., it might mounted by UBIFS.
4. 'uif_init()' fails to add volume S (S > N <= M), and all resources, including the opened volume L will be freed, and the system is in trouble.

Quoted 7 lines

In current version, "notifies about volume adding" corresponds to ubi_create_gluebi and "...deleting" means ubi_destory_gluebi"

Does this sound right? OK, then I am replacing ubi_create_gluebi with notification, notification function tries to open new (just appeared) volume... and fails, because ubi_open_volume tries to ubi_get_device. It, in turn checks the "ubi_devices[ubi_num]" which is not filled yet.

I think the solution is to call notifiers _after_ _everything_ is successfully initialized and has no chances to fail anymore, i.e., at the very end of 'ubi_attach_mtd_dev()' function.

#5 lore raw
Quoted 17 lines · dmitry pervushin
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I do not understand this change. The point is to prevent anyone from opening the volume before it is completely initialized. What you do - you allow the volume to be opened while it is in the middle of initialization, which is wrong. E.g., what if the initialization fails at some point?

And this change does not seem to be relevant to this patch.

Quoted 9 lines
Quoted 9 lines

This change is absolutely needed :)
Well, the sequence of steps is as follows:
1. uif_init calls ubi_add_volume
2. ubi_add_volume notifies everyone about volume adding
3. (successful exit is not interested to us)
4. in case of errors reported by uif_init ubi_attach_mtd_dev calls ubi_kill_volumes
5. ubi_kill_volumes calls ubi_free_volume, which notifies everyone about volume deleting.

Quoted 2 lines

Isn't it better then to protect the critical section in uif_init and open_volume by mutexes?

May be. If you need this, feel free to send a patch. But it would not give you much, because you would have to call your notifiers _outside_ the mutexes, i.e. at the very end of the attach function.

Quoted 2 lines

Now it looks as you are adding volumes on
non-existing-yet device.

Right. For a short period of time during the attach process you may see volumes which you cannot really open (you get -ENODEV). That was not a problem so far, and it was just easier to implement things this way.

If you want to improve this and make the opening processes wait on a mutex - please, go ahead. But I doubt you really need this.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#6 lore raw
Quoted 28 lines · Artem Bityutskiy
Quoted 17 lines · dmitry pervushin
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I do not understand this change. The point is to prevent anyone from opening the volume before it is completely initialized. What you do - you allow the volume to be opened while it is in the middle of initialization, which is wrong. E.g., what if the initialization fails at some point?

And this change does not seem to be relevant to this patch.

Quoted 9 lines
Quoted 9 lines

This change is absolutely needed :)
Well, the sequence of steps is as follows:
1. uif_init calls ubi_add_volume
2. ubi_add_volume notifies everyone about volume adding
3. (successful exit is not interested to us)
4. in case of errors reported by uif_init ubi_attach_mtd_dev calls ubi_kill_volumes
5. ubi_kill_volumes calls ubi_free_volume, which notifies everyone about volume deleting.

Quoted 2 lines

Isn't it better then to protect the critical section in uif_init and open_volume by mutexes?

May be. If you need this, feel free to send a patch. But it would not give you much, because you would have to call your notifiers _outside_ the mutexes, i.e. at the very end of the attach function.

Quoted 2 lines

Now it looks as you are adding volumes on
non-existing-yet device.

Quoted 6 lines

Right. For a short period of time during the attach process you may see volumes which you cannot really open (you get -ENODEV). That was not a problem so far, and it was just easier to implement things this way.

If you want to improve this and make the opening processes wait on a mutex - please, go ahead. But I doubt you really need this.

Well, agreed. It makes sense. I am attaching new serie of patches:

ubi-notifications.patch - ubi notifications
remove-gluebi.patch - removes current mtd emulation
gluebi.patch - adds notification-based one
mtdblkdevs.patch - changes MTD blkdevs to accept NULL mtd and allow
dynamic major number assignment
ubiblock.patch - simple FTL