From cc8f6e3dbc86dd0e5a532669092941e84c31b841 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 9 Jan 2004 19:18:20 +0000 Subject: [PATCH] If PV/VG uuids are missing, generate them from the pv/vg numbers. [This situation could occur if the uuids were oritinally created by LVM1 on a system without /dev/urandom.] --- lib/format1/disk-rep.c | 8 ++++++++ lib/uuid/uuid.c | 12 ++++++++++++ lib/uuid/uuid.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index 2c15aadba..a72fb9636 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -150,6 +150,10 @@ static int _read_pvd(struct device *dev, struct pv_disk *pvd) return 0; } + /* If UUID is missing, create one */ + if (pvd->pv_uuid[0] == '\0') + uuid_from_num(pvd->pv_uuid, pvd->pv_number); + return 1; } @@ -172,6 +176,10 @@ static int _read_vgd(struct disk_list *data) _xlate_vgd(vgd); + /* If UUID is missing, create one */ + if (vgd->vg_uuid[0] == '\0') + uuid_from_num(vgd->vg_uuid, vgd->vg_number); + return 1; } diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c index 8083b7abe..8e4a1533e 100644 --- a/lib/uuid/uuid.c +++ b/lib/uuid/uuid.c @@ -25,6 +25,18 @@ int lvid_create(union lvid *lvid, struct id *vgid) return 1; } +void uuid_from_num(char *uuid, uint32_t num) +{ + unsigned i; + + for (i = ID_LEN; i; i--) { + uuid[i - 1] = _c[num % (sizeof(_c) - 1)]; + num /= sizeof(_c) - 1; + } + + uuid[ID_LEN] = '\0'; +} + int lvid_from_lvnum(union lvid *lvid, struct id *vgid, uint32_t lv_num) { int i; diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h index aa25773d7..ee7e36542 100644 --- a/lib/uuid/uuid.h +++ b/lib/uuid/uuid.h @@ -26,6 +26,8 @@ union lvid { int lvid_from_lvnum(union lvid *lvid, struct id *vgid, uint32_t lv_num); int lvnum_from_lvid(union lvid *lvid); +void uuid_from_num(char *uuid, uint32_t num); + int lvid_create(union lvid *lvid, struct id *vgid); int id_create(struct id *id); int id_valid(struct id *id); -- 2.43.5