]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/subvolume.h
Update bcachefs sources to f638850417 bcachefs: bch2_trans_log_msg()
[bcachefs-tools-debian] / libbcachefs / subvolume.h
index ed02b982ff96f6f0eec46ff217e5ef1f3bbc369e..f609291acafa5a1dff95a526325a5c6091166813 100644 (file)
@@ -2,6 +2,9 @@
 #ifndef _BCACHEFS_SUBVOLUME_H
 #define _BCACHEFS_SUBVOLUME_H
 
+#include "darray.h"
+#include "subvolume_types.h"
+
 void bch2_snapshot_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 const char *bch2_snapshot_invalid(const struct bch_fs *, struct bkey_s_c);
 
@@ -10,8 +13,8 @@ const char *bch2_snapshot_invalid(const struct bch_fs *, struct bkey_s_c);
        .val_to_text    = bch2_snapshot_to_text,                \
 }
 
-int bch2_mark_snapshot(struct bch_fs *, struct bkey_s_c,
-                      struct bkey_s_c, u64, unsigned);
+int bch2_mark_snapshot(struct btree_trans *, struct bkey_s_c,
+                      struct bkey_s_c, unsigned);
 
 static inline struct snapshot_t *snapshot_t(struct bch_fs *c, u32 id)
 {
@@ -56,15 +59,13 @@ static inline bool bch2_snapshot_is_ancestor(struct bch_fs *c, u32 id, u32 ances
 
 struct snapshots_seen {
        struct bpos                     pos;
-       size_t                          nr;
-       size_t                          size;
-       u32                             *d;
+       DARRAY(u32)                     ids;
 };
 
 static inline void snapshots_seen_exit(struct snapshots_seen *s)
 {
-       kfree(s->d);
-       s->d = NULL;
+       kfree(s->ids.data);
+       s->ids.data = NULL;
 }
 
 static inline void snapshots_seen_init(struct snapshots_seen *s)
@@ -74,22 +75,21 @@ static inline void snapshots_seen_init(struct snapshots_seen *s)
 
 static inline int snapshots_seen_add(struct bch_fs *c, struct snapshots_seen *s, u32 id)
 {
-       if (s->nr == s->size) {
-               size_t new_size = max(s->size, 128UL) * 2;
-               u32 *d = krealloc(s->d, new_size * sizeof(s->d[0]), GFP_KERNEL);
-
-               if (!d) {
-                       bch_err(c, "error reallocating snapshots_seen table (new size %zu)",
-                               new_size);
-                       return -ENOMEM;
-               }
+       int ret = darray_push(s->ids, id);
+       if (ret)
+               bch_err(c, "error reallocating snapshots_seen table (size %zu)",
+                       s->ids.size);
+       return ret;
+}
 
-               s->size = new_size;
-               s->d    = d;
-       }
+static inline bool snapshot_list_has_id(snapshot_id_list *s, u32 id)
+{
+       u32 *i;
 
-       s->d[s->nr++] = id;
-       return 0;
+       darray_for_each(*s, i)
+               if (*i == id)
+                       return true;
+       return false;
 }
 
 int bch2_fs_snapshots_check(struct bch_fs *);
@@ -106,9 +106,16 @@ void bch2_subvolume_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c)
 
 int bch2_subvolume_get(struct btree_trans *, unsigned,
                       bool, int, struct bch_subvolume *);
+int bch2_snapshot_get_subvol(struct btree_trans *, u32,
+                            struct bch_subvolume *);
 int bch2_subvolume_get_snapshot(struct btree_trans *, u32, u32 *);
 
-int bch2_subvolume_delete(struct btree_trans *, u32, int);
+/* only exported for tests: */
+int bch2_snapshot_node_create(struct btree_trans *, u32,
+                             u32 *, u32 *, unsigned);
+
+int bch2_subvolume_delete(struct btree_trans *, u32);
+int bch2_subvolume_unlink(struct btree_trans *, u32);
 int bch2_subvolume_create(struct btree_trans *, u64, u32,
                          u32 *, u32 *, bool);