UBI: simplify internal interfaces
Instead of passing vol_id to all functions and then find struct ubi_volume, pass struct ubi_volume pointer. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
This commit is contained in:
parent
0411e73531
commit
1b68d0eea5
|
@ -354,7 +354,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
|
||||||
if (!vol->updating)
|
if (!vol->updating)
|
||||||
return vol_cdev_direct_write(file, buf, count, offp);
|
return vol_cdev_direct_write(file, buf, count, offp);
|
||||||
|
|
||||||
err = ubi_more_update_data(ubi, vol->vol_id, buf, count);
|
err = ubi_more_update_data(ubi, vol, buf, count);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
ubi_err("cannot write %zd bytes of update data, error %d",
|
ubi_err("cannot write %zd bytes of update data, error %d",
|
||||||
count, err);
|
count, err);
|
||||||
|
@ -427,7 +427,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
err = ubi_start_update(ubi, vol->vol_id, bytes);
|
err = ubi_start_update(ubi, vol, bytes);
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
revoke_exclusive(desc, UBI_READWRITE);
|
revoke_exclusive(desc, UBI_READWRITE);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -423,8 +423,9 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol);
|
||||||
void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol);
|
void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol);
|
||||||
|
|
||||||
/* upd.c */
|
/* upd.c */
|
||||||
int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes);
|
int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
|
||||||
int ubi_more_update_data(struct ubi_device *ubi, int vol_id,
|
long long bytes);
|
||||||
|
int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
|
||||||
const void __user *buf, int count);
|
const void __user *buf, int count);
|
||||||
|
|
||||||
/* misc.c */
|
/* misc.c */
|
||||||
|
|
|
@ -45,30 +45,30 @@
|
||||||
/**
|
/**
|
||||||
* set_update_marker - set update marker.
|
* set_update_marker - set update marker.
|
||||||
* @ubi: UBI device description object
|
* @ubi: UBI device description object
|
||||||
* @vol_id: volume ID
|
* @vol: volume description object
|
||||||
*
|
*
|
||||||
* This function sets the update marker flag for volume @vol_id. Returns zero
|
* This function sets the update marker flag for volume @vol. Returns zero
|
||||||
* in case of success and a negative error code in case of failure.
|
* in case of success and a negative error code in case of failure.
|
||||||
*/
|
*/
|
||||||
static int set_update_marker(struct ubi_device *ubi, int vol_id)
|
static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct ubi_vtbl_record vtbl_rec;
|
struct ubi_vtbl_record vtbl_rec;
|
||||||
struct ubi_volume *vol = ubi->volumes[vol_id];
|
|
||||||
|
|
||||||
dbg_msg("set update marker for volume %d", vol_id);
|
dbg_msg("set update marker for volume %d", vol->vol_id);
|
||||||
|
|
||||||
if (vol->upd_marker) {
|
if (vol->upd_marker) {
|
||||||
ubi_assert(ubi->vtbl[vol_id].upd_marker);
|
ubi_assert(ubi->vtbl[vol->vol_id].upd_marker);
|
||||||
dbg_msg("already set");
|
dbg_msg("already set");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record));
|
memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id],
|
||||||
|
sizeof(struct ubi_vtbl_record));
|
||||||
vtbl_rec.upd_marker = 1;
|
vtbl_rec.upd_marker = 1;
|
||||||
|
|
||||||
mutex_lock(&ubi->volumes_mutex);
|
mutex_lock(&ubi->volumes_mutex);
|
||||||
err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
|
err = ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec);
|
||||||
mutex_unlock(&ubi->volumes_mutex);
|
mutex_unlock(&ubi->volumes_mutex);
|
||||||
vol->upd_marker = 1;
|
vol->upd_marker = 1;
|
||||||
return err;
|
return err;
|
||||||
|
@ -77,23 +77,24 @@ static int set_update_marker(struct ubi_device *ubi, int vol_id)
|
||||||
/**
|
/**
|
||||||
* clear_update_marker - clear update marker.
|
* clear_update_marker - clear update marker.
|
||||||
* @ubi: UBI device description object
|
* @ubi: UBI device description object
|
||||||
* @vol_id: volume ID
|
* @vol: volume description object
|
||||||
* @bytes: new data size in bytes
|
* @bytes: new data size in bytes
|
||||||
*
|
*
|
||||||
* This function clears the update marker for volume @vol_id, sets new volume
|
* This function clears the update marker for volume @vol, sets new volume
|
||||||
* data size and clears the "corrupted" flag (static volumes only). Returns
|
* data size and clears the "corrupted" flag (static volumes only). Returns
|
||||||
* zero in case of success and a negative error code in case of failure.
|
* zero in case of success and a negative error code in case of failure.
|
||||||
*/
|
*/
|
||||||
static int clear_update_marker(struct ubi_device *ubi, int vol_id, long long bytes)
|
static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol,
|
||||||
|
long long bytes)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
uint64_t tmp;
|
uint64_t tmp;
|
||||||
struct ubi_vtbl_record vtbl_rec;
|
struct ubi_vtbl_record vtbl_rec;
|
||||||
struct ubi_volume *vol = ubi->volumes[vol_id];
|
|
||||||
|
|
||||||
dbg_msg("clear update marker for volume %d", vol_id);
|
dbg_msg("clear update marker for volume %d", vol->vol_id);
|
||||||
|
|
||||||
memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record));
|
memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id],
|
||||||
|
sizeof(struct ubi_vtbl_record));
|
||||||
ubi_assert(vol->upd_marker && vtbl_rec.upd_marker);
|
ubi_assert(vol->upd_marker && vtbl_rec.upd_marker);
|
||||||
vtbl_rec.upd_marker = 0;
|
vtbl_rec.upd_marker = 0;
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ static int clear_update_marker(struct ubi_device *ubi, int vol_id, long long byt
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&ubi->volumes_mutex);
|
mutex_lock(&ubi->volumes_mutex);
|
||||||
err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
|
err = ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec);
|
||||||
mutex_unlock(&ubi->volumes_mutex);
|
mutex_unlock(&ubi->volumes_mutex);
|
||||||
vol->upd_marker = 0;
|
vol->upd_marker = 0;
|
||||||
return err;
|
return err;
|
||||||
|
@ -118,23 +119,23 @@ static int clear_update_marker(struct ubi_device *ubi, int vol_id, long long byt
|
||||||
/**
|
/**
|
||||||
* ubi_start_update - start volume update.
|
* ubi_start_update - start volume update.
|
||||||
* @ubi: UBI device description object
|
* @ubi: UBI device description object
|
||||||
* @vol_id: volume ID
|
* @vol: volume description object
|
||||||
* @bytes: update bytes
|
* @bytes: update bytes
|
||||||
*
|
*
|
||||||
* This function starts volume update operation. If @bytes is zero, the volume
|
* This function starts volume update operation. If @bytes is zero, the volume
|
||||||
* is just wiped out. Returns zero in case of success and a negative error code
|
* is just wiped out. Returns zero in case of success and a negative error code
|
||||||
* in case of failure.
|
* in case of failure.
|
||||||
*/
|
*/
|
||||||
int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes)
|
int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
|
||||||
|
long long bytes)
|
||||||
{
|
{
|
||||||
int i, err;
|
int i, err;
|
||||||
uint64_t tmp;
|
uint64_t tmp;
|
||||||
struct ubi_volume *vol = ubi->volumes[vol_id];
|
|
||||||
|
|
||||||
dbg_msg("start update of volume %d, %llu bytes", vol_id, bytes);
|
dbg_msg("start update of volume %d, %llu bytes", vol->vol_id, bytes);
|
||||||
vol->updating = 1;
|
vol->updating = 1;
|
||||||
|
|
||||||
err = set_update_marker(ubi, vol_id);
|
err = set_update_marker(ubi, vol);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -146,7 +147,7 @@ int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes == 0) {
|
if (bytes == 0) {
|
||||||
err = clear_update_marker(ubi, vol_id, 0);
|
err = clear_update_marker(ubi, vol, 0);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
err = ubi_wl_flush(ubi);
|
err = ubi_wl_flush(ubi);
|
||||||
|
@ -169,7 +170,7 @@ int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes)
|
||||||
/**
|
/**
|
||||||
* write_leb - write update data.
|
* write_leb - write update data.
|
||||||
* @ubi: UBI device description object
|
* @ubi: UBI device description object
|
||||||
* @vol_id: volume ID
|
* @vol: volume description object
|
||||||
* @lnum: logical eraseblock number
|
* @lnum: logical eraseblock number
|
||||||
* @buf: data to write
|
* @buf: data to write
|
||||||
* @len: data size
|
* @len: data size
|
||||||
|
@ -195,11 +196,10 @@ int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes)
|
||||||
* This function returns zero in case of success and a negative error code in
|
* This function returns zero in case of success and a negative error code in
|
||||||
* case of failure.
|
* case of failure.
|
||||||
*/
|
*/
|
||||||
static int write_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf,
|
static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
|
||||||
int len, int used_ebs)
|
void *buf, int len, int used_ebs)
|
||||||
{
|
{
|
||||||
int err, l;
|
int err, l;
|
||||||
struct ubi_volume *vol = ubi->volumes[vol_id];
|
|
||||||
|
|
||||||
if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
|
if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
|
||||||
l = ALIGN(len, ubi->min_io_size);
|
l = ALIGN(len, ubi->min_io_size);
|
||||||
|
@ -244,11 +244,10 @@ static int write_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf,
|
||||||
* the last call if the whole volume update was successfully finished, and a
|
* the last call if the whole volume update was successfully finished, and a
|
||||||
* negative error code in case of failure.
|
* negative error code in case of failure.
|
||||||
*/
|
*/
|
||||||
int ubi_more_update_data(struct ubi_device *ubi, int vol_id,
|
int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
|
||||||
const void __user *buf, int count)
|
const void __user *buf, int count)
|
||||||
{
|
{
|
||||||
uint64_t tmp;
|
uint64_t tmp;
|
||||||
struct ubi_volume *vol = ubi->volumes[vol_id];
|
|
||||||
int lnum, offs, err = 0, len, to_write = count;
|
int lnum, offs, err = 0, len, to_write = count;
|
||||||
|
|
||||||
dbg_msg("write %d of %lld bytes, %lld already passed",
|
dbg_msg("write %d of %lld bytes, %lld already passed",
|
||||||
|
@ -293,8 +292,8 @@ int ubi_more_update_data(struct ubi_device *ubi, int vol_id,
|
||||||
* is the last chunk, it's time to flush the buffer.
|
* is the last chunk, it's time to flush the buffer.
|
||||||
*/
|
*/
|
||||||
ubi_assert(flush_len <= vol->usable_leb_size);
|
ubi_assert(flush_len <= vol->usable_leb_size);
|
||||||
err = write_leb(ubi, vol_id, lnum, vol->upd_buf,
|
err = write_leb(ubi, vol, lnum, vol->upd_buf, flush_len,
|
||||||
flush_len, vol->upd_ebs);
|
vol->upd_ebs);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -321,8 +320,8 @@ int ubi_more_update_data(struct ubi_device *ubi, int vol_id,
|
||||||
|
|
||||||
if (len == vol->usable_leb_size ||
|
if (len == vol->usable_leb_size ||
|
||||||
vol->upd_received + len == vol->upd_bytes) {
|
vol->upd_received + len == vol->upd_bytes) {
|
||||||
err = write_leb(ubi, vol_id, lnum, vol->upd_buf, len,
|
err = write_leb(ubi, vol, lnum, vol->upd_buf,
|
||||||
vol->upd_ebs);
|
len, vol->upd_ebs);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -336,7 +335,7 @@ int ubi_more_update_data(struct ubi_device *ubi, int vol_id,
|
||||||
ubi_assert(vol->upd_received <= vol->upd_bytes);
|
ubi_assert(vol->upd_received <= vol->upd_bytes);
|
||||||
if (vol->upd_received == vol->upd_bytes) {
|
if (vol->upd_received == vol->upd_bytes) {
|
||||||
/* The update is finished, clear the update marker */
|
/* The update is finished, clear the update marker */
|
||||||
err = clear_update_marker(ubi, vol_id, vol->upd_bytes);
|
err = clear_update_marker(ubi, vol, vol->upd_bytes);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
err = ubi_wl_flush(ubi);
|
err = ubi_wl_flush(ubi);
|
||||||
|
|
Loading…
Reference in New Issue