svn commit: r249916 - head/usr.sbin/bhyve

Neel Natu neel at FreeBSD.org
Fri Apr 26 02:24:52 UTC 2013


Author: neel
Date: Fri Apr 26 02:24:50 2013
New Revision: 249916
URL: http://svnweb.freebsd.org/changeset/base/249916

Log:
  Gripe if some <slot,function> tuple is specified more than once instead of
  silently overwriting the previous assignment.
  
  Gripe if the emulation is not recognized instead of silently ignoring the
  emulated device.
  
  If an error is detected by pci_parse_slot() then exit from the command line
  parsing loop in main().
  
  Submitted by (initial version):	Chris Torek (chris.torek at gmail.com)

Modified:
  head/usr.sbin/bhyve/bhyverun.c
  head/usr.sbin/bhyve/pci_emul.c
  head/usr.sbin/bhyve/pci_emul.h

Modified: head/usr.sbin/bhyve/bhyverun.c
==============================================================================
--- head/usr.sbin/bhyve/bhyverun.c	Fri Apr 26 01:56:58 2013	(r249915)
+++ head/usr.sbin/bhyve/bhyverun.c	Fri Apr 26 02:24:50 2013	(r249916)
@@ -631,11 +631,15 @@ main(int argc, char *argv[])
 			guest_tslice = atoi(optarg);
 			break;
 		case 's':
-			pci_parse_slot(optarg, 0);
-			break;
+			if (pci_parse_slot(optarg, 0) != 0)
+				exit(1);
+			else
+				break;
 		case 'S':
-			pci_parse_slot(optarg, 1);
-			break;
+			if (pci_parse_slot(optarg, 1) != 0)
+				exit(1);
+			else
+				break;
                 case 'm':
 			memsize = strtoul(optarg, NULL, 0) * MB;
 			break;

Modified: head/usr.sbin/bhyve/pci_emul.c
==============================================================================
--- head/usr.sbin/bhyve/pci_emul.c	Fri Apr 26 01:56:58 2013	(r249915)
+++ head/usr.sbin/bhyve/pci_emul.c	Fri Apr 26 02:24:50 2013	(r249916)
@@ -100,6 +100,8 @@ static uint64_t pci_emul_membase64;
 #define	PCI_EMUL_MEMBASE64	0xD000000000UL
 #define	PCI_EMUL_MEMLIMIT64	0xFD00000000UL
 
+static struct pci_devemu *pci_emul_finddev(char *name);
+
 static int pci_emul_devices;
 
 /*
@@ -123,17 +125,18 @@ static int pci_emul_devices;
 static void
 pci_parse_slot_usage(char *aopt)
 {
-	printf("Invalid PCI slot info field \"%s\"\n", aopt);
-	free(aopt);
+
+	fprintf(stderr, "Invalid PCI slot info field \"%s\"\n", aopt);
 }
 
-void
+int
 pci_parse_slot(char *opt, int legacy)
 {
 	char *slot, *func, *emul, *config;
 	char *str, *cpy;
-	int snum, fnum;
+	int error, snum, fnum;
 
+	error = -1;
 	str = cpy = strdup(opt);
 
 	config = NULL;
@@ -152,19 +155,40 @@ pci_parse_slot(char *opt, int legacy)
 	}
 
 	if (emul == NULL) {
-		pci_parse_slot_usage(cpy);
-		return;
+		pci_parse_slot_usage(opt);
+		goto done;
 	}
 
 	snum = atoi(slot);
 	fnum = func ? atoi(func) : 0;
+
 	if (snum < 0 || snum >= MAXSLOTS || fnum < 0 || fnum >= MAXFUNCS) {
-		pci_parse_slot_usage(cpy);
-	} else {
-		pci_slotinfo[snum][fnum].si_name = emul;
-		pci_slotinfo[snum][fnum].si_param = config;
-		pci_slotinfo[snum][fnum].si_legacy = legacy;
+		pci_parse_slot_usage(opt);
+		goto done;
 	}
+
+	if (pci_slotinfo[snum][fnum].si_name != NULL) {
+		fprintf(stderr, "pci slot %d:%d already occupied!\n",
+			snum, fnum);
+		goto done;
+	}
+
+	if (pci_emul_finddev(emul) == NULL) {
+		fprintf(stderr, "pci slot %d:%d: unknown device \"%s\"\n",
+			snum, fnum, emul);
+		goto done;
+	}
+
+	error = 0;
+	pci_slotinfo[snum][fnum].si_name = emul;
+	pci_slotinfo[snum][fnum].si_param = config;
+	pci_slotinfo[snum][fnum].si_legacy = legacy;
+
+done:
+	if (error)
+		free(cpy);
+
+	return (error);
 }
 
 static int
@@ -988,10 +1012,9 @@ init_pci(struct vmctx *ctx)
 			si = &pci_slotinfo[slot][func];
 			if (si->si_name != NULL) {
 				pde = pci_emul_finddev(si->si_name);
-				if (pde != NULL) {
-					pci_emul_init(ctx, pde, slot, func,
-						      si->si_param);
-				}
+				assert(pde != NULL);
+				pci_emul_init(ctx, pde, slot, func,
+					      si->si_param);
 			}
 		}
 	}

Modified: head/usr.sbin/bhyve/pci_emul.h
==============================================================================
--- head/usr.sbin/bhyve/pci_emul.h	Fri Apr 26 01:56:58 2013	(r249915)
+++ head/usr.sbin/bhyve/pci_emul.h	Fri Apr 26 02:24:50 2013	(r249916)
@@ -206,7 +206,7 @@ int	pci_msix_enabled(struct pci_devinst 
 int	pci_msix_table_bar(struct pci_devinst *pi);
 int	pci_msix_pba_bar(struct pci_devinst *pi);
 int	pci_msi_msgnum(struct pci_devinst *pi);
-void	pci_parse_slot(char *opt, int legacy);
+int	pci_parse_slot(char *opt, int legacy);
 void	pci_populate_msicap(struct msicap *cap, int msgs, int nextptr);
 int	pci_emul_add_msixcap(struct pci_devinst *pi, int msgnum, int barnum);
 int	pci_emul_msix_twrite(struct pci_devinst *pi, uint64_t offset, int size,


More information about the svn-src-head mailing list