1515
1633
dm_list_init(&_vginfos);
1517
1635
if (retain_orphans)
1518
init_lvmcache_orphans(cmd);
1636
if (!init_lvmcache_orphans(cmd))
1640
int lvmcache_pvid_is_locked(const char *pvid) {
1641
struct lvmcache_info *info;
1642
info = lvmcache_info_from_pvid(pvid, 0);
1643
if (!info || !info->vginfo)
1646
return lvmcache_vgname_is_locked(info->vginfo->vgname);
1649
int lvmcache_fid_add_mdas(struct lvmcache_info *info, struct format_instance *fid,
1650
const char *id, int id_len)
1652
return fid_add_mdas(fid, &info->mdas, id, id_len);
1655
int lvmcache_fid_add_mdas_pv(struct lvmcache_info *info, struct format_instance *fid)
1657
return lvmcache_fid_add_mdas(info, fid, info->dev->pvid, ID_LEN);
1660
int lvmcache_fid_add_mdas_vg(struct lvmcache_vginfo *vginfo, struct format_instance *fid)
1662
struct lvmcache_info *info;
1663
dm_list_iterate_items(info, &vginfo->infos) {
1664
if (!lvmcache_fid_add_mdas_pv(info, fid))
1670
static int _get_pv_if_in_vg(struct lvmcache_info *info,
1671
struct physical_volume *pv)
1673
char vgname[NAME_LEN + 1];
1674
char vgid[ID_LEN + 1];
1676
if (info->vginfo && info->vginfo->vgname &&
1677
!is_orphan_vg(info->vginfo->vgname)) {
1679
* get_pv_from_vg_by_id() may call
1680
* lvmcache_label_scan() and drop cached
1681
* vginfo so make a local copy of string.
1683
strcpy(vgname, info->vginfo->vgname);
1684
memcpy(vgid, info->vginfo->vgid, sizeof(vgid));
1686
if (get_pv_from_vg_by_id(info->fmt, vgname, vgid,
1687
info->dev->pvid, pv))
1694
int lvmcache_populate_pv_fields(struct lvmcache_info *info,
1695
struct physical_volume *pv,
1696
int scan_label_only)
1698
struct data_area_list *da;
1700
/* Have we already cached vgname? */
1701
if (!scan_label_only && _get_pv_if_in_vg(info, pv))
1704
/* Perform full scan (just the first time) and try again */
1705
if (!scan_label_only && !critical_section() && !full_scan_done()) {
1706
lvmcache_label_scan(info->fmt->cmd, 2);
1708
if (_get_pv_if_in_vg(info, pv))
1713
pv->dev = info->dev;
1714
pv->fmt = info->fmt;
1715
pv->size = info->device_size >> SECTOR_SHIFT;
1716
pv->vg_name = FMT_TEXT_ORPHAN_VG_NAME;
1717
memcpy(&pv->id, &info->dev->pvid, sizeof(pv->id));
1719
/* Currently only support exactly one data area */
1720
if (dm_list_size(&info->das) != 1) {
1721
log_error("Must be exactly one data area (found %d) on PV %s",
1722
dm_list_size(&info->das), dev_name(info->dev));
1726
dm_list_iterate_items(da, &info->das)
1727
pv->pe_start = da->disk_locn.offset >> SECTOR_SHIFT;
1732
int lvmcache_check_format(struct lvmcache_info *info, const struct format_type *fmt)
1734
if (info->fmt != fmt) {
1735
log_error("PV %s is a different format (seqno %s)",
1736
dev_name(info->dev), info->fmt->name);
1742
void lvmcache_del_mdas(struct lvmcache_info *info)
1745
del_mdas(&info->mdas);
1746
dm_list_init(&info->mdas);
1749
void lvmcache_del_das(struct lvmcache_info *info)
1752
del_das(&info->das);
1753
dm_list_init(&info->das);
1756
int lvmcache_add_mda(struct lvmcache_info *info, struct device *dev,
1757
uint64_t start, uint64_t size, unsigned ignored)
1759
return add_mda(info->fmt, NULL, &info->mdas, dev, start, size, ignored);
1762
int lvmcache_add_da(struct lvmcache_info *info, uint64_t start, uint64_t size)
1764
return add_da(NULL, &info->das, start, size);
1768
void lvmcache_update_pv(struct lvmcache_info *info, struct physical_volume *pv,
1769
const struct format_type *fmt)
1771
info->device_size = pv->size << SECTOR_SHIFT;
1775
int lvmcache_update_das(struct lvmcache_info *info, struct physical_volume *pv)
1777
struct data_area_list *da;
1780
dm_list_iterate_items(da, &info->das)
1781
pv->pe_start = da->disk_locn.offset >> SECTOR_SHIFT;
1782
del_das(&info->das);
1784
dm_list_init(&info->das);
1786
if (!add_da(NULL, &info->das, pv->pe_start << SECTOR_SHIFT, 0 /*pv->size << SECTOR_SHIFT*/))
1792
int lvmcache_foreach_pv(struct lvmcache_vginfo *vginfo,
1793
int (*fun)(struct lvmcache_info *, void *),
1796
struct lvmcache_info *info;
1797
dm_list_iterate_items(info, &vginfo->infos) {
1798
if (!fun(info, baton))
1805
int lvmcache_foreach_mda(struct lvmcache_info *info,
1806
int (*fun)(struct metadata_area *, void *),
1809
struct metadata_area *mda;
1810
dm_list_iterate_items(mda, &info->mdas) {
1811
if (!fun(mda, baton))
1818
int lvmcache_mda_count(struct lvmcache_info *info)
1820
return dm_list_size(&info->mdas);
1823
int lvmcache_foreach_da(struct lvmcache_info *info,
1824
int (*fun)(struct disk_locn *, void *),
1827
struct data_area_list *da;
1828
dm_list_iterate_items(da, &info->das) {
1829
if (!fun(&da->disk_locn, baton))
1837
* The lifetime of the label returned is tied to the lifetime of the
1838
* lvmcache_info which is the same as lvmcache itself.
1840
struct label *lvmcache_get_label(struct lvmcache_info *info) {
1844
void lvmcache_make_valid(struct lvmcache_info *info) {
1845
info->status &= ~CACHE_INVALID;
1848
uint64_t lvmcache_device_size(struct lvmcache_info *info) {
1849
return info->device_size;
1852
void lvmcache_set_device_size(struct lvmcache_info *info, uint64_t size) {
1853
info->device_size = size;
1856
struct device *lvmcache_device(struct lvmcache_info *info) {
1860
int lvmcache_is_orphan(struct lvmcache_info *info) {
1862
return 1; /* FIXME? */
1863
return is_orphan_vg(info->vginfo->vgname);
1866
int lvmcache_vgid_is_cached(const char *vgid) {
1867
struct lvmcache_vginfo *vginfo;
1869
if (lvmetad_active())
1872
vginfo = lvmcache_vginfo_from_vgid(vgid);
1874
if (!vginfo || !vginfo->vgname)
1877
if (is_orphan_vg(vginfo->vgname))
1884
* Return true iff it is impossible to find out from this info alone whether the
1885
* PV in question is or is not an orphan.
1887
int lvmcache_uncertain_ownership(struct lvmcache_info *info) {
1888
return mdas_empty_or_ignored(&info->mdas);
1891
int lvmcache_smallest_mda_size(struct lvmcache_info *info)
1893
return find_min_mda_size(&info->mdas);
1896
const struct format_type *lvmcache_fmt(struct lvmcache_info *info) {