Skip to content

Commit

Permalink
Update bcachefs sources to 5b8c4a1366 bcachefs: bcachefs_metadata_ver…
Browse files Browse the repository at this point in the history
…sion_deleted_inodes
  • Loading branch information
Kent Overstreet committed Aug 3, 2023
1 parent 87179c7 commit bafc817
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
33a60d9b05f523be93973b25e0df1ab2d65fa4fc
5b8c4a1366df20bc043404cb882230ce86296590
44 changes: 2 additions & 42 deletions libbcachefs/bcachefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
#include "fifo.h"
#include "nocow_locking_types.h"
#include "opts.h"
#include "recovery_types.h"
#include "seqmutex.h"
#include "util.h"

Expand Down Expand Up @@ -452,6 +453,7 @@ enum gc_phase {
GC_PHASE_BTREE_backpointers,
GC_PHASE_BTREE_bucket_gens,
GC_PHASE_BTREE_snapshot_trees,
GC_PHASE_BTREE_deleted_inodes,

GC_PHASE_PENDING_DELETE,
};
Expand Down Expand Up @@ -655,48 +657,6 @@ enum bch_write_ref {
BCH_WRITE_REF_NR,
};

#define PASS_SILENT BIT(0)
#define PASS_FSCK BIT(1)
#define PASS_UNCLEAN BIT(2)
#define PASS_ALWAYS BIT(3)

#define BCH_RECOVERY_PASSES() \
x(alloc_read, PASS_ALWAYS) \
x(stripes_read, PASS_ALWAYS) \
x(initialize_subvolumes, 0) \
x(snapshots_read, PASS_ALWAYS) \
x(check_topology, 0) \
x(check_allocations, PASS_FSCK) \
x(set_may_go_rw, PASS_ALWAYS|PASS_SILENT) \
x(journal_replay, PASS_ALWAYS) \
x(check_alloc_info, PASS_FSCK) \
x(check_lrus, PASS_FSCK) \
x(check_btree_backpointers, PASS_FSCK) \
x(check_backpointers_to_extents,PASS_FSCK) \
x(check_extents_to_backpointers,PASS_FSCK) \
x(check_alloc_to_lru_refs, PASS_FSCK) \
x(fs_freespace_init, PASS_ALWAYS|PASS_SILENT) \
x(bucket_gens_init, 0) \
x(check_snapshot_trees, PASS_FSCK) \
x(check_snapshots, PASS_FSCK) \
x(check_subvols, PASS_FSCK) \
x(delete_dead_snapshots, PASS_FSCK|PASS_UNCLEAN) \
x(fs_upgrade_for_subvolumes, 0) \
x(check_inodes, PASS_FSCK|PASS_UNCLEAN) \
x(check_extents, PASS_FSCK) \
x(check_dirents, PASS_FSCK) \
x(check_xattrs, PASS_FSCK) \
x(check_root, PASS_FSCK) \
x(check_directory_structure, PASS_FSCK) \
x(check_nlinks, PASS_FSCK) \
x(fix_reflink_p, 0) \

enum bch_recovery_pass {
#define x(n, when) BCH_RECOVERY_PASS_##n,
BCH_RECOVERY_PASSES()
#undef x
};

struct bch_fs {
struct closure cl;

Expand Down
8 changes: 6 additions & 2 deletions libbcachefs/bcachefs_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,9 @@ struct bch_sb_field_journal_seq_blacklist {
x(major_minor, BCH_VERSION(1, 0), \
0) \
x(snapshot_skiplists, BCH_VERSION(1, 1), \
BIT_ULL(BCH_RECOVERY_PASS_check_snapshots))
BIT_ULL(BCH_RECOVERY_PASS_check_snapshots)) \
x(deleted_inodes, BCH_VERSION(1, 2), \
BIT_ULL(BCH_RECOVERY_PASS_check_inodes))

enum bcachefs_metadata_version {
bcachefs_metadata_version_min = 9,
Expand Down Expand Up @@ -2251,7 +2253,9 @@ enum btree_id_flags {
x(bucket_gens, 14, 0, \
BIT_ULL(KEY_TYPE_bucket_gens)) \
x(snapshot_trees, 15, 0, \
BIT_ULL(KEY_TYPE_snapshot_tree))
BIT_ULL(KEY_TYPE_snapshot_tree)) \
x(deleted_inodes, 16, BTREE_ID_SNAPSHOTS, \
BIT_ULL(KEY_TYPE_set))

enum btree_id {
#define x(name, nr, ...) BTREE_ID_##name = nr,
Expand Down
81 changes: 56 additions & 25 deletions libbcachefs/fs-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include <trace/events/writeback.h>

static void bch2_clamp_data_hole(struct inode *, u64 *, u64 *, unsigned);
static int bch2_clamp_data_hole(struct inode *, u64 *, u64 *, unsigned, bool);

struct folio_vec {
struct folio *fv_folio;
Expand Down Expand Up @@ -3410,11 +3410,15 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
}

if (!(mode & FALLOC_FL_ZERO_RANGE)) {
ret = drop_locks_do(&trans,
(bch2_clamp_data_hole(&inode->v,
&hole_start,
&hole_end,
opts.data_replicas), 0));
if (bch2_clamp_data_hole(&inode->v,
&hole_start,
&hole_end,
opts.data_replicas, true))
ret = drop_locks_do(&trans,
(bch2_clamp_data_hole(&inode->v,
&hole_start,
&hole_end,
opts.data_replicas, false), 0));
bch2_btree_iter_set_pos(&iter, POS(iter.pos.inode, hole_start));

if (ret)
Expand Down Expand Up @@ -3714,7 +3718,8 @@ static int folio_data_offset(struct folio *folio, loff_t pos,
static loff_t bch2_seek_pagecache_data(struct inode *vinode,
loff_t start_offset,
loff_t end_offset,
unsigned min_replicas)
unsigned min_replicas,
bool nonblock)
{
struct folio_batch fbatch;
pgoff_t start_index = start_offset >> PAGE_SHIFT;
Expand All @@ -3731,7 +3736,13 @@ static loff_t bch2_seek_pagecache_data(struct inode *vinode,
for (i = 0; i < folio_batch_count(&fbatch); i++) {
struct folio *folio = fbatch.folios[i];

folio_lock(folio);
if (!nonblock) {
folio_lock(folio);
} else if (!folio_trylock(folio)) {
folio_batch_release(&fbatch);
return -EAGAIN;
}

offset = folio_data_offset(folio,
max(folio_pos(folio), start_offset),
min_replicas);
Expand Down Expand Up @@ -3796,26 +3807,32 @@ static loff_t bch2_seek_data(struct file *file, u64 offset)

if (next_data > offset)
next_data = bch2_seek_pagecache_data(&inode->v,
offset, next_data, 0);
offset, next_data, 0, false);

if (next_data >= isize)
return -ENXIO;

return vfs_setpos(file, next_data, MAX_LFS_FILESIZE);
}

static bool folio_hole_offset(struct address_space *mapping, loff_t *offset,
unsigned min_replicas)
static int folio_hole_offset(struct address_space *mapping, loff_t *offset,
unsigned min_replicas, bool nonblock)
{
struct folio *folio;
struct bch_folio *s;
unsigned i, sectors;
bool ret = true;

folio = filemap_lock_folio(mapping, *offset >> PAGE_SHIFT);
folio = __filemap_get_folio(mapping, *offset >> PAGE_SHIFT,
!nonblock ? FGP_LOCK : 0, 0);
if (IS_ERR_OR_NULL(folio))
return true;

if (nonblock && !folio_trylock(folio)) {
folio_put(folio);
return -EAGAIN;
}

s = bch2_folio(folio);
if (!s)
goto unlock;
Expand All @@ -3833,37 +3850,51 @@ static bool folio_hole_offset(struct address_space *mapping, loff_t *offset,
ret = false;
unlock:
folio_unlock(folio);
folio_put(folio);
return ret;
}

static loff_t bch2_seek_pagecache_hole(struct inode *vinode,
loff_t start_offset,
loff_t end_offset,
unsigned min_replicas)
unsigned min_replicas,
bool nonblock)
{
struct address_space *mapping = vinode->i_mapping;
loff_t offset = start_offset;

while (offset < end_offset &&
!folio_hole_offset(mapping, &offset, min_replicas))
!folio_hole_offset(mapping, &offset, min_replicas, nonblock))
;

return min(offset, end_offset);
}

static void bch2_clamp_data_hole(struct inode *inode,
u64 *hole_start,
u64 *hole_end,
unsigned min_replicas)
static int bch2_clamp_data_hole(struct inode *inode,
u64 *hole_start,
u64 *hole_end,
unsigned min_replicas,
bool nonblock)
{
*hole_start = bch2_seek_pagecache_hole(inode,
*hole_start << 9, *hole_end << 9, min_replicas) >> 9;
loff_t ret;

ret = bch2_seek_pagecache_hole(inode,
*hole_start << 9, *hole_end << 9, min_replicas, nonblock) >> 9;
if (ret < 0)
return ret;

*hole_start = ret;

if (*hole_start == *hole_end)
return;
return 0;

*hole_end = bch2_seek_pagecache_data(inode,
*hole_start << 9, *hole_end << 9, min_replicas) >> 9;
ret = bch2_seek_pagecache_data(inode,
*hole_start << 9, *hole_end << 9, min_replicas, nonblock) >> 9;
if (ret < 0)
return ret;

*hole_end = ret;
return 0;
}

static loff_t bch2_seek_hole(struct file *file, u64 offset)
Expand Down Expand Up @@ -3895,12 +3926,12 @@ static loff_t bch2_seek_hole(struct file *file, u64 offset)
BTREE_ITER_SLOTS, k, ret) {
if (k.k->p.inode != inode->v.i_ino) {
next_hole = bch2_seek_pagecache_hole(&inode->v,
offset, MAX_LFS_FILESIZE, 0);
offset, MAX_LFS_FILESIZE, 0, false);
break;
} else if (!bkey_extent_is_data(k.k)) {
next_hole = bch2_seek_pagecache_hole(&inode->v,
max(offset, bkey_start_offset(k.k) << 9),
k.k->p.offset << 9, 0);
k.k->p.offset << 9, 0, false);

if (next_hole < k.k->p.offset << 9)
break;
Expand Down
Loading

0 comments on commit bafc817

Please sign in to comment.