static int sd_snapshot_delete(BlockDriverState *bs,

                              const char *snapshot_id,

                              const char *name,

                              Error **errp)

{

    unsigned long snap_id = 0;

    char snap_tag[SD_MAX_VDI_TAG_LEN];

    Error *local_err = NULL;

    int fd, ret;

    char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];

    BDRVSheepdogState *s = bs->opaque;

    unsigned int wlen = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN, rlen = 0;

    uint32_t vid;

    SheepdogVdiReq hdr = {

        .opcode = SD_OP_DEL_VDI,

        .data_length = wlen,

        .flags = SD_FLAG_CMD_WRITE,

    };

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;



    if (!remove_objects(s)) {

        return -1;

    }



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

    memset(snap_tag, 0, sizeof(snap_tag));

    pstrcpy(buf, SD_MAX_VDI_LEN, s->name);

    ret = qemu_strtoul(snapshot_id, NULL, 10, &snap_id);

    if (ret || snap_id > UINT32_MAX) {

        error_setg(errp, "Invalid snapshot ID: %s",

                         snapshot_id ? snapshot_id : "<null>");

        return -EINVAL;

    }



    if (snap_id) {

        hdr.snapid = (uint32_t) snap_id;

    } else {

        pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id);

        pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);

    }



    ret = find_vdi_name(s, s->name, snap_id, snap_tag, &vid, true,

                        &local_err);

    if (ret) {

        return ret;

    }



    fd = connect_to_sdog(s, &local_err);

    if (fd < 0) {

        error_report_err(local_err);

        return -1;

    }



    ret = do_req(fd, s->bs, (SheepdogReq *)&hdr,

                 buf, &wlen, &rlen);

    closesocket(fd);

    if (ret) {

        return ret;

    }



    switch (rsp->result) {

    case SD_RES_NO_VDI:

        error_report("%s was already deleted", s->name);

    case SD_RES_SUCCESS:

        break;

    default:

        error_report("%s, %s", sd_strerror(rsp->result), s->name);

        return -1;

    }



    return ret;

}

static int sd_snapshot_delete(BlockDriverState *bs,

                              const char *snapshot_id,

                              const char *name,

                              Error **errp)

{

    unsigned long snap_id = 0;

    char snap_tag[SD_MAX_VDI_TAG_LEN];

    Error *local_err = NULL;

    int fd, ret;

    char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];

    BDRVSheepdogState *s = bs->opaque;

    unsigned int wlen = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN, rlen = 0;

    uint32_t vid;

    SheepdogVdiReq hdr = {

        .opcode = SD_OP_DEL_VDI,

        .data_length = wlen,

        .flags = SD_FLAG_CMD_WRITE,

    };

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;



    if (!remove_objects(s)) {

        return -1;

    }



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

    memset(snap_tag, 0, sizeof(snap_tag));

    pstrcpy(buf, SD_MAX_VDI_LEN, s->name);

    ret = qemu_strtoul(snapshot_id, NULL, 10, &snap_id);

    if (ret || snap_id > UINT32_MAX) {

        error_setg(errp, "Invalid snapshot ID: %s",

                         snapshot_id ? snapshot_id : "<null>");

        return -EINVAL;

    }



    if (snap_id) {

        hdr.snapid = (uint32_t) snap_id;

    } else {

        pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id);

        pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);

    }



    ret = find_vdi_name(s, s->name, snap_id, snap_tag, &vid, true,

                        &local_err);

    if (ret) {

        return ret;

    }



    fd = connect_to_sdog(s, &local_err);

    if (fd < 0) {

        error_report_err(local_err);

        return -1;

    }



    ret = do_req(fd, s->bs, (SheepdogReq *)&hdr,

                 buf, &wlen, &rlen);

    closesocket(fd);

    if (ret) {

        return ret;

    }



    switch (rsp->result) {

    case SD_RES_NO_VDI:

        error_report("%s was already deleted", s->name);

    case SD_RES_SUCCESS:

        break;

    default:

        error_report("%s, %s", sd_strerror(rsp->result), s->name);

        return -1;

    }



    return ret;

}

    Error *local_err = NULL;     fd = connect_to_sdog(s, &local_err);         error_report_err(local_err);     Error *local_err = NULL;     if (!remove_objects(s)) {         return -1;     ret = find_vdi_name(s, s->name, snap_id, snap_tag, &vid, true,                         &local_err);     fd = connect_to_sdog(s, &local_err);         error_report_err(local_err);         return -1;         error_report("%s was already deleted", s->name);         error_report("%s, %s", sd_strerror(rsp->result), s->name);         return -1;     return ret;
static int FUNC_0(BlockDriverState *VAR_0,

                              const char *VAR_1,

                              const char *VAR_2,

                              Error **VAR_3)

{

    unsigned long VAR_4 = 0;

    char VAR_5[SD_MAX_VDI_TAG_LEN];

    Error *local_err = NULL;

    int VAR_6, VAR_7;

    char VAR_8[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];

    BDRVSheepdogState *s = VAR_0->opaque;

    unsigned int VAR_9 = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN, VAR_10 = 0;

    uint32_t vid;

    SheepdogVdiReq hdr = {

        .opcode = SD_OP_DEL_VDI,

        .data_length = VAR_9,

        .flags = SD_FLAG_CMD_WRITE,

    };

    SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;



    if (!remove_objects(s)) {

        return -1;

    }



    memset(VAR_8, 0, sizeof(VAR_8));

    memset(VAR_5, 0, sizeof(VAR_5));

    pstrcpy(VAR_8, SD_MAX_VDI_LEN, s->VAR_2);

    VAR_7 = qemu_strtoul(VAR_1, NULL, 10, &VAR_4);

    if (VAR_7 || VAR_4 > UINT32_MAX) {

        error_setg(VAR_3, "Invalid snapshot ID: %s",

                         VAR_1 ? VAR_1 : "<null>");

        return -EINVAL;

    }



    if (VAR_4) {

        hdr.snapid = (uint32_t) VAR_4;

    } else {

        pstrcpy(VAR_5, sizeof(VAR_5), VAR_1);

        pstrcpy(VAR_8 + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, VAR_5);

    }



    VAR_7 = find_vdi_name(s, s->VAR_2, VAR_4, VAR_5, &vid, true,

                        &local_err);

    if (VAR_7) {

        return VAR_7;

    }



    VAR_6 = connect_to_sdog(s, &local_err);

    if (VAR_6 < 0) {

        error_report_err(local_err);

        return -1;

    }



    VAR_7 = do_req(VAR_6, s->VAR_0, (SheepdogReq *)&hdr,

                 VAR_8, &VAR_9, &VAR_10);

    closesocket(VAR_6);

    if (VAR_7) {

        return VAR_7;

    }



    switch (rsp->result) {

    case SD_RES_NO_VDI:

        error_report("%s was already deleted", s->VAR_2);

    case SD_RES_SUCCESS:

        break;

    default:

        error_report("%s, %s", sd_strerror(rsp->result), s->VAR_2);

        return -1;

    }



    return VAR_7;

}

static int FUNC_0(BlockDriverState *VAR_0,
const char *VAR_1,
const char *VAR_2,
Error **VAR_3)
{ unsigned long VAR_4 = 0; char VAR_5[SD_MAX_VDI_TAG_LEN]; Error *local_err = NULL; int VAR_6, VAR_7; char VAR_8[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN]; BDRVSheepdogState *s = VAR_0->opaque; unsigned int VAR_9 = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN, VAR_10 = 0; uint32_t vid; SheepdogVdiReq hdr = { .opcode = SD_OP_DEL_VDI,
.data_length = VAR_9,
.flags = SD_FLAG_CMD_WRITE,
}; SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr; if (!remove_objects(s)) { return -1; } memset(VAR_8, 0, sizeof(VAR_8)); memset(VAR_5, 0, sizeof(VAR_5)); pstrcpy(VAR_8, SD_MAX_VDI_LEN, s->VAR_2); VAR_7 = qemu_strtoul(VAR_1, NULL, 10, &VAR_4); if (VAR_7 || VAR_4 > UINT32_MAX) { error_setg(VAR_3, "Invalid snapshot ID: %s",
VAR_1 ? VAR_1 : "<null>"); return -EINVAL; } if (VAR_4) { hdr.snapid = (uint32_t) VAR_4; } else { pstrcpy(VAR_5, sizeof(VAR_5), VAR_1); pstrcpy(VAR_8 + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, VAR_5); } VAR_7 = find_vdi_name(s, s->VAR_2, VAR_4, VAR_5, &vid, true,
&local_err); if (VAR_7) { return VAR_7; } VAR_6 = connect_to_sdog(s, &local_err); if (VAR_6 < 0) { error_report_err(local_err); return -1; } VAR_7 = do_req(VAR_6, s->VAR_0, (SheepdogReq *)&hdr,
VAR_8, &VAR_9, &VAR_10); closesocket(VAR_6); if (VAR_7) { return VAR_7; } switch (rsp->result) { case SD_RES_NO_VDI:
error_report("%s was already deleted", s->VAR_2); case SD_RES_SUCCESS:
break; default:
error_report("%s, %s", sd_strerror(rsp->result), s->VAR_2); return -1; } return VAR_7; }