1. 02 11月, 2016 6 次提交
    • E
      nbd: Less allocation during NBD_OPT_LIST · 75368aab
      Eric Blake 提交于
      Since we know that the maximum name we are willing to accept
      is small enough to stack-allocate, rework the iteration over
      NBD_OPT_LIST responses to reuse a stack buffer rather than
      allocating every time.  Furthermore, we don't even have to
      allocate if we know the server's length doesn't match what
      we are searching for.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-12-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      75368aab
    • E
      nbd: Let client skip portions of server reply · 7d3123e1
      Eric Blake 提交于
      The server has a nice helper function nbd_negotiate_drop_sync()
      which lets it easily ignore fluff from the client (such as the
      payload to an unknown option request).  We can't quite make it
      common, since it depends on nbd_negotiate_read() which handles
      coroutine magic, but we can copy the idea into the client where
      we have places where we want to ignore data (such as the
      description tacked on the end of NBD_REP_SERVER).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-11-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      7d3123e1
    • E
      nbd: Let server know when client gives up negotiation · 2cdbf413
      Eric Blake 提交于
      The NBD spec says that a client should send NBD_OPT_ABORT
      rather than just dropping the connection, if the client doesn't
      like something the server sent during option negotiation.  This
      is a best-effort attempt only, and can only be done in places
      where we know the server is still in sync with what we've sent,
      whether or not we've read everything the server has sent.
      Technically, the server then has to reply with NBD_REP_ACK, but
      it's not worth complicating the client to wait around for that
      reply.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1476469998-28592-10-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      2cdbf413
    • 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
  2. 27 10月, 2016 1 次提交
  3. 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
  4. 17 6月, 2016 8 次提交
  5. 18 5月, 2016 1 次提交
  6. 15 4月, 2016 1 次提交
    • E
      nbd: Don't fail handshake on NBD_OPT_LIST descriptions · 200650d4
      Eric Blake 提交于
      The NBD Protocol states that NBD_REP_SERVER may set
      'length > sizeof(namelen) + namelen'; in which case the rest
      of the packet is a UTF-8 description of the export.  While we
      don't know of any NBD servers that send this description yet,
      we had better consume the data so we don't choke when we start
      to talk to such a server.
      
      Also, a (buggy/malicious) server that replies with length <
      sizeof(namelen) would cause us to block waiting for bytes that
      the server is not sending, and one that replies with super-huge
      lengths could cause us to temporarily allocate up to 4G memory.
      Sanity check things before blindly reading incorrectly.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-id: 1460077777-31004-1-git-send-email-eblake@redhat.com
      Reviewed-by: NAlex Bligh <alex@alex.org.uk>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      200650d4
  7. 08 4月, 2016 2 次提交
    • A
      nbd: Fix NBD unsupported options · 6ff58164
      Alex Bligh 提交于
      nbd-client.c currently fails to handle unsupported options properly.
      If during option haggling the server finds an option that is
      unsupported, it returns an NBD_REP_ERR_UNSUP reply.
      
      According to nbd's proto.md, the format for such a reply
      should be:
      
        S: 64 bits, 0x3e889045565a9 (magic number for replies)
        S: 32 bits, the option as sent by the client to which this is a reply
        S: 32 bits, reply type (e.g., NBD_REP_ACK for successful completion,
           or NBD_REP_ERR_UNSUP to mark use of an option not known by this server
        S: 32 bits, length of the reply. This may be zero for some replies,
           in which case the next field is not sent
        S: any data as required by the reply (e.g., an export name in the case
           of NBD_REP_SERVER, or optional UTF-8 message for NBD_REP_ERR_*)
      
      However, in nbd-client.c, the reply type was being read, and if it
      contained an error, it was bailing out and issuing the next option
      request without first reading the length. This meant that the
      next option / handshake read had an extra 4 or more bytes of data in it.
      In practice, this makes Qemu incompatible with servers that do not
      support NBD_OPT_LIST.
      
      To verify this isn't an error in the specification or my reading of
      it, replies are sent by the reference implementation here:
       https://github.com/yoe/nbd/blob/66dfb35/nbd-server.c#L1232
      and as is evident it always sends a 'datasize' (aka length) 32 bit
      word. Unsupported elements are replied to here:
       https://github.com/yoe/nbd/blob/66dfb35/nbd-server.c#L1371Signed-off-by: NAlex Bligh <alex@alex.org.uk>
      Message-Id: <1459882500-24316-1-git-send-email-alex@alex.org.uk>
      [rework to ALWAYS consume an optional UTF-8 message from the server]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1459961962-18771-1-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      6ff58164
    • E
      nbd: Improve debug traces on little-endian · 7548fe31
      Eric Blake 提交于
      Print debug tracing messages while data is still in native
      ordering, rather than after we've potentially swapped it into
      network order for transmission.  Also, it's nice if the server
      mentions what it is replying, to correlate it to with what the
      client says it is receiving.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1459913704-19949-4-git-send-email-eblake@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      7548fe31
  8. 05 4月, 2016 1 次提交
  9. 23 3月, 2016 1 次提交
    • M
      include/qemu/osdep.h: Don't include qapi/error.h · da34e65c
      Markus Armbruster 提交于
      Commit 57cb38b3 included qapi/error.h into qemu/osdep.h to get the
      Error typedef.  Since then, we've moved to include qemu/osdep.h
      everywhere.  Its file comment explains: "To avoid getting into
      possible circular include dependencies, this file should not include
      any other QEMU headers, with the exceptions of config-host.h,
      compiler.h, os-posix.h and os-win32.h, all of which are doing a
      similar job to this file and are under similar constraints."
      qapi/error.h doesn't do a similar job, and it doesn't adhere to
      similar constraints: it includes qapi-types.h.  That's in excess of
      100KiB of crap most .c files don't actually need.
      
      Add the typedef to qemu/typedefs.h, and include that instead of
      qapi/error.h.  Include qapi/error.h in .c files that need it and don't
      get it now.  Include qapi-types.h in qom/object.h for uint16List.
      
      Update scripts/clean-includes accordingly.  Update it further to match
      reality: replace config.h by config-target.h, add sysemu/os-posix.h,
      sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
      comment quoted above similarly.
      
      This reduces the number of objects depending on qapi/error.h from "all
      of them" to less than a third.  Unfortunately, the number depending on
      qapi-types.h shrinks only a little.  More work is needed for that one.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      [Fix compilation without the spice devel packages. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      da34e65c
  10. 17 2月, 2016 6 次提交
  11. 05 2月, 2016 1 次提交
    • P
      all: Clean up includes · d38ea87a
      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.
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1454089805-5470-16-git-send-email-peter.maydell@linaro.org
      d38ea87a
  12. 16 1月, 2016 1 次提交
    • F
      nbd: Split nbd.c · 798bfe00
      Fam Zheng 提交于
      We have NBD server code and client code, all mixed in a file. Now split
      them into separate files under nbd/, and update MAINTAINERS.
      
      filter_nbd for iotest 083 is updated to keep the log filtered out.
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-Id: <1452760863-25350-3-git-send-email-famz@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      798bfe00