[sheepdog] [PATCH] sheep: check memory address alignment for direct IO

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed May 22 09:49:34 CEST 2013


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/plain_store.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index b932d6a..e8dfb65 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -20,6 +20,11 @@
 #include "config.h"
 #include "sha1.h"
 
+static inline bool is_aligned_to_pagesize(void *p)
+{
+	return ((uintptr_t)p & (getpagesize() - 1)) == 0;
+}
+
 static int get_open_flags(uint64_t oid, bool create)
 {
 	int flags = O_DSYNC | O_RDWR;
@@ -97,6 +102,8 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 	char path[PATH_MAX];
 	ssize_t size;
 
+	assert(flags & O_DIRECT ? is_aligned_to_pagesize(iocb->buf) : true);
+
 	if (iocb->epoch < sys_epoch()) {
 		sd_dprintf("%"PRIu32" sys %"PRIu32, iocb->epoch, sys_epoch());
 		return SD_RES_OLD_NODE_VER;
@@ -237,6 +244,8 @@ static int default_read_from_path(uint64_t oid, char *path,
 	    ret = SD_RES_SUCCESS;
 	ssize_t size;
 
+	assert(flags & O_DIRECT ? is_aligned_to_pagesize(iocb->buf) : true);
+
 	fd = open(path, flags);
 
 	if (fd < 0)
@@ -298,6 +307,8 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 	int ret, fd;
 	uint32_t len = iocb->length;
 
+	assert(flags & O_DIRECT ? is_aligned_to_pagesize(iocb->buf) : true);
+
 	get_obj_path(oid, path);
 	get_tmp_obj_path(oid, tmp_path);
 
-- 
1.8.1.3.566.gaa39828



More information about the sheepdog mailing list