mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
devices: isolate fake device setup for config file
Freeing dev-cache from dumb fake device usage.
This commit is contained in:
parent
92fd2cb498
commit
76bd678ce3
@ -49,7 +49,6 @@ struct config_file {
|
|||||||
off_t st_size;
|
off_t st_size;
|
||||||
char *filename;
|
char *filename;
|
||||||
int exists;
|
int exists;
|
||||||
int keep_open;
|
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -104,7 +103,7 @@ static inline int _is_file_based_config_source(config_source_t source)
|
|||||||
*/
|
*/
|
||||||
struct dm_config_tree *config_open(config_source_t source,
|
struct dm_config_tree *config_open(config_source_t source,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
int keep_open)
|
int unused)
|
||||||
{
|
{
|
||||||
struct dm_config_tree *cft = dm_config_create();
|
struct dm_config_tree *cft = dm_config_create();
|
||||||
struct config_source *cs;
|
struct config_source *cs;
|
||||||
@ -124,7 +123,6 @@ struct dm_config_tree *config_open(config_source_t source,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
cf->keep_open = keep_open;
|
|
||||||
if (filename &&
|
if (filename &&
|
||||||
!(cf->filename = dm_pool_strdup(cft->mem, filename))) {
|
!(cf->filename = dm_pool_strdup(cft->mem, filename))) {
|
||||||
log_error("Failed to duplicate filename.");
|
log_error("Failed to duplicate filename.");
|
||||||
@ -241,22 +239,8 @@ int config_file_changed(struct dm_config_tree *cft)
|
|||||||
|
|
||||||
void config_destroy(struct dm_config_tree *cft)
|
void config_destroy(struct dm_config_tree *cft)
|
||||||
{
|
{
|
||||||
struct config_source *cs;
|
if (cft)
|
||||||
struct config_file *cf;
|
dm_config_destroy(cft);
|
||||||
|
|
||||||
if (!cft)
|
|
||||||
return;
|
|
||||||
|
|
||||||
cs = dm_config_get_custom(cft);
|
|
||||||
|
|
||||||
if (_is_file_based_config_source(cs->type)) {
|
|
||||||
cf = cs->source.file;
|
|
||||||
if (cf && cf->dev)
|
|
||||||
if (!dev_close(cf->dev))
|
|
||||||
stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
dm_config_destroy(cft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dm_config_tree *config_file_open_and_read(const char *config_file,
|
struct dm_config_tree *config_file_open_and_read(const char *config_file,
|
||||||
@ -611,6 +595,10 @@ int config_file_read(struct dm_config_tree *cft)
|
|||||||
struct config_source *cs = dm_config_get_custom(cft);
|
struct config_source *cs = dm_config_get_custom(cft);
|
||||||
struct config_file *cf;
|
struct config_file *cf;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
struct device fake_dev = { 0 };
|
||||||
|
struct dm_str_list *alias;
|
||||||
|
int free_fake = 0;
|
||||||
|
int fd;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!config_file_check(cft, &filename, &info))
|
if (!config_file_check(cft, &filename, &info))
|
||||||
@ -622,25 +610,43 @@ int config_file_read(struct dm_config_tree *cft)
|
|||||||
|
|
||||||
cf = cs->source.file;
|
cf = cs->source.file;
|
||||||
|
|
||||||
if (!cf->dev) {
|
/* fixme: get rid of fake dev and just
|
||||||
if (!(cf->dev = dev_create_file(filename, NULL, NULL, 1)))
|
add separate code paths for files */
|
||||||
return_0;
|
|
||||||
|
|
||||||
if (!dev_open_readonly_buffered(cf->dev)) {
|
if (!cf->dev) {
|
||||||
dev_destroy_file(cf->dev);
|
if (!(alias = zalloc(sizeof(*alias))))
|
||||||
cf->dev = NULL;
|
return_0;
|
||||||
|
if (!(alias->str = strdup(filename))) {
|
||||||
|
free(alias);
|
||||||
return_0;
|
return_0;
|
||||||
}
|
}
|
||||||
|
dev_init(&fake_dev);
|
||||||
|
fake_dev.flags = DEV_REGULAR;
|
||||||
|
dm_list_add(&fake_dev.aliases, &alias->list);
|
||||||
|
|
||||||
|
if ((fd = open(filename, O_RDONLY, 0777)) < 0) {
|
||||||
|
log_error("Failed to open config file %s.", filename);
|
||||||
|
free((void*)alias->str);
|
||||||
|
free((void*)alias);
|
||||||
|
return_0;
|
||||||
|
}
|
||||||
|
fake_dev.fd = fd;
|
||||||
|
free_fake = 1;
|
||||||
|
cf->dev = &fake_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = config_file_read_fd(cft, cf->dev, DEV_IO_MDA_CONTENT, 0, (size_t) info.st_size, 0, 0,
|
r = config_file_read_fd(cft, cf->dev, DEV_IO_MDA_CONTENT, 0, (size_t) info.st_size, 0, 0,
|
||||||
(checksum_fn_t) NULL, 0, 0, 0);
|
(checksum_fn_t) NULL, 0, 0, 0);
|
||||||
|
|
||||||
if (!cf->keep_open) {
|
if (free_fake) {
|
||||||
|
free((void*)alias->str);
|
||||||
|
free((void*)alias);
|
||||||
|
close(fd);
|
||||||
|
} else {
|
||||||
if (!dev_close(cf->dev))
|
if (!dev_close(cf->dev))
|
||||||
stack;
|
stack;
|
||||||
cf->dev = NULL;
|
|
||||||
}
|
}
|
||||||
|
cf->dev = NULL;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -94,66 +94,6 @@ void dev_init(struct device *dev)
|
|||||||
dm_list_init(&dev->wwids);
|
dm_list_init(&dev->wwids);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dev_destroy_file(struct device *dev)
|
|
||||||
{
|
|
||||||
if (!(dev->flags & DEV_ALLOCED))
|
|
||||||
return;
|
|
||||||
|
|
||||||
free((void *) dm_list_item(dev->aliases.n, struct dm_str_list)->str);
|
|
||||||
free(dev->aliases.n);
|
|
||||||
free(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct device *dev_create_file(const char *filename, struct device *dev,
|
|
||||||
struct dm_str_list *alias, int use_malloc)
|
|
||||||
{
|
|
||||||
int allocate = !dev;
|
|
||||||
|
|
||||||
if (allocate) {
|
|
||||||
if (use_malloc) {
|
|
||||||
if (!(dev = zalloc(sizeof(*dev)))) {
|
|
||||||
log_error("struct device allocation failed");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(alias = zalloc(sizeof(*alias)))) {
|
|
||||||
log_error("struct dm_str_list allocation failed");
|
|
||||||
free(dev);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(alias->str = strdup(filename))) {
|
|
||||||
log_error("filename strdup failed");
|
|
||||||
free(dev);
|
|
||||||
free(alias);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!(dev = _zalloc(sizeof(*dev)))) {
|
|
||||||
log_error("struct device allocation failed");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(alias = _zalloc(sizeof(*alias)))) {
|
|
||||||
log_error("struct dm_str_list allocation failed");
|
|
||||||
_free(dev);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(alias->str = _strdup(filename))) {
|
|
||||||
log_error("filename strdup failed");
|
|
||||||
_free(dev);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!(alias->str = strdup(filename))) {
|
|
||||||
log_error("filename strdup failed");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev_init(dev);
|
|
||||||
dev->flags = DEV_REGULAR | ((use_malloc) ? DEV_ALLOCED : 0);
|
|
||||||
dm_list_add(&dev->aliases, &alias->list);
|
|
||||||
|
|
||||||
return dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct device *_dev_create(dev_t d)
|
static struct device *_dev_create(dev_t d)
|
||||||
{
|
{
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
@ -34,6 +34,8 @@ struct dev_filter {
|
|||||||
const char *name;
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void dev_init(struct device *dev);
|
||||||
|
|
||||||
struct dm_list *dev_cache_get_dev_list_for_vgid(const char *vgid);
|
struct dm_list *dev_cache_get_dev_list_for_vgid(const char *vgid);
|
||||||
struct dm_list *dev_cache_get_dev_list_for_lvid(const char *lvid);
|
struct dm_list *dev_cache_get_dev_list_for_lvid(const char *lvid);
|
||||||
|
|
||||||
|
@ -448,11 +448,6 @@ int dev_open_readonly(struct device *dev)
|
|||||||
return dev_open_flags(dev, O_RDONLY, 1, 0);
|
return dev_open_flags(dev, O_RDONLY, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dev_open_readonly_buffered(struct device *dev)
|
|
||||||
{
|
|
||||||
return dev_open_flags(dev, O_RDONLY, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int dev_open_readonly_quiet(struct device *dev)
|
int dev_open_readonly_quiet(struct device *dev)
|
||||||
{
|
{
|
||||||
return dev_open_flags(dev, O_RDONLY, 1, 1);
|
return dev_open_flags(dev, O_RDONLY, 1, 1);
|
||||||
@ -465,9 +460,6 @@ static void _close(struct device *dev)
|
|||||||
dev->fd = -1;
|
dev->fd = -1;
|
||||||
|
|
||||||
log_debug_devs("Closed %s", dev_name(dev));
|
log_debug_devs("Closed %s", dev_name(dev));
|
||||||
|
|
||||||
if (dev->flags & DEV_ALLOCED)
|
|
||||||
dev_destroy_file(dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _dev_close(struct device *dev, int immediate)
|
static int _dev_close(struct device *dev, int immediate)
|
||||||
|
@ -220,7 +220,6 @@ int dev_open(struct device *dev);
|
|||||||
int dev_open_quiet(struct device *dev);
|
int dev_open_quiet(struct device *dev);
|
||||||
int dev_open_flags(struct device *dev, int flags, int direct, int quiet);
|
int dev_open_flags(struct device *dev, int flags, int direct, int quiet);
|
||||||
int dev_open_readonly(struct device *dev);
|
int dev_open_readonly(struct device *dev);
|
||||||
int dev_open_readonly_buffered(struct device *dev);
|
|
||||||
int dev_open_readonly_quiet(struct device *dev);
|
int dev_open_readonly_quiet(struct device *dev);
|
||||||
int dev_close(struct device *dev);
|
int dev_close(struct device *dev);
|
||||||
int dev_close_immediate(struct device *dev);
|
int dev_close_immediate(struct device *dev);
|
||||||
@ -230,10 +229,6 @@ const char *dev_name(const struct device *dev);
|
|||||||
|
|
||||||
void dev_flush(struct device *dev);
|
void dev_flush(struct device *dev);
|
||||||
|
|
||||||
struct device *dev_create_file(const char *filename, struct device *dev,
|
|
||||||
struct dm_str_list *alias, int use_malloc);
|
|
||||||
void dev_destroy_file(struct device *dev);
|
|
||||||
|
|
||||||
int dev_mpath_init(const char *config_wwids_file);
|
int dev_mpath_init(const char *config_wwids_file);
|
||||||
void dev_mpath_exit(void);
|
void dev_mpath_exit(void);
|
||||||
int parse_vpd_ids(const unsigned char *vpd_data, int vpd_datalen, struct dm_list *ids);
|
int parse_vpd_ids(const unsigned char *vpd_data, int vpd_datalen, struct dm_list *ids);
|
||||||
|
@ -5762,7 +5762,6 @@ static int _lv_reduce_vdo_discard(struct cmd_context *cmd,
|
|||||||
if (!dev_discard_max_bytes(cmd->dev_types, dev) ||
|
if (!dev_discard_max_bytes(cmd->dev_types, dev) ||
|
||||||
!dev_discard_granularity(cmd->dev_types, dev)) {
|
!dev_discard_granularity(cmd->dev_types, dev)) {
|
||||||
log_error("%s: max bytes and granularity query fails.", name);
|
log_error("%s: max bytes and granularity query fails.", name);
|
||||||
dev_destroy_file(dev);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5773,11 +5772,9 @@ static int _lv_reduce_vdo_discard(struct cmd_context *cmd,
|
|||||||
if (!dev_discard_blocks(dev, ((uint64_t)lp->extents * vg->extent_size) << SECTOR_SHIFT,
|
if (!dev_discard_blocks(dev, ((uint64_t)lp->extents * vg->extent_size) << SECTOR_SHIFT,
|
||||||
((uint64_t)(lv->le_count - lp->extents) * vg->extent_size) << SECTOR_SHIFT)) {
|
((uint64_t)(lv->le_count - lp->extents) * vg->extent_size) << SECTOR_SHIFT)) {
|
||||||
log_error("%s: discarding failed.", name);
|
log_error("%s: discarding failed.", name);
|
||||||
dev_destroy_file(dev);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_destroy_file(dev);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user