diff mbox

[1/1] ubi: remove and create MTD device back when UBI volume is resized

Message ID 1376306265-8671-1-git-send-email-Andrew.Rybchenko@oktetlabs.ru
State New, archived
Headers show

Commit Message

Andrew Rybchenko Aug. 12, 2013, 11:17 a.m. UTC
If underlying MTD device size is simply corrected (as it was before),
MTD block device is not notified about MTD device size change. As the
result, for example, mount fails after create with zero size, resize,
write file system image.

Side effect of the patch is change of MTD device number on resize/update.

Signed-off-by: Andrew Rybchenko <Andrew.Rybchenko@oktetlabs.ru>
---
 drivers/mtd/ubi/gluebi.c |   64 +++++-----------------------------------------
 1 file changed, 7 insertions(+), 57 deletions(-)

Comments

Artem Bityutskiy Aug. 16, 2013, 2:07 p.m. UTC | #1
On Mon, 2013-08-12 at 15:17 +0400, Andrew Rybchenko wrote:
> If underlying MTD device size is simply corrected (as it was before),
> MTD block device is not notified about MTD device size change. As the
> result, for example, mount fails after create with zero size, resize,
> write file system image.
> 
> Side effect of the patch is change of MTD device number on resize/update.
> 
> Signed-off-by: Andrew Rybchenko <Andrew.Rybchenko@oktetlabs.ru>

Usually MTD devices never change their size, and the whole MTD subsystem
is implemented with this assumption, and the users of the MTD interface
have the same assumption - MTD devices do not size change their size.

So this change is fixing one problem by introducing another problem -
now not only the size may change, but the device number may change, and
even more ...

> +		gluebi_remove(&nt->vi);

... the device may just disappear for a while (not, the mtd mutex is
dropped here).

> +		gluebi_create(&nt->di, &nt->vi);

... then appear again in a different form :-)

When you remove the device, you also remove its sysfs files. And then
re-creates it. What an app keeps it open? Not big deal, it'll just get a
read error next time it reads it.

Anyway, this patch is not ideal.

I guess the right way to solve the problem would be to just prohibit
re-sizing a UBI volumes if we use gluebi.

Or just put the entire emulated MTD device to some "invalid" state if
the underlying UBI volume was resized. May be not always, but only if it
became smaller.

Or something else.

Anyway, I do acknowledge this is a problem, but I am not sure this is a
good solution...
diff mbox

Patch

diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index b93807b..fa4f764 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -403,60 +403,6 @@  static int gluebi_remove(struct ubi_volume_info *vi)
 }
 
 /**
- * gluebi_updated - UBI volume was updated notifier.
- * @vi: volume info structure
- *
- * This function is called every time an UBI volume is updated. It does nothing
- * if te volume @vol is dynamic, and changes MTD device size if the
- * volume is static. This is needed because static volumes cannot be read past
- * data they contain. This function returns zero in case of success and a
- * negative error code in case of error.
- */
-static int gluebi_updated(struct ubi_volume_info *vi)
-{
-	struct gluebi_device *gluebi;
-
-	mutex_lock(&devices_mutex);
-	gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id);
-	if (!gluebi) {
-		mutex_unlock(&devices_mutex);
-		err_msg("got update notification for unknown UBI device %d volume %d",
-			vi->ubi_num, vi->vol_id);
-		return -ENOENT;
-	}
-
-	if (vi->vol_type == UBI_STATIC_VOLUME)
-		gluebi->mtd.size = vi->used_bytes;
-	mutex_unlock(&devices_mutex);
-	return 0;
-}
-
-/**
- * gluebi_resized - UBI volume was re-sized notifier.
- * @vi: volume info structure
- *
- * This function is called every time an UBI volume is re-size. It changes the
- * corresponding fake MTD device size. This function returns zero in case of
- * success and a negative error code in case of error.
- */
-static int gluebi_resized(struct ubi_volume_info *vi)
-{
-	struct gluebi_device *gluebi;
-
-	mutex_lock(&devices_mutex);
-	gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id);
-	if (!gluebi) {
-		mutex_unlock(&devices_mutex);
-		err_msg("got update notification for unknown UBI device %d volume %d",
-			vi->ubi_num, vi->vol_id);
-		return -ENOENT;
-	}
-	gluebi->mtd.size = vi->used_bytes;
-	mutex_unlock(&devices_mutex);
-	return 0;
-}
-
-/**
  * gluebi_notify - UBI notification handler.
  * @nb: registered notifier block
  * @l: notification type
@@ -475,10 +421,14 @@  static int gluebi_notify(struct notifier_block *nb, unsigned long l,
 		gluebi_remove(&nt->vi);
 		break;
 	case UBI_VOLUME_RESIZED:
-		gluebi_resized(&nt->vi);
-		break;
 	case UBI_VOLUME_UPDATED:
-		gluebi_updated(&nt->vi);
+		/*
+		 * In theory it could be possible to simply change MTD device
+		 * size, but it would require a way to notify
+		 * corresponding block device as well.
+		 */
+		gluebi_remove(&nt->vi);
+		gluebi_create(&nt->di, &nt->vi);
 		break;
 	default:
 		break;