Revision cb595887 block/sheepdog.c

b/block/sheepdog.c
468 468
    if (ret) {
469 469
        error_report("unable to get address info %s, %s",
470 470
                     addr, strerror(errno));
471
        return -1;
471
        return -errno;
472 472
    }
473 473

  
474 474
    for (res = res0; res; res = res->ai_next) {
......
495 495
        dprintf("connected to %s:%s\n", addr, port);
496 496
        goto success;
497 497
    }
498
    fd = -1;
498
    fd = -errno;
499 499
    error_report("failed connect to %s:%s", addr, port);
500 500
success:
501 501
    freeaddrinfo(res0);
......
510 510
    ret = qemu_send_full(sockfd, hdr, sizeof(*hdr), 0);
511 511
    if (ret < sizeof(*hdr)) {
512 512
        error_report("failed to send a req, %s", strerror(errno));
513
        return ret;
513
        return -errno;
514 514
    }
515 515

  
516 516
    ret = qemu_send_full(sockfd, data, *wlen, 0);
517 517
    if (ret < *wlen) {
518 518
        error_report("failed to send a req, %s", strerror(errno));
519
        ret = -errno;
519 520
    }
520 521

  
521 522
    return ret;
......
553 554
    ret = qemu_recv_full(sockfd, hdr, sizeof(*hdr), 0);
554 555
    if (ret < sizeof(*hdr)) {
555 556
        error_report("failed to get a rsp, %s", strerror(errno));
557
        ret = -errno;
556 558
        goto out;
557 559
    }
558 560

  
......
564 566
        ret = qemu_recv_full(sockfd, data, *rlen, 0);
565 567
        if (ret < *rlen) {
566 568
            error_report("failed to get the data, %s", strerror(errno));
569
            ret = -errno;
567 570
            goto out;
568 571
        }
569 572
    }
......
587 590
    ret = qemu_co_recv(sockfd, hdr, sizeof(*hdr));
588 591
    if (ret < sizeof(*hdr)) {
589 592
        error_report("failed to get a rsp, %s", strerror(errno));
593
        ret = -errno;
590 594
        goto out;
591 595
    }
592 596

  
......
598 602
        ret = qemu_co_recv(sockfd, data, *rlen);
599 603
        if (ret < *rlen) {
600 604
            error_report("failed to get the data, %s", strerror(errno));
605
            ret = -errno;
601 606
            goto out;
602 607
        }
603 608
    }
......
787 792
    fd = connect_to_sdog(s->addr, s->port);
788 793
    if (fd < 0) {
789 794
        error_report("%s", strerror(errno));
790
        return -1;
795
        return fd;
791 796
    }
792 797

  
793 798
    socket_set_nonblock(fd);
......
796 801
    if (ret) {
797 802
        error_report("%s", strerror(errno));
798 803
        closesocket(fd);
799
        return -1;
804
        return -errno;
800 805
    }
801 806

  
802 807
    qemu_aio_set_fd_handler(fd, co_read_response, NULL, aio_flush_request, s);
......
883 888

  
884 889
    fd = connect_to_sdog(s->addr, s->port);
885 890
    if (fd < 0) {
886
        return -1;
891
        return fd;
887 892
    }
888 893

  
889 894
    memset(buf, 0, sizeof(buf));
......
904 909

  
905 910
    ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen);
906 911
    if (ret) {
907
        ret = -1;
908 912
        goto out;
909 913
    }
910 914

  
911 915
    if (rsp->result != SD_RES_SUCCESS) {
912 916
        error_report("cannot get vdi info, %s, %s %d %s",
913 917
                     sd_strerror(rsp->result), filename, snapid, tag);
914
        ret = -1;
918
        if (rsp->result == SD_RES_NO_VDI) {
919
            ret = -ENOENT;
920
        } else {
921
            ret = -EIO;
922
        }
915 923
        goto out;
916 924
    }
917 925
    *vid = rsp->vdi_id;
......
980 988
    if (ret < 0) {
981 989
        qemu_co_mutex_unlock(&s->lock);
982 990
        error_report("failed to send a req, %s", strerror(errno));
983
        return -EIO;
991
        return -errno;
984 992
    }
985 993

  
986 994
    if (wlen) {
......
988 996
        if (ret < 0) {
989 997
            qemu_co_mutex_unlock(&s->lock);
990 998
            error_report("failed to send a data, %s", strerror(errno));
991
            return -EIO;
999
            return -errno;
992 1000
        }
993 1001
    }
994 1002

  
......
1038 1046
    ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen);
1039 1047
    if (ret) {
1040 1048
        error_report("failed to send a request to the sheep");
1041
        return -1;
1049
        return ret;
1042 1050
    }
1043 1051

  
1044 1052
    switch (rsp->result) {
......
1046 1054
        return 0;
1047 1055
    default:
1048 1056
        error_report("%s", sd_strerror(rsp->result));
1049
        return -1;
1057
        return -EIO;
1050 1058
    }
1051 1059
}
1052 1060

  
......
1082 1090
    memset(vdi, 0, sizeof(vdi));
1083 1091
    memset(tag, 0, sizeof(tag));
1084 1092
    if (parse_vdiname(s, filename, vdi, &snapid, tag) < 0) {
1093
        ret = -EINVAL;
1085 1094
        goto out;
1086 1095
    }
1087 1096
    s->fd = get_sheep_fd(s);
1088 1097
    if (s->fd < 0) {
1098
        ret = s->fd;
1089 1099
        goto out;
1090 1100
    }
1091 1101

  
......
1099 1109
        s->flush_fd = connect_to_sdog(s->addr, s->port);
1100 1110
        if (s->flush_fd < 0) {
1101 1111
            error_report("failed to connect");
1112
            ret = s->flush_fd;
1102 1113
            goto out;
1103 1114
        }
1104 1115
    }
......
1111 1122
    fd = connect_to_sdog(s->addr, s->port);
1112 1123
    if (fd < 0) {
1113 1124
        error_report("failed to connect");
1125
        ret = fd;
1114 1126
        goto out;
1115 1127
    }
1116 1128

  
......
1139 1151
        closesocket(s->fd);
1140 1152
    }
1141 1153
    g_free(buf);
1142
    return -1;
1154
    return ret;
1143 1155
}
1144 1156

  
1145 1157
static int do_sd_create(char *filename, int64_t vdi_size,
......
1154 1166

  
1155 1167
    fd = connect_to_sdog(addr, port);
1156 1168
    if (fd < 0) {
1157
        return -EIO;
1169
        return fd;
1158 1170
    }
1159 1171

  
1160 1172
    memset(buf, 0, sizeof(buf));
......
1177 1189
    closesocket(fd);
1178 1190

  
1179 1191
    if (ret) {
1180
        return -EIO;
1192
        return ret;
1181 1193
    }
1182 1194

  
1183 1195
    if (rsp->result != SD_RES_SUCCESS) {
......
1294 1306
        }
1295 1307

  
1296 1308
        ret = bdrv_file_open(&bs, backing_file, 0);
1297
        if (ret < 0)
1298
            return -EIO;
1309
        if (ret < 0) {
1310
            return ret;
1311
        }
1299 1312

  
1300 1313
        s = bs->opaque;
1301 1314

  
......
1379 1392

  
1380 1393
    fd = connect_to_sdog(s->addr, s->port);
1381 1394
    if (fd < 0) {
1382
        return -EIO;
1395
        return fd;
1383 1396
    }
1384 1397

  
1385 1398
    /* we don't need to update entire object */
......
1391 1404

  
1392 1405
    if (ret < 0) {
1393 1406
        error_report("failed to update an inode.");
1394
        return -EIO;
1395 1407
    }
1396 1408

  
1397
    return 0;
1409
    return ret;
1398 1410
}
1399 1411

  
1400 1412
/*
......
1464 1476
    fd = connect_to_sdog(s->addr, s->port);
1465 1477
    if (fd < 0) {
1466 1478
        error_report("failed to connect");
1479
        ret = fd;
1467 1480
        goto out;
1468 1481
    }
1469 1482

  
......
1606 1619

  
1607 1620
    if (bs->growable && sector_num + nb_sectors > bs->total_sectors) {
1608 1621
        /* TODO: shouldn't block here */
1609
        if (sd_truncate(bs, (sector_num + nb_sectors) * SECTOR_SIZE) < 0) {
1610
            return -EIO;
1622
        ret = sd_truncate(bs, (sector_num + nb_sectors) * SECTOR_SIZE);
1623
        if (ret < 0) {
1624
            return ret;
1611 1625
        }
1612 1626
        bs->total_sectors = sector_num + nb_sectors;
1613 1627
    }
......
1724 1738
    /* refresh inode. */
1725 1739
    fd = connect_to_sdog(s->addr, s->port);
1726 1740
    if (fd < 0) {
1727
        ret = -EIO;
1741
        ret = fd;
1728 1742
        goto cleanup;
1729 1743
    }
1730 1744

  
......
1732 1746
                       s->inode.nr_copies, datalen, 0, 0, s->cache_enabled);
1733 1747
    if (ret < 0) {
1734 1748
        error_report("failed to write snapshot's inode.");
1735
        ret = -EIO;
1736 1749
        goto cleanup;
1737 1750
    }
1738 1751

  
......
1741 1754
    if (ret < 0) {
1742 1755
        error_report("failed to create inode for snapshot. %s",
1743 1756
                     strerror(errno));
1744
        ret = -EIO;
1745 1757
        goto cleanup;
1746 1758
    }
1747 1759

  
......
1752 1764

  
1753 1765
    if (ret < 0) {
1754 1766
        error_report("failed to read new inode info. %s", strerror(errno));
1755
        ret = -EIO;
1756 1767
        goto cleanup;
1757 1768
    }
1758 1769

  
......
1773 1784
    char *buf = NULL;
1774 1785
    uint32_t vid;
1775 1786
    uint32_t snapid = 0;
1776
    int ret = -ENOENT, fd;
1787
    int ret = 0, fd;
1777 1788

  
1778 1789
    old_s = g_malloc(sizeof(BDRVSheepdogState));
1779 1790

  
......
1791 1802
    ret = find_vdi_name(s, vdi, snapid, tag, &vid, 1);
1792 1803
    if (ret) {
1793 1804
        error_report("Failed to find_vdi_name");
1794
        ret = -ENOENT;
1795 1805
        goto out;
1796 1806
    }
1797 1807

  
1798 1808
    fd = connect_to_sdog(s->addr, s->port);
1799 1809
    if (fd < 0) {
1800 1810
        error_report("failed to connect");
1811
        ret = fd;
1801 1812
        goto out;
1802 1813
    }
1803 1814

  
......
1808 1819
    closesocket(fd);
1809 1820

  
1810 1821
    if (ret) {
1811
        ret = -ENOENT;
1812 1822
        goto out;
1813 1823
    }
1814 1824

  
......
1861 1871

  
1862 1872
    fd = connect_to_sdog(s->addr, s->port);
1863 1873
    if (fd < 0) {
1874
        ret = fd;
1864 1875
        goto out;
1865 1876
    }
1866 1877

  
......
1888 1899
    fd = connect_to_sdog(s->addr, s->port);
1889 1900
    if (fd < 0) {
1890 1901
        error_report("failed to connect");
1902
        ret = fd;
1891 1903
        goto out;
1892 1904
    }
1893 1905

  
......
1925 1937

  
1926 1938
    g_free(vdi_inuse);
1927 1939

  
1940
    if (ret < 0) {
1941
        return ret;
1942
    }
1943

  
1928 1944
    return found;
1929 1945
}
1930 1946

  
......
1940 1956

  
1941 1957
    fd = connect_to_sdog(s->addr, s->port);
1942 1958
    if (fd < 0) {
1943
        ret = -EIO;
1944
        goto cleanup;
1959
        return fd;
1945 1960
    }
1946 1961

  
1947 1962
    while (size) {
......
1965 1980

  
1966 1981
        if (ret < 0) {
1967 1982
            error_report("failed to save vmstate %s", strerror(errno));
1968
            ret = -EIO;
1969 1983
            goto cleanup;
1970 1984
        }
1971 1985

  

Also available in: Unified diff