Revision fc19f8a0

b/block/nbd.c
197 197
    qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, nbd_restart_write,
198 198
                            nbd_have_request, NULL, s);
199 199
    rc = nbd_send_request(s->sock, request);
200
    if (rc != -1 && iov) {
200
    if (rc >= 0 && iov) {
201 201
        ret = qemu_co_sendv(s->sock, iov, request->len, offset);
202 202
        if (ret != request->len) {
203 203
            errno = -EIO;
......
260 260
    }
261 261

  
262 262
    /* Failed to establish connection */
263
    if (sock == -1) {
263
    if (sock < 0) {
264 264
        logout("Failed to establish connection to NBD server\n");
265 265
        return -errno;
266 266
    }
......
268 268
    /* NBD handshake */
269 269
    ret = nbd_receive_negotiate(sock, s->export_name, &s->nbdflags, &size,
270 270
                                &blocksize);
271
    if (ret == -1) {
271
    if (ret < 0) {
272 272
        logout("Failed to negotiate with the NBD server\n");
273 273
        closesocket(sock);
274 274
        return -errno;
......
331 331
    BDRVNBDState *s = bs->opaque;
332 332
    struct nbd_request request;
333 333
    struct nbd_reply reply;
334
    ssize_t ret;
334 335

  
335 336
    request.type = NBD_CMD_READ;
336 337
    request.from = sector_num * 512;
337 338
    request.len = nb_sectors * 512;
338 339

  
339 340
    nbd_coroutine_start(s, &request);
340
    if (nbd_co_send_request(s, &request, NULL, 0) == -1) {
341
    ret = nbd_co_send_request(s, &request, NULL, 0);
342
    if (ret < 0) {
341 343
        reply.error = errno;
342 344
    } else {
343 345
        nbd_co_receive_reply(s, &request, &reply, qiov->iov, offset);
......
354 356
    BDRVNBDState *s = bs->opaque;
355 357
    struct nbd_request request;
356 358
    struct nbd_reply reply;
359
    ssize_t ret;
357 360

  
358 361
    request.type = NBD_CMD_WRITE;
359 362
    if (!bdrv_enable_write_cache(bs) && (s->nbdflags & NBD_FLAG_SEND_FUA)) {
......
364 367
    request.len = nb_sectors * 512;
365 368

  
366 369
    nbd_coroutine_start(s, &request);
367
    if (nbd_co_send_request(s, &request, qiov->iov, offset) == -1) {
370
    ret = nbd_co_send_request(s, &request, qiov->iov, offset);
371
    if (ret < 0) {
368 372
        reply.error = errno;
369 373
    } else {
370 374
        nbd_co_receive_reply(s, &request, &reply, NULL, 0);
......
416 420
    BDRVNBDState *s = bs->opaque;
417 421
    struct nbd_request request;
418 422
    struct nbd_reply reply;
423
    ssize_t ret;
419 424

  
420 425
    if (!(s->nbdflags & NBD_FLAG_SEND_FLUSH)) {
421 426
        return 0;
......
430 435
    request.len = 0;
431 436

  
432 437
    nbd_coroutine_start(s, &request);
433
    if (nbd_co_send_request(s, &request, NULL, 0) == -1) {
438
    ret = nbd_co_send_request(s, &request, NULL, 0);
439
    if (ret < 0) {
434 440
        reply.error = errno;
435 441
    } else {
436 442
        nbd_co_receive_reply(s, &request, &reply, NULL, 0);
......
445 451
    BDRVNBDState *s = bs->opaque;
446 452
    struct nbd_request request;
447 453
    struct nbd_reply reply;
454
    ssize_t ret;
448 455

  
449 456
    if (!(s->nbdflags & NBD_FLAG_SEND_TRIM)) {
450 457
        return 0;
......
454 461
    request.len = nb_sectors * 512;
455 462

  
456 463
    nbd_coroutine_start(s, &request);
457
    if (nbd_co_send_request(s, &request, NULL, 0) == -1) {
464
    ret = nbd_co_send_request(s, &request, NULL, 0);
465
    if (ret < 0) {
458 466
        reply.error = errno;
459 467
    } else {
460 468
        nbd_co_receive_reply(s, &request, &reply, NULL, 0);
b/nbd.c
102 102
            len = send(fd, buffer + offset, size - offset, 0);
103 103
        }
104 104

  
105
        if (len == -1)
105
        if (len < 0) {
106 106
            errno = socket_error();
107 107

  
108
        /* recoverable error */
109
        if (len == -1 && (errno == EAGAIN || errno == EINTR)) {
110
            continue;
108
            /* recoverable error */
109
            if (errno == EINTR || errno == EAGAIN) {
110
                continue;
111
            }
112

  
113
            /* unrecoverable error */
114
            return 0;
111 115
        }
112 116

  
113 117
        /* eof */
......
115 119
            break;
116 120
        }
117 121

  
118
        /* unrecoverable error */
119
        if (len == -1) {
120
            return 0;
121
        }
122

  
123 122
        offset += len;
124 123
    }
125 124

  
......
364 363
{
365 364
    TRACE("Setting NBD socket");
366 365

  
367
    if (ioctl(fd, NBD_SET_SOCK, csock) == -1) {
366
    if (ioctl(fd, NBD_SET_SOCK, csock) < 0) {
368 367
        int serrno = errno;
369 368
        LOG("Failed to set NBD socket");
370 369
        errno = serrno;
......
373 372

  
374 373
    TRACE("Setting block size to %lu", (unsigned long)blocksize);
375 374

  
376
    if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) == -1) {
375
    if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) < 0) {
377 376
        int serrno = errno;
378 377
        LOG("Failed setting NBD block size");
379 378
        errno = serrno;
......
382 381

  
383 382
        TRACE("Setting size to %zd block(s)", (size_t)(size / blocksize));
384 383

  
385
    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / blocksize) == -1) {
384
    if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / blocksize) < 0) {
386 385
        int serrno = errno;
387 386
        LOG("Failed setting size (in blocks)");
388 387
        errno = serrno;
......
430 429
    TRACE("Doing NBD loop");
431 430

  
432 431
    ret = ioctl(fd, NBD_DO_IT);
433
    if (ret == -1 && errno == EPIPE) {
432
    if (ret < 0 && errno == EPIPE) {
434 433
        /* NBD_DO_IT normally returns EPIPE when someone has disconnected
435 434
         * the socket via NBD_DISCONNECT.  We do not want to return 1 in
436 435
         * that case.
......
714 713

  
715 714
    if (!len) {
716 715
        rc = nbd_send_reply(csock, reply);
717
        if (rc == -1) {
716
        if (rc < 0) {
718 717
            rc = -errno;
719 718
        }
720 719
    } else {
721 720
        socket_set_cork(csock, 1);
722 721
        rc = nbd_send_reply(csock, reply);
723
        if (rc != -1) {
722
        if (rc >= 0) {
724 723
            ret = qemu_co_send(csock, req->data, len);
725 724
            if (ret != len) {
726 725
                errno = EIO;
727 726
                rc = -1;
728 727
            }
729 728
        }
730
        if (rc == -1) {
729
        if (rc < 0) {
731 730
            rc = -errno;
732 731
        }
733 732
        socket_set_cork(csock, 0);
......
746 745
    ssize_t rc;
747 746

  
748 747
    client->recv_coroutine = qemu_coroutine_self();
749
    if (nbd_receive_request(csock, request) == -1) {
748
    if (nbd_receive_request(csock, request) < 0) {
750 749
        rc = -EIO;
751 750
        goto out;
752 751
    }
......
860 859
            }
861 860
        }
862 861

  
863
        if (nbd_co_send_reply(req, &reply, 0) < 0)
862
        if (nbd_co_send_reply(req, &reply, 0) < 0) {
864 863
            goto out;
864
        }
865 865
        break;
866 866
    case NBD_CMD_DISC:
867 867
        TRACE("Request type is DISCONNECT");
......
875 875
            LOG("flush failed");
876 876
            reply.error = -ret;
877 877
        }
878

  
879
        if (nbd_co_send_reply(req, &reply, 0) < 0)
878
        if (nbd_co_send_reply(req, &reply, 0) < 0) {
880 879
            goto out;
880
        }
881 881
        break;
882 882
    case NBD_CMD_TRIM:
883 883
        TRACE("Request type is TRIM");
......
887 887
            LOG("discard failed");
888 888
            reply.error = -ret;
889 889
        }
890
        if (nbd_co_send_reply(req, &reply, 0) < 0)
890
        if (nbd_co_send_reply(req, &reply, 0) < 0) {
891 891
            goto out;
892
        }
892 893
        break;
893 894
    default:
894 895
        LOG("invalid request type (%u) received", request.type);
895 896
    invalid_request:
896 897
        reply.error = -EINVAL;
897 898
    error_reply:
898
        if (nbd_co_send_reply(req, &reply, 0) == -1)
899
        if (nbd_co_send_reply(req, &reply, 0) < 0) {
899 900
            goto out;
901
        }
900 902
        break;
901 903
    }
902 904

  
......
939 941
                          void (*close)(NBDClient *))
940 942
{
941 943
    NBDClient *client;
942
    if (nbd_send_negotiate(csock, exp->size, exp->nbdflags) == -1) {
944
    if (nbd_send_negotiate(csock, exp->size, exp->nbdflags) < 0) {
943 945
        return NULL;
944 946
    }
945 947
    client = g_malloc0(sizeof(NBDClient));
b/qemu-nbd.c
186 186
     *     modprobe nbd max_part=63
187 187
     */
188 188
    nbd = open(device, O_RDWR);
189
    if (nbd != -1) {
189
    if (nbd >= 0) {
190 190
        close(nbd);
191 191
    }
192 192
    return NULL;
......
203 203
    pthread_t show_parts_thread;
204 204

  
205 205
    sock = unix_socket_outgoing(sockpath);
206
    if (sock == -1) {
206
    if (sock < 0) {
207 207
        goto out;
208 208
    }
209 209

  
210 210
    ret = nbd_receive_negotiate(sock, NULL, &nbdflags,
211 211
                                &size, &blocksize);
212
    if (ret == -1) {
212
    if (ret < 0) {
213 213
        goto out;
214 214
    }
215 215

  
216 216
    fd = open(device, O_RDWR);
217
    if (fd == -1) {
217
    if (fd < 0) {
218 218
        /* Linux-only, we can use %m in printf.  */
219 219
        fprintf(stderr, "Failed to open %s: %m", device);
220 220
        goto out;
221 221
    }
222 222

  
223 223
    ret = nbd_init(fd, sock, nbdflags, size, blocksize);
224
    if (ret == -1) {
224
    if (ret < 0) {
225 225
        goto out;
226 226
    }
227 227

  
......
268 268

  
269 269
    int fd = accept(server_fd, (struct sockaddr *)&addr, &addr_len);
270 270
    nbd_started = true;
271
    if (fd != -1 && nbd_client_new(exp, fd, nbd_client_closed)) {
271
    if (fd >= 0 && nbd_client_new(exp, fd, nbd_client_closed)) {
272 272
        nb_fds++;
273 273
    }
274 274
}
......
410 410

  
411 411
    if (disconnect) {
412 412
        fd = open(argv[optind], O_RDWR);
413
        if (fd == -1)
413
        if (fd < 0) {
414 414
            err(EXIT_FAILURE, "Cannot open %s", argv[optind]);
415

  
415
        }
416 416
        nbd_disconnect(fd);
417 417

  
418 418
        close(fd);
......
427 427
        pid_t pid;
428 428
        int ret;
429 429

  
430
        if (qemu_pipe(stderr_fd) == -1) {
430
        if (qemu_pipe(stderr_fd) < 0) {
431 431
            err(EXIT_FAILURE, "Error setting up communication pipe");
432 432
        }
433 433

  
......
441 441

  
442 442
            /* Temporarily redirect stderr to the parent's pipe...  */
443 443
            dup2(stderr_fd[1], STDERR_FILENO);
444
            if (ret == -1) {
444
            if (ret < 0) {
445 445
                err(EXIT_FAILURE, "Failed to daemonize");
446 446
            }
447 447

  
......
459 459
            while ((ret = read(stderr_fd[0], buf, 1024)) > 0) {
460 460
                errors = true;
461 461
                ret = qemu_write_full(STDERR_FILENO, buf, ret);
462
                if (ret == -1) {
462
                if (ret < 0) {
463 463
                    exit(EXIT_FAILURE);
464 464
                }
465 465
            }
466
            if (ret == -1) {
466
            if (ret < 0) {
467 467
                err(EXIT_FAILURE, "Cannot read from daemon");
468 468
            }
469 469

  
......
504 504
        fd = tcp_socket_incoming(bindto, port);
505 505
    }
506 506

  
507
    if (fd == -1) {
507
    if (fd < 0) {
508 508
        return 1;
509 509
    }
510 510

  

Also available in: Unified diff