1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

devices: clean up block size functions

Replace calls to the old dev_get_block_size function
with calls to the new dev_get_direct_block_size function,
and remove the old function.
This commit is contained in:
David Teigland 2019-08-07 11:38:06 -05:00
parent bec3088f85
commit 09bc2d0fd1
5 changed files with 18 additions and 95 deletions

View File

@ -64,8 +64,6 @@ static int _insert(const char *path, const struct stat *info,
/* Setup non-zero members of passed zeroed 'struct device' */ /* Setup non-zero members of passed zeroed 'struct device' */
static void _dev_init(struct device *dev) static void _dev_init(struct device *dev)
{ {
dev->phys_block_size = -1;
dev->block_size = -1;
dev->fd = -1; dev->fd = -1;
dev->read_ahead = -1; dev->read_ahead = -1;

View File

@ -53,77 +53,6 @@
static unsigned _dev_size_seqno = 1; static unsigned _dev_size_seqno = 1;
/*
* Get the physical and logical block size for a device.
*/
int dev_get_block_size(struct device *dev, unsigned int *physical_block_size, unsigned int *block_size)
{
const char *name = dev_name(dev);
int fd = dev->bcache_fd;
int do_close = 0;
int r = 1;
if ((dev->phys_block_size > 0) && (dev->block_size > 0)) {
*physical_block_size = (unsigned int)dev->phys_block_size;
*block_size = (unsigned int)dev->block_size;
return 1;
}
if (fd <= 0) {
if (!dev->open_count) {
if (!dev_open_readonly(dev))
return_0;
do_close = 1;
}
fd = dev_fd(dev);
}
if (dev->block_size == -1) {
if (ioctl(fd, BLKBSZGET, &dev->block_size) < 0) {
log_sys_error("ioctl BLKBSZGET", name);
r = 0;
goto out;
}
log_debug_devs("%s: Block size is %u bytes", name, dev->block_size);
}
#ifdef BLKPBSZGET
/* BLKPBSZGET is available in kernel >= 2.6.32 only */
if (dev->phys_block_size == -1) {
if (ioctl(fd, BLKPBSZGET, &dev->phys_block_size) < 0) {
log_sys_error("ioctl BLKPBSZGET", name);
r = 0;
goto out;
}
log_debug_devs("%s: Physical block size is %u bytes", name, dev->phys_block_size);
}
#elif defined (BLKSSZGET)
/* if we can't get physical block size, just use logical block size instead */
if (dev->phys_block_size == -1) {
if (ioctl(fd, BLKSSZGET, &dev->phys_block_size) < 0) {
log_sys_error("ioctl BLKSSZGET", name);
r = 0;
goto out;
}
log_debug_devs("%s: Physical block size can't be determined: Using logical block size of %u bytes", name, dev->phys_block_size);
}
#else
/* if even BLKSSZGET is not available, use default 512b */
if (dev->phys_block_size == -1) {
dev->phys_block_size = 512;
log_debug_devs("%s: Physical block size can't be determined: Using block size of %u bytes instead", name, dev->phys_block_size);
}
#endif
*physical_block_size = (unsigned int) dev->phys_block_size;
*block_size = (unsigned int) dev->block_size;
out:
if (do_close && !dev_close_immediate(dev))
stack;
return r;
}
static int _dev_get_size_file(struct device *dev, uint64_t *size) static int _dev_get_size_file(struct device *dev, uint64_t *size)
{ {
const char *name = dev_name(dev); const char *name = dev_name(dev);
@ -515,8 +444,6 @@ static void _close(struct device *dev)
if (close(dev->fd)) if (close(dev->fd))
log_sys_error("close", dev_name(dev)); log_sys_error("close", dev_name(dev));
dev->fd = -1; dev->fd = -1;
dev->phys_block_size = -1;
dev->block_size = -1;
log_debug_devs("Closed %s", dev_name(dev)); log_debug_devs("Closed %s", dev_name(dev));

View File

@ -67,8 +67,6 @@ struct device {
/* private */ /* private */
int fd; int fd;
int open_count; int open_count;
int phys_block_size; /* From either BLKPBSZGET or BLKSSZGET, don't use */
int block_size; /* From BLKBSZGET, returns bdev->bd_block_size, likely set by fs, probably don't use */
int physical_block_size; /* From BLKPBSZGET: lowest possible sector size that the hardware can operate on without reverting to read-modify-write operations */ int physical_block_size; /* From BLKPBSZGET: lowest possible sector size that the hardware can operate on without reverting to read-modify-write operations */
int logical_block_size; /* From BLKSSZGET: lowest possible block size that the storage device can address */ int logical_block_size; /* From BLKSSZGET: lowest possible block size that the storage device can address */
int read_ahead; int read_ahead;
@ -133,7 +131,6 @@ void dev_size_seqno_inc(void);
/* /*
* All io should use these routines. * All io should use these routines.
*/ */
int dev_get_block_size(struct device *dev, unsigned int *phys_block_size, unsigned int *block_size);
int dev_get_direct_block_sizes(struct device *dev, unsigned int *physical_block_size, int dev_get_direct_block_sizes(struct device *dev, unsigned int *physical_block_size,
unsigned int *logical_block_size); unsigned int *logical_block_size);
int dev_get_size(struct device *dev, uint64_t *size); int dev_get_size(struct device *dev, uint64_t *size);

View File

@ -636,7 +636,7 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg, in
struct pv_list *pvl; struct pv_list *pvl;
struct device *sector_dev; struct device *sector_dev;
uint32_t sector_size = 0; uint32_t sector_size = 0;
unsigned int phys_block_size, block_size; unsigned int physical_block_size, logical_block_size;
int num_mb = 0; int num_mb = 0;
int result; int result;
int ret; int ret;
@ -653,14 +653,14 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg, in
*/ */
dm_list_iterate_items(pvl, &vg->pvs) { dm_list_iterate_items(pvl, &vg->pvs) {
if (!dev_get_block_size(pvl->pv->dev, &phys_block_size, &block_size)) if (!dev_get_direct_block_sizes(pvl->pv->dev, &physical_block_size, &logical_block_size))
continue; continue;
if (!sector_size) { if (!sector_size) {
sector_size = phys_block_size; sector_size = logical_block_size;
sector_dev = pvl->pv->dev; sector_dev = pvl->pv->dev;
} else if (sector_size != phys_block_size) { } else if (sector_size != logical_block_size) {
log_error("Inconsistent sector sizes for %s and %s.", log_error("Inconsistent logical block sizes for %s and %s.",
dev_name(pvl->pv->dev), dev_name(sector_dev)); dev_name(pvl->pv->dev), dev_name(sector_dev));
return 0; return 0;
} }

View File

@ -679,20 +679,21 @@ int vg_remove(struct volume_group *vg)
} }
int check_dev_block_size_for_vg(struct device *dev, const struct volume_group *vg, int check_dev_block_size_for_vg(struct device *dev, const struct volume_group *vg,
unsigned int *max_phys_block_size_found) unsigned int *max_logical_block_size_found)
{ {
unsigned int phys_block_size, block_size; unsigned int physical_block_size, logical_block_size;
if (!(dev_get_block_size(dev, &phys_block_size, &block_size))) if (!(dev_get_direct_block_sizes(dev, &physical_block_size, &logical_block_size)))
return_0; return_0;
if (phys_block_size > *max_phys_block_size_found) /* FIXME: max_logical_block_size_found does not seem to be used anywhere */
*max_phys_block_size_found = phys_block_size; if (logical_block_size > *max_logical_block_size_found)
*max_logical_block_size_found = logical_block_size;
if (phys_block_size >> SECTOR_SHIFT > vg->extent_size) { if (logical_block_size >> SECTOR_SHIFT > vg->extent_size) {
log_error("Physical extent size used for volume group %s " log_error("Physical extent size used for volume group %s "
"is less than physical block size that %s uses.", "is less than logical block size (%u bytes) that %s uses.",
vg->name, dev_name(dev)); vg->name, logical_block_size, dev_name(dev));
return 0; return 0;
} }
@ -702,10 +703,10 @@ int check_dev_block_size_for_vg(struct device *dev, const struct volume_group *v
int vg_check_pv_dev_block_sizes(const struct volume_group *vg) int vg_check_pv_dev_block_sizes(const struct volume_group *vg)
{ {
struct pv_list *pvl; struct pv_list *pvl;
unsigned int max_phys_block_size_found = 0; unsigned int max_logical_block_size_found = 0;
dm_list_iterate_items(pvl, &vg->pvs) { dm_list_iterate_items(pvl, &vg->pvs) {
if (!check_dev_block_size_for_vg(pvl->pv->dev, vg, &max_phys_block_size_found)) if (!check_dev_block_size_for_vg(pvl->pv->dev, vg, &max_logical_block_size_found))
return 0; return 0;
} }
@ -750,7 +751,7 @@ int check_pv_dev_sizes(struct volume_group *vg)
int vg_extend_each_pv(struct volume_group *vg, struct pvcreate_params *pp) int vg_extend_each_pv(struct volume_group *vg, struct pvcreate_params *pp)
{ {
struct pv_list *pvl; struct pv_list *pvl;
unsigned int max_phys_block_size = 0; unsigned int max_logical_block_size = 0;
unsigned int physical_block_size, logical_block_size; unsigned int physical_block_size, logical_block_size;
unsigned int prev_lbs = 0; unsigned int prev_lbs = 0;
int inconsistent_existing_lbs = 0; int inconsistent_existing_lbs = 0;
@ -790,7 +791,7 @@ int vg_extend_each_pv(struct volume_group *vg, struct pvcreate_params *pp)
if (!(check_dev_block_size_for_vg(pvl->pv->dev, if (!(check_dev_block_size_for_vg(pvl->pv->dev,
(const struct volume_group *) vg, (const struct volume_group *) vg,
&max_phys_block_size))) { &max_logical_block_size))) {
log_error("PV %s has wrong block size.", pv_dev_name(pvl->pv)); log_error("PV %s has wrong block size.", pv_dev_name(pvl->pv));
return 0; return 0;
} }