dm: use i_size_read
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 22 Jun 2009 09:12:14 +0000 (10:12 +0100)
committerAlasdair G Kergon <agk@redhat.com>
Mon, 22 Jun 2009 09:12:14 +0000 (10:12 +0100)
Use i_size_read() instead of reading i_size.

If someone changes the size of the device simultaneously, i_size_read
is guaranteed to return a valid value (either the old one or the new one).

i_size can return some intermediate invalid value (on 32-bit computers
with 64-bit i_size, the reads to both halves of i_size can be interleaved
with updates to i_size, resulting in garbage being returned).

Cc: stable@kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
drivers/md/dm-exception-store.h
drivers/md/dm-log.c
drivers/md/dm-table.c

index c92701dc50016ff2f1eb87f40a76b8a8dce1b208..2442c8c0789808607089722a2157ca94f4176c92 100644 (file)
@@ -156,7 +156,7 @@ static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e)
  */
 static inline sector_t get_dev_size(struct block_device *bdev)
 {
-       return bdev->bd_inode->i_size >> SECTOR_SHIFT;
+       return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
 }
 
 static inline chunk_t sector_to_chunk(struct dm_exception_store *store,
index 6fa8ccf91c70e70174d578e10b8793b884a86406..6352a9ad44461c9ac473fb4f6560008eb0241cc2 100644 (file)
@@ -416,7 +416,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
                                       bitset_size,
                                       ti->limits.logical_block_size);
 
-               if (buf_size > dev->bdev->bd_inode->i_size) {
+               if (buf_size > i_size_read(dev->bdev->bd_inode)) {
                        DMWARN("log device %s too small: need %llu bytes",
                                dev->name, (unsigned long long)buf_size);
                        kfree(lc);
index e9a73bb242b0935eefae2ce0744ed97965a2143d..0e2210c0c168e1e51473cb6ff175dac9ed8a879c 100644 (file)
@@ -388,7 +388,8 @@ static void close_dev(struct dm_dev_internal *d, struct mapped_device *md)
 static int check_device_area(struct dm_dev_internal *dd, sector_t start,
                             sector_t len)
 {
-       sector_t dev_size = dd->dm_dev.bdev->bd_inode->i_size >> SECTOR_SHIFT;
+       sector_t dev_size = i_size_read(dd->dm_dev.bdev->bd_inode) >>
+                           SECTOR_SHIFT;
 
        if (!dev_size)
                return 1;