/* Setup non-zero members of passed zeroed 'struct device' */
static void _dev_init(struct device *dev)
{
- dev->phys_block_size = -1;
- dev->block_size = -1;
dev->fd = -1;
dev->read_ahead = -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)
{
const char *name = dev_name(dev);
if (close(dev->fd))
log_sys_error("close", dev_name(dev));
dev->fd = -1;
- dev->phys_block_size = -1;
- dev->block_size = -1;
log_debug_devs("Closed %s", dev_name(dev));
/* private */
int fd;
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 logical_block_size; /* From BLKSSZGET: lowest possible block size that the storage device can address */
int read_ahead;
/*
* 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,
unsigned int *logical_block_size);
int dev_get_size(struct device *dev, uint64_t *size);
struct pv_list *pvl;
struct device *sector_dev;
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 result;
int ret;
*/
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;
if (!sector_size) {
- sector_size = phys_block_size;
+ sector_size = logical_block_size;
sector_dev = pvl->pv->dev;
- } else if (sector_size != phys_block_size) {
- log_error("Inconsistent sector sizes for %s and %s.",
+ } else if (sector_size != logical_block_size) {
+ log_error("Inconsistent logical block sizes for %s and %s.",
dev_name(pvl->pv->dev), dev_name(sector_dev));
return 0;
}
}
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;
- if (phys_block_size > *max_phys_block_size_found)
- *max_phys_block_size_found = phys_block_size;
+ /* FIXME: max_logical_block_size_found does not seem to be used anywhere */
+ 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 "
- "is less than physical block size that %s uses.",
- vg->name, dev_name(dev));
+ "is less than logical block size (%u bytes) that %s uses.",
+ vg->name, logical_block_size, dev_name(dev));
return 0;
}
int vg_check_pv_dev_block_sizes(const struct volume_group *vg)
{
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) {
- 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;
}
int vg_extend_each_pv(struct volume_group *vg, struct pvcreate_params *pp)
{
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 prev_lbs = 0;
int inconsistent_existing_lbs = 0;
if (!(check_dev_block_size_for_vg(pvl->pv->dev,
(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));
return 0;
}