1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-07 05:58:00 +03:00

o Additional device/filter-level debugging messages + duplicate alias fix

o 32/64-bit size_t fix (pjc)
This commit is contained in:
Alasdair Kergon 2003-01-08 16:41:22 +00:00
parent c68e513814
commit 4970ebfb92
10 changed files with 60 additions and 21 deletions

View File

@ -1 +1 @@
1.95.13-cvs (2003-01-07)
1.95.14-cvs (2003-01-08)

View File

@ -12,6 +12,13 @@
#include <sys/types.h>
#include <inttypes.h>
/* Define some portable printing types */
#if __WORDSIZE == 64
#define PRIsize_t "lu"
#else
#define PRIsize_t "u"
#endif
struct str_list {
struct list list;
char *str;

View File

@ -18,11 +18,6 @@
#include <dirent.h>
#include <linux/kdev_t.h>
/*
* FIXME: really need to seperate names from the devices since
* multiple names can point to the same device.
*/
struct dev_iter {
struct btree_iter *current;
struct dev_filter *filter;
@ -53,7 +48,7 @@ static struct device *_create_dev(dev_t d)
struct device *dev;
if (!(dev = _alloc(sizeof(*dev)))) {
stack;
log_error("struct device allocation failed");
return NULL;
}
@ -62,6 +57,7 @@ static struct device *_create_dev(dev_t d)
dev->fd = -1;
dev->flags = 0;
memset(dev->pvid, 0, sizeof(dev->pvid));
return dev;
}
@ -129,6 +125,7 @@ static int _compare_paths(const char *path0, const char *path1)
static int _add_alias(struct device *dev, const char *path)
{
struct str_list *sl = _alloc(sizeof(*sl));
struct list *ah;
const char *oldpath;
int prefer_old = 1;
@ -137,6 +134,14 @@ static int _add_alias(struct device *dev, const char *path)
return 0;
}
/* Is name already there? */
list_iterate(ah, &dev->aliases) {
if (!strcmp(list_item(ah, struct str_list)->str, path)) {
stack;
return 1;
}
}
if (!(sl->str = pool_strdup(_cache.mem, path))) {
stack;
return 0;
@ -145,7 +150,11 @@ static int _add_alias(struct device *dev, const char *path)
if (!list_empty(&dev->aliases)) {
oldpath = list_item(dev->aliases.n, struct str_list)->str;
prefer_old = _compare_paths(path, oldpath);
}
log_debug("%s: Aliased to %s in device cache%s",
path, oldpath, prefer_old ? "" : " (preferred name)");
} else
log_debug("%s: Added to device cache", path);
if (prefer_old)
list_add(&dev->aliases, &sl->list);
@ -382,8 +391,10 @@ int dev_cache_add_dir(const char *path)
return 1;
}
if (!(dl = _alloc(sizeof(*dl) + strlen(path) + 1)))
if (!(dl = _alloc(sizeof(*dl) + strlen(path) + 1))) {
log_error("dir_list allocation failed");
return 0;
}
strcpy(dl->dir, path);
list_add(&_cache.dirs, &dl->list);
@ -451,8 +462,10 @@ struct dev_iter *dev_iter_create(struct dev_filter *f)
{
struct dev_iter *di = dbg_malloc(sizeof(*di));
if (!di)
if (!di) {
log_error("dev_iter allocation failed");
return NULL;
}
_full_scan();
di->current = btree_first(_cache.devices);

View File

@ -238,10 +238,10 @@ int dev_zero(struct device *dev, uint64_t offset, size_t len)
}
if ((offset % SECTOR_SIZE) || (len % SECTOR_SIZE))
log_debug("Wiping %s at %" PRIu64 " length %u",
log_debug("Wiping %s at %" PRIu64 " length %" PRIsize_t,
dev_name(dev), offset, len);
else
log_debug("Wiping %s at sector %" PRIu64 " length %u"
log_debug("Wiping %s at sector %" PRIu64 " length %" PRIsize_t
" sectors", dev_name(dev), offset >> SECTOR_SHIFT,
len >> SECTOR_SHIFT);

View File

@ -19,6 +19,8 @@ static int _and_p(struct dev_filter *f, struct device *dev)
filters++;
}
log_debug("Using %s", dev_name(dev));
return 1;
}

View File

@ -32,8 +32,12 @@ static int _init_hash(struct pfilter *pf)
if (pf->devices)
hash_destroy(pf->devices);
pf->devices = hash_create(128);
return pf->devices ? 1 : 0;
if (!(pf->devices = hash_create(128))) {
stack;
return 0;
}
return 1;
}
int persistent_filter_wipe(struct dev_filter *f)
@ -201,7 +205,11 @@ static int _lookup_p(struct dev_filter *f, struct device *dev)
}
}
return l == PF_GOOD_DEVICE;
if (l == PF_BAD_DEVICE) {
log_debug("%s: Skipping (cached)", dev_name(dev));
return 0;
} else
return 1;
}
static void _destroy(struct dev_filter *f)

View File

@ -162,6 +162,8 @@ static int _accept_p(struct dev_filter *f, struct device *dev)
if (bit(rf->accept, m)) {
if (!first) {
log_debug("%s: New preferred name",
sl->str);
list_del(&sl->list);
list_add_h(&dev->aliases, &sl->list);
}

View File

@ -68,12 +68,16 @@ static int _passes_lvm_type_device_filter(struct dev_filter *f,
const char *name = dev_name(dev);
/* Is this a recognised device type? */
if (!(((int *) f->private)[MAJOR(dev->dev)]))
if (!(((int *) f->private)[MAJOR(dev->dev)])) {
log_debug("%s: Skipping: Unrecognised LVM device type %"
PRIu64, name, (uint64_t) MAJOR(dev->dev));
return 0;
}
/* Check it's accessible */
if ((fd = open(name, O_RDONLY)) < 0) {
log_debug("Unable to open %s: %s", name, strerror(errno));
log_debug("%s: Skipping: open failed: %s", name,
strerror(errno));
return 0;
}
@ -203,8 +207,10 @@ struct dev_filter *lvm_type_filter_create(const char *proc,
f->passes_filter = _passes_lvm_type_device_filter;
f->destroy = lvm_type_filter_destroy;
if (!(f->private = _scan_proc_dev(proc, cn)))
if (!(f->private = _scan_proc_dev(proc, cn))) {
stack;
return NULL;
}
return f;
}

View File

@ -744,7 +744,7 @@ static int _parse_options(struct report_handle *rh, const char *format)
while (*we && *we != ',')
we++;
if (!_field_match(rh, ws, (size_t) (we - ws))) {
log_error("Unrecognised field: %.*s", we - ws, ws);
log_error("Unrecognised field: %.*s", (int) (we - ws), ws);
return 0;
}
}
@ -765,7 +765,7 @@ static int _parse_keys(struct report_handle *rh, const char *keys)
while (*we && *we != ',')
we++;
if (!_key_match(rh, ws, (size_t) (we - ws))) {
log_error("Unrecognised field: %.*s", we - ws, ws);
log_error("Unrecognised field: %.*s", (int) (we - ws), ws);
return 0;
}
}

View File

@ -19,6 +19,7 @@
*/
#include "tools.h"
#include "lvm-types.h"
int lvrename(struct cmd_context *cmd, int argc, char **argv)
{
@ -78,7 +79,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
maxlen = NAME_LEN - strlen(vg_name) - strlen(cmd->dev_dir) - 3;
if (strlen(lv_name_new) > maxlen) {
log_error("New logical volume path exceeds maximum length "
"of %u!", maxlen);
"of %" PRIsize_t "!", maxlen);
return ECMD_FAILED;
}