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

label: use formaters FMTu64 and FMTsize_t

Produces code without casts to differntly signed types
and also shortens and enhances readbility.
This commit is contained in:
Zdenek Kabelac 2020-09-15 21:47:39 +02:00
parent 2b36542f41
commit d0ccb2521b

View File

@ -132,8 +132,8 @@ int label_remove(struct device *dev)
memset(readbuf, 0, sizeof(readbuf)); memset(readbuf, 0, sizeof(readbuf));
if (!dev_read_bytes(dev, sector << SECTOR_SHIFT, LABEL_SIZE, readbuf)) { if (!dev_read_bytes(dev, sector << SECTOR_SHIFT, LABEL_SIZE, readbuf)) {
log_error("Failed to read label from %s sector %llu", log_error("Failed to read label from %s sector " FMTu64,
dev_name(dev), (unsigned long long)sector); dev_name(dev), sector);
continue; continue;
} }
@ -154,12 +154,12 @@ int label_remove(struct device *dev)
} }
if (wipe) { if (wipe) {
log_very_verbose("%s: Wiping label at sector %llu", log_very_verbose("%s: Wiping label at sector " FMTu64,
dev_name(dev), (unsigned long long)sector); dev_name(dev), sector);
if (!dev_write_zeros(dev, sector << SECTOR_SHIFT, LABEL_SIZE)) { if (!dev_write_zeros(dev, sector << SECTOR_SHIFT, LABEL_SIZE)) {
log_error("Failed to remove label from %s at sector %llu", log_error("Failed to remove label from %s at sector " FMTu64,
dev_name(dev), (unsigned long long)sector); dev_name(dev), sector);
r = 0; r = 0;
} else { } else {
/* Also remove the PV record from cache. */ /* Also remove the PV record from cache. */
@ -187,7 +187,7 @@ int label_write(struct device *dev, struct label *label)
} }
if ((LABEL_SIZE + (label->sector << SECTOR_SHIFT)) > LABEL_SCAN_SIZE) { if ((LABEL_SIZE + (label->sector << SECTOR_SHIFT)) > LABEL_SCAN_SIZE) {
log_error("Label sector %" PRIu64 " beyond range (%ld)", log_error("Label sector " FMTu64 " beyond range (%ld)",
label->sector, LABEL_SCAN_SECTORS); label->sector, LABEL_SCAN_SECTORS);
return 0; return 0;
} }
@ -204,8 +204,8 @@ int label_write(struct device *dev, struct label *label)
lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl, LABEL_SIZE - lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl, LABEL_SIZE -
((uint8_t *) &lh->offset_xl - (uint8_t *) lh))); ((uint8_t *) &lh->offset_xl - (uint8_t *) lh)));
log_very_verbose("%s: Writing label to sector %" PRIu64 " with stored offset %" log_very_verbose("%s: Writing label to sector " FMTu64 " with stored offset "
PRIu32 ".", dev_name(dev), label->sector, FMTu32 ".", dev_name(dev), label->sector,
xlate32(lh->offset_xl)); xlate32(lh->offset_xl));
if (!label_scan_open(dev)) { if (!label_scan_open(dev)) {
@ -297,14 +297,13 @@ static struct labeller *_find_lvm_header(struct device *dev,
if (!memcmp(lh->id, LABEL_ID, sizeof(lh->id))) { if (!memcmp(lh->id, LABEL_ID, sizeof(lh->id))) {
if (found) { if (found) {
log_error("Ignoring additional label on %s at sector %llu", log_error("Ignoring additional label on %s at sector " FMTu64,
dev_name(dev), (unsigned long long)(block_sector + sector)); dev_name(dev), (block_sector + sector));
} }
if (xlate64(lh->sector_xl) != sector) { if (xlate64(lh->sector_xl) != sector) {
log_warn("%s: Label for sector %llu found at sector %llu - ignoring.", log_warn("%s: Label for sector " FMTu64 " found at sector " FMTu64 " - ignoring.",
dev_name(dev), dev_name(dev), xlate64(lh->sector_xl),
(unsigned long long)xlate64(lh->sector_xl), (block_sector + sector));
(unsigned long long)(block_sector + sector));
continue; continue;
} }
if (calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl, if (calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl,
@ -318,13 +317,13 @@ static struct labeller *_find_lvm_header(struct device *dev,
dm_list_iterate_items(li, &_labellers) { dm_list_iterate_items(li, &_labellers) {
if (li->l->ops->can_handle(li->l, (char *) lh, block_sector + sector)) { if (li->l->ops->can_handle(li->l, (char *) lh, block_sector + sector)) {
log_very_verbose("%s: %s label detected at sector %llu", log_very_verbose("%s: %s label detected at sector " FMTu64,
dev_name(dev), li->name, dev_name(dev), li->name,
(unsigned long long)(block_sector + sector)); (block_sector + sector));
if (found) { if (found) {
log_error("Ignoring additional label on %s at sector %llu", log_error("Ignoring additional label on %s at sector " FMTu64,
dev_name(dev), dev_name(dev),
(unsigned long long)(block_sector + sector)); (block_sector + sector));
continue; continue;
} }
@ -1137,8 +1136,8 @@ int label_scan(struct cmd_context *cmd)
log_warn("WARNING: metadata may not be usable with current io_memory_size %d KiB", log_warn("WARNING: metadata may not be usable with current io_memory_size %d KiB",
io_memory_size()); io_memory_size());
log_warn("WARNING: increase lvm.conf io_memory_size to at least %llu KiB", log_warn("WARNING: increase lvm.conf io_memory_size to at least " FMTu64 " KiB",
(unsigned long long)want_size_kb); want_size_kb);
} }
dm_list_init(&cmd->hints); dm_list_init(&cmd->hints);
@ -1442,15 +1441,15 @@ bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data)
if (dev->bcache_fd <= 0) { if (dev->bcache_fd <= 0) {
/* This is not often needed. */ /* This is not often needed. */
if (!label_scan_open(dev)) { if (!label_scan_open(dev)) {
log_error("Error opening device %s for reading at %llu length %u.", log_error("Error opening device %s for reading at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
return false; return false;
} }
} }
if (!bcache_read_bytes(scan_bcache, dev->bcache_fd, start, len, data)) { if (!bcache_read_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
log_error("Error reading device %s at %llu length %u.", log_error("Error reading device %s at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
label_scan_invalidate(dev); label_scan_invalidate(dev);
return false; return false;
} }
@ -1483,23 +1482,23 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
/* This is not often needed. */ /* This is not often needed. */
dev->flags |= DEV_BCACHE_WRITE; dev->flags |= DEV_BCACHE_WRITE;
if (!label_scan_open(dev)) { if (!label_scan_open(dev)) {
log_error("Error opening device %s for writing at %llu length %u.", log_error("Error opening device %s for writing at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
return false; return false;
} }
} }
if (!bcache_write_bytes(scan_bcache, dev->bcache_fd, start, len, data)) { if (!bcache_write_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
log_error("Error writing device %s at %llu length %u.", log_error("Error writing device %s at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
dev_unset_last_byte(dev); dev_unset_last_byte(dev);
label_scan_invalidate(dev); label_scan_invalidate(dev);
return false; return false;
} }
if (!bcache_flush(scan_bcache)) { if (!bcache_flush(scan_bcache)) {
log_error("Error writing device %s at %llu length %u.", log_error("Error writing device %s at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
dev_unset_last_byte(dev); dev_unset_last_byte(dev);
label_scan_invalidate(dev); label_scan_invalidate(dev);
return false; return false;
@ -1539,8 +1538,8 @@ bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val)
/* This is not often needed. */ /* This is not often needed. */
dev->flags |= DEV_BCACHE_WRITE; dev->flags |= DEV_BCACHE_WRITE;
if (!label_scan_open(dev)) { if (!label_scan_open(dev)) {
log_error("Error opening device %s for writing at %llu length %u.", log_error("Error opening device %s for writing at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
return false; return false;
} }
} }
@ -1549,16 +1548,16 @@ bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val)
if ((!val && !bcache_zero_bytes(scan_bcache, dev->bcache_fd, start, len)) || if ((!val && !bcache_zero_bytes(scan_bcache, dev->bcache_fd, start, len)) ||
!bcache_set_bytes(scan_bcache, dev->bcache_fd, start, len, val)) { !bcache_set_bytes(scan_bcache, dev->bcache_fd, start, len, val)) {
log_error("Error writing device %s at %llu length %u.", log_error("Error writing device %s at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
dev_unset_last_byte(dev); dev_unset_last_byte(dev);
label_scan_invalidate(dev); label_scan_invalidate(dev);
return false; return false;
} }
if (!bcache_flush(scan_bcache)) { if (!bcache_flush(scan_bcache)) {
log_error("Error writing device %s at %llu length %u.", log_error("Error writing device %s at " FMTu64 " length " FMTsize_t ".",
dev_name(dev), (unsigned long long)start, (uint32_t)len); dev_name(dev), start, len);
dev_unset_last_byte(dev); dev_unset_last_byte(dev);
label_scan_invalidate(dev); label_scan_invalidate(dev);
return false; return false;