static int find_vdi_name(BDRVSheepdogState *s, char *filename, uint32_t snapid,

                         char *tag, uint32_t *vid, int for_snapshot)

{

    int ret, fd;

    SheepdogVdiReq hdr;

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;

    unsigned int wlen, rlen = 0;

    char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];



    fd = connect_to_sdog(s->addr, s->port);

    if (fd < 0) {

        return fd;

    }



    memset(buf, 0, sizeof(buf));

    strncpy(buf, filename, SD_MAX_VDI_LEN);

    strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN);



    memset(&hdr, 0, sizeof(hdr));

    if (for_snapshot) {

        hdr.opcode = SD_OP_GET_VDI_INFO;

    } else {

        hdr.opcode = SD_OP_LOCK_VDI;

    }

    wlen = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN;

    hdr.proto_ver = SD_PROTO_VER;

    hdr.data_length = wlen;

    hdr.snapid = snapid;

    hdr.flags = SD_FLAG_CMD_WRITE;



    ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen);

    if (ret) {

        goto out;

    }



    if (rsp->result != SD_RES_SUCCESS) {

        error_report("cannot get vdi info, %s, %s %d %s",

                     sd_strerror(rsp->result), filename, snapid, tag);

        if (rsp->result == SD_RES_NO_VDI) {

            ret = -ENOENT;

        } else {

            ret = -EIO;

        }

        goto out;

    }

    *vid = rsp->vdi_id;



    ret = 0;

out:

    closesocket(fd);

    return ret;

}

static int find_vdi_name(BDRVSheepdogState *s, char *filename, uint32_t snapid,

                         char *tag, uint32_t *vid, int for_snapshot)

{

    int ret, fd;

    SheepdogVdiReq hdr;

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;

    unsigned int wlen, rlen = 0;

    char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];



    fd = connect_to_sdog(s->addr, s->port);

    if (fd < 0) {

        return fd;

    }



    memset(buf, 0, sizeof(buf));

    strncpy(buf, filename, SD_MAX_VDI_LEN);

    strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN);



    memset(&hdr, 0, sizeof(hdr));

    if (for_snapshot) {

        hdr.opcode = SD_OP_GET_VDI_INFO;

    } else {

        hdr.opcode = SD_OP_LOCK_VDI;

    }

    wlen = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN;

    hdr.proto_ver = SD_PROTO_VER;

    hdr.data_length = wlen;

    hdr.snapid = snapid;

    hdr.flags = SD_FLAG_CMD_WRITE;



    ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen);

    if (ret) {

        goto out;

    }



    if (rsp->result != SD_RES_SUCCESS) {

        error_report("cannot get vdi info, %s, %s %d %s",

                     sd_strerror(rsp->result), filename, snapid, tag);

        if (rsp->result == SD_RES_NO_VDI) {

            ret = -ENOENT;

        } else {

            ret = -EIO;

        }

        goto out;

    }

    *vid = rsp->vdi_id;



    ret = 0;

out:

    closesocket(fd);

    return ret;

}

    memset(buf, 0, sizeof(buf));     strncpy(buf, filename, SD_MAX_VDI_LEN);
static int FUNC_0(BDRVSheepdogState *VAR_0, char *VAR_1, uint32_t VAR_2,

                         char *VAR_3, uint32_t *VAR_4, int VAR_5)

{

    int VAR_6, VAR_7;

    SheepdogVdiReq hdr;

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;

    unsigned int VAR_8, VAR_9 = 0;

    char VAR_10[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];



    VAR_7 = connect_to_sdog(VAR_0->addr, VAR_0->port);

    if (VAR_7 < 0) {

        return VAR_7;

    }



    memset(VAR_10, 0, sizeof(VAR_10));

    strncpy(VAR_10, VAR_1, SD_MAX_VDI_LEN);

    strncpy(VAR_10 + SD_MAX_VDI_LEN, VAR_3, SD_MAX_VDI_TAG_LEN);



    memset(&hdr, 0, sizeof(hdr));

    if (VAR_5) {

        hdr.opcode = SD_OP_GET_VDI_INFO;

    } else {

        hdr.opcode = SD_OP_LOCK_VDI;

    }

    VAR_8 = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN;

    hdr.proto_ver = SD_PROTO_VER;

    hdr.data_length = VAR_8;

    hdr.VAR_2 = VAR_2;

    hdr.flags = SD_FLAG_CMD_WRITE;



    VAR_6 = do_req(VAR_7, (SheepdogReq *)&hdr, VAR_10, &VAR_8, &VAR_9);

    if (VAR_6) {

        goto out;

    }



    if (rsp->result != SD_RES_SUCCESS) {

        error_report("cannot get vdi info, %VAR_0, %VAR_0 %d %VAR_0",

                     sd_strerror(rsp->result), VAR_1, VAR_2, VAR_3);

        if (rsp->result == SD_RES_NO_VDI) {

            VAR_6 = -ENOENT;

        } else {

            VAR_6 = -EIO;

        }

        goto out;

    }

    *VAR_4 = rsp->vdi_id;



    VAR_6 = 0;

out:

    closesocket(VAR_7);

    return VAR_6;

}

static int FUNC_0(BDRVSheepdogState *VAR_0, char *VAR_1, uint32_t VAR_2,
char *VAR_3, uint32_t *VAR_4, int VAR_5)
{ int VAR_6, VAR_7; SheepdogVdiReq hdr; SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr; unsigned int VAR_8, VAR_9 = 0; char VAR_10[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN]; VAR_7 = connect_to_sdog(VAR_0->addr, VAR_0->port); if (VAR_7 < 0) { return VAR_7; } memset(VAR_10, 0, sizeof(VAR_10)); strncpy(VAR_10, VAR_1, SD_MAX_VDI_LEN); strncpy(VAR_10 + SD_MAX_VDI_LEN, VAR_3, SD_MAX_VDI_TAG_LEN); memset(&hdr, 0, sizeof(hdr)); if (VAR_5) { hdr.opcode = SD_OP_GET_VDI_INFO; } else { hdr.opcode = SD_OP_LOCK_VDI; } VAR_8 = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN; hdr.proto_ver = SD_PROTO_VER; hdr.data_length = VAR_8; hdr.VAR_2 = VAR_2; hdr.flags = SD_FLAG_CMD_WRITE; VAR_6 = do_req(VAR_7, (SheepdogReq *)&hdr, VAR_10, &VAR_8, &VAR_9); if (VAR_6) { goto out; } if (rsp->result != SD_RES_SUCCESS) { error_report("cannot get vdi info, %VAR_0, %VAR_0 %d %VAR_0",
sd_strerror(rsp->result), VAR_1, VAR_2, VAR_3); if (rsp->result == SD_RES_NO_VDI) { VAR_6 = -ENOENT; } else { VAR_6 = -EIO; } goto out; } *VAR_4 = rsp->vdi_id; VAR_6 = 0; out:
closesocket(VAR_7); return VAR_6; }