filters: Fix .trim with FUA
commit4aae4a83e14b81149bb2c82c1acaea6c35f62735
authorEric Blake <eblake@redhat.com>
Tue, 3 Sep 2019 01:12:45 +0000 (2 20:12 -0500)
committerEric Blake <eblake@redhat.com>
Tue, 3 Sep 2019 01:15:58 +0000 (2 20:15 -0500)
treefba7e25e911cae826f27cbb8e01a372f547f1630
parenta3ed80020f335ce3fbddab2b30ae665b63af2f18
filters: Fix .trim with FUA

It is very unusual for a client to request FUA on a trim (the main use
for FUA is to ensure disk changes have settled; but since trim is
advisory, there is no guarantee as to WHAT contents are being
settled).  Still, the spec allows it, so we should support it.

Unfortunately, the rarity of the combination means we've missed that
we have a broken implementation since v1.2:

$ ./nbdkit -U - sh script \
  --run 'nbdsh --connect nbd+unix:///?socket=$unixsocket
     -c "h.trim(1024,1024,nbd.CMD_FLAG_FUA)"'
$ ./nbdkit -U - --filter=offset sh script \
  --run 'nbdsh --connect nbd+unix:///?socket=$unixsocket
     -c "h.trim(1024,1024,nbd.CMD_FLAG_FUA)"'
nbdkit: filters.c:647: filter_trim: Assertion `flags == 0' failed.
Traceback (most recent call last):
...
nbd.Error: nbd_trim: trim: command failed: Transport endpoint is not connected (ENOTCONN)

The breakage was only present for filters up to 1.14, but more
recently copied over to plugins as well.

Fixes: dcf87173
Fixes: 11f79789
Signed-off-by: Eric Blake <eblake@redhat.com>
server/backend.c