since it just get's the first alias.
static int _insert(const char *path, int rec);
-static struct device *_create_dev(const char *path, dev_t d)
+static struct device *_create_dev(dev_t d)
{
struct device *dev;
- char *name = pool_strdup(_cache.mem, path);
-
- if (!name) {
- stack;
- return NULL;
- }
if (!(dev = _alloc(sizeof(*dev)))) {
stack;
- goto bad;
+ return NULL;
}
- dev->name = name;
INIT_LIST_HEAD(&dev->aliases);
dev->dev = d;
return dev;
-
- bad:
- _free(name);
- return NULL;
}
static int _add_alias(struct device *dev, const char *path)
struct device *dev;
/* is this device already registered ? */
- if ((dev = (struct device *) btree_lookup(_cache.devices, d))) {
- if (!_add_alias(dev, path)) {
- log_err("Couldn't add alias to dir cache.");
- return 0;
- }
-
- } else {
+ if (!(dev = (struct device *) btree_lookup(_cache.devices, d))) {
/* create new device */
- if (!(dev = _create_dev(path, d))) {
+ if (!(dev = _create_dev(d))) {
stack;
return 0;
}
}
}
- /* insert the name/alias */
- if (!(hash_insert(_cache.names, path, dev))) {
- log_err("Couldn't insert device into hash table.");
+ if (!_add_alias(dev, path)) {
+ log_err("Couldn't add alias to dir cache.");
return 0;
}
{
int fd;
long s;
+ const char *name = dev_name(dev);
- log_very_verbose("Getting size of %s", dev->name);
- if ((fd = open(dev->name, O_RDONLY)) < 0) {
- log_sys_error("open", dev->name);
+ log_very_verbose("Getting size of %s", name);
+ if ((fd = open(name, O_RDONLY)) < 0) {
+ log_sys_error("open", name);
return 0;
}
/* FIXME: add 64 bit ioctl */
if (ioctl(fd, BLKGETSIZE, &s) < 0) {
- log_sys_error("ioctl BLKGETSIZE", dev->name);
+ log_sys_error("ioctl BLKGETSIZE", name);
close(fd);
return 0;
}
int64_t len, void *buffer)
{
int64_t r;
- int fd = open(dev->name, O_RDONLY);
+ const char *name = dev_name(dev);
+ int fd = open(name, O_RDONLY);
if (fd < 0) {
- log_sys_very_verbose("open", dev->name);
+ log_sys_very_verbose("open", name);
return 0;
}
if (lseek(fd, offset, SEEK_SET) < 0) {
- log_sys_error("lseek", dev->name);
+ log_sys_error("lseek", name);
return 0;
}
int64_t len, void *buffer)
{
int64_t r;
- int fd = open(dev->name, O_WRONLY);
+ const char *name = dev_name(dev);
+ int fd = open(name, O_WRONLY);
if (fd < 0) {
- log_sys_error("open", dev->name);
+ log_sys_error("open", name);
return 0;
}
if (lseek(fd, offset, SEEK_SET) < 0) {
- log_sys_error("lseek", dev->name);
+ log_sys_error("lseek", name);
return 0;
}
* pointer comparisons are valid.
*/
struct device {
- char *name;
struct list_head aliases; /* struct str_list from lvm-types.h */
dev_t dev;
};
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;
+}
+
static inline int is_lvm_partition(const char *name) {
return 1;
uuid = display_uuid(pv->id.uuid);
log_print("%s:%s:%llu:-1:%u:%u:-1:%llu:%u:%u:%u:%s",
- pv->dev->name,
+ dev_name(pv->dev),
pv->vg_name,
pv->size,
/* FIXME pv->pv_number, Derive or remove? */
uuid = display_uuid(pv->id.uuid);
log_print("--- %sPhysical volume ---", pv->pe_size ? "" : "NEW ");
- log_print("PV Name %s", pv->dev->name);
+ log_print("PV Name %s", dev_name(pv->dev));
log_print("VG Name %s", pv->vg_name);
size = display_size(pv->size / 2, SIZE_SHORT);
if (!pv)
return;
- log_print("PV Name %s ", pv->dev->name);
+ log_print("PV Name %s ", dev_name(pv->dev));
/* FIXME pv->pv_number); */
log_print("PV Status %savailable / %sallocatable",
(pv->status & ACTIVE) ? "" : "NOT ",
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);
+ void *l = hash_lookup(pf->devices, dev_name(dev));
if (!l) {
l = pf->real->passes_filter(pf->real, dev) ?
PF_GOOD_DEVICE : PF_BAD_DEVICE;
- hash_insert(pf->devices, dev->name, l);
+ hash_insert(pf->devices, dev_name(dev), l);
}
return l == PF_GOOD_DEVICE;
int m;
struct rfilter *rf = (struct rfilter *) f->private;
- m = matcher_run(rf->engine, dev->name);
+ m = matcher_run(rf->engine, dev_name(dev));
/*
* pass everything that doesn't match,
static int *scan_proc_dev(void);
-static int passes_lvm_type_device_filter(struct dev_filter *f, struct device *dev)
+static int passes_lvm_type_device_filter(struct dev_filter *f,
+ struct device *dev)
{
int fd;
+ const char *name = dev_name(dev);
/* Is this a recognised device type? */
if (!(((int *) f->private)[MAJOR(dev->dev)]))
return 0;
/* Check it's accessible */
- if ((fd = open(dev->name, O_RDONLY)) < 0) {
- log_debug("Unable to open %s: %s", dev->name, strerror(errno));
+ if ((fd = open(name, O_RDONLY)) < 0) {
+ log_debug("Unable to open %s: %s", name, strerror(errno));
return 0;
}
const char *vg_name)
{
struct disk_list *data = pool_alloc(mem, sizeof(*data));
+ const char *name = dev_name(dev);
+
data->dev = dev;
data->mem = mem;
INIT_LIST_HEAD(&data->uuids);
INIT_LIST_HEAD(&data->lvs);
if (!_read_pv(data)) {
- log_debug("Failed to read PV data from %s", dev->name);
+ log_debug("Failed to read PV data from %s", name);
goto bad;
}
if (data->pv.id[0] != 'H' || data->pv.id[1] != 'M') {
log_very_verbose("%s does not have a valid PV identifier",
- dev->name);
+ name);
goto bad;
}
if (!_munge_formats(&data->pv)) {
log_very_verbose("Unknown metadata version %d found on %s",
- data->pv.version, dev->name);
+ data->pv.version, name);
goto bad;
}
* is it an orphan ?
*/
if (data->pv.vg_name == '\0') {
- log_very_verbose("%s is not a member of any VG", dev->name);
+ log_very_verbose("%s is not a member of any VG", name);
return data;
}
if (vg_name && strcmp(vg_name, data->pv.vg_name)) {
log_very_verbose("%s is not a member of the VG %s",
- dev->name, vg_name);
+ name, vg_name);
goto bad;
}
if (!_read_vg(data)) {
- log_error("Failed to read VG data from PV (%s)", dev->name);
+ log_error("Failed to read VG data from PV (%s)", name);
goto bad;
}
if (!_read_uuids(data)) {
- log_error("Failed to read PV uuid list from %s", dev->name);
+ log_error("Failed to read PV uuid list from %s", name);
goto bad;
}
if (!_read_lvs(data)) {
- log_error("Failed to read LV's from %s", dev->name);
+ log_error("Failed to read LV's from %s", name);
goto bad;
}
if (!_read_extents(data)) {
- log_error("Failed to read extents from %s", dev->name);
+ log_error("Failed to read extents from %s", name);
goto bad;
}
list_for_each(tmp, &data->uuids) {
if (pos >= end) {
log_error("Too many uuids to fit on %s",
- data->dev->name);
+ dev_name(data->dev));
return 0;
}
static int _write_all_pv(struct disk_list *data)
{
- const char *pv_name = data->dev->name;
+ const char *pv_name = dev_name(data->dev);
if (!_write_pv(data)) {
log_error("Failed to write PV structure onto %s", pv_name);
if (!(_write_all_pv(dl)))
fail;
- log_debug("Successfully wrote data to %s", dl->dev->name);
+ log_debug("Successfully wrote data to %s", dev_name(dl->dev));
}
return 1;
first = dl;
else if (memcmp(&first->vg, &dl->vg, sizeof(first->vg))) {
log_err("VG data differs between PVs %s and %s",
- first->dev->name, dl->dev->name);
+ dev_name(first->dev), dev_name(dl->dev));
return 0;
}
pv_count++;
if (pvd->pe_total < PE_SIZE_PV_SIZE_REL) {
log_error("Insufficient space for extents on %s",
- pv->dev->name);
+ dev_name(pv->dev));
return 0;
}
struct list_head *find_pv_in_vg(struct volume_group *vg, const char *pv_name)
{
- struct list_head *pvh;
- list_for_each(pvh, &vg->pvs) {
- if (!strcmp(list_entry(pvh, struct pv_list, list)->pv.dev->name,
- pv_name)) return pvh;
+ struct list_head *tmp;
+ struct pv_list *pv;
+
+ list_for_each(tmp, &vg->pvs) {
+ pv = list_entry(tmp, struct pv_list, list);
+ if (!strcmp(dev_name(pv->pv.dev), pv_name))
+ return tmp;
}
return NULL;
struct volume_group *vg = NULL;
struct list_head *pvh;
- char *pv_name = pv->dev->name;
+ const char *pv_name = dev_name(pv->dev);
int allocation = !strcmp(arg_str_value(allocation_ARG, "n"), "y");
log_verbose("Physical volume %s inactive", pv_name);
}
- log_verbose("Updating physical volume %s", pv->dev->name);
+ log_verbose("Updating physical volume %s", pv_name);
if (*pv->vg_name) {
if (!(ios->vg_write(ios,vg))) {
log_error("Failed to store physical volume %s in "
char *sz;
uint64_t size;
- char *pv_name = pv->dev->name;
+ const char *pv_name = dev_name(pv->dev);
if (!*pv->vg_name)
size = pv->size;
- else
+ else
size = (pv->pe_count - pv->pe_allocated) * pv->pe_size;
if (arg_count(short_ARG)) {
return;
}
- if (pv->status & EXPORTED_VG)
+ if (pv->status & EXPORTED_VG)
log_print("Physical volume '%s' of volume group '%s' "
"is exported" , pv_name, pv->vg_name);
if (!pv->vg_name) {
log_print ( "'%s' is a new physical volume of %s",
- pv_name, ( sz = display_size ( size / 2,
+ pv_name, ( sz = display_size ( size / 2,
SIZE_SHORT)));
dbg_free(sz);
}
pv_max_name_len = vg_max_name_len = 0;
list_for_each(pvh, pvs) {
pv = &list_entry(pvh, struct pv_list, list)->pv;
- len = strlen(pv->dev->name);
+ len = strlen(dev_name(pv->dev));
if (pv_max_name_len < len)
pv_max_name_len = len;
len = strlen(pv->vg_name);
/* short listing? */
if (arg_count(short_ARG) > 0) {
- log_print("%s", pv->dev->name);
+ log_print("%s", dev_name(pv->dev));
return;
}
sprintf(pv_tmp_name,
"%-*s with UUID %s",
pv_max_name_len - 2,
- pv->dev->name, display_uuid(pv->id.uuid));
+ dev_name(pv->dev), display_uuid(pv->id.uuid));
} else {
- sprintf(pv_tmp_name, "%s", pv->dev->name);
+ sprintf(pv_tmp_name, "%s", dev_name(pv->dev));
}
if (!*pv->vg_name) {
static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
{
struct list_head *pvh;
+ const char *name = dev_name(pv->dev);
if (pv->pe_allocated) {
- log_error("Physical volume %s still in use", pv->dev->name);
+ log_error("Physical volume %s still in use", name);
return ECMD_FAILED;
}
if (vg->pv_count == 1) {
log_error("Can't remove final physical volume %s from "
- "volume group %s", pv->dev->name, vg->name);
+ "volume group %s", name, vg->name);
return ECMD_FAILED;
}
- pvh = find_pv_in_vg(vg, pv->dev->name);
+ pvh = find_pv_in_vg(vg, name);
- log_verbose("Removing %s from volume group %s", pv->dev->name,
- vg->name);
+ log_verbose("Removing %s from volume group %s", name, vg->name);
list_del(pvh);
*pv->vg_name = '\0';
vg->pv_count--;
if (!(ios->vg_write(ios, vg))) {
log_error("Removal of physical volume %s from %s failed",
- pv->dev->name, vg->name);
+ name, vg->name);
return ECMD_FAILED;
}
if (!ios->pv_write(ios, pv)) {
log_error("Failed to clear metadata from physical volume %s "
- "after removal from %s", pv->dev->name, vg->name);
+ "after removal from %s", name, vg->name);
return ECMD_FAILED;
}
- log_print("Removed %s from volume group %s", pv->dev->name, vg->name);
+ log_print("Removed %s from volume group %s", name, vg->name);
return 0;
}
list_for_each(pvh, &vg->pvs) {
pv = &list_entry(pvh, struct pv_list, list)->pv;
log_verbose("Removing physical volume %s from volume group %s",
- pv->dev->name, vg_name);
+ dev_name(pv->dev), vg_name);
*pv->vg_name = '\0';
if (!(ios->pv_write(ios, pv))) {
log_error("Failed to remove physical volume %s from "
- "volume group %s", pv->dev->name, vg_name);
+ "volume group %s", dev_name(pv->dev),
+ vg_name);
ret = ECMD_FAILED;
}
}