1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-05 12:19:48 +03:00

Revert "bcache: move from global variable to cmd struct"

This reverts commit 5bf4efbab5.
This commit is contained in:
David Teigland 2024-07-08 15:32:35 -05:00
parent 5bf4efbab5
commit 39e65c8f59
7 changed files with 48 additions and 54 deletions

View File

@ -236,17 +236,6 @@ struct cmd_context {
const char *devicesfile; /* from --devicesfile option */
struct dm_list deviceslist; /* from --devices option, struct dm_str_list */
/*
* Cache of blocks read from devices, generally blocks containing
* headers and metadata from PVs. (It functions more as an i/o layer
* rather than a cache, the caching occurs when blocks are reused
* between label_scan and vg_read.)
* (FIXME: in some cases blocks from LVs are contained here, e.g. for
* zeroing, but that's not the intended use of bcache, and those cases
* should be changed to perform i/o to LVs separately.)
*/
struct bcache *dev_blocks;
/*
* LV dev index.
*/

View File

@ -251,6 +251,11 @@ struct label *label_create(struct labeller *labeller)
return label;
}
/* global variable for accessing the bcache populated by label scan */
/* FIXME/TODO convert to cmd_context */
static struct bcache *scan_bcache;
#define BCACHE_BLOCK_SIZE_IN_SECTORS 256 /* 256*512 = 128K */
static bool _in_bcache(struct device *dev)
@ -636,7 +641,7 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
log_debug_devs("Scanning %d devices for VG info", dm_list_size(devs));
scan_more:
rem_prefetches = bcache_max_prefetches(cmd->dev_blocks);
rem_prefetches = bcache_max_prefetches(scan_bcache);
submit_count = 0;
dm_list_iterate_items_safe(devl, devl2, devs) {
@ -663,7 +668,7 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
}
}
bcache_prefetch(cmd->dev_blocks, devl->dev->bcache_di, 0);
bcache_prefetch(scan_bcache, devl->dev->bcache_di, 0);
rem_prefetches--;
submit_count++;
@ -678,7 +683,7 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
bb = NULL;
is_lvm_device = 0;
if (!bcache_get(cmd->dev_blocks, devl->dev->bcache_di, 0, 0, &bb)) {
if (!bcache_get(scan_bcache, devl->dev->bcache_di, 0, 0, &bb)) {
log_debug_devs("Scan failed to read %s.", dev_name(devl->dev));
scan_read_errors++;
scan_failed_count++;
@ -729,7 +734,7 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
* e.g. to pvcreate them.
*/
if (!is_lvm_device && !want_other_devs) {
_invalidate_di(cmd->dev_blocks, devl->dev->bcache_di);
_invalidate_di(scan_bcache, devl->dev->bcache_di);
_scan_dev_close(devl->dev);
}
@ -764,14 +769,14 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
#define MIN_BCACHE_BLOCKS 32 /* 4MB (32 * 128KB) */
#define MAX_BCACHE_BLOCKS 4096 /* 512MB (4096 * 128KB) */
int label_scan_setup_bcache(struct cmd_context *cmd)
int label_scan_setup_bcache(void)
{
struct io_engine *ioe = NULL;
int iomem_kb = io_memory_size();
int block_size_kb = (BCACHE_BLOCK_SIZE_IN_SECTORS * 512) / 1024;
int cache_blocks;
if (cmd->dev_blocks)
if (scan_bcache)
return 1;
cache_blocks = iomem_kb / block_size_kb;
@ -798,7 +803,7 @@ int label_scan_setup_bcache(struct cmd_context *cmd)
}
}
if (!(cmd->dev_blocks = bcache_create(BCACHE_BLOCK_SIZE_IN_SECTORS, cache_blocks, ioe))) {
if (!(scan_bcache = bcache_create(BCACHE_BLOCK_SIZE_IN_SECTORS, cache_blocks, ioe))) {
log_error("Failed to set up io layer with %d blocks.", cache_blocks);
return 0;
}
@ -885,7 +890,7 @@ int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev
return 0;
}
if (!label_scan_setup_bcache(cmd))
if (!label_scan_setup_bcache())
return_0;
/*
@ -1123,7 +1128,7 @@ int label_scan_vg_online(struct cmd_context *cmd, const char *vgname,
log_debug("label_scan_vg_online: read and filter devs");
label_scan_setup_bcache(cmd);
label_scan_setup_bcache();
dm_list_iterate_items_safe(devl, devl2, &devs) {
struct dev_use *du;
@ -1249,7 +1254,7 @@ int label_scan(struct cmd_context *cmd)
dm_list_init(&scan_devs);
dm_list_init(&hints_list);
if (!label_scan_setup_bcache(cmd))
if (!label_scan_setup_bcache())
return_0;
/*
@ -1548,7 +1553,7 @@ int label_read_pvid(struct device *dev, int *has_pvid)
*/
int label_scan_devs_cached(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs)
{
if (!cmd->dev_blocks)
if (!scan_bcache)
return 0;
_scan_list(cmd, f, devs, 0, NULL);
@ -1568,12 +1573,12 @@ int label_scan_devs(struct cmd_context *cmd, struct dev_filter *f, struct dm_lis
{
struct device_list *devl;
if (!label_scan_setup_bcache(cmd))
if (!label_scan_setup_bcache())
return_0;
dm_list_iterate_items(devl, devs) {
if (_in_bcache(devl->dev))
_invalidate_di(cmd->dev_blocks, devl->dev->bcache_di);
_invalidate_di(scan_bcache, devl->dev->bcache_di);
}
_scan_list(cmd, f, devs, 0, NULL);
@ -1585,12 +1590,12 @@ int label_scan_devs_rw(struct cmd_context *cmd, struct dev_filter *f, struct dm_
{
struct device_list *devl;
if (!label_scan_setup_bcache(cmd))
if (!label_scan_setup_bcache())
return_0;
dm_list_iterate_items(devl, devs) {
if (_in_bcache(devl->dev))
_invalidate_di(cmd->dev_blocks, devl->dev->bcache_di);
_invalidate_di(scan_bcache, devl->dev->bcache_di);
devl->dev->flags |= DEV_BCACHE_WRITE;
}
@ -1624,7 +1629,7 @@ int label_scan_devs_excl(struct cmd_context *cmd, struct dev_filter *f, struct d
void label_scan_invalidate(struct device *dev)
{
if (_in_bcache(dev)) {
_invalidate_di(dev->cmd->dev_blocks, dev->bcache_di);
_invalidate_di(scan_bcache, dev->bcache_di);
_scan_dev_close(dev);
}
}
@ -1701,13 +1706,13 @@ void label_scan_drop(struct cmd_context *cmd)
void label_scan_destroy(struct cmd_context *cmd)
{
if (!cmd->dev_blocks)
if (!scan_bcache)
return;
label_scan_drop(cmd);
bcache_destroy(cmd->dev_blocks);
cmd->dev_blocks = NULL;
bcache_destroy(scan_bcache);
scan_bcache = NULL;
}
/*
@ -1759,7 +1764,7 @@ int label_scan_open_excl(struct device *dev)
{
if (_in_bcache(dev) && !(dev->flags & DEV_BCACHE_EXCL)) {
log_debug("close and reopen excl %s", dev_name(dev));
_invalidate_di(dev->cmd->dev_blocks, dev->bcache_di);
_invalidate_di(scan_bcache, dev->bcache_di);
_scan_dev_close(dev);
}
dev->flags |= DEV_BCACHE_EXCL;
@ -1771,7 +1776,7 @@ int label_scan_open_rw(struct device *dev)
{
if (_in_bcache(dev) && !(dev->flags & DEV_BCACHE_WRITE)) {
log_debug("close and reopen rw %s", dev_name(dev));
_invalidate_di(dev->cmd->dev_blocks, dev->bcache_di);
_invalidate_di(scan_bcache, dev->bcache_di);
_scan_dev_close(dev);
}
dev->flags |= DEV_BCACHE_WRITE;
@ -1858,7 +1863,7 @@ int label_scan_reopen_rw(struct device *dev)
bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data)
{
if (!dev->cmd->dev_blocks) {
if (!scan_bcache) {
/* Should not happen */
log_error("dev_read bcache not set up %s", dev_name(dev));
return false;
@ -1873,7 +1878,7 @@ bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data)
}
}
if (!bcache_read_bytes(dev->cmd->dev_blocks, dev->bcache_di, start, len, data)) {
if (!bcache_read_bytes(scan_bcache, dev->bcache_di, start, len, data)) {
log_error("Error reading device %s at %llu length %u.",
dev_name(dev), (unsigned long long)start, (uint32_t)len);
label_scan_invalidate(dev);
@ -1888,7 +1893,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
if (test_mode())
return true;
if (!dev->cmd->dev_blocks) {
if (!scan_bcache) {
/* Should not happen */
log_error("dev_write bcache not set up %s", dev_name(dev));
return false;
@ -1897,7 +1902,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
if (_in_bcache(dev) && !(dev->flags & DEV_BCACHE_WRITE)) {
/* FIXME: avoid tossing out bcache blocks just to replace fd. */
log_debug("close and reopen to write %s", dev_name(dev));
_invalidate_di(dev->cmd->dev_blocks, dev->bcache_di);
_invalidate_di(scan_bcache, dev->bcache_di);
_scan_dev_close(dev);
dev->flags |= DEV_BCACHE_WRITE;
@ -1914,7 +1919,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
}
}
if (!bcache_write_bytes(dev->cmd->dev_blocks, dev->bcache_di, start, len, data)) {
if (!bcache_write_bytes(scan_bcache, dev->bcache_di, start, len, data)) {
log_error("Error writing device %s at %llu length %u.",
dev_name(dev), (unsigned long long)start, (uint32_t)len);
dev_unset_last_byte(dev);
@ -1922,7 +1927,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
return false;
}
if (!bcache_flush(dev->cmd->dev_blocks)) {
if (!bcache_flush(scan_bcache)) {
log_error("Error writing device %s at %llu length %u.",
dev_name(dev), (unsigned long long)start, (uint32_t)len);
dev_unset_last_byte(dev);
@ -1934,12 +1939,12 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
bool dev_invalidate_bytes(struct device *dev, uint64_t start, size_t len)
{
return bcache_invalidate_bytes(dev->cmd->dev_blocks, dev->bcache_di, start, len);
return bcache_invalidate_bytes(scan_bcache, dev->bcache_di, start, len);
}
void dev_invalidate(struct device *dev)
{
bcache_invalidate_di(dev->cmd->dev_blocks, dev->bcache_di);
bcache_invalidate_di(scan_bcache, dev->bcache_di);
}
bool dev_write_zeros(struct device *dev, uint64_t start, size_t len)
@ -1954,14 +1959,14 @@ bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val)
if (test_mode())
return true;
if (!dev->cmd->dev_blocks) {
if (!scan_bcache) {
log_error("dev_set_bytes bcache not set up %s", dev_name(dev));
return false;
}
if (_in_bcache(dev) && !(dev->flags & DEV_BCACHE_WRITE)) {
log_debug("close and reopen to write %s", dev_name(dev));
_invalidate_di(dev->cmd->dev_blocks, dev->bcache_di);
_invalidate_di(scan_bcache, dev->bcache_di);
_scan_dev_close(dev);
/* goes to label_scan_open() since bcache_di < 0 */
}
@ -1979,9 +1984,9 @@ bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val)
dev_set_last_byte(dev, start + len);
if (!val)
rv = bcache_zero_bytes(dev->cmd->dev_blocks, dev->bcache_di, start, len);
rv = bcache_zero_bytes(scan_bcache, dev->bcache_di, start, len);
else
rv = bcache_set_bytes(dev->cmd->dev_blocks, dev->bcache_di, start, len, val);
rv = bcache_set_bytes(scan_bcache, dev->bcache_di, start, len, val);
if (!rv) {
log_error("Error writing device value %s at %llu length %u.",
@ -1989,7 +1994,7 @@ bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val)
goto fail;
}
if (!bcache_flush(dev->cmd->dev_blocks)) {
if (!bcache_flush(scan_bcache)) {
log_error("Error writing device %s at %llu length %u.",
dev_name(dev), (unsigned long long)start, (uint32_t)len);
goto fail;
@ -2033,10 +2038,10 @@ void dev_set_last_byte(struct device *dev, uint64_t offset)
bs = 512;
}
bcache_set_last_byte(dev->cmd->dev_blocks, dev->bcache_di, offset, bs);
bcache_set_last_byte(scan_bcache, dev->bcache_di, offset, bs);
}
void dev_unset_last_byte(struct device *dev)
{
bcache_unset_last_byte(dev->cmd->dev_blocks, dev->bcache_di);
bcache_unset_last_byte(scan_bcache, dev->bcache_di);
}

View File

@ -111,7 +111,7 @@ void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv
void label_scan_invalidate_lvs(struct cmd_context *cmd, struct dm_list *lvs);
void label_scan_drop(struct cmd_context *cmd);
void label_scan_destroy(struct cmd_context *cmd);
int label_scan_setup_bcache(struct cmd_context *cmd);
int label_scan_setup_bcache(void);
int label_scan_open(struct device *dev);
int label_scan_open_excl(struct device *dev);
int label_scan_open_rw(struct device *dev);

View File

@ -628,7 +628,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
unlink_searched_devnames(cmd);
label_scan_setup_bcache(cmd);
label_scan_setup_bcache();
dm_list_iterate_items(du, &cmd->use_devices) {
if (!du->dev)
@ -806,7 +806,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* reads pvid from dev header, sets dev->pvid.
* (it's ok if the device is not a PV and has no PVID)
*/
label_scan_setup_bcache(cmd);
label_scan_setup_bcache();
if (!label_read_pvid(dev, NULL)) {
log_error("Failed to read %s.", devname);
goto bad;
@ -845,7 +845,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
char pvid[ID_LEN+1] = { 0 };
const char *pvid_arg;
label_scan_setup_bcache(cmd);
label_scan_setup_bcache();
/*
* Iterate through all devs on the system, reading the

View File

@ -3073,7 +3073,7 @@ static int _pvck_mf(struct metadata_file *mf, struct cmd_context *cmd, int argc,
return_ECMD_FAILED;
}
label_scan_setup_bcache(cmd);
label_scan_setup_bcache();
if (dev) {
char buf[4096];

View File

@ -1571,7 +1571,7 @@ static int _pvscan_cache_args(struct cmd_context *cmd, int argc, char **argv,
log_debug("pvscan_cache_args: read and filter devs");
label_scan_setup_bcache(cmd);
label_scan_setup_bcache();
dm_list_iterate_items_safe(devl, devl2, &pvscan_devs) {
int has_pvid;

View File

@ -287,7 +287,7 @@ int vgimportclone(struct cmd_context *cmd, int argc, char **argv)
*/
log_debug("scan new devs");
label_scan_setup_bcache(cmd);
label_scan_setup_bcache();
cmd->filter_nodata_only = 0;