Skip to contentSkip to conversation

sheepdog driver update

PATCH Applied Hitoshi Mitake 4 participants 10 messages Sep 1, 2015 – Sep 25, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

cover sheepdog driver update

This patchset has two patches. The first one is a defensive purpose for rare cases. It is an improvement of the previous commit 96b14ff85acf. The second one is refining discard operation caused by fstrim command, etc. Current sheepdog driver corrupts VDIs when the discard operation is issued. This patch solves the problem.

Hitoshi Mitake (2):
sheepdog: use per AIOCB dirty indexes for non overlapping requests
sheepdog: refine discard support

 block/sheepdog.c | 92 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 55 insertions(+), 37 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 sheepdog: use per AIOCB dirty indexes for non overlapping requests

In the commit 96b14ff85acf, requests for overlapping areas are serialized. However, it cannot handle a case of non overlapping requests. In such a case, min_dirty_data_idx and max_dirty_data_idx can be overwritten by the requests and invalid inode update can happen e.g. a case like create(1, 2) and create(3, 4) are issued in parallel.

This patch lets SheepdogAIOCB have dirty data indexes instead of BDRVSheepdogState for avoiding the above situation.

This patch also does trivial renaming for better description:
overwrapping -> overlapping

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>
---
 block/sheepdog.c | 63 +++++++++++++++++++++++++++++++-------------------------
 1 file changed, 35 insertions(+), 28 deletions(-)
block/sheepdog.c +35 -28
index 9585beb..24341ea 100644
@@ -318,7 +318,7 @@ enum AIOCBState {
     AIOCB_DISCARD_OBJ,
 };
 
-#define AIOCBOverwrapping(x, y)                                 \
+#define AIOCBOverlapping(x, y)                                 \
     (!(x->max_affect_data_idx < y->min_affect_data_idx          \
        || y->max_affect_data_idx < x->min_affect_data_idx))
 
@@ -342,6 +342,15 @@ struct SheepdogAIOCB {
     uint32_t min_affect_data_idx;
     uint32_t max_affect_data_idx;
 
+    /*
+     * The difference between affect_data_idx and dirty_data_idx:
+     * affect_data_idx represents range of index of all request types.
+     * dirty_data_idx represents range of index updated by COW requests.
+     * dirty_data_idx is used for updating an inode object.
+     */
+    uint32_t min_dirty_data_idx;
+    uint32_t max_dirty_data_idx;
+
     QLIST_ENTRY(SheepdogAIOCB) aiocb_siblings;
 };
 
@@ -351,9 +360,6 @@ typedef struct BDRVSheepdogState {
 
     SheepdogInode inode;
 
-    uint32_t min_dirty_data_idx;
-    uint32_t max_dirty_data_idx;
-
     char name[SD_MAX_VDI_LEN];
     bool is_snapshot;
     uint32_t cache_flags;
@@ -373,7 +379,7 @@ typedef struct BDRVSheepdogState {
     QLIST_HEAD(inflight_aio_head, AIOReq) inflight_aio_head;
     QLIST_HEAD(failed_aio_head, AIOReq) failed_aio_head;
 
-    CoQueue overwrapping_queue;
+    CoQueue overlapping_queue;
     QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head;
 } BDRVSheepdogState;
 
@@ -556,6 +562,9 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
     acb->max_affect_data_idx = (acb->sector_num * BDRV_SECTOR_SIZE +
                               acb->nb_sectors * BDRV_SECTOR_SIZE) / object_size;
 
+    acb->min_dirty_data_idx = UINT32_MAX;
+    acb->max_dirty_data_idx = 0;
+
     return acb;
 }
 
@@ -819,8 +828,8 @@ static void coroutine_fn aio_read_response(void *opaque)
              */
             if (rsp.result == SD_RES_SUCCESS) {
                 s->inode.data_vdi_id[idx] = s->inode.vdi_id;
-                s->max_dirty_data_idx = MAX(idx, s->max_dirty_data_idx);
-                s->min_dirty_data_idx = MIN(idx, s->min_dirty_data_idx);
+                acb->max_dirty_data_idx = MAX(idx, acb->max_dirty_data_idx);
+                acb->min_dirty_data_idx = MIN(idx, acb->min_dirty_data_idx);
             }
         }
         break;
@@ -1466,13 +1475,11 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
     }
 
     memcpy(&s->inode, buf, sizeof(s->inode));
-    s->min_dirty_data_idx = UINT32_MAX;
-    s->max_dirty_data_idx = 0;
 
     bs->total_sectors = s->inode.vdi_size / BDRV_SECTOR_SIZE;
     pstrcpy(s->name, sizeof(s->name), vdi);
     qemu_co_mutex_init(&s->lock);
-    qemu_co_queue_init(&s->overwrapping_queue);
+    qemu_co_queue_init(&s->overlapping_queue);
     qemu_opts_del(opts);
     g_free(buf);
     return 0;
@@ -1923,16 +1930,16 @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb)
     AIOReq *aio_req;
     uint32_t offset, data_len, mn, mx;
 
-    mn = s->min_dirty_data_idx;
-    mx = s->max_dirty_data_idx;
+    mn = acb->min_dirty_data_idx;
+    mx = acb->max_dirty_data_idx;
     if (mn <= mx) {
         /* we need to update the vdi object. */
         offset = sizeof(s->inode) - sizeof(s->inode.data_vdi_id) +
             mn * sizeof(s->inode.data_vdi_id[0]);
         data_len = (mx - mn + 1) * sizeof(s->inode.data_vdi_id[0]);
 
-        s->min_dirty_data_idx = UINT32_MAX;
-        s->max_dirty_data_idx = 0;
+        acb->min_dirty_data_idx = UINT32_MAX;
+        acb->max_dirty_data_idx = 0;
 
         iov.iov_base = &s->inode;
         iov.iov_len = sizeof(s->inode);
@@ -2158,12 +2165,12 @@ out:
     return 1;
 }
 
-static bool check_overwrapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb)
+static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb)
 {
     SheepdogAIOCB *cb;
 
     QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) {
-        if (AIOCBOverwrapping(aiocb, cb)) {
+        if (AIOCBOverlapping(aiocb, cb)) {
             return true;
         }
     }
@@ -2192,15 +2199,15 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
     acb->aiocb_type = AIOCB_WRITE_UDATA;
 
 retry:
-    if (check_overwrapping_aiocb(s, acb)) {
-        qemu_co_queue_wait(&s->overwrapping_queue);
+    if (check_overlapping_aiocb(s, acb)) {
+        qemu_co_queue_wait(&s->overlapping_queue);
         goto retry;
     }
 
     ret = sd_co_rw_vector(acb);
     if (ret <= 0) {
         QLIST_REMOVE(acb, aiocb_siblings);
-        qemu_co_queue_restart_all(&s->overwrapping_queue);
+        qemu_co_queue_restart_all(&s->overlapping_queue);
         qemu_aio_unref(acb);
         return ret;
     }
@@ -2208,7 +2215,7 @@ retry:
     qemu_coroutine_yield();
 
     QLIST_REMOVE(acb, aiocb_siblings);
-    qemu_co_queue_restart_all(&s->overwrapping_queue);
+    qemu_co_queue_restart_all(&s->overlapping_queue);
 
     return acb->ret;
 }
@@ -2225,15 +2232,15 @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num,
     acb->aio_done_func = sd_finish_aiocb;
 
 retry:
-    if (check_overwrapping_aiocb(s, acb)) {
-        qemu_co_queue_wait(&s->overwrapping_queue);
+    if (check_overlapping_aiocb(s, acb)) {
+        qemu_co_queue_wait(&s->overlapping_queue);
         goto retry;
     }
 
     ret = sd_co_rw_vector(acb);
     if (ret <= 0) {
         QLIST_REMOVE(acb, aiocb_siblings);
-        qemu_co_queue_restart_all(&s->overwrapping_queue);
+        qemu_co_queue_restart_all(&s->overlapping_queue);
         qemu_aio_unref(acb);
         return ret;
     }
@@ -2241,7 +2248,7 @@ retry:
     qemu_coroutine_yield();
 
     QLIST_REMOVE(acb, aiocb_siblings);
-    qemu_co_queue_restart_all(&s->overwrapping_queue);
+    qemu_co_queue_restart_all(&s->overlapping_queue);
     return acb->ret;
 }
 
@@ -2590,15 +2597,15 @@ static coroutine_fn int sd_co_discard(BlockDriverState *bs, int64_t sector_num,
     acb->aio_done_func = sd_finish_aiocb;
 
 retry:
-    if (check_overwrapping_aiocb(s, acb)) {
-        qemu_co_queue_wait(&s->overwrapping_queue);
+    if (check_overlapping_aiocb(s, acb)) {
+        qemu_co_queue_wait(&s->overlapping_queue);
         goto retry;
     }
 
     ret = sd_co_rw_vector(acb);
     if (ret <= 0) {
         QLIST_REMOVE(acb, aiocb_siblings);
-        qemu_co_queue_restart_all(&s->overwrapping_queue);
+        qemu_co_queue_restart_all(&s->overlapping_queue);
         qemu_aio_unref(acb);
         return ret;
     }
@@ -2606,7 +2613,7 @@ retry:
     qemu_coroutine_yield();
 
     QLIST_REMOVE(acb, aiocb_siblings);
-    qemu_co_queue_restart_all(&s->overwrapping_queue);
+    qemu_co_queue_restart_all(&s->overlapping_queue);
 
     return acb->ret;
 }
Signature · 1 line
1.9.1
Tested-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] sheepdog: use per AIOCB dirty indexes for non overlapping requests

2015-09-01 6:03 GMT+03:00 Hitoshi Mitake <[email protected]>:

Quoted 10 lines

n the commit 96b14ff85acf, requests for overlapping areas are serialized. However, it cannot handle a case of non overlapping requests. In such a case, min_dirty_data_idx and max_dirty_data_idx can be overwritten by the requests and invalid inode update can happen e.g. a case like create(1, 2) and create(3, 4) are issued in parallel.

This patch lets SheepdogAIOCB have dirty data indexes instead of BDRVSheepdogState for avoiding the above situation.

Quoted 7 lines

This patch also does trivial renaming for better description:
overwrapping -> overlapping

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>

I'm test this patch and now discard working properly and no errors in sheepdog log file.

Signature · 2 lines
Vasiliy Tolstov,
e-mail: [email protected]
#3 lore raw

Re: [Qemu-devel] [sheepdog] [PATCH 1/2] sheepdog: use per AIOCB dirty indexes for non overlapping requests

Quoted 19 lines · Vasiliy Tolstov

2015-09-01 6:03 GMT+03:00 Hitoshi Mitake <[email protected]>:

Quoted 10 lines

n the commit 96b14ff85acf, requests for overlapping areas are serialized. However, it cannot handle a case of non overlapping requests. In such a case, min_dirty_data_idx and max_dirty_data_idx can be overwritten by the requests and invalid inode update can happen e.g. a case like create(1, 2) and create(3, 4) are issued in parallel.

This patch lets SheepdogAIOCB have dirty data indexes instead of BDRVSheepdogState for avoiding the above situation.

Quoted 7 lines

This patch also does trivial renaming for better description:
overwrapping -> overlapping

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>
Quoted 4 lines

I'm test this patch and now discard working properly and no errors in sheepdog log file.

Ping, Jeff?

Thanks,
Hitoshi

Quoted 8 lines

--
Vasiliy Tolstov,
e-mail: [email protected]
--
sheepdog mailing list
[email protected]
https://lists.wpkg.org/mailman/listinfo/sheepdog

#4 lore raw

PATCH 2/2 sheepdog: refine discard support

In reply to Hitoshi Mitake

This patch refines discard support of the sheepdog driver. The existing discard mechanism was implemented on SD_OP_DISCARD_OBJ, which was introduced before fine grained reference counting on newer sheepdog. It doesn't care about relations of snapshots and clones and discards objects unconditionally.

With this patch, the driver just updates an inode object for updating reference. Removing the object is done in sheep process side.

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>
---
 block/sheepdog.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
block/sheepdog.c +20 -9
index 24341ea..e3c5cb5 100644
@@ -28,7 +28,6 @@
 #define SD_OP_READ_OBJ       0x02
 #define SD_OP_WRITE_OBJ      0x03
 /* 0x04 is used internally by Sheepdog */
-#define SD_OP_DISCARD_OBJ    0x05
 
 #define SD_OP_NEW_VDI        0x11
 #define SD_OP_LOCK_VDI       0x12
@@ -856,10 +855,6 @@ static void coroutine_fn aio_read_response(void *opaque)
             rsp.result = SD_RES_SUCCESS;
             s->discard_supported = false;
             break;
-        case SD_RES_SUCCESS:
-            idx = data_oid_to_idx(aio_req->oid);
-            s->inode.data_vdi_id[idx] = 0;
-            break;
         default:
             break;
         }
@@ -1174,7 +1169,13 @@ static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
         hdr.flags = SD_FLAG_CMD_WRITE | flags;
         break;
     case AIOCB_DISCARD_OBJ:
-        hdr.opcode = SD_OP_DISCARD_OBJ;
+        hdr.opcode = SD_OP_WRITE_OBJ;
+        hdr.flags = SD_FLAG_CMD_WRITE | flags;
+        s->inode.data_vdi_id[data_oid_to_idx(oid)] = 0;
+        offset = offsetof(SheepdogInode,
+                          data_vdi_id[data_oid_to_idx(oid)]);
+        oid = vid_to_vdi_oid(s->inode.vdi_id);
+        wlen = datalen = sizeof(uint32_t);
         break;
     }
 
@@ -2148,7 +2149,9 @@ static int coroutine_fn sd_co_rw_vector(void *p)
         }
 
         aio_req = alloc_aio_req(s, acb, oid, len, offset, flags, create,
-                                old_oid, done);
+                                old_oid,
+                                acb->aiocb_type == AIOCB_DISCARD_OBJ ?
+                                0 : done);
         QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
 
         add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov,
@@ -2584,15 +2587,23 @@ static coroutine_fn int sd_co_discard(BlockDriverState *bs, int64_t sector_num,
                                       int nb_sectors)
 {
     SheepdogAIOCB *acb;
-    QEMUIOVector dummy;
     BDRVSheepdogState *s = bs->opaque;
     int ret;
+    QEMUIOVector discard_iov;
+    struct iovec iov;
+    uint32_t zero = 0;
 
     if (!s->discard_supported) {
             return 0;
     }
 
-    acb = sd_aio_setup(bs, &dummy, sector_num, nb_sectors);
+    memset(&discard_iov, 0, sizeof(discard_iov));
+    memset(&iov, 0, sizeof(iov));
+    iov.iov_base = &zero;
+    iov.iov_len = sizeof(zero);
+    discard_iov.iov = &iov;
+    discard_iov.niov = 1;
+    acb = sd_aio_setup(bs, &discard_iov, sector_num, nb_sectors);
     acb->aiocb_type = AIOCB_DISCARD_OBJ;
     acb->aio_done_func = sd_finish_aiocb;
 
Signature · 1 line
1.9.1
Tested-by on v1 2/2
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] sheepdog: refine discard support

2015-09-01 6:03 GMT+03:00 Hitoshi Mitake <[email protected]>:

Quoted 6 lines

This patch refines discard support of the sheepdog driver. The existing discard mechanism was implemented on SD_OP_DISCARD_OBJ, which was introduced before fine grained reference counting on newer sheepdog. It doesn't care about relations of snapshots and clones and discards objects unconditionally.

Quoted 7 lines

With this patch, the driver just updates an inode object for updating reference. Removing the object is done in sheep process side.

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>

I'm test this patch and now discard working properly and no errors in sheepdog log file.

Signature · 2 lines
Vasiliy Tolstov,
e-mail: [email protected]
#6 lore raw

Re: [Qemu-devel] [sheepdog] [PATCH 2/2] sheepdog: refine discard support

Quoted 16 lines · Vasiliy Tolstov

2015-09-01 6:03 GMT+03:00 Hitoshi Mitake <[email protected]>:

Quoted 6 lines

This patch refines discard support of the sheepdog driver. The existing discard mechanism was implemented on SD_OP_DISCARD_OBJ, which was introduced before fine grained reference counting on newer sheepdog. It doesn't care about relations of snapshots and clones and discards objects unconditionally.

Quoted 7 lines

With this patch, the driver just updates an inode object for updating reference. Removing the object is done in sheep process side.

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>
Quoted 4 lines

I'm test this patch and now discard working properly and no errors in sheepdog log file.

On the second thought, this patch has a problem of handling snapshot. Please drop this one (1st patch is ok to apply).

I'll solve the problem in sheepdog side.

Thanks,
Hitoshi

Quoted 8 lines

--
Vasiliy Tolstov,
e-mail: [email protected]
--
sheepdog mailing list
[email protected]
https://lists.wpkg.org/mailman/listinfo/sheepdog

#7 lore raw

Re: [Qemu-devel] [sheepdog] [PATCH 2/2] sheepdog: refine discard support

Quoted 20 lines · Hitoshi Mitake
Quoted 19 lines · Vasiliy Tolstov

2015-09-01 6:03 GMT+03:00 Hitoshi Mitake <[email protected]>:

Quoted 6 lines

This patch refines discard support of the sheepdog driver. The existing discard mechanism was implemented on SD_OP_DISCARD_OBJ, which was introduced before fine grained reference counting on newer sheepdog. It doesn't care about relations of snapshots and clones and discards objects unconditionally.

Quoted 7 lines

With this patch, the driver just updates an inode object for updating reference. Removing the object is done in sheep process side.

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>

I'm test this patch and now discard working properly and no errors in sheepdog log file.

Quoted 6 lines
Quoted 1 line

On the second thought, this patch has a problem of handling snapshot. Please drop this one (1st patch is ok to apply).

I'll solve the problem in sheepdog side.

On the third thought, this patch can work well ;) Please pick this patch, Jeff.

I considered about a case of interleaving of snapshotting and discarding requests like below:
1. user invokes dog vdi snapshot, a command for making current VDI snapshot (updating inode objects)
2. discard request from VM before the request of 1 completes
3. discard completes
4. request of 1 completes

In this case, some data_vdi_id of original inode can be overwritten before completion of snapshotting. However, this behavior is valid because dog vdi snapshot doesn't return ack to the user.

Thanks,
Hitoshi

Quoted 12 lines

Thanks,
Hitoshi

Quoted 8 lines

--
Vasiliy Tolstov,
e-mail: [email protected]
--
sheepdog mailing list
[email protected]
https://lists.wpkg.org/mailman/listinfo/sheepdog

#8 lore raw

Re: [Qemu-devel] [sheepdog] [PATCH 2/2] sheepdog: refine discard support

04 сент. 2015 г. 12:57 пользователь "Hitoshi Mitake" < [email protected]> написал:

Quoted 2 lines

On Fri, Sep 4, 2015 at 5:51 PM, Hitoshi Mitake <[email protected]>

Quoted 1 line · wrote:
Quoted 1 line

On Wed, Sep 2, 2015 at 9:36 PM, Vasiliy Tolstov <[email protected]>

Quoted 20 lines · wrote:
Quoted 1 line
Quoted 1 line

2015-09-01 6:03 GMT+03:00 Hitoshi Mitake <[email protected]

:

Quoted 18 lines
Quoted 18 lines
Quoted 6 lines

This patch refines discard support of the sheepdog driver. The existing discard mechanism was implemented on SD_OP_DISCARD_OBJ, which was introduced before fine grained reference counting on newer sheepdog. It doesn't care about relations of snapshots and clones and discards objects unconditionally.

Quoted 7 lines

With this patch, the driver just updates an inode object for updating reference. Removing the object is done in sheep process side.

Cc Teruaki Ishizaki <[email protected]>
Cc Vasiliy Tolstov <[email protected]>
Cc Jeff Cody <[email protected]>

I'm test this patch and now discard working properly and no errors in sheepdog log file.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

On the second thought, this patch has a problem of handling snapshot. Please drop this one (1st patch is ok to apply).

I'll solve the problem in sheepdog side.

On the third thought, this patch can work well ;) Please pick this patch,

Jeff.

Quoted 9 lines

I considered about a case of interleaving of snapshotting and discarding requests like below:
1. user invokes dog vdi snapshot, a command for making current VDI snapshot (updating inode objects)
2. discard request from VM before the request of 1 completes
3. discard completes
4. request of 1 completes

Quoted 4 lines

In this case, some data_vdi_id of original inode can be overwritten before completion of snapshotting. However, this behavior is valid because dog vdi snapshot doesn't return ack to the user.

This is normal for snapshots, to get consistent data you need to cooperate with guest system to get freeze it fs before snapshot. Quemu-ga already have this via sending freeze to fs beforw and thaw after snapshot .

Quoted 15 lines

Thanks,
Hitoshi

Quoted 12 lines

Thanks,
Hitoshi

Quoted 8 lines

--
Vasiliy Tolstov,
e-mail: [email protected]
--
sheepdog mailing list
[email protected]
https://lists.wpkg.org/mailman/listinfo/sheepdog

Applied
#9 lore raw
In reply to Hitoshi Mitake
Quoted 7 lines · Hitoshi Mitake

This patchset has two patches. The first one is a defensive purpose for rare cases. It is an improvement of the previous commit 96b14ff85acf. The second one is refining discard operation caused by fstrim command, etc. Current sheepdog driver corrupts VDIs when the discard operation is issued. This patch solves the problem.

Quoted 11 lines

Hitoshi Mitake (2):
sheepdog: use per AIOCB dirty indexes for non overlapping requests
sheepdog: refine discard support

 block/sheepdog.c | 92 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 55 insertions(+), 37 deletions(-)
Signature · 1 line
1.9.1

Thanks, applied to my block branch:

git://github.com/codyprime/qemu-kvm-jtc.git block

-Jeff