> Date: Thu, 28 Nov 2019 17:12:28 +0100
> From: Klemens Nanni <[email protected]>
>
> Replace the hand-written routing with a proper library allowing even
> more formats. vmctl(8) does the same, which is also where I took the
> manual wording from.
>
> ldomctl has a local "util.h" which is included by parse.y, so
> compilation would fail to find scan_scaled after including <util.h> due
> the include paths set in Makefile.
>
> After consulting with mortimer and guenther, the solution is to rename
> the local util.h, so I went with ldom_util.h - this file is reached
> around to from ldomd as well, hence no ldomctl_util.h or so.
>
> ldomctl seems to be the only case where local files conflict with global
> ones; is that the right approach? Do others consider it worth it?
>
> util.h is small and generic, so renaming won't really cause annoyance
> with CVS logs.
>
> Feedback? OK?
The man page change is not an improvement.
Last time something like this was tried, it required additional spaces
between numbers and factors. This diff doesn't suffer from that?
> Index: ldomd/ds.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomd/ds.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 ds.c
> --- ldomd/ds.c 20 Oct 2019 16:18:36 -0000 1.9
> +++ ldomd/ds.c 28 Nov 2019 06:01:21 -0000
> @@ -27,7 +27,7 @@
> #include <unistd.h>
>
> #include "ds.h"
> -#include "util.h"
> +#include "ldom_util.h"
>
> void ldc_rx_ctrl_vers(struct ldc_conn *, struct ldc_pkt *);
> void ldc_rx_ctrl_rtr(struct ldc_conn *, struct ldc_pkt *);
> Index: ldomd/ldomd.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomd/ldomd.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 ldomd.c
> --- ldomd/ldomd.c 29 Sep 2019 17:10:00 -0000 1.9
> +++ ldomd/ldomd.c 28 Nov 2019 06:01:21 -0000
> @@ -34,7 +34,7 @@
> #include "ds.h"
> #include "hvctl.h"
> #include "mdesc.h"
> -#include "util.h"
> +#include "ldom_util.h"
> #include "ldomd.h"
>
> TAILQ_HEAD(guest_head, guest) guests;
> Index: ldomd/var-config.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomd/var-config.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 var-config.c
> --- ldomd/var-config.c 27 Oct 2012 20:51:42 -0000 1.2
> +++ ldomd/var-config.c 28 Nov 2019 06:01:21 -0000
> @@ -29,7 +29,7 @@
>
> #include "ds.h"
> #include "mdesc.h"
> -#include "util.h"
> +#include "ldom_util.h"
> #include "ldomd.h"
>
> void var_config_start(struct ldc_conn *, uint64_t);
> Index: ldomctl/Makefile
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/Makefile,v
> retrieving revision 1.10
> diff -u -p -r1.10 Makefile
> --- ldomctl/Makefile 20 Nov 2019 18:11:28 -0000 1.10
> +++ ldomctl/Makefile 28 Nov 2019 05:59:47 -0000
> @@ -8,6 +8,8 @@ PROG= ldomctl
> SRCS= ldomctl.c ds.c mdesc.c util.c mdstore.c pri.c config.c parse.y
> CFLAGS+=-Wall
> CFLAGS+=-I${.CURDIR}/../ldomd -I${.CURDIR}
> +LDADD+= -lutil
> +DPADD+= ${LIBUTIL}
>
> .else
>
> Index: ldomctl/config.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/config.c,v
> retrieving revision 1.28
> diff -u -p -r1.28 config.c
> --- ldomctl/config.c 27 Nov 2019 19:54:10 -0000 1.28
> +++ ldomctl/config.c 28 Nov 2019 05:59:01 -0000
> @@ -28,7 +28,7 @@
>
> #include "mdesc.h"
> #include "ldomctl.h"
> -#include "util.h"
> +#include "ldom_util.h"
>
> #define LDC_GUEST 0
> #define LDC_HV 1
> Index: ldomctl/ldom.conf.5
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/ldom.conf.5,v
> retrieving revision 1.6
> diff -u -p -r1.6 ldom.conf.5
> --- ldomctl/ldom.conf.5 5 Aug 2019 19:27:47 -0000 1.6
> +++ ldomctl/ldom.conf.5 28 Nov 2019 04:40:53 -0000
> @@ -41,10 +41,11 @@ Declare the number of virtual CPUs assig
> Optionally a stride can be specified to allocate additional virtual CPUs
> but not assign them to a domain.
> This can be used to distribute virtual CPUs over the available CPU cores.
> -.It Ic memory Ar number Ns Op Ar unit
> +.It Ic memory Ar bytes
> Declare the amount of memory assigned to a domain, in bytes.
> -Optionally, the units 'K', 'M', or 'G', for kilo-, mega-, and gigabytes
> -can be used.
> +.Ar bytes
> +can be specified with a human-readable scale, using the format described in
> +.Xr scan_scaled 3 .
> .It Ic iodevice Ar path
> Assign the specified PCIe device to the guest domain.
> This keyword can be used multiple times.
> Index: ldomctl/ldom_util.h
> ===================================================================
> RCS file: ldomctl/ldom_util.h
> diff -N ldomctl/ldom_util.h
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ ldomctl/ldom_util.h 28 Nov 2019 05:59:01 -0000
> @@ -0,0 +1,30 @@
> +/* $OpenBSD: util.h,v 1.4 2014/10/15 21:37:27 deraadt Exp $ */
> +
> +/*
> + * Copyright (c) 2012 Mark Kettenis
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <stddef.h>
> +
> +extern int debug;
> +#define DPRINTF(x) if (debug) printf x
> +
> +void *xmalloc(size_t);
> +void *xzalloc(size_t);
> +void *xreallocarray(void *, size_t, size_t);
> +char *xstrdup(const char *);
> +int xasprintf(char**, const char *, ...);
> +
> +#define roundup(n, m) (((n) + ((m) - 1)) & ~((m) - 1))
> Index: ldomctl/ldomctl.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.c,v
> retrieving revision 1.24
> diff -u -p -r1.24 ldomctl.c
> --- ldomctl/ldomctl.c 28 Nov 2019 04:29:39 -0000 1.24
> +++ ldomctl/ldomctl.c 28 Nov 2019 05:59:01 -0000
> @@ -29,7 +29,7 @@
> #include "hvctl.h"
> #include "mdstore.h"
> #include "mdesc.h"
> -#include "util.h"
> +#include "ldom_util.h"
> #include "ldomctl.h"
>
> extern struct ds_service pri_service;
> Index: ldomctl/mdesc.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/mdesc.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 mdesc.c
> --- ldomctl/mdesc.c 14 Jul 2019 14:40:55 -0000 1.12
> +++ ldomctl/mdesc.c 28 Nov 2019 05:59:01 -0000
> @@ -25,7 +25,7 @@
> #include <string.h>
>
> #include "mdesc.h"
> -#include "util.h"
> +#include "ldom_util.h"
>
> struct md_name *
> md_find_name(struct md *md, const char *str)
> Index: ldomctl/mdstore.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/mdstore.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 mdstore.c
> --- ldomctl/mdstore.c 7 Jul 2019 14:45:15 -0000 1.11
> +++ ldomctl/mdstore.c 28 Nov 2019 05:59:01 -0000
> @@ -26,7 +26,7 @@
> #include "ds.h"
> #include "mdesc.h"
> #include "mdstore.h"
> -#include "util.h"
> +#include "ldom_util.h"
> #include "ldomctl.h"
>
> void mdstore_start(struct ldc_conn *, uint64_t);
> Index: ldomctl/parse.y
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/parse.y,v
> retrieving revision 1.12
> diff -u -p -r1.12 parse.y
> --- ldomctl/parse.y 5 Aug 2019 19:27:47 -0000 1.12
> +++ ldomctl/parse.y 28 Nov 2019 04:39:07 -0000
> @@ -37,6 +37,7 @@
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <util.h>
>
> #include "ldomctl.h"
> #include "util.h"
> @@ -236,23 +237,10 @@ memory : NUMBER {
> $$ = $1;
> }
> | STRING {
> - uint64_t size;
> - char *cp;
> -
> - size = strtoll($1, &cp, 10);
> - if (cp != NULL) {
> - if (strcmp(cp, "K") == 0)
> - size *= 1024;
> - else if (strcmp(cp, "M") == 0)
> - size *= 1024 * 1024;
> - else if (strcmp(cp, "G") == 0)
> - size *= 1024 * 1024 * 1024;
> - else {
> - yyerror("unknown unit %s", cp);
> - YYERROR;
> - }
> + if (scan_scaled($1, &$$) == -1) {
> + yyerror("invalid size: %s", $1);
> + YYERROR;
> }
> - $$ = size;
> }
> ;
>
> Index: ldomctl/pri.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/pri.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 pri.c
> --- ldomctl/pri.c 4 Nov 2012 19:04:11 -0000 1.1
> +++ ldomctl/pri.c 28 Nov 2019 05:59:01 -0000
> @@ -21,7 +21,7 @@
>
> #include "ds.h"
> #include "mdesc.h"
> -#include "util.h"
> +#include "ldom_util.h"
>
> void pri_start(struct ldc_conn *, uint64_t);
> void pri_rx_data(struct ldc_conn *, uint64_t, void *, size_t);
> Index: ldomctl/util.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ldomctl/util.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 util.c
> --- ldomctl/util.c 15 Oct 2014 21:37:27 -0000 1.4
> +++ ldomctl/util.c 28 Nov 2019 05:59:01 -0000
> @@ -22,7 +22,7 @@
> #include <stdlib.h>
> #include <string.h>
>
> -#include "util.h"
> +#include "ldom_util.h"
>
> int debug;
>
> Index: ldomctl/util.h
> ===================================================================
> RCS file: ldomctl/util.h
> diff -N ldomctl/util.h
> --- ldomctl/util.h 15 Oct 2014 21:37:27 -0000 1.4
> +++ /dev/null 1 Jan 1970 00:00:00 -0000
> @@ -1,33 +0,0 @@
> -/* $OpenBSD: util.h,v 1.4 2014/10/15 21:37:27 deraadt Exp $ */
> -
> -/*
> - * Copyright (c) 2012 Mark Kettenis
> - *
> - * Permission to use, copy, modify, and distribute this software for any
> - * purpose with or without fee is hereby granted, provided that the above
> - * copyright notice and this permission notice appear in all copies.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> - */
> -
> -#include <stddef.h>
> -
> -extern int debug;
> -#define DPRINTF(x) if (debug) printf x
> -
> -void *xmalloc(size_t);
> -void *xzalloc(size_t);
> -void *xreallocarray(void *, size_t, size_t);
> -char *xstrdup(const char *);
> -int xasprintf(char**, const char *, ...);
> -
> -#define min(a, b) ((a) < (b) ? (a) : (b))
> -#define max(a, b) ((a) > (b) ? (a) : (b))
> -
> -#define roundup(n, m) (((n) + ((m) - 1)) & ~((m) - 1))
>
>