Merge pull request #16924 from liewegas/wip-20923

os/bluestore: fail early on very large objects

Reviewed-by: xie xingguo <xie.xingguo@zte.com.cn>
This commit is contained in:
Sage Weil 2017-08-11 21:55:34 -05:00 committed by GitHub
commit 4f6ae418c0
2 changed files with 33 additions and 10 deletions

View File

@ -9016,7 +9016,7 @@ void BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t)
case Transaction::OP_TRUNCATE: case Transaction::OP_TRUNCATE:
{ {
uint64_t off = op->off; uint64_t off = op->off;
_truncate(txc, c, o, off); r = _truncate(txc, c, o, off);
} }
break; break;
@ -10336,10 +10336,14 @@ int BlueStore::_write(TransContext *txc,
dout(15) << __func__ << " " << c->cid << " " << o->oid dout(15) << __func__ << " " << c->cid << " " << o->oid
<< " 0x" << std::hex << offset << "~" << length << std::dec << " 0x" << std::hex << offset << "~" << length << std::dec
<< dendl; << dendl;
_assign_nid(txc, o); int r = 0;
int r = _do_write(txc, c, o, offset, length, bl, fadvise_flags); if (offset + length >= OBJECT_MAX_SIZE) {
txc->write_onode(o); r = -E2BIG;
} else {
_assign_nid(txc, o);
r = _do_write(txc, c, o, offset, length, bl, fadvise_flags);
txc->write_onode(o);
}
dout(10) << __func__ << " " << c->cid << " " << o->oid dout(10) << __func__ << " " << c->cid << " " << o->oid
<< " 0x" << std::hex << offset << "~" << length << std::dec << " 0x" << std::hex << offset << "~" << length << std::dec
<< " = " << r << dendl; << " = " << r << dendl;
@ -10354,8 +10358,13 @@ int BlueStore::_zero(TransContext *txc,
dout(15) << __func__ << " " << c->cid << " " << o->oid dout(15) << __func__ << " " << c->cid << " " << o->oid
<< " 0x" << std::hex << offset << "~" << length << std::dec << " 0x" << std::hex << offset << "~" << length << std::dec
<< dendl; << dendl;
_assign_nid(txc, o); int r = 0;
int r = _do_zero(txc, c, o, offset, length); if (offset + length >= OBJECT_MAX_SIZE) {
r = -E2BIG;
} else {
_assign_nid(txc, o);
r = _do_zero(txc, c, o, offset, length);
}
dout(10) << __func__ << " " << c->cid << " " << o->oid dout(10) << __func__ << " " << c->cid << " " << o->oid
<< " 0x" << std::hex << offset << "~" << length << std::dec << " 0x" << std::hex << offset << "~" << length << std::dec
<< " = " << r << dendl; << " = " << r << dendl;
@ -10430,7 +10439,7 @@ void BlueStore::_do_truncate(
txc->write_onode(o); txc->write_onode(o);
} }
void BlueStore::_truncate(TransContext *txc, int BlueStore::_truncate(TransContext *txc,
CollectionRef& c, CollectionRef& c,
OnodeRef& o, OnodeRef& o,
uint64_t offset) uint64_t offset)
@ -10438,7 +10447,16 @@ void BlueStore::_truncate(TransContext *txc,
dout(15) << __func__ << " " << c->cid << " " << o->oid dout(15) << __func__ << " " << c->cid << " " << o->oid
<< " 0x" << std::hex << offset << std::dec << " 0x" << std::hex << offset << std::dec
<< dendl; << dendl;
_do_truncate(txc, c, o, offset); int r = 0;
if (offset >= OBJECT_MAX_SIZE) {
r = -E2BIG;
} else {
_do_truncate(txc, c, o, offset);
}
dout(10) << __func__ << " " << c->cid << " " << o->oid
<< " 0x" << std::hex << offset << std::dec
<< " = " << r << dendl;
return r;
} }
int BlueStore::_do_remove( int BlueStore::_do_remove(
@ -11021,6 +11039,11 @@ int BlueStore::_clone_range(TransContext *txc,
<< " to offset 0x" << dstoff << std::dec << dendl; << " to offset 0x" << dstoff << std::dec << dendl;
int r = 0; int r = 0;
if (srcoff + length >= OBJECT_MAX_SIZE ||
dstoff + length >= OBJECT_MAX_SIZE) {
r = -E2BIG;
goto out;
}
if (srcoff + length > oldo->onode.size) { if (srcoff + length > oldo->onode.size) {
r = -EINVAL; r = -EINVAL;
goto out; goto out;

View File

@ -2591,7 +2591,7 @@ private:
OnodeRef o, OnodeRef o,
uint64_t offset, uint64_t offset,
set<SharedBlob*> *maybe_unshared_blobs=0); set<SharedBlob*> *maybe_unshared_blobs=0);
void _truncate(TransContext *txc, int _truncate(TransContext *txc,
CollectionRef& c, CollectionRef& c,
OnodeRef& o, OnodeRef& o,
uint64_t offset); uint64_t offset);