mirror of
git://sourceware.org/git/lvm2.git
synced 2025-05-19 14:50:39 +03:00
o use dev_name(dev) to get the name of a device, this operation is cheap
since it just get's the first alias.
This commit is contained in:
parent
3cfae6cfce
commit
c7f0b573ac
@ -51,29 +51,18 @@ static struct {
|
||||
|
||||
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) {
|
||||
if (!(dev = _alloc(sizeof(*dev)))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(dev = _alloc(sizeof(*dev)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
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)
|
||||
@ -103,15 +92,9 @@ static int _insert_dev(const char *path, dev_t d)
|
||||
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;
|
||||
}
|
||||
@ -123,9 +106,8 @@ static int _insert_dev(const char *path, dev_t d)
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,17 @@ int dev_get_size(struct device *dev, uint64_t *size)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -66,15 +67,16 @@ int64_t dev_read(struct device *dev, uint64_t offset,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -107,15 +109,16 @@ int64_t dev_write(struct device *dev, uint64_t offset,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
* pointer comparisons are valid.
|
||||
*/
|
||||
struct device {
|
||||
char *name;
|
||||
struct list_head aliases; /* struct str_list from lvm-types.h */
|
||||
dev_t dev;
|
||||
};
|
||||
@ -31,6 +30,10 @@ int64_t dev_read(struct device *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;
|
||||
|
@ -102,7 +102,7 @@ void pvdisplay_colons(struct physical_volume *pv)
|
||||
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? */
|
||||
@ -133,7 +133,7 @@ void pvdisplay_full(struct physical_volume * pv)
|
||||
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);
|
||||
@ -194,7 +194,7 @@ void pv_display_short(struct physical_volume *pv)
|
||||
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 ",
|
||||
|
@ -162,13 +162,13 @@ int persistent_filter_dump(struct dev_filter *f)
|
||||
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;
|
||||
|
@ -151,7 +151,7 @@ static int _accept_p(struct dev_filter *f, struct device *dev)
|
||||
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,
|
||||
|
@ -55,17 +55,19 @@ static device_info_t device_info[] = {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -237,25 +237,27 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -263,33 +265,33 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem,
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -350,7 +352,7 @@ static int _write_uuids(struct disk_list *data)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -423,7 +425,7 @@ static int _write_pv(struct disk_list *data)
|
||||
|
||||
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);
|
||||
@ -474,7 +476,7 @@ int write_pvs(struct list_head *pvs)
|
||||
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;
|
||||
|
@ -29,7 +29,7 @@ static int _check_vgs(struct list_head *pvs)
|
||||
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++;
|
||||
|
@ -130,7 +130,7 @@ int calculate_extent_count(struct physical_volume *pv)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -218,10 +218,13 @@ struct physical_volume *pv_create(struct io_space *ios, const char *name)
|
||||
|
||||
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;
|
||||
|
@ -89,7 +89,7 @@ int pvchange_single(struct physical_volume *pv)
|
||||
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");
|
||||
|
||||
@ -135,7 +135,7 @@ int pvchange_single(struct physical_volume *pv)
|
||||
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 "
|
||||
|
@ -62,11 +62,11 @@ void pvdisplay_single(struct physical_volume *pv)
|
||||
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)) {
|
||||
@ -77,7 +77,7 @@ void pvdisplay_single(struct physical_volume *pv)
|
||||
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);
|
||||
|
||||
@ -87,7 +87,7 @@ void pvdisplay_single(struct physical_volume *pv)
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ int pvscan(int argc, char **argv)
|
||||
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);
|
||||
@ -143,7 +143,7 @@ void pvscan_display_single(struct physical_volume *pv)
|
||||
|
||||
/* short listing? */
|
||||
if (arg_count(short_ARG) > 0) {
|
||||
log_print("%s", pv->dev->name);
|
||||
log_print("%s", dev_name(pv->dev));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -167,9 +167,9 @@ void pvscan_display_single(struct physical_volume *pv)
|
||||
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) {
|
||||
|
@ -88,9 +88,10 @@ int vgreduce(int argc, char **argv)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -102,31 +103,30 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv)
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -62,11 +62,12 @@ static int vgremove_single(const char *vg_name)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user