static int multiwrite_f(BlockBackend *blk, int argc, char **argv)

{

    struct timeval t1, t2;

    int Cflag = 0, qflag = 0;

    int c, cnt;

    char **buf;

    int64_t offset, first_offset = 0;

    /* Some compilers get confused and warn if this is not initialized.  */

    int total = 0;

    int nr_iov;

    int nr_reqs;

    int pattern = 0xcd;

    QEMUIOVector *qiovs;

    int i;

    BlockRequest *reqs;



    while ((c = getopt(argc, argv, "CqP:")) != EOF) {

        switch (c) {

        case 'C':

            Cflag = 1;

            break;

        case 'q':

            qflag = 1;

            break;

        case 'P':

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        default:

            return qemuio_command_usage(&writev_cmd);

        }

    }



    if (optind > argc - 2) {

        return qemuio_command_usage(&writev_cmd);

    }



    nr_reqs = 1;

    for (i = optind; i < argc; i++) {

        if (!strcmp(argv[i], ";")) {

            nr_reqs++;

        }

    }



    reqs = g_new0(BlockRequest, nr_reqs);

    buf = g_new0(char *, nr_reqs);

    qiovs = g_new(QEMUIOVector, nr_reqs);



    for (i = 0; i < nr_reqs && optind < argc; i++) {

        int j;



        /* Read the offset of the request */

        offset = cvtnum(argv[optind]);

        if (offset < 0) {

            printf("non-numeric offset argument -- %s\n", argv[optind]);

            goto out;

        }

        optind++;



        if (offset & 0x1ff) {

            printf("offset %lld is not sector aligned\n",

                   (long long)offset);

            goto out;

        }



        if (i == 0) {

            first_offset = offset;

        }



        /* Read lengths for qiov entries */

        for (j = optind; j < argc; j++) {

            if (!strcmp(argv[j], ";")) {

                break;

            }

        }



        nr_iov = j - optind;



        /* Build request */

        buf[i] = create_iovec(blk, &qiovs[i], &argv[optind], nr_iov, pattern);

        if (buf[i] == NULL) {

            goto out;

        }



        reqs[i].qiov = &qiovs[i];

        reqs[i].sector = offset >> 9;

        reqs[i].nb_sectors = reqs[i].qiov->size >> 9;



        optind = j + 1;



        pattern++;

    }



    /* If there were empty requests at the end, ignore them */

    nr_reqs = i;



    gettimeofday(&t1, NULL);

    cnt = do_aio_multiwrite(blk, reqs, nr_reqs, &total);

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

        printf("aio_multiwrite failed: %s\n", strerror(-cnt));

        goto out;

    }



    if (qflag) {

        goto out;

    }



    /* Finally, report back -- -C gives a parsable format */

    t2 = tsub(t2, t1);

    print_report("wrote", &t2, first_offset, total, total, cnt, Cflag);

out:

    for (i = 0; i < nr_reqs; i++) {

        qemu_io_free(buf[i]);

        if (reqs[i].qiov != NULL) {

            qemu_iovec_destroy(&qiovs[i]);

        }

    }

    g_free(buf);

    g_free(reqs);

    g_free(qiovs);

    return 0;

}

static int multiwrite_f(BlockBackend *blk, int argc, char **argv)

{

    struct timeval t1, t2;

    int Cflag = 0, qflag = 0;

    int c, cnt;

    char **buf;

    int64_t offset, first_offset = 0;

    

    int total = 0;

    int nr_iov;

    int nr_reqs;

    int pattern = 0xcd;

    QEMUIOVector *qiovs;

    int i;

    BlockRequest *reqs;



    while ((c = getopt(argc, argv, "CqP:")) != EOF) {

        switch (c) {

        case 'C':

            Cflag = 1;

            break;

        case 'q':

            qflag = 1;

            break;

        case 'P':

            pattern = parse_pattern(optarg);

            if (pattern < 0) {

                return 0;

            }

            break;

        default:

            return qemuio_command_usage(&writev_cmd);

        }

    }



    if (optind > argc - 2) {

        return qemuio_command_usage(&writev_cmd);

    }



    nr_reqs = 1;

    for (i = optind; i < argc; i++) {

        if (!strcmp(argv[i], ";")) {

            nr_reqs++;

        }

    }



    reqs = g_new0(BlockRequest, nr_reqs);

    buf = g_new0(char *, nr_reqs);

    qiovs = g_new(QEMUIOVector, nr_reqs);



    for (i = 0; i < nr_reqs && optind < argc; i++) {

        int j;



        

        offset = cvtnum(argv[optind]);

        if (offset < 0) {

            printf("non-numeric offset argument -- %s\n", argv[optind]);

            goto out;

        }

        optind++;



        if (offset & 0x1ff) {

            printf("offset %lld is not sector aligned\n",

                   (long long)offset);

            goto out;

        }



        if (i == 0) {

            first_offset = offset;

        }



        

        for (j = optind; j < argc; j++) {

            if (!strcmp(argv[j], ";")) {

                break;

            }

        }



        nr_iov = j - optind;



        

        buf[i] = create_iovec(blk, &qiovs[i], &argv[optind], nr_iov, pattern);

        if (buf[i] == NULL) {

            goto out;

        }



        reqs[i].qiov = &qiovs[i];

        reqs[i].sector = offset >> 9;

        reqs[i].nb_sectors = reqs[i].qiov->size >> 9;



        optind = j + 1;



        pattern++;

    }



    

    nr_reqs = i;



    gettimeofday(&t1, NULL);

    cnt = do_aio_multiwrite(blk, reqs, nr_reqs, &total);

    gettimeofday(&t2, NULL);



    if (cnt < 0) {

        printf("aio_multiwrite failed: %s\n", strerror(-cnt));

        goto out;

    }



    if (qflag) {

        goto out;

    }



    

    t2 = tsub(t2, t1);

    print_report("wrote", &t2, first_offset, total, total, cnt, Cflag);

out:

    for (i = 0; i < nr_reqs; i++) {

        qemu_io_free(buf[i]);

        if (reqs[i].qiov != NULL) {

            qemu_iovec_destroy(&qiovs[i]);

        }

    }

    g_free(buf);

    g_free(reqs);

    g_free(qiovs);

    return 0;

}

static int FUNC_0(BlockBackend *VAR_0, int VAR_1, char **VAR_2)

{

    struct timeval VAR_3, VAR_4;

    int VAR_5 = 0, VAR_6 = 0;

    int VAR_7, VAR_8;

    char **VAR_9;

    int64_t offset, first_offset = 0;

    

    int VAR_10 = 0;

    int VAR_11;

    int VAR_12;

    int VAR_13 = 0xcd;

    QEMUIOVector *qiovs;

    int VAR_14;

    BlockRequest *reqs;



    while ((VAR_7 = getopt(VAR_1, VAR_2, "CqP:")) != EOF) {

        switch (VAR_7) {

        case 'C':

            VAR_5 = 1;

            break;

        case 'q':

            VAR_6 = 1;

            break;

        case 'P':

            VAR_13 = parse_pattern(optarg);

            if (VAR_13 < 0) {

                return 0;

            }

            break;

        default:

            return qemuio_command_usage(&writev_cmd);

        }

    }



    if (optind > VAR_1 - 2) {

        return qemuio_command_usage(&writev_cmd);

    }



    VAR_12 = 1;

    for (VAR_14 = optind; VAR_14 < VAR_1; VAR_14++) {

        if (!strcmp(VAR_2[VAR_14], ";")) {

            VAR_12++;

        }

    }



    reqs = g_new0(BlockRequest, VAR_12);

    VAR_9 = g_new0(char *, VAR_12);

    qiovs = g_new(QEMUIOVector, VAR_12);



    for (VAR_14 = 0; VAR_14 < VAR_12 && optind < VAR_1; VAR_14++) {

        int j;



        

        offset = cvtnum(VAR_2[optind]);

        if (offset < 0) {

            printf("non-numeric offset argument -- %s\n", VAR_2[optind]);

            goto out;

        }

        optind++;



        if (offset & 0x1ff) {

            printf("offset %lld is not sector aligned\n",

                   (long long)offset);

            goto out;

        }



        if (VAR_14 == 0) {

            first_offset = offset;

        }



        

        for (j = optind; j < VAR_1; j++) {

            if (!strcmp(VAR_2[j], ";")) {

                break;

            }

        }



        VAR_11 = j - optind;



        

        VAR_9[VAR_14] = create_iovec(VAR_0, &qiovs[VAR_14], &VAR_2[optind], VAR_11, VAR_13);

        if (VAR_9[VAR_14] == NULL) {

            goto out;

        }



        reqs[VAR_14].qiov = &qiovs[VAR_14];

        reqs[VAR_14].sector = offset >> 9;

        reqs[VAR_14].nb_sectors = reqs[VAR_14].qiov->size >> 9;



        optind = j + 1;



        VAR_13++;

    }



    

    VAR_12 = VAR_14;



    gettimeofday(&VAR_3, NULL);

    VAR_8 = do_aio_multiwrite(VAR_0, reqs, VAR_12, &VAR_10);

    gettimeofday(&VAR_4, NULL);



    if (VAR_8 < 0) {

        printf("aio_multiwrite failed: %s\n", strerror(-VAR_8));

        goto out;

    }



    if (VAR_6) {

        goto out;

    }



    

    VAR_4 = tsub(VAR_4, VAR_3);

    print_report("wrote", &VAR_4, first_offset, VAR_10, VAR_10, VAR_8, VAR_5);

out:

    for (VAR_14 = 0; VAR_14 < VAR_12; VAR_14++) {

        qemu_io_free(VAR_9[VAR_14]);

        if (reqs[VAR_14].qiov != NULL) {

            qemu_iovec_destroy(&qiovs[VAR_14]);

        }

    }

    g_free(VAR_9);

    g_free(reqs);

    g_free(qiovs);

    return 0;

}

static int FUNC_0(BlockBackend *VAR_0, int VAR_1, char **VAR_2)
{ struct timeval VAR_3, VAR_4; int VAR_5 = 0, VAR_6 = 0; int VAR_7, VAR_8; char **VAR_9; int64_t offset, first_offset = 0; int VAR_10 = 0; int VAR_11; int VAR_12; int VAR_13 = 0xcd; QEMUIOVector *qiovs; int VAR_14; BlockRequest *reqs; while ((VAR_7 = getopt(VAR_1, VAR_2, "CqP:")) != EOF) { switch (VAR_7) { case 'C':
VAR_5 = 1; break; case 'q':
VAR_6 = 1; break; case 'P':
VAR_13 = parse_pattern(optarg); if (VAR_13 < 0) { return 0; } break; default:
return qemuio_command_usage(&writev_cmd); } } if (optind > VAR_1 - 2) { return qemuio_command_usage(&writev_cmd); } VAR_12 = 1; for (VAR_14 = optind; VAR_14 < VAR_1; VAR_14++) { if (!strcmp(VAR_2[VAR_14], ";")) { VAR_12++; } } reqs = g_new0(BlockRequest, VAR_12); VAR_9 = g_new0(char *, VAR_12); qiovs = g_new(QEMUIOVector, VAR_12); for (VAR_14 = 0; VAR_14 < VAR_12 && optind < VAR_1; VAR_14++) { int j; offset = cvtnum(VAR_2[optind]); if (offset < 0) { printf("non-numeric offset argument -- %s\n", VAR_2[optind]); goto out; } optind++; if (offset & 0x1ff) { printf("offset %lld is not sector aligned\n",
(long long)offset); goto out; } if (VAR_14 == 0) { first_offset = offset; } for (j = optind; j < VAR_1; j++) { if (!strcmp(VAR_2[j], ";")) { break; } } VAR_11 = j - optind; VAR_9[VAR_14] = create_iovec(VAR_0, &qiovs[VAR_14], &VAR_2[optind], VAR_11, VAR_13); if (VAR_9[VAR_14] == NULL) { goto out; } reqs[VAR_14].qiov = &qiovs[VAR_14]; reqs[VAR_14].sector = offset >> 9; reqs[VAR_14].nb_sectors = reqs[VAR_14].qiov->size >> 9; optind = j + 1; VAR_13++; } VAR_12 = VAR_14; gettimeofday(&VAR_3, NULL); VAR_8 = do_aio_multiwrite(VAR_0, reqs, VAR_12, &VAR_10); gettimeofday(&VAR_4, NULL); if (VAR_8 < 0) { printf("aio_multiwrite failed: %s\n", strerror(-VAR_8)); goto out; } if (VAR_6) { goto out; } VAR_4 = tsub(VAR_4, VAR_3); print_report("wrote", &VAR_4, first_offset, VAR_10, VAR_10, VAR_8, VAR_5); out:
for (VAR_14 = 0; VAR_14 < VAR_12; VAR_14++) { qemu_io_free(VAR_9[VAR_14]); if (reqs[VAR_14].qiov != NULL) { qemu_iovec_destroy(&qiovs[VAR_14]); } } g_free(VAR_9); g_free(reqs); g_free(qiovs); return 0; }