From 2b18ed109fa5ec2fd7bd4706569c79c98473cab8 Mon Sep 17 00:00:00 2001 From: sageweil Date: Thu, 6 Dec 2007 06:01:16 +0000 Subject: [PATCH] fixed page alignment/sizing checks git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@2184 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/include/buffer.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/trunk/ceph/include/buffer.h b/trunk/ceph/include/buffer.h index c370bba9c166f..6b67d9db1e59c 100644 --- a/trunk/ceph/include/buffer.h +++ b/trunk/ceph/include/buffer.h @@ -27,6 +27,7 @@ #endif #define BUFFER_PAGE_SIZE 4096 // FIXME +#define BUFFER_PAGE_MASK (BUFFER_PAGE_SIZE-1) // FIXME // // these are in config.o @@ -72,7 +73,10 @@ private: } bool is_page_aligned() { - return (long)data % BUFFER_PAGE_SIZE == 0; + return ((long)data & BUFFER_PAGE_MASK) == 0; + } + bool is_n_page_sized() { + return (len & BUFFER_PAGE_MASK) == 0; } }; @@ -147,7 +151,7 @@ private: public: raw_hack_aligned(unsigned l) : raw(l) { realdata = new char[len+BUFFER_PAGE_SIZE-1]; - unsigned off = ((unsigned)realdata) % BUFFER_PAGE_SIZE; + unsigned off = ((unsigned)realdata) & BUFFER_PAGE_MASK; if (off) data = realdata + BUFFER_PAGE_SIZE - off; else @@ -283,7 +287,8 @@ public: bool at_buffer_head() const { return _off == 0; } bool at_buffer_tail() const { return _off + _len == _raw->len; } - bool is_page_aligned() const { return (long)c_str() % BUFFER_PAGE_SIZE == 0; } + bool is_page_aligned() const { return ((long)c_str() & BUFFER_PAGE_MASK) == 0; } + bool is_n_page_sized() const { return (length() & BUFFER_PAGE_MASK) == 0; } // accessors raw *get_raw() const { return _raw; } @@ -558,7 +563,11 @@ public: return true; } bool is_n_page_sized() const { - return length() % BUFFER_PAGE_SIZE == 0; + for (std::list::const_iterator it = _buffers.begin(); + it != _buffers.end(); + it++) + if (!it->is_n_page_sized()) return false; + return true; } // modifiers -- 2.39.5