]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/alloc_foreground.h
New upstream snapshot
[bcachefs-tools-debian] / libbcachefs / alloc_foreground.h
index c658295cb8e09f375b5b416a222b14e3070fb779..d466bda9afc8fdddb49f7b353c8c571b12f1fcf6 100644 (file)
@@ -12,13 +12,6 @@ struct bch_dev;
 struct bch_fs;
 struct bch_devs_List;
 
-enum bucket_alloc_ret {
-       ALLOC_SUCCESS,
-       OPEN_BUCKETS_EMPTY,
-       FREELIST_EMPTY,         /* Allocator thread not keeping up */
-       INSUFFICIENT_DEVICES,
-};
-
 struct dev_alloc_list {
        unsigned        nr;
        u8              devs[BCH_SB_MEMBERS_MAX];
@@ -92,14 +85,37 @@ static inline void bch2_open_bucket_get(struct bch_fs *c,
        unsigned i;
 
        open_bucket_for_each(c, &wp->ptrs, ob, i) {
-               ob->type = wp->type;
+               ob->data_type = wp->data_type;
                atomic_inc(&ob->pin);
                ob_push(c, ptrs, ob);
        }
 }
 
-enum bucket_alloc_ret
-bch2_bucket_alloc_set(struct bch_fs *, struct open_buckets *,
+static inline open_bucket_idx_t *open_bucket_hashslot(struct bch_fs *c,
+                                                 unsigned dev, u64 bucket)
+{
+       return c->open_buckets_hash +
+               (jhash_3words(dev, bucket, bucket >> 32, 0) &
+                (OPEN_BUCKETS_COUNT - 1));
+}
+
+static inline bool bch2_bucket_is_open(struct bch_fs *c, unsigned dev, u64 bucket)
+{
+       open_bucket_idx_t slot = *open_bucket_hashslot(c, dev, bucket);
+
+       while (slot) {
+               struct open_bucket *ob = &c->open_buckets[slot];
+
+               if (ob->dev == dev && ob->bucket == bucket)
+                       return true;
+
+               slot = ob->hash;
+       }
+
+       return false;
+}
+
+int bch2_bucket_alloc_set(struct bch_fs *, struct open_buckets *,
                      struct dev_stripe_state *, struct bch_devs_mask *,
                      unsigned, unsigned *, bool *, enum alloc_reserve,
                      unsigned, struct closure *);
@@ -113,8 +129,9 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *,
                                             unsigned,
                                             struct closure *);
 
+struct bch_extent_ptr bch2_ob_ptr(struct bch_fs *, struct open_bucket *);
 void bch2_alloc_sectors_append_ptrs(struct bch_fs *, struct write_point *,
-                                   struct bkey_i *, unsigned);
+                                   struct bkey_i *, unsigned, bool);
 void bch2_alloc_sectors_done(struct bch_fs *, struct write_point *);
 
 void bch2_open_buckets_stop_dev(struct bch_fs *, struct bch_dev *,
@@ -135,4 +152,6 @@ static inline struct write_point_specifier writepoint_ptr(struct write_point *wp
 
 void bch2_fs_allocator_foreground_init(struct bch_fs *);
 
+void bch2_open_buckets_to_text(struct printbuf *, struct bch_fs *);
+
 #endif /* _BCACHEFS_ALLOC_FOREGROUND_H */