1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

label: Move _set_label_read_result call into _find_labeller.

Move responsibility for setting the label_read() result parameter down
into _find_labeller().
This commit is contained in:
Alasdair G Kergon 2018-01-02 14:58:21 +00:00
parent 4f4ddb806d
commit 9b830791ea

View File

@ -119,25 +119,32 @@ static void _update_lvmcache_orphan(struct lvmcache_info *info)
stack; stack;
} }
static void _set_label_read_result(struct device *dev, uint64_t sector, struct label **result) static void _set_label_read_result(int failed, struct device *dev, uint64_t sector, struct label **result)
{ {
if (failed)
goto_out;
if (result && *result) { if (result && *result) {
(*result)->dev = dev; (*result)->dev = dev;
(*result)->sector = sector; (*result)->sector = sector;
} }
out:
if (!dev_close(dev))
stack;
} }
static struct labeller *_find_labeller(struct device *dev, char *labelbuf, static int _find_labeller(struct device *dev, uint64_t scan_sector, struct label **result)
uint64_t *label_sector,
uint64_t scan_sector)
{ {
char labelbuf[LABEL_SIZE] __attribute__((aligned(8)));
uint64_t label_sector;
struct labeller_i *li; struct labeller_i *li;
struct labeller *r = NULL; struct labeller *l = NULL; /* Set when a labeller claims the label */
struct label_header *lh; struct label_header *lh;
struct lvmcache_info *info; struct lvmcache_info *info;
uint64_t sector; uint64_t sector;
int found = 0;
char *buf = NULL; char *buf = NULL;
int r = 0;
if (!(buf = dev_read(dev, scan_sector << SECTOR_SHIFT, LABEL_SCAN_SIZE, DEV_IO_LABEL))) { if (!(buf = dev_read(dev, scan_sector << SECTOR_SHIFT, LABEL_SCAN_SIZE, DEV_IO_LABEL))) {
log_debug_devs("%s: Failed to read label area", dev_name(dev)); log_debug_devs("%s: Failed to read label area", dev_name(dev));
@ -150,7 +157,7 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
lh = (struct label_header *) (buf + (sector << SECTOR_SHIFT)); lh = (struct label_header *) (buf + (sector << SECTOR_SHIFT));
if (!strncmp((char *)lh->id, LABEL_ID, sizeof(lh->id))) { if (!strncmp((char *)lh->id, LABEL_ID, sizeof(lh->id))) {
if (found) { if (l) {
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 + scan_sector); sector + scan_sector);
@ -170,7 +177,7 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
"ignoring", dev_name(dev)); "ignoring", dev_name(dev));
continue; continue;
} }
if (found) if (l)
continue; continue;
} }
@ -181,18 +188,16 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
"sector %" PRIu64, "sector %" PRIu64,
dev_name(dev), li->name, dev_name(dev), li->name,
sector + scan_sector); sector + scan_sector);
if (found) { if (l) {
log_error("Ignoring additional label " log_error("Ignoring additional label "
"on %s at sector %" PRIu64, "on %s at sector %" PRIu64,
dev_name(dev), dev_name(dev),
sector + scan_sector); sector + scan_sector);
continue; continue;
} }
r = li->l;
memcpy(labelbuf, lh, LABEL_SIZE); memcpy(labelbuf, lh, LABEL_SIZE);
if (label_sector) label_sector = sector + scan_sector;
*label_sector = sector + scan_sector; l = li->l;
found = 1;
break; break;
} }
} }
@ -201,11 +206,14 @@ static struct labeller *_find_labeller(struct device *dev, char *labelbuf,
out: out:
dm_free(buf); dm_free(buf);
if (!found) { if (!l) {
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0))) if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0)))
_update_lvmcache_orphan(info); _update_lvmcache_orphan(info);
log_very_verbose("%s: No label detected", dev_name(dev)); log_very_verbose("%s: No label detected", dev_name(dev));
} } else
r = (l->ops->read)(l, dev, labelbuf, result);
_set_label_read_result(!r, dev, label_sector, result);
return r; return r;
} }
@ -285,13 +293,9 @@ int label_remove(struct device *dev)
return r; return r;
} }
static int _label_read(struct device *dev, struct label **result, uint64_t scan_sector) static int _label_read(struct device *dev, uint64_t scan_sector, struct label **result)
{ {
char buf[LABEL_SIZE] __attribute__((aligned(8)));
struct labeller *l;
uint64_t sector;
struct lvmcache_info *info; struct lvmcache_info *info;
int r = 0;
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 1))) { if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 1))) {
log_debug_devs("Reading label from lvmcache for %s", dev_name(dev)); log_debug_devs("Reading label from lvmcache for %s", dev_name(dev));
@ -307,22 +311,15 @@ static int _label_read(struct device *dev, struct label **result, uint64_t scan_
if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0))) if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0)))
_update_lvmcache_orphan(info); _update_lvmcache_orphan(info);
return r; return 0;
} }
if ((l = _find_labeller(dev, buf, &sector, scan_sector))) return _find_labeller(dev, scan_sector, result);
if ((r = (l->ops->read)(l, dev, buf, result)))
_set_label_read_result(dev, sector, result);
if (!dev_close(dev))
stack;
return r;
} }
int label_read(struct device *dev, struct label **result, uint64_t scan_sector) int label_read(struct device *dev, struct label **result, uint64_t scan_sector)
{ {
return _label_read(dev, result, scan_sector); return _label_read(dev, scan_sector, result);
} }
/* Caller may need to use label_get_handler to create label struct! */ /* Caller may need to use label_get_handler to create label struct! */