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

label: simplify code

This commit is contained in:
Zdenek Kabelac 2024-01-26 16:08:54 +01:00
parent d486b379d0
commit c534cf3bca

View File

@ -769,13 +769,16 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
#define MIN_BCACHE_BLOCKS 32 /* 4MB (32 * 128KB) */ #define MIN_BCACHE_BLOCKS 32 /* 4MB (32 * 128KB) */
#define MAX_BCACHE_BLOCKS 4096 /* 512MB (4096 * 128KB) */ #define MAX_BCACHE_BLOCKS 4096 /* 512MB (4096 * 128KB) */
static int _setup_bcache(void) int label_scan_setup_bcache(void)
{ {
struct io_engine *ioe = NULL; struct io_engine *ioe = NULL;
int iomem_kb = io_memory_size(); int iomem_kb = io_memory_size();
int block_size_kb = (BCACHE_BLOCK_SIZE_IN_SECTORS * 512) / 1024; int block_size_kb = (BCACHE_BLOCK_SIZE_IN_SECTORS * 512) / 1024;
int cache_blocks; int cache_blocks;
if (scan_bcache)
return 1;
cache_blocks = iomem_kb / block_size_kb; cache_blocks = iomem_kb / block_size_kb;
if (cache_blocks < MIN_BCACHE_BLOCKS) if (cache_blocks < MIN_BCACHE_BLOCKS)
@ -909,10 +912,8 @@ int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev
}; };
dev_iter_destroy(iter); dev_iter_destroy(iter);
if (!scan_bcache) { if (!label_scan_setup_bcache())
if (!_setup_bcache()) goto_out;
goto_out;
}
log_debug_devs("Reading labels for pvid"); log_debug_devs("Reading labels for pvid");
@ -1266,10 +1267,8 @@ int label_scan(struct cmd_context *cmd)
dm_list_init(&scan_devs); dm_list_init(&scan_devs);
dm_list_init(&hints_list); dm_list_init(&hints_list);
if (!scan_bcache) { if (!label_scan_setup_bcache())
if (!_setup_bcache()) return_0;
return_0;
}
/* /*
* Creates a list of available devices, does not open or read any, * Creates a list of available devices, does not open or read any,
@ -1505,12 +1504,10 @@ int label_scan(struct cmd_context *cmd)
*/ */
int label_read_pvid(struct device *dev, int *has_pvid) int label_read_pvid(struct device *dev, int *has_pvid)
{ {
char buf[4096] __attribute__((aligned(8))); char buf[4096] __attribute__((aligned(8))) = { 0 };
struct label_header *lh; struct label_header *lh;
struct pv_header *pvh; struct pv_header *pvh;
memset(buf, 0, sizeof(buf));
if (!label_scan_open(dev)) if (!label_scan_open(dev))
return_0; return_0;
@ -1580,10 +1577,8 @@ int label_scan_devs(struct cmd_context *cmd, struct dev_filter *f, struct dm_lis
{ {
struct device_list *devl; struct device_list *devl;
if (!scan_bcache) { if (!label_scan_setup_bcache())
if (!_setup_bcache()) return_0;
return 0;
}
dm_list_iterate_items(devl, devs) { dm_list_iterate_items(devl, devs) {
if (_in_bcache(devl->dev)) if (_in_bcache(devl->dev))
@ -1599,10 +1594,8 @@ int label_scan_devs_rw(struct cmd_context *cmd, struct dev_filter *f, struct dm_
{ {
struct device_list *devl; struct device_list *devl;
if (!scan_bcache) { if (!label_scan_setup_bcache())
if (!_setup_bcache()) return_0;
return 0;
}
dm_list_iterate_items(devl, devs) { dm_list_iterate_items(devl, devs) {
if (_in_bcache(devl->dev)) if (_in_bcache(devl->dev))
@ -1776,16 +1769,6 @@ int label_scan_dev(struct cmd_context *cmd, struct device *dev)
return 1; return 1;
} }
int label_scan_setup_bcache(void)
{
if (!scan_bcache) {
if (!_setup_bcache())
return 0;
}
return 1;
}
/* /*
* This is needed to write to a new non-lvm device. * This is needed to write to a new non-lvm device.
* Scanning that dev would not keep it open or in * Scanning that dev would not keep it open or in