1. 14 3月, 2018 1 次提交
  2. 31 10月, 2017 1 次提交
  3. 24 8月, 2017 1 次提交
  4. 15 8月, 2017 1 次提交
    • E
      nbd-client: Fix regression when server sends garbage · 72b6ffc7
      Eric Blake 提交于
      When we switched NBD to use coroutines for qemu 2.9 (in particular,
      commit a12a712a), we introduced a regression: if a server sends us
      garbage (such as a corrupted magic number), we quit the read loop
      but do not stop sending further queued commands, resulting in the
      client hanging when it never reads the response to those additional
      commands.  In qemu 2.8, we properly detected that the server is no
      longer reliable, and cancelled all existing pending commands with
      EIO, then tore down the socket so that all further command attempts
      get EPIPE.
      
      Restore the proper behavior of quitting (almost) all communication
      with a broken server: Once we know we are out of sync or otherwise
      can't trust the server, we must assume that any further incoming
      data is unreliable and therefore end all pending commands with EIO,
      and quit trying to send any further commands.  As an exception, we
      still (try to) send NBD_CMD_DISC to let the server know we are going
      away (in part, because it is easier to do that than to further
      refactor nbd_teardown_connection, and in part because it is the
      only command where we do not have to wait for a reply).
      
      Based on a patch by Vladimir Sementsov-Ogievskiy.
      
      A malicious server can be created with the following hack,
      followed by setting NBD_SERVER_DEBUG to a non-zero value in the
      environment when running qemu-nbd:
      
      | --- a/nbd/server.c
      | +++ b/nbd/server.c
      | @@ -919,6 +919,17 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
      |      stl_be_p(buf + 4, reply->error);
      |      stq_be_p(buf + 8, reply->handle);
      |
      | +    static int debug;
      | +    static int count;
      | +    if (!count++) {
      | +        const char *str = getenv("NBD_SERVER_DEBUG");
      | +        if (str) {
      | +            debug = atoi(str);
      | +        }
      | +    }
      | +    if (debug && !(count % debug)) {
      | +        buf[0] = 0;
      | +    }
      |      return nbd_write(ioc, buf, sizeof(buf), errp);
      |  }
      Reported-by: NVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20170814213426.24681-1-eblake@redhat.com>
      Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
      72b6ffc7
  5. 14 7月, 2017 1 次提交
    • E
      nbd: Create struct for tracking export info · 004a89fc
      Eric Blake 提交于
      The NBD Protocol is introducing some additional information
      about exports, such as minimum request size and alignment, as
      well as an advertised maximum request size.  It will be easier
      to feed this information back to the block layer if we gather
      all the information into a struct, rather than adding yet more
      pointer parameters during negotiation.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20170707203049.534-2-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      004a89fc
  6. 26 6月, 2017 1 次提交
  7. 27 3月, 2017 1 次提交
  8. 21 2月, 2017 1 次提交
  9. 02 11月, 2016 3 次提交
  10. 01 11月, 2016 1 次提交
    • C
      nbd: Use CoQueue for free_sema instead of CoMutex · 9bc9732f
      Changlong Xie 提交于
      NBD is using the CoMutex in a way that wasn't anticipated. For example, if there are
      N(N=26, MAX_NBD_REQUESTS=16) nbd write requests, so we will invoke nbd_client_co_pwritev
      N times.
      ----------------------------------------------------------------------------------------
      time request Actions
      1    1       in_flight=1, Coroutine=C1
      2    2       in_flight=2, Coroutine=C2
      ...
      15   15      in_flight=15, Coroutine=C15
      16   16      in_flight=16, Coroutine=C16, free_sema->holder=C16, mutex->locked=true
      17   17      in_flight=16, Coroutine=C17, queue C17 into free_sema->queue
      18   18      in_flight=16, Coroutine=C18, queue C18 into free_sema->queue
      ...
      26   N       in_flight=16, Coroutine=C26, queue C26 into free_sema->queue
      ----------------------------------------------------------------------------------------
      
      Once nbd client recieves request No.16' reply, we will re-enter C16. It's ok, because
      it's equal to 'free_sema->holder'.
      ----------------------------------------------------------------------------------------
      time request Actions
      27   16      in_flight=15, Coroutine=C16, free_sema->holder=C16, mutex->locked=false
      ----------------------------------------------------------------------------------------
      
      Then nbd_coroutine_end invokes qemu_co_mutex_unlock what will pop coroutines from
      free_sema->queue's head and enter C17. More free_sema->holder is C17 now.
      ----------------------------------------------------------------------------------------
      time request Actions
      28   17      in_flight=16, Coroutine=C17, free_sema->holder=C17, mutex->locked=true
      ----------------------------------------------------------------------------------------
      
      In above scenario, we only recieves request No.16' reply. As time goes by, nbd client will
      almostly recieves replies from requests 1 to 15 rather than request 17 who owns C17. In this
      case, we will encounter assert "mutex->holder == self" failed since Kevin's commit 0e438cdc
      "coroutine: Let CoMutex remember who holds it". For example, if nbd client recieves request
      No.15' reply, qemu will stop unexpectedly:
      ----------------------------------------------------------------------------------------
      time request       Actions
      29   15(most case) in_flight=15, Coroutine=C15, free_sema->holder=C17, mutex->locked=false
      ----------------------------------------------------------------------------------------
      
      Per Paolo's suggestion "The simplest fix is to change it to CoQueue, which is like a condition
      variable", this patch replaces CoMutex with CoQueue.
      
      Cc: Wen Congyang <wency@cn.fujitsu.com>
      Reported-by: Nzhanghailiang <zhang.zhanghailiang@huawei.com>
      Suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NChanglong Xie <xiecl.fnst@cn.fujitsu.com>
      Message-Id: <1476267508-19499-1-git-send-email-xiecl.fnst@cn.fujitsu.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      9bc9732f
  11. 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
  12. 20 7月, 2016 2 次提交
  13. 12 5月, 2016 1 次提交
  14. 30 3月, 2016 1 次提交
    • K
      nbd: Support BDRV_REQ_FUA · 2b556518
      Kevin Wolf 提交于
      The NBD server already used to send a FUA flag when the writethrough
      mode was set. This code was a remnant from the times where protocol
      drivers actually had to implement writethrough modes. Since nowadays the
      block layer sends flushes in writethrough mode and non-root nodes are
      always writeback, this was mostly dead code - only mostly because if NBD
      was configured to be used without a format, we sent _both_ FUA and an
      explicit flush afterwards, which makes the code not technically dead,
      but useless overhead.
      
      This patch changes the code so that the block layer's FUA flag is
      recognised and translated into a NBD FUA flag. The additional flush is
      avoided now.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      2b556518
  15. 17 2月, 2016 2 次提交
    • D
      nbd: enable use of TLS with NBD block driver · 75822a12
      Daniel P. Berrange 提交于
      This modifies the NBD driver so that it is possible to request
      use of TLS. This is done by providing the 'tls-creds' parameter
      with the ID of a previously created QCryptoTLSCreds object.
      
      For example
      
        $QEMU -object tls-creds-x509,id=tls0,endpoint=client,\
                      dir=/home/berrange/security/qemutls \
              -drive driver=nbd,host=localhost,port=9000,tls-creds=tls0
      
      The client will drop the connection if the NBD server does not
      provide TLS.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1455129674-17255-15-git-send-email-berrange@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      75822a12
    • D
      nbd: convert block client to use I/O channels for connection setup · 064097d9
      Daniel P. Berrange 提交于
      This converts the NBD block driver client to use the QIOChannelSocket
      class for initial connection setup. The NbdClientSession struct has
      two pointers, one to the master QIOChannelSocket providing the raw
      data channel, and one to a QIOChannel which is the current channel
      used for I/O. Initially the two point to the same object, but when
      TLS support is added, they will point to different objects.
      
      The qemu-img & qemu-io tools now need to use MODULE_INIT_QOM to
      ensure the QIOChannel object classes are registered. The qemu-nbd
      tool already did this.
      
      In this initial conversion though, all I/O is still actually done
      using the raw POSIX sockets APIs.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1455129674-17255-4-git-send-email-berrange@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      064097d9
  16. 18 3月, 2015 1 次提交
  17. 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
  18. 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
  19. 04 6月, 2014 1 次提交
  20. 16 12月, 2013 2 次提交