static void v9fs_write(void *opaque)

{

    int cnt;

    ssize_t err;

    int32_t fid;

    int64_t off;

    int32_t count;

    int32_t len = 0;

    int32_t total = 0;

    size_t offset = 7;

    V9fsFidState *fidp;

    struct iovec iov[128]; /* FIXME: bad, bad, bad */

    struct iovec *sg = iov;

    V9fsPDU *pdu = opaque;

    V9fsState *s = pdu->s;



    pdu_unmarshal(pdu, offset, "dqdv", &fid, &off, &count, sg, &cnt);

    trace_v9fs_write(pdu->tag, pdu->id, fid, off, count, cnt);



    fidp = get_fid(pdu, fid);

    if (fidp == NULL) {

        err = -EINVAL;

        goto out_nofid;

    }

    if (fidp->fid_type == P9_FID_FILE) {

        if (fidp->fs.fd == -1) {

            err = -EINVAL;

            goto out;

        }

    } else if (fidp->fid_type == P9_FID_XATTR) {

        /*

         * setxattr operation

         */

        err = v9fs_xattr_write(s, pdu, fidp, off, count, sg, cnt);

        goto out;

    } else {

        err = -EINVAL;

        goto out;

    }

    sg = cap_sg(sg, count, &cnt);

    do {

        if (0) {

            print_sg(sg, cnt);

        }

        /* Loop in case of EINTR */

        do {

            len = v9fs_co_pwritev(pdu, fidp, sg, cnt, off);

            if (len >= 0) {

                off   += len;

                total += len;

            }

        } while (len == -EINTR && !pdu->cancelled);

        if (len < 0) {

            /* IO error return the error */

            err = len;

            goto out;

        }

        sg = adjust_sg(sg, len, &cnt);

    } while (total < count && len > 0);

    offset += pdu_marshal(pdu, offset, "d", total);

    err = offset;

    trace_v9fs_write_return(pdu->tag, pdu->id, total, err);

out:

    put_fid(pdu, fidp);

out_nofid:

    complete_pdu(s, pdu, err);

}

static void v9fs_write(void *opaque)

{

    int cnt;

    ssize_t err;

    int32_t fid;

    int64_t off;

    int32_t count;

    int32_t len = 0;

    int32_t total = 0;

    size_t offset = 7;

    V9fsFidState *fidp;

    struct iovec iov[128]; 

    struct iovec *sg = iov;

    V9fsPDU *pdu = opaque;

    V9fsState *s = pdu->s;



    pdu_unmarshal(pdu, offset, "dqdv", &fid, &off, &count, sg, &cnt);

    trace_v9fs_write(pdu->tag, pdu->id, fid, off, count, cnt);



    fidp = get_fid(pdu, fid);

    if (fidp == NULL) {

        err = -EINVAL;

        goto out_nofid;

    }

    if (fidp->fid_type == P9_FID_FILE) {

        if (fidp->fs.fd == -1) {

            err = -EINVAL;

            goto out;

        }

    } else if (fidp->fid_type == P9_FID_XATTR) {

        





        err = v9fs_xattr_write(s, pdu, fidp, off, count, sg, cnt);

        goto out;

    } else {

        err = -EINVAL;

        goto out;

    }

    sg = cap_sg(sg, count, &cnt);

    do {

        if (0) {

            print_sg(sg, cnt);

        }

        

        do {

            len = v9fs_co_pwritev(pdu, fidp, sg, cnt, off);

            if (len >= 0) {

                off   += len;

                total += len;

            }

        } while (len == -EINTR && !pdu->cancelled);

        if (len < 0) {

            

            err = len;

            goto out;

        }

        sg = adjust_sg(sg, len, &cnt);

    } while (total < count && len > 0);

    offset += pdu_marshal(pdu, offset, "d", total);

    err = offset;

    trace_v9fs_write_return(pdu->tag, pdu->id, total, err);

out:

    put_fid(pdu, fidp);

out_nofid:

    complete_pdu(s, pdu, err);

}

    } else {     int cnt;     struct iovec *sg = iov;     pdu_unmarshal(pdu, offset, "dqdv", &fid, &off, &count, sg, &cnt);     trace_v9fs_write(pdu->tag, pdu->id, fid, off, count, cnt);         err = v9fs_xattr_write(s, pdu, fidp, off, count, sg, cnt);     sg = cap_sg(sg, count, &cnt);             print_sg(sg, cnt);             len = v9fs_co_pwritev(pdu, fidp, sg, cnt, off);             goto out;         sg = adjust_sg(sg, len, &cnt);
static void FUNC_0(void *VAR_0)

{

    int VAR_1;

    ssize_t err;

    int32_t fid;

    int64_t off;

    int32_t count;

    int32_t len = 0;

    int32_t total = 0;

    size_t offset = 7;

    V9fsFidState *fidp;

    struct iovec VAR_2[128]; 

    struct iovec *VAR_3 = VAR_2;

    V9fsPDU *pdu = VAR_0;

    V9fsState *s = pdu->s;



    pdu_unmarshal(pdu, offset, "dqdv", &fid, &off, &count, VAR_3, &VAR_1);

    trace_v9fs_write(pdu->tag, pdu->id, fid, off, count, VAR_1);



    fidp = get_fid(pdu, fid);

    if (fidp == NULL) {

        err = -EINVAL;

        goto out_nofid;

    }

    if (fidp->fid_type == P9_FID_FILE) {

        if (fidp->fs.fd == -1) {

            err = -EINVAL;

            goto out;

        }

    } else if (fidp->fid_type == P9_FID_XATTR) {

        





        err = v9fs_xattr_write(s, pdu, fidp, off, count, VAR_3, VAR_1);

        goto out;

    } else {

        err = -EINVAL;

        goto out;

    }

    VAR_3 = cap_sg(VAR_3, count, &VAR_1);

    do {

        if (0) {

            print_sg(VAR_3, VAR_1);

        }

        

        do {

            len = v9fs_co_pwritev(pdu, fidp, VAR_3, VAR_1, off);

            if (len >= 0) {

                off   += len;

                total += len;

            }

        } while (len == -EINTR && !pdu->cancelled);

        if (len < 0) {

            

            err = len;

            goto out;

        }

        VAR_3 = adjust_sg(VAR_3, len, &VAR_1);

    } while (total < count && len > 0);

    offset += pdu_marshal(pdu, offset, "d", total);

    err = offset;

    trace_v9fs_write_return(pdu->tag, pdu->id, total, err);

out:

    put_fid(pdu, fidp);

out_nofid:

    complete_pdu(s, pdu, err);

}

static void FUNC_0(void *VAR_0)
{ int VAR_1; ssize_t err; int32_t fid; int64_t off; int32_t count; int32_t len = 0; int32_t total = 0; size_t offset = 7; V9fsFidState *fidp; struct iovec VAR_2[128]; struct iovec *VAR_3 = VAR_2; V9fsPDU *pdu = VAR_0; V9fsState *s = pdu->s; pdu_unmarshal(pdu, offset, "dqdv", &fid, &off, &count, VAR_3, &VAR_1); trace_v9fs_write(pdu->tag, pdu->id, fid, off, count, VAR_1); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } if (fidp->fid_type == P9_FID_FILE) { if (fidp->fs.fd == -1) { err = -EINVAL; goto out; } } else if (fidp->fid_type == P9_FID_XATTR) { err = v9fs_xattr_write(s, pdu, fidp, off, count, VAR_3, VAR_1); goto out; } else { err = -EINVAL; goto out; } VAR_3 = cap_sg(VAR_3, count, &VAR_1); do { if (0) { print_sg(VAR_3, VAR_1); } do { len = v9fs_co_pwritev(pdu, fidp, VAR_3, VAR_1, off); if (len >= 0) { off   += len; total += len; } } while (len == -EINTR && !pdu->cancelled); if (len < 0) { err = len; goto out; } VAR_3 = adjust_sg(VAR_3, len, &VAR_1); } while (total < count && len > 0); offset += pdu_marshal(pdu, offset, "d", total); err = offset; trace_v9fs_write_return(pdu->tag, pdu->id, total, err); out:
put_fid(pdu, fidp); out_nofid:
complete_pdu(s, pdu, err); }