bhyveload.c (267399) | bhyveload.c (268932) |
---|---|
1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: stable/10/usr.sbin/bhyveload/bhyveload.c 267399 2014-06-12 15:20:59Z jhb $ | 26 * $FreeBSD: stable/10/usr.sbin/bhyveload/bhyveload.c 268932 2014-07-20 22:54:03Z jhb $ |
27 */ 28 29/*- 30 * Copyright (c) 2011 Google, Inc. 31 * All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 * SUCH DAMAGE. 53 * | 27 */ 28 29/*- 30 * Copyright (c) 2011 Google, Inc. 31 * All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 * SUCH DAMAGE. 53 * |
54 * $FreeBSD: stable/10/usr.sbin/bhyveload/bhyveload.c 267399 2014-06-12 15:20:59Z jhb $ | 54 * $FreeBSD: stable/10/usr.sbin/bhyveload/bhyveload.c 268932 2014-07-20 22:54:03Z jhb $ |
55 */ 56 57#include <sys/cdefs.h> | 55 */ 56 57#include <sys/cdefs.h> |
58__FBSDID("$FreeBSD: stable/10/usr.sbin/bhyveload/bhyveload.c 267399 2014-06-12 15:20:59Z jhb $"); | 58__FBSDID("$FreeBSD: stable/10/usr.sbin/bhyveload/bhyveload.c 268932 2014-07-20 22:54:03Z jhb $"); |
59 60#include <sys/ioctl.h> 61#include <sys/stat.h> 62#include <sys/disk.h> 63#include <sys/queue.h> 64 65#include <machine/specialreg.h> 66#include <machine/vmm.h> --- 16 unchanged lines hidden (view full) --- 83#include <vmmapi.h> 84 85#include "userboot.h" 86 87#define MB (1024 * 1024UL) 88#define GB (1024 * 1024 * 1024UL) 89#define BSP 0 90 | 59 60#include <sys/ioctl.h> 61#include <sys/stat.h> 62#include <sys/disk.h> 63#include <sys/queue.h> 64 65#include <machine/specialreg.h> 66#include <machine/vmm.h> --- 16 unchanged lines hidden (view full) --- 83#include <vmmapi.h> 84 85#include "userboot.h" 86 87#define MB (1024 * 1024UL) 88#define GB (1024 * 1024 * 1024UL) 89#define BSP 0 90 |
91#define NDISKS 32 92 |
|
91static char *host_base; 92static struct termios term, oldterm; | 93static char *host_base; 94static struct termios term, oldterm; |
93static int disk_fd = -1; | 95static int disk_fd[NDISKS]; 96static int ndisks; |
94static int consin_fd, consout_fd; 95 96static char *vmname, *progname; 97static struct vmctx *ctx; 98 99static uint64_t gdtbase, cr3, rsp; 100 101static void cb_exit(void *arg, int v); --- 180 unchanged lines hidden (view full) --- 282 */ 283 284static int 285cb_diskread(void *arg, int unit, uint64_t from, void *to, size_t size, 286 size_t *resid) 287{ 288 ssize_t n; 289 | 97static int consin_fd, consout_fd; 98 99static char *vmname, *progname; 100static struct vmctx *ctx; 101 102static uint64_t gdtbase, cr3, rsp; 103 104static void cb_exit(void *arg, int v); --- 180 unchanged lines hidden (view full) --- 285 */ 286 287static int 288cb_diskread(void *arg, int unit, uint64_t from, void *to, size_t size, 289 size_t *resid) 290{ 291 ssize_t n; 292 |
290 if (unit != 0 || disk_fd == -1) | 293 if (unit < 0 || unit >= ndisks ) |
291 return (EIO); | 294 return (EIO); |
292 n = pread(disk_fd, to, size, from); | 295 n = pread(disk_fd[unit], to, size, from); |
293 if (n < 0) 294 return (errno); 295 *resid = size - n; 296 return (0); 297} 298 299static int 300cb_diskioctl(void *arg, int unit, u_long cmd, void *data) 301{ 302 struct stat sb; 303 | 296 if (n < 0) 297 return (errno); 298 *resid = size - n; 299 return (0); 300} 301 302static int 303cb_diskioctl(void *arg, int unit, u_long cmd, void *data) 304{ 305 struct stat sb; 306 |
304 if (unit != 0 || disk_fd == -1) | 307 if (unit < 0 || unit >= ndisks) |
305 return (EBADF); 306 307 switch (cmd) { 308 case DIOCGSECTORSIZE: 309 *(u_int *)data = 512; 310 break; 311 case DIOCGMEDIASIZE: | 308 return (EBADF); 309 310 switch (cmd) { 311 case DIOCGSECTORSIZE: 312 *(u_int *)data = 512; 313 break; 314 case DIOCGMEDIASIZE: |
312 if (fstat(disk_fd, &sb) == 0) | 315 if (fstat(disk_fd[unit], &sb) == 0) |
313 *(off_t *)data = sb.st_size; 314 else 315 return (ENOTTY); 316 break; 317 default: 318 return (ENOTTY); 319 } 320 --- 275 unchanged lines hidden (view full) --- 596 else 597 consin_fd = consout_fd = fd; 598 } 599 } 600 601 return (err); 602} 603 | 316 *(off_t *)data = sb.st_size; 317 else 318 return (ENOTTY); 319 break; 320 default: 321 return (ENOTTY); 322 } 323 --- 275 unchanged lines hidden (view full) --- 599 else 600 consin_fd = consout_fd = fd; 601 } 602 } 603 604 return (err); 605} 606 |
607static int 608disk_open(char *path) 609{ 610 int err, fd; 611 612 if (ndisks > NDISKS) 613 return (ERANGE); 614 615 err = 0; 616 fd = open(path, O_RDONLY); 617 618 if (fd > 0) { 619 disk_fd[ndisks] = fd; 620 ndisks++; 621 } else 622 err = errno; 623 624 return (err); 625} 626 |
|
604static void 605usage(void) 606{ 607 608 fprintf(stderr, 609 "usage: %s [-m mem-size] [-d <disk-path>] [-h <host-path>]\n" 610 " %*s [-e <name=value>] [-c <console-device>] <vmname>\n", 611 progname, 612 (int)strlen(progname), ""); 613 exit(1); 614} 615 616int 617main(int argc, char** argv) 618{ 619 void *h; 620 void (*func)(struct loader_callbacks *, void *, int, int); 621 uint64_t mem_size; 622 int opt, error; | 627static void 628usage(void) 629{ 630 631 fprintf(stderr, 632 "usage: %s [-m mem-size] [-d <disk-path>] [-h <host-path>]\n" 633 " %*s [-e <name=value>] [-c <console-device>] <vmname>\n", 634 progname, 635 (int)strlen(progname), ""); 636 exit(1); 637} 638 639int 640main(int argc, char** argv) 641{ 642 void *h; 643 void (*func)(struct loader_callbacks *, void *, int, int); 644 uint64_t mem_size; 645 int opt, error; |
623 char *disk_image; | |
624 625 progname = basename(argv[0]); 626 627 mem_size = 256 * MB; | 646 647 progname = basename(argv[0]); 648 649 mem_size = 256 * MB; |
628 disk_image = NULL; | |
629 630 consin_fd = STDIN_FILENO; 631 consout_fd = STDOUT_FILENO; 632 633 while ((opt = getopt(argc, argv, "c:d:e:h:m:")) != -1) { 634 switch (opt) { 635 case 'c': 636 error = altcons_open(optarg); 637 if (error != 0) 638 errx(EX_USAGE, "Could not open '%s'", optarg); 639 break; | 650 651 consin_fd = STDIN_FILENO; 652 consout_fd = STDOUT_FILENO; 653 654 while ((opt = getopt(argc, argv, "c:d:e:h:m:")) != -1) { 655 switch (opt) { 656 case 'c': 657 error = altcons_open(optarg); 658 if (error != 0) 659 errx(EX_USAGE, "Could not open '%s'", optarg); 660 break; |
661 |
|
640 case 'd': | 662 case 'd': |
641 disk_image = optarg; | 663 error = disk_open(optarg); 664 if (error != 0) 665 errx(EX_USAGE, "Could not open '%s'", optarg); |
642 break; 643 644 case 'e': 645 addenv(optarg); 646 break; 647 648 case 'h': 649 host_base = optarg; --- 49 unchanged lines hidden (view full) --- 699 return (1); 700 } 701 func = dlsym(h, "loader_main"); 702 if (!func) { 703 printf("%s\n", dlerror()); 704 return (1); 705 } 706 | 666 break; 667 668 case 'e': 669 addenv(optarg); 670 break; 671 672 case 'h': 673 host_base = optarg; --- 49 unchanged lines hidden (view full) --- 723 return (1); 724 } 725 func = dlsym(h, "loader_main"); 726 if (!func) { 727 printf("%s\n", dlerror()); 728 return (1); 729 } 730 |
707 if (disk_image) { 708 disk_fd = open(disk_image, O_RDONLY); 709 } 710 | |
711 addenv("smbios.bios.vendor=BHYVE"); 712 addenv("boot_serial=1"); 713 | 731 addenv("smbios.bios.vendor=BHYVE"); 732 addenv("boot_serial=1"); 733 |
714 func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0); | 734 func(&cb, NULL, USERBOOT_VERSION_3, ndisks); |
715} | 735} |