diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-11-29 15:27:00 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-11-29 15:38:44 -0500 |
commit | ab73857e354ab9e317613cba7db714e2c12c6547 (patch) | |
tree | de5b6fec7caec530f0dd72c9394a1a7d0b6f9878 /fs/direct-io.c | |
parent | 1e8b33328a5407b447ff80953655a47014a6dcb9 (diff) |
direct-io: don't read inode->i_blkbits multiple times
Since directio can work on a raw block device, and the block size of the
device can change under it, we need to do the same thing that
fs/buffer.c now does: read the block size a single time, using
ACCESS_ONCE().
Reading it multiple times can get different results, which will then
confuse the code because it actually encodes the i_blksize in
relationship to the underlying logical blocksize.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/direct-io.c')
-rw-r--r-- | fs/direct-io.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/fs/direct-io.c b/fs/direct-io.c index f86c720dba0e..cf5b44b10c67 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -540,6 +540,7 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, | |||
540 | sector_t fs_endblk; /* Into file, in filesystem-sized blocks */ | 540 | sector_t fs_endblk; /* Into file, in filesystem-sized blocks */ |
541 | unsigned long fs_count; /* Number of filesystem-sized blocks */ | 541 | unsigned long fs_count; /* Number of filesystem-sized blocks */ |
542 | int create; | 542 | int create; |
543 | unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor; | ||
543 | 544 | ||
544 | /* | 545 | /* |
545 | * If there was a memory error and we've overwritten all the | 546 | * If there was a memory error and we've overwritten all the |
@@ -554,7 +555,7 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, | |||
554 | fs_count = fs_endblk - fs_startblk + 1; | 555 | fs_count = fs_endblk - fs_startblk + 1; |
555 | 556 | ||
556 | map_bh->b_state = 0; | 557 | map_bh->b_state = 0; |
557 | map_bh->b_size = fs_count << dio->inode->i_blkbits; | 558 | map_bh->b_size = fs_count << i_blkbits; |
558 | 559 | ||
559 | /* | 560 | /* |
560 | * For writes inside i_size on a DIO_SKIP_HOLES filesystem we | 561 | * For writes inside i_size on a DIO_SKIP_HOLES filesystem we |
@@ -1053,7 +1054,8 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1053 | int seg; | 1054 | int seg; |
1054 | size_t size; | 1055 | size_t size; |
1055 | unsigned long addr; | 1056 | unsigned long addr; |
1056 | unsigned blkbits = inode->i_blkbits; | 1057 | unsigned i_blkbits = ACCESS_ONCE(inode->i_blkbits); |
1058 | unsigned blkbits = i_blkbits; | ||
1057 | unsigned blocksize_mask = (1 << blkbits) - 1; | 1059 | unsigned blocksize_mask = (1 << blkbits) - 1; |
1058 | ssize_t retval = -EINVAL; | 1060 | ssize_t retval = -EINVAL; |
1059 | loff_t end = offset; | 1061 | loff_t end = offset; |
@@ -1149,7 +1151,7 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1149 | dio->inode = inode; | 1151 | dio->inode = inode; |
1150 | dio->rw = rw; | 1152 | dio->rw = rw; |
1151 | sdio.blkbits = blkbits; | 1153 | sdio.blkbits = blkbits; |
1152 | sdio.blkfactor = inode->i_blkbits - blkbits; | 1154 | sdio.blkfactor = i_blkbits - blkbits; |
1153 | sdio.block_in_file = offset >> blkbits; | 1155 | sdio.block_in_file = offset >> blkbits; |
1154 | 1156 | ||
1155 | sdio.get_block = get_block; | 1157 | sdio.get_block = get_block; |