qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: qemu-devel@nongnu.org, keith.busch@intel.com, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] nvme: implement the DSM command
Date: Wed, 1 Feb 2017 16:40:50 +0000	[thread overview]
Message-ID: <20170201164050.GD12283@stefanha-x1.localdomain> (raw)
In-Reply-To: <1485800032-24404-2-git-send-email-hch@lst.de>

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

On Mon, Jan 30, 2017 at 07:13:51PM +0100, Christoph Hellwig wrote:
> +static uint16_t nvme_dsm_discard(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
> +    NvmeRequest *req)
> +{
> +    uint16_t nr = (le32_to_cpu(cmd->cdw10) & 0xff) + 1;
> +    uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
> +    uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds - BDRV_SECTOR_BITS;
> +    NvmeDsmRange *range;
> +    QEMUSGList qsg;
> +    int i;
> +
> +    range = g_new(NvmeDsmRange, nr);
> +
> +    if (nvme_map_prp(&qsg, le64_to_cpu(cmd->prp1), le64_to_cpu(cmd->prp2),
> +            sizeof(range), n)) {
> +        goto out_free_range;
> +    }
> +
> +    if (dma_buf_write((uint8_t *)range, sizeof(range), &qsg)) {

Did you mean sizeof(*range) * nr?

> +        goto out_destroy_qsg;
> +    }
> +
> +    qemu_sglist_destroy(&qsg);
> +
> +    req->status = NVME_SUCCESS;
> +    req->has_sg = false;
> +    req->aio_inflight = 1;
> +
> +    for (i = 0; i < nr; i++) {
> +        uint64_t slba = le64_to_cpu(range[i].slba);
> +        uint32_t nlb = le32_to_cpu(range[i].nlb);
> +
> +        if (slba + nlb > le64_to_cpu(ns->id_ns.nsze)) {
> +            return NVME_LBA_RANGE | NVME_DNR;

aio requests are potentially in flight, range is still allocated, and
req->aio_inflight still needs to be decremented once.  Is there cleanup
code missing here at least so range will be freed?

> +        }
> +
> +        req->aio_inflight++;
> +        req->aiocb = blk_aio_pdiscard(n->conf.blk, slba << data_shift,
> +                                      nlb << data_shift, nvme_discard_cb, req);
> +    }
> +
> +    g_free(range);
> +
> +    if (--req->aio_inflight > 0) {
> +        return NVME_NO_COMPLETE;
> +    }
> +
> +    return NVME_SUCCESS;
> +
> +out_destroy_qsg:
> +    qemu_sglist_destroy(&qsg);
> +out_free_range:
> +    g_free(range);
> +    return NVME_INVALID_FIELD | NVME_DNR;
> +}

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

  parent reply	other threads:[~2017-02-01 16:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-30 18:13 [Qemu-devel] [PATCH 0/2] two more NVMe commands Christoph Hellwig
2017-01-30 18:13 ` [Qemu-devel] [PATCH 1/2] nvme: implement the DSM command Christoph Hellwig
2017-01-30 18:55   ` Keith Busch
2017-02-01 16:40   ` Stefan Hajnoczi [this message]
2017-02-01 20:29     ` Paolo Bonzini
2017-02-02 10:17       ` Stefan Hajnoczi
2017-02-02 12:04         ` Paolo Bonzini
2017-01-30 18:13 ` [Qemu-devel] [PATCH 2/2] nvme: Implement Write Zeroes Christoph Hellwig
2017-02-01 16:41   ` 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=20170201164050.GD12283@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=hch@lst.de \
    --cc=keith.busch@intel.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).