summaryrefslogtreecommitdiff
path: root/libbcachefs/fs-io.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-07-13 00:43:23 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2018-07-13 00:45:28 -0400
commit75c7148e0aff2184c75a52e7c4c58e46e715757b (patch)
treece823d6a7b2a5d3057bd912d00088fc707dec08b /libbcachefs/fs-io.c
parent17e2f2775be6e10b966cd958bc0461aab662571a (diff)
Update bcachefs sources to 940d6ca657 bcachefs: acl code improvements
Diffstat (limited to 'libbcachefs/fs-io.c')
-rw-r--r--libbcachefs/fs-io.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/libbcachefs/fs-io.c b/libbcachefs/fs-io.c
index 737b9be3..9e78798a 100644
--- a/libbcachefs/fs-io.c
+++ b/libbcachefs/fs-io.c
@@ -2078,6 +2078,29 @@ out:
/* truncate: */
+static inline int range_has_data(struct bch_fs *c,
+ struct bpos start,
+ struct bpos end)
+{
+
+ struct btree_iter iter;
+ struct bkey_s_c k;
+ int ret = 0;
+
+ for_each_btree_key(&iter, c, BTREE_ID_EXTENTS,
+ start, 0, k) {
+ if (bkey_cmp(bkey_start_pos(k.k), end) >= 0)
+ break;
+
+ if (bkey_extent_is_data(k.k)) {
+ ret = 1;
+ break;
+ }
+ }
+
+ return bch2_btree_iter_unlock(&iter) ?: ret;
+}
+
static int __bch2_truncate_page(struct bch_inode_info *inode,
pgoff_t index, loff_t start, loff_t end)
{
@@ -2099,30 +2122,16 @@ static int __bch2_truncate_page(struct bch_inode_info *inode,
page = find_lock_page(mapping, index);
if (!page) {
- struct btree_iter iter;
- struct bkey_s_c k = bkey_s_c_null;
-
/*
* XXX: we're doing two index lookups when we end up reading the
* page
*/
- for_each_btree_key(&iter, c, BTREE_ID_EXTENTS,
- POS(inode->v.i_ino,
- index << PAGE_SECTOR_SHIFT), 0, k) {
- if (bkey_cmp(bkey_start_pos(k.k),
- POS(inode->v.i_ino,
- (index + 1) << PAGE_SECTOR_SHIFT)) >= 0)
- break;
+ ret = range_has_data(c,
+ POS(inode->v.i_ino, index << PAGE_SECTOR_SHIFT),
+ POS(inode->v.i_ino, (index + 1) << PAGE_SECTOR_SHIFT));
+ if (ret <= 0)
+ return ret;
- if (k.k->type != KEY_TYPE_DISCARD &&
- k.k->type != BCH_RESERVATION) {
- bch2_btree_iter_unlock(&iter);
- goto create;
- }
- }
- bch2_btree_iter_unlock(&iter);
- return 0;
-create:
page = find_or_create_page(mapping, index, GFP_KERNEL);
if (unlikely(!page)) {
ret = -ENOMEM;
@@ -2389,9 +2398,6 @@ static long bch2_fcollapse(struct bch_inode_info *inode,
bkey_reassemble(&copy.k, k);
- if (bkey_deleted(&copy.k.k))
- copy.k.k.type = KEY_TYPE_DISCARD;
-
bch2_cut_front(src.pos, &copy.k);
copy.k.k.p.offset -= len >> 9;