diff options
author | Petr Rockai <prockai@redhat.com> | 2012-02-10 01:28:27 +0000 |
---|---|---|
committer | Petr Rockai <prockai@redhat.com> | 2012-02-10 01:28:27 +0000 |
commit | 8e5f7cf3dc1d75d0a370729326522bcac29b489d (patch) | |
tree | a8e7130afabb199942ac06ac6298b13ce4988266 /lib/format_text/text_label.c | |
parent | 5fa417a9c0aa2d7ea80e1087e0d2943536fc5b9d (diff) | |
download | lvm2-8e5f7cf3dc1d75d0a370729326522bcac29b489d.tar.gz lvm2-8e5f7cf3dc1d75d0a370729326522bcac29b489d.tar.xz lvm2-8e5f7cf3dc1d75d0a370729326522bcac29b489d.zip |
Move lvmcache data structures behind an API (making the structures private to
lvmcache.c). No functional change.
Diffstat (limited to 'lib/format_text/text_label.c')
-rw-r--r-- | lib/format_text/text_label.c | 203 |
1 files changed, 113 insertions, 90 deletions
diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c index 11f93e20..b4257a7d 100644 --- a/lib/format_text/text_label.c +++ b/lib/format_text/text_label.c @@ -35,15 +35,41 @@ static int _text_can_handle(struct labeller *l __attribute__((unused)), return 0; } +struct _da_setup_baton { + struct disk_locn *pvh_dlocn_xl; + struct device *dev; +}; + +static int _da_setup(struct data_area_list *da, void *baton) +{ + struct _da_setup_baton *p = baton; + p->pvh_dlocn_xl->offset = xlate64(da->disk_locn.offset); + p->pvh_dlocn_xl->size = xlate64(da->disk_locn.size); + p->pvh_dlocn_xl++; + return 1; +} + +static int _mda_setup(struct metadata_area *mda, void *baton) +{ + struct _da_setup_baton *p = baton; + struct mda_context *mdac = (struct mda_context *) mda->metadata_locn; + + if (mdac->area.dev != p->dev) + return 1; + + p->pvh_dlocn_xl->offset = xlate64(mdac->area.start); + p->pvh_dlocn_xl->size = xlate64(mdac->area.size); + p->pvh_dlocn_xl++; + + return 1; +} + static int _text_write(struct label *label, void *buf) { struct label_header *lh = (struct label_header *) buf; struct pv_header *pvhdr; struct lvmcache_info *info; - struct disk_locn *pvh_dlocn_xl; - struct metadata_area *mda; - struct mda_context *mdac; - struct data_area_list *da; + struct _da_setup_baton baton; char buffer[64] __attribute__((aligned(8))); int da1, mda1, mda2; @@ -54,43 +80,31 @@ static int _text_write(struct label *label, void *buf) pvhdr = (struct pv_header *) ((char *) buf + xlate32(lh->offset_xl)); info = (struct lvmcache_info *) label->info; - pvhdr->device_size_xl = xlate64(info->device_size); - memcpy(pvhdr->pv_uuid, &info->dev->pvid, sizeof(struct id)); + pvhdr->device_size_xl = xlate64(lvmcache_device_size(info)); + memcpy(pvhdr->pv_uuid, &lvmcache_device(info)->pvid, sizeof(struct id)); if (!id_write_format((const struct id *)pvhdr->pv_uuid, buffer, sizeof(buffer))) { stack; buffer[0] = '\0'; } - pvh_dlocn_xl = &pvhdr->disk_areas_xl[0]; + baton.dev = lvmcache_device(info); /* List of data areas (holding PEs) */ - dm_list_iterate_items(da, &info->das) { - pvh_dlocn_xl->offset = xlate64(da->disk_locn.offset); - pvh_dlocn_xl->size = xlate64(da->disk_locn.size); - pvh_dlocn_xl++; - } + baton.pvh_dlocn_xl = &pvhdr->disk_areas_xl[0]; + lvmcache_foreach_da(info, _da_setup, &baton); /* NULL-termination */ - pvh_dlocn_xl->offset = xlate64(UINT64_C(0)); - pvh_dlocn_xl->size = xlate64(UINT64_C(0)); - pvh_dlocn_xl++; + baton.pvh_dlocn_xl->offset = xlate64(UINT64_C(0)); + baton.pvh_dlocn_xl->size = xlate64(UINT64_C(0)); + baton.pvh_dlocn_xl++; /* List of metadata area header locations */ - dm_list_iterate_items(mda, &info->mdas) { - mdac = (struct mda_context *) mda->metadata_locn; - - if (mdac->area.dev != info->dev) - continue; - - pvh_dlocn_xl->offset = xlate64(mdac->area.start); - pvh_dlocn_xl->size = xlate64(mdac->area.size); - pvh_dlocn_xl++; - } + lvmcache_foreach_mda(info, _mda_setup, &baton); /* NULL-termination */ - pvh_dlocn_xl->offset = xlate64(UINT64_C(0)); - pvh_dlocn_xl->size = xlate64(UINT64_C(0)); + baton.pvh_dlocn_xl->offset = xlate64(UINT64_C(0)); + baton.pvh_dlocn_xl->size = xlate64(UINT64_C(0)); /* Create debug message with da and mda locations */ if (xlate64(pvhdr->disk_areas_xl[0].offset) || @@ -113,7 +127,7 @@ static int _text_write(struct label *label, void *buf) "%s%.*" PRIu64 "%s%.*" PRIu64 "%s" "%s%.*" PRIu64 "%s%.*" PRIu64 "%s" "%s%.*" PRIu64 "%s%.*" PRIu64 "%s", - dev_name(info->dev), buffer, info->device_size, + dev_name(lvmcache_device(info)), buffer, lvmcache_device_size(info), (da1 > -1) ? " da1 (" : "", (da1 > -1) ? 1 : 0, (da1 > -1) ? xlate64(pvhdr->disk_areas_xl[da1].offset) >> SECTOR_SHIFT : 0, @@ -138,7 +152,7 @@ static int _text_write(struct label *label, void *buf) if (da1 < 0) { log_error(INTERNAL_ERROR "%s label header currently requires " - "a data area.", dev_name(info->dev)); + "a data area.", dev_name(lvmcache_device(info))); return 0; } @@ -250,6 +264,62 @@ static int _text_initialise_label(struct labeller *l __attribute__((unused)), return 1; } +struct _update_mda_baton { + struct lvmcache_info *info; + struct label *label; +}; + +static int _update_mda(struct metadata_area *mda, void *baton) +{ + struct _update_mda_baton *p = baton; + const struct format_type *fmt = p->label->labeller->private; // Oh dear. + struct mda_context *mdac = (struct mda_context *) mda->metadata_locn; + struct mda_header *mdah; + const char *vgname; + struct id vgid; + uint64_t vgstatus; + char *creation_host; + + if (!dev_open_readonly(mdac->area.dev)) { + mda_set_ignored(mda, 1); + stack; + return 1; + } + + if (!(mdah = raw_read_mda_header(fmt, &mdac->area))) { + stack; + goto close_dev; + } + + mda_set_ignored(mda, rlocn_is_ignored(mdah->raw_locns)); + + if (mda_is_ignored(mda)) { + log_debug("Ignoring mda on device %s at offset %"PRIu64, + dev_name(mdac->area.dev), + mdac->area.start); + if (!dev_close(mdac->area.dev)) + stack; + return 1; + } + + if ((vgname = vgname_from_mda(fmt, mdah, + &mdac->area, + &vgid, &vgstatus, &creation_host, + &mdac->free_sectors)) && + !lvmcache_update_vgname_and_id(p->info, vgname, + (char *) &vgid, vgstatus, + creation_host)) { + if (!dev_close(mdac->area.dev)) + stack; + return_0; + } +close_dev: + if (!dev_close(mdac->area.dev)) + stack; + + return 1; +} + static int _text_read(struct labeller *l, struct device *dev, void *buf, struct label **label) { @@ -258,13 +328,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf, struct lvmcache_info *info; struct disk_locn *dlocn_xl; uint64_t offset; - struct metadata_area *mda; - struct id vgid; - struct mda_context *mdac; - const char *vgname; - uint64_t vgstatus; - char *creation_host; - struct mda_header *mdah; + struct _update_mda_baton baton; pvhdr = (struct pv_header *) ((char *) buf + xlate32(lh->offset_xl)); @@ -272,73 +336,34 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf, FMT_TEXT_ORPHAN_VG_NAME, FMT_TEXT_ORPHAN_VG_NAME, 0))) return_0; - *label = info->label; - info->device_size = xlate64(pvhdr->device_size_xl); + /* this one is leaked forever */ + *label = lvmcache_get_label(info); - if (info->das.n) - del_das(&info->das); - dm_list_init(&info->das); + lvmcache_set_device_size(info, xlate64(pvhdr->device_size_xl)); - if (info->mdas.n) - del_mdas(&info->mdas); - dm_list_init(&info->mdas); + lvmcache_del_das(info); + lvmcache_del_mdas(info); /* Data areas holding the PEs */ dlocn_xl = pvhdr->disk_areas_xl; while ((offset = xlate64(dlocn_xl->offset))) { - add_da(NULL, &info->das, offset, - xlate64(dlocn_xl->size)); + lvmcache_add_da(info, offset, xlate64(dlocn_xl->size)); dlocn_xl++; } /* Metadata area headers */ dlocn_xl++; while ((offset = xlate64(dlocn_xl->offset))) { - add_mda(info->fmt, NULL, &info->mdas, dev, offset, - xlate64(dlocn_xl->size), 0); + lvmcache_add_mda(info, dev, offset, xlate64(dlocn_xl->size), 0); dlocn_xl++; } - dm_list_iterate_items(mda, &info->mdas) { - mdac = (struct mda_context *) mda->metadata_locn; - if (!dev_open_readonly(mdac->area.dev)) { - mda_set_ignored(mda, 1); - stack; - continue; - } - if (!(mdah = raw_read_mda_header(info->fmt, &mdac->area))) { - stack; - goto close_dev; - } - mda_set_ignored(mda, rlocn_is_ignored(mdah->raw_locns)); - - if (mda_is_ignored(mda)) { - log_debug("Ignoring mda on device %s at offset %"PRIu64, - dev_name(mdac->area.dev), - mdac->area.start); - if (!dev_close(mdac->area.dev)) - stack; - continue; - } - - if ((vgname = vgname_from_mda(info->fmt, mdah, - &mdac->area, - &vgid, &vgstatus, &creation_host, - &mdac->free_sectors)) && - !lvmcache_update_vgname_and_id(info, vgname, - (char *) &vgid, vgstatus, - creation_host)) { - if (!dev_close(mdac->area.dev)) - stack; - return_0; - } - close_dev: - if (!dev_close(mdac->area.dev)) - stack; - } + baton.info = info; + baton.label = *label; - info->status &= ~CACHE_INVALID; + lvmcache_foreach_mda(info, _update_mda, &baton); + lvmcache_make_valid(info); return 1; } @@ -348,10 +373,8 @@ static void _text_destroy_label(struct labeller *l __attribute__((unused)), { struct lvmcache_info *info = (struct lvmcache_info *) label->info; - if (info->mdas.n) - del_mdas(&info->mdas); - if (info->das.n) - del_das(&info->das); + lvmcache_del_mdas(info); + lvmcache_del_das(info); } static void _fmt_text_destroy(struct labeller *l) |