qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liu Yuan <namei.unix@gmail.com>
To: sheepdog@lists.wpkg.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/3] sheep: teach sheep to discard unused objects
Date: Sat, 13 Apr 2013 19:27:20 +0800	[thread overview]
Message-ID: <1365852442-28941-3-git-send-email-namei.unix@gmail.com> (raw)
In-Reply-To: <1365852442-28941-1-git-send-email-namei.unix@gmail.com>

From: Liu Yuan <tailai.ly@taobao.com>

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
---
 include/sheepdog_proto.h |    1 +
 sheep/ops.c              |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index f3d69e1..99a6627 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -35,6 +35,7 @@
 #define SD_OP_GET_VDI_INFO   0x14
 #define SD_OP_READ_VDIS      0x15
 #define SD_OP_FLUSH_VDI      0x16
+#define SD_OP_DISCARD        0x17
 
 #define SD_FLAG_CMD_WRITE    0x01
 #define SD_FLAG_CMD_COW      0x02
diff --git a/sheep/ops.c b/sheep/ops.c
index a0502b2..8f6b0c1 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -741,6 +741,20 @@ static int local_flush_vdi(struct request *req)
 	return ret;
 }
 
+static int local_discard(struct request *req)
+{
+	uint64_t oid = req->rq.obj.oid;
+	uint32_t vid = oid_to_vid(oid), zero = 0;
+	int ret, cp = get_vdi_copy_number(vid), idx = data_oid_to_idx(oid);
+
+	sd_dprintf("%"PRIx64, oid);
+	ret = remove_object(oid, cp);
+	if (ret != SD_RES_SUCCESS)
+		return ret;
+	return write_object(vid_to_vdi_oid(vid), (char *)&zero, sizeof(zero),
+			    SD_INODE_HEADER_SIZE + sizeof(vid) * idx, 0, cp);
+}
+
 static int local_flush_and_del(struct request *req)
 {
 	if (!sys->enable_object_cache)
@@ -1109,6 +1123,12 @@ static struct sd_op_template sd_ops[] = {
 		.process_work = local_flush_vdi,
 	},
 
+	[SD_OP_DISCARD] = {
+		.name = "DISCARD",
+		.type = SD_OP_TYPE_LOCAL,
+		.process_work = local_discard,
+	},
+
 	[SD_OP_FLUSH_DEL_CACHE] = {
 		.name = "DEL_CACHE",
 		.type = SD_OP_TYPE_LOCAL,
-- 
1.7.9.5

  parent reply	other threads:[~2013-04-13 11:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-13 11:27 [Qemu-devel] [PATCH For SD and QEMU] Add discard/trim support for Sheepdog Liu Yuan
2013-04-13 11:27 ` [Qemu-devel] [PATCH 1/3] sheep: remove unused 'flags' in remove_object() Liu Yuan
2013-04-13 11:27 ` Liu Yuan [this message]
2013-04-13 11:27 ` [Qemu-devel] [PATCH 3/3] tests: add 058 to test discard/trim Liu Yuan
2013-04-13 11:27 ` [Qemu-devel] [PATCH for QEMU] sheepdog: add discard/trim support for sheepdog Liu Yuan
2013-04-14  5:07   ` [Qemu-devel] [PATCH for QEMU v2] " Liu Yuan
2013-04-14  5:16   ` [Qemu-devel] [PATCH for QEMU v3] " Liu Yuan
2013-04-15 15:10     ` [Qemu-devel] [sheepdog] " MORITA Kazutaka
2013-04-15 15:52   ` [Qemu-devel] [PATCH v4] " Liu Yuan
2013-04-15 16:03     ` [Qemu-devel] [sheepdog] " MORITA Kazutaka
2013-04-15 16:15   ` [Qemu-devel] [PATCH v5] " Liu Yuan
2013-04-15 16:25     ` [Qemu-devel] [sheepdog] " MORITA Kazutaka
2013-04-16  8:18     ` [Qemu-devel] " Stefan Hajnoczi
2013-04-16  8:47       ` Kevin Wolf
2013-04-16  9:08         ` Liu Yuan

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=1365852442-28941-3-git-send-email-namei.unix@gmail.com \
    --to=namei.unix@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sheepdog@lists.wpkg.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).