All of lore.kernel.org
 help / color / mirror / Atom feed
From: e-t172 <e-t172@akegroup.org>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH] block/raw-posix.c: add BLKDISCARD support
Date: Fri, 11 Nov 2011 21:56:00 +0100	[thread overview]
Message-ID: <4EBD8BE0.50908@akegroup.org> (raw)

This adds ioctl(BLKDISCARD) (a.k.a "discard", "TRIM", "UNMAP", "hole
punching") support for host devices. This is especially useful if the
raw device is a SSD or some kind of thin-provisioned device.

Cc: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Etienne Dechamps <e-t172@akegroup.org>
---
  block/raw-posix.c |   20 ++++++++++++++++++++
  1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index a3de373..d6eac66 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -104,6 +104,10 @@
  #define O_DIRECT O_DSYNC
  #endif

+#ifndef BLKDISCARD
+#define BLKDISCARD _IO(0x12, 119)
+#endif
+
  #define FTYPE_FILE   0
  #define FTYPE_CD     1
  #define FTYPE_FD     2
@@ -892,6 +896,21 @@ static int hdev_has_zero_init(BlockDriverState *bs)
      return 0;
  }

+static int hdev_co_discard(BlockDriverState *bs, int64_t sector_num,
+                        int nb_sectors)
+{
+    BDRVRawState *s = bs->opaque;
+    int fd = s->fd;
+    uint64_t range[2];
+
+    range[0] = sector_num << 9;
+    range[1] = nb_sectors << 9;
+    if (ioctl(fd, BLKDISCARD, &range)) {
+        return -errno;
+    }
+    return 0;
+}
+
  static BlockDriver bdrv_host_device = {
      .format_name        = "host_device",
      .protocol_name        = "host_device",
@@ -902,6 +921,7 @@ static BlockDriver bdrv_host_device = {
      .bdrv_create        = hdev_create,
      .create_options     = raw_create_options,
      .bdrv_has_zero_init = hdev_has_zero_init,
+    .bdrv_co_discard       = hdev_co_discard,

      .bdrv_aio_readv    = raw_aio_readv,
      .bdrv_aio_writev   = raw_aio_writev,
-- 
1.7.7.1


-- 
Etienne Dechamps / e-t172 - AKE Group
Phone: +33 6 23 42 24 82

             reply	other threads:[~2011-11-11 20:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-11 20:56 e-t172 [this message]
2011-11-14 14:08 ` [Qemu-devel] [PATCH] block/raw-posix.c: add BLKDISCARD support 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=4EBD8BE0.50908@akegroup.org \
    --to=e-t172@akegroup.org \
    --cc=kwolf@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.