platform/upstream/nbd.git
7 years agoMerge branch 'extension-structured-reply' into extension-blockstatus
Eric Blake [Fri, 27 Oct 2017 07:19:01 +0000 (09:19 +0200)]
Merge branch 'extension-structured-reply' into extension-blockstatus

7 years agostructured-reply: Tweak some protocol requirements
Eric Blake [Mon, 16 Oct 2017 14:34:37 +0000 (09:34 -0500)]
structured-reply: Tweak some protocol requirements

Several tweaks noticed while implementing structured reply for qemu:
- Document that errors are possible for NBD_OPT_STRUCTURED_REPLY, and
that non-zero size is an error
- Reformat the paragraph on NBD_CMD_FLAG_DF
- Mention what a client should do if a server sends an unexpected
structured reply
- Document that structured NBD_CMD_READ replies are absolute offsets,
rather than relative to the request offset

Signed-off-by: Eric Blake <eblake@redhat.com>
7 years agoMerge branch 'master' into extension-structured-reply
Eric Blake [Thu, 26 Oct 2017 06:13:49 +0000 (08:13 +0200)]
Merge branch 'master' into extension-structured-reply

7 years agoRemove symlinks when they're not needed
Wouter Verhelst [Tue, 24 Oct 2017 16:06:26 +0000 (18:06 +0200)]
Remove symlinks when they're not needed

We create symlinks to the toplevel source files so we don't have to copy
them, but it does mean we leave some cruft in this directory upon "make
clean".

Fix by just adding them to CLEANFILES

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoImprove badges a bit
Wouter Verhelst [Tue, 24 Oct 2017 11:53:06 +0000 (13:53 +0200)]
Improve badges a bit

- Add badge for Travis (yes, it's failing currently)
- Make them all be in markdown format, rather than doing so only for some of them

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoOne more
Wouter Verhelst [Tue, 24 Oct 2017 11:39:49 +0000 (13:39 +0200)]
One more

Since the test suite doesn't get compiled by default, we forgot about
this one. Fix.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoRemove unused variables
Wouter Verhelst [Tue, 24 Oct 2017 11:24:06 +0000 (13:24 +0200)]
Remove unused variables

gcc -Wall -Werror failed due to a number of unused variables. Remove.

In one case, we really should have been checking that variable, but
didn't. Since after the check there isn't much we can do anymore, drop
the variable and its assignment, and replace it by an if() { error
handling} construct instead.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMore systemd fixes
Wouter Verhelst [Tue, 24 Oct 2017 11:17:58 +0000 (13:17 +0200)]
More systemd fixes

We need Before=remote-fs-pre.target, as explained in systemd/3627.

7 years agodocs: Clarify that some options should be send-once
Eric Blake [Wed, 18 Oct 2017 20:11:37 +0000 (15:11 -0500)]
docs: Clarify that some options should be send-once

Some options, like NBD_OPT_STARTTLS or the experimental
NBD_OPT_STRUCTURED_REPLY, only need to be sent once, so
clients should not expect any particular server behavior
if they mistakenly send the option again.  Document this
once up-front, rather than repeating it for every option
that falls in this category.

Signed-off-by: Eric Blake <eblake@redhat.com>
7 years agodocs: Clarify options that should not have data
Eric Blake [Wed, 18 Oct 2017 19:40:12 +0000 (14:40 -0500)]
docs: Clarify options that should not have data

The spec indirectly stated that NBD_OPT_LIST should be sent without
data (by virtue of the fact that NBD_REP_ERR_INVALID mentioned
non-zero data length as a reason for failure), but making zero-length
options explicit in the documentation of each option is nicer.
As an exception, make it clear that NBD_OPT_ABORT should succeed at
ending the connection rather than being ignored with an error due
to non-zero length, even though well-behaved clients won't send such
length.

This mirrors existing practice in many implementations, and is done
in a way that can be copied to NBD_OPT_STRUCTURED_REPLY and other
extension options that do not require data.

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoFix HAVE_NETLINK guards
Wouter Verhelst [Thu, 14 Sep 2017 11:06:20 +0000 (13:06 +0200)]
Fix HAVE_NETLINK guards

HAVE_NETLINK is always defined, it just is defined to 1 or 0 depending
on whether libnl3 was available.

Fix the guards so they work when libnl3 isn't there, too.

7 years agonbd-client: add the ability to use the netlink interface
Josef Bacik [Tue, 28 Feb 2017 16:43:49 +0000 (11:43 -0500)]
nbd-client: add the ability to use the netlink interface

This adds the ability to setup and tear down an nbd device with the
netlink interface.

Signed-off-by: Josef Bacik <jbacik@fb.com>
(cherry picked from commit c72b53d7d8280ccf27e6316992f2022eb78223d7)
[wouter: update so the patch applies in the face of STARTTLS code]
Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoRemove outdated buildbot link
Wouter Verhelst [Thu, 14 Sep 2017 10:33:24 +0000 (12:33 +0200)]
Remove outdated buildbot link

7 years agoMove badges to a separate page, and add a repology.org badge
Wouter Verhelst [Wed, 13 Sep 2017 14:45:39 +0000 (16:45 +0200)]
Move badges to a separate page, and add a repology.org badge

7 years agoImprove --version and --help output nbd-3.16.2
Wouter Verhelst [Mon, 11 Sep 2017 23:14:20 +0000 (01:14 +0200)]
Improve --version and --help output

- nbd-client: ensure --version exists, add PACKAGE_BUGREPORT to output, add
  program name to output
- nbd-server: add PACKAGE_BUGREPORT to output

7 years agoUpdate list address to reflect the name that was actually assigned
Wouter Verhelst [Mon, 11 Sep 2017 22:46:15 +0000 (00:46 +0200)]
Update list address to reflect the name that was actually assigned

7 years agoIgnore the minimal (i.e., non-TLS-enabled) version of nbd-client
Wouter Verhelst [Sat, 9 Sep 2017 12:04:53 +0000 (14:04 +0200)]
Ignore the minimal (i.e., non-TLS-enabled) version of nbd-client

7 years agoDon't forget to actually add the configure check
Wouter Verhelst [Sat, 9 Sep 2017 12:01:25 +0000 (14:01 +0200)]
Don't forget to actually add the configure check

Fixes: 866c2d5752901e8f47c86beb64fea05acf11a825

7 years agoEnsure that <sys/uio.h> is included when it's needed
Wouter Verhelst [Sat, 9 Sep 2017 12:00:20 +0000 (14:00 +0200)]
Ensure that <sys/uio.h> is included when it's needed

7 years agoUpdate bugreport address to point to mailinglist (at new address), rather than me
Wouter Verhelst [Sat, 9 Sep 2017 11:59:09 +0000 (13:59 +0200)]
Update bugreport address to point to mailinglist (at new address), rather than me

7 years agoWe can't do anything unless and until the network is up and running
Wouter Verhelst [Sun, 16 Jul 2017 10:06:31 +0000 (12:06 +0200)]
We can't do anything unless and until the network is up and running

7 years agoEnsure we get shut down properly, too
Wouter Verhelst [Sun, 16 Jul 2017 09:40:38 +0000 (11:40 +0200)]
Ensure we get shut down properly, too

Now that we have DefaultDependencies=no, we don't have the default
Conflicts=shutdown.target anymore, which means we won't be stopped at
shutdown time.

Add an explicit dependency for that.

7 years agoAdd dependencies for partitions, too
Wouter Verhelst [Sun, 16 Jul 2017 09:33:08 +0000 (11:33 +0200)]
Add dependencies for partitions, too

If a device is partitioned, we need to have that depend on the device,
too.

7 years agoAdd DefaultDependencies=no to nbd@ systemd service
Wouter Verhelst [Sun, 16 Jul 2017 08:36:51 +0000 (10:36 +0200)]
Add DefaultDependencies=no to nbd@ systemd service

This service is involved in early boot, so shouldn't have the default
dependencies...

7 years agoRemove contraction
Wouter Verhelst [Sun, 16 Jul 2017 08:35:07 +0000 (10:35 +0200)]
Remove contraction

vim syntax highlighting gets confused about the extra apostrophe, so
rephrase this sentence so it isn't needed.

7 years agoDon't define _BSD_SOURCE unconditionally
Wouter Verhelst [Sun, 16 Jul 2017 08:31:56 +0000 (10:31 +0200)]
Don't define _BSD_SOURCE unconditionally

On older versions of glibc, _BSD_SOURCE was needed to get at the DT_*
macros. On glibc 2.19 and above, however, this is no longer needed; and
on FreeBSD it is actually detrimental since it removes a few symbols
which we do need.

Add a configure.ac check for whether we need _BSD_SOURCE to be set in
order for the DT_* macros to be defined, and only set it in that case.

7 years agoDestroy the diff file upon client disconnect
Wouter Verhelst [Tue, 20 Jun 2017 21:12:57 +0000 (23:12 +0200)]
Destroy the diff file upon client disconnect

When a client disconnects, we need to ensure that the diff file is gone.
Currently, we don't do that, because apparently we forgot.

Fixes #52 on github.

7 years agoDon't print anything on travis, at all...
Wouter Verhelst [Wed, 14 Jun 2017 15:56:45 +0000 (17:56 +0200)]
Don't print anything on travis, at all...

7 years agoReduce output even further
Wouter Verhelst [Wed, 14 Jun 2017 15:25:09 +0000 (17:25 +0200)]
Reduce output even further

7 years agoDon't dist these symlinks
Wouter Verhelst [Wed, 14 Jun 2017 15:23:41 +0000 (17:23 +0200)]
Don't dist these symlinks

7 years agoEnsure that syslog doesn't break again nbd-3.16.1
Wouter Verhelst [Fri, 26 May 2017 15:44:10 +0000 (17:44 +0200)]
Ensure that syslog doesn't break again

"make distcheck" doesn't have --enable-syslog on by default. Since that
enables a few lines of code that we otherwise don't test, tell automake
to enable that by default for the distcheck build.

That way, we don't release with a broken build again :-)

7 years agoFix the LOG_* constants
Wouter Verhelst [Fri, 26 May 2017 15:38:21 +0000 (17:38 +0200)]
Fix the LOG_* constants

There is no LOG_WARN, there is only a LOG_WARNING. d'oh.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoDocument the waitfile option nbd-3.16
Wouter Verhelst [Fri, 26 May 2017 07:08:39 +0000 (09:08 +0200)]
Document the waitfile option

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoEnsure that i is not used uninitialized
Wouter Verhelst [Fri, 26 May 2017 06:42:20 +0000 (08:42 +0200)]
Ensure that i is not used uninitialized

Currently, multifile and treefile are mutually exclusive (so this
message cannot be produced in that case), and the only effect this will
have is that the log message will contain a garbage integer value, but
it's not nice.

Ensure i is initialized to 0, so that at least we say that there are no
files in use, in that case.

Coverity CID#1264432

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoRemove extraneous LOG_INFO option
Wouter Verhelst [Fri, 26 May 2017 06:39:32 +0000 (08:39 +0200)]
Remove extraneous LOG_INFO option

not needed for err_nonfatal

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoHandle failure of open() call
Wouter Verhelst [Fri, 26 May 2017 06:30:48 +0000 (08:30 +0200)]
Handle failure of open() call

If opening the file for the partition table fails, we can't do much
anyway. However, it makes sense to inform the user of that fact, so that
they won't be confused.

Coverity CID#1298132

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years ago... and ensure this buffer is null-terminated, too
Wouter Verhelst [Fri, 26 May 2017 06:28:31 +0000 (08:28 +0200)]
... and ensure this buffer is null-terminated, too

Coverity CID#1345811

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoEnsure the filename is null-terminated
Wouter Verhelst [Fri, 26 May 2017 06:26:47 +0000 (08:26 +0200)]
Ensure the filename is null-terminated

Coverity CID#1352242

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoDon't overflow s1
Wouter Verhelst [Fri, 26 May 2017 06:24:29 +0000 (08:24 +0200)]
Don't overflow s1

s1 is a fixed-size buffer of 150 bytes. Even though that should be
plenty for any kind of error message we might want to produce, it still
makes sense to double-check that we do not overflow this buffer.

Coverity CID#1352244

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoCheck that the correct number of bytes was read
Wouter Verhelst [Fri, 26 May 2017 06:17:38 +0000 (08:17 +0200)]
Check that the correct number of bytes was read

It's highly unlikely that we get anything but EOF or sizeof(int), but
not checking that is improper.

Coverity CID#1437702

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMove the close() call back to where it belongs
Wouter Verhelst [Fri, 26 May 2017 06:09:52 +0000 (08:09 +0200)]
Move the close() call back to where it belongs

In trying to write a fix for CID#1437710, we missed the fact that the
close in the handle_modern_connection() call is necessary for more than
just the failure return of negotiate(). As a result, we now leak a
resource in some cases.

Revert the removal of the close() call, and do it in
handle_modern_connection() anyway.

Coverity CID#1437712

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoDon't deadlock
Wouter Verhelst [Thu, 25 May 2017 22:11:39 +0000 (00:11 +0200)]
Don't deadlock

When trying to commit our diff file in the new wait_file feature, if
something happened to the read or write that we didn't expect, we
currently deadlock. That's not nice.

Instead, log a message, unlock the rwlock, and then return from the
function.

Coverity CID#1437703

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoCode style: add missing space
Wouter Verhelst [Thu, 25 May 2017 22:06:24 +0000 (00:06 +0200)]
Code style: add missing space

7 years agoAdd missing return statement
Wouter Verhelst [Thu, 25 May 2017 22:05:55 +0000 (00:05 +0200)]
Add missing return statement

Coverity CID#1437704

Isn't strictly a problem, but it's nice to be correct.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoAdd missing free()
Wouter Verhelst [Thu, 25 May 2017 22:01:33 +0000 (00:01 +0200)]
Add missing free()

Coverity CID#1437706

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoAdd missing brackets
Wouter Verhelst [Thu, 25 May 2017 21:50:41 +0000 (23:50 +0200)]
Add missing brackets

We want to check whether the NBDC_DO_LIST flag is not set in opts; this
requires that we perform a logical not on the whole expression, rather
than just the first part of it.

Coverity CID#1437709

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoFix double close
Wouter Verhelst [Thu, 25 May 2017 21:43:53 +0000 (23:43 +0200)]
Fix double close

We had two code paths exiting the negotiate() function in error; one
which would close the network, and one which wouldn't.

This is not an ideal situation. Since closing the network socket is
something we'll always need to do anyway, it makes more sense to do it
in the negotiate function rather than in the calling function.

Coverity CID#1437710

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoFix double free
Wouter Verhelst [Thu, 25 May 2017 21:38:03 +0000 (23:38 +0200)]
Fix double free

Coverity CID#1437711

Signed-Off-By: Wouter Verhelst <w@uter.be>
7 years agoRevert command line additions
Wouter Verhelst [Thu, 25 May 2017 21:18:12 +0000 (23:18 +0200)]
Revert command line additions

We don't want to extend the command line in this way anymore, so revert
the -w option for now.

We may add another way to specify an export from the command line at
some point in the future, but not in this way anymore.

7 years agoReduce output, so that travis stops breaking
Wouter Verhelst [Thu, 25 May 2017 21:12:54 +0000 (23:12 +0200)]
Reduce output, so that travis stops breaking

7 years agoMerge branch 'master' of https://github.com/danielkucera/nbd
Wouter Verhelst [Thu, 25 May 2017 21:01:40 +0000 (23:01 +0200)]
Merge branch 'master' of https://github.com/danielkucera/nbd

7 years agoInstall GnuTLS for travis/osx
Wouter Verhelst [Sat, 13 May 2017 07:42:12 +0000 (09:42 +0200)]
Install GnuTLS for travis/osx

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoClarify that this isn't an option
Wouter Verhelst [Sat, 13 May 2017 07:35:10 +0000 (09:35 +0200)]
Clarify that this isn't an option

clang was complaining that there wasn't an else clause that assigned a
value to addrbits.

Since we should never get there, use assert_not_reached to declare that.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoDon't forget to initialize socket_closed
Wouter Verhelst [Sat, 13 May 2017 07:33:34 +0000 (09:33 +0200)]
Don't forget to initialize socket_closed

We added the socket_closed function, but forgot to initialize it. Fix.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoFix the used variable, here
Wouter Verhelst [Sat, 13 May 2017 07:31:55 +0000 (09:31 +0200)]
Fix the used variable, here

We were using an uninitialized variable. This resulted in undefined behaviour,
and as a result, aggressive optimizing away of that behaviour by clang.

As a result, the test suite was failing.

Fix by using the correct variable

Signed-Off-By: Wouter Verhelst <w@uter.be>
7 years agoUnbreak the cherry-pick
Wouter Verhelst [Sat, 13 May 2017 07:29:22 +0000 (09:29 +0200)]
Unbreak the cherry-pick

7 years agoFix the location of the nbd-server cflags modification
Wouter Verhelst [Tue, 21 Mar 2017 12:56:51 +0000 (12:56 +0000)]
Fix the location of the nbd-server cflags modification

The "if GNUTLS" conditional was nested inside an "if CLIENT"
conditional. That made sense for the client bits, but not for the server
bits.

Move those out into their rightful place.

7 years agoAdd missing "return true"
Wouter Verhelst [Thu, 11 May 2017 08:43:46 +0000 (10:43 +0200)]
Add missing "return true"

Spotted-By: Greg Menke <gregory.d.menke@nasa.gov>
7 years agoimplemented waiting for file
Daniel Kucera [Sun, 7 May 2017 08:19:09 +0000 (08:19 +0000)]
implemented waiting for file

If we expect an export file to appear and know its size, we can
temporarily save writes into diff file. When the file appears
we commit all writes into it and switch writes to export file.

This mode can be useful when live migrating VM between hypervisors:
We start mirroring writes from source HV to destination despite
the destination storage doesn't exist yet. Then we can start
copying the source storage (ZFS, LVM, ...) to destination and
when it appears on destination, cached writes are commited to it.

7 years agoMerge commit 'f673479c3b8a104cdd5c5561f3ae55c9dc486ecd'
Wouter Verhelst [Wed, 3 May 2017 22:04:51 +0000 (00:04 +0200)]
Merge commit 'f673479c3b8a104cdd5c5561f3ae55c9dc486ecd'

We'd rebase, but we've already (force-)pushed this, let's not overdo it.

hate mess.

7 years agoMerge branch 'extension-info'
Wouter Verhelst [Wed, 3 May 2017 22:03:36 +0000 (00:03 +0200)]
Merge branch 'extension-info'

For real this time, without losing a few commits that were still on top

7 years agoHandle socket errors better
Wouter Verhelst [Wed, 3 May 2017 21:46:04 +0000 (23:46 +0200)]
Handle socket errors better

Previously, when reading from or writing to a socket failed, we would
handle errors by simply producing an error message and exiting the
program. While that works, it does not allow for the postrun command,
specified in the configuration file, to run.

Fix this by adding a return value to readit/writeit-like functions, and
handling nonzero return values in the socket_read()/socket_write()
function, which then call a cleanup function that does the same exit
(but which will allow for doing the necessary postrun stuff).

Fixes #47 on Github

7 years agoMerge branch 'extension-info'
Wouter Verhelst [Sun, 30 Apr 2017 09:24:59 +0000 (11:24 +0200)]
Merge branch 'extension-info'

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoDon't forget to read the length of the request
Wouter Verhelst [Sun, 30 Apr 2017 09:15:53 +0000 (11:15 +0200)]
Don't forget to read the length of the request

We read out the NBD_OPT_INFO packet's length as the length of the name
(which follows it immediately), rather than the length of the packet.

Add a second read to fix that.

While at it, add a sanity check for the length of both, and send back an
NBD_REP_ERR_INVALID if it fails.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoRegenerate certificate
Wouter Verhelst [Mon, 24 Apr 2017 16:39:43 +0000 (18:39 +0200)]
Regenerate certificate

Although the configuration file specified a validity of 3650 days (i.e.,
almost 10 years), the actual certificate in this directory was generated
with a certificate validity of 1 year. It expired on april 19th, 2017
(i.e., 5 days ago), causing the test suite to fail from now on.

Fix by regenerating the certificate (not the keys) of the certificate
with the actual configuration in this directory.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoFollow the spec a bit more.
Wouter Verhelst [Sat, 22 Apr 2017 22:33:05 +0000 (00:33 +0200)]
Follow the spec a bit more.

When a TLS-only export is used, we should send TLS_REQD, not UNKNOWN. We
are allowed, however, to also send TLS_REQD for unknown exports (but
we were not going to do that).

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoImplement NBD_OPT_GO in the client
Wouter Verhelst [Sat, 22 Apr 2017 22:12:40 +0000 (00:12 +0200)]
Implement NBD_OPT_GO in the client

We don't (yet) use any information apart from NBD_INFO_EXPORT, and we
don't call NBD_OPT_INFO, either, since we need neither; however, write
it in a manner that makes it possible and easy to add said functionality
in the future.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoRemove warning
Wouter Verhelst [Sat, 22 Apr 2017 22:11:05 +0000 (00:11 +0200)]
Remove warning

%llu is nonstandard and not guaranteed to match a uint64_t variable.
PRIu64 is.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoAllow for not passing any data
Wouter Verhelst [Sat, 22 Apr 2017 22:10:01 +0000 (00:10 +0200)]
Allow for not passing any data

It's sometimes useful to call this function so that a header is sent
out, without actually sending the data (yet), as we already allow in the
server.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMerge branch 'master' into extension-info
Wouter Verhelst [Fri, 21 Apr 2017 07:01:19 +0000 (09:01 +0200)]
Merge branch 'master' into extension-info

7 years agoPrint the description properly
Wouter Verhelst [Tue, 18 Apr 2017 13:36:10 +0000 (15:36 +0200)]
Print the description properly

Previously, when a server sent a description along with the name, we
would try to parse part of the description as the magic number of the
next reply, and fail (d'oh).

Fix parsing of the NBD_REP_SERVER reply by properly parsing and
displaying the contents of the message.

7 years agoFix typo
Wouter Verhelst [Tue, 18 Apr 2017 09:38:40 +0000 (11:38 +0200)]
Fix typo

7 years agoSwap options and option name
Wouter Verhelst [Fri, 14 Apr 2017 12:46:37 +0000 (14:46 +0200)]
Swap options and option name

When trying to reply to a client with certain information, it's useful
if we don't need to read the whole reply but can handle it by reading
one option, handling it, reading the next one, etc etc. This requires
that the server is told which export to deal with before getting the
option names, however.

As specified, that isn't the case, so this would require the server to
read in the whole request before it can start processing it.

Swap options around to make handling the INFO/GO messages easier to do.

Signed-off-by: Wouter Verhelst <w@uter.be>
Acked-By: Eric Blake <eblake@redhat.com>
7 years agoMerge branch 'master' into extension-info
Wouter Verhelst [Fri, 14 Apr 2017 20:30:39 +0000 (22:30 +0200)]
Merge branch 'master' into extension-info

7 years agoStop open-coding request sending
Wouter Verhelst [Fri, 14 Apr 2017 20:02:06 +0000 (22:02 +0200)]
Stop open-coding request sending

We have a "send_reply" function in the server which makes it easier to
send a negotiation reply to the client. So why don't we implement the
same thing for the client, too?

Add it, so that sending a request should become easier.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMove writeit to cliserv
Wouter Verhelst [Fri, 14 Apr 2017 20:00:25 +0000 (22:00 +0200)]
Move writeit to cliserv

A function to write until success is useful regardless of whether we're
in the client or in the server.

As such, move it to cliserv so we can use it from both.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoImplement NBD_OPT_INFO and NBD_OPT_GO
Wouter Verhelst [Fri, 14 Apr 2017 19:44:30 +0000 (21:44 +0200)]
Implement NBD_OPT_INFO and NBD_OPT_GO

7 years agoMove more initialisation into commit_client
Wouter Verhelst [Fri, 14 Apr 2017 19:41:52 +0000 (21:41 +0200)]
Move more initialisation into commit_client

All callers were doing the same preparatory initialisation. That's a bit
silly; better to move it into the function instead.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoAllow for sending the data outside of the send_reply() function
Wouter Verhelst [Fri, 14 Apr 2017 19:39:57 +0000 (21:39 +0200)]
Allow for sending the data outside of the send_reply() function

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoTurn various fatal errors into return values
Wouter Verhelst [Fri, 14 Apr 2017 15:32:53 +0000 (17:32 +0200)]
Turn various fatal errors into return values

Previously, we would err() out of a function whenever things went south.
That's fine for NBD_OPT_EXPORT_NAME, but not for NBD_OPT_GO, which needs
to deal with things differently.

Turn each and every one of those err() calls into an err_nonfatal, and
change the return value of the function.

While at it, harmonize the function return signatures into booleans
everywhere.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoDon't forget to return a value from commit_client
Wouter Verhelst [Fri, 14 Apr 2017 15:31:59 +0000 (17:31 +0200)]
Don't forget to return a value from commit_client

Upon exiting the function with successful results, we shouldn't forget
to actually return true...

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoHandle commit_client failures
Wouter Verhelst [Fri, 14 Apr 2017 15:28:17 +0000 (17:28 +0200)]
Handle commit_client failures

The commit_client() function is set up to return false when things fail.
We should actually handle that situation, then, rather than ignoring it.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMove send_export_info up
Wouter Verhelst [Fri, 14 Apr 2017 15:18:35 +0000 (17:18 +0200)]
Move send_export_info up

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMove copyonwrite_prepare up
Wouter Verhelst [Fri, 14 Apr 2017 15:17:55 +0000 (17:17 +0200)]
Move copyonwrite_prepare up

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMove setupexport up
Wouter Verhelst [Fri, 14 Apr 2017 15:17:04 +0000 (17:17 +0200)]
Move setupexport up

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMove do_run up
Wouter Verhelst [Fri, 14 Apr 2017 15:16:42 +0000 (17:16 +0200)]
Move do_run up

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoMove set_peername up
Wouter Verhelst [Fri, 14 Apr 2017 15:13:40 +0000 (17:13 +0200)]
Move set_peername up

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoCentralize what needs to be done before exporting
Wouter Verhelst [Fri, 14 Apr 2017 15:01:51 +0000 (17:01 +0200)]
Centralize what needs to be done before exporting

Previously, we ran everything that needed to be done before exporting
for a particular client (e.g., checking access rights, opening files,
running scripts, ...) in various locations all over the place. This
works, but it assumes NBD_OPT_EXPORT_NAME usage only, because it sends
the sizes and flags etc unconditionally after we've left the
negotiation() function.

This works for NBD_OPT_EXPORT_NAME, but not for NBD_OPT_GO, which needs
to send a negotiation acknowledgement before formally closing the
negotiation phase. As such, rearrange things so that they're all in one
function, commit_client, which does all the setup, and call that
function before returning from the negotiation() function.

This new function wants to call a number of other functions that need to
be moved up in the nbd-server file; but we'll do that after this commit
so as to not muddle the diff with irrelevant fluff. Add forward
declarations to them for now.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoAdd missing backticks
Wouter Verhelst [Fri, 14 Apr 2017 14:22:28 +0000 (16:22 +0200)]
Add missing backticks

7 years agoMerge branch 'master' into extension-info
Wouter Verhelst [Fri, 14 Apr 2017 14:20:18 +0000 (16:20 +0200)]
Merge branch 'master' into extension-info

7 years agoRemove incorrect statements
Wouter Verhelst [Fri, 17 Mar 2017 08:19:35 +0000 (09:19 +0100)]
Remove incorrect statements

STARTTLS has been implemented by the reference implementation now, too.

7 years agodoc: Fix some minor issues
Eric Blake [Thu, 16 Feb 2017 23:04:52 +0000 (17:04 -0600)]
doc: Fix some minor issues

Fix a grammar nit, and resolve a conflict between two extensions
picking the same command number (BLOCK_STATUS is the older proposal,
so it keeps command 7, RESIZE gets command 8).

Signed-off-by: Eric Blake <eblake@redhat.com>
[added in missing typo fix]
Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agobuild: Fix build with older gcc
Eric Blake [Mon, 19 Dec 2016 22:15:50 +0000 (16:15 -0600)]
build: Fix build with older gcc

gcc 4.4.7 (hello RHEL 6) complains about redefinition of typedefs,
as in:

gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DSYSCONFDIR='"/usr/local/etc"'  -g -O2  -g -O2 -MT nbd_client-buffer.o -MD -MP -MF .deps/nbd_client-buffer.Tpo -c -o nbd_client-buffer.o `test -f 'buffer.c' || echo './'`buffer.c
buffer.c:39: error: redefinition of typedef ‘buffer_t’
buffer.h:31: note: previous declaration of ‘buffer_t’ was here

The .c file only has to declare the struct being typedef'd, not
repeat the typedef declaration.

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoUse AM_CONDITIONAL rather than AC_SUBST nbd-3.15.2
Wouter Verhelst [Mon, 23 Jan 2017 10:08:29 +0000 (11:08 +0100)]
Use AM_CONDITIONAL rather than AC_SUBST

AC_SUBST'ing the nbd-client program worked when we didn't need to
compile the client twice. Now that we do, this makes us try to compile
the minimal (i.e., non-TLS) client even if we're on a system where the
client can't be compiled. This is obviously wrong.

Fix it by using AM_CONDITIONAL a second time, and nesting the whole
GnuTLS conditional below that.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoDon't seek() in files without holding a lock.
Wouter Verhelst [Mon, 23 Jan 2017 10:01:35 +0000 (11:01 +0100)]
Don't seek() in files without holding a lock.

The introduction of multithread handling of requests failed to consider
what happens with copyonwrite enabled. We would seek, then read (or
write), a file.

If we have copyonwrite enabled, this fails badly in that two threads can
race against eachother for the current file pointer. Instead, we should
use pread() or pwrite() to read from offset without relying on the
current file offset, as explained in #43.

Remove the myseek() function to ensure we don't make use of it anymore,
and fix up all callers.

The only exception where we can still use lseek() safely is in the
open_treefile() function, since there we hold a mutex and hence we can't
race against other threads.

TODO: test whether this fixes the problem.

Signed-off-by: Wouter Verhelst <w@uter.be>
7 years agoAdd numbers for resize extension
Wouter Verhelst [Sun, 22 Jan 2017 11:41:59 +0000 (12:41 +0100)]
Add numbers for resize extension

7 years agoRename request in line with the kernel
Wouter Verhelst [Tue, 17 Jan 2017 10:23:14 +0000 (11:23 +0100)]
Rename request in line with the kernel

Closes #45

7 years agoNBD_REP_ERR_UNSUP not EINVAL for options
Alex Bligh [Thu, 12 Jan 2017 13:16:09 +0000 (13:16 +0000)]
NBD_REP_ERR_UNSUP not EINVAL for options

Signed-off-by: Alex Bligh <alex@alex.org.uk>
7 years agoMake returned default status context dependent
Alex Bligh [Thu, 12 Jan 2017 13:11:27 +0000 (13:11 +0000)]
Make returned default status context dependent

Signed-off-by: Alex Bligh <alex@alex.org.uk>
7 years agoRe-sort options in this man page
Wouter Verhelst [Tue, 20 Dec 2016 17:56:58 +0000 (18:56 +0100)]
Re-sort options in this man page

The options are supposed to be alphabetically ranked, but they weren't
anymore. Fix that.

Signed-off-by: Wouter Verhelst <w@uter.be>