nbd.c (bed2e759eb642931e0ebb95ea99580c27f57560e) | nbd.c (f2e5dca46b5ba4588c0756c5f272123585cbbf23) |
---|---|
1/* 2 * QEMU Block driver for NBD 3 * 4 * Copyright (C) 2008 Bull S.A.S. 5 * Author: Laurent Vivier <Laurent.Vivier@bull.net> 6 * 7 * Some parts: 8 * Copyright (C) 2007 Anthony Liguori <anthony@codemonkey.ws> --- 320 unchanged lines hidden (view full) --- 329 330static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request, 331 QEMUIOVector *qiov, int offset) 332{ 333 int rc, ret; 334 335 qemu_co_mutex_lock(&s->send_mutex); 336 s->send_coroutine = qemu_coroutine_self(); | 1/* 2 * QEMU Block driver for NBD 3 * 4 * Copyright (C) 2008 Bull S.A.S. 5 * Author: Laurent Vivier <Laurent.Vivier@bull.net> 6 * 7 * Some parts: 8 * Copyright (C) 2007 Anthony Liguori <anthony@codemonkey.ws> --- 320 unchanged lines hidden (view full) --- 329 330static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request, 331 QEMUIOVector *qiov, int offset) 332{ 333 int rc, ret; 334 335 qemu_co_mutex_lock(&s->send_mutex); 336 s->send_coroutine = qemu_coroutine_self(); |
337 qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, nbd_restart_write, 338 NULL, s); | 337 qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, nbd_restart_write, s); |
339 if (qiov) { 340 if (!s->is_unix) { 341 socket_set_cork(s->sock, 1); 342 } 343 rc = nbd_send_request(s->sock, request); 344 if (rc >= 0) { 345 ret = qemu_co_sendv(s->sock, qiov->iov, qiov->niov, 346 offset, request->len); 347 if (ret != request->len) { 348 rc = -EIO; 349 } 350 } 351 if (!s->is_unix) { 352 socket_set_cork(s->sock, 0); 353 } 354 } else { 355 rc = nbd_send_request(s->sock, request); 356 } | 338 if (qiov) { 339 if (!s->is_unix) { 340 socket_set_cork(s->sock, 1); 341 } 342 rc = nbd_send_request(s->sock, request); 343 if (rc >= 0) { 344 ret = qemu_co_sendv(s->sock, qiov->iov, qiov->niov, 345 offset, request->len); 346 if (ret != request->len) { 347 rc = -EIO; 348 } 349 } 350 if (!s->is_unix) { 351 socket_set_cork(s->sock, 0); 352 } 353 } else { 354 rc = nbd_send_request(s->sock, request); 355 } |
357 qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, NULL, 358 NULL, s); | 356 qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, NULL, s); |
359 s->send_coroutine = NULL; 360 qemu_co_mutex_unlock(&s->send_mutex); 361 return rc; 362} 363 364static void nbd_co_receive_reply(BDRVNBDState *s, struct nbd_request *request, 365 struct nbd_reply *reply, 366 QEMUIOVector *qiov, int offset) --- 59 unchanged lines hidden (view full) --- 426 logout("Failed to negotiate with the NBD server\n"); 427 closesocket(sock); 428 return ret; 429 } 430 431 /* Now that we're connected, set the socket to be non-blocking and 432 * kick the reply mechanism. */ 433 qemu_set_nonblock(sock); | 357 s->send_coroutine = NULL; 358 qemu_co_mutex_unlock(&s->send_mutex); 359 return rc; 360} 361 362static void nbd_co_receive_reply(BDRVNBDState *s, struct nbd_request *request, 363 struct nbd_reply *reply, 364 QEMUIOVector *qiov, int offset) --- 59 unchanged lines hidden (view full) --- 424 logout("Failed to negotiate with the NBD server\n"); 425 closesocket(sock); 426 return ret; 427 } 428 429 /* Now that we're connected, set the socket to be non-blocking and 430 * kick the reply mechanism. */ 431 qemu_set_nonblock(sock); |
434 qemu_aio_set_fd_handler(sock, nbd_reply_ready, NULL, 435 NULL, s); | 432 qemu_aio_set_fd_handler(sock, nbd_reply_ready, NULL, s); |
436 437 s->sock = sock; 438 s->size = size; 439 s->blocksize = blocksize; 440 441 logout("Established connection with NBD server\n"); 442 return 0; 443} 444 445static void nbd_teardown_connection(BlockDriverState *bs) 446{ 447 BDRVNBDState *s = bs->opaque; 448 struct nbd_request request; 449 450 request.type = NBD_CMD_DISC; 451 request.from = 0; 452 request.len = 0; 453 nbd_send_request(s->sock, &request); 454 | 433 434 s->sock = sock; 435 s->size = size; 436 s->blocksize = blocksize; 437 438 logout("Established connection with NBD server\n"); 439 return 0; 440} 441 442static void nbd_teardown_connection(BlockDriverState *bs) 443{ 444 BDRVNBDState *s = bs->opaque; 445 struct nbd_request request; 446 447 request.type = NBD_CMD_DISC; 448 request.from = 0; 449 request.len = 0; 450 nbd_send_request(s->sock, &request); 451 |
455 qemu_aio_set_fd_handler(s->sock, NULL, NULL, NULL, NULL); | 452 qemu_aio_set_fd_handler(s->sock, NULL, NULL, NULL); |
456 closesocket(s->sock); 457} 458 459static int nbd_open(BlockDriverState *bs, QDict *options, int flags) 460{ 461 BDRVNBDState *s = bs->opaque; 462 int result; 463 --- 230 unchanged lines hidden --- | 453 closesocket(s->sock); 454} 455 456static int nbd_open(BlockDriverState *bs, QDict *options, int flags) 457{ 458 BDRVNBDState *s = bs->opaque; 459 int result; 460 --- 230 unchanged lines hidden --- |