diff --git a/WHATS_NEW b/WHATS_NEW index 1f8e6bd2a..e118c6731 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.01.02 - =================================== + Always fail if random id generation fails. Recognise gnbd devices. Version 2.01.01 - 19th January 2005 diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index de9e374ac..520ac53f9 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -88,8 +88,11 @@ static int _lv_setup(struct format_instance *fid, struct logical_volume *lv) } */ - if (!*lv->lvid.s) - lvid_create(&lv->lvid, &lv->vg->id); + if (!*lv->lvid.s && !lvid_create(&lv->lvid, &lv->vg->id)) { + log_error("Random lvid creation failed for %s/%s.", + lv->vg->name, lv->name); + return 0; + } return 1; } diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index e5daf1d5a..213628d5d 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -267,10 +267,13 @@ struct physical_volume *pv_create(const struct format_type *fmt, return NULL; } - if (!id) - id_create(&pv->id); - else + if (id) memcpy(&pv->id, id, sizeof(*id)); + else if (!id_create(&pv->id)) { + log_error("Failed to create random uuid for %s.", + dev_name(dev)); + return NULL; + } pv->dev = dev; diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c index 664c73b28..c1ec39ab3 100644 --- a/lib/metadata/snapshot_manip.c +++ b/lib/metadata/snapshot_manip.c @@ -134,7 +134,8 @@ int vg_add_snapshot(struct logical_volume *origin, struct logical_volume *cow, if (id) s->id = *id; else if (!id_create(&s->id)) { - log_error("Snapshot UUID creation failed"); + log_error("Random UUID creation failed for snapshot %s.", + cow->name); return 0; } diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c index f86ba9f83..61e789308 100644 --- a/lib/uuid/uuid.c +++ b/lib/uuid/uuid.c @@ -29,9 +29,7 @@ static unsigned char _inverse_c[256]; int lvid_create(union lvid *lvid, struct id *vgid) { memcpy(lvid->id, vgid, sizeof(*lvid->id)); - id_create(&lvid->id[1]); - - return 1; + return id_create(&lvid->id[1]); } void uuid_from_num(char *uuid, uint32_t num) @@ -83,16 +81,18 @@ int id_create(struct id *id) memset(id->uuid, 0, len); if ((randomfile = open("/dev/urandom", O_RDONLY)) < 0) { - log_sys_error("open", "id_create"); + log_sys_error("open", "id_create: /dev/urandom"); return 0; } if (read(randomfile, id->uuid, len) != len) { - log_sys_error("read", "id_create"); - close(randomfile); + log_sys_error("read", "id_create: /dev/urandom"); + if (close(randomfile)) + stack; return 0; } - close(randomfile); + if (close(randomfile)) + stack; /* * Skip out the last 2 chars in randomized creation for LVM1 diff --git a/tools/pvchange.c b/tools/pvchange.c index c54b35608..5a8cf6c8a 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -173,7 +173,11 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv, } } else { /* --uuid: Change PV ID randomly */ - id_create(&pv->id); + if (!id_create(&pv->id)) { + log_error("Failed to generate new random UUID for %s.", + pv_name); + return 0; + } } log_verbose("Updating physical volume \"%s\"", pv_name); diff --git a/tools/vgchange.c b/tools/vgchange.c index a9fc36272..17cdcb842 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -264,7 +264,11 @@ static int _vgchange_uuid(struct cmd_context *cmd, struct volume_group *vg) if (!archive(vg)) return ECMD_FAILED; - id_create(&vg->id); + if (!id_create(&vg->id)) { + log_error("Failed to generate new random UUID for VG %s.", + vg->name); + return ECMD_FAILED; + } list_iterate_items(lvl, &vg->lvs) { memcpy(&lvl->lv->lvid, &vg->id, sizeof(vg->id));