diff --git a/lib/activate/activate.c b/lib/activate/activate.c index b9b32f3da..02e46f983 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "metadata.h" diff --git a/lib/activate/table-build.c b/lib/activate/table-build.c index 56ac31eba..e8f87e8b1 100644 --- a/lib/activate/table-build.c +++ b/lib/activate/table-build.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "table-build.c" diff --git a/lib/config/config.c b/lib/config/config.c index ba16d291a..9df84fcd7 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include diff --git a/lib/datastruct/bitset.c b/lib/datastruct/bitset.c index 707a51d61..44d696263 100644 --- a/lib/datastruct/bitset.c +++ b/lib/datastruct/bitset.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "bitset.h" diff --git a/lib/datastruct/btree.c b/lib/datastruct/btree.c index d121c309e..c27d489ea 100644 --- a/lib/datastruct/btree.c +++ b/lib/datastruct/btree.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "btree.h" diff --git a/lib/datastruct/hash.c b/lib/datastruct/hash.c index 11f09b05b..dea7e87c7 100644 --- a/lib/datastruct/hash.c +++ b/lib/datastruct/hash.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software * - * This file is released under the GPL. + * This file is released under the LGPL. */ diff --git a/lib/datastruct/list.h b/lib/datastruct/list.h index 29b7ec3f8..8fbe1aefa 100644 --- a/lib/datastruct/list.h +++ b/lib/datastruct/list.h @@ -1,110 +1,55 @@ -/* stolen from the Linux kernel. */ +/* + * Copyright (C) 2001 Sistina Software + * + * This file is released under the LGPL. + */ #ifndef _LVM_LIST_H #define _LVM_LIST_H -/* - * Simple doubly linked list implementation. - * - * Some of the internal functions ("__xxx") are useful when - * manipulating whole lists rather than single entries, as - * sometimes we already know the next/prev entries and we can - * generate better code by using them directly rather than - * using the generic single-entry routines. - */ +#include -struct list_head { - struct list_head *next, *prev; +struct list { + struct list *n, *p; }; -#define LIST_HEAD_INIT(name) { &(name), &(name) } - -#define LIST_HEAD(name) \ - struct list_head name = { &name, &name } - -#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) - -/* - * Insert a new entry between two known consecutive entries. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_add(struct list_head *new, - struct list_head *prev, - struct list_head *next) -{ - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; +static inline void list_init(struct list *head) { + head->n = head->p = head; } -/* - * Insert a new entry after the specified head.. - */ -static __inline__ void list_add(struct list_head *new, struct list_head *head) -{ - __list_add(new, head, head->next); +static inline void list_add(struct list *head, struct list *elem) { + assert(head->n); + + elem->n = head; + elem->p = head->p; + + head->p->n = elem; + head->p = elem; } -/* - * Insert a new entry at the tail - */ -static __inline__ void list_add_tail(struct list_head *new, struct list_head *head) -{ - __list_add(new, head->prev, head); +static inline void list_add_h(struct list *head, struct list *elem) { + assert(head->n); + + elem->n = head->n; + elem->p = head; + + head->n->p = elem; + head->n = elem; } -/* - * Delete a list entry by making the prev/next entries - * point to each other. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_del(struct list_head * prev, - struct list_head * next) -{ - next->prev = prev; - prev->next = next; +static inline void list_del(struct list *elem) { + elem->n->p = elem->p; + elem->p->n = elem->n; } -static __inline__ void list_del(struct list_head *entry) -{ - __list_del(entry->prev, entry->next); +static inline int list_empty(struct list *head) { + return head->n == head; } -static __inline__ int list_empty(struct list_head *head) -{ - return head->next == head; -} +#define list_iterate(v, head) \ + for (v = (head)->n; v != head; v = v->n) -/* - * Splice in "list" into "head" - */ -static __inline__ void list_splice(struct list_head *list, struct list_head *head) -{ - struct list_head *first = list->next; - - if (first != list) { - struct list_head *last = list->prev; - struct list_head *at = head->next; - - first->prev = head; - head->next = first; - - last->next = at; - at->prev = last; - } -} - -#define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) - -#define list_for_each(pos, head) \ - for (pos = (head)->next; pos != (head); pos = pos->next) +#define list_item(v, t) \ + ((t *)((char *)(v) - (unsigned int) &((t *) 0)->list)) #endif diff --git a/lib/datastruct/lvm-types.h b/lib/datastruct/lvm-types.h index 3614e7b64..84b534af8 100644 --- a/lib/datastruct/lvm-types.h +++ b/lib/datastruct/lvm-types.h @@ -25,7 +25,7 @@ typedef __int64_t int64_t; struct str_list { - struct list_head list; + struct list list; char *str; }; diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index e44447827..dc68667a3 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "dev-cache.h" @@ -31,7 +31,7 @@ struct dev_iter { }; struct dir_list { - struct list_head list; + struct list list; char dir[0]; }; @@ -41,7 +41,7 @@ static struct { struct btree *devices; int has_scanned; - struct list_head dirs; + struct list dirs; } _cache; @@ -60,7 +60,7 @@ static struct device *_create_dev(dev_t d) return NULL; } - INIT_LIST_HEAD(&dev->aliases); + list_init(&dev->aliases); dev->dev = d; return dev; } @@ -79,7 +79,7 @@ static int _add_alias(struct device *dev, const char *path) return 0; } - list_add(&sl->list, &dev->aliases); + list_add(&dev->aliases, &sl->list); return 1; } @@ -254,15 +254,15 @@ static int _insert(const char *path, int rec) static void _full_scan(void) { - struct list_head *tmp; + struct list *dh; if (_cache.has_scanned) return; - list_for_each(tmp, &_cache.dirs) { - struct dir_list *dl = list_entry(tmp, struct dir_list, list); + list_iterate(dh, &_cache.dirs) { + struct dir_list *dl = list_item(dh, struct dir_list); _insert_dir(dl->dir); - } + }; _cache.has_scanned = 1; } @@ -288,7 +288,7 @@ int dev_cache_init(void) goto bad; } - INIT_LIST_HEAD(&_cache.dirs); + list_init(&_cache.dirs); return 1; @@ -324,7 +324,7 @@ int dev_cache_add_dir(const char *path) return 0; strcpy(dl->dir, path); - list_add(&dl->list, &_cache.dirs); + list_add(&_cache.dirs, &dl->list); return 1; } diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index 8d132396e..6ff16e8d4 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "device.h" diff --git a/lib/device/device.h b/lib/device/device.h index b4bdd9d40..e690b979c 100644 --- a/lib/device/device.h +++ b/lib/device/device.h @@ -15,7 +15,7 @@ * pointer comparisons are valid. */ struct device { - struct list_head aliases; /* struct str_list from lvm-types.h */ + struct list aliases; /* struct str_list from lvm-types.h */ dev_t dev; }; @@ -31,7 +31,7 @@ int64_t dev_write(struct device *dev, uint64_t offset, int64_t len, void *buffer); static inline const char *dev_name(struct device *dev) { - return list_entry(dev->aliases.next, struct str_list, list)->str; + return list_item(dev->aliases.n, struct str_list)->str; } diff --git a/lib/filters/filter-composite.c b/lib/filters/filter-composite.c index 34d40e4b9..5b93e6d5a 100644 --- a/lib/filters/filter-composite.c +++ b/lib/filters/filter-composite.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "filter-composite.h" diff --git a/lib/filters/filter-persistent.c b/lib/filters/filter-persistent.c index fcdc26c9c..af1c4d8ba 100644 --- a/lib/filters/filter-persistent.c +++ b/lib/filters/filter-persistent.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "config.h" @@ -165,15 +165,15 @@ static int _lookup_p(struct dev_filter *f, struct device *dev) { struct pfilter *pf = (struct pfilter *) f->private; void *l = hash_lookup(pf->devices, dev_name(dev)); - struct list_head *tmp; struct str_list *sl; + struct list *ah; if (!l) { l = pf->real->passes_filter(pf->real, dev) ? PF_GOOD_DEVICE : PF_BAD_DEVICE; - list_for_each(tmp, &dev->aliases) { - sl = list_entry(tmp, struct str_list, list); + list_iterate(ah, &dev->aliases) { + sl = list_item(ah, struct str_list); hash_insert(pf->devices, sl->str, l); } } diff --git a/lib/filters/filter-regex.c b/lib/filters/filter-regex.c index a450ca844..e90224d6c 100644 --- a/lib/filters/filter-regex.c +++ b/lib/filters/filter-regex.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "pool.h" @@ -149,13 +149,13 @@ static int _build_matcher(struct rfilter *rf, struct config_value *val) static int _accept_p(struct dev_filter *f, struct device *dev) { + struct list *ah; int m, first = 1; struct rfilter *rf = (struct rfilter *) f->private; - struct list_head *tmp; struct str_list *sl; - list_for_each(tmp, &dev->aliases) { - sl = list_entry(tmp, struct str_list, list); + list_iterate(ah, &dev->aliases) { + sl = list_item(ah, struct str_list); m = matcher_run(rf->engine, sl->str); if (m >= 0) { @@ -163,7 +163,7 @@ static int _accept_p(struct dev_filter *f, struct device *dev) if (!first) { list_del(&sl->list); - list_add(&sl->list, &dev->aliases); + list_add_h(&dev->aliases, &sl->list); } return 1; diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index ba2bc0e06..d2339aa26 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "disk-rep.h" @@ -170,7 +170,7 @@ static int _read_uuids(struct disk_list *data) memcpy(ul->uuid, buffer, NAME_LEN); ul->uuid[NAME_LEN] = '\0'; - list_add(&ul->list, &data->uuids); + list_add(&data->uuids, &ul->list); pos += NAME_LEN; num_read++; @@ -209,7 +209,7 @@ static int _read_lvs(struct disk_list *data) if (!_check_lv(&ll->lv)) fail; - list_add(&ll->list, &data->lvs); + list_add(&data->lvs, &ll->list); } return 1; @@ -241,8 +241,8 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem, data->dev = dev; data->mem = mem; - INIT_LIST_HEAD(&data->uuids); - INIT_LIST_HEAD(&data->lvs); + list_init(&data->uuids); + list_init(&data->lvs); if (!_read_pv(data)) { log_debug("Failed to read PV data from %s", name); @@ -311,7 +311,7 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem, * the memory if something goes wrong. */ int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter, - struct pool *mem, struct list_head *head) + struct pool *mem, struct list *head) { struct dev_iter *iter = dev_iter_create(filter); struct device *dev; @@ -319,7 +319,7 @@ int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter, for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) { if ((data = read_pv(dev, mem, vg_name))) - list_add(&data->list, head); + list_add(head, &data->list); } dev_iter_destroy(iter); @@ -347,18 +347,18 @@ static int _write_vg(struct disk_list *data) static int _write_uuids(struct disk_list *data) { struct uuid_list *ul; - struct list_head *tmp; + struct list *uh; ulong pos = data->pv.pv_uuidlist_on_disk.base; ulong end = pos + data->pv.pv_uuidlist_on_disk.size; - list_for_each(tmp, &data->uuids) { + list_iterate(uh, &data->uuids) { if (pos >= end) { log_error("Too many uuids to fit on %s", dev_name(data->dev)); return 0; } - ul = list_entry(tmp, struct uuid_list, list); + ul = list_item(uh, struct uuid_list); if (dev_write(data->dev, pos, NAME_LEN, ul->uuid) != NAME_LEN) fail; @@ -381,11 +381,11 @@ static int _write_lv(struct device *dev, ulong pos, struct lv_disk *disk) static int _write_lvs(struct disk_list *data) { - struct list_head *tmp; + struct list *lvh; unsigned long pos; - list_for_each(tmp, &data->lvs) { - struct lvd_list *ll = list_entry(tmp, struct lvd_list, list); + list_iterate(lvh, &data->lvs) { + struct lvd_list *ll = list_item(lvh, struct lvd_list); pos = data->pv.lv_on_disk.base; if (!_write_lv(data->dev, pos, &ll->lv)) @@ -468,13 +468,13 @@ static int _write_all_pv(struct disk_list *data) * little sanity checking, so make sure correct * data is passed to here. */ -int write_pvs(struct list_head *pvs) +int write_pvs(struct list *pvs) { - struct list_head *tmp; + struct list *pvh; struct disk_list *dl; - list_for_each(tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); if (!(_write_all_pv(dl))) fail; diff --git a/lib/format1/disk-rep.h b/lib/format1/disk-rep.h index 0f7589d02..9b52b5b4a 100644 --- a/lib/format1/disk-rep.h +++ b/lib/format1/disk-rep.h @@ -134,24 +134,24 @@ struct pe_disk { struct uuid_list { - struct list_head list; + struct list list; char uuid[NAME_LEN]; }; struct lvd_list { - struct list_head list; + struct list list; struct lv_disk lv; }; struct disk_list { struct pool *mem; struct device *dev; - struct list_head list; + struct list list; struct pv_disk pv; struct vg_disk vg; - struct list_head uuids; - struct list_head lvs; + struct list uuids; + struct list lvs; struct pe_disk *extents; }; @@ -182,9 +182,9 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem, const char *vg_name); int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter, - struct pool *mem, struct list_head *results); + struct pool *mem, struct list *results); -int write_pvs(struct list_head *pvs); +int write_pvs(struct list *pvs); /* @@ -204,30 +204,29 @@ int import_lv(struct pool *mem, struct logical_volume *lv, void export_lv(struct lv_disk *lvd, struct volume_group *vg, struct logical_volume *lv, const char *prefix); -int import_extents(struct pool *mem, struct volume_group *vg, - struct list_head *pvs); +int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs); int export_extents(struct disk_list *dl, int lv_num, struct logical_volume *lv, struct physical_volume *pv); -int import_pvs(struct pool *mem, struct list_head *pvs, - struct list_head *results, int *count); +int import_pvs(struct pool *mem, struct list *pvs, + struct list *results, int *count); int import_lvs(struct pool *mem, struct volume_group *vg, - struct list_head *pvs); + struct list *pvs); int export_lvs(struct disk_list *dl, struct volume_group *vg, struct physical_volume *pv, const char *prefix); int export_uuids(struct disk_list *dl, struct volume_group *vg); -void export_numbers(struct list_head *pvs, struct volume_group *vg); +void export_numbers(struct list *pvs, struct volume_group *vg); -void export_pv_act(struct list_head *pvs); +void export_pv_act(struct list *pvs); /* blech */ int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg, int *result); -int export_vg_number(struct list_head *pvs, const char *vg_name, +int export_vg_number(struct list *pvs, const char *vg_name, struct dev_filter *filter); diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 18c0009f8..7b8ee4c59 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "disk-rep.h" @@ -13,17 +13,17 @@ #include "display.h" /* VG consistency checks */ -static int _check_vgs(struct list_head *pvs) +static int _check_vgs(struct list *pvs) { - struct list_head *tmp; + struct list *pvh; struct disk_list *dl = NULL; struct disk_list *first = NULL; int pv_count = 0; /* check all the vg's are the same */ - list_for_each(tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); if (!first) first = dl; @@ -45,7 +45,7 @@ static int _check_vgs(struct list_head *pvs) return 1; } -static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs) +static struct volume_group *_build_vg(struct pool *mem, struct list *pvs) { struct volume_group *vg = pool_alloc(mem, sizeof(*vg)); struct disk_list *dl; @@ -56,12 +56,12 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs) if (list_empty(pvs)) goto bad; - dl = list_entry(pvs->next, struct disk_list, list); + dl = list_item(pvs->n, struct disk_list); memset(vg, 0, sizeof(*vg)); - INIT_LIST_HEAD(&vg->pvs); - INIT_LIST_HEAD(&vg->lvs); + list_init(&vg->pvs); + list_init(&vg->lvs); if (!_check_vgs(pvs)) goto bad; @@ -89,9 +89,9 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs) static struct volume_group *_vg_read(struct io_space *is, const char *vg_name) { struct pool *mem = pool_create(1024 * 10); - struct list_head pvs; + struct list pvs; struct volume_group *vg; - INIT_LIST_HEAD(&pvs); + list_init(&pvs); if (!mem) { stack; @@ -128,8 +128,8 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg, dl->mem = mem; dl->dev = pv->dev; - INIT_LIST_HEAD(&dl->uuids); - INIT_LIST_HEAD(&dl->lvs); + list_init(&dl->uuids); + list_init(&dl->lvs); if (!export_pv(&dl->pv, pv) || !export_vg(&dl->vg, vg) || @@ -145,22 +145,22 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg, } static int _flatten_vg(struct pool *mem, struct volume_group *vg, - struct list_head *pvs, const char *prefix, + struct list *pvs, const char *prefix, struct dev_filter *filter) { - struct list_head *tmp; + struct list *pvh; struct pv_list *pvl; struct disk_list *data; - list_for_each(tmp, &vg->pvs) { - pvl = list_entry(tmp, struct pv_list, list); + list_iterate(pvh, &vg->pvs) { + pvl = list_item(pvh, struct pv_list); if (!(data = _flatten_pv(mem, vg, &pvl->pv, prefix))) { stack; return 0; } - list_add(&data->list, pvs); + list_add(pvs, &data->list); } export_numbers(pvs, vg); @@ -177,7 +177,7 @@ static int _flatten_vg(struct pool *mem, struct volume_group *vg, static int _vg_write(struct io_space *is, struct volume_group *vg) { struct pool *mem = pool_create(1024 * 10); - struct list_head pvs; + struct list pvs; int r = 0; if (!mem) { @@ -185,7 +185,7 @@ static int _vg_write(struct io_space *is, struct volume_group *vg) return 0; } - INIT_LIST_HEAD(&pvs); + list_init(&pvs); r = (_flatten_vg(mem, vg, &pvs, is->prefix, is->filter) && write_pvs(&pvs)); @@ -201,7 +201,7 @@ static struct physical_volume *_pv_read(struct io_space *is, struct disk_list *dl; struct device *dev; - log_very_verbose("Reading physical volume data %s from disk", name); + log_very_verbose("Reading physical volume data %s from disk", name); if (!mem) { stack; @@ -236,10 +236,10 @@ static struct physical_volume *_pv_read(struct io_space *is, return NULL; } -static struct list_head *_get_pvs(struct io_space *is) +static struct list *_get_pvs(struct io_space *is) { struct pool *mem = pool_create(1024 * 10); - struct list_head pvs, *results; + struct list pvs, *results; uint32_t count; if (!mem) { @@ -253,8 +253,8 @@ static struct list_head *_get_pvs(struct io_space *is) return NULL; } - INIT_LIST_HEAD(&pvs); - INIT_LIST_HEAD(results); + list_init(&pvs); + list_init(results); if (!read_pvs_in_vg(NULL, is->filter, mem, &pvs)) { stack; @@ -275,13 +275,13 @@ static struct list_head *_get_pvs(struct io_space *is) return NULL; } -static int _find_vg_name(struct list_head *names, const char *vg) +static int _find_vg_name(struct list *names, const char *vg) { - struct list_head *tmp; + struct list *nh; struct name_list *nl; - list_for_each(tmp, names) { - nl = list_entry(tmp, struct name_list, list); + list_iterate(nh, names) { + nl = list_item(nh, struct name_list); if (!strcmp(nl->name, vg)) return 1; } @@ -289,10 +289,10 @@ static int _find_vg_name(struct list_head *names, const char *vg) return 0; } -static struct list_head *_get_vgs(struct io_space *is) +static struct list *_get_vgs(struct io_space *is) { - struct list_head *tmp, *pvs; - struct list_head *names = pool_alloc(is->mem, sizeof(*names)); + struct list *pvh; + struct list *pvs, *names = pool_alloc(is->mem, sizeof(*names)); struct name_list *nl; if (!names) { @@ -300,17 +300,17 @@ static struct list_head *_get_vgs(struct io_space *is) return NULL; } - INIT_LIST_HEAD(names); + list_init(names); if (!(pvs = _get_pvs(is))) { stack; goto bad; } - list_for_each(tmp, pvs) { - struct pv_list *pvl = list_entry(tmp, struct pv_list, list); + list_iterate(pvh, pvs) { + struct pv_list *pvl = list_item(pvh, struct pv_list); - if (!(*pvl->pv.vg_name) || + if (!(*pvl->pv.vg_name) || _find_vg_name(names, pvl->pv.vg_name)) continue; @@ -324,7 +324,7 @@ static struct list_head *_get_vgs(struct io_space *is) goto bad; } - list_add(&nl->list, names); + list_add(names, &nl->list); } if (list_empty(names)) @@ -355,12 +355,12 @@ static int _pv_write(struct io_space *is, struct physical_volume *pv) { struct pool *mem; struct disk_list *dl; - struct list_head pvs; + struct list pvs; - INIT_LIST_HEAD(&pvs); + list_init(&pvs); if (*pv->vg_name || pv->pe_allocated ) { - log_error("Assertion failed: can't _pv_write non-orphan PV " + log_error("Assertion failed: can't _pv_write non-orphan PV " "(in VG %s)", pv->vg_name); return 0; } @@ -387,7 +387,7 @@ static int _pv_write(struct io_space *is, struct physical_volume *pv) goto bad; } - list_add(&dl->list, &pvs); + list_add(&pvs, &dl->list); if (!write_pvs(&pvs)) { stack; goto bad; @@ -414,7 +414,7 @@ int _vg_setup(struct io_space *is, struct volume_group *vg) char *dummy, *dummy2; log_error("Extent size must be between %s and %s", - (dummy = display_size(MIN_PE_SIZE / 2, SIZE_SHORT)), + (dummy = display_size(MIN_PE_SIZE / 2, SIZE_SHORT)), (dummy2 = display_size(MAX_PE_SIZE / 2, SIZE_SHORT))); dbg_free(dummy); diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index c9d3ded3b..904cf0450 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "disk-rep.h" @@ -37,12 +37,12 @@ static char *_create_lv_name(struct pool *mem, const char *full_name) static int _fill_lv_array(struct logical_volume **lvs, struct volume_group *vg, struct disk_list *dl) { - struct list_head *tmp; + struct list *lvh; struct logical_volume *lv; int i = 0; - list_for_each(tmp, &dl->lvs) { - struct lvd_list *ll = list_entry(tmp, struct lvd_list, list); + list_iterate(lvh, &dl->lvs) { + struct lvd_list *ll = list_item(lvh, struct lvd_list); if (!(lv = find_lv(vg, ll->lv.lv_name))) { stack; @@ -317,19 +317,18 @@ void export_lv(struct lv_disk *lvd, struct volume_group *vg, lvd->lv_allocation = LV_CONTIGUOUS; } -int import_extents(struct pool *mem, struct volume_group *vg, - struct list_head *pvs) +int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs) { - struct list_head *tmp; struct disk_list *dl; struct logical_volume *lv, *lvs[MAX_LV]; struct physical_volume *pv; struct pe_disk *e; int i; uint32_t lv_num, le; + struct list *pvh; - list_for_each(tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); pv = _find_pv(vg, dl->dev); e = dl->extents; @@ -380,16 +379,16 @@ int export_extents(struct disk_list *dl, int lv_num, return 1; } -int import_pvs(struct pool *mem, struct list_head *pvs, - struct list_head *results, int *count) +int import_pvs(struct pool *mem, struct list *pvs, + struct list *results, int *count) { - struct list_head *tmp; + struct list *pvh; struct disk_list *dl; struct pv_list *pvl; *count = 0; - list_for_each(tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); pvl = pool_alloc(mem, sizeof(*pvl)); if (!pvl) { @@ -402,7 +401,7 @@ int import_pvs(struct pool *mem, struct list_head *pvs, return 0; } - list_add(&pvl->list, results); + list_add(results, &pvl->list); (*count)++; } @@ -427,24 +426,24 @@ static struct logical_volume *_add_lv(struct pool *mem, return NULL; } - list_add(&ll->list, &vg->lvs); + list_add(&vg->lvs, &ll->list); vg->lv_count++; return lv; } int import_lvs(struct pool *mem, struct volume_group *vg, - struct list_head *pvs) + struct list *pvs) { - struct list_head *tmp, *tmp2; struct disk_list *dl; struct lvd_list *ll; struct lv_disk *lvd; + struct list *pvh, *lvh; - list_for_each(tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); - list_for_each(tmp2, &dl->lvs) { - ll = list_entry(tmp2, struct lvd_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); + list_iterate(lvh, &dl->lvs) { + ll = list_item(lvh, struct lvd_list); lvd = &ll->lv; if (!find_lv(vg, lvd->lv_name) && @@ -461,7 +460,7 @@ int import_lvs(struct pool *mem, struct volume_group *vg, int export_lvs(struct disk_list *dl, struct volume_group *vg, struct physical_volume *pv, const char *prefix) { - struct list_head *tmp; + struct list *lvh; struct lv_list *ll; struct lvd_list *lvdl; int lv_num = 1, len; @@ -477,8 +476,8 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg, memset(dl->extents, 0, len); - list_for_each(tmp, &vg->lvs) { - ll = list_entry(tmp, struct lv_list, list); + list_iterate(lvh, &vg->lvs) { + ll = list_item(lvh, struct lv_list); if (!(lvdl = pool_alloc(dl->mem, sizeof(*lvdl)))) { stack; return 0; @@ -490,7 +489,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg, return 0; } - list_add(&lvdl->list, &dl->lvs); + list_add(&dl->lvs, &lvdl->list); dl->pv.lv_cur++; } return 1; @@ -498,12 +497,12 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg, int export_uuids(struct disk_list *dl, struct volume_group *vg) { - struct list_head *tmp; struct uuid_list *ul; struct pv_list *pvl; + struct list *pvh; - list_for_each(tmp, &vg->pvs) { - pvl = list_entry(tmp, struct pv_list, list); + list_iterate(pvh, &vg->pvs) { + pvl = list_item(pvh, struct pv_list); if (!(ul = pool_alloc(dl->mem, sizeof(*ul)))) { stack; return 0; @@ -512,7 +511,7 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg) memset(ul->uuid, 0, sizeof(ul->uuid)); memcpy(ul->uuid, pvl->pv.id.uuid, ID_LEN); - list_add(&ul->list, &dl->uuids); + list_add(&dl->uuids, &ul->list); } return 1; } @@ -520,12 +519,11 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg) static int _get_lv_number(struct volume_group *vg, const char *name) { /* FIXME: inefficient */ - struct list_head *tmp; - struct lv_list *ll; int r = 0; + struct list *lvh; - list_for_each (tmp, &vg->lvs) { - ll = list_entry(tmp, struct lv_list, list); + list_iterate(lvh, &vg->lvs) { + struct lv_list *ll = list_item(lvh, struct lv_list); if (!strcmp(ll->lv.name, name)) break; r++; @@ -539,19 +537,19 @@ static int _get_lv_number(struct volume_group *vg, const char *name) * lv_number fields used by LVM1. Very * inefficient code. */ -void export_numbers(struct list_head *pvs, struct volume_group *vg) +void export_numbers(struct list *pvs, struct volume_group *vg) { - struct list_head *tmp, *tmp2; + struct list *pvh, *lvh; struct disk_list *dl; struct lvd_list *ll; int pv_num = 1; - list_for_each (tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); dl->pv.pv_number = pv_num++; - list_for_each (tmp2, &dl->lvs) { - ll = list_entry(tmp2, struct lvd_list, list); + list_iterate(lvh, &dl->lvs) { + ll = list_item(lvh, struct lvd_list); ll->lv.lv_number = _get_lv_number(vg, ll->lv.lv_name); } } @@ -560,28 +558,28 @@ void export_numbers(struct list_head *pvs, struct volume_group *vg) /* * Calculate vg_disk->pv_act. */ -void export_pv_act(struct list_head *pvs) +void export_pv_act(struct list *pvs) { - struct list_head *tmp; + struct list *pvh; struct disk_list *dl; int act = 0; - list_for_each (tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); if (dl->pv.pv_status & PV_ACTIVE) act++; } - list_for_each (tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); dl->vg.pv_act = act; } } -int export_vg_number(struct list_head *pvs, const char *vg_name, +int export_vg_number(struct list *pvs, const char *vg_name, struct dev_filter *filter) { - struct list_head *tmp; + struct list *pvh; struct disk_list *dl; int vg_num; @@ -590,8 +588,8 @@ int export_vg_number(struct list_head *pvs, const char *vg_name, return 0; } - list_for_each (tmp, pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, pvs) { + dl = list_item(pvh, struct disk_list); dl->vg.vg_number = vg_num; } diff --git a/lib/format1/layout.c b/lib/format1/layout.c index e4a9f166a..2a4f48ac7 100644 --- a/lib/format1/layout.c +++ b/lib/format1/layout.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "disk-rep.h" diff --git a/lib/format1/vg_number.c b/lib/format1/vg_number.c index 19c25414d..909797e7a 100644 --- a/lib/format1/vg_number.c +++ b/lib/format1/vg_number.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "log.h" @@ -18,12 +18,13 @@ int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg, int *result) { - struct list_head all_pvs, *tmp; + struct list *pvh; + struct list all_pvs; struct disk_list *dl; struct pool *mem = pool_create(10 * 1024); int numbers[MAX_VG], i, r = 0; - INIT_LIST_HEAD(&all_pvs); + list_init(&all_pvs); if (!mem) { stack; @@ -37,8 +38,8 @@ int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg, memset(numbers, 0, sizeof(numbers)); - list_for_each (tmp, &all_pvs) { - dl = list_entry(tmp, struct disk_list, list); + list_iterate(pvh, &all_pvs) { + dl = list_item(pvh, struct disk_list); if (!strcmp(dl->pv.vg_name, candidate_vg)) continue; diff --git a/lib/log/log.c b/lib/log/log.c index 70827fed6..60510421a 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "log.h" diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 19194a693..7c2968d1a 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "log.h" @@ -91,7 +91,7 @@ int _add_pv_to_vg(struct io_space *ios, struct volume_group *vg, memcpy(&pvl->pv, pv, sizeof (struct physical_volume)); - list_add(&pvl->list, &vg->pvs); + list_add(&vg->pvs, &pvl->list); vg->pv_count++; return 1; @@ -154,10 +154,10 @@ struct volume_group *vg_create(struct io_space *ios, const char *vg_name, vg->max_pv = max_pv; vg->pv_count = 0; - INIT_LIST_HEAD(&vg->pvs); + list_init(&vg->pvs); vg->lv_count = 0; - INIT_LIST_HEAD(&vg->lvs); + list_init(&vg->lvs); if (!ios->vg_setup(ios, vg)) { log_error("Format specific setup of volume group '%s' failed.", @@ -216,13 +216,13 @@ struct physical_volume *pv_create(struct io_space *ios, const char *name) return NULL; } -struct list_head *find_pv_in_vg(struct volume_group *vg, const char *pv_name) +struct list *find_pv_in_vg(struct volume_group *vg, const char *pv_name) { - struct list_head *pvh; + struct list *pvh; struct pv_list *pv; - list_for_each(pvh, &vg->pvs) { - pv = list_entry(pvh, struct pv_list, list); + list_iterate(pvh, &vg->pvs) { + pv = list_item(pvh, struct pv_list); /* FIXME check dev not name */ if (!strcmp(dev_name(pv->pv.dev), pv_name)) return pvh; @@ -232,10 +232,9 @@ struct list_head *find_pv_in_vg(struct volume_group *vg, const char *pv_name) } -struct list_head *find_lv_in_vg(struct volume_group *vg, const char *lv_name) +struct list *find_lv_in_vg(struct volume_group *vg, const char *lv_name) { - struct list_head *lvh; - + struct list *lvh; const char *ptr; /* Use last component */ @@ -243,10 +242,9 @@ struct list_head *find_lv_in_vg(struct volume_group *vg, const char *lv_name) ptr++; else ptr = lv_name; - - list_for_each(lvh, &vg->lvs) - if (!strcmp(list_entry(lvh, struct lv_list, list)->lv.name, - ptr)) + + list_iterate(lvh, &vg->lvs) + if (!strcmp(list_item(lvh, struct lv_list)->lv.name, ptr)) return lvh; return NULL; @@ -254,23 +252,22 @@ struct list_head *find_lv_in_vg(struct volume_group *vg, const char *lv_name) struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name) { - struct list_head *lvh; + struct list *lvh; if ((lvh = find_lv_in_vg(vg, lv_name))) - return &list_entry(lvh, struct lv_list, list)->lv; + return &list_item(lvh, struct lv_list)->lv; else return NULL; } -struct physical_volume *_find_pv(struct volume_group *vg, - struct device *dev) +struct physical_volume *_find_pv(struct volume_group *vg, struct device *dev) { - struct list_head *tmp; + struct list *pvh; struct physical_volume *pv; struct pv_list *pl; - list_for_each(tmp, &vg->pvs) { - pl = list_entry(tmp, struct pv_list, list); + list_iterate(pvh, &vg->pvs) { + pl = list_item(pvh, struct pv_list); pv = &pl->pv; if (dev == pv->dev) return pv; @@ -278,7 +275,7 @@ struct physical_volume *_find_pv(struct volume_group *vg, return NULL; } -int lv_remove(struct volume_group *vg, struct list_head *lvh) +int lv_remove(struct volume_group *vg, struct list *lvh) { list_del(lvh); vg->lv_count--; diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 002c5a655..300fa0fb7 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -95,25 +95,25 @@ struct volume_group { /* physical volumes */ uint32_t pv_count; - struct list_head pvs; + struct list pvs; /* logical volumes */ uint32_t lv_count; - struct list_head lvs; + struct list lvs; }; struct name_list { - struct list_head list; + struct list list; char *name; }; struct pv_list { - struct list_head list; + struct list list; struct physical_volume pv; }; struct lv_list { - struct list_head list; + struct list list; struct logical_volume lv; }; @@ -124,12 +124,12 @@ struct io_space { /* * Returns a name_list of vg's. */ - struct list_head *(*get_vgs)(struct io_space *is); + struct list *(*get_vgs)(struct io_space *is); /* * Returns pv_list of fully-populated pv structures. */ - struct list_head *(*get_pvs)(struct io_space *is); + struct list *(*get_pvs)(struct io_space *is); /* * Return PV with given path. @@ -234,13 +234,13 @@ struct physical_volume *pv_find(struct volume_group *vg, int lv_add(struct volume_group *vg, struct logical_volume *lv); /* Remove an LV from a given VG */ -int lv_remove(struct volume_group *vg, struct list_head *lvh); +int lv_remove(struct volume_group *vg, struct list *lvh); /* Find a PV within a given VG */ -struct list_head *find_pv_in_vg(struct volume_group *vg, const char *pv_name); +struct list *find_pv_in_vg(struct volume_group *vg, const char *pv_name); /* Find an LV within a given VG */ -struct list_head *find_lv_in_vg(struct volume_group *vg, const char *lv_name); +struct list *find_lv_in_vg(struct volume_group *vg, const char *lv_name); /* Return the VG that contains a given LV (based on path given in lv_name) */ /* or environment var */ diff --git a/lib/mm/dbg_malloc.c b/lib/mm/dbg_malloc.c index 4c6b3cf0a..6358adde9 100644 --- a/lib/mm/dbg_malloc.c +++ b/lib/mm/dbg_malloc.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include diff --git a/lib/mm/pool.c b/lib/mm/pool.c index 65fb3f6bd..4fc3a92dd 100644 --- a/lib/mm/pool.c +++ b/lib/mm/pool.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include diff --git a/lib/regex/matcher.c b/lib/regex/matcher.c index c41c00373..9fc5e47a3 100644 --- a/lib/regex/matcher.c +++ b/lib/regex/matcher.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "matcher.h" diff --git a/lib/regex/parse_rx.c b/lib/regex/parse_rx.c index 285971c09..53f023b54 100644 --- a/lib/regex/parse_rx.c +++ b/lib/regex/parse_rx.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "parse_rx.h" diff --git a/lib/regex/ttree.c b/lib/regex/ttree.c index 90436dc5e..fbc54bd53 100644 --- a/lib/regex/ttree.c +++ b/lib/regex/ttree.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "ttree.h" diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c index a96b5ad67..b3dc7d77e 100644 --- a/lib/uuid/uuid.c +++ b/lib/uuid/uuid.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2001 Sistina Software (UK) Limited. * - * This file is released under the GPL. + * This file is released under the LGPL. */ #include "uuid.h" diff --git a/libdm/datastruct/list.h b/libdm/datastruct/list.h index 29b7ec3f8..8fbe1aefa 100644 --- a/libdm/datastruct/list.h +++ b/libdm/datastruct/list.h @@ -1,110 +1,55 @@ -/* stolen from the Linux kernel. */ +/* + * Copyright (C) 2001 Sistina Software + * + * This file is released under the LGPL. + */ #ifndef _LVM_LIST_H #define _LVM_LIST_H -/* - * Simple doubly linked list implementation. - * - * Some of the internal functions ("__xxx") are useful when - * manipulating whole lists rather than single entries, as - * sometimes we already know the next/prev entries and we can - * generate better code by using them directly rather than - * using the generic single-entry routines. - */ +#include -struct list_head { - struct list_head *next, *prev; +struct list { + struct list *n, *p; }; -#define LIST_HEAD_INIT(name) { &(name), &(name) } - -#define LIST_HEAD(name) \ - struct list_head name = { &name, &name } - -#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) - -/* - * Insert a new entry between two known consecutive entries. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_add(struct list_head *new, - struct list_head *prev, - struct list_head *next) -{ - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; +static inline void list_init(struct list *head) { + head->n = head->p = head; } -/* - * Insert a new entry after the specified head.. - */ -static __inline__ void list_add(struct list_head *new, struct list_head *head) -{ - __list_add(new, head, head->next); +static inline void list_add(struct list *head, struct list *elem) { + assert(head->n); + + elem->n = head; + elem->p = head->p; + + head->p->n = elem; + head->p = elem; } -/* - * Insert a new entry at the tail - */ -static __inline__ void list_add_tail(struct list_head *new, struct list_head *head) -{ - __list_add(new, head->prev, head); +static inline void list_add_h(struct list *head, struct list *elem) { + assert(head->n); + + elem->n = head->n; + elem->p = head; + + head->n->p = elem; + head->n = elem; } -/* - * Delete a list entry by making the prev/next entries - * point to each other. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_del(struct list_head * prev, - struct list_head * next) -{ - next->prev = prev; - prev->next = next; +static inline void list_del(struct list *elem) { + elem->n->p = elem->p; + elem->p->n = elem->n; } -static __inline__ void list_del(struct list_head *entry) -{ - __list_del(entry->prev, entry->next); +static inline int list_empty(struct list *head) { + return head->n == head; } -static __inline__ int list_empty(struct list_head *head) -{ - return head->next == head; -} +#define list_iterate(v, head) \ + for (v = (head)->n; v != head; v = v->n) -/* - * Splice in "list" into "head" - */ -static __inline__ void list_splice(struct list_head *list, struct list_head *head) -{ - struct list_head *first = list->next; - - if (first != list) { - struct list_head *last = list->prev; - struct list_head *at = head->next; - - first->prev = head; - head->next = first; - - last->next = at; - at->prev = last; - } -} - -#define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) - -#define list_for_each(pos, head) \ - for (pos = (head)->next; pos != (head); pos = pos->next) +#define list_item(v, t) \ + ((t *)((char *)(v) - (unsigned int) &((t *) 0)->list)) #endif diff --git a/tools/lvchange.c b/tools/lvchange.c index 8b988f63e..a224427db 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -59,7 +59,7 @@ static int lvchange_single(char *lv_name) int doit = 0; struct volume_group *vg; - struct list_head *lvh; + struct list *lvh; struct logical_volume *lv; /* FIXME Common code here - Add to a foreach? */ @@ -86,7 +86,7 @@ static int lvchange_single(char *lv_name) return ECMD_FAILED; } - lv = &list_entry(lvh, struct lv_list, list)->lv; + lv = &list_item(lvh, struct lv_list)->lv; if (lv->status & SNAPSHOT_ORG) { log_error("Can't change logical volume %s under snapshot", diff --git a/tools/lvremove.c b/tools/lvremove.c index 252c40d95..cc2d17f37 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -45,7 +45,7 @@ int lvremove_single(char *lv_name) char *vg_name = NULL; struct volume_group *vg; - struct list_head *lvh; + struct list *lvh; struct logical_volume *lv; /* does VG exist? */ @@ -71,7 +71,7 @@ int lvremove_single(char *lv_name) return ECMD_FAILED; } - lv = &list_entry(lvh, struct lv_list, list)->lv; + lv = &list_item(lvh, struct lv_list)->lv; if (lv->status & SNAPSHOT_ORG) { log_error("Can't remove logical volume %s under snapshot", diff --git a/tools/lvscan.c b/tools/lvscan.c index a7ee974b5..cb17881dd 100644 --- a/tools/lvscan.c +++ b/tools/lvscan.c @@ -69,7 +69,7 @@ static int lvscan_single(const char *vg_name) struct volume_group *vg; struct logical_volume *lv; - struct list_head *lvh; + struct list *lvh; log_verbose("Checking for volume group %s", vg_name); if (!(vg = ios->vg_read(ios, vg_name))) { @@ -84,8 +84,8 @@ static int lvscan_single(const char *vg_name) vg_total++; - list_for_each(lvh, &vg->lvs) { - lv = &list_entry(lvh, struct lv_list, list)->lv; + list_iterate(lvh, &vg->lvs) { + lv = &list_item(lvh, struct lv_list)->lv; if (lv->status & ACTIVE) { active_str = "ACTIVE "; diff --git a/tools/pvchange.c b/tools/pvchange.c index 7fbdc4ce8..94dae99a0 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -31,7 +31,7 @@ int pvchange(int argc, char **argv) struct physical_volume *pv; char *pv_name; - struct list_head *pvh, *pvs; + struct list *pvh, *pvs; if (arg_count(allocation_ARG) == 0) { log_error("Please give the x option"); @@ -66,10 +66,10 @@ int pvchange(int argc, char **argv) return ECMD_FAILED; } - list_for_each(pvh, pvs) { + list_iterate(pvh, pvs) { total++; - done += pvchange_single(&list_entry(pvh, struct pv_list, - list)->pv); + done += pvchange_single( + &list_item(pvh, struct pv_list)->pv); } } @@ -87,7 +87,7 @@ int pvchange(int argc, char **argv) int pvchange_single(struct physical_volume *pv) { struct volume_group *vg = NULL; - struct list_head *pvh; + struct list *pvh; const char *pv_name = dev_name(pv->dev); @@ -107,7 +107,7 @@ int pvchange_single(struct physical_volume *pv) pv_name, vg->name); return 0; } - pv = &list_entry(pvh, struct pv_list, list)->pv; + pv = &list_item(pvh, struct pv_list)->pv; } /* change allocatability for a PV */ diff --git a/tools/pvdisplay.c b/tools/pvdisplay.c index 2484f56ba..c8cff098b 100644 --- a/tools/pvdisplay.c +++ b/tools/pvdisplay.c @@ -26,7 +26,7 @@ int pvdisplay(int argc, char **argv) { int opt=0; - struct list_head *pvh, *pvs; + struct list *pvh, *pvs; struct physical_volume *pv; if (arg_count(colon_ARG) && arg_count(verbose_ARG)) { @@ -50,8 +50,8 @@ int pvdisplay(int argc, char **argv) if (!(pvs = ios->get_pvs(ios))) return ECMD_FAILED; - list_for_each(pvh, pvs) - pvdisplay_single(&list_entry(pvh, struct pv_list, list)->pv); + list_iterate(pvh, pvs) + pvdisplay_single(&list_item(pvh, struct pv_list)->pv); } return 0; diff --git a/tools/pvscan.c b/tools/pvscan.c index 6242369aa..93d5c3287 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -31,8 +31,8 @@ int pvscan(int argc, char **argv) int pvs_found = 0; char *s1, *s2, *s3; - struct list_head *pvs; - struct list_head *pvh; + struct list *pvs; + struct list *pvh; struct pv_list *pvl; struct physical_volume *pv; @@ -61,13 +61,13 @@ int pvscan(int argc, char **argv) return ECMD_FAILED; /* eliminate exported/new if required */ - list_for_each(pvh, pvs) { - pvl = list_entry(pvh, struct pv_list, list); + list_iterate(pvh, pvs) { + pvl = list_item(pvh, struct pv_list); pv = &pvl->pv; if ((arg_count(exported_ARG) && !(pv->status & EXPORTED_VG)) || (arg_count(novolumegroup_ARG) && (*pv->vg_name))) { - list_del(&pvl->list); + list_del(&pvl->list); continue; } @@ -88,15 +88,15 @@ int pvscan(int argc, char **argv) new_pvs_found++; size_new += pv->size; size_total += pv->size; - } else - size_total += (pv->pe_count - pv->pe_allocated) + } else + size_total += (pv->pe_count - pv->pe_allocated) * pv->pe_size; } /* find maximum pv name length */ pv_max_name_len = vg_max_name_len = 0; - list_for_each(pvh, pvs) { - pv = &list_entry(pvh, struct pv_list, list)->pv; + list_iterate(pvh, pvs) { + pv = &list_item(pvh, struct pv_list)->pv; len = strlen(dev_name(pv->dev)); if (pv_max_name_len < len) pv_max_name_len = len; @@ -107,8 +107,8 @@ int pvscan(int argc, char **argv) pv_max_name_len += 2; vg_max_name_len += 2; - list_for_each(pvh, pvs) - pvscan_display_single(&list_entry(pvh, struct pv_list, list)->pv); + list_iterate(pvh, pvs) + pvscan_display_single(&list_item(pvh, struct pv_list)->pv); if (!pvs_found) { log_print("No matching physical volumes found"); diff --git a/tools/toollib.c b/tools/toollib.c index 74f172d37..79b945f43 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -94,8 +94,8 @@ int process_each_vg(int argc, char **argv, int ret_max = 0; int ret = 0; - struct list_head *vgh; - struct list_head *vgs_list; + struct list *vgh; + struct list *vgs_list; if (argc) { log_verbose("Using volume group(s) on command line"); @@ -108,10 +108,9 @@ int process_each_vg(int argc, char **argv, log_error("No volume groups found"); return ECMD_FAILED; } - list_for_each(vgh, vgs_list) { - ret = - process_single(list_entry - (vgh, struct name_list, list)->name); + list_iterate(vgh, vgs_list) { + ret = process_single( + list_item(vgh, struct name_list)->name); if (ret > ret_max) ret_max = ret; } @@ -128,7 +127,7 @@ int process_each_pv(int argc, char **argv, struct volume_group *vg, int ret_max = 0; int ret = 0; - struct list_head *pvh; + struct list *pvh; if (argc) { log_verbose("Using physical volume(s) on command line"); @@ -139,16 +138,16 @@ int process_each_pv(int argc, char **argv, struct volume_group *vg, vg->name); continue; } - ret = process_single(vg, &list_entry - (pvh, struct pv_list, list)->pv); + ret = process_single(vg, + &list_item(pvh, struct pv_list)->pv); if (ret > ret_max) ret_max = ret; } } else { log_verbose("Using all physical volume(s) in volume group"); - list_for_each(pvh, &vg->pvs) { - ret = process_single(vg, &list_entry - (pvh, struct pv_list, list)->pv); + list_iterate(pvh, &vg->pvs) { + ret = process_single(vg, + &list_item(pvh, struct pv_list)->pv); if (ret > ret_max) ret_max = ret; } diff --git a/tools/vgchange.c b/tools/vgchange.c index 866acc021..6630cf994 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -79,7 +79,7 @@ static int vgchange_single(const char *vg_name) void vgchange_available(struct volume_group *vg) { int lv_open; - struct list_head *pvh; + struct list *pvh; int available = !strcmp(arg_str_value(available_ARG, "n"), "y"); /* FIXME Kernel status to override disk flags ! */ @@ -102,13 +102,13 @@ void vgchange_available(struct volume_group *vg) if (available) { vg->status |= ACTIVE; - list_for_each(pvh, &vg->pvs) - list_entry(pvh, struct pv_list, list)->pv.status + list_iterate(pvh, &vg->pvs) + list_item(pvh, struct pv_list)->pv.status |= ACTIVE; } else { vg->status &= ~ACTIVE; - list_for_each(pvh, &vg->pvs) - list_entry(pvh, struct pv_list, list)->pv.status + list_iterate(pvh, &vg->pvs) + list_item(pvh, struct pv_list)->pv.status &= ~ACTIVE; } diff --git a/tools/vgreduce.c b/tools/vgreduce.c index 4d4e6fecd..5bfdbbc9d 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -87,7 +87,7 @@ int vgreduce(int argc, char **argv) /* Or take pv_name instead? */ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv) { - struct list_head *pvh; + struct list *pvh; const char *name = dev_name(pv->dev); if (pv->pe_allocated) { diff --git a/tools/vgremove.c b/tools/vgremove.c index 1a20d507b..eec50db76 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -31,7 +31,7 @@ static int vgremove_single(const char *vg_name) { struct volume_group *vg; struct physical_volume *pv; - struct list_head *pvh; + struct list *pvh; int ret = 0; log_verbose("Checking for volume group %s", vg_name); @@ -59,8 +59,8 @@ static int vgremove_single(const char *vg_name) *************/ /* init physical volumes */ - list_for_each(pvh, &vg->pvs) { - pv = &list_entry(pvh, struct pv_list, list)->pv; + list_iterate(pvh, &vg->pvs) { + pv = &list_item(pvh, struct pv_list)->pv; log_verbose("Removing physical volume %s from volume group %s", dev_name(pv->dev), vg_name); *pv->vg_name = '\0'; diff --git a/tools/vgrename.c b/tools/vgrename.c index 571185028..c97116955 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -30,7 +30,7 @@ int vgrename(int argc, char **argv) char old_path[NAME_LEN], new_path[NAME_LEN]; struct volume_group *vg_old, *vg_new; - struct list_head *pvh; + struct list *pvh; if (argc != 2) { log_error("old and new volume group names need specifying"); @@ -91,8 +91,8 @@ int vgrename(int argc, char **argv) strcpy(vg_old->name, vg_name_new); /* FIXME Should vg_write fix these implicitly? It has to check them. */ - list_for_each(pvh, &vg_old->pvs) { - strcpy(list_entry(pvh, struct pv_list, list)->pv.vg_name, + list_iterate(pvh, &vg_old->pvs) { + strcpy(list_item(pvh, struct pv_list)->pv.vg_name, vg_name_new); }