diff mbox series

[06/11] md-bitmap: refactor md_bitmap_init_from_disk

Message ID 20230615064840.629492-7-hch@lst.de (mailing list archive)
State Accepted, archived
Headers show
Series [01/11] md-bitmap: set BITMAP_WRITE_ERROR in write_sb_page | expand

Commit Message

Christoph Hellwig June 15, 2023, 6:48 a.m. UTC
Split the confusing loop in md_bitmap_init_from_disk that iterates over
all chunks but also needs to read and map the pages into three separate
loops: one that iterates over the pages to read them, a second optional
one to iterate over the pages to mark them invalid if the bitmaps are
out of date, and a final one that actually iterates over the chunks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/md-bitmap.c | 142 ++++++++++++++++++++---------------------
 1 file changed, 70 insertions(+), 72 deletions(-)

Comments

kernel test robot June 15, 2023, 9:59 p.m. UTC | #1
Hi Christoph,

kernel test robot noticed the following build warnings:

[auto build test WARNING on song-md/md-next]
[also build test WARNING on device-mapper-dm/for-next linus/master v6.4-rc6 next-20230615]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christoph-Hellwig/md-bitmap-initialize-variables-at-declaration-time-in-md_bitmap_file_unmap/20230615-154928
base:   git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next
patch link:    https://lore.kernel.org/r/20230615064840.629492-7-hch%40lst.de
patch subject: [PATCH 06/11] md-bitmap: refactor md_bitmap_init_from_disk
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20230616/202306160552.smw0qbmb-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        git remote add song-md git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git
        git fetch song-md md-next
        git checkout song-md/md-next
        b4 shazam https://lore.kernel.org/r/20230615064840.629492-7-hch@lst.de
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/md/

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306160552.smw0qbmb-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/md/md-bitmap.c:1107:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (file && i_size_read(file->f_mapping->host) < store->bytes) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/md-bitmap.c:1198:9: note: uninitialized use occurs here
           return ret;
                  ^~~
   drivers/md/md-bitmap.c:1107:2: note: remove the 'if' if its condition is always false
           if (file && i_size_read(file->f_mapping->host) < store->bytes) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/md-bitmap.c:1090:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0
   1 warning generated.


vim +1107 drivers/md/md-bitmap.c

5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1068  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1069  /*
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1070   * Initialize the in-memory bitmap from the on-disk bitmap and set up the memory
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1071   * mapping of the bitmap file.
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1072   *
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1073   * Special case: If there's no bitmap file, or if the bitmap file had been
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1074   * previously kicked from the array, we mark all the bits as 1's in order to
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1075   * cause a full resync.
6a07997fc34ac1 drivers/md/bitmap.c    NeilBrown         2005-09-09  1076   *
6a07997fc34ac1 drivers/md/bitmap.c    NeilBrown         2005-09-09  1077   * We ignore all bits for sectors that end earlier than 'start'.
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1078   * This is used when reading an out-of-date bitmap.
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1079   */
e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko   2018-08-01  1080  static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1081  {
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1082  	bool outofdate = test_bit(BITMAP_STALE, &bitmap->flags);
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1083  	struct mddev *mddev = bitmap->mddev;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1084  	unsigned long chunks = bitmap->counts.chunks;
1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1085  	struct bitmap_storage *store = &bitmap->storage;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1086  	struct file *file = store->file;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1087  	unsigned long node_offset = 0;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1088  	unsigned long bit_cnt = 0;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1089  	unsigned long i;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1090  	int ret;
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1091  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1092  	if (!file && !mddev->bitmap_info.offset) {
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1093  		/* No permanent bitmap - fill with '1s'. */
1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1094  		store->filemap = NULL;
1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1095  		store->file_pages = 0;
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1096  		for (i = 0; i < chunks ; i++) {
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1097  			/* if the disk bit is set, set the memory bit */
40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1098  			int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift)
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1099  				      >= start);
e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko   2018-08-01  1100  			md_bitmap_set_memory_bits(bitmap,
40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1101  						  (sector_t)i << bitmap->counts.chunkshift,
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1102  						  needed);
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1103  		}
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1104  		return 0;
ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1105  	}
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1106  
d1244cb062750b drivers/md/bitmap.c    NeilBrown         2012-05-22 @1107  	if (file && i_size_read(file->f_mapping->host) < store->bytes) {
ec0cc226854a79 drivers/md/bitmap.c    NeilBrown         2016-11-02  1108  		pr_warn("%s: bitmap file too short %lu < %lu\n",
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1109  			bmname(bitmap),
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1110  			(unsigned long) i_size_read(file->f_mapping->host),
d1244cb062750b drivers/md/bitmap.c    NeilBrown         2012-05-22  1111  			store->bytes);
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1112  		goto err;
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1113  	}
bc7f77de2cd817 drivers/md/bitmap.c    NeilBrown         2005-06-21  1114  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1115  	if (mddev_is_clustered(mddev))
b97e92574c0bf3 drivers/md/bitmap.c    Goldwyn Rodrigues 2014-06-06  1116  		node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE));
b97e92574c0bf3 drivers/md/bitmap.c    Goldwyn Rodrigues 2014-06-06  1117  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1118  	for (i = 0; i < store->file_pages; i++) {
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1119  		struct page *page = store->filemap[i];
d785a06a0b9d0c drivers/md/bitmap.c    NeilBrown         2006-06-26  1120  		int count;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1121  
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1122  		/* unmap the old page, we're done with it */
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1123  		if (i == store->file_pages - 1)
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1124  			count = store->bytes - i * PAGE_SIZE;
d785a06a0b9d0c drivers/md/bitmap.c    NeilBrown         2006-06-26  1125  		else
d785a06a0b9d0c drivers/md/bitmap.c    NeilBrown         2006-06-26  1126  			count = PAGE_SIZE;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1127  
27581e5ae01f77 drivers/md/bitmap.c    NeilBrown         2012-05-22  1128  		if (file)
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1129  			ret = read_file_page(file, i, bitmap, count, page);
27581e5ae01f77 drivers/md/bitmap.c    NeilBrown         2012-05-22  1130  		else
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1131  			ret = read_sb_page(mddev, mddev->bitmap_info.offset,
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1132  					   page, i + node_offset, count);
27581e5ae01f77 drivers/md/bitmap.c    NeilBrown         2012-05-22  1133  		if (ret)
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1134  			goto err;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1135  	}
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1136  
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1137  	if (outofdate) {
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1138  		pr_warn("%s: bitmap file is out of date, doing full recovery\n",
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1139  			bmname(bitmap));
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1140  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1141  		for (i = 0; i < store->file_pages; i++) {
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1142  			struct page *page = store->filemap[i];
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1143  			unsigned long offset = 0;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1144  			void *paddr;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1145  	
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1146  			if (i == 0 && !mddev->bitmap_info.external)
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1147  				offset = sizeof(bitmap_super_t);
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1148  
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1149  			/*
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1150  			 * If the bitmap is out of date, dirty the whole page
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1151  			 * and write it out
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1152  			 */
b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1153  			paddr = kmap_atomic(page);
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1154  			memset(paddr + offset, 0xff, PAGE_SIZE - offset);
b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1155  			kunmap_atomic(paddr);
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1156  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1157  			write_page(bitmap, page, 1);
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1158  			if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) {
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1159  				ret = -EIO;
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1160  				goto err;
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1161  			}
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1162  		}
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1163  	}
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1164  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1165  	for (i = 0; i < chunks; i++) {
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1166  		struct page *page = filemap_get_page(&bitmap->storage, i);
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1167  		unsigned long bit = file_page_offset(&bitmap->storage, i);
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1168  		void *paddr;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1169  		bool was_set;
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1170  
b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1171  		paddr = kmap_atomic(page);
b405fe91e50c60 drivers/md/bitmap.c    NeilBrown         2012-05-22  1172  		if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1173  			was_set = test_bit(bit, paddr);
bd926c63b7a684 drivers/md/bitmap.c    NeilBrown         2005-11-08  1174  		else
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1175  			was_set = test_bit_le(bit, paddr);
b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1176  		kunmap_atomic(paddr);
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1177  
5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1178  		if (was_set) {
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1179  			/* if the disk bit is set, set the memory bit */
40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1180  			int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift
db305e507d5544 drivers/md/bitmap.c    NeilBrown         2009-05-07  1181  				      >= start);
e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko   2018-08-01  1182  			md_bitmap_set_memory_bits(bitmap,
40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1183  						  (sector_t)i << bitmap->counts.chunkshift,
db305e507d5544 drivers/md/bitmap.c    NeilBrown         2009-05-07  1184  						  needed);
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1185  			bit_cnt++;
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1186  		}
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1187  	}
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1188  
ec0cc226854a79 drivers/md/bitmap.c    NeilBrown         2016-11-02  1189  	pr_debug("%s: bitmap initialized from disk: read %lu pages, set %lu of %lu bits\n",
1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1190  		 bmname(bitmap), store->file_pages,
d1244cb062750b drivers/md/bitmap.c    NeilBrown         2012-05-22  1191  		 bit_cnt, chunks);
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1192  
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1193  	return 0;
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1194  
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1195   err:
ec0cc226854a79 drivers/md/bitmap.c    NeilBrown         2016-11-02  1196  	pr_warn("%s: bitmap initialisation failed: %d\n",
4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1197  		bmname(bitmap), ret);
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1198  	return ret;
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1199  }
32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1200
Song Liu June 16, 2023, 6:53 a.m. UTC | #2
On Thu, Jun 15, 2023 at 3:01 PM kernel test robot <lkp@intel.com> wrote:
>
> Hi Christoph,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on song-md/md-next]
> [also build test WARNING on device-mapper-dm/for-next linus/master v6.4-rc6 next-20230615]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Christoph-Hellwig/md-bitmap-initialize-variables-at-declaration-time-in-md_bitmap_file_unmap/20230615-154928
> base:   git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next
> patch link:    https://lore.kernel.org/r/20230615064840.629492-7-hch%40lst.de
> patch subject: [PATCH 06/11] md-bitmap: refactor md_bitmap_init_from_disk
> config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20230616/202306160552.smw0qbmb-lkp@intel.com/config)
> compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> reproduce (this is a W=1 build):
>         mkdir -p ~/bin
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         git remote add song-md git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git
>         git fetch song-md md-next
>         git checkout song-md/md-next
>         b4 shazam https://lore.kernel.org/r/20230615064840.629492-7-hch@lst.de
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/md/
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202306160552.smw0qbmb-lkp@intel.com/

I fixed this one, and applied the set to md-next.

Thanks,
Song

>
> All warnings (new ones prefixed by >>):
>
> >> drivers/md/md-bitmap.c:1107:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>            if (file && i_size_read(file->f_mapping->host) < store->bytes) {
>                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    drivers/md/md-bitmap.c:1198:9: note: uninitialized use occurs here
>            return ret;
>                   ^~~
>    drivers/md/md-bitmap.c:1107:2: note: remove the 'if' if its condition is always false
>            if (file && i_size_read(file->f_mapping->host) < store->bytes) {
>            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    drivers/md/md-bitmap.c:1090:9: note: initialize the variable 'ret' to silence this warning
>            int ret;
>                   ^
>                    = 0
>    1 warning generated.
>
>
> vim +1107 drivers/md/md-bitmap.c
>
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1068
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1069  /*
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1070   * Initialize the in-memory bitmap from the on-disk bitmap and set up the memory
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1071   * mapping of the bitmap file.
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1072   *
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1073   * Special case: If there's no bitmap file, or if the bitmap file had been
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1074   * previously kicked from the array, we mark all the bits as 1's in order to
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1075   * cause a full resync.
> 6a07997fc34ac1 drivers/md/bitmap.c    NeilBrown         2005-09-09  1076   *
> 6a07997fc34ac1 drivers/md/bitmap.c    NeilBrown         2005-09-09  1077   * We ignore all bits for sectors that end earlier than 'start'.
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1078   * This is used when reading an out-of-date bitmap.
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1079   */
> e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko   2018-08-01  1080  static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1081  {
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1082        bool outofdate = test_bit(BITMAP_STALE, &bitmap->flags);
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1083        struct mddev *mddev = bitmap->mddev;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1084        unsigned long chunks = bitmap->counts.chunks;
> 1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1085        struct bitmap_storage *store = &bitmap->storage;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1086        struct file *file = store->file;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1087        unsigned long node_offset = 0;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1088        unsigned long bit_cnt = 0;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1089        unsigned long i;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1090        int ret;
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1091
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1092        if (!file && !mddev->bitmap_info.offset) {
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1093                /* No permanent bitmap - fill with '1s'. */
> 1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1094                store->filemap = NULL;
> 1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1095                store->file_pages = 0;
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1096                for (i = 0; i < chunks ; i++) {
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1097                        /* if the disk bit is set, set the memory bit */
> 40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1098                        int needed = ((sector_t)(i+1) << (bitmap->counts.chunkshift)
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1099                                      >= start);
> e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko   2018-08-01  1100                        md_bitmap_set_memory_bits(bitmap,
> 40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1101                                                  (sector_t)i << bitmap->counts.chunkshift,
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1102                                                  needed);
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1103                }
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1104                return 0;
> ef99bf480de9bd drivers/md/bitmap.c    NeilBrown         2012-05-22  1105        }
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1106
> d1244cb062750b drivers/md/bitmap.c    NeilBrown         2012-05-22 @1107        if (file && i_size_read(file->f_mapping->host) < store->bytes) {
> ec0cc226854a79 drivers/md/bitmap.c    NeilBrown         2016-11-02  1108                pr_warn("%s: bitmap file too short %lu < %lu\n",
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1109                        bmname(bitmap),
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1110                        (unsigned long) i_size_read(file->f_mapping->host),
> d1244cb062750b drivers/md/bitmap.c    NeilBrown         2012-05-22  1111                        store->bytes);
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1112                goto err;
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1113        }
> bc7f77de2cd817 drivers/md/bitmap.c    NeilBrown         2005-06-21  1114
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1115        if (mddev_is_clustered(mddev))
> b97e92574c0bf3 drivers/md/bitmap.c    Goldwyn Rodrigues 2014-06-06  1116                node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE));
> b97e92574c0bf3 drivers/md/bitmap.c    Goldwyn Rodrigues 2014-06-06  1117
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1118        for (i = 0; i < store->file_pages; i++) {
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1119                struct page *page = store->filemap[i];
> d785a06a0b9d0c drivers/md/bitmap.c    NeilBrown         2006-06-26  1120                int count;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1121
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1122                /* unmap the old page, we're done with it */
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1123                if (i == store->file_pages - 1)
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1124                        count = store->bytes - i * PAGE_SIZE;
> d785a06a0b9d0c drivers/md/bitmap.c    NeilBrown         2006-06-26  1125                else
> d785a06a0b9d0c drivers/md/bitmap.c    NeilBrown         2006-06-26  1126                        count = PAGE_SIZE;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1127
> 27581e5ae01f77 drivers/md/bitmap.c    NeilBrown         2012-05-22  1128                if (file)
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1129                        ret = read_file_page(file, i, bitmap, count, page);
> 27581e5ae01f77 drivers/md/bitmap.c    NeilBrown         2012-05-22  1130                else
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1131                        ret = read_sb_page(mddev, mddev->bitmap_info.offset,
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1132                                           page, i + node_offset, count);
> 27581e5ae01f77 drivers/md/bitmap.c    NeilBrown         2012-05-22  1133                if (ret)
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1134                        goto err;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1135        }
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1136
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1137        if (outofdate) {
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1138                pr_warn("%s: bitmap file is out of date, doing full recovery\n",
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1139                        bmname(bitmap));
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1140
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1141                for (i = 0; i < store->file_pages; i++) {
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1142                        struct page *page = store->filemap[i];
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1143                        unsigned long offset = 0;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1144                        void *paddr;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1145
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1146                        if (i == 0 && !mddev->bitmap_info.external)
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1147                                offset = sizeof(bitmap_super_t);
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1148
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1149                        /*
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1150                         * If the bitmap is out of date, dirty the whole page
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1151                         * and write it out
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1152                         */
> b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1153                        paddr = kmap_atomic(page);
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1154                        memset(paddr + offset, 0xff, PAGE_SIZE - offset);
> b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1155                        kunmap_atomic(paddr);
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1156
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1157                        write_page(bitmap, page, 1);
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1158                        if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) {
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1159                                ret = -EIO;
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1160                                goto err;
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1161                        }
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1162                }
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1163        }
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1164
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1165        for (i = 0; i < chunks; i++) {
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1166                struct page *page = filemap_get_page(&bitmap->storage, i);
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1167                unsigned long bit = file_page_offset(&bitmap->storage, i);
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1168                void *paddr;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1169                bool was_set;
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1170
> b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1171                paddr = kmap_atomic(page);
> b405fe91e50c60 drivers/md/bitmap.c    NeilBrown         2012-05-22  1172                if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1173                        was_set = test_bit(bit, paddr);
> bd926c63b7a684 drivers/md/bitmap.c    NeilBrown         2005-11-08  1174                else
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1175                        was_set = test_bit_le(bit, paddr);
> b2f46e68825648 drivers/md/bitmap.c    Cong Wang         2011-11-28  1176                kunmap_atomic(paddr);
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1177
> 5479b6ae3886b9 drivers/md/md-bitmap.c Christoph Hellwig 2023-06-15  1178                if (was_set) {
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1179                        /* if the disk bit is set, set the memory bit */
> 40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1180                        int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift
> db305e507d5544 drivers/md/bitmap.c    NeilBrown         2009-05-07  1181                                      >= start);
> e64e4018d57271 drivers/md/md-bitmap.c Andy Shevchenko   2018-08-01  1182                        md_bitmap_set_memory_bits(bitmap,
> 40cffcc0e8f9f6 drivers/md/bitmap.c    NeilBrown         2012-05-22  1183                                                  (sector_t)i << bitmap->counts.chunkshift,
> db305e507d5544 drivers/md/bitmap.c    NeilBrown         2009-05-07  1184                                                  needed);
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1185                        bit_cnt++;
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1186                }
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1187        }
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1188
> ec0cc226854a79 drivers/md/bitmap.c    NeilBrown         2016-11-02  1189        pr_debug("%s: bitmap initialized from disk: read %lu pages, set %lu of %lu bits\n",
> 1ec885cdd01a9a drivers/md/bitmap.c    NeilBrown         2012-05-22  1190                 bmname(bitmap), store->file_pages,
> d1244cb062750b drivers/md/bitmap.c    NeilBrown         2012-05-22  1191                 bit_cnt, chunks);
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1192
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1193        return 0;
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1194
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1195   err:
> ec0cc226854a79 drivers/md/bitmap.c    NeilBrown         2016-11-02  1196        pr_warn("%s: bitmap initialisation failed: %d\n",
> 4ad1366376bfef drivers/md/bitmap.c    NeilBrown         2007-07-17  1197                bmname(bitmap), ret);
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1198        return ret;
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1199  }
> 32a7627cf3a353 drivers/md/bitmap.c    NeilBrown         2005-06-21  1200
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
Christoph Hellwig June 16, 2023, 7:01 a.m. UTC | #3
On Thu, Jun 15, 2023 at 11:53:49PM -0700, Song Liu wrote:
> I fixed this one, and applied the set to md-next.

Thanks!
diff mbox series

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index fa0f6ca7b61b0b..1f71683b417981 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1065,33 +1065,31 @@  void md_bitmap_unplug_async(struct bitmap *bitmap)
 EXPORT_SYMBOL(md_bitmap_unplug_async);
 
 static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
-/* * bitmap_init_from_disk -- called at bitmap_create time to initialize
- * the in-memory bitmap from the on-disk bitmap -- also, sets up the
- * memory mapping of the bitmap file
- * Special cases:
- *   if there's no bitmap file, or if the bitmap file had been
- *   previously kicked from the array, we mark all the bits as
- *   1's in order to cause a full resync.
+
+/*
+ * Initialize the in-memory bitmap from the on-disk bitmap and set up the memory
+ * mapping of the bitmap file.
+ *
+ * Special case: If there's no bitmap file, or if the bitmap file had been
+ * previously kicked from the array, we mark all the bits as 1's in order to
+ * cause a full resync.
  *
  * We ignore all bits for sectors that end earlier than 'start'.
- * This is used when reading an out-of-date bitmap...
+ * This is used when reading an out-of-date bitmap.
  */
 static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 {
-	unsigned long i, chunks, index, oldindex, bit, node_offset = 0;
-	struct page *page = NULL;
-	unsigned long bit_cnt = 0;
-	struct file *file;
-	unsigned long offset;
-	int outofdate;
-	int ret = -ENOSPC;
-	void *paddr;
+	bool outofdate = test_bit(BITMAP_STALE, &bitmap->flags);
+	struct mddev *mddev = bitmap->mddev;
+	unsigned long chunks = bitmap->counts.chunks;
 	struct bitmap_storage *store = &bitmap->storage;
+	struct file *file = store->file;
+	unsigned long node_offset = 0;
+	unsigned long bit_cnt = 0;
+	unsigned long i;
+	int ret;
 
-	chunks = bitmap->counts.chunks;
-	file = store->file;
-
-	if (!file && !bitmap->mddev->bitmap_info.offset) {
+	if (!file && !mddev->bitmap_info.offset) {
 		/* No permanent bitmap - fill with '1s'. */
 		store->filemap = NULL;
 		store->file_pages = 0;
@@ -1106,10 +1104,6 @@  static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 		return 0;
 	}
 
-	outofdate = test_bit(BITMAP_STALE, &bitmap->flags);
-	if (outofdate)
-		pr_warn("%s: bitmap file is out of date, doing full recovery\n", bmname(bitmap));
-
 	if (file && i_size_read(file->f_mapping->host) < store->bytes) {
 		pr_warn("%s: bitmap file too short %lu < %lu\n",
 			bmname(bitmap),
@@ -1118,65 +1112,70 @@  static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 		goto err;
 	}
 
-	oldindex = ~0L;
-	offset = 0;
-	if (!bitmap->mddev->bitmap_info.external)
-		offset = sizeof(bitmap_super_t);
-
-	if (mddev_is_clustered(bitmap->mddev))
+	if (mddev_is_clustered(mddev))
 		node_offset = bitmap->cluster_slot * (DIV_ROUND_UP(store->bytes, PAGE_SIZE));
 
-	for (i = 0; i < chunks; i++) {
-		int b;
-		index = file_page_index(&bitmap->storage, i);
-		bit = file_page_offset(&bitmap->storage, i);
-		if (index != oldindex) { /* this is a new page, read it in */
-			int count;
-			/* unmap the old page, we're done with it */
-			if (index == store->file_pages-1)
-				count = store->bytes - index * PAGE_SIZE;
-			else
-				count = PAGE_SIZE;
-			page = store->filemap[index];
-			if (file)
-				ret = read_file_page(file, index, bitmap,
-						count, page);
-			else
-				ret = read_sb_page(
-					bitmap->mddev,
-					bitmap->mddev->bitmap_info.offset,
-					page,
-					index + node_offset, count);
-
-			if (ret)
-				goto err;
+	for (i = 0; i < store->file_pages; i++) {
+		struct page *page = store->filemap[i];
+		int count;
 
-			oldindex = index;
+		/* unmap the old page, we're done with it */
+		if (i == store->file_pages - 1)
+			count = store->bytes - i * PAGE_SIZE;
+		else
+			count = PAGE_SIZE;
 
-			if (outofdate) {
-				/*
-				 * if bitmap is out of date, dirty the
-				 * whole page and write it out
-				 */
-				paddr = kmap_atomic(page);
-				memset(paddr + offset, 0xff,
-				       PAGE_SIZE - offset);
-				kunmap_atomic(paddr);
-				write_page(bitmap, page, 1);
+		if (file)
+			ret = read_file_page(file, i, bitmap, count, page);
+		else
+			ret = read_sb_page(mddev, mddev->bitmap_info.offset,
+					   page, i + node_offset, count);
+		if (ret)
+			goto err;
+	}
+
+	if (outofdate) {
+		pr_warn("%s: bitmap file is out of date, doing full recovery\n",
+			bmname(bitmap));
+
+		for (i = 0; i < store->file_pages; i++) {
+			struct page *page = store->filemap[i];
+			unsigned long offset = 0;
+			void *paddr;
+	
+			if (i == 0 && !mddev->bitmap_info.external)
+				offset = sizeof(bitmap_super_t);
+
+			/*
+			 * If the bitmap is out of date, dirty the whole page
+			 * and write it out
+			 */
+			paddr = kmap_atomic(page);
+			memset(paddr + offset, 0xff, PAGE_SIZE - offset);
+			kunmap_atomic(paddr);
 
+			write_page(bitmap, page, 1);
+			if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) {
 				ret = -EIO;
-				if (test_bit(BITMAP_WRITE_ERROR,
-					     &bitmap->flags))
-					goto err;
+				goto err;
 			}
 		}
+	}
+
+	for (i = 0; i < chunks; i++) {
+		struct page *page = filemap_get_page(&bitmap->storage, i);
+		unsigned long bit = file_page_offset(&bitmap->storage, i);
+		void *paddr;
+		bool was_set;
+
 		paddr = kmap_atomic(page);
 		if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
-			b = test_bit(bit, paddr);
+			was_set = test_bit(bit, paddr);
 		else
-			b = test_bit_le(bit, paddr);
+			was_set = test_bit_le(bit, paddr);
 		kunmap_atomic(paddr);
-		if (b) {
+
+		if (was_set) {
 			/* if the disk bit is set, set the memory bit */
 			int needed = ((sector_t)(i+1) << bitmap->counts.chunkshift
 				      >= start);
@@ -1185,7 +1184,6 @@  static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 						  needed);
 			bit_cnt++;
 		}
-		offset = 0;
 	}
 
 	pr_debug("%s: bitmap initialized from disk: read %lu pages, set %lu of %lu bits\n",