bcachefs: Fix a null ptr deref in bch2_inode_delete_keys()

Similarly to bch2_btree_delete_range_trans(), bch2_inode_delete_keys()
may sometimes split compressed extents, and needs to pass in a disk
reservation.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-12-22 22:39:50 -05:00 committed by Kent Overstreet
parent e409999069
commit 73b460977e

View File

@ -4,6 +4,7 @@
#include "btree_key_cache.h"
#include "bkey_methods.h"
#include "btree_update.h"
#include "buckets.h"
#include "error.h"
#include "extents.h"
#include "extent_update.h"
@ -588,6 +589,8 @@ static int bch2_inode_delete_keys(struct btree_trans *trans,
int ret = 0;
while (!ret || ret == -EINTR) {
struct disk_reservation disk_res =
bch2_disk_reservation_init(trans->c, 0);
struct btree_iter iter;
struct bkey_s_c k;
struct bkey_i delete;
@ -630,8 +633,9 @@ static int bch2_inode_delete_keys(struct btree_trans *trans,
}
ret = bch2_trans_update(trans, &iter, &delete, 0) ?:
bch2_trans_commit(trans, NULL, NULL,
bch2_trans_commit(trans, &disk_res, NULL,
BTREE_INSERT_NOFAIL);
bch2_disk_reservation_put(trans->c, &disk_res);
err:
offset = iter.pos.offset;
bch2_trans_iter_exit(trans, &iter);