diff options
author | Alasdair Kergon <agk@redhat.com> | 2011-06-01 19:29:31 +0000 |
---|---|---|
committer | Alasdair Kergon <agk@redhat.com> | 2011-06-01 19:29:31 +0000 |
commit | 3cac20f850d76f373e9bcf672bf8c3f5d9283c78 (patch) | |
tree | 8d8e7120eb1c6b2ee8ab445c287348eb841af4a9 /lib/cache/lvmcache.c | |
parent | 2aa785c85f65cd468d2d66bee9c22354c2eefd7d (diff) | |
download | lvm2-3cac20f850d76f373e9bcf672bf8c3f5d9283c78.tar.gz lvm2-3cac20f850d76f373e9bcf672bf8c3f5d9283c78.tar.xz lvm2-3cac20f850d76f373e9bcf672bf8c3f5d9283c78.zip |
Defer writing PV labels to vg_write.
Store label_sector only in struct physical_volume.
Diffstat (limited to 'lib/cache/lvmcache.c')
-rw-r--r-- | lib/cache/lvmcache.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 80eb510e..b448acab 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -539,7 +539,7 @@ char *lvmcache_vgname_from_pvid(struct cmd_context *cmd, const char *pvid) struct lvmcache_info *info; char *vgname; - if (!device_from_pvid(cmd, (const struct id *)pvid, NULL)) { + if (!device_from_pvid(cmd, (const struct id *)pvid, NULL, NULL)) { log_error("Couldn't find device with uuid %s.", pvid); return NULL; } @@ -769,31 +769,41 @@ struct dm_list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname, return pvids; } -struct device *device_from_pvid(struct cmd_context *cmd, const struct id *pvid, - unsigned *scan_done_once) +static struct device *_device_from_pvid(const struct id *pvid, + uint64_t *label_sector) { - struct label *label; struct lvmcache_info *info; + struct label *label; - /* Already cached ? */ if ((info = info_from_pvid((const char *) pvid, 0))) { if (label_read(info->dev, &label, UINT64_C(0))) { info = (struct lvmcache_info *) label->info; - if (id_equal(pvid, (struct id *) &info->dev->pvid)) + if (id_equal(pvid, (struct id *) &info->dev->pvid)) { + if (label_sector) + *label_sector = label->sector; return info->dev; + } } } + return NULL; +} + +struct device *device_from_pvid(struct cmd_context *cmd, const struct id *pvid, + unsigned *scan_done_once, uint64_t *label_sector) +{ + struct device *dev; + + /* Already cached ? */ + dev = _device_from_pvid(pvid, label_sector); + if (dev) + return dev; lvmcache_label_scan(cmd, 0); /* Try again */ - if ((info = info_from_pvid((const char *) pvid, 0))) { - if (label_read(info->dev, &label, UINT64_C(0))) { - info = (struct lvmcache_info *) label->info; - if (id_equal(pvid, (struct id *) &info->dev->pvid)) - return info->dev; - } - } + dev = _device_from_pvid(pvid, label_sector); + if (dev) + return dev; if (critical_section() || (scan_done_once && *scan_done_once)) return NULL; @@ -803,13 +813,9 @@ struct device *device_from_pvid(struct cmd_context *cmd, const struct id *pvid, *scan_done_once = 1; /* Try again */ - if ((info = info_from_pvid((const char *) pvid, 0))) { - if (label_read(info->dev, &label, UINT64_C(0))) { - info = (struct lvmcache_info *) label->info; - if (id_equal(pvid, (struct id *) &info->dev->pvid)) - return info->dev; - } - } + dev = _device_from_pvid(pvid, label_sector); + if (dev) + return dev; return NULL; } |