Merge pull request #3764 from ceph/wip-10919

cls_rbd: invalidate bufferlist CRC when updating object map

Reviewed-by: Josh Durgin <jdurgin@redhat.com>
This commit is contained in:
Josh Durgin 2015-02-20 09:00:26 -08:00
commit c0e897e9fd
2 changed files with 16 additions and 16 deletions

View File

@ -200,9 +200,7 @@ void BitVector<_b>::encode_data(bufferlist& bl, uint64_t byte_offset,
bufferlist bit;
bit.substr_of(m_data, byte_offset, len);
m_data_crcs[byte_offset / CEPH_PAGE_SIZE] =
ceph_crc32c(0, reinterpret_cast<unsigned char*>(bit.c_str()),
bit.length());
m_data_crcs[byte_offset / CEPH_PAGE_SIZE] = bit.crc32c(0);
bl.claim_append(bit);
byte_offset += CEPH_PAGE_SIZE;
@ -388,11 +386,10 @@ typename BitVector<_b>::Reference& BitVector<_b>::Reference::operator=(uint8_t v
uint64_t shift;
this->m_bit_vector.compute_index(this->m_offset, &index, &shift);
// TODO: find out why bufferlist doesn't support char& operator[]()
uint8_t mask = MASK << shift;
char* packed_data = this->m_bit_vector.m_data.c_str();
uint8_t packed_value = (packed_data[index] & ~mask) | ((v << shift) & mask);
packed_data[index] = packed_value;
char packed_value = (this->m_bit_vector.m_data[index] & ~mask) |
((v << shift) & mask);
this->m_bit_vector.m_data.copy_in(index, 1, &packed_value);
return *this;
}

View File

@ -202,27 +202,30 @@ TYPED_TEST(BitVectorTest, header_crc) {
}
TYPED_TEST(BitVectorTest, data_crc) {
typename TestFixture::bit_vector_t bit_vector;
typename TestFixture::bit_vector_t bit_vector1;
typename TestFixture::bit_vector_t bit_vector2;
uint64_t elements_per_byte = 8 / bit_vector.BIT_COUNT;
bit_vector.resize((CEPH_PAGE_SIZE + 1) * elements_per_byte);
uint64_t elements_per_byte = 8 / bit_vector1.BIT_COUNT;
bit_vector1.resize((CEPH_PAGE_SIZE + 1) * elements_per_byte);
bit_vector2.resize((CEPH_PAGE_SIZE + 1) * elements_per_byte);
uint64_t byte_offset;
uint64_t byte_length;
bit_vector.get_data_extents(0, bit_vector.size(), &byte_offset, &byte_length);
bit_vector1.get_data_extents(0, bit_vector1.size(), &byte_offset,
&byte_length);
bufferlist data;
bit_vector.encode_data(data, byte_offset, byte_length);
bit_vector1.encode_data(data, byte_offset, byte_length);
bufferlist::iterator data_it = data.begin();
bit_vector.decode_data(data_it, byte_offset);
bit_vector1.decode_data(data_it, byte_offset);
bit_vector[bit_vector.size() - 1] = 1;
bit_vector2[bit_vector2.size() - 1] = 1;
bufferlist dummy_data;
bit_vector.encode_data(dummy_data, byte_offset, byte_length);
bit_vector2.encode_data(dummy_data, byte_offset, byte_length);
data_it = data.begin();
ASSERT_THROW(bit_vector.decode_data(data_it, byte_offset),
ASSERT_THROW(bit_vector2.decode_data(data_it, byte_offset),
buffer::malformed_input);
}