]> sourceware.org Git - lvm2.git/commitdiff
devices: clean up block size functions
authorDavid Teigland <teigland@redhat.com>
Wed, 7 Aug 2019 16:38:06 +0000 (11:38 -0500)
committerDavid Teigland <teigland@redhat.com>
Wed, 7 Aug 2019 16:48:10 +0000 (11:48 -0500)
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.

lib/device/dev-cache.c
lib/device/dev-io.c
lib/device/device.h
lib/locking/lvmlockd.c
lib/metadata/metadata.c

index 980dd3cbc2cf0571f8aa066f5e7753809e5e2433..a15e239ecfee42f2ff8ed6c646ae1e59264a7b20 100644 (file)
@@ -64,8 +64,6 @@ static int _insert(const char *path, const struct stat *info,
 /* 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;
 
index 5fa0b7a9e6f18a7a28d4dacd338b92f39756c11b..8a9ed5c7335212c598ddf65df4356b4f5aefb99a 100644 (file)
 
 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);
@@ -515,8 +444,6 @@ static void _close(struct device *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));
 
index bb65f841d482c44e28ba4a7fc3f55ec413d61108..bd3b35557674af05dc3a4e79076486e69f176525 100644 (file)
@@ -67,8 +67,6 @@ struct device {
        /* 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;
@@ -133,7 +131,6 @@ void dev_size_seqno_inc(void);
 /*
  * 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);
index 5ef3c94faf09179c1f1ac76ce1231347b9f04a06..612de5d22a8a4918134e294289cb00a02494c3d6 100644 (file)
@@ -636,7 +636,7 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg, in
        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;
@@ -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) {
-               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;
                }
index e55adc2125a93ce7c1d3a5b9220ff399d8575ee6..0f5154dec3518144be3f9812ac93fa6450fa8330 100644 (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,
-                               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;
        }
 
@@ -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)
 {
        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;
        }
 
@@ -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)
 {
        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;
@@ -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,
                                                  (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;
                }
This page took 0.042408 seconds and 5 git commands to generate.