1. 15 6月, 2017 1 次提交
    • E
      nbd: Fix regression on resiliency to port scan · 0c9390d9
      Eric Blake 提交于
      Back in qemu 2.5, qemu-nbd was immune to port probes (a transient
      server would not quit, regardless of how many probe connections
      came and went, until a connection actually negotiated).  But we
      broke that in commit ee7d7aab when removing the return value to
      nbd_client_new(), although that patch also introduced a bug causing
      an assertion failure on a client that fails negotiation.  We then
      made it worse during refactoring in commit 1a6245a5 (a segfault
      before we could even assert); the (masked) assertion was cleaned
      up in d3780c2d (still in 2.6), and just recently we finally fixed
      the segfault ("nbd: Fully intialize client in case of failed
      negotiation").  But that still means that ever since we added
      TLS support to qemu-nbd, we have been vulnerable to an ill-timed
      port-scan being able to cause a denial of service by taking down
      qemu-nbd before a real client has a chance to connect.
      
      Since negotiation is now handled asynchronously via coroutines,
      we no longer have a synchronous point of return by re-adding a
      return value to nbd_client_new().  So this patch instead wires
      things up to pass the negotiation status through the close_fn
      callback function.
      
      Simple test across two terminals:
      $ qemu-nbd -f raw -p 30001 file
      $ nmap 127.0.0.1 -p 30001 && \
        qemu-io -c 'r 0 512' -f raw nbd://localhost:30001
      
      Note that this patch does not change what constitutes successful
      negotiation (thus, a client must enter transmission phase before
      that client can be considered as a reason to terminate the server
      when the connection ends).  Perhaps we may want to tweak things
      in a later patch to also treat a client that uses NBD_OPT_ABORT
      as being a 'successful' negotiation (the client correctly talked
      the NBD protocol, and informed us it was not going to use our
      export after all), but that's a discussion for another day.
      
      Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1451614Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20170608222617.20376-1-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      0c9390d9
  2. 07 6月, 2017 2 次提交
  3. 09 5月, 2017 1 次提交
  4. 02 11月, 2016 7 次提交
    • E
      nbd: Implement NBD_CMD_WRITE_ZEROES on server · 1f4d6d18
      Eric Blake 提交于
      Upstream NBD protocol recently added the ability to efficiently
      write zeroes without having to send the zeroes over the wire,
      along with a flag to control whether the client wants to allow
      a hole.
      
      Note that when it comes to requiring full allocation, vs.
      permitting optimizations, the NBD spec intentionally picked a
      different sense for the flag; the rules in qemu are:
      MAY_UNMAP == 0: must write zeroes
      MAY_UNMAP == 1: may use holes if reads will see zeroes
      
      while in NBD, the rules are:
      FLAG_NO_HOLE == 1: must write zeroes
      FLAG_NO_HOLE == 0: may use holes if reads will see zeroes
      
      In all cases, the 'may use holes' scenario is optional (the
      server need not use a hole, and must not use a hole if
      subsequent reads would not see zeroes).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-16-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      1f4d6d18
    • E
      nbd: Improve server handling of shutdown requests · b6f5d3b5
      Eric Blake 提交于
      NBD commit 6d34500b clarified how clients and servers are supposed
      to behave before closing a connection. It added NBD_REP_ERR_SHUTDOWN
      (for the server to announce it is about to go away during option
      haggling, so the client should quit sending NBD_OPT_* other than
      NBD_OPT_ABORT) and ESHUTDOWN (for the server to announce it is about
      to go away during transmission, so the client should quit sending
      NBD_CMD_* other than NBD_CMD_DISC).  It also clarified that
      NBD_OPT_ABORT gets a reply, while NBD_CMD_DISC does not.
      
      This patch merely adds the missing reply to NBD_OPT_ABORT and teaches
      the client to recognize server errors.  Actually teaching the server
      to send NBD_REP_ERR_SHUTDOWN or ESHUTDOWN would require knowing that
      the server has been requested to shut down soon (maybe we could do
      that by installing a SIGINT handler in qemu-nbd, which transitions
      from RUNNING to a new state that waits for the client to react,
      rather than just out-right quitting - but that's a bigger task for
      another day).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-15-git-send-email-eblake@redhat.com>
      [Move dummy ESHUTDOWN to include/qemu/osdep.h. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b6f5d3b5
    • E
      nbd: Support shorter handshake · c203c59a
      Eric Blake 提交于
      The NBD Protocol allows the server and client to mutually agree
      on a shorter handshake (omit the 124 bytes of reserved 0), via
      the server advertising NBD_FLAG_NO_ZEROES and the client
      acknowledging with NBD_FLAG_C_NO_ZEROES (only possible in
      newstyle, whether or not it is fixed newstyle).  It doesn't
      shave much off the wire, but we might as well implement it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NAlex Bligh <alex@alex.org.uk>
      Message-Id: <1476469998-28592-13-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      c203c59a
    • E
      nbd: Share common option-sending code in client · c8a3a1b6
      Eric Blake 提交于
      Rather than open-coding each option request, it's easier to
      have common helper functions do the work.  That in turn requires
      having convenient packed types for handling option requests
      and replies.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-9-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      c8a3a1b6
    • E
      nbd: Rename struct nbd_request and nbd_reply · ed2dd912
      Eric Blake 提交于
      Our coding convention prefers CamelCase names, and we already
      have other existing structs with NBDFoo naming.  Let's be
      consistent, before later patches add even more structs.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-6-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ed2dd912
    • E
      nbd: Treat flags vs. command type as separate fields · b626b51a
      Eric Blake 提交于
      Current upstream NBD documents that requests have a 16-bit flags,
      followed by a 16-bit type integer; although older versions mentioned
      only a 32-bit field with masking to find flags.  Since the protocol
      is in network order (big-endian over the wire), the ABI is unchanged;
      but dealing with the flags as a separate field rather than masking
      will make it easier to add support for upcoming NBD extensions that
      increase the number of both flags and commands.
      
      Improve some comments in nbd.h based on the current upstream
      NBD protocol (https://github.com/yoe/nbd/blob/master/doc/proto.md),
      and touch some nearby code to keep checkpatch.pl happy.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-3-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b626b51a
    • E
      nbd: Add qemu-nbd -D for human-readable description · b1a75b33
      Eric Blake 提交于
      The NBD protocol allows servers to advertise a human-readable
      description alongside an export name during NBD_OPT_LIST.  Add
      an option to pass through the user's string to the NBD client.
      
      Doing this also makes it easier to test commit 200650d4, which
      is the client counterpart of receiving the description.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-2-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b1a75b33
  5. 06 9月, 2016 1 次提交
    • K
      nbd-server: Use a separate BlockBackend · cd7fca95
      Kevin Wolf 提交于
      The builtin NBD server uses its own BlockBackend now instead of reusing
      the monitor/guest device one.
      
      This means that it has its own writethrough setting now. The builtin
      NBD server always uses writeback caching now regardless of whether the
      guest device has WCE enabled. qemu-nbd respects the cache mode given on
      the command line.
      
      We still need to keep a reference to the monitor BB because we put an
      eject notifier on it, but we don't use it for any I/O.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      cd7fca95
  6. 04 8月, 2016 1 次提交
    • E
      nbd: Limit nbdflags to 16 bits · 7423f417
      Eric Blake 提交于
      Rather than asserting that nbdflags is within range, just give
      it the correct type to begin with :)  nbdflags corresponds to
      the per-export portion of NBD Protocol "transmission flags", which
      is 16 bits in response to NBD_OPT_EXPORT_NAME and NBD_OPT_GO.
      
      Furthermore, upstream NBD has never passed the global flags to
      the kernel via ioctl(NBD_SET_FLAGS) (the ioctl was first
      introduced in NBD 2.9.22; then a latent bug in NBD 3.1 actually
      tried to OR the global flags with the transmission flags, with
      the disaster that the addition of NBD_FLAG_NO_ZEROES in 3.9
      caused all earlier NBD 3.x clients to treat every export as
      read-only; NBD 3.10 and later intentionally clip things to 16
      bits to pass only transmission flags).  Qemu should follow suit,
      since the current two global flags (NBD_FLAG_FIXED_NEWSTYLE
      and NBD_FLAG_NO_ZEROES) have no impact on the kernel's behavior
      during transmission.
      
      CC: qemu-stable@nongnu.org
      Signed-off-by: NEric Blake <eblake@redhat.com>
      
      Message-Id: <1469129688-22848-3-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      7423f417
  7. 20 7月, 2016 2 次提交
  8. 05 7月, 2016 1 次提交
  9. 17 6月, 2016 2 次提交
    • E
      nbd: Avoid magic number for NBD max name size · 943cec86
      Eric Blake 提交于
      Declare a constant and use that when determining if an export
      name fits within the constraints we are willing to support.
      
      Note that upstream NBD recently documented that clients MUST
      support export names of 256 bytes (not including trailing NUL),
      and SHOULD support names up to 4096 bytes.  4096 is a bit big
      (we would lose benefits of stack-allocation of a name array),
      and we already have other limits in place (for example, qcow2
      snapshot names are clamped around 1024).  So for now, just
      stick to the required minimum, as that's easier to audit than
      a full-scale support for larger names.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      
      Message-Id: <1463006384-7734-12-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      943cec86
    • P
      nbd: simplify the nbd_request and nbd_reply structs · 56af2dda
      Paolo Bonzini 提交于
      These structs are never used to represent the bytes that go over the
      network.  The big-endian network data is built into a uint8_t array
      in nbd_{receive,send}_{request,reply}.  Remove the unused magic field,
      reorder the struct to avoid holes, and remove the packed attribute.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      56af2dda
  10. 23 2月, 2016 1 次提交
    • P
      include: Clean up includes · 90ce6e26
      Peter Maydell 提交于
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      
      NB: If this commit breaks compilation for your out-of-tree
      patchseries or fork, then you need to make sure you add
      #include "qemu/osdep.h" to any new .c files that you have.
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      90ce6e26
  11. 17 2月, 2016 2 次提交
  12. 16 1月, 2016 1 次提交
    • F
      nbd: Always call "close_fn" in nbd_client_new · ee7d7aab
      Fam Zheng 提交于
      Rename the parameter "close" to "close_fn" to disambiguous with
      close(2).
      
      This unifies error handling paths of NBDClient allocation:
      nbd_client_new will shutdown the socket and call the "close_fn" callback
      if negotiation failed, so the caller don't need a different path than
      the normal close.
      
      The returned pointer is never used, make it void in preparation for the
      next patch.
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-Id: <1452760863-25350-2-git-send-email-famz@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      ee7d7aab
  13. 18 3月, 2015 3 次提交
  14. 16 2月, 2015 1 次提交
    • M
      nbd: Drop BDS backpointer · f53a829b
      Max Reitz 提交于
      Before this patch, the "opaque" pointer in an NBD BDS points to a
      BDRVNBDState, which contains an NbdClientSession object, which in turn
      contains a pointer to the BDS. This pointer may become invalid due to
      bdrv_swap(), so drop it, and instead pass the BDS directly to the
      nbd-client.c functions which then retrieve the NbdClientSession object
      from there.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 1423256778-3340-2-git-send-email-mreitz@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      f53a829b
  15. 07 2月, 2015 1 次提交
    • M
      nbd: Improve error messages · 1ce52846
      Max Reitz 提交于
      This patch makes use of the Error object for nbd_receive_negotiate() so
      that errors during negotiation look nicer.
      
      Furthermore, this patch adds an additional error message if the received
      magic was wrong, but would be correct for the other protocol version,
      respectively: So if an export name was specified, but the NBD server
      magic corresponds to an old handshake, this condition is explicitly
      signaled to the user, and vice versa.
      
      As these messages are now part of the "Could not open image" error
      message, additional filtering has to be employed in iotest 083, which
      this patch does as well.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      1ce52846
  16. 10 12月, 2014 1 次提交
  17. 30 6月, 2014 2 次提交
  18. 22 2月, 2014 3 次提交
  19. 03 5月, 2013 1 次提交
    • S
      nbd: support large NBD requests · 2d821488
      Stefan Hajnoczi 提交于
      The Linux nbd driver recently increased the maximum supported request
      size up to 32 MB:
      
        commit 078be02b80359a541928c899c2631f39628f56df
        Author: Michal Belczyk <belczyk@bsd.krakow.pl>
        Date:   Tue Apr 30 15:28:28 2013 -0700
      
            nbd: increase default and max request sizes
      
            Raise the default max request size for nbd to 128KB (from 127KB) to get it
            4KB aligned.  This patch also allows the max request size to be increased
            (via /sys/block/nbd<x>/queue/max_sectors_kb) to 32MB.
      
      QEMU's 1 MB buffers are too small to handle these requests.
      
      This patch allocates data buffers dynamically and allows up to 32 MB per
      request.
      Reported-by: NNick Thomas <nick@bytemark.co.uk>
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      2d821488
  20. 23 3月, 2013 2 次提交
  21. 19 12月, 2012 1 次提交
  22. 19 9月, 2012 3 次提交