tools headers UAPI: Sync openat2.h with the kernel sources
[linux-2.6-microblaze.git] / fs / btrfs / zoned.h
index 8abe2f8..61e9696 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/blkdev.h>
 #include "volumes.h"
 #include "disk-io.h"
+#include "block-group.h"
 
 struct btrfs_zoned_device_info {
        /*
@@ -25,6 +26,7 @@ struct btrfs_zoned_device_info {
 #ifdef CONFIG_BLK_DEV_ZONED
 int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
                       struct blk_zone *zone);
+int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info);
 int btrfs_get_dev_zone_info(struct btrfs_device *device);
 void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
 int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
@@ -35,6 +37,28 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
                          u64 *bytenr_ret);
 void btrfs_advance_sb_log(struct btrfs_device *device, int mirror);
 int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror);
+u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,
+                                u64 hole_end, u64 num_bytes);
+int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical,
+                           u64 length, u64 *bytes);
+int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size);
+int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new);
+void btrfs_calc_zone_unusable(struct btrfs_block_group *cache);
+void btrfs_redirty_list_add(struct btrfs_transaction *trans,
+                           struct extent_buffer *eb);
+void btrfs_free_redirty_list(struct btrfs_transaction *trans);
+bool btrfs_use_zone_append(struct btrfs_inode *inode, struct extent_map *em);
+void btrfs_record_physical_zoned(struct inode *inode, u64 file_offset,
+                                struct bio *bio);
+void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered);
+bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info,
+                                   struct extent_buffer *eb,
+                                   struct btrfs_block_group **cache_ret);
+void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache,
+                                    struct extent_buffer *eb);
+int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length);
+int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical,
+                                 u64 physical_start, u64 physical_pos);
 #else /* CONFIG_BLK_DEV_ZONED */
 static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
                                     struct blk_zone *zone)
@@ -42,6 +66,11 @@ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
        return 0;
 }
 
+static inline int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info)
+{
+       return 0;
+}
+
 static inline int btrfs_get_dev_zone_info(struct btrfs_device *device)
 {
        return 0;
@@ -85,6 +114,78 @@ static inline int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror
        return 0;
 }
 
+static inline u64 btrfs_find_allocatable_zones(struct btrfs_device *device,
+                                              u64 hole_start, u64 hole_end,
+                                              u64 num_bytes)
+{
+       return hole_start;
+}
+
+static inline int btrfs_reset_device_zone(struct btrfs_device *device,
+                                         u64 physical, u64 length, u64 *bytes)
+{
+       *bytes = 0;
+       return 0;
+}
+
+static inline int btrfs_ensure_empty_zones(struct btrfs_device *device,
+                                          u64 start, u64 size)
+{
+       return 0;
+}
+
+static inline int btrfs_load_block_group_zone_info(
+               struct btrfs_block_group *cache, bool new)
+{
+       return 0;
+}
+
+static inline void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) { }
+
+static inline void btrfs_redirty_list_add(struct btrfs_transaction *trans,
+                                         struct extent_buffer *eb) { }
+static inline void btrfs_free_redirty_list(struct btrfs_transaction *trans) { }
+
+static inline bool btrfs_use_zone_append(struct btrfs_inode *inode,
+                                        struct extent_map *em)
+{
+       return false;
+}
+
+static inline void btrfs_record_physical_zoned(struct inode *inode,
+                                              u64 file_offset, struct bio *bio)
+{
+}
+
+static inline void btrfs_rewrite_logical_zoned(
+                               struct btrfs_ordered_extent *ordered) { }
+
+static inline bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info,
+                              struct extent_buffer *eb,
+                              struct btrfs_block_group **cache_ret)
+{
+       return true;
+}
+
+static inline void btrfs_revert_meta_write_pointer(
+                                               struct btrfs_block_group *cache,
+                                               struct extent_buffer *eb)
+{
+}
+
+static inline int btrfs_zoned_issue_zeroout(struct btrfs_device *device,
+                                           u64 physical, u64 length)
+{
+       return -EOPNOTSUPP;
+}
+
+static inline int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev,
+                                               u64 logical, u64 physical_start,
+                                               u64 physical_pos)
+{
+       return -EOPNOTSUPP;
+}
+
 #endif
 
 static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
@@ -136,12 +237,16 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 p
 static inline bool btrfs_check_device_zone_type(const struct btrfs_fs_info *fs_info,
                                                struct block_device *bdev)
 {
-       u64 zone_size;
-
        if (btrfs_is_zoned(fs_info)) {
-               zone_size = bdev_zone_sectors(bdev) << SECTOR_SHIFT;
-               /* Do not allow non-zoned device */
-               return bdev_is_zoned(bdev) && fs_info->zone_size == zone_size;
+               /*
+                * We can allow a regular device on a zoned filesystem, because
+                * we will emulate the zoned capabilities.
+                */
+               if (!bdev_is_zoned(bdev))
+                       return true;
+
+               return fs_info->zone_size ==
+                       (bdev_zone_sectors(bdev) << SECTOR_SHIFT);
        }
 
        /* Do not allow Host Manged zoned device */
@@ -157,4 +262,46 @@ static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 p
        return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
 }
 
+static inline bool btrfs_can_zone_reset(struct btrfs_device *device,
+                                       u64 physical, u64 length)
+{
+       u64 zone_size;
+
+       if (!btrfs_dev_is_sequential(device, physical))
+               return false;
+
+       zone_size = device->zone_info->zone_size;
+       if (!IS_ALIGNED(physical, zone_size) || !IS_ALIGNED(length, zone_size))
+               return false;
+
+       return true;
+}
+
+static inline void btrfs_zoned_meta_io_lock(struct btrfs_fs_info *fs_info)
+{
+       if (!btrfs_is_zoned(fs_info))
+               return;
+       mutex_lock(&fs_info->zoned_meta_io_lock);
+}
+
+static inline void btrfs_zoned_meta_io_unlock(struct btrfs_fs_info *fs_info)
+{
+       if (!btrfs_is_zoned(fs_info))
+               return;
+       mutex_unlock(&fs_info->zoned_meta_io_lock);
+}
+
+static inline void btrfs_clear_treelog_bg(struct btrfs_block_group *bg)
+{
+       struct btrfs_fs_info *fs_info = bg->fs_info;
+
+       if (!btrfs_is_zoned(fs_info))
+               return;
+
+       spin_lock(&fs_info->treelog_bg_lock);
+       if (fs_info->treelog_bg == bg->start)
+               fs_info->treelog_bg = 0;
+       spin_unlock(&fs_info->treelog_bg_lock);
+}
+
 #endif