]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/super.h
Update bcachefs sources to 1d669389f7 bcachefs: use a radix tree for inum bitmap...
[bcachefs-tools-debian] / libbcachefs / super.h
index a52ee3bb37ee3e80d3e8e1f3677d5c0f8bed1071..02c81f3555c3559d7a7d2b2f65bce28ded807899 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _BCACHEFS_SUPER_H
 #define _BCACHEFS_SUPER_H
 
@@ -27,7 +28,26 @@ static inline sector_t bucket_remainder(const struct bch_dev *ca, sector_t s)
 
 static inline bool bch2_dev_is_online(struct bch_dev *ca)
 {
-       return ca->disk_sb.bdev != NULL;
+       return !percpu_ref_is_zero(&ca->io_ref);
+}
+
+static inline bool bch2_dev_is_readable(struct bch_dev *ca)
+{
+       return bch2_dev_is_online(ca) &&
+               ca->mi.state != BCH_MEMBER_STATE_FAILED;
+}
+
+static inline bool bch2_dev_get_ioref(struct bch_dev *ca, int rw)
+{
+       if (!percpu_ref_tryget(&ca->io_ref))
+               return false;
+
+       if (ca->mi.state == BCH_MEMBER_STATE_RW ||
+           (ca->mi.state == BCH_MEMBER_STATE_RO && rw == READ))
+               return true;
+
+       percpu_ref_put(&ca->io_ref);
+       return false;
 }
 
 static inline unsigned dev_mask_nr(const struct bch_devs_mask *devs)
@@ -179,7 +199,6 @@ static inline struct bch_devs_mask bch2_online_devs(struct bch_fs *c)
 
 struct bch_fs *bch2_bdev_to_fs(struct block_device *);
 struct bch_fs *bch2_uuid_to_fs(uuid_le);
-int bch2_congested(void *, int);
 
 bool bch2_dev_state_allowed(struct bch_fs *, struct bch_dev *,
                           enum bch_member_state, int);
@@ -198,11 +217,24 @@ struct bch_dev *bch2_dev_lookup(struct bch_fs *, const char *);
 
 bool bch2_fs_emergency_read_only(struct bch_fs *);
 void bch2_fs_read_only(struct bch_fs *);
-const char *bch2_fs_read_write(struct bch_fs *);
 
+int bch2_fs_read_write(struct bch_fs *);
+int bch2_fs_read_write_early(struct bch_fs *);
+
+/*
+ * Only for use in the recovery/fsck path:
+ */
+static inline void bch2_fs_lazy_rw(struct bch_fs *c)
+{
+       if (percpu_ref_is_zero(&c->writes))
+               bch2_fs_read_write_early(c);
+}
+
+void __bch2_fs_stop(struct bch_fs *);
+void bch2_fs_free(struct bch_fs *);
 void bch2_fs_stop(struct bch_fs *);
 
-const char *bch2_fs_start(struct bch_fs *);
+int bch2_fs_start(struct bch_fs *);
 struct bch_fs *bch2_fs_open(char * const *, unsigned, struct bch_opts);
 const char *bch2_fs_open_incremental(const char *path);