[sheepdog] [PATCH 1/2] sheep: read inode directly from backend in VDI deletion work

levin li levin108 at gmail.com
Wed Sep 5 10:41:58 CEST 2012


From: levin li <xingke.lwp at taobao.com>

This patch is preparation for next patch that deletes object cache
when deleting VDI, if object cache deletion work is processed in
notify, then it may causes race between cache deletion and next VDI
deletion work, because VDI deletion work may needs to read its parent
VDI inode data, so we can not read the inode data from cache

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 sheep/sheep_priv.h |    2 ++
 sheep/store.c      |   30 ++++++++++++++++++++----------
 sheep/vdi.c        |    6 +++---
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 5969c26..75267b5 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -292,6 +292,8 @@ bool oid_in_recovery(uint64_t oid);
 int is_recovery_init(void);
 int node_in_recovery(void);
 
+int read_object_direct(uint64_t oid, char *data, unsigned int datalen,
+		       uint64_t offset, int nr_copies);
 int write_object(uint64_t oid, char *data, unsigned int datalen,
 		 uint64_t offset, uint16_t flags, int create, int nr_copies);
 int read_object(uint64_t oid, char *data, unsigned int datalen,
diff --git a/sheep/store.c b/sheep/store.c
index 8326156..5c5aa96 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -565,6 +565,25 @@ forward_write:
 	return ret;
 }
 
+int read_object_direct(uint64_t oid, char *data, unsigned int datalen,
+		       uint64_t offset, int nr_copies)
+{
+	struct sd_req hdr;
+	int ret;
+
+	sd_init_req(&hdr, SD_OP_READ_OBJ);
+	hdr.data_length = datalen;
+	hdr.obj.oid = oid;
+	hdr.obj.offset = offset;
+	hdr.obj.copies = nr_copies;
+
+	ret = exec_local_req(&hdr, data);
+	if (ret != SD_RES_SUCCESS)
+		eprintf("failed to read object %" PRIx64 ", %x\n", oid, ret);
+
+	return ret;
+}
+
 /*
  * Read data firstly from local object cache(if enabled), if fail,
  * try read backends
@@ -572,7 +591,6 @@ forward_write:
 int read_object(uint64_t oid, char *data, unsigned int datalen,
 		uint64_t offset, int nr_copies)
 {
-	struct sd_req hdr;
 	int ret;
 
 	if (sys->enable_write_cache && object_is_cached(oid)) {
@@ -586,15 +604,7 @@ int read_object(uint64_t oid, char *data, unsigned int datalen,
 	}
 
 forward_read:
-	sd_init_req(&hdr, SD_OP_READ_OBJ);
-	hdr.data_length = datalen;
-	hdr.obj.oid = oid;
-	hdr.obj.offset = offset;
-	hdr.obj.copies = nr_copies;
-
-	ret = exec_local_req(&hdr, data);
-	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to read object %" PRIx64 ", %x\n", oid, ret);
+	ret = read_object_direct(oid, data, datalen, offset, nr_copies);
 
 	return ret;
 }
diff --git a/sheep/vdi.c b/sheep/vdi.c
index f7e762f..1ccbe25 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -606,7 +606,7 @@ static void delete_one(struct work *work)
 	}
 
 	nr_copies = get_vdi_copy_number(vdi_id);
-	ret = read_object(vid_to_vdi_oid(vdi_id),
+	ret = read_object_direct(vid_to_vdi_oid(vdi_id),
 			  (void *)inode, sizeof(*inode), 0, nr_copies);
 
 	if (ret != SD_RES_SUCCESS) {
@@ -697,7 +697,7 @@ static int fill_vdi_list(struct deletion_work *dw, uint32_t root_vid)
 again:
 	vid = dw->buf[done++];
 	nr_copies = get_vdi_copy_number(vid);
-	ret = read_object(vid_to_vdi_oid(vid), (char *)inode,
+	ret = read_object_direct(vid_to_vdi_oid(vid), (char *)inode,
 			  SD_INODE_HEADER_SIZE, 0, nr_copies);
 
 	if (ret != SD_RES_SUCCESS) {
@@ -740,7 +740,7 @@ static uint64_t get_vdi_root(uint32_t vid, int *cloned)
 	}
 next:
 	nr_copies = get_vdi_copy_number(vid);
-	ret = read_object(vid_to_vdi_oid(vid), (char *)inode,
+	ret = read_object_direct(vid_to_vdi_oid(vid), (char *)inode,
 			  SD_INODE_HEADER_SIZE, 0, nr_copies);
 
 	if (vid == inode->vdi_id && inode->snap_id == 1
-- 
1.7.1




More information about the sheepdog mailing list