aboutsummaryrefslogtreecommitdiff
path: root/nbd.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-09-18 13:58:25 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2012-09-19 15:26:29 +0200
commit4b9441f6b3565ba6affa95141590cd2be4ae0cd9 (patch)
treea5d272e679b5c987b51179aa6053f13ea2fd4c68 /nbd.c
parent2c8d9f065538a5a0ef2421e90b6076d05148accf (diff)
nbd: track clients into NBDExport
Track the NBDClients of each NBDExport, and use it to implement nbd_export_close. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'nbd.c')
-rw-r--r--nbd.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/nbd.c b/nbd.c
index 4922d38ea3..c39692b61f 100644
--- a/nbd.c
+++ b/nbd.c
@@ -94,6 +94,7 @@ struct NBDExport {
off_t dev_offset;
off_t size;
uint32_t nbdflags;
+ QTAILQ_HEAD(, NBDClient) clients;
QSIMPLEQ_HEAD(, NBDRequest) requests;
};
@@ -109,6 +110,7 @@ struct NBDClient {
CoMutex send_lock;
Coroutine *send_coroutine;
+ QTAILQ_ENTRY(NBDClient) next;
int nb_requests;
bool closing;
};
@@ -665,6 +667,7 @@ void nbd_client_put(NBDClient *client)
qemu_set_fd_handler2(client->sock, NULL, NULL, NULL, NULL);
close(client->sock);
client->sock = -1;
+ QTAILQ_REMOVE(&client->exp->clients, client, next);
nbd_export_put(client->exp);
g_free(client);
}
@@ -725,6 +728,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
NBDExport *exp = g_malloc0(sizeof(NBDExport));
QSIMPLEQ_INIT(&exp->requests);
exp->refcount = 1;
+ QTAILQ_INIT(&exp->clients);
exp->bs = bs;
exp->dev_offset = dev_offset;
exp->nbdflags = nbdflags;
@@ -734,9 +738,13 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
void nbd_export_close(NBDExport *exp)
{
- assert(exp->refcount == 1);
+ NBDClient *client, *next;
- /* stub */
+ nbd_export_get(exp);
+ QTAILQ_FOREACH_SAFE(client, &exp->clients, next, next) {
+ nbd_client_close(client);
+ }
+ nbd_export_put(exp);
}
void nbd_export_get(NBDExport *exp)
@@ -1035,6 +1043,7 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
qemu_co_mutex_init(&client->send_lock);
qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
+ QTAILQ_INSERT_TAIL(&exp->clients, client, next);
nbd_export_get(exp);
return client;
}