Simplify the code a bit. For own providers GEOM_PART always provides
"start" and "end" config attributes. MFC after: 1 week
This commit is contained in:
parent
4f6760821e
commit
cb86ada75d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=221952
@ -253,13 +253,7 @@ find_provider(struct ggeom *gp, off_t minsector)
|
|||||||
bestsector = 0;
|
bestsector = 0;
|
||||||
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
||||||
s = find_provcfg(pp, "start");
|
s = find_provcfg(pp, "start");
|
||||||
if (s == NULL) {
|
sector = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "offset");
|
|
||||||
sector =
|
|
||||||
(off_t)strtoimax(s, NULL, 0) / pp->lg_sectorsize;
|
|
||||||
} else
|
|
||||||
sector = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
|
|
||||||
if (sector < minsector)
|
if (sector < minsector)
|
||||||
continue;
|
continue;
|
||||||
if (bestpp != NULL && sector >= bestsector)
|
if (bestpp != NULL && sector >= bestsector)
|
||||||
@ -379,18 +373,9 @@ gpart_autofill_resize(struct gctl_req *req)
|
|||||||
errx(EXIT_FAILURE, "invalid partition index");
|
errx(EXIT_FAILURE, "invalid partition index");
|
||||||
|
|
||||||
s = find_provcfg(pp, "start");
|
s = find_provcfg(pp, "start");
|
||||||
if (s == NULL) {
|
start = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "offset");
|
|
||||||
start = (off_t)strtoimax(s, NULL, 0) / pp->lg_sectorsize;
|
|
||||||
} else
|
|
||||||
start = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
s = find_provcfg(pp, "end");
|
s = find_provcfg(pp, "end");
|
||||||
if (s == NULL) {
|
lba = (off_t)strtoimax(s, NULL, 0) + 1;
|
||||||
s = find_provcfg(pp, "length");
|
|
||||||
lba = start +
|
|
||||||
(off_t)strtoimax(s, NULL, 0) / pp->lg_sectorsize;
|
|
||||||
} else
|
|
||||||
lba = (off_t)strtoimax(s, NULL, 0) + 1;
|
|
||||||
|
|
||||||
if (lba > last) {
|
if (lba > last) {
|
||||||
geom_deletetree(&mesh);
|
geom_deletetree(&mesh);
|
||||||
@ -402,12 +387,7 @@ gpart_autofill_resize(struct gctl_req *req)
|
|||||||
new_size = ALIGNDOWN(last - start + 1, alignment);
|
new_size = ALIGNDOWN(last - start + 1, alignment);
|
||||||
else {
|
else {
|
||||||
s = find_provcfg(pp, "start");
|
s = find_provcfg(pp, "start");
|
||||||
if (s == NULL) {
|
new_lba = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "offset");
|
|
||||||
new_lba =
|
|
||||||
(off_t)strtoimax(s, NULL, 0) / pp->lg_sectorsize;
|
|
||||||
} else
|
|
||||||
new_lba = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
/*
|
/*
|
||||||
* Is there any free space between current and
|
* Is there any free space between current and
|
||||||
* next providers?
|
* next providers?
|
||||||
@ -512,12 +492,7 @@ gpart_autofill(struct gctl_req *req)
|
|||||||
last = ALIGNDOWN(last, alignment);
|
last = ALIGNDOWN(last, alignment);
|
||||||
while ((pp = find_provider(gp, first)) != NULL) {
|
while ((pp = find_provider(gp, first)) != NULL) {
|
||||||
s = find_provcfg(pp, "start");
|
s = find_provcfg(pp, "start");
|
||||||
if (s == NULL) {
|
lba = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "offset");
|
|
||||||
lba = (off_t)strtoimax(s, NULL, 0) / pp->lg_sectorsize;
|
|
||||||
} else
|
|
||||||
lba = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
|
|
||||||
a_lba = ALIGNDOWN(lba, alignment);
|
a_lba = ALIGNDOWN(lba, alignment);
|
||||||
if (first < a_lba && a_first < a_lba) {
|
if (first < a_lba && a_first < a_lba) {
|
||||||
/* Free space [first, lba> */
|
/* Free space [first, lba> */
|
||||||
@ -543,12 +518,7 @@ gpart_autofill(struct gctl_req *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
s = find_provcfg(pp, "end");
|
s = find_provcfg(pp, "end");
|
||||||
if (s == NULL) {
|
first = (off_t)strtoimax(s, NULL, 0) + 1;
|
||||||
s = find_provcfg(pp, "length");
|
|
||||||
first = lba +
|
|
||||||
(off_t)strtoimax(s, NULL, 0) / pp->lg_sectorsize;
|
|
||||||
} else
|
|
||||||
first = (off_t)strtoimax(s, NULL, 0) + 1;
|
|
||||||
a_first = ALIGNUP(first, alignment);
|
a_first = ALIGNUP(first, alignment);
|
||||||
}
|
}
|
||||||
if (a_first <= last) {
|
if (a_first <= last) {
|
||||||
@ -625,21 +595,12 @@ gpart_show_geom(struct ggeom *gp, const char *element, int show_providers)
|
|||||||
|
|
||||||
while ((pp = find_provider(gp, first)) != NULL) {
|
while ((pp = find_provider(gp, first)) != NULL) {
|
||||||
s = find_provcfg(pp, "start");
|
s = find_provcfg(pp, "start");
|
||||||
if (s == NULL) {
|
sector = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "offset");
|
|
||||||
sector = (off_t)strtoimax(s, NULL, 0) / secsz;
|
|
||||||
} else
|
|
||||||
sector = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
|
|
||||||
s = find_provcfg(pp, "end");
|
s = find_provcfg(pp, "end");
|
||||||
if (s == NULL) {
|
end = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "length");
|
length = end - sector + 1;
|
||||||
length = (off_t)strtoimax(s, NULL, 0) / secsz;
|
|
||||||
end = sector + length - 1;
|
|
||||||
} else {
|
|
||||||
end = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
length = end - sector + 1;
|
|
||||||
}
|
|
||||||
s = find_provcfg(pp, "index");
|
s = find_provcfg(pp, "index");
|
||||||
idx = atoi(s);
|
idx = atoi(s);
|
||||||
if (first < sector) {
|
if (first < sector) {
|
||||||
@ -782,20 +743,12 @@ gpart_backup(struct gctl_req *req, unsigned int fl __unused)
|
|||||||
printf("%s %s\n", scheme, s);
|
printf("%s %s\n", scheme, s);
|
||||||
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
LIST_FOREACH(pp, &gp->lg_provider, lg_provider) {
|
||||||
s = find_provcfg(pp, "start");
|
s = find_provcfg(pp, "start");
|
||||||
if (s == NULL) {
|
sector = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "offset");
|
|
||||||
sector = (off_t)strtoimax(s, NULL, 0) / secsz;
|
|
||||||
} else
|
|
||||||
sector = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
|
|
||||||
s = find_provcfg(pp, "end");
|
s = find_provcfg(pp, "end");
|
||||||
if (s == NULL) {
|
end = (off_t)strtoimax(s, NULL, 0);
|
||||||
s = find_provcfg(pp, "length");
|
length = end - sector + 1;
|
||||||
length = (off_t)strtoimax(s, NULL, 0) / secsz;
|
|
||||||
} else {
|
|
||||||
end = (off_t)strtoimax(s, NULL, 0);
|
|
||||||
length = end - sector + 1;
|
|
||||||
}
|
|
||||||
s = find_provcfg(pp, "label");
|
s = find_provcfg(pp, "label");
|
||||||
printf("%-*s %*s %*jd %*jd %s %s\n",
|
printf("%-*s %*s %*jd %*jd %s %s\n",
|
||||||
windex, find_provcfg(pp, "index"),
|
windex, find_provcfg(pp, "index"),
|
||||||
|
Loading…
Reference in New Issue
Block a user