Re: vmd writes corrupt qcow2 images

2022-04-18 Thread Ori Bernstein
Yep. I can look at it in a few days. I'm assuming that the vm was stopped before running the check? On April 18, 2022 3:42:50 PM EDT, Mike Larkin wrote: >On Mon, Apr 18, 2022 at 12:21:39PM -0400, Dave Voutila wrote: >> >> "Thomas L." writes: >> >> > Hi, >> > >> > I recently tried to use

Re: fix and enable vmd(8) diskfmt regress test

2021-06-13 Thread Ori Bernstein
On Sun, 13 Jun 2021 11:09:20 -0400, Dave Voutila wrote: > Was about to add a test for something I'm hacking on when I noticed the > diskfmt regress test wasn't enabled. I took a look and it's rotted. :( > > It was originally written by Ori Bernstein and imported by ccardenas@ &

Re: Fixes for padding in OpenFlow header match fields

2019-11-26 Thread Ori Bernstein
_print_setfield(const u_char *bp, u_int length) > { > struct ofp_action_set_field *asf; > - struct ofp_ox_match *oxm; > int omlen; > > if (length < (sizeof(*asf) - AH_UNPADDED)) { > @@ -1030,27 +1000,7 @@ action_print_setfield(const u_char *bp, > if (omlen == 0) > return; > > - parse_next_oxm: > - if (length < sizeof(*oxm)) { > - printf(" [|OpenFlow]"); > - return; > - } > - > - oxm = (struct ofp_ox_match *)bp; > - bp += sizeof(*oxm); > - length -= sizeof(*oxm); > - if (length < oxm->oxm_length) { > - printf(" [|OpenFlow]"); > - return; > - } > - > - ofp_print_oxm(oxm, bp, length); > - > - bp += oxm->oxm_length; > - length -= oxm->oxm_length; > - omlen -= min(sizeof(*oxm) + oxm->oxm_length, omlen); > - if (omlen) > - goto parse_next_oxm; > + ofp_print_oxm_field(bp, length, omlen, 1); > } > > void > @@ -1094,6 +1044,7 @@ ofp_print_action(struct ofp_action_heade > break; > > case OFP_ACTION_SET_FIELD: > + action_print_setfield(bp, length); > break; > > case OFP_ACTION_COPY_TTL_OUT: > -- Ori Bernstein

Re: Reuse VM ids.

2018-11-23 Thread Ori Bernstein
On Fri, 16 Nov 2018 16:15:14 +0100, Reyk Floeter wrote: > On Sat, Oct 27, 2018 at 02:53:16PM -0700, Ori Bernstein wrote: > > On Fri, 26 Oct 2018 01:57:15 +0200, Reyk Floeter wrote: > > > > > On Tue, Oct 23, 2018 at 10:21:08PM -0700, Ori Bernstein wrote: > > &

Re: Reuse VM ids.

2018-11-03 Thread Ori Bernstein
On Sat, 27 Oct 2018 14:53:16 -0700, Ori Bernstein wrote: > On Fri, 26 Oct 2018 01:57:15 +0200, Reyk Floeter wrote: > > > On Tue, Oct 23, 2018 at 10:21:08PM -0700, Ori Bernstein wrote: > > > On Mon, 8 Oct 2018 07:59:15 -0700, Bob Beck wrote: > > >

Re: Qcow2: Clean up logging/error handling

2018-11-03 Thread Ori Bernstein
On Tue, 30 Oct 2018 23:01:50 -0700, Mike Larkin wrote: > On Tue, Oct 30, 2018 at 10:41:21PM -0700, o...@eigenstate.org wrote: > > > On Tue, Oct 30, 2018 at 10:32:37PM -0700, Ori Bernstein wrote: > > >> On Tue, 30 Oct 2018 22:29:01 -0700, Mi

Re: Qcow2: Clean up logging/error handling

2018-10-30 Thread Ori Bernstein
ail if we could not open a disk image -- especially since these ones are actually *parts* of a disk image, meaning that we've got a corrupt image. I can easily change these back to warns + error returns. -- Ori Bernstein

Re: Qcow2: Clean up logging/error handling

2018-10-30 Thread Ori Bernstein
sk->end; disk->end += disk->clustersz; - if (ftruncate(disk->fd, disk->end) < 0) { - log_warn("%s: refs block grow fail", __func__); - return -1; - } + if (ftruncate(disk->fd, disk->end) < 0) + fatal("%s: failed to allocate ref block", __func__); buf = htobe64(l2cluster); - if (pwrite(disk->fd, , sizeof(buf), l1off) != 8) { - return -1; - } + if (pwrite(disk->fd, , sizeof(buf), l1off) != 8) + fatal("%s: failed to write ref block", __func__); } refs = 1; if (!newcluster) { if (pread(disk->fd, , sizeof(refs), l2cluster + 2 * l2idx) != 2) - return -1; + fatal("could not read ref cluster"); refs = be16toh(refs) + 1; } refs = htobe16(refs); - if (pwrite(disk->fd, , sizeof(refs), l2cluster + 2 * l2idx) != 2) { - log_warn("%s: could not write ref block", __func__); - return -1; - } - return 0; + if (pwrite(disk->fd, , sizeof(refs), l2cluster + 2 * l2idx) != 2) + fatal("%s: could not write ref block", __func__); } -- Ori Bernstein

Re: Qcow2: Clean up logging/error handling

2018-10-27 Thread Ori Bernstein
to change it, I think it's better as an independent patch that converts all of vmd. -- Ori Bernstein

Re: Reuse VM ids.

2018-10-27 Thread Ori Bernstein
On Fri, 26 Oct 2018 01:57:15 +0200, Reyk Floeter wrote: > On Tue, Oct 23, 2018 at 10:21:08PM -0700, Ori Bernstein wrote: > > On Mon, 8 Oct 2018 07:59:15 -0700, Bob Beck wrote: > > > > > works here and I like it. but probably for after unlock > > > >

Re: Qcow2: Clean up logging/error handling

2018-10-27 Thread Ori Bernstein
On Wed, 24 Oct 2018 16:23:29 +0800, Michael Mikonos wrote: > On Tue, Oct 23, 2018 at 09:44:24PM -0700, Ori Bernstein wrote: > > This patch turns most warnings into errors, and uses the > > appropriate fatal/fatalx so that we don't print bogus error > > strings

Re: Reuse VM ids.

2018-10-23 Thread Ori Bernstein
On Mon, 8 Oct 2018 07:59:15 -0700, Bob Beck wrote: > works here and I like it. but probably for after unlock > It's after unlock -- pinging for OKs. -- Ori Bernstein

Qcow2: Clean up logging/error handling

2018-10-23 Thread Ori Bernstein
ff; - -fail: - pthread_rwlock_unlock(>lock); - return -1; } /* Copies a cluster containing src to dst. Src and dst need not be aligned. */ @@ -630,7 +597,7 @@ inc_refs(struct qcdisk *disk, off_t off, int newcluster) l2cluster = disk->end; disk->end += disk->clustersz; if (ftruncate(disk->fd, disk->end) < 0) { - log_warn("%s: refs block grow fail", __func__); + fatalx("%s: refs block grow fail", __func__); return -1; } buf = htobe64(l2cluster); @@ -648,7 +615,7 @@ inc_refs(struct qcdisk *disk, off_t off, int newcluster) } refs = htobe16(refs); if (pwrite(disk->fd, , sizeof(refs), l2cluster + 2 * l2idx) != 2) { - log_warn("%s: could not write ref block", __func__); + fatalx("%s: could not write ref block", __func__); return -1; } return 0; -- Ori Bernstein

Reuse VM ids.

2018-10-07 Thread Ori Bernstein
uint32_t vmd_nvm; struct vmlist *vmd_vms; + struct name2idlist *vmd_known; uint32_t vmd_nswitches; struct switchlist *vmd_switches; struct userlist *vmd_users; -- Ori Bernstein

Re: Qcow2: External snapshots

2018-10-06 Thread Ori Bernstein
On Wed, 3 Oct 2018 07:27:17 +0100, Jason McIntyre wrote: > On Tue, Oct 02, 2018 at 11:13:35PM -0700, Ori Bernstein wrote: > > > > Updated version. Changes from the last diff: > > > > - Merge in syntax changes. > > - Don't over-read when getting the base

Re: Qcow2: External snapshots

2018-10-04 Thread Ori Bernstein
On Wed, 3 Oct 2018 11:36:53 +0200, Reyk Floeter wrote: > On Tue, Oct 02, 2018 at 11:13:35PM -0700, Ori Bernstein wrote: > > On Mon, 1 Oct 2018 11:24:01 -0700, Ori Bernstein > > wrote: > > > > > On Mon, 1 Oct 2018 12:55:12 +0200 > > > Rey

Re: Qcow2: External snapshots

2018-10-03 Thread Ori Bernstein
On Mon, 1 Oct 2018 11:24:01 -0700, Ori Bernstein wrote: > On Mon, 1 Oct 2018 12:55:12 +0200 > Reyk Floeter wrote: > > > Hi Ori, > > > > On Sun, Sep 30, 2018 at 12:27:00PM -0700, Ori Bernstein wrote: > > > I've added support to vmd for external

Re: Qcow2: External snapshots

2018-10-01 Thread Ori Bernstein
On Mon, 1 Oct 2018 12:55:12 +0200 Reyk Floeter wrote: > Hi Ori, > > On Sun, Sep 30, 2018 at 12:27:00PM -0700, Ori Bernstein wrote: > > I've added support to vmd for external snapshots. That is, > > snapshots that are derived from a base image. Data lookups > >

Re: Qcow2: External snapshots

2018-09-30 Thread Ori Bernstein
On Sun, 30 Sep 2018 12:27:00 -0700, Ori Bernstein wrote: > I've added support to vmd for external snapshots. That is, > snapshots that are derived from a base image. Data lookups > start in the derived image, and if the derived image does not > contain some data, the search proceeds

Qcow2: External snapshots

2018-09-30 Thread Ori Bernstein
bin/vmd/vmm.c usr.sbin/vmd/vmm.c index 7757856323f..3176fd85713 100644 --- usr.sbin/vmd/vmm.c +++ usr.sbin/vmd/vmm.c @@ -608,7 +608,7 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid) struct vmd_vm *vm; int ret = EINVAL; int fds[2]; - size_t i; + size_t i, j; if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { log_warnx("%s: can't find vm", __func__); @@ -643,8 +643,11 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid) close(fds[1]); for (i = 0 ; i < vcp->vcp_ndisks; i++) { - close(vm->vm_disks[i]); - vm->vm_disks[i] = -1; + for (j = 0; j < VMM_MAX_BASE_PER_DISK; j++) { + if (vm->vm_disks[i][j] != -1) + close(vm->vm_disks[i][j]); + vm->vm_disks[i][j] = -1; + } } for (i = 0 ; i < vcp->vcp_nnics; i++) { close(vm->vm_ifs[i].vif_fd); -- Ori Bernstein

Re: vmd: add some NULL checks after {c,m}alloc()

2018-09-14 Thread Ori Bernstein
On Fri, 14 Sep 2018 13:50:40 +0800, Michael Mikonos wrote: > On Thu, Sep 13, 2018 at 10:08:16PM -0700, Ori Bernstein wrote: > > On Thu, 13 Sep 2018 10:30:54 +0800, Michael Mikonos wrote: > > > I think a check for !disk->base belongs here as done above for disk->

Re: vmd: add some NULL checks after {c,m}alloc()

2018-09-13 Thread Ori Bernstein
); uint32_t vring_size(uint32_t); diff --git usr.sbin/vmd/vm.c usr.sbin/vmd/vm.c index 046b2be8503..491ca2eae3f 100644 --- usr.sbin/vmd/vm.c +++ usr.sbin/vmd/vm.c @@ -371,6 +371,9 @@ start_vm(struct vmd_vm *vm, int fd) /* Execute the vcpu run loop(s) for this VM */ ret = run_vm(vm->vm_cdrom, vm->vm_disks, nicfds, >vm_params, ); + /* Ensure that any in-flight data is written back */ + virtio_shutdown(vm); + return (ret); } -- 2.18.0 -- Ori Bernstein

Re: vmd: add some NULL checks after {c,m}alloc()

2018-09-12 Thread Ori Bernstein
On Wed, 12 Sep 2018 15:36:32 +0800 Michael Mikonos wrote: > On Wed, Sep 12, 2018 at 12:13:35AM -0700, Ori Bernstein wrote: > > On Tue, 11 Sep 2018 23:29:53 -0700, Ori Bernstein > > wrote: > > > > > static ssize_t > > > @@ -362,8 +377,9 @@ qc2_clo

Re: vmd: add some NULL checks after {c,m}alloc()

2018-09-12 Thread Ori Bernstein
On Tue, 11 Sep 2018 23:29:53 -0700, Ori Bernstein wrote: > static ssize_t > @@ -362,8 +377,9 @@ qc2_close(void *p) > struct qcdisk *disk; > > disk = p; > - pwrite(disk->fd, disk->l1, disk->l1sz, disk->l1off); > - close(

Re: vmd: add some NULL checks after {c,m}alloc()

2018-09-12 Thread Ori Bernstein
On Wed, 12 Sep 2018 12:04:21 +0800, Michael Mikonos wrote: > On Tue, Sep 11, 2018 at 11:25:52AM -0700, Ori Bernstein wrote: > > On Tue, 11 Sep 2018 15:36:49 +0800 > > Michael Mikonos wrote: > > > > > Hello, > > > > > > Sometimes vmd doesn't se

Re: vmd: add some NULL checks after {c,m}alloc()

2018-09-11 Thread Ori Bernstein
-r1.1 vioraw.c > --- vioraw.c 25 Aug 2018 04:16:09 - 1.1 > +++ vioraw.c 11 Sep 2018 07:29:10 - > @@ -62,6 +62,8 @@ virtio_init_raw(struct virtio_backing *f > return -1; > > fdp = malloc(sizeof(int)); > + if (fdp == NULL) > + return -1; > *fdp = fd; > file->p = fdp; > file->pread = raw_pread; > -- Ori Bernstein

Re: vmd fail fast on unknown disk format

2018-09-10 Thread Ori Bernstein
nk I changed that in my (WIP) cluster reuse change, but if you're touching the code it might as well go in here. -- Ori Bernstein

Re: [PATCH] qcow2 disk format

2018-08-31 Thread Ori Bernstein
cribble-images + +.include diff --git regress/usr.sbin/vmd/diskfmt/vioscribble.c regress/usr.sbin/vmd/diskfmt/vioscribble.c new file mode 100644 index 000..3821c3b277b --- /dev/null +++ regress/usr.sbin/vmd/diskfmt/vioscribble.c @@ -0,0 +1,165 @@ +/* $OpenBSD: $ */ + +/* + * Copyright

Re: [PATCH] qcow2 disk format

2018-08-31 Thread Ori Bernstein
On Wed, 15 Aug 2018 23:02:16 -0700, Ori Bernstein wrote: > Updated style from feedback from off-list. Also added checks and > erroring for incompatible extensions. One more update. This revision adds explicit definitions of the disk format, and adds regress tests for parsing it. The

Re: [PATCH] Pluggable disk formats for vmd (qcow2 preparation)

2018-08-24 Thread Ori Bernstein
On Tue, 21 Aug 2018 23:03:36 -0700, Carlos Cardenas wrote: > On Sun, Aug 19, 2018 at 11:46:12PM -0700, Ori Bernstein wrote: > > One more minor update to this patch: > > > > - Remove unused enum > > - Remove unused function prototype > > -

Re: [patch] switchd(8) on sparc64: panic: trap type 0x34

2018-08-20 Thread Ori Bernstein
oxm_value itself is not at the start of the packet, and is not aligned within the ofp_ox_match. I'm not familiar enough with the open flowz to know if ofp_ox_match is guaranteed to start at a 4-byte alignment (which would push oxm_value out to an 8 byte alignment), but I suspect that's not the case. -- Ori Bernstein

Re: [PATCH] qcow2 disk format

2018-08-20 Thread Ori Bernstein
On Sun, 12 Aug 2018 22:51:24 -0700, Ori Bernstein wrote: > This patch adds preliminary support for creating qcow2 disk images. It gives the 'vmctl create' command an option '-f', which can be given arguments of either 'raw' (defualt) or 'qcow2', and it creates a disk of the appropriate for

Re: [PATCH] qcow2 disk format

2018-08-20 Thread Ori Bernstein
On Sun, 12 Aug 2018 22:51:24 -0700, Ori Bernstein wrote: > On Sun, 5 Aug 2018 00:52:32 -0700, Ori Bernstein wrote: > > And, now something that actually appears to work. You can create a > disk on OpenBSD using qemu: > > qemu-img create foo.qc2 16G > >

Re: [PATCH] Pluggable disk formats for vmd (qcow2 preparation)

2018-08-20 Thread Ori Bernstein
index 000..d377546de67 --- /dev/null +++ usr.sbin/vmd/vioraw.c @@ -0,0 +1,73 @@ +/* $OpenBSD: $ */ +/* + * Copyright (c) 2018 Ori Bernstein + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided

Re: [PATCH] qcow2 disk format

2018-08-16 Thread Ori Bernstein
mode 100644 index 000..f951fcbd99a --- /dev/null +++ usr.sbin/vmd/vioqcow2.c @@ -0,0 +1,546 @@ +/* $OpenBSD: $ */ + +/* + * Copyright (c) 2018 Ori Bernstein + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby

Re: [PATCH] Pluggable disk formats for vmd (qcow2 preparation)

2018-08-15 Thread Ori Bernstein
index 000..409974003f8 --- /dev/null +++ usr.sbin/vmd/vioraw.c @@ -0,0 +1,68 @@ +/* $OpenBSD: $ */ +/* + * Copyright (c) 2018 Ori Bernstein + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided

Re: [PATCH] qcow2 disk format

2018-08-12 Thread Ori Bernstein
On Sun, 5 Aug 2018 00:52:32 -0700, Ori Bernstein wrote: > This change introduces a 'struct virtio_backing' which makes the > disk i/o pluggable, providing 'backing->{pread,pwrite}' calls that > can be replaced by different disk i/o drivers. > > This is necessary preparatio

Re: [PATCH] Pluggable disk formats for vmd (qcow2 preparation)

2018-08-05 Thread Ori Bernstein
/null +++ usr.sbin/vmd/vioqcow2.c @@ -0,0 +1,612 @@ +/* $OpenBSD: $ */ + +/* + * Copyright (c) 2018 Ori Bernstein + * + * 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

[PATCH] Pluggable disk formats for vmd (qcow2 preparation)

2018-08-05 Thread Ori Bernstein
off_t offset; - int fd; int error; }; @@ -261,6 +275,9 @@ void viornd_update_qs(void); void viornd_update_qa(void); int viornd_notifyq(void); +int virtio_init_raw(struct virtio_backing *dev, off_t *sz, int fd); +int virtio_init_qcow2(struct virtio_backing *dev, off_t *sz, int fd); + int virtio_blk_io(int, uint16_t, uint32_t *, uint8_t *, void *, uint8_t); int vioblk_dump(int); int vioblk_restore(int, struct vm_create_params *, int *); -- Ori Bernstein

Re: patterns.c question or possible bug

2018-01-29 Thread Ori Bernstein
^^^^^ matches.sm_match[0] = "the quick the brown the fox" matches.sm_match[1] = "qu" matches.sm_match[2] = "the" The choice to capture implicitly, I think, is confusing, but the behavior seems to me to be correct. -- Ori Bernstein

Re: Remove commented out pledge in tsort

2017-11-13 Thread Ori Bernstein
ne, > or activate it instead. > > Dust is not yet settled. > In this specific case, the line is already activated. It's just duplicated in a comment one line before the pledge gets called. -- Ori Bernstein

Re: Httpd support for internal redirects.

2017-10-21 Thread Ori Bernstein
well, and based on the contents of the cited thread, it seemed like something that might be accepted if implemented. It was easy to implement, so I added it and sent a patch. If it's not a desirable feature for httpd, no problem. -- Ori Bernstein

Re: ksh: skip long history lines

2017-10-18 Thread Ori Bernstein
gt; } > - *p = '\0'; > + *nl = '\0'; > s->line = line_co; > s->cmd_offset = line_co; > strunvis(line, encoded); > histsave(line_co, line, 0); > + line_co++; > } > > history_write(); > > -- > jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE > -- Ori Bernstein <o...@eigenstate.org>

Re: Httpd support for internal redirects.

2017-10-18 Thread Ori Bernstein
Pinging this patch. On Tue, 10 Oct 2017 21:31:20 -0700 Ori Bernstein <o...@eigenstate.org> wrote: > My website generator is a little stupid at times. It generates > files with .html suffixes, but urls without them. > > I worked around this with some redirects, but it never

Re: ksh: skip long history lines

2017-10-18 Thread Ori Bernstein
} while (p != NULL && strchr(p, '\n') == NULL); > + > + continue; > } > - *p = '\0'; > + *nl = '\0'; > s->line = line_co; > s->cmd_offset = line_co; > strunvis(line, encoded); > histsave(line_co, line, 0); > + line_co++; > } > > history_write(); > > -- > jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE > -- Ori Bernstein <o...@eigenstate.org>

Httpd support for internal redirects.

2017-10-10 Thread Ori Bernstein
My website generator is a little stupid at times. It generates files with .html suffixes, but urls without them. I worked around this with some redirects, but it never felt quite right doing an extra round trip. Therefore, I added internal redirects, processing the rewrite before responding to an

Awk: Store program name before printing it.

2017-10-08 Thread Ori Bernstein
Just move the assignment up a bit. diff --git usr.bin/awk/main.c usr.bin/awk/main.c index 82996bc6f71..ebff17d240a 100644 --- usr.bin/awk/main.c +++ usr.bin/awk/main.c @@ -64,13 +64,13 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); setlocale(LC_NUMERIC,

Re: Exec pledges

2017-10-08 Thread Ori Bernstein
And pax, because I can diff --git bin/pax/ar_io.c bin/pax/ar_io.c index 40a6492405e..ce53a9ae51b 100644 --- bin/pax/ar_io.c +++ bin/pax/ar_io.c @@ -1281,6 +1281,11 @@ ar_start_gzip(int fd, const char *path, int wr) /* System compressors are more likely to use

Re: Exec pledges

2017-10-08 Thread Ori Bernstein
Slowcgi. Because if someone could fool it into running the wrong binary, the outcome may be suboptimal. diff --git usr.sbin/slowcgi/slowcgi.8 usr.sbin/slowcgi/slowcgi.8 index d3ab4030bed..f8f07630204 100644 --- usr.sbin/slowcgi/slowcgi.8 +++ usr.sbin/slowcgi/slowcgi.8 @@ -24,6

Re: Exec pledges

2017-10-08 Thread Ori Bernstein
-Werror + +.include diff --git usr.bin/pledge/pledge.1 usr.bin/pledge/pledge.1 new file mode 100644 index 000..e049277fdff --- /dev/null +++ usr.bin/pledge/pledge.1 @@ -0,0 +1,44 @@ +.\" $OpenBSD$ +.\" +.\"Copyright (c) 2017 Ori Bernstein <o...@eigenstate.org>

Exec pledges

2017-10-08 Thread Ori Bernstein
I wrote some patches to allow pledging across execs. Currently, the exec pledge passes down the process tree. The initial version simply inherited the current pledge when execing with the `pledge("rexec")` promise, but after discussing with Theo at EuroBSD, a better design was suggested. Because

Re: llvm - xor return pointers

2017-08-15 Thread Ori Bernstein
On Sat, 22 Jul 2017 02:25:29 -0400 Todd Mortimer <t...@opennet.ca> wrote: > xor [rsp], rsp > > at the start of each function, and before every RET. Wouldn't this break with alloca() or C99 VLAs? %rbp may work better, if the frame pointer is retained. -- Ori Bernstein <o...@eigenstate.org>