linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] UBI: Implement UBI_METAONLY
@ 2014-11-24 21:30 Richard Weinberger
  2014-11-24 21:30 ` [PATCH 2/2] UBI: rename_volumes: Use UBI_METAONLY Richard Weinberger
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Weinberger @ 2014-11-24 21:30 UTC (permalink / raw)
  To: dedekind1
  Cc: linux-mtd, linux-kernel, Richard Weinberger, Ezequiel Garcia,
	Andrew Murray

UBI_METAONLY is a new open mode for UBI volumes, it indicates
that only meta data is being changed.
Meta data in terms of UBI volumes means data which is stored in the
UBI volume table but not on the volume itself.
While it does not interfere with UBI_READONLY and UBI_READWRITE
it is not allowed to use UBI_METAONLY together with UBI_EXCLUSIVE.

Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Cc: Andrew Murray <amurray@embedded-bits.co.uk>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/cdev.c  |  8 +++++---
 drivers/mtd/ubi/kapi.c  | 15 +++++++++++++--
 drivers/mtd/ubi/ubi.h   |  8 ++++++--
 include/linux/mtd/ubi.h |  5 ++++-
 4 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 3410ea81..f5c715c 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -61,13 +61,13 @@ static int get_exclusive(struct ubi_device *ubi, struct ubi_volume_desc *desc)
 	struct ubi_volume *vol = desc->vol;
 
 	spin_lock(&vol->ubi->volumes_lock);
-	users = vol->readers + vol->writers + vol->exclusive;
+	users = vol->readers + vol->writers + vol->exclusive + vol->metaonly;
 	ubi_assert(users > 0);
 	if (users > 1) {
 		ubi_err(ubi, "%d users for volume %d", users, vol->vol_id);
 		err = -EBUSY;
 	} else {
-		vol->readers = vol->writers = 0;
+		vol->readers = vol->writers = vol->metaonly = 0;
 		vol->exclusive = 1;
 		err = desc->mode;
 		desc->mode = UBI_EXCLUSIVE;
@@ -87,13 +87,15 @@ static void revoke_exclusive(struct ubi_volume_desc *desc, int mode)
 	struct ubi_volume *vol = desc->vol;
 
 	spin_lock(&vol->ubi->volumes_lock);
-	ubi_assert(vol->readers == 0 && vol->writers == 0);
+	ubi_assert(vol->readers == 0 && vol->writers == 0 && vol->metaonly == 0);
 	ubi_assert(vol->exclusive == 1 && desc->mode == UBI_EXCLUSIVE);
 	vol->exclusive = 0;
 	if (mode == UBI_READONLY)
 		vol->readers = 1;
 	else if (mode == UBI_READWRITE)
 		vol->writers = 1;
+	else if (mode == UBI_METAONLY)
+		vol->metaonly = 1;
 	else
 		vol->exclusive = 1;
 	spin_unlock(&vol->ubi->volumes_lock);
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index f3bab66..589c423 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -137,7 +137,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
 		return ERR_PTR(-EINVAL);
 
 	if (mode != UBI_READONLY && mode != UBI_READWRITE &&
-	    mode != UBI_EXCLUSIVE)
+	    mode != UBI_EXCLUSIVE && mode != UBI_METAONLY)
 		return ERR_PTR(-EINVAL);
 
 	/*
@@ -182,10 +182,17 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
 		break;
 
 	case UBI_EXCLUSIVE:
-		if (vol->exclusive || vol->writers || vol->readers)
+		if (vol->exclusive || vol->writers || vol->readers ||
+		    vol->metaonly)
 			goto out_unlock;
 		vol->exclusive = 1;
 		break;
+
+	case UBI_METAONLY:
+		if (vol->metaonly || vol->exclusive)
+			goto out_unlock;
+		vol->metaonly = 1;
+		break;
 	}
 	get_device(&vol->dev);
 	vol->ref_count += 1;
@@ -343,6 +350,10 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
 		break;
 	case UBI_EXCLUSIVE:
 		vol->exclusive = 0;
+		break;
+	case UBI_METAONLY:
+		vol->metaonly = 0;
+		break;
 	}
 	vol->ref_count -= 1;
 	spin_unlock(&ubi->volumes_lock);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index f80ffab..20cabc0 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -261,6 +261,7 @@ struct ubi_fm_pool {
  * @readers: number of users holding this volume in read-only mode
  * @writers: number of users holding this volume in read-write mode
  * @exclusive: whether somebody holds this volume in exclusive mode
+ * @metaonly: whether somebody is altering only meta data of this volume
  *
  * @reserved_pebs: how many physical eraseblocks are reserved for this volume
  * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
@@ -309,6 +310,7 @@ struct ubi_volume {
 	int readers;
 	int writers;
 	int exclusive;
+	int metaonly;
 
 	int reserved_pebs;
 	int vol_type;
@@ -339,7 +341,8 @@ struct ubi_volume {
 /**
  * struct ubi_volume_desc - UBI volume descriptor returned when it is opened.
  * @vol: reference to the corresponding volume description object
- * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE)
+ * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, %UBI_EXCLUSIVE
+ * or %UBI_METAONLY)
  */
 struct ubi_volume_desc {
 	struct ubi_volume *vol;
@@ -390,7 +393,8 @@ struct ubi_debug_info {
  * @volumes_lock: protects @volumes, @rsvd_pebs, @avail_pebs, beb_rsvd_pebs,
  *                @beb_rsvd_level, @bad_peb_count, @good_peb_count, @vol_count,
  *                @vol->readers, @vol->writers, @vol->exclusive,
- *                @vol->ref_count, @vol->mapping and @vol->eba_tbl.
+ *                @vol->metaonly, @vol->ref_count, @vol->mapping and
+ *                @vol->eba_tbl.
  * @ref_count: count of references on the UBI device
  * @image_seq: image sequence number recorded on EC headers
  *
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index c3918a0..8fa2753 100644
--- a/include/linux/mtd/ubi.h
+++ b/include/linux/mtd/ubi.h
@@ -34,11 +34,14 @@
  * UBI_READONLY: read-only mode
  * UBI_READWRITE: read-write mode
  * UBI_EXCLUSIVE: exclusive mode
+ * UBI_METAONLY: modify only the volume meta-data,
+ *  i.e. the data stored in the volume table, but not in any of volume LEBs.
  */
 enum {
 	UBI_READONLY = 1,
 	UBI_READWRITE,
-	UBI_EXCLUSIVE
+	UBI_EXCLUSIVE,
+	UBI_METAONLY
 };
 
 /**
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] UBI: rename_volumes: Use UBI_METAONLY
  2014-11-24 21:30 [PATCH 1/2] UBI: Implement UBI_METAONLY Richard Weinberger
@ 2014-11-24 21:30 ` Richard Weinberger
  2014-12-17 17:49   ` Guido Martínez
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Weinberger @ 2014-11-24 21:30 UTC (permalink / raw)
  To: dedekind1
  Cc: linux-mtd, linux-kernel, Richard Weinberger, Ezequiel Garcia,
	Andrew Murray

By using UBI_METAONLY in rename_volumes() it is now possible to rename
an UBI volume atomically while it is mounted.
This is useful for firmware upgrades.

Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Cc: Andrew Murray <amurray@embedded-bits.co.uk>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/cdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index f5c715c..286383c 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -736,7 +736,7 @@ static int rename_volumes(struct ubi_device *ubi,
 			goto out_free;
 		}
 
-		re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_READWRITE);
+		re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_METAONLY);
 		if (IS_ERR(re->desc)) {
 			err = PTR_ERR(re->desc);
 			ubi_err(ubi, "cannot open volume %d, error %d",
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] UBI: rename_volumes: Use UBI_METAONLY
  2014-11-24 21:30 ` [PATCH 2/2] UBI: rename_volumes: Use UBI_METAONLY Richard Weinberger
@ 2014-12-17 17:49   ` Guido Martínez
  2015-01-20 19:50     ` Christoph Fritz
  0 siblings, 1 reply; 10+ messages in thread
From: Guido Martínez @ 2014-12-17 17:49 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: dedekind1, linux-mtd, linux-kernel, Ezequiel Garcia, Andrew Murray

On Mon, Nov 24, 2014 at 10:30:10PM +0100, Richard Weinberger wrote:
> By using UBI_METAONLY in rename_volumes() it is now possible to rename
> an UBI volume atomically while it is mounted.
> This is useful for firmware upgrades.
Minor nitpick: should this say 'while it is open for writing' or 'an
UBIFS volume'? Renaming volumes opened for read-only (with ubiblock on
top for example) was already supported.

Regardless:

Tested name swapping mounted UBIFS volumes and read-only ubiblocks, as
well as UBI volumes opened for writing (not updating).

(for both patches)
Tested-by: Guido Martínez <guido@vanguardiasur.com.ar>
Reviewed-by: Guido Martínez <guido@vanguardiasur.com.ar>

I'm not sure if we could now make the handler for UBI_IOCVOLUP take
read-write access instead of exclusive, but that's material for another
patch. Also I can't really think of a use case for that...


> Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> Cc: Andrew Murray <amurray@embedded-bits.co.uk>
> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
>  drivers/mtd/ubi/cdev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
> index f5c715c..286383c 100644
> --- a/drivers/mtd/ubi/cdev.c
> +++ b/drivers/mtd/ubi/cdev.c
> @@ -736,7 +736,7 @@ static int rename_volumes(struct ubi_device *ubi,
>  			goto out_free;
>  		}
>  
> -		re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_READWRITE);
> +		re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_METAONLY);
>  		if (IS_ERR(re->desc)) {
>  			err = PTR_ERR(re->desc);
>  			ubi_err(ubi, "cannot open volume %d, error %d",
> -- 
> 1.8.4.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Guido Martínez, VanguardiaSur
www.vanguardiasur.com.ar

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] UBI: rename_volumes: Use UBI_METAONLY
  2014-12-17 17:49   ` Guido Martínez
@ 2015-01-20 19:50     ` Christoph Fritz
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Fritz @ 2015-01-20 19:50 UTC (permalink / raw)
  To: Guido Martínez, Richard Weinberger
  Cc: dedekind1, linux-mtd, linux-kernel, Ezequiel Garcia,
	Andrew Murray, Artem Bityutskiy

On Wed, 2014-12-17 at 14:49 -0300, Guido Martínez wrote:
> 
> (for both patches)
> Tested-by: Guido Martínez <guido@vanguardiasur.com.ar>

here too,
Tested-by: Christoph Fritz <chf.fritz@googlemail.com>

By the way, when will this patch get merged?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] UBI: Implement UBI_METAONLY
  2014-11-07 12:42     ` Andrew Murray
@ 2014-11-24 21:32       ` Richard Weinberger
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Weinberger @ 2014-11-24 21:32 UTC (permalink / raw)
  To: Andrew Murray; +Cc: Artem Bityutskiy, linux-mtd, LKML, Ezequiel Garcia

Am 07.11.2014 um 13:42 schrieb Andrew Murray:
>> Please send a patch for that. :)
> 
> Apologies for the delay - did you just want junk a hunk so you can
> include in your next revision - or did you want me to come up with a
> v2 of your patch?

I have to say sorry, your mail got lost in my inbox. :-(
The change in ubi.h is trivial, I've added it directly to my patch.
If you want you can send a patch for gluebi.c.

Thanks,
//richard

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] UBI: Implement UBI_METAONLY
  2014-10-29 20:20   ` Richard Weinberger
@ 2014-11-07 12:42     ` Andrew Murray
  2014-11-24 21:32       ` Richard Weinberger
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Murray @ 2014-11-07 12:42 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Artem Bityutskiy, linux-mtd, LKML, Ezequiel Garcia

On 29 October 2014 20:20, Richard Weinberger <richard@nod.at> wrote:
> Am 29.10.2014 um 21:11 schrieb Andrew Murray:
>> On 29 October 2014 14:52, Richard Weinberger <richard@nod.at> wrote:
>>> diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
>>> index c3918a0..82b693f 100644
>>> --- a/include/linux/mtd/ubi.h
>>> +++ b/include/linux/mtd/ubi.h
>>> @@ -34,11 +34,13 @@
>>>   * UBI_READONLY: read-only mode
>>>   * UBI_READWRITE: read-write mode
>>>   * UBI_EXCLUSIVE: exclusive mode
>>> + * UBI_METAONLY: modify voulme meta data only
>>
>> Typo - s/voulme/volume/g
>
> Thanks. :)
>
>>>   */
>>>  enum {
>>>         UBI_READONLY = 1,
>>>         UBI_READWRITE,
>>> -       UBI_EXCLUSIVE
>>> +       UBI_EXCLUSIVE,
>>> +       UBI_METAONLY
>>>  };
>>>
>>
>> Also you may want to add something similar to this:
>>
>> --- a/drivers/mtd/ubi/ubi.h
>> +++ b/drivers/mtd/ubi/ubi.h
>> @@ -339,7 +339,7 @@ struct ubi_volume {
>>  /**
>>   * struct ubi_volume_desc - UBI volume descriptor returned when it is opened.
>>   * @vol: reference to the corresponding volume description object
>> - * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE)
>> + * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, %UBI_EXCLUSIVE or
>> %UBI_METAONLY)
>>   */
>>  struct ubi_volume_desc {
>>         struct ubi_volume *vol;
>>
>> There is also a similar mention in gluebi.c: 'readers/writes/exclusive'.
>
> Please send a patch for that. :)

Apologies for the delay - did you just want junk a hunk so you can
include in your next revision - or did you want me to come up with a
v2 of your patch?

Andrew Murray

>
> Thanks,
> //richard

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] UBI: Implement UBI_METAONLY
  2014-10-29 14:52 [PATCH 1/2] UBI: Implement UBI_METAONLY Richard Weinberger
  2014-10-29 20:11 ` Andrew Murray
@ 2014-11-07  9:37 ` Artem Bityutskiy
  1 sibling, 0 replies; 10+ messages in thread
From: Artem Bityutskiy @ 2014-11-07  9:37 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, linux-kernel, Ezequiel Garcia, Andrew Murray

On Wed, 2014-10-29 at 15:52 +0100, Richard Weinberger wrote:
> + * UBI_METAONLY: modify voulme meta data only

Can we please have a bit extended comment for this, explaining what
meta-data is? Like

UBI_METAONLY: modify only the volume meta-data, i.e. the data stored in
              the volume table, but not in any of volume LEBs.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] UBI: Implement UBI_METAONLY
  2014-10-29 20:11 ` Andrew Murray
@ 2014-10-29 20:20   ` Richard Weinberger
  2014-11-07 12:42     ` Andrew Murray
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Weinberger @ 2014-10-29 20:20 UTC (permalink / raw)
  To: Andrew Murray; +Cc: Artem Bityutskiy, linux-mtd, LKML, Ezequiel Garcia

Am 29.10.2014 um 21:11 schrieb Andrew Murray:
> On 29 October 2014 14:52, Richard Weinberger <richard@nod.at> wrote:
>> diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
>> index c3918a0..82b693f 100644
>> --- a/include/linux/mtd/ubi.h
>> +++ b/include/linux/mtd/ubi.h
>> @@ -34,11 +34,13 @@
>>   * UBI_READONLY: read-only mode
>>   * UBI_READWRITE: read-write mode
>>   * UBI_EXCLUSIVE: exclusive mode
>> + * UBI_METAONLY: modify voulme meta data only
> 
> Typo - s/voulme/volume/g

Thanks. :)

>>   */
>>  enum {
>>         UBI_READONLY = 1,
>>         UBI_READWRITE,
>> -       UBI_EXCLUSIVE
>> +       UBI_EXCLUSIVE,
>> +       UBI_METAONLY
>>  };
>>
> 
> Also you may want to add something similar to this:
> 
> --- a/drivers/mtd/ubi/ubi.h
> +++ b/drivers/mtd/ubi/ubi.h
> @@ -339,7 +339,7 @@ struct ubi_volume {
>  /**
>   * struct ubi_volume_desc - UBI volume descriptor returned when it is opened.
>   * @vol: reference to the corresponding volume description object
> - * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE)
> + * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, %UBI_EXCLUSIVE or
> %UBI_METAONLY)
>   */
>  struct ubi_volume_desc {
>         struct ubi_volume *vol;
> 
> There is also a similar mention in gluebi.c: 'readers/writes/exclusive'.

Please send a patch for that. :)

Thanks,
//richard

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] UBI: Implement UBI_METAONLY
  2014-10-29 14:52 [PATCH 1/2] UBI: Implement UBI_METAONLY Richard Weinberger
@ 2014-10-29 20:11 ` Andrew Murray
  2014-10-29 20:20   ` Richard Weinberger
  2014-11-07  9:37 ` Artem Bityutskiy
  1 sibling, 1 reply; 10+ messages in thread
From: Andrew Murray @ 2014-10-29 20:11 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Artem Bityutskiy, linux-mtd, LKML, Ezequiel Garcia

On 29 October 2014 14:52, Richard Weinberger <richard@nod.at> wrote:
> diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
> index c3918a0..82b693f 100644
> --- a/include/linux/mtd/ubi.h
> +++ b/include/linux/mtd/ubi.h
> @@ -34,11 +34,13 @@
>   * UBI_READONLY: read-only mode
>   * UBI_READWRITE: read-write mode
>   * UBI_EXCLUSIVE: exclusive mode
> + * UBI_METAONLY: modify voulme meta data only

Typo - s/voulme/volume/g

>   */
>  enum {
>         UBI_READONLY = 1,
>         UBI_READWRITE,
> -       UBI_EXCLUSIVE
> +       UBI_EXCLUSIVE,
> +       UBI_METAONLY
>  };
>

Also you may want to add something similar to this:

--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -339,7 +339,7 @@ struct ubi_volume {
 /**
  * struct ubi_volume_desc - UBI volume descriptor returned when it is opened.
  * @vol: reference to the corresponding volume description object
- * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE)
+ * @mode: open mode (%UBI_READONLY, %UBI_READWRITE, %UBI_EXCLUSIVE or
%UBI_METAONLY)
  */
 struct ubi_volume_desc {
        struct ubi_volume *vol;

There is also a similar mention in gluebi.c: 'readers/writes/exclusive'.

Thanks,

Andrew Murray

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] UBI: Implement UBI_METAONLY
@ 2014-10-29 14:52 Richard Weinberger
  2014-10-29 20:11 ` Andrew Murray
  2014-11-07  9:37 ` Artem Bityutskiy
  0 siblings, 2 replies; 10+ messages in thread
From: Richard Weinberger @ 2014-10-29 14:52 UTC (permalink / raw)
  To: dedekind1
  Cc: linux-mtd, linux-kernel, Richard Weinberger, Ezequiel Garcia,
	Andrew Murray

UBI_METAONLY is a new open mode for UBI volumes, it indicates
that only meta data is being changed.
Meta data in terms of UBI volumes means data which is stored in the
UBI volume table but not on the volume itself.
While it does not interfere with UBI_READONLY and UBI_READWRITE
it is not allowed to use UBI_METAONLY together with UBI_EXCLUSIVE.

Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Cc: Andrew Murray <amurray@embedded-bits.co.uk>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 drivers/mtd/ubi/cdev.c  |  8 +++++---
 drivers/mtd/ubi/kapi.c  | 15 +++++++++++++--
 drivers/mtd/ubi/ubi.h   |  5 ++++-
 include/linux/mtd/ubi.h |  4 +++-
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 59de69a..5f01edd 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -60,13 +60,13 @@ static int get_exclusive(struct ubi_volume_desc *desc)
 	struct ubi_volume *vol = desc->vol;
 
 	spin_lock(&vol->ubi->volumes_lock);
-	users = vol->readers + vol->writers + vol->exclusive;
+	users = vol->readers + vol->writers + vol->exclusive + vol->metaonly;
 	ubi_assert(users > 0);
 	if (users > 1) {
 		ubi_err("%d users for volume %d", users, vol->vol_id);
 		err = -EBUSY;
 	} else {
-		vol->readers = vol->writers = 0;
+		vol->readers = vol->writers = vol->metaonly = 0;
 		vol->exclusive = 1;
 		err = desc->mode;
 		desc->mode = UBI_EXCLUSIVE;
@@ -86,13 +86,15 @@ static void revoke_exclusive(struct ubi_volume_desc *desc, int mode)
 	struct ubi_volume *vol = desc->vol;
 
 	spin_lock(&vol->ubi->volumes_lock);
-	ubi_assert(vol->readers == 0 && vol->writers == 0);
+	ubi_assert(vol->readers == 0 && vol->writers == 0 && vol->metaonly == 0);
 	ubi_assert(vol->exclusive == 1 && desc->mode == UBI_EXCLUSIVE);
 	vol->exclusive = 0;
 	if (mode == UBI_READONLY)
 		vol->readers = 1;
 	else if (mode == UBI_READWRITE)
 		vol->writers = 1;
+	else if (mode == UBI_METAONLY)
+		vol->metaonly = 1;
 	else
 		vol->exclusive = 1;
 	spin_unlock(&vol->ubi->volumes_lock);
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 3aac1ac..8599690 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -137,7 +137,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
 		return ERR_PTR(-EINVAL);
 
 	if (mode != UBI_READONLY && mode != UBI_READWRITE &&
-	    mode != UBI_EXCLUSIVE)
+	    mode != UBI_EXCLUSIVE && mode != UBI_METAONLY)
 		return ERR_PTR(-EINVAL);
 
 	/*
@@ -182,10 +182,17 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
 		break;
 
 	case UBI_EXCLUSIVE:
-		if (vol->exclusive || vol->writers || vol->readers)
+		if (vol->exclusive || vol->writers || vol->readers ||
+		    vol->metaonly)
 			goto out_unlock;
 		vol->exclusive = 1;
 		break;
+
+	case UBI_METAONLY:
+		if (vol->metaonly || vol->exclusive)
+			goto out_unlock;
+		vol->metaonly = 1;
+		break;
 	}
 	get_device(&vol->dev);
 	vol->ref_count += 1;
@@ -343,6 +350,10 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
 		break;
 	case UBI_EXCLUSIVE:
 		vol->exclusive = 0;
+		break;
+	case UBI_METAONLY:
+		vol->metaonly = 0;
+		break;
 	}
 	vol->ref_count -= 1;
 	spin_unlock(&ubi->volumes_lock);
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 320fc38..c991a09 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -260,6 +260,7 @@ struct ubi_fm_pool {
  * @readers: number of users holding this volume in read-only mode
  * @writers: number of users holding this volume in read-write mode
  * @exclusive: whether somebody holds this volume in exclusive mode
+ * @metaonly: whether somebody is altering only meta data of this volume
  *
  * @reserved_pebs: how many physical eraseblocks are reserved for this volume
  * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
@@ -308,6 +309,7 @@ struct ubi_volume {
 	int readers;
 	int writers;
 	int exclusive;
+	int metaonly;
 
 	int reserved_pebs;
 	int vol_type;
@@ -389,7 +391,8 @@ struct ubi_debug_info {
  * @volumes_lock: protects @volumes, @rsvd_pebs, @avail_pebs, beb_rsvd_pebs,
  *                @beb_rsvd_level, @bad_peb_count, @good_peb_count, @vol_count,
  *                @vol->readers, @vol->writers, @vol->exclusive,
- *                @vol->ref_count, @vol->mapping and @vol->eba_tbl.
+ *                @vol->metaonly, @vol->ref_count, @vol->mapping and
+ *                @vol->eba_tbl.
  * @ref_count: count of references on the UBI device
  * @image_seq: image sequence number recorded on EC headers
  *
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index c3918a0..82b693f 100644
--- a/include/linux/mtd/ubi.h
+++ b/include/linux/mtd/ubi.h
@@ -34,11 +34,13 @@
  * UBI_READONLY: read-only mode
  * UBI_READWRITE: read-write mode
  * UBI_EXCLUSIVE: exclusive mode
+ * UBI_METAONLY: modify voulme meta data only
  */
 enum {
 	UBI_READONLY = 1,
 	UBI_READWRITE,
-	UBI_EXCLUSIVE
+	UBI_EXCLUSIVE,
+	UBI_METAONLY
 };
 
 /**
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-01-20 19:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-24 21:30 [PATCH 1/2] UBI: Implement UBI_METAONLY Richard Weinberger
2014-11-24 21:30 ` [PATCH 2/2] UBI: rename_volumes: Use UBI_METAONLY Richard Weinberger
2014-12-17 17:49   ` Guido Martínez
2015-01-20 19:50     ` Christoph Fritz
  -- strict thread matches above, loose matches on Subject: below --
2014-10-29 14:52 [PATCH 1/2] UBI: Implement UBI_METAONLY Richard Weinberger
2014-10-29 20:11 ` Andrew Murray
2014-10-29 20:20   ` Richard Weinberger
2014-11-07 12:42     ` Andrew Murray
2014-11-24 21:32       ` Richard Weinberger
2014-11-07  9:37 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).