Skip to content

Commit

Permalink
Only grow, but never shrink the disk
Browse files Browse the repository at this point in the history
  • Loading branch information
reyk committed Jun 2, 2019
1 parent bce8634 commit 0509d8d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions agent/growdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "main.h"

#define MEG(_n) ((_n) * DEV_BSIZE / 1024 / 1024)

static uint16_t dkcksum(struct disklabel *);

static uint16_t
Expand Down Expand Up @@ -115,18 +117,22 @@ growdisk(struct system_config *sc)
bend = DL_GETDSIZE(&lp) - DL_GETBSTART(&lp);
psize = bend - DL_GETPOFFSET(p);

if (sc->sc_dryrun ||
(bend == DL_GETBEND(&lp) && psize == DL_GETPSIZE(p))) {
log_debug("%s: %s%c uses maximum size %llu",
__func__, sc->sc_rootdisk, last_part, psize);

/* Only grow, but never shring the disk */
if (bend <= DL_GETBEND(&lp) && psize <= DL_GETPSIZE(p)) {
log_debug("%s: not growing %s%c, size is %lluMB",
__func__, sc->sc_rootdisk, last_part, MEG(psize));
ret = 0;
} else {
log_info("growing %s%c from %lluMB to %lluMB",
sc->sc_rootdisk, last_part,
MEG(DL_GETPSIZE(p)), MEG(psize));
ret = -1;
}
if (sc->sc_dryrun || ret == 0) {
ret = 0;
goto done;
}

log_debug("%s: growing %s%c from %llu to %llu",
__func__, sc->sc_rootdisk, last_part, DL_GETPSIZE(p), psize);

/* Update OpenBSD boundaries */
DL_SETBEND(&lp, bend);

Expand Down

0 comments on commit 0509d8d

Please sign in to comment.