https://github.com/torvalds/linux
Revision 6e0d9fd38b750d678bf9fd07db23582f52fafa55 authored by Artem Bityutskiy on 21 April 2011, 11:49:55 UTC, committed by Artem Bityutskiy on 21 April 2011, 12:27:21 UTC
This patch fixes the following symptoms:
1. Unmount UBIFS cleanly.
2. Start mounting UBIFS R/W and have a power cut immediately
3. Start mounting UBIFS R/O, this succeeds
4. Try to re-mount UBIFS R/W - this fails immediately or later on,
   because UBIFS will write the master node to the flash area
   which has been written before.

The analysis of the problem:

1. UBIFS is unmounted cleanly, both copies of the master node are clean.
2. UBIFS is being mounter R/W, starts changing master node copy 1, and
   a power cut happens. The copy N1 becomes corrupted.
3. UBIFS is being mounted R/O. It notices the copy N1 is corrupted and
   reads copy N2. Copy N2 is clean.
4. Because of R/O mode, UBIFS cannot recover copy 1.
5. The mount code (ubifs_mount()) sees that the master node is clean,
   so it decides that no recovery is needed.
6. We are re-mounting R/W. UBIFS believes no recovery is needed and
   starts updating the master node, but copy N1 is still corrupted
   and was not recovered!

Fix this problem by marking the master node as dirty every time we
recover it and we are in R/O mode. This forces further recovery and
the UBIFS cleans-up the corruptions and recovers the copy N1 when
re-mounting R/W later.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Cc: stable@kernel.org
1 parent 1a067a2
Raw File
Tip revision: 6e0d9fd38b750d678bf9fd07db23582f52fafa55 authored by Artem Bityutskiy on 21 April 2011, 11:49:55 UTC
UBIFS: fix master node recovery
Tip revision: 6e0d9fd
checkkconfigsymbols.sh
#!/bin/sh
# Find Kconfig variables used in source code but never defined in Kconfig
# Copyright (C) 2007, Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>

# Tested with dash.
paths="$@"
[ -z "$paths" ] && paths=.

# Doing this once at the beginning saves a lot of time, on a cache-hot tree.
Kconfigs="`find . -name 'Kconfig' -o -name 'Kconfig*[^~]'`"

/bin/echo -e "File list \tundefined symbol used"
find $paths -name '*.[chS]' -o -name 'Makefile' -o -name 'Makefile*[^~]'| while read i
do
	# Output the bare Kconfig variable and the filename; the _MODULE part at
	# the end is not removed here (would need perl an not-hungry regexp for that).
	sed -ne 's!^.*\<\(UML_\)\?CONFIG_\([0-9A-Za-z_]\+\).*!\2 '$i'!p' < $i
done | \
# Smart "sort|uniq" implemented in awk and tuned to collect the names of all
# files which use a given symbol
awk '{map[$1, count[$1]++] = $2; }
END {
	for (combIdx in map) {
		split(combIdx, separate, SUBSEP);
		# The value may have been removed.
		if (! ( (separate[1], separate[2]) in map ) )
			continue;
		symb=separate[1];
		printf "%s ", symb;
		#Use gawk extension to delete the names vector
		delete names;
		#Portably delete the names vector
		#split("", names);
		for (i=0; i < count[symb]; i++) {
			names[map[symb, i]] = 1;
			# Unfortunately, we may still encounter symb, i in the
			# outside iteration.
			delete map[symb, i];
		}
		i=0;
		for (name in names) {
			if (i > 0)
				printf ", %s", name;
			else
				printf "%s", name;
			i++;
		}
		printf "\n";
	}
}' |
while read symb files; do
	# Remove the _MODULE suffix when checking the variable name. This should
	# be done only on tristate symbols, actually, but Kconfig parsing is
	# beyond the purpose of this script.
	symb_bare=`echo $symb | sed -e 's/_MODULE//'`
	if ! grep -q "\<$symb_bare\>" $Kconfigs; then
		/bin/echo -e "$files: \t$symb"
	fi
done|sort
back to top