[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if
From: |
nick |
Subject: |
[Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server |
Date: |
Mon, 22 Oct 2012 12:09:17 +0100 |
This is unlikely to come up now, but is a necessary prerequisite for
reconnection
behaviour.
Signed-off-by: Nick Thomas <address@hidden>
---
block/nbd.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index 2bce47b..9536408 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -71,6 +71,11 @@ typedef struct BDRVNBDState {
char *host_spec;
} BDRVNBDState;
+static bool nbd_is_connected(BDRVNBDState *s)
+{
+ return s->sock >= 0;
+}
+
static int nbd_config(BDRVNBDState *s, const char *filename, int flags)
{
char *file;
@@ -309,6 +314,7 @@ static void nbd_teardown_connection(BlockDriverState *bs)
qemu_aio_set_fd_handler(s->sock, NULL, NULL, NULL, NULL);
closesocket(s->sock);
+ s->sock = -1;
}
static int nbd_open(BlockDriverState *bs, const char* filename, int flags)
@@ -316,6 +322,8 @@ static int nbd_open(BlockDriverState *bs, const char*
filename, int flags)
BDRVNBDState *s = bs->opaque;
int result;
+ s->sock = -1;
+
qemu_co_mutex_init(&s->send_mutex);
qemu_co_mutex_init(&s->free_sema);
@@ -431,7 +439,7 @@ static int nbd_co_flush(BlockDriverState *bs)
struct nbd_reply reply;
ssize_t ret;
- if (!(s->nbdflags & NBD_FLAG_SEND_FLUSH)) {
+ if (!nbd_is_connected(s) || !(s->nbdflags & NBD_FLAG_SEND_FLUSH)) {
return 0;
}
@@ -462,7 +470,7 @@ static int nbd_co_discard(BlockDriverState *bs, int64_t
sector_num,
struct nbd_reply reply;
ssize_t ret;
- if (!(s->nbdflags & NBD_FLAG_SEND_TRIM)) {
+ if (!nbd_is_connected(s) || !(s->nbdflags & NBD_FLAG_SEND_TRIM)) {
return 0;
}
request.type = NBD_CMD_TRIM;
@@ -515,3 +523,4 @@ static void bdrv_nbd_init(void)
}
block_init(bdrv_nbd_init);
+
- [Qemu-devel] [PATCH 0/3] NBD reconnection behaviour, nick, 2012/10/22
- [Qemu-devel] [PATCH 3/3] nbd: Move reconnection attempts from each new I/O request to a 5-second timer, nick, 2012/10/22
- [Qemu-devel] [PATCH 2/3] nbd: Explicitly disconnect and fail inflight I/O requests on error, then reconnect next I/O request., nick, 2012/10/22
- [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server,
nick <=
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Kevin Wolf, 2012/10/23
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Nicholas Thomas, 2012/10/23
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Kevin Wolf, 2012/10/23
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Jamie Lokier, 2012/10/23
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Nicholas Thomas, 2012/10/24
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Kevin Wolf, 2012/10/24
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Jamie Lokier, 2012/10/24
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Paolo Bonzini, 2012/10/24
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Kevin Wolf, 2012/10/25
- Re: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server, Jamie Lokier, 2012/10/25