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

dev-type: get swap device size from blkid using FSSIZE

blkid does not report FSLASTBLOCK for a swap device. However, blkid
does report FSSIZE for swap devices, so use this field (and including
the header size which is of FSBLOCKSIZE for the swap) instead to
set the "filesystem last block" which is used subsequently for
further calculations and conditions.
This commit is contained in:
Peter Rajnoha 2024-09-19 12:39:46 +02:00
parent 4524778b23
commit e009becd73
No known key found for this signature in database
GPG Key ID: E776664036DF84AB

View File

@ -943,6 +943,7 @@ int fs_get_blkid(const char *pathname, struct fs_info *fsi)
const char *str = ""; const char *str = "";
size_t len = 0; size_t len = 0;
uint64_t fslastblock = 0; uint64_t fslastblock = 0;
uint64_t fssize = 0;
unsigned int fsblocksize = 0; unsigned int fsblocksize = 0;
int rc; int rc;
@ -993,10 +994,25 @@ int fs_get_blkid(const char *pathname, struct fs_info *fsi)
if (!blkid_probe_lookup_value(probe, "FSBLOCKSIZE", &str, &len) && len) if (!blkid_probe_lookup_value(probe, "FSBLOCKSIZE", &str, &len) && len)
fsblocksize = (unsigned int)atoi(str); fsblocksize = (unsigned int)atoi(str);
if (!blkid_probe_lookup_value(probe, "FSSIZE", &str, &len) && len)
fssize = strtoull(str, NULL, 0);
blkid_free_probe(probe); blkid_free_probe(probe);
if (fslastblock && fsblocksize) if (fslastblock && fsblocksize)
fsi->fs_last_byte = fslastblock * fsblocksize; fsi->fs_last_byte = fslastblock * fsblocksize;
else if (fssize) {
fsi->fs_last_byte = fssize;
/*
* For swap, there's no FSLASTBLOCK reported by blkid. We do have FSSIZE reported though.
* The last block is then calculated as:
* FSSIZE (== size of the usable swap area) + FSBLOCKSIZE (== size of the swap header)
*/
if (!strcmp(fsi->fstype, "swap"))
fsi->fs_last_byte += fsblocksize;
}
log_debug("libblkid TYPE %s BLOCK_SIZE %d FSLASTBLOCK %llu FSBLOCKSIZE %u fs_last_byte %llu", log_debug("libblkid TYPE %s BLOCK_SIZE %d FSLASTBLOCK %llu FSBLOCKSIZE %u fs_last_byte %llu",
fsi->fstype, fsi->fs_block_size_bytes, (unsigned long long)fslastblock, fsblocksize, fsi->fstype, fsi->fs_block_size_bytes, (unsigned long long)fslastblock, fsblocksize,