diff options
author | Jason King <jasonbking@users.noreply.github.com> | 2020-04-03 15:19:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 15:19:01 -0500 |
commit | c6b5d5788f3f75eefac0f25b62e7ea710a10c0cd (patch) | |
tree | afc10fd31f963a853ed90d43f712b0e7c2ef9081 | |
parent | 0842b8733385ba587ffdaf4ebb48ff329a8e0134 (diff) | |
download | illumos-joyent-c6b5d5788f3f75eefac0f25b62e7ea710a10c0cd.tar.gz |
OS-8154 Expose bhyve sectsize property for virtio block devices (#283)
Reviewed by: Mike Gerdts <mike.gerdts@joyent.com>
Reviewed by: Mike Zeller <mike.zeller@joyent.com>
Approved by: Mike Zeller <mike.zeller@joyent.com>
-rw-r--r-- | usr/src/lib/brand/bhyve/zone/boot.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/usr/src/lib/brand/bhyve/zone/boot.c b/usr/src/lib/brand/bhyve/zone/boot.c index dadcf4e96a..645958d14a 100644 --- a/usr/src/lib/brand/bhyve/zone/boot.c +++ b/usr/src/lib/brand/bhyve/zone/boot.c @@ -225,11 +225,17 @@ add_disk(char *disk, char *path, char *slotconf, size_t slotconf_len) static char *boot = NULL; static int next_cd = 0; static int next_other = 0; + custr_t *sconfstr = NULL; const char *model = "virtio-blk"; uint_t pcibus = 0, pcidev = 0, pcifn = 0; const char *slotstr; - const char *nodelstr = ""; + const char *guest_block_size = NULL; boolean_t isboot; + boolean_t nodelete = B_FALSE; + + if (custr_alloc_buf(&sconfstr, slotconf, slotconf_len) == -1) { + return (-1); + } isboot = is_env_true("device", disk, "boot"); if (isboot) { @@ -237,14 +243,14 @@ add_disk(char *disk, char *path, char *slotconf, size_t slotconf_len) if (boot != NULL) { (void) printf("Error: multiple boot disks: %s %s\n", boot, path); - return (-1); + goto fail; } boot = path; } if ((slotstr = get_zcfg_var("device", disk, "pci_slot")) != NULL) { if (parse_pcislot(slotstr, &pcibus, &pcidev, &pcifn) != 0) { - return (-1); + goto fail; } } else { if (isboot) { @@ -271,8 +277,15 @@ add_disk(char *disk, char *path, char *slotconf, size_t slotconf_len) * be the most familiar name for the operation (and less * likely to cause confusion). */ - if (is_env_string("device", disk, "notrim", "true")) - nodelstr = ",nodelete"; + nodelete = is_env_true("device", disk, "notrim"); + guest_block_size = get_zcfg_var("device", disk, + "guest_block_size"); + + /* Treat a 0 size to mean the whatever the volume advertises */ + if (guest_block_size != NULL && + strcmp(guest_block_size, "0") == 0) { + guest_block_size = NULL; + } } else if (is_env_string("device", disk, "model", "ahci")) { if (is_env_string("device", disk, "media", "cdrom")) { model = "ahci-cd"; @@ -281,16 +294,32 @@ add_disk(char *disk, char *path, char *slotconf, size_t slotconf_len) } } else { (void) printf("Error: unknown disk model '%s'\n", model); - return (-1); + goto fail; } - if (snprintf(slotconf, slotconf_len, "%u:%u:%u,%s,%s%s", - pcibus, pcidev, pcifn, model, path, nodelstr) >= slotconf_len) { + if (custr_append_printf(sconfstr, "%u:%u:%u,%s,%s", + pcibus, pcidev, pcifn, model, path) == -1) { (void) printf("Error: disk path '%s' too long\n", path); - return (-1); + goto fail; + } + + if (nodelete && custr_append(sconfstr, ",nodelete") == -1) { + (void) printf("Error: too many disk options\n"); + goto fail; + } + + if (guest_block_size != NULL && custr_append_printf(sconfstr, + ",sectorsize=%s", guest_block_size) == -1) { + (void) printf("Error: too many disk options\n"); + goto fail; } + custr_free(sconfstr); return (0); + +fail: + custr_free(sconfstr); + return (-1); } static int |