1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

devs: use bcache fd for read ahead ioctl

to avoid an unnecessary open of the device in
most cases.
This commit is contained in:
David Teigland 2018-06-26 12:05:39 -05:00
parent 90e419c645
commit f7ffba204e

View File

@ -367,18 +367,24 @@ static int _dev_get_size_dev(struct device *dev, uint64_t *size)
static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead) static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead)
{ {
long read_ahead_long; long read_ahead_long;
int fd = dev->bcache_fd;
int do_close = 0;
if (dev->read_ahead != -1) { if (dev->read_ahead != -1) {
*read_ahead = (uint32_t) dev->read_ahead; *read_ahead = (uint32_t) dev->read_ahead;
return 1; return 1;
} }
if (!dev_open_readonly(dev)) if (fd <= 0) {
return_0; if (!dev_open_readonly(dev))
return_0;
fd = dev_fd(dev);
do_close = 1;
}
if (ioctl(dev->fd, BLKRAGET, &read_ahead_long) < 0) { if (ioctl(fd, BLKRAGET, &read_ahead_long) < 0) {
log_sys_error("ioctl BLKRAGET", dev_name(dev)); log_sys_error("ioctl BLKRAGET", dev_name(dev));
if (!dev_close_immediate(dev)) if (do_close && !dev_close_immediate(dev))
stack; stack;
return 0; return 0;
} }
@ -389,8 +395,8 @@ static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead)
log_very_verbose("%s: read_ahead is %u sectors", log_very_verbose("%s: read_ahead is %u sectors",
dev_name(dev), *read_ahead); dev_name(dev), *read_ahead);
if (!dev_close_immediate(dev)) if (do_close && !dev_close_immediate(dev))
stack; log_sys_error("close", dev_name(dev));
return 1; return 1;
} }