To keep strong consistency, Sheepdog assumes that no two VMs can open the same VDI at the same time. This patch relaxes it and allows us to read data from opened VDIs by specifying SD_FLAG_CMD_WEAK_CONSISTENCY. Note that the obtained data may not the latest one. Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- include/sheep.h | 6 ++++++ sheep/group.c | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/sheep.h b/include/sheep.h index 2b2eb57..8d4840c 100644 --- a/include/sheep.h +++ b/include/sheep.h @@ -42,6 +42,12 @@ #define SD_FLAG_CMD_IO_LOCAL 0x0010 #define SD_FLAG_CMD_RECOVERY 0x0020 +/* set this flag when you want to read a VDI which is opened by + another client. Note that the obtained data may not be the latest + one because Sheepdog cannot ensure strong consistency against + concurrent accesses to non-snapshot VDIs. */ +#define SD_FLAG_CMD_WEAK_CONSISTENCY 0x0040 + /* flags for vdi attribute operations */ #define SD_FLAG_CMD_CREAT 0x0100 #define SD_FLAG_CMD_EXCL 0x0200 diff --git a/sheep/group.c b/sheep/group.c index 6513b14..72d88b6 100644 --- a/sheep/group.c +++ b/sheep/group.c @@ -1020,6 +1020,23 @@ static int __is_access_to_busy_objects(struct request *req) return 0; } +static int need_consistency_check(uint8_t opcode, uint16_t flags) +{ + if (flags & SD_FLAG_CMD_IO_LOCAL) + /* only gateway fixes data consistency */ + return 0; + + if (opcode != SD_OP_READ_OBJ) + /* consistency is fixed when clients read data for the + * first time */ + return 0; + + if (flags & SD_FLAG_CMD_WEAK_CONSISTENCY) + return 0; + + return 1; +} + /* can be called only by the main process */ void start_cpg_event_work(void) { @@ -1089,8 +1106,7 @@ do_retry: } } - if (!(req->rq.flags & SD_FLAG_CMD_IO_LOCAL) && - req->rq.opcode == SD_OP_READ_OBJ) { + if (need_consistency_check(req->rq.opcode, req->rq.flags)) { struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq; uint32_t vdi_id = oid_to_vid(hdr->oid); struct data_object_bmap *bmap; -- 1.7.2.5 |