qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] sheepdog: implement SD_OP_FLUSH_VDI operation
@ 2012-04-02 17:35 Liu Yuan
  2012-04-02 20:01 ` Michael Tokarev
  0 siblings, 1 reply; 19+ messages in thread
From: Liu Yuan @ 2012-04-02 17:35 UTC (permalink / raw)
  To: qemu-devel, morita.kazutaka; +Cc: Kevin Wolf

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

Flush operation is supposed to flush the write-back cache of
sheepdog cluster.

By issuing flush operation, we can assure the Guest of data
reaching the sheepdog cluster storage.

Cc: Kevin Wolf <kwolf@redhat.com>
Reviewd-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
---
 block/sheepdog.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 00276f6f..c08c69b 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -32,9 +32,11 @@
 #define SD_OP_RELEASE_VDI    0x13
 #define SD_OP_GET_VDI_INFO   0x14
 #define SD_OP_READ_VDIS      0x15
+#define SD_OP_FLUSH_VDI      0x16
 
 #define SD_FLAG_CMD_WRITE    0x01
 #define SD_FLAG_CMD_COW      0x02
+#define SD_FLAG_CMD_CACHE    0x04
 
 #define SD_RES_SUCCESS       0x00 /* Success */
 #define SD_RES_UNKNOWN       0x01 /* Unknown error */
@@ -179,6 +181,8 @@ typedef struct SheepdogInode {
     uint32_t data_vdi_id[MAX_DATA_OBJS];
 } SheepdogInode;
 
+static int cache_enabled;
+
 /*
  * 64 bit FNV-1a non-zero initial basis
  */
@@ -900,6 +904,10 @@ static int coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
         hdr.flags = SD_FLAG_CMD_WRITE | flags;
     }
 
+    if (cache_enabled) {
+        hdr.flags |= SD_FLAG_CMD_CACHE;
+    }
+
     hdr.oid = oid;
     hdr.cow_oid = old_oid;
     hdr.copies = s->inode.nr_copies;
@@ -965,6 +973,11 @@ static int read_write_object(int fd, char *buf, uint64_t oid, int copies,
         rlen = datalen;
         hdr.opcode = SD_OP_READ_OBJ;
     }
+
+    if (cache_enabled) {
+        hdr.flags |= SD_FLAG_CMD_CACHE;
+    }
+
     hdr.oid = oid;
     hdr.data_length = datalen;
     hdr.offset = offset;
@@ -1011,6 +1024,10 @@ static int sd_open(BlockDriverState *bs, const char *filename, int flags)
     QLIST_INIT(&s->outstanding_aio_head);
     s->fd = -1;
 
+    if (flags & BDRV_O_CACHE_WB) {
+            cache_enabled = 1;
+    }
+
     memset(vdi, 0, sizeof(vdi));
     memset(tag, 0, sizeof(tag));
     if (parse_vdiname(s, filename, vdi, &snapid, tag) < 0) {
@@ -1575,6 +1592,38 @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num,
     return acb->ret;
 }
 
+static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
+{
+    BDRVSheepdogState *s = bs->opaque;
+    SheepdogObjReq hdr = { 0 };
+    SheepdogObjRsp *rsp = (SheepdogObjRsp *)&hdr;
+    SheepdogInode *inode = &s->inode;
+    int fd, ret;
+    unsigned int wlen = 0, rlen = 0;
+
+    fd = connect_to_sdog(s->addr, s->port);
+    if (fd < 0) {
+        return -1;
+    }
+
+    hdr.opcode = SD_OP_FLUSH_VDI;
+    hdr.oid = vid_to_vdi_oid(inode->vdi_id);
+
+    ret = do_req(fd, (SheepdogReq *)&hdr, NULL, &wlen, &rlen);
+    closesocket(fd);
+    if (ret) {
+        error_report("failed to send a request to the sheep");
+        return -1;
+    }
+
+    if (rsp->result != SD_RES_SUCCESS) {
+        error_report("%s", sd_strerror(rsp->result));
+        return -1;
+    }
+
+    return 0;
+}
+
 static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
 {
     BDRVSheepdogState *s = bs->opaque;
@@ -1904,6 +1953,7 @@ BlockDriver bdrv_sheepdog = {
 
     .bdrv_co_readv  = sd_co_readv,
     .bdrv_co_writev = sd_co_writev,
+    .bdrv_co_flush_to_disk  = sd_co_flush_to_disk,
 
     .bdrv_snapshot_create   = sd_snapshot_create,
     .bdrv_snapshot_goto     = sd_snapshot_goto,
-- 
1.7.8.2

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-04-04  9:16 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-02 17:35 [Qemu-devel] [PATCH] sheepdog: implement SD_OP_FLUSH_VDI operation Liu Yuan
2012-04-02 20:01 ` Michael Tokarev
2012-04-03  5:14   ` Liu Yuan
2012-04-03  5:15   ` [Qemu-devel] [PATCH v2] " Liu Yuan
2012-04-03  7:23     ` Stefan Hajnoczi
2012-04-03  8:35       ` [Qemu-devel] [PATCH v3] " Liu Yuan
2012-04-03  9:12         ` Kevin Wolf
2012-04-03 10:04           ` [Qemu-devel] RE. [PATCH] sheepdog: fix send req helpers Liu Yuan
2012-04-03 11:13             ` MORITA Kazutaka
2012-04-03 11:34               ` Kevin Wolf
2012-04-03  9:52         ` [Qemu-devel] [PATCH v3] sheepdog: implement SD_OP_FLUSH_VDI operation MORITA Kazutaka
2012-04-03  9:58           ` [Qemu-devel] [PATCH v4] " Liu Yuan
2012-04-03 10:08             ` [Qemu-devel] [PATCH v4 UPDATE] " Liu Yuan
2012-04-03 10:32               ` MORITA Kazutaka
2012-04-03 10:30                 ` Kevin Wolf
2012-04-03 20:03                   ` [Qemu-devel] [PATCH v5] " Liu Yuan
2012-04-04  8:53                     ` Kevin Wolf
2012-04-04  8:58                       ` Liu Yuan
2012-04-04  9:20                         ` Kevin Wolf

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).