summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2016-03-09 11:25:07 +0100
committerPeter Rajnoha <prajnoha@redhat.com>2016-03-09 13:28:17 +0100
commit62e799cbd10a68bc055d58e295c52d86ca60735f (patch)
tree8db56b96aa3df91111bfb806bdf72a54c2d7c31d
parent55d1105fc9f7e81bdca0f4d489d157b79350cac8 (diff)
downloadlvm2-62e799cbd10a68bc055d58e295c52d86ca60735f.tar.gz
dev-cache: add 'struct slave_list', 'slaves' field in struct device and 'custom_index' in dev cache
-rw-r--r--lib/device/dev-cache.c16
-rw-r--r--lib/device/dev-cache.h1
-rw-r--r--lib/device/device.h6
3 files changed, 23 insertions, 0 deletions
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 47ae1403e..829bfa33d 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -38,6 +38,7 @@ struct dir_list {
static struct {
struct dm_pool *mem;
struct dm_hash_table *names;
+ struct dm_hash_table *custom_index;
struct btree *devices;
struct dm_regex *preferred_names_matcher;
const char *dev_dir;
@@ -64,6 +65,8 @@ static void _dev_init(struct device *dev, int max_error_count)
dev->read_ahead = -1;
dev->max_error_count = max_error_count;
+ dm_list_init(&dev->slaves);
+
dev->ext.enabled = 0;
dev->ext.src = DEV_EXT_NONE;
@@ -757,6 +760,11 @@ int dev_cache_init(struct cmd_context *cmd)
return_0;
}
+ if (!(_cache.custom_index = dm_hash_create(128))) {
+ log_error("Couldn't create custom index for dev-cache.");
+ goto bad;
+ }
+
if (!(_cache.devices = btree_create(_cache.mem))) {
log_error("Couldn't create binary tree for dev-cache.");
goto bad;
@@ -822,6 +830,9 @@ int dev_cache_exit(void)
if (_cache.mem)
dm_pool_destroy(_cache.mem);
+ if (_cache.custom_index)
+ dm_hash_destroy(_cache.custom_index);
+
if (_cache.names)
dm_hash_destroy(_cache.names);
@@ -974,6 +985,11 @@ struct device *dev_cache_get(const char *name, struct dev_filter *f)
return d;
}
+struct device *dev_cache_get_by_custom_key(const char *key)
+{
+ return dm_hash_lookup(_cache.custom_index, key);
+}
+
static struct device *_dev_cache_seek_devt(dev_t dev)
{
struct device *d = NULL;
diff --git a/lib/device/dev-cache.h b/lib/device/dev-cache.h
index 05911d468..a69091d57 100644
--- a/lib/device/dev-cache.h
+++ b/lib/device/dev-cache.h
@@ -51,6 +51,7 @@ int dev_cache_add_dir(const char *path);
int dev_cache_add_loopfile(const char *path);
__attribute__((nonnull(1)))
struct device *dev_cache_get(const char *name, struct dev_filter *f);
+struct device *dev_cache_get_by_custom_key(const char *key);
// TODO
struct device *dev_cache_get_by_devt(dev_t device, struct dev_filter *f);
diff --git a/lib/device/device.h b/lib/device/device.h
index 6b01fb6e7..93b71ae55 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -45,6 +45,11 @@ struct dev_ext {
void *handle;
};
+struct slave_list {
+ struct dm_list list;
+ dev_t devno;
+};
+
/*
* All devices in LVM will be represented by one of these.
* pointer comparisons are valid.
@@ -67,6 +72,7 @@ struct device {
uint64_t end;
struct dm_list open_list;
struct dev_ext ext;
+ struct dm_list slaves;
char pvid[ID_LEN + 1];
char _padding[7];