diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2013-05-30 00:35:23 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2013-05-30 20:46:27 -0400 |
commit | 21363ca873334391992f2f424856aa864345bb61 (patch) | |
tree | a3bf98065a2ae02afd26dce1b1c34e75a4c7ee5b /drivers/target | |
parent | 1d19f7800d643b270b28d0a969c5eca455d54397 (diff) |
target/file: Fix off-by-one READ_CAPACITY bug for !S_ISBLK export
This patch fixes a bug where FILEIO was incorrectly reporting the number
of logical blocks (+ 1) when using non struct block_device export mode.
It changes fd_get_blocks() to follow all other backend ->get_blocks() cases,
and reduces the calculated dev_size by one dev->dev_attrib.block_size
number of bytes, and also fixes initial fd_block_size assignment at
fd_configure_device() time introduced in commit 0fd97ccf4.
Reported-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Reported-by: Badari Pulavarty <pbadari@us.ibm.com>
Tested-by: Badari Pulavarty <pbadari@us.ibm.com>
Cc: stable@vger.kernel.org
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/target_core_file.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index 1b1d544e927a..b11890d85120 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c | |||
@@ -153,6 +153,7 @@ static int fd_configure_device(struct se_device *dev) | |||
153 | struct request_queue *q = bdev_get_queue(inode->i_bdev); | 153 | struct request_queue *q = bdev_get_queue(inode->i_bdev); |
154 | unsigned long long dev_size; | 154 | unsigned long long dev_size; |
155 | 155 | ||
156 | fd_dev->fd_block_size = bdev_logical_block_size(inode->i_bdev); | ||
156 | /* | 157 | /* |
157 | * Determine the number of bytes from i_size_read() minus | 158 | * Determine the number of bytes from i_size_read() minus |
158 | * one (1) logical sector from underlying struct block_device | 159 | * one (1) logical sector from underlying struct block_device |
@@ -199,6 +200,7 @@ static int fd_configure_device(struct se_device *dev) | |||
199 | goto fail; | 200 | goto fail; |
200 | } | 201 | } |
201 | 202 | ||
203 | fd_dev->fd_block_size = FD_BLOCKSIZE; | ||
202 | /* | 204 | /* |
203 | * Limit UNMAP emulation to 8k Number of LBAs (NoLB) | 205 | * Limit UNMAP emulation to 8k Number of LBAs (NoLB) |
204 | */ | 206 | */ |
@@ -217,9 +219,7 @@ static int fd_configure_device(struct se_device *dev) | |||
217 | dev->dev_attrib.max_write_same_len = 0x1000; | 219 | dev->dev_attrib.max_write_same_len = 0x1000; |
218 | } | 220 | } |
219 | 221 | ||
220 | fd_dev->fd_block_size = dev->dev_attrib.hw_block_size; | 222 | dev->dev_attrib.hw_block_size = fd_dev->fd_block_size; |
221 | |||
222 | dev->dev_attrib.hw_block_size = FD_BLOCKSIZE; | ||
223 | dev->dev_attrib.hw_max_sectors = FD_MAX_SECTORS; | 223 | dev->dev_attrib.hw_max_sectors = FD_MAX_SECTORS; |
224 | dev->dev_attrib.hw_queue_depth = FD_MAX_DEVICE_QUEUE_DEPTH; | 224 | dev->dev_attrib.hw_queue_depth = FD_MAX_DEVICE_QUEUE_DEPTH; |
225 | 225 | ||
@@ -694,11 +694,12 @@ static sector_t fd_get_blocks(struct se_device *dev) | |||
694 | * to handle underlying block_device resize operations. | 694 | * to handle underlying block_device resize operations. |
695 | */ | 695 | */ |
696 | if (S_ISBLK(i->i_mode)) | 696 | if (S_ISBLK(i->i_mode)) |
697 | dev_size = (i_size_read(i) - fd_dev->fd_block_size); | 697 | dev_size = i_size_read(i); |
698 | else | 698 | else |
699 | dev_size = fd_dev->fd_dev_size; | 699 | dev_size = fd_dev->fd_dev_size; |
700 | 700 | ||
701 | return div_u64(dev_size, dev->dev_attrib.block_size); | 701 | return div_u64(dev_size - dev->dev_attrib.block_size, |
702 | dev->dev_attrib.block_size); | ||
702 | } | 703 | } |
703 | 704 | ||
704 | static struct sbc_ops fd_sbc_ops = { | 705 | static struct sbc_ops fd_sbc_ops = { |