]> sourceware.org Git - lvm2.git/commitdiff
o use dev_name(dev) to get the name of a device, this operation is cheap
authorJoe Thornber <thornber@redhat.com>
Thu, 25 Oct 2001 14:04:18 +0000 (14:04 +0000)
committerJoe Thornber <thornber@redhat.com>
Thu, 25 Oct 2001 14:04:18 +0000 (14:04 +0000)
  since it just get's the first alias.

16 files changed:
lib/device/dev-cache.c
lib/device/dev-io.c
lib/device/device.h
lib/display/display.c
lib/filters/filter-persistent.c
lib/filters/filter-regex.c
lib/filters/filter.c
lib/format1/disk-rep.c
lib/format1/format1.c
lib/format1/layout.c
lib/metadata/metadata.c
tools/pvchange.c
tools/pvdisplay.c
tools/pvscan.c
tools/vgreduce.c
tools/vgremove.c

index 7b4d6a79364e3801ee591ddd12caf4fc87dad70d..11336ba8cf77b19d3819f0d5f41d0d45e53cac6a 100644 (file)
@@ -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) {
-               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)
@@ -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;
        }
 
index 60c37b6b11d0d7d9f227e876be94b0b3bb30419a..8d132396eb7260077310d4d110b24694cba299c0 100644 (file)
@@ -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;
        }
 
index bf6354e839a3ddea52c23c30b884ea30cf98c4dd..b4bdd9d4044f270984c03d4f3db4314de110b936 100644 (file)
@@ -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;
index c4d4692baf0b2b556dcee731ea8316aa3a67628b..4ae15a57b5fbf78732592f4f3df541a5a208ea14 100644 (file)
@@ -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 ",
index 9750b398d2935762340ce676a3432df2fa4c0b24..690c07b22a42dd935355f5823a1b91c8cc712bc0 100644 (file)
@@ -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;
index 4054f652ae652ca5b4282eaad42ed5680dae64e4..34c34eb1aed75618dcf837b4ecbb11f13eea077a 100644 (file)
@@ -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,
index 30eb3b6d5d6b34510d7a51dc44209416af16d83c..2cb6434fc2e34960b8ab4c33f820284a10710145 100644 (file)
@@ -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;
        }
 
index 94a6f34388dca8230b87d729bbb513b443f43082..50f4a7fd9b979d25ab7d24e100e3e462e7b7e8dc 100644 (file)
@@ -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;
index 1c7167f8530140f24d8483f95b83f177de41802d..837fde5f7506f9c32e1cb468c8fefc0bd24d38f2 100644 (file)
@@ -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++;
index c1aeb57407b7bf1869505becf3b0a8a74af39d18..e4a9f166a215d0c17251b63bda7de76adf1006cb 100644 (file)
@@ -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;
        }
 
index 95d28041c63b5ca2b847c86f732301affc5f2d6d..0a8f26af051fb5f0a3a27564759a333d1ae3e79f 100644 (file)
@@ -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;
index 3ab5a65ff694fd3efa3e31e8f35c5b1851e4125e..7fbdc4ce80b7ebf18a214a385f5abeee9f4e96b2 100644 (file)
@@ -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 "
index 3ba3af94ad0cc8a9b09ec47b7354df66691e191b..2484f56baaeccab2c9aa72b67a6c42d6ecc7a1fb 100644 (file)
@@ -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);
        }
index 7adc59f6ef30f8586d4def5fae0bae81f89d385f..6242369aa251f00dc2a46e79e5894b4159907aab 100644 (file)
@@ -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) {
index 83581ee58e382941b4f7f20045933b231520dfa9..4d4e6fecde3422d8d7b4f61dab1bb47597ef0cab 100644 (file)
@@ -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;
 }
index da1bf299f2ce14a576ca8c332b8a4a0cbe78f48b..1a20d507bb407f1cf3c42c855e0f44174e2e54c4 100644 (file)
@@ -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;
                }
        }
This page took 0.062052 seconds and 5 git commands to generate.