From 29ebccc3e26b472a0873951736f4057487b143c2 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 26 Aug 2003 21:12:06 +0000 Subject: [PATCH] Cope better when format functions are missing. --- lib/label/label.c | 11 +++++++++-- lib/metadata/metadata.c | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/label/label.c b/lib/label/label.c index dc549dafd..0c78ed0dd 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -280,6 +280,11 @@ int label_write(struct device *dev, struct label *label) struct label_header *lh = (struct label_header *) buf; int r = 1; + if (!label->labeller->ops->write) { + log_err("Label handler does not support label writes"); + return 0; + } + if ((LABEL_SIZE + (label->sector << SECTOR_SHIFT)) > LABEL_SCAN_SIZE) { log_error("Label sector %" PRIu64 " beyond range (%ld)", label->sector, LABEL_SCAN_SECTORS); @@ -292,8 +297,10 @@ int label_write(struct device *dev, struct label *label) lh->sector_xl = xlate64(label->sector); lh->offset_xl = xlate32(sizeof(*lh)); - if (!label->labeller->ops->write(label, buf)) + if (!label->labeller->ops->write(label, buf)) { + stack; return 0; + } lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE - ((void *) &lh->offset_xl - (void *) lh))); @@ -327,7 +334,7 @@ int label_verify(struct device *dev) return 0; } - return l->ops->verify(l, buf, sector); + return ((l->ops->verify) ? l->ops->verify(l, buf, sector) : 1); } void label_destroy(struct label *label) diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 3f2bc054e..6acf843ae 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -217,7 +217,8 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name, goto bad; } - if (!vg->fid->fmt->ops->vg_setup(vg->fid, vg)) { + if (vg->fid->fmt->ops->vg_setup && + !vg->fid->fmt->ops->vg_setup(vg->fid, vg)) { log_error("Format specific setup of volume group '%s' failed.", vg_name); goto bad; @@ -463,6 +464,19 @@ int vg_write(struct volume_group *vg) /* Write to each copy of the metadata area */ list_iterate(mdah, &vg->fid->metadata_areas) { mda = list_item(mdah, struct metadata_area); + if(!mda->ops->vg_write) { + log_error("Format does not support writing volume" + "group metadata areas"); + /* Revert */ + list_uniterate(mdah2, &vg->fid->metadata_areas, mdah) { + mda = list_item(mdah2, struct metadata_area); + if (mda->ops->vg_revert && + !mda->ops->vg_revert(vg->fid, vg, mda)) { + stack; + } + } + return 0; + } if (!mda->ops->vg_write(vg->fid, vg, mda)) { stack; /* Revert */ @@ -869,6 +883,11 @@ struct list *get_pvs(struct cmd_context *cmd) int pv_write(struct cmd_context *cmd, struct physical_volume *pv, struct list *mdas, int64_t label_sector) { + if (!pv->fmt->ops->pv_write) { + log_error("Format does not support writing physical volumes"); + return 0; + } + if (*pv->vg_name || pv->pe_alloc_count) { log_error("Assertion failed: can't _pv_write non-orphan PV " "(in VG %s)", pv->vg_name);