[sheepdog-users] [PATCH stable-0.8 02/22] sheep: go to panic if using unaligned memory in direct-io mode

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Mon Feb 24 08:06:50 CET 2014

From: Robin Dong <robin.k.dong at gmail.com>

When startup sheep with option "-D", the plain_store will check alignment of
read/write buffer, but if the buffer is not aligned, it will do nothing if
it dose not choose "--enable-debug" for configuration. Then sheep will open
file with "O_DIRECT" and call pread() with unaligned buffer, it will cause
error io and remove the disk from md which is totally wrong behavior.
So, we should make the check strong enough: sheep will panic directlly if
finding unaligned buffer.

Signed-off-by: Robin Dong <sanbai at taobao.com>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
 sheep/plain_store.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index fa6c01b..9a4871c 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -48,7 +48,8 @@ static int prepare_iocb(uint64_t oid, const struct siocb *iocb, bool create)
 		flags &= ~O_DSYNC;
 	if (sys->backend_dio && iocb_is_aligned(iocb)) {
-		assert(is_aligned_to_pagesize(iocb->buf));
+		if (!is_aligned_to_pagesize(iocb->buf))
+			panic("Memory isn't aligned to pagesize %p", iocb->buf);
 		flags |= O_DIRECT;

More information about the sheepdog-users mailing list