Commit 18d1d7fb authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBIFS: introduce mounting flag

This is a preparational patch which removes the 'c->always_chk_crc' which was
set during mounting and remounting to R/W mode and introduces 'c->mounting'
flag which is set when mounting. Now the 'c->always_chk_crc' flag is the
same as 'c->remounting_rw && c->mounting'.

This patch is a preparation for the next one which will need to know when we
are mounting and remounting to R/W mode, which is exactly what
'c->always_chk_crc' effectively is, but its name does not suite the
next patch. The other possibility would be to just re-name it, but then
we'd end up with less logical flags coverage.
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent d8cdda3e
...@@ -88,8 +88,12 @@ void ubifs_ro_mode(struct ubifs_info *c, int err) ...@@ -88,8 +88,12 @@ void ubifs_ro_mode(struct ubifs_info *c, int err)
* This function may skip data nodes CRC checking if @c->no_chk_data_crc is * This function may skip data nodes CRC checking if @c->no_chk_data_crc is
* true, which is controlled by corresponding UBIFS mount option. However, if * true, which is controlled by corresponding UBIFS mount option. However, if
* @must_chk_crc is true, then @c->no_chk_data_crc is ignored and CRC is * @must_chk_crc is true, then @c->no_chk_data_crc is ignored and CRC is
* checked. Similarly, if @c->always_chk_crc is true, @c->no_chk_data_crc is * checked. Similarly, if @c->mounting or @c->remounting_rw is true (we are
* ignored and CRC is checked. * mounting or re-mounting to R/W mode), @c->no_chk_data_crc is ignored and CRC
* is checked. This is because during mounting or re-mounting from R/O mode to
* R/W mode we may read journal nodes (when replying the journal or doing the
* recovery) and the journal nodes may potentially be corrupted, so checking is
* required.
* *
* This function returns zero in case of success and %-EUCLEAN in case of bad * This function returns zero in case of success and %-EUCLEAN in case of bad
* CRC or magic. * CRC or magic.
...@@ -131,8 +135,8 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum, ...@@ -131,8 +135,8 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
node_len > c->ranges[type].max_len) node_len > c->ranges[type].max_len)
goto out_len; goto out_len;
if (!must_chk_crc && type == UBIFS_DATA_NODE && !c->always_chk_crc && if (!must_chk_crc && type == UBIFS_DATA_NODE && !c->mounting &&
c->no_chk_data_crc) !c->remounting_rw && c->no_chk_data_crc)
return 0; return 0;
crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8);
......
...@@ -1194,11 +1194,7 @@ static int mount_ubifs(struct ubifs_info *c) ...@@ -1194,11 +1194,7 @@ static int mount_ubifs(struct ubifs_info *c)
if (c->bulk_read == 1) if (c->bulk_read == 1)
bu_init(c); bu_init(c);
/* c->mounting = 1;
* We have to check all CRCs, even for data nodes, when we mount the FS
* (specifically, when we are replaying).
*/
c->always_chk_crc = 1;
err = ubifs_read_superblock(c); err = ubifs_read_superblock(c);
if (err) if (err)
...@@ -1374,7 +1370,7 @@ static int mount_ubifs(struct ubifs_info *c) ...@@ -1374,7 +1370,7 @@ static int mount_ubifs(struct ubifs_info *c)
if (err) if (err)
goto out_infos; goto out_infos;
c->always_chk_crc = 0; c->mounting = 0;
ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"", ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"",
c->vi.ubi_num, c->vi.vol_id, c->vi.name); c->vi.ubi_num, c->vi.vol_id, c->vi.name);
...@@ -1535,7 +1531,6 @@ static int ubifs_remount_rw(struct ubifs_info *c) ...@@ -1535,7 +1531,6 @@ static int ubifs_remount_rw(struct ubifs_info *c)
mutex_lock(&c->umount_mutex); mutex_lock(&c->umount_mutex);
dbg_save_space_info(c); dbg_save_space_info(c);
c->remounting_rw = 1; c->remounting_rw = 1;
c->always_chk_crc = 1;
err = check_free_space(c); err = check_free_space(c);
if (err) if (err)
...@@ -1642,7 +1637,6 @@ static int ubifs_remount_rw(struct ubifs_info *c) ...@@ -1642,7 +1637,6 @@ static int ubifs_remount_rw(struct ubifs_info *c)
dbg_gen("re-mounted read-write"); dbg_gen("re-mounted read-write");
c->ro_mount = 0; c->ro_mount = 0;
c->remounting_rw = 0; c->remounting_rw = 0;
c->always_chk_crc = 0;
err = dbg_check_space_info(c); err = dbg_check_space_info(c);
mutex_unlock(&c->umount_mutex); mutex_unlock(&c->umount_mutex);
return err; return err;
...@@ -1659,7 +1653,6 @@ static int ubifs_remount_rw(struct ubifs_info *c) ...@@ -1659,7 +1653,6 @@ static int ubifs_remount_rw(struct ubifs_info *c)
c->ileb_buf = NULL; c->ileb_buf = NULL;
ubifs_lpt_free(c, 1); ubifs_lpt_free(c, 1);
c->remounting_rw = 0; c->remounting_rw = 0;
c->always_chk_crc = 0;
mutex_unlock(&c->umount_mutex); mutex_unlock(&c->umount_mutex);
return err; return err;
} }
......
...@@ -447,8 +447,11 @@ static int tnc_read_node_nm(struct ubifs_info *c, struct ubifs_zbranch *zbr, ...@@ -447,8 +447,11 @@ static int tnc_read_node_nm(struct ubifs_info *c, struct ubifs_zbranch *zbr,
* *
* Note, this function does not check CRC of data nodes if @c->no_chk_data_crc * Note, this function does not check CRC of data nodes if @c->no_chk_data_crc
* is true (it is controlled by corresponding mount option). However, if * is true (it is controlled by corresponding mount option). However, if
* @c->always_chk_crc is true, @c->no_chk_data_crc is ignored and CRC is always * @c->mounting or @c->remounting_rw is true (we are mounting or re-mounting to
* checked. * R/W mode), @c->no_chk_data_crc is ignored and CRC is checked. This is
* because during mounting or re-mounting from R/O mode to R/W mode we may read
* journal nodes (when replying the journal or doing the recovery) and the
* journal nodes may potentially be corrupted, so checking is required.
*/ */
static int try_read_node(const struct ubifs_info *c, void *buf, int type, static int try_read_node(const struct ubifs_info *c, void *buf, int type,
int len, int lnum, int offs) int len, int lnum, int offs)
...@@ -476,7 +479,8 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type, ...@@ -476,7 +479,8 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type,
if (node_len != len) if (node_len != len)
return 0; return 0;
if (type == UBIFS_DATA_NODE && !c->always_chk_crc && c->no_chk_data_crc) if (type == UBIFS_DATA_NODE && c->no_chk_data_crc && !c->mounting &&
!c->remounting_rw)
return 1; return 1;
crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8); crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8);
......
...@@ -1169,9 +1169,8 @@ struct ubifs_debug_info; ...@@ -1169,9 +1169,8 @@ struct ubifs_debug_info;
* @empty: %1 if the UBI device is empty * @empty: %1 if the UBI device is empty
* @need_recovery: %1 if the file-system needs recovery * @need_recovery: %1 if the file-system needs recovery
* @replaying: %1 during journal replay * @replaying: %1 during journal replay
* @mounting: %1 while mounting
* @remounting_rw: %1 while re-mounting from R/O mode to R/W mode * @remounting_rw: %1 while re-mounting from R/O mode to R/W mode
* @always_chk_crc: always check CRCs (while mounting and remounting to R/W
* mode)
* @replay_tree: temporary tree used during journal replay * @replay_tree: temporary tree used during journal replay
* @replay_list: temporary list used during journal replay * @replay_list: temporary list used during journal replay
* @replay_buds: list of buds to replay * @replay_buds: list of buds to replay
...@@ -1405,8 +1404,8 @@ struct ubifs_info { ...@@ -1405,8 +1404,8 @@ struct ubifs_info {
unsigned int empty:1; unsigned int empty:1;
unsigned int need_recovery:1; unsigned int need_recovery:1;
unsigned int replaying:1; unsigned int replaying:1;
unsigned int mounting:1;
unsigned int remounting_rw:1; unsigned int remounting_rw:1;
unsigned int always_chk_crc:1;
struct rb_root replay_tree; struct rb_root replay_tree;
struct list_head replay_list; struct list_head replay_list;
struct list_head replay_buds; struct list_head replay_buds;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment