From 7ca73f4e6ee458ce82bdbb86467388dc207b8e5c Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Thu, 28 Apr 2016 07:31:14 +0800 Subject: [PATCH] common/buffer: For bufferlist add func is_aligned_size_and_memory. For directIO requirement, we need check bufferpt whether size aligned and the address aligned. To do this, we should call is_aligned && is_n_align_sized. Every func also list all ptr of bufferlist. To reduce one list, we add is_aligned_size_and_memroy(align_size, align_memory) which only need list once. Signed-off-by: Jianpeng Ma --- src/common/buffer.cc | 12 ++++++++++++ src/include/buffer.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 651a3687fa9..3557b3775d4 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1422,6 +1422,18 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; return true; } + bool buffer::list::is_aligned_size_and_memory(unsigned align_size, + unsigned align_memory) const + { + for (std::list::const_iterator it = _buffers.begin(); + it != _buffers.end(); + ++it) { + if (!it->is_aligned(align_memory) || !it->is_n_align_sized(align_size)) + return false; + } + return true; + } + bool buffer::list::is_zero() const { for (std::list::const_iterator it = _buffers.begin(); it != _buffers.end(); diff --git a/src/include/buffer.h b/src/include/buffer.h index 37c40423bd4..4c5de1d486b 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -436,6 +436,8 @@ namespace buffer CEPH_BUFFER_API { bool is_page_aligned() const; bool is_n_align_sized(unsigned align) const; bool is_n_page_sized() const; + bool is_aligned_size_and_memory(unsigned align_size, + unsigned align_memory) const; bool is_zero() const; -- 2.39.5