nbd patches for 2018-01-10

- Vladimir Sementsov-Ogievskiy: nbd: rename nbd_option and nbd_opt_reply
 - Vladimir Sementsov-Ogievskiy: nbd/server: add additional assert to nbd_export_put
 -----BEGIN PGP SIGNATURE-----
 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
 
 iQEcBAABCAAGBQJaVpl9AAoJEKeha0olJ0Nqd1cIAKQrlgqQbyayEHHSHU93/kpX
 6+PLv4kNeV6EwLzYmY91XO7RLzobeHkHmH1b5PnTqqQFFQLEZ6UPYz8HljkSzgmN
 33WKAWqSECQ4U0zGD5RXRcqntiVjsQCzlO1bzi/eWGBh9X411mTF7y/R+KzOmrdm
 dv9Spo1VZ48KxmoTklDEDgbpABu4GcwrDbVcQbDxYIZ6PdU4TIL57JFsAkASJvPZ
 qWrGMH7ij+ropSHFkqP2bzixsDiBcStFC9eATHf6+/wYmm4N0TRJrykJpKGiCJ23
 oeQdeoZ78jTk3moxFixbNap14BNM76OMVU1Alsr5Y7zGMPgiv3Gpy83XLg050lw=
 =w/o2
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-01-10' into staging

nbd patches for 2018-01-10

- Vladimir Sementsov-Ogievskiy: nbd: rename nbd_option and nbd_opt_reply
- Vladimir Sementsov-Ogievskiy: nbd/server: add additional assert to nbd_export_put

# gpg: Signature made Wed 10 Jan 2018 22:53:49 GMT
# gpg:                using RSA key 0xA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>"
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>"
# gpg:                 aka "[jpeg image of size 6874]"
# Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2  F3AA A7A1 6B4A 2527 436A

* remotes/ericb/tags/pull-nbd-2018-01-10:
  nbd: rename nbd_option and nbd_opt_reply
  nbd/server: add additional assert to nbd_export_put

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2018-01-11 11:52:40 +00:00
commit 612061b277
3 changed files with 16 additions and 10 deletions

View File

@ -28,20 +28,20 @@
/* Handshake phase structs - this struct is passed on the wire */
struct nbd_option {
struct NBDOption {
uint64_t magic; /* NBD_OPTS_MAGIC */
uint32_t option; /* NBD_OPT_* */
uint32_t length;
} QEMU_PACKED;
typedef struct nbd_option nbd_option;
typedef struct NBDOption NBDOption;
struct nbd_opt_reply {
struct NBDOptionReply {
uint64_t magic; /* NBD_REP_MAGIC */
uint32_t option; /* NBD_OPT_* */
uint32_t type; /* NBD_REP_* */
uint32_t length;
} QEMU_PACKED;
typedef struct nbd_opt_reply nbd_opt_reply;
typedef struct NBDOptionReply NBDOptionReply;
/* Transmission phase structs
*

View File

@ -66,7 +66,7 @@ static int nbd_send_option_request(QIOChannel *ioc, uint32_t opt,
uint32_t len, const char *data,
Error **errp)
{
nbd_option req;
NBDOption req;
QEMU_BUILD_BUG_ON(sizeof(req) != 16);
if (len == -1) {
@ -109,7 +109,7 @@ static void nbd_send_opt_abort(QIOChannel *ioc)
* payload. Return 0 if successful, -1 with errp set if it is
* impossible to continue. */
static int nbd_receive_option_reply(QIOChannel *ioc, uint32_t opt,
nbd_opt_reply *reply, Error **errp)
NBDOptionReply *reply, Error **errp)
{
QEMU_BUILD_BUG_ON(sizeof(*reply) != 20);
if (nbd_read(ioc, reply, sizeof(*reply), errp) < 0) {
@ -146,7 +146,7 @@ static int nbd_receive_option_reply(QIOChannel *ioc, uint32_t opt,
* can fall back to other approaches), or -1 with errp set for other
* errors.
*/
static int nbd_handle_reply_err(QIOChannel *ioc, nbd_opt_reply *reply,
static int nbd_handle_reply_err(QIOChannel *ioc, NBDOptionReply *reply,
Error **errp)
{
char *msg = NULL;
@ -239,7 +239,7 @@ static int nbd_handle_reply_err(QIOChannel *ioc, nbd_opt_reply *reply,
static int nbd_receive_list(QIOChannel *ioc, const char *want, bool *match,
Error **errp)
{
nbd_opt_reply reply;
NBDOptionReply reply;
uint32_t len;
uint32_t namelen;
char name[NBD_MAX_NAME_SIZE + 1];
@ -325,7 +325,7 @@ static int nbd_receive_list(QIOChannel *ioc, const char *want, bool *match,
static int nbd_opt_go(QIOChannel *ioc, const char *wantname,
NBDExportInfo *info, Error **errp)
{
nbd_opt_reply reply;
NBDOptionReply reply;
uint32_t len = strlen(wantname);
uint16_t type;
int error;
@ -517,7 +517,7 @@ static int nbd_receive_query_exports(QIOChannel *ioc,
*/
static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)
{
nbd_opt_reply reply;
NBDOptionReply reply;
int error;
if (nbd_send_option_request(ioc, opt, 0, NULL, errp) < 0) {

View File

@ -1190,6 +1190,12 @@ void nbd_export_put(NBDExport *exp)
nbd_export_close(exp);
}
/* nbd_export_close() may theoretically reduce refcount to 0. It may happen
* if someone calls nbd_export_put() on named export not through
* nbd_export_set_name() when refcount is 1. So, let's assert that
* it is > 0.
*/
assert(exp->refcount > 0);
if (--exp->refcount == 0) {
assert(exp->name == NULL);
assert(exp->description == NULL);