1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-04-25 02:51:16 +03:00

more str_list fns

This commit is contained in:
Alasdair Kergon 2003-10-15 20:04:29 +00:00
parent f2b7349e2f
commit ac21f47034
3 changed files with 53 additions and 26 deletions

22
lib/cache/lvmcache.c vendored
View File

@ -13,6 +13,7 @@
#include "metadata.h"
#include "filter.h"
#include "memlock.h"
#include "str_list.h"
static struct hash_table *_pvid_hash = NULL;
static struct hash_table *_vgid_hash = NULL;
@ -207,31 +208,22 @@ int lvmcache_label_scan(struct cmd_context *cmd, int full_scan)
struct list *lvmcache_get_vgnames(struct cmd_context *cmd, int full_scan)
{
struct list *vgih, *vgnames;
struct str_list *sl;
struct list *vgnames;
struct lvmcache_vginfo *vgi;
lvmcache_label_scan(cmd, full_scan);
if (!(vgnames = pool_alloc(cmd->mem, sizeof(struct list)))) {
if (!(vgnames = str_list_create(cmd->mem))) {
log_error("vgnames list allocation failed");
return NULL;
}
list_init(vgnames);
list_iterate(vgih, &_vginfos) {
if (!(sl = pool_alloc(cmd->mem, sizeof(*sl)))) {
list_iterate_items(vgi, &_vginfos) {
if (!str_list_add(cmd->mem, vgnames,
pool_strdup(cmd->mem, vgi->vgname))) {
log_error("strlist allocation failed");
return NULL;
}
if (!(sl->str = pool_strdup(cmd->mem,
list_item(vgih,
struct lvmcache_vginfo)->
vgname))) {
log_error("vgname allocation failed");
return NULL;
}
list_add(vgnames, &sl->list);
}
return vgnames;

View File

@ -7,10 +7,23 @@
#include "lib.h"
#include "str_list.h"
int str_list_add(struct pool *mem, struct list *sl, const char *str)
struct list *str_list_create(struct pool *mem)
{
struct list *sl;
if (!(sl = pool_alloc(mem, sizeof(struct list)))) {
stack;
return NULL;
}
list_init(sl);
return sl;
}
int str_list_add(struct pool *mem, struct list *sll, const char *str)
{
struct str_list *sln;
struct list *slh;
if (!str) {
stack;
@ -18,10 +31,8 @@ int str_list_add(struct pool *mem, struct list *sl, const char *str)
}
/* Already in list? */
list_iterate(slh, sl) {
if (!strcmp(str, list_item(slh, struct str_list)->str))
return 1;
}
if (str_list_match_item(sll, str))
return 1;
if (!(sln = pool_alloc(mem, sizeof(*sln)))) {
stack;
@ -29,16 +40,16 @@ int str_list_add(struct pool *mem, struct list *sl, const char *str)
}
sln->str = str;
list_add(sl, &sln->list);
list_add(sll, &sln->list);
return 1;
}
int str_list_del(struct list *sl, const char *str)
int str_list_del(struct list *sll, const char *str)
{
struct list *slh, *slht;
list_iterate_safe(slh, slht, sl) {
list_iterate_safe(slh, slht, sll) {
if (!strcmp(str, list_item(slh, struct str_list)->str))
list_del(slh);
}
@ -46,3 +57,24 @@ int str_list_del(struct list *sl, const char *str)
return 1;
}
int str_list_match_item(struct list *sll, const char *str)
{
struct str_list *sl;
list_iterate_items(sl, sll)
if (!strcmp(str, sl->str))
return 1;
return 0;
}
int str_list_match_list(struct list *sll, struct list *sll2)
{
struct str_list *sl;
list_iterate_items(sl, sll)
if (str_list_match_item(sll2, sl->str))
return 1;
return 0;
}

View File

@ -9,7 +9,10 @@
#include "pool.h"
int str_list_add(struct pool *mem, struct list *sl, const char *str);
int str_list_del(struct list *sl, const char *str);
struct list *str_list_create(struct pool *mem);
int str_list_add(struct pool *mem, struct list *sll, const char *str);
int str_list_del(struct list *sll, const char *str);
int str_list_match_item(struct list *sll, const char *str);
int str_list_match_list(struct list *sll, struct list *sll2);
#endif