1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

Add common initialization code for struct device

Avoid duplicate code and add _dev_init() where all common
member values are initialized.
This commit is contained in:
Zdenek Kabelac 2011-12-21 13:17:54 +00:00
parent b062ee2826
commit 5146908366
2 changed files with 17 additions and 23 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.89 - Version 2.02.89 -
================================== ==================================
Add function to inialize common structure device members.
Always zalloc device structure during initialization. Always zalloc device structure during initialization.
Fix missing thread list manipulation protection in dmeventd. Fix missing thread list manipulation protection in dmeventd.
Do not derefence lv pointer in _percent_run() function before NULL check. Do not derefence lv pointer in _percent_run() function before NULL check.

View File

@ -54,6 +54,18 @@ static struct {
static int _insert(const char *path, int rec, int check_with_udev_db); static int _insert(const char *path, int rec, int check_with_udev_db);
/* Setup non-zero members of passed zeroed 'struct device' */
static void _dev_init(struct device *dev, int max_error_count)
{
dev->block_size = -1;
dev->fd = -1;
dev->read_ahead = -1;
dev->max_error_count = max_error_count;
dm_list_init(&dev->aliases);
dm_list_init(&dev->open_list);
}
struct device *dev_create_file(const char *filename, struct device *dev, struct device *dev_create_file(const char *filename, struct device *dev,
struct str_list *alias, int use_malloc) struct str_list *alias, int use_malloc)
{ {
@ -76,7 +88,6 @@ struct device *dev_create_file(const char *filename, struct device *dev,
dm_free(alias); dm_free(alias);
return NULL; return NULL;
} }
dev->flags = DEV_ALLOCED;
} else { } else {
if (!(dev = _zalloc(sizeof(*dev)))) { if (!(dev = _zalloc(sizeof(*dev)))) {
log_error("struct device allocation failed"); log_error("struct device allocation failed");
@ -97,19 +108,9 @@ struct device *dev_create_file(const char *filename, struct device *dev,
return NULL; return NULL;
} }
dev->flags |= DEV_REGULAR; _dev_init(dev, NO_DEV_ERROR_COUNT_LIMIT);
dm_list_init(&dev->aliases); dev->flags = DEV_REGULAR | ((use_malloc) ? DEV_ALLOCED : 0);
dm_list_add(&dev->aliases, &alias->list); dm_list_add(&dev->aliases, &alias->list);
dev->end = UINT64_C(0);
dev->dev = 0;
dev->fd = -1;
dev->open_count = 0;
dev->error_count = 0;
dev->max_error_count = NO_DEV_ERROR_COUNT_LIMIT;
dev->block_size = -1;
dev->read_ahead = -1;
memset(dev->pvid, 0, sizeof(dev->pvid));
dm_list_init(&dev->open_list);
return dev; return dev;
} }
@ -122,17 +123,9 @@ static struct device *_dev_create(dev_t d)
log_error("struct device allocation failed"); log_error("struct device allocation failed");
return NULL; return NULL;
} }
dev->flags = 0;
dm_list_init(&dev->aliases); _dev_init(dev, dev_disable_after_error_count());
dev->dev = d; dev->dev = d;
dev->fd = -1;
dev->open_count = 0;
dev->max_error_count = dev_disable_after_error_count();
dev->block_size = -1;
dev->read_ahead = -1;
dev->end = UINT64_C(0);
memset(dev->pvid, 0, sizeof(dev->pvid));
dm_list_init(&dev->open_list);
return dev; return dev;
} }