Skip to content

Commit fafdd2b

Browse files
UBI: Implement UBI_METAONLY
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> Tested-by: Guido Martínez <guido@vanguardiasur.com.ar> Reviewed-by: Guido Martínez <guido@vanguardiasur.com.ar> Tested-by: Christoph Fritz <chf.fritz@googlemail.com> Tested-by: Andrew Murray <amurray@embedded-bits.co.uk>
1 parent 346be9b commit fafdd2b

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎drivers/mtd/ubi/cdev.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ static int get_exclusive(struct ubi_device *ubi, struct ubi_volume_desc *desc)
6161
struct ubi_volume *vol = desc->vol;
6262

6363
spin_lock(&vol->ubi->volumes_lock);
64-
users = vol->readers + vol->writers + vol->exclusive;
64+
users = vol->readers + vol->writers + vol->exclusive + vol->metaonly;
6565
ubi_assert(users > 0);
6666
if (users > 1) {
6767
ubi_err(ubi, "%d users for volume %d", users, vol->vol_id);
6868
err = -EBUSY;
6969
} else {
70-
vol->readers = vol->writers = 0;
70+
vol->readers = vol->writers = vol->metaonly = 0;
7171
vol->exclusive = 1;
7272
err = desc->mode;
7373
desc->mode = UBI_EXCLUSIVE;
@@ -87,13 +87,15 @@ static void revoke_exclusive(struct ubi_volume_desc *desc, int mode)
8787
struct ubi_volume *vol = desc->vol;
8888

8989
spin_lock(&vol->ubi->volumes_lock);
90-
ubi_assert(vol->readers == 0 && vol->writers == 0);
90+
ubi_assert(vol->readers == 0 && vol->writers == 0 && vol->metaonly == 0);
9191
ubi_assert(vol->exclusive == 1 && desc->mode == UBI_EXCLUSIVE);
9292
vol->exclusive = 0;
9393
if (mode == UBI_READONLY)
9494
vol->readers = 1;
9595
else if (mode == UBI_READWRITE)
9696
vol->writers = 1;
97+
else if (mode == UBI_METAONLY)
98+
vol->metaonly = 1;
9799
else
98100
vol->exclusive = 1;
99101
spin_unlock(&vol->ubi->volumes_lock);

‎drivers/mtd/ubi/kapi.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
137137
return ERR_PTR(-EINVAL);
138138

139139
if (mode != UBI_READONLY && mode != UBI_READWRITE &&
140-
mode != UBI_EXCLUSIVE)
140+
mode != UBI_EXCLUSIVE && mode != UBI_METAONLY)
141141
return ERR_PTR(-EINVAL);
142142

143143
/*
@@ -182,10 +182,17 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
182182
break;
183183

184184
case UBI_EXCLUSIVE:
185-
if (vol->exclusive || vol->writers || vol->readers)
185+
if (vol->exclusive || vol->writers || vol->readers ||
186+
vol->metaonly)
186187
goto out_unlock;
187188
vol->exclusive = 1;
188189
break;
190+
191+
case UBI_METAONLY:
192+
if (vol->metaonly || vol->exclusive)
193+
goto out_unlock;
194+
vol->metaonly = 1;
195+
break;
189196
}
190197
get_device(&vol->dev);
191198
vol->ref_count += 1;
@@ -343,6 +350,10 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
343350
break;
344351
case UBI_EXCLUSIVE:
345352
vol->exclusive = 0;
353+
break;
354+
case UBI_METAONLY:
355+
vol->metaonly = 0;
356+
break;
346357
}
347358
vol->ref_count -= 1;
348359
spin_unlock(&ubi->volumes_lock);

‎drivers/mtd/ubi/ubi.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ struct ubi_fm_pool {
261261
* @readers: number of users holding this volume in read-only mode
262262
* @writers: number of users holding this volume in read-write mode
263263
* @exclusive: whether somebody holds this volume in exclusive mode
264+
* @metaonly: whether somebody is altering only meta data of this volume
264265
*
265266
* @reserved_pebs: how many physical eraseblocks are reserved for this volume
266267
* @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
@@ -309,6 +310,7 @@ struct ubi_volume {
309310
int readers;
310311
int writers;
311312
int exclusive;
313+
int metaonly;
312314

313315
int reserved_pebs;
314316
int vol_type;
@@ -339,7 +341,8 @@ struct ubi_volume {
339341
/**
340342
* struct ubi_volume_desc - UBI volume descriptor returned when it is opened.
341343
* @vol: reference to the corresponding volume description object
342-
* @mode: open mode (%UBI_READONLY, %UBI_READWRITE, or %UBI_EXCLUSIVE)
344+
* @mode: open mode (%UBI_READONLY, %UBI_READWRITE, %UBI_EXCLUSIVE
345+
* or %UBI_METAONLY)
343346
*/
344347
struct ubi_volume_desc {
345348
struct ubi_volume *vol;
@@ -390,7 +393,8 @@ struct ubi_debug_info {
390393
* @volumes_lock: protects @volumes, @rsvd_pebs, @avail_pebs, beb_rsvd_pebs,
391394
* @beb_rsvd_level, @bad_peb_count, @good_peb_count, @vol_count,
392395
* @vol->readers, @vol->writers, @vol->exclusive,
393-
* @vol->ref_count, @vol->mapping and @vol->eba_tbl.
396+
* @vol->metaonly, @vol->ref_count, @vol->mapping and
397+
* @vol->eba_tbl.
394398
* @ref_count: count of references on the UBI device
395399
* @image_seq: image sequence number recorded on EC headers
396400
*

‎include/linux/mtd/ubi.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@
3434
* UBI_READONLY: read-only mode
3535
* UBI_READWRITE: read-write mode
3636
* UBI_EXCLUSIVE: exclusive mode
37+
* UBI_METAONLY: modify only the volume meta-data,
38+
* i.e. the data stored in the volume table, but not in any of volume LEBs.
3739
*/
3840
enum {
3941
UBI_READONLY = 1,
4042
UBI_READWRITE,
41-
UBI_EXCLUSIVE
43+
UBI_EXCLUSIVE,
44+
UBI_METAONLY
4245
};
4346

4447
/**

0 commit comments

Comments
 (0)