mirror of
git://sourceware.org/git/lvm2.git
synced 2025-10-11 03:33:14 +03:00
Add 'scan_sector' parameter to label_read and _find_labeller to add
flexibility in searching for disk labels.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
Version 2.02.25 -
|
Version 2.02.25 -
|
||||||
=================================
|
=================================
|
||||||
|
Add scan_sector param to label_read and _find_labeller.
|
||||||
Make clvmd cope with quorum devices on RHEL5
|
Make clvmd cope with quorum devices on RHEL5
|
||||||
Add dev_read_circular.
|
Add dev_read_circular.
|
||||||
Add pvck command stub.
|
Add pvck command stub.
|
||||||
|
12
lib/cache/lvmcache.c
vendored
12
lib/cache/lvmcache.c
vendored
@@ -135,7 +135,7 @@ const struct format_type *fmt_from_vgname(const char *vgname, const char *vgid)
|
|||||||
|
|
||||||
list_iterate_safe(devh, tmp, &devs) {
|
list_iterate_safe(devh, tmp, &devs) {
|
||||||
devl = list_item(devh, struct device_list);
|
devl = list_item(devh, struct device_list);
|
||||||
label_read(devl->dev, &label);
|
label_read(devl->dev, &label, UINT64_C(0));
|
||||||
list_del(&devl->list);
|
list_del(&devl->list);
|
||||||
dm_free(devl);
|
dm_free(devl);
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ static void _rescan_entry(struct lvmcache_info *info)
|
|||||||
struct label *label;
|
struct label *label;
|
||||||
|
|
||||||
if (info->status & CACHE_INVALID)
|
if (info->status & CACHE_INVALID)
|
||||||
label_read(info->dev, &label);
|
label_read(info->dev, &label, UINT64_C(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _scan_invalid(void)
|
static int _scan_invalid(void)
|
||||||
@@ -247,7 +247,7 @@ int lvmcache_label_scan(struct cmd_context *cmd, int full_scan)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((dev = dev_iter_get(iter)))
|
while ((dev = dev_iter_get(iter)))
|
||||||
label_read(dev, &label);
|
label_read(dev, &label, UINT64_C(0));
|
||||||
|
|
||||||
dev_iter_destroy(iter);
|
dev_iter_destroy(iter);
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid)
|
|||||||
|
|
||||||
/* Already cached ? */
|
/* Already cached ? */
|
||||||
if ((info = info_from_pvid((char *) pvid))) {
|
if ((info = info_from_pvid((char *) pvid))) {
|
||||||
if (label_read(info->dev, &label)) {
|
if (label_read(info->dev, &label, UINT64_C(0))) {
|
||||||
info = (struct lvmcache_info *) label->info;
|
info = (struct lvmcache_info *) label->info;
|
||||||
if (id_equal(pvid, (struct id *) &info->dev->pvid))
|
if (id_equal(pvid, (struct id *) &info->dev->pvid))
|
||||||
return info->dev;
|
return info->dev;
|
||||||
@@ -357,7 +357,7 @@ struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid)
|
|||||||
|
|
||||||
/* Try again */
|
/* Try again */
|
||||||
if ((info = info_from_pvid((char *) pvid))) {
|
if ((info = info_from_pvid((char *) pvid))) {
|
||||||
if (label_read(info->dev, &label)) {
|
if (label_read(info->dev, &label, UINT64_C(0))) {
|
||||||
info = (struct lvmcache_info *) label->info;
|
info = (struct lvmcache_info *) label->info;
|
||||||
if (id_equal(pvid, (struct id *) &info->dev->pvid))
|
if (id_equal(pvid, (struct id *) &info->dev->pvid))
|
||||||
return info->dev;
|
return info->dev;
|
||||||
@@ -371,7 +371,7 @@ struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid)
|
|||||||
|
|
||||||
/* Try again */
|
/* Try again */
|
||||||
if ((info = info_from_pvid((char *) pvid))) {
|
if ((info = info_from_pvid((char *) pvid))) {
|
||||||
if (label_read(info->dev, &label)) {
|
if (label_read(info->dev, &label, UINT64_C(0))) {
|
||||||
info = (struct lvmcache_info *) label->info;
|
info = (struct lvmcache_info *) label->info;
|
||||||
if (id_equal(pvid, (struct id *) &info->dev->pvid))
|
if (id_equal(pvid, (struct id *) &info->dev->pvid))
|
||||||
return info->dev;
|
return info->dev;
|
||||||
|
@@ -1287,7 +1287,7 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME Optimise out repeated reading when cache lock held */
|
/* FIXME Optimise out repeated reading when cache lock held */
|
||||||
if (!(label_read(dev, &label))) {
|
if (!(label_read(dev, &label, UINT64_C(0)))) {
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -107,7 +107,8 @@ struct labeller *label_get_handler(const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct labeller *_find_labeller(struct device *dev, char *buf,
|
static struct labeller *_find_labeller(struct device *dev, char *buf,
|
||||||
uint64_t *label_sector)
|
uint64_t *label_sector,
|
||||||
|
uint64_t scan_sector)
|
||||||
{
|
{
|
||||||
struct labeller_i *li;
|
struct labeller_i *li;
|
||||||
struct labeller *r = NULL;
|
struct labeller *r = NULL;
|
||||||
@@ -117,12 +118,13 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
|
|||||||
int found = 0;
|
int found = 0;
|
||||||
char readbuf[LABEL_SCAN_SIZE] __attribute((aligned(8)));
|
char readbuf[LABEL_SCAN_SIZE] __attribute((aligned(8)));
|
||||||
|
|
||||||
if (!dev_read(dev, UINT64_C(0), LABEL_SCAN_SIZE, readbuf)) {
|
if (!dev_read(dev, scan_sector << SECTOR_SHIFT,
|
||||||
|
LABEL_SCAN_SIZE, readbuf)) {
|
||||||
log_debug("%s: Failed to read label area", dev_name(dev));
|
log_debug("%s: Failed to read label area", dev_name(dev));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scan first few sectors for a valid label */
|
/* Scan a few sectors for a valid label */
|
||||||
for (sector = 0; sector < LABEL_SCAN_SECTORS;
|
for (sector = 0; sector < LABEL_SCAN_SECTORS;
|
||||||
sector += LABEL_SIZE >> SECTOR_SHIFT) {
|
sector += LABEL_SIZE >> SECTOR_SHIFT) {
|
||||||
lh = (struct label_header *) (readbuf +
|
lh = (struct label_header *) (readbuf +
|
||||||
@@ -132,13 +134,14 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
|
|||||||
if (found) {
|
if (found) {
|
||||||
log_error("Ignoring additional label on %s at "
|
log_error("Ignoring additional label on %s at "
|
||||||
"sector %" PRIu64, dev_name(dev),
|
"sector %" PRIu64, dev_name(dev),
|
||||||
sector);
|
sector + scan_sector);
|
||||||
}
|
}
|
||||||
if (xlate64(lh->sector_xl) != sector) {
|
if (xlate64(lh->sector_xl) != sector + scan_sector) {
|
||||||
log_info("%s: Label for sector %" PRIu64
|
log_info("%s: Label for sector %" PRIu64
|
||||||
" found at sector %" PRIu64
|
" found at sector %" PRIu64
|
||||||
" - ignoring", dev_name(dev),
|
" - ignoring", dev_name(dev),
|
||||||
xlate64(lh->sector_xl), sector);
|
xlate64(lh->sector_xl),
|
||||||
|
sector + scan_sector);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE -
|
if (calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE -
|
||||||
@@ -153,19 +156,21 @@ static struct labeller *_find_labeller(struct device *dev, char *buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
list_iterate_items(li, &_labellers) {
|
list_iterate_items(li, &_labellers) {
|
||||||
if (li->l->ops->can_handle(li->l, (char *) lh, sector)) {
|
if (li->l->ops->can_handle(li->l, (char *) lh,
|
||||||
|
sector + scan_sector)) {
|
||||||
log_very_verbose("%s: %s label detected",
|
log_very_verbose("%s: %s label detected",
|
||||||
dev_name(dev), li->name);
|
dev_name(dev), li->name);
|
||||||
if (found) {
|
if (found) {
|
||||||
log_error("Ignoring additional label "
|
log_error("Ignoring additional label "
|
||||||
"on %s at sector %" PRIu64,
|
"on %s at sector %" PRIu64,
|
||||||
dev_name(dev), sector);
|
dev_name(dev),
|
||||||
|
sector + scan_sector);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
r = li->l;
|
r = li->l;
|
||||||
memcpy(buf, lh, LABEL_SIZE);
|
memcpy(buf, lh, LABEL_SIZE);
|
||||||
if (label_sector)
|
if (label_sector)
|
||||||
*label_sector = sector;
|
*label_sector = sector + scan_sector;
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -256,7 +261,8 @@ int label_remove(struct device *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME Avoid repeated re-reading if cache lock held */
|
/* FIXME Avoid repeated re-reading if cache lock held */
|
||||||
int label_read(struct device *dev, struct label **result)
|
int label_read(struct device *dev, struct label **result,
|
||||||
|
uint64_t scan_sector)
|
||||||
{
|
{
|
||||||
char buf[LABEL_SIZE] __attribute((aligned(8)));
|
char buf[LABEL_SIZE] __attribute((aligned(8)));
|
||||||
struct labeller *l;
|
struct labeller *l;
|
||||||
@@ -274,7 +280,7 @@ int label_read(struct device *dev, struct label **result)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(l = _find_labeller(dev, buf, §or)))
|
if (!(l = _find_labeller(dev, buf, §or, scan_sector)))
|
||||||
goto_out;
|
goto_out;
|
||||||
|
|
||||||
if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result)
|
if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result)
|
||||||
@@ -354,7 +360,7 @@ int label_verify(struct device *dev)
|
|||||||
return_0;
|
return_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(l = _find_labeller(dev, buf, §or)))
|
if (!(l = _find_labeller(dev, buf, §or, UINT64_C(0))))
|
||||||
goto_out;
|
goto_out;
|
||||||
|
|
||||||
r = l->ops->verify ? l->ops->verify(l, buf, sector) : 1;
|
r = l->ops->verify ? l->ops->verify(l, buf, sector) : 1;
|
||||||
|
@@ -96,7 +96,8 @@ int label_register_handler(const char *name, struct labeller *handler);
|
|||||||
struct labeller *label_get_handler(const char *name);
|
struct labeller *label_get_handler(const char *name);
|
||||||
|
|
||||||
int label_remove(struct device *dev);
|
int label_remove(struct device *dev);
|
||||||
int label_read(struct device *dev, struct label **result);
|
int label_read(struct device *dev, struct label **result,
|
||||||
|
uint64_t scan_sector);
|
||||||
int label_write(struct device *dev, struct label *label);
|
int label_write(struct device *dev, struct label *label);
|
||||||
int label_verify(struct device *dev);
|
int label_verify(struct device *dev);
|
||||||
struct label *label_create(struct labeller *labeller);
|
struct label *label_create(struct labeller *labeller);
|
||||||
|
@@ -1403,7 +1403,7 @@ struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(label_read(dev, &label))) {
|
if (!(label_read(dev, &label, UINT64_C(0)))) {
|
||||||
if (warnings)
|
if (warnings)
|
||||||
log_error("No physical volume label read from %s",
|
log_error("No physical volume label read from %s",
|
||||||
pv_name);
|
pv_name);
|
||||||
|
@@ -112,7 +112,7 @@ int lvmdiskscan(struct cmd_context *cmd, int argc __attribute((unused)),
|
|||||||
/* Do scan */
|
/* Do scan */
|
||||||
for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
|
for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
|
||||||
/* Try if it is a PV first */
|
/* Try if it is a PV first */
|
||||||
if ((label_read(dev, &label))) {
|
if ((label_read(dev, &label, UINT64_C(0)))) {
|
||||||
if (!dev_get_size(dev, &size)) {
|
if (!dev_get_size(dev, &size)) {
|
||||||
log_error("Couldn't get size of \"%s\"",
|
log_error("Couldn't get size of \"%s\"",
|
||||||
dev_name(dev));
|
dev_name(dev));
|
||||||
|
Reference in New Issue
Block a user