qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Chrysostomos Nanakos <cnanakos@grnet.gr>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v6 3/5] block/archipelago: Add support for creating images
Date: Mon, 21 Jul 2014 17:01:51 +0100	[thread overview]
Message-ID: <20140721160151.GB26753@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1403857452-23768-4-git-send-email-cnanakos@grnet.gr>

[-- Attachment #1: Type: text/plain, Size: 3646 bytes --]

On Fri, Jun 27, 2014 at 11:24:10AM +0300, Chrysostomos Nanakos wrote:
> +static int qemu_archipelago_create_volume(Error **errp, const char *volname,
> +                                          char *segment_name,
> +                                          uint64_t size, xport mportno,
> +                                          xport vportno)
> +{
> +    int ret, targetlen;
> +    struct xseg *xseg = NULL;
> +    struct xseg_request *req;
> +    struct xseg_request_clone *xclone;
> +    struct xseg_port *port;
> +    xport srcport = NoPort, sport = NoPort;
> +    char *target;
> +
> +    /* Try default values if none has been set */
> +    if (mportno == (xport) -1) {
> +        mportno = 1001;
> +    }
> +
> +    if (vportno == (xport) -1) {
> +        vportno = 501;
> +    }
> +
> +    if (segment_name == NULL) {
> +        segment_name = g_strdup("archipelago");
> +    }
> +
> +    if (xseg_initialize()) {
> +        error_setg(errp, "Cannot initialize XSEG");
> +        return -1;

Leaks segment_name (if internally allocated)

> +    }
> +
> +    xseg = xseg_join((char *)"posix", segment_name,
> +                     (char *)"posixfd", NULL);
> +
> +    if (!xseg) {
> +        error_setg(errp, "Cannot join XSEG shared memory segment");
> +        return -1;

Leaks segment_name (if internally allocated)

> +    }
> +
> +    port = xseg_bind_dynport(xseg);
> +    srcport = port->portno;
> +    init_local_signal(xseg, sport, srcport);
> +
> +    req = xseg_get_request(xseg, srcport, mportno, X_ALLOC);
> +    if (!req) {
> +        error_setg(errp, "Cannot get XSEG request");
> +        return -1;

Leaks segment_name (if internally allocated)

> +    }
> +
> +    targetlen = strlen(volname);
> +    ret = xseg_prep_request(xseg, req, targetlen,
> +                            sizeof(struct xseg_request_clone));
> +    if (ret < 0) {
> +        error_setg(errp, "Cannot prepare XSEG request");
> +        goto err_exit;
> +    }
> +
> +    target = xseg_get_target(xseg, req);
> +    if (!target) {
> +        error_setg(errp, "Cannot get XSEG target.\n");
> +        goto err_exit;
> +    }
> +    memcpy(target, volname, targetlen);
> +    xclone = (struct xseg_request_clone *) xseg_get_data(xseg, req);
> +    memset(xclone->target, 0 , XSEG_MAX_TARGETLEN);
> +    xclone->targetlen = 0;
> +    xclone->size = size;
> +    req->offset = 0;
> +    req->size = req->datalen;
> +    req->op = X_CLONE;
> +
> +    xport p = xseg_submit(xseg, req, srcport, X_ALLOC);
> +    if (p == NoPort) {
> +        error_setg(errp, "Could not submit XSEG request");
> +        goto err_exit;
> +    }
> +    xseg_signal(xseg, p);
> +
> +    ret = wait_reply(xseg, srcport, port, req);
> +    if (ret < 0) {
> +        error_setg(errp, "wait_reply() error.");
> +    }
> +
> +    xseg_put_request(xseg, req, srcport);
> +    xseg_quit_local_signal(xseg, srcport);
> +    xseg_leave_dynport(xseg, port);
> +    xseg_leave(xseg);
> +    return ret;
> +
> +err_exit:
> +    xseg_put_request(xseg, req, srcport);
> +    xseg_quit_local_signal(xseg, srcport);
> +    xseg_leave_dynport(xseg, port);
> +    xseg_leave(xseg);
> +    return -1;

Leaks segment_name (if internally allocated)

> +    /* Create an Archipelago volume */
> +    ret = qemu_archipelago_create_volume(errp, volname, segment_name,
> +                                         total_size, mport,
> +                                         vport);
> +
> +    if (volname) {
> +        g_free(volname);
> +    }
> +    if (segment_name) {
> +        g_free(segment_name);
> +    }

g_free(NULL) is a nop.  The if statement isn't needed to check NULL
pointers.

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  parent reply	other threads:[~2014-07-21 16:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27  8:24 [Qemu-devel] [PATCH v6 0/5] Support Archipelago as a QEMU block backend Chrysostomos Nanakos
2014-06-27  8:24 ` [Qemu-devel] [PATCH v6 1/5] block: " Chrysostomos Nanakos
2014-07-02 13:59   ` Eric Blake
2014-07-02 14:18     ` Chrysostomos Nanakos
2014-07-02 14:30       ` Eric Blake
2014-07-10  0:23   ` Jeff Cody
2014-07-10 10:04     ` Chrysostomos Nanakos
2014-07-10 14:02       ` Chrysostomos Nanakos
2014-07-22 12:40       ` Stefan Hajnoczi
2014-07-22 12:35   ` Stefan Hajnoczi
2014-06-27  8:24 ` [Qemu-devel] [PATCH v6 2/5] block/archipelago: Implement bdrv_parse_filename() Chrysostomos Nanakos
2014-07-21 15:55   ` Stefan Hajnoczi
2014-06-27  8:24 ` [Qemu-devel] [PATCH v6 3/5] block/archipelago: Add support for creating images Chrysostomos Nanakos
2014-07-02 14:01   ` Eric Blake
2014-07-02 14:06     ` Chrysostomos Nanakos
2014-07-21 16:01   ` Stefan Hajnoczi [this message]
2014-06-27  8:24 ` [Qemu-devel] [PATCH v6 4/5] QMP: Add support for Archipelago Chrysostomos Nanakos
2014-07-02 13:58   ` Eric Blake
2014-07-02 14:11     ` Chrysostomos Nanakos
2014-07-02 14:22       ` Eric Blake
2014-06-27  8:24 ` [Qemu-devel] [PATCH v6 5/5] qemu-iotests: add support for Archipelago protocol Chrysostomos Nanakos
2014-07-21 16:02   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140721160151.GB26753@stefanha-thinkpad.redhat.com \
    --to=stefanha@gmail.com \
    --cc=cnanakos@grnet.gr \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).