1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

report: select: refactor: move str_list to libdm

The list of strings is used quite frequently and we'd like to reuse
this simple structure for report selection support too. Make it part
of libdevmapper for general reuse throughout the code.

This also simplifies the LVM code a bit since we don't need to
include and manage lvm-types.h anymore (the string list was the
only structure defined there).
This commit is contained in:
Peter Rajnoha 2014-05-29 09:41:03 +02:00
parent fe952e735a
commit 5abdb52fdc
33 changed files with 51 additions and 84 deletions

View File

@ -17,7 +17,6 @@
#include <pthread.h>
#include "lvm-types.h"
#include "clvm.h"
#include "clvmd-comms.h"
#include "clvmd.h"

View File

@ -11,7 +11,6 @@
@top_srcdir@/lib/config/config_settings.h
@top_srcdir@/lib/config/defaults.h
@top_srcdir@/lib/datastruct/btree.h
@top_srcdir@/lib/datastruct/lvm-types.h
@top_srcdir@/lib/datastruct/str_list.h
@top_srcdir@/lib/device/dev-cache.h
@top_srcdir@/lib/device/dev-type.h

View File

@ -88,17 +88,17 @@ int lvmcache_vgname_is_locked(const char *vgname);
void lvmcache_seed_infos_from_lvmetad(struct cmd_context *cmd);
/* Returns list of struct str_lists containing pool-allocated copy of vgnames */
/* Returns list of struct dm_str_list containing pool-allocated copy of vgnames */
/* If include_internal is not set, return only proper vg names. */
struct dm_list *lvmcache_get_vgnames(struct cmd_context *cmd,
int include_internal);
/* Returns list of struct str_lists containing pool-allocated copy of vgids */
/* Returns list of struct dm_str_list containing pool-allocated copy of vgids */
/* If include_internal is not set, return only proper vg ids. */
struct dm_list *lvmcache_get_vgids(struct cmd_context *cmd,
int include_internal);
/* Returns list of struct str_lists containing pool-allocated copy of pvids */
/* Returns list of struct dm_str_list containing pool-allocated copy of pvids */
struct dm_list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname,
const char *vgid);

View File

@ -615,7 +615,7 @@ static int _init_lvm_conf(struct cmd_context *cmd)
/* Read any additional config files */
static int _init_tag_configs(struct cmd_context *cmd)
{
struct str_list *sl;
struct dm_str_list *sl;
/* Tag list may grow while inside this loop */
dm_list_iterate_items(sl, &cmd->tags) {

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LVM_TYPES_H
#define _LVM_TYPES_H
#include "libdevmapper.h"
struct str_list {
struct dm_list list;
const char *str;
};
#endif

View File

@ -32,7 +32,7 @@ struct dm_list *str_list_create(struct dm_pool *mem)
int str_list_add(struct dm_pool *mem, struct dm_list *sll, const char *str)
{
struct str_list *sln;
struct dm_str_list *sln;
if (!str)
return_0;
@ -55,14 +55,14 @@ void str_list_del(struct dm_list *sll, const char *str)
struct dm_list *slh, *slht;
dm_list_iterate_safe(slh, slht, sll)
if (!strcmp(str, dm_list_item(slh, struct str_list)->str))
if (!strcmp(str, dm_list_item(slh, struct dm_str_list)->str))
dm_list_del(slh);
}
int str_list_dup(struct dm_pool *mem, struct dm_list *sllnew,
const struct dm_list *sllold)
{
struct str_list *sl;
struct dm_str_list *sl;
dm_list_init(sllnew);
@ -79,7 +79,7 @@ int str_list_dup(struct dm_pool *mem, struct dm_list *sllnew,
*/
int str_list_match_item(const struct dm_list *sll, const char *str)
{
struct str_list *sl;
struct dm_str_list *sl;
dm_list_iterate_items(sl, sll)
if (!strcmp(str, sl->str))
@ -94,7 +94,7 @@ int str_list_match_item(const struct dm_list *sll, const char *str)
*/
int str_list_match_list(const struct dm_list *sll, const struct dm_list *sll2, const char **tag_matched)
{
struct str_list *sl;
struct dm_str_list *sl;
dm_list_iterate_items(sl, sll)
if (str_list_match_item(sll2, sl->str)) {
@ -111,7 +111,7 @@ int str_list_match_list(const struct dm_list *sll, const struct dm_list *sll2, c
*/
int str_list_lists_equal(const struct dm_list *sll, const struct dm_list *sll2)
{
struct str_list *sl;
struct dm_str_list *sl;
if (dm_list_size(sll) != dm_list_size(sll2))
return 0;

View File

@ -14,7 +14,6 @@
*/
#include "lib.h"
#include "lvm-types.h"
#include "btree.h"
#include "config.h"
#include "toolcontext.h"
@ -70,7 +69,7 @@ static void _dev_init(struct device *dev, int max_error_count)
}
struct device *dev_create_file(const char *filename, struct device *dev,
struct str_list *alias, int use_malloc)
struct dm_str_list *alias, int use_malloc)
{
int allocate = !dev;
@ -81,7 +80,7 @@ struct device *dev_create_file(const char *filename, struct device *dev,
return NULL;
}
if (!(alias = dm_zalloc(sizeof(*alias)))) {
log_error("struct str_list allocation failed");
log_error("struct dm_str_list allocation failed");
dm_free(dev);
return NULL;
}
@ -97,7 +96,7 @@ struct device *dev_create_file(const char *filename, struct device *dev,
return NULL;
}
if (!(alias = _zalloc(sizeof(*alias)))) {
log_error("struct str_list allocation failed");
log_error("struct dm_str_list allocation failed");
_free(dev);
return NULL;
}
@ -133,7 +132,7 @@ static struct device *_dev_create(dev_t d)
return dev;
}
void dev_set_preferred_name(struct str_list *sl, struct device *dev)
void dev_set_preferred_name(struct dm_str_list *sl, struct device *dev)
{
/*
* Don't interfere with ordering specified in config file.
@ -308,8 +307,8 @@ static int _compare_paths(const char *path0, const char *path1)
static int _add_alias(struct device *dev, const char *path)
{
struct str_list *sl = _zalloc(sizeof(*sl));
struct str_list *strl;
struct dm_str_list *sl = _zalloc(sizeof(*sl));
struct dm_str_list *strl;
const char *oldpath;
int prefer_old = 1;
@ -327,7 +326,7 @@ static int _add_alias(struct device *dev, const char *path)
sl->str = path;
if (!dm_list_empty(&dev->aliases)) {
oldpath = dm_list_item(dev->aliases.n, struct str_list)->str;
oldpath = dm_list_item(dev->aliases.n, struct dm_str_list)->str;
prefer_old = _compare_paths(path, oldpath);
log_debug_devs("%s: Aliased to %s in device cache%s",
path, oldpath, prefer_old ? "" : " (preferred name)");
@ -889,7 +888,7 @@ const char *dev_name_confirmed(struct device *dev, int quiet)
return dev_name(dev);
while ((r = stat(name = dm_list_item(dev->aliases.n,
struct str_list)->str, &buf)) ||
struct dm_str_list)->str, &buf)) ||
(buf.st_rdev != dev->dev)) {
if (r < 0) {
if (quiet)
@ -1073,6 +1072,6 @@ int dev_fd(struct device *dev)
const char *dev_name(const struct device *dev)
{
return (dev && dev->aliases.n) ? dm_list_item(dev->aliases.n, struct str_list)->str :
return (dev && dev->aliases.n) ? dm_list_item(dev->aliases.n, struct dm_str_list)->str :
"unknown device";
}

View File

@ -54,7 +54,7 @@ struct device *dev_cache_get(const char *name, struct dev_filter *f);
// TODO
struct device *dev_cache_get_by_devt(dev_t device, struct dev_filter *f);
void dev_set_preferred_name(struct str_list *sl, struct device *dev);
void dev_set_preferred_name(struct dm_str_list *sl, struct device *dev);
/*
* Object for iterating through the cache.

View File

@ -14,7 +14,6 @@
*/
#include "lib.h"
#include "lvm-types.h"
#include "device.h"
#include "metadata.h"
#include "lvmcache.h"
@ -591,7 +590,7 @@ static void _close(struct device *dev)
log_debug_devs("Closed %s", dev_name(dev));
if (dev->flags & DEV_ALLOCED) {
dm_free((void *) dm_list_item(dev->aliases.n, struct str_list)->
dm_free((void *) dm_list_item(dev->aliases.n, struct dm_str_list)->
str);
dm_free(dev->aliases.n);
dm_free(dev);

View File

@ -17,7 +17,6 @@
#define _LVM_DEVICE_H
#include "uuid.h"
#include "lvm-types.h"
#include <fcntl.h>
@ -34,7 +33,7 @@
* pointer comparisons are valid.
*/
struct device {
struct dm_list aliases; /* struct str_list from lvm-types.h */
struct dm_list aliases; /* struct dm_str_list */
dev_t dev;
/* private */
@ -96,7 +95,7 @@ int dev_set(struct device *dev, uint64_t offset, size_t len, int value);
void dev_flush(struct device *dev);
struct device *dev_create_file(const char *filename, struct device *dev,
struct str_list *alias, int use_malloc);
struct dm_str_list *alias, int use_malloc);
/* Return a valid device name from the alias list; NULL otherwise */
const char *dev_name_confirmed(struct device *dev, int quiet);

View File

@ -833,7 +833,7 @@ void display_segtypes(const struct cmd_context *cmd)
void display_tags(const struct cmd_context *cmd)
{
const struct str_list *sl;
const struct dm_str_list *sl;
dm_list_iterate_items(sl, &cmd->tags) {
log_print("%s", sl->str);

View File

@ -272,7 +272,7 @@ static int _lookup_p(struct dev_filter *f, struct device *dev)
{
struct pfilter *pf = (struct pfilter *) f->private;
void *l = dm_hash_lookup(pf->devices, dev_name(dev));
struct str_list *sl;
struct dm_str_list *sl;
/* Cached BAD? */
if (l == PF_BAD_DEVICE) {

View File

@ -149,7 +149,7 @@ static int _accept_p(struct dev_filter *f, struct device *dev)
{
int m, first = 1, rejected = 0;
struct rfilter *rf = (struct rfilter *) f->private;
struct str_list *sl;
struct dm_str_list *sl;
dm_list_iterate_items(sl, &dev->aliases) {
m = dm_regex_match(rf->engine, sl->str);

View File

@ -16,7 +16,6 @@
#ifndef DISK_REP_FORMAT1_H
#define DISK_REP_FORMAT1_H
#include "lvm-types.h"
#include "metadata.h"
#include "toolcontext.h"

View File

@ -16,7 +16,6 @@
#ifndef _LVM_FORMAT_TEXT_H
#define _LVM_FORMAT_TEXT_H
#include "lvm-types.h"
#include "metadata.h"
#define FMT_TEXT_NAME "lvm2"

View File

@ -17,7 +17,6 @@
#define _LVM_TEXT_LAYOUT_H
#include "config.h"
#include "lvm-types.h"
#include "metadata.h"
#include "uuid.h"

View File

@ -21,7 +21,7 @@
char *alloc_printed_tags(struct dm_list *tagsl)
{
struct str_list *sl;
struct dm_str_list *sl;
int first = 1;
size_t size = 0;
char *buffer, *buf;

View File

@ -23,7 +23,7 @@
static FILE *_log_file;
static struct device _log_dev;
static struct str_list _log_dev_alias;
static struct dm_str_list _log_dev_alias;
static int _syslog = 0;
static int _log_to_file = 0;

View File

@ -5281,7 +5281,7 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd,
int r;
char *name;
size_t len;
struct str_list *sl;
struct dm_str_list *sl;
struct logical_volume *layer_lv;
struct segment_type *segtype;
struct lv_segment *mapseg;

View File

@ -2322,7 +2322,7 @@ int vg_validate(struct volume_group *vg)
struct pv_list *pvl;
struct lv_list *lvl;
struct lv_segment *seg;
struct str_list *sl;
struct dm_str_list *sl;
char uuid[64] __attribute__((aligned(8)));
int r = 1;
unsigned hidden_lv_count = 0, lv_count = 0, lv_visible_count = 0;
@ -3571,7 +3571,7 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
const char *vgname;
struct dm_list *vgnames;
struct volume_group *vg;
struct str_list *strl;
struct dm_str_list *strl;
int consistent = 0;
/* Is corresponding vgname already cached? */
@ -3802,7 +3802,7 @@ struct dm_list *get_vgids(struct cmd_context *cmd, int include_internal)
static int _get_pvs(struct cmd_context *cmd, int warnings,
struct dm_list *pvslist, struct dm_list *vgslist)
{
struct str_list *strl;
struct dm_str_list *strl;
const char *vgname, *vgid;
struct pv_list *pvl, *pvl_copy;
struct dm_list *vgids;
@ -4712,7 +4712,7 @@ int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignored)
char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tagsl)
{
struct str_list *sl;
struct dm_str_list *sl;
if (!dm_pool_begin_object(mem, 256)) {
log_error("dm_pool_begin_object failed");

View File

@ -281,7 +281,7 @@ static int _init_mirror_log(struct cmd_context *cmd,
struct logical_volume *log_lv, int in_sync,
struct dm_list *tagsl, int remove_on_failure)
{
struct str_list *sl;
struct dm_str_list *sl;
uint64_t orig_status = log_lv->status;
int was_active = 0;
@ -420,7 +420,7 @@ static int _activate_lv_like_model(struct logical_volume *model,
static int _delete_lv(struct logical_volume *mirror_lv, struct logical_volume *lv)
{
struct cmd_context *cmd = mirror_lv->vg->cmd;
struct str_list *sl;
struct dm_str_list *sl;
/* Inherit tags - maybe needed for activation */
if (!str_list_match_list(&mirror_lv->tags, &lv->tags, NULL)) {

View File

@ -40,7 +40,6 @@
# include "lvm-logging.h"
# include "lvm-globals.h"
# include "lvm-wrappers.h"
# include "lvm-types.h"
#endif
#include <unistd.h>

View File

@ -15,7 +15,6 @@
#define _LVM_PROPERTIES_H
#include "libdevmapper.h"
#include "lvm-types.h"
#include "metadata.h"
#include "report.h"
#include "prop_common.h"

View File

@ -1178,6 +1178,14 @@ struct dm_list {
struct dm_list *n, *p;
};
/*
* String list.
*/
struct dm_str_list {
struct dm_list list;
const char *str;
};
/*
* Initialise a list before use.
* The list head's next and previous pointers point back to itself.

View File

@ -22,7 +22,7 @@ struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
{
struct dm_list *list;
lvm_str_list_t *lsl;
struct str_list *sl;
struct dm_str_list *sl;
if (!(list = dm_pool_zalloc(p, sizeof(*list)))) {
log_errno(ENOMEM, "Memory allocation fail for dm_list.");

View File

@ -14,7 +14,6 @@
#include "lvm_prop.h"
#include "libdevmapper.h"
#include "lvm-types.h"
#include "metadata.h"
/* lv create parameters */

View File

@ -24,7 +24,7 @@ int main(int argc, char **argv)
struct device *dev;
struct dev_iter *iter;
struct list_head *tmp;
struct str_list *sl;
struct dm_str_list *sl;
if (argc < 2) {
fprintf(stderr, "usage: %s <dir>\n", argv[0]);
@ -55,7 +55,7 @@ int main(int argc, char **argv)
printf("%s", dev->name);
list_for_each(tmp, &dev->aliases) {
sl = list_entry(tmp, struct str_list, list);
sl = list_entry(tmp, struct dm_str_list, list);
printf(", %s", sl->str);
}
printf("\n");

View File

@ -21,8 +21,6 @@
#ifndef _LVM_RANDOM_H
#define _LVM_RANDOM_H
#include "lvm-types.h"
void rand_init(int32_t seed);
int32_t rand_get(void);

View File

@ -14,7 +14,6 @@
*/
#include "tools.h"
#include "lvm-types.h"
/*
* lvrename command implementation.

View File

@ -161,7 +161,7 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)
struct pv_list *pvl;
struct dm_list *vgnames;
struct str_list *sll;
struct dm_str_list *sll;
if (!(arg_count(cmd, allocatable_ARG) + arg_is_set(cmd, addtag_ARG) +
arg_is_set(cmd, deltag_ARG) + arg_count(cmd, uuid_ARG) +

View File

@ -293,7 +293,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
struct dm_list *tags_arg;
struct dm_list *vgnames; /* VGs to process */
struct str_list *sll, *strl;
struct dm_str_list *sll, *strl;
struct cmd_vg *cvl_vg;
struct dm_list cmd_vgs;
struct dm_list failed_lvnames;
@ -621,7 +621,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
int opt = 0;
int ret_max = ECMD_PROCESSED;
struct str_list *sl;
struct dm_str_list *sl;
struct dm_list *vgnames, *vgids;
struct dm_list arg_vgnames, tagsl;
@ -803,7 +803,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
struct physical_volume *pv;
struct dm_list *pvslist = NULL, *vgnames;
struct dm_list tagsl;
struct str_list *sll;
struct dm_str_list *sll;
char *at_sign, *tagname;
struct device *dev;

View File

@ -23,7 +23,6 @@
#include <assert.h>
#include "libdevmapper.h"
#include "lvm-types.h"
#include "lvm-logging.h"
#include "activate.h"
#include "archiver.h"

View File

@ -62,7 +62,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
int match = 0;
int found_id = 0;
struct dm_list *vgids;
struct str_list *sl;
struct dm_str_list *sl;
const char *vg_name_new;
const char *vgid = NULL, *vg_name, *vg_name_old;
char old_path[NAME_LEN], new_path[NAME_LEN];