From f58c5e6b30f6dd3080c78ac171940d6688b1c65e Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 8 Jan 2003 16:41:22 +0000 Subject: [PATCH] o Additional device/filter-level debugging messages + duplicate alias fix o 32/64-bit size_t fix (pjc) --- VERSION | 2 +- lib/datastruct/lvm-types.h | 7 +++++++ lib/device/dev-cache.c | 31 ++++++++++++++++++++++--------- lib/device/dev-io.c | 4 ++-- lib/filters/filter-composite.c | 2 ++ lib/filters/filter-persistent.c | 14 +++++++++++--- lib/filters/filter-regex.c | 2 ++ lib/filters/filter.c | 12 +++++++++--- lib/report/report.c | 4 ++-- tools/lvrename.c | 3 ++- 10 files changed, 60 insertions(+), 21 deletions(-) diff --git a/VERSION b/VERSION index be892d30d..b6bb182cb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.95.13-cvs (2003-01-07) +1.95.14-cvs (2003-01-08) diff --git a/lib/datastruct/lvm-types.h b/lib/datastruct/lvm-types.h index 5d45f828e..bba936c48 100644 --- a/lib/datastruct/lvm-types.h +++ b/lib/datastruct/lvm-types.h @@ -12,6 +12,13 @@ #include #include +/* 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; diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 6e2b463a8..b16528599 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -18,11 +18,6 @@ #include #include -/* - * 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); diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index 12f6ab8b3..2371b348b 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -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); diff --git a/lib/filters/filter-composite.c b/lib/filters/filter-composite.c index 8c96ba8d3..78e41dc8c 100644 --- a/lib/filters/filter-composite.c +++ b/lib/filters/filter-composite.c @@ -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; } diff --git a/lib/filters/filter-persistent.c b/lib/filters/filter-persistent.c index a6cff575a..8fced85f7 100644 --- a/lib/filters/filter-persistent.c +++ b/lib/filters/filter-persistent.c @@ -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) diff --git a/lib/filters/filter-regex.c b/lib/filters/filter-regex.c index 131c92efb..4b23fe789 100644 --- a/lib/filters/filter-regex.c +++ b/lib/filters/filter-regex.c @@ -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); } diff --git a/lib/filters/filter.c b/lib/filters/filter.c index 213c7447f..baf245b2e 100644 --- a/lib/filters/filter.c +++ b/lib/filters/filter.c @@ -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; } diff --git a/lib/report/report.c b/lib/report/report.c index a4d8c1e60..7293de23c 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -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; } } diff --git a/tools/lvrename.c b/tools/lvrename.c index c4ebce766..f9c645714 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -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; }