btrfs-progs: sync basic code from the kernel
Subsystems (2)
cover btrfs-progs: sync basic code from the kernel
Hello,
This series copies the easier to sync files from the kernel into btrfs-progs and updates all the users to include the appropriate headers. There's an extra change in here to deal with va_format, which we'll need for future syncs. I put it in here because it's related to the messages sync, so it seemed appropriate.
This depends on the series
btrfs-progs: prep work for syncing files into kernel-shared
Thanks,
Josef
Josef Bacik (8):
btrfs-progs: sync uapi/btrfs.h into btrfs-progs
btrfs-progs: sync ondisk definitions from the kernel
btrfs-progs: sync messages.* from the kernel
btrfs-progs: add struct va_format support to our btrfs_no_printk
helper
btrfs-progs: sync accessors.[ch] from the kernel
btrfs-progs: sync file-item.h into progs
btrfs-progs: sync async-thread.[ch] from the kernel
btrfs-progs: sync extent-io-tree.[ch] and misc.h from the kernel
Makefile | 4 + btrfs-corrupt-block.c | 3 +- btrfs-fragments.c | 2 +- check/clear-cache.c | 15 +- check/common.h | 2 +- check/main.c | 34 +- check/mode-common.c | 19 +- check/mode-lowmem.c | 11 +- check/repair.c | 16 +- cmds/balance.c | 2 +- cmds/device.c | 2 +- cmds/filesystem-usage.h | 2 +- cmds/filesystem.c | 2 +- cmds/inspect-tree-stats.c | 1 + cmds/inspect.c | 2 +- cmds/property.c | 2 +- cmds/qgroup.c | 2 +- cmds/qgroup.h | 2 +- cmds/quota.c | 2 +- cmds/receive.c | 2 +- cmds/replace.c | 2 +- cmds/rescue-chunk-recover.c | 4 +- cmds/restore.c | 3 +- cmds/scrub.c | 2 +- cmds/send.c | 2 +- cmds/subvolume-list.c | 2 +- cmds/subvolume.c | 2 +- common/device-scan.c | 2 +- common/device-scan.h | 2 +- common/fsfeatures.c | 2 +- common/internal.h | 4 + common/messages.c | 42 + common/messages.h | 18 + common/send-stream.c | 2 +- common/send-utils.c | 2 +- common/utils.c | 2 +- common/utils.h | 2 +- convert/common.c | 2 +- convert/main.c | 1 + convert/source-ext2.c | 1 + image/main.c | 12 +- include/kerncompat.h | 285 ++- kernel-lib/bitops.h | 12 + kernel-lib/trace.h | 55 + kernel-shared/accessors.c | 117 + kernel-shared/accessors.h | 1087 ++++++++++ kernel-shared/async-thread.c | 339 +++ kernel-shared/async-thread.h | 46 + kernel-shared/backref.c | 1 + kernel-shared/ctree.h | 1890 +---------------- kernel-shared/delayed-ref.c | 1 + kernel-shared/dir-item.c | 8 +- kernel-shared/disk-io.c | 16 +- kernel-shared/extent-io-tree.c | 1733 +++++++++++++++ kernel-shared/extent-io-tree.h | 239 +++ kernel-shared/extent-tree.c | 52 +- kernel-shared/extent_io.c | 474 +---- kernel-shared/extent_io.h | 39 +- kernel-shared/file-item.c | 13 +- kernel-shared/file-item.h | 89 + kernel-shared/file.c | 1 + kernel-shared/free-space-tree.c | 1 + kernel-shared/inode.c | 2 +- kernel-shared/messages.c | 336 +++ kernel-shared/messages.h | 216 ++ kernel-shared/misc.h | 143 ++ kernel-shared/print-tree.c | 17 +- kernel-shared/transaction.c | 5 +- include/ioctl.h => kernel-shared/uapi/btrfs.h | 566 +++-- kernel-shared/uapi/btrfs_tree.h | 1259 +++++++++++ kernel-shared/ulist.c | 1 + kernel-shared/zoned.h | 1 + libbtrfs/kerncompat.h | 20 - mkfs/common.c | 3 +- mkfs/rootdir.c | 1 + tests/ioctl-test.c | 2 +- tune/change-metadata-uuid.c | 2 +- tune/change-uuid.c | 2 +- 78 files changed, 6530 insertions(+), 2782 deletions(-) create mode 100644 kernel-lib/trace.h create mode 100644 kernel-shared/accessors.c create mode 100644 kernel-shared/accessors.h create mode 100644 kernel-shared/async-thread.c create mode 100644 kernel-shared/async-thread.h create mode 100644 kernel-shared/extent-io-tree.c create mode 100644 kernel-shared/extent-io-tree.h create mode 100644 kernel-shared/file-item.h create mode 100644 kernel-shared/messages.c create mode 100644 kernel-shared/messages.h create mode 100644 kernel-shared/misc.h rename include/ioctl.h => kernel-shared/uapi/btrfs.h (72%) create mode 100644 kernel-shared/uapi/btrfs_tree.h
Signature · 1 line
2.40.0
PATCH 4/8 btrfs-progs: add struct va_format support to our btrfs_no_printk helper
We use the struct va_format to do nested printk's internally with our message handling. Add the appropriate user space code to make this work properly so when we start copying this code into btrfs-progs we get the proper messages.
--- common/messages.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
common/messages.c +31 -0
@@ -16,6 +16,7 @@#include <stdio.h> #include <stdarg.h> +#include <printf.h> #include "common/messages.h" #include "common/utils.h"
@@ -25,6 +26,8 @@ static const char *common_error_string[] = { [ERROR_MSG_COMMIT_TRANS] = "failed to commit transaction", }; +static int va_modifier =-1 ; + __attribute__ ((format (printf,1 ,2 )))void __btrfs_printf (const char *fmt, ...) {
@@ -35,11 +38,39 @@ void __btrfs_printf(const char *fmt, ...)va_end (args); } +static int print_va_format (FILE *stream,const struct printf_info *info, +const void *const *args) +{ +const struct va_format *fmt; + +if (!(info->user & va_modifier)) +return -2 ; + + fmt = *((const struct va_format **)(args[0 ])); +return vfprintf (stream, fmt->fmt, *(fmt->va)); +} + +static int print_va_format_arginfo (const struct printf_info *info, +size_t n,int *argtypes,int *size) +{ +if (n >0 ) { + argtypes[0 ] =PA_POINTER ; + size[0 ] =sizeof (struct va_format *); + } +return 1 ; + } + __attribute__ ((format (printf,2 ,3 )))void btrfs_no_printk (const void *fs_info,const char *fmt, ...) {va_list args; +if (va_modifier ==-1 ) { +register_printf_specifier ('V' , print_va_format, + print_va_format_arginfo); + va_modifier =register_printf_modifier (L"p" ); + } +va_start (args, fmt);vfprintf (stderr, fmt, args);va_end (args);
Signature · 1 line
2.40.0
PATCH 3/8 btrfs-progs: sync messages.* from the kernel
In reply to Josef BacikThese are the printk helpers from the kernel. There were a few modifications, the hi-lights are
- We do not have fs_info::fs_state, so that needed to be removed.
- We do not have discard.h sync'ed yet, so that dependency was dropped.
- Anything related to struct super_block was commented out.
- The transaction abort had to be modified to fit with the current btrfs-progs code.
- Added a btrfs_no_printk() helper to common/messages.* so that the print statements still worked.
Additionally there were kerncompat.h changes that needed to be made to handle the dependencies properly. Those are easier to spot.
Any function that needed to be modified has a MODIFIED tag in the comment section with a list of things that were changed.
--- Makefile | 1 + common/messages.c | 11 ++ common/messages.h | 18 ++ include/kerncompat.h | 44 +++-- kernel-shared/backref.c | 1 + kernel-shared/ctree.h | 2 + kernel-shared/delayed-ref.c | 1 + kernel-shared/extent_io.c | 1 + kernel-shared/free-space-tree.c | 1 + kernel-shared/messages.c | 336 ++++++++++++++++++++++++++++++++ kernel-shared/messages.h | 216 ++++++++++++++++++++ kernel-shared/ulist.c | 1 + kernel-shared/zoned.h | 1 + libbtrfs/kerncompat.h | 20 -- 14 files changed, 614 insertions(+), 40 deletions(-) create mode 100644 kernel-shared/messages.c create mode 100644 kernel-shared/messages.h
Makefile +1 -0
@@ -179,6 +179,7 @@ objects = \ kernel-shared/free-space-tree.o \ kernel-shared/inode-item.o \ kernel-shared/inode.o \ + kernel-shared/messages.o \ kernel-shared/print-tree.o \ kernel-shared/root-tree.o \ kernel-shared/transaction.o \
common/messages.c +11 -0
@@ -35,6 +35,17 @@ void __btrfs_printf(const char *fmt, ...)va_end (args); } +__attribute__ ((format (printf,2 ,3 ))) +void btrfs_no_printk (const void *fs_info,const char *fmt, ...) +{ +va_list args; + +va_start (args, fmt); +vfprintf (stderr, fmt, args); +va_end (args); +fputc ('\n' , stderr); +} +static bool should_print (int level) {if (bconf.verbose ==BTRFS_BCONF_QUIET || level ==BTRFS_BCONF_QUIET )
common/messages.h +18 -0
@@ -111,6 +111,9 @@ __attribute__ ((format (printf,1 ,2 )))void __btrfs_printf (const char *fmt, ...); +__attribute__ ((format (printf,2 ,3 ))) +void btrfs_no_printk (const void *fs_info,const char *fmt, ...); +/* * Level of messages that must be printed by default (in case the verbosity * options haven't been set by the user) due to backward compatibility reasons
@@ -154,6 +157,21 @@ __attribute__ ((format (printf, 2, 3)))void error_msg (enum common_error error,const char *msg, ...);#ifndef BTRFS_DISABLE_BACKTRACE +static inline void assert_trace (const char *assertion,const char *filename, +const char *func,unsigned line,long val) +{ +if (val) +return ; +fprintf (stderr, +"%s:%d: %s: Assertion `%s` failed, value %ld\n" , + filename, line, func, assertion, val); +#ifndef BTRFS_DISABLE_BACKTRACE +print_trace (); +#endif +abort (); +exit (1 ); +} +#define UASSERT (c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))#else #define UASSERT (c) assert(c)
include/kerncompat.h +24 -20
70 lines not on this page · raw message
kernel-shared/backref.c +1 -0
@@ -23,6 +23,7 @@#include "kernel-shared/ulist.h" #include "kernel-shared/transaction.h" #include "common/internal.h" +#include "messages.h" #define pr_debug (...) do { } while (0)
kernel-shared/ctree.h +2 -0
@@ -377,6 +377,8 @@ struct btrfs_fs_info {u64 zone_size;u64 zoned; }; + +struct super_block *sb; };static inline bool btrfs_is_zoned (const struct btrfs_fs_info *fs_info)
kernel-shared/delayed-ref.c +1 -0
@@ -20,6 +20,7 @@#include "kernel-shared/ctree.h" #include "kernel-shared/delayed-ref.h" #include "kernel-shared/transaction.h" +#include "messages.h" /* * delayed back reference update tracking. For subvolume trees
kernel-shared/extent_io.c +1 -0
@@ -34,6 +34,7 @@#include "common/utils.h" #include "common/device-utils.h" #include "common/internal.h" +#include "messages.h" static void free_extent_buffer_final (struct extent_buffer *eb);
kernel-shared/free-space-tree.c +1 -0
@@ -24,6 +24,7 @@#include "kernel-shared/transaction.h" #include "kernel-lib/bitops.h" #include "common/internal.h" +#include "messages.h" static struct btrfs_root *btrfs_free_space_root (struct btrfs_fs_info *fs_info,struct btrfs_block_group *block_group)
kernel-shared/messages.c new file +336 -0
336 lines not on this page · raw message
kernel-shared/messages.h new file +216 -0
216 lines not on this page · raw message
kernel-shared/ulist.c +1 -0
@@ -21,6 +21,7 @@#include "kerncompat.h" #include "ulist.h" #include "kernel-shared/ctree.h" +#include "messages.h" /* * ulist is a generic data structure to hold a collection of unique u64
kernel-shared/zoned.h +1 -0
@@ -22,6 +22,7 @@#include <stdbool.h> #include "kernel-shared/disk-io.h" #include "kernel-shared/volumes.h" +#include "messages.h" #ifdef BTRFS_ZONED #include <linux/blkzoned.h>
libbtrfs/kerncompat.h +0 -20
@@ -325,26 +325,6 @@ static inline int IS_ERR_OR_NULL(const void *ptr)#define memalloc_nofs_save () (0)#define memalloc_nofs_restore (x) ((void)(x)) -#ifndef BTRFS_DISABLE_BACKTRACE -static inline void assert_trace (const char *assertion,const char *filename, -const char *func,unsigned line,long val) -{ -if (val) -return ; -fprintf (stderr, -"%s:%d: %s: Assertion `%s` failed, value %ld\n" , - filename, line, func, assertion, val); -#ifndef BTRFS_DISABLE_BACKTRACE -print_trace (); -#endif -abort (); -exit (1 ); -} -#define ASSERT (c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) -#else -#define ASSERT (c) assert(c) -#endif -#define BUG_ON (c) bugon_trace(#c, __FILE__, __func__, __LINE__, (long)(c))#define BUG () \ do { \
Signature · 1 line
2.40.0
PATCH 1/8 btrfs-progs: sync uapi/btrfs.h into btrfs-progs
In reply to Josef BacikWe want to keep this file locally as we want to be uptodate with upstream, so we can build btrfs-progs regardless of which kernel is currently installed. Sync this with the upstream version and put it in kernel-shared/uapi to maintain some semblance of where this file comes from.
--- btrfs-fragments.c | 2 +- check/main.c | 2 +- cmds/balance.c | 2 +- cmds/device.c | 2 +- cmds/filesystem-usage.h | 2 +- cmds/filesystem.c | 2 +- cmds/inspect.c | 2 +- cmds/property.c | 2 +- cmds/qgroup.c | 2 +- cmds/qgroup.h | 2 +- cmds/quota.c | 2 +- cmds/receive.c | 2 +- cmds/replace.c | 2 +- cmds/rescue-chunk-recover.c | 2 +- cmds/scrub.c | 2 +- cmds/send.c | 2 +- cmds/subvolume-list.c | 2 +- cmds/subvolume.c | 2 +- common/device-scan.c | 2 +- common/device-scan.h | 2 +- common/fsfeatures.c | 2 +- common/send-stream.c | 2 +- common/send-utils.c | 2 +- common/utils.c | 2 +- common/utils.h | 2 +- convert/common.c | 2 +- image/main.c | 2 +- include/kerncompat.h | 1 + kernel-shared/ctree.h | 2 +- include/ioctl.h => kernel-shared/uapi/btrfs.h | 566 ++++++++++-------- mkfs/common.c | 2 +- tests/ioctl-test.c | 2 +- tune/change-metadata-uuid.c | 2 +- tune/change-uuid.c | 2 +- 34 files changed, 365 insertions(+), 266 deletions(-) rename include/ioctl.h => kernel-shared/uapi/btrfs.h (72%)
btrfs-fragments.c +1 -1
@@ -31,7 +31,7 @@#include <gd.h> #include "kernel-shared/ctree.h" #include "common/utils.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static int use_color; static void
check/main.c +1 -1
@@ -61,7 +61,7 @@#include "check/mode-lowmem.h" #include "check/qgroup-verify.h" #include "check/clear-cache.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" /* Global context variables */ struct btrfs_fs_info *gfs_info;
cmds/balance.c +1 -1
@@ -33,7 +33,7 @@#include "common/messages.h" #include "common/help.h" #include "cmds/commands.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static const char *const balance_cmd_group_usage[] = {"btrfs balance <command> [options] <path>" ,
cmds/device.c +1 -1
@@ -41,7 +41,7 @@#include "cmds/commands.h" #include "cmds/filesystem-usage.h" #include "mkfs/common.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static const char *const device_cmd_group_usage[] = {"btrfs device <command> [<args>]" ,
cmds/filesystem-usage.h +1 -1
@@ -20,7 +20,7 @@#define __CMDS_FI_USAGE_H__#include "kerncompat.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" struct device_info {u64 devid;
cmds/filesystem.c +1 -1
@@ -57,7 +57,7 @@#include "common/format-output.h" #include "cmds/commands.h" #include "cmds/filesystem-usage.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" /* * for btrfs fi show, we maintain a hash of fsids we've already printed.
cmds/inspect.c +1 -1
@@ -43,7 +43,7 @@#include "common/string-utils.h" #include "common/string-table.h" #include "cmds/commands.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static const char *const inspect_cmd_group_usage[] = {"btrfs inspect-internal <command> <args>" ,
cmds/property.c +1 -1
@@ -38,7 +38,7 @@#include "common/filesystem-utils.h" #include "cmds/commands.h" #include "cmds/props.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" #define XATTR_BTRFS_PREFIX "btrfs."#define XATTR_BTRFS_PREFIX_LEN (sizeof(XATTR_BTRFS_PREFIX) - 1)
cmds/qgroup.c +1 -1
@@ -39,7 +39,7 @@#include "common/messages.h" #include "cmds/commands.h" #include "cmds/qgroup.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" #define BTRFS_QGROUP_NFILTERS_INCREASE (2 * BTRFS_QGROUP_FILTER_MAX)#define BTRFS_QGROUP_NCOMPS_INCREASE (2 * BTRFS_QGROUP_COMP_MAX)
cmds/qgroup.h +1 -1
@@ -20,7 +20,7 @@#define __CMDS_QGROUP_H__#include "kerncompat.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" struct btrfs_qgroup_info {u64 generation;
cmds/quota.c +1 -1
@@ -27,7 +27,7 @@#include "common/open-utils.h" #include "common/messages.h" #include "cmds/commands.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static const char *const quota_cmd_group_usage[] = {"btrfs quota <command> [options] <path>" ,
cmds/receive.c +1 -1
@@ -55,7 +55,7 @@#include "common/string-utils.h" #include "cmds/commands.h" #include "cmds/receive-dump.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" struct btrfs_receive {
cmds/replace.c +1 -1
@@ -39,7 +39,7 @@#include "common/messages.h" #include "cmds/commands.h" #include "mkfs/common.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static int print_replace_status (int fd,const char *path,int once);static char *time2string (char *buf,size_t s,__u64 t);
cmds/rescue-chunk-recover.c +1 -1
@@ -37,7 +37,7 @@#include "common/utils.h" #include "cmds/rescue.h" #include "check/common.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" struct recover_control {int verbose;
cmds/scrub.c +1 -1
@@ -51,7 +51,7 @@#include "common/units.h" #include "common/help.h" #include "cmds/commands.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static unsigned unit_mode =UNITS_DEFAULT ;
cmds/send.c +1 -1
@@ -35,7 +35,7 @@#include "common/string-utils.h" #include "common/messages.h" #include "cmds/commands.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" #define BTRFS_SEND_BUF_SIZE_V1 (SZ_64K)#define BTRFS_MAX_COMPRESSED (SZ_128K)
cmds/subvolume-list.c +1 -1
@@ -35,7 +35,7 @@#include "common/string-utils.h" #include "common/utils.h" #include "cmds/commands.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" /* * Naming of options:
cmds/subvolume.c +1 -1
@@ -42,7 +42,7 @@#include "common/units.h" #include "cmds/commands.h" #include "cmds/qgroup.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static int wait_for_subvolume_cleaning (int fd,size_t count,uint64_t *ids,int sleep_interval)
common/device-scan.c +1 -1
@@ -50,7 +50,7 @@#include "common/defs.h" #include "common/open-utils.h" #include "common/units.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static int btrfs_scan_done =0 ;
common/device-scan.h +1 -1
@@ -19,7 +19,7 @@#include "kerncompat.h" #include <dirent.h> -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" #define BTRFS_SCAN_MOUNTED (1ULL << 0)#define BTRFS_SCAN_LBLKID (1ULL << 1)
common/fsfeatures.c +1 -1
@@ -29,7 +29,7 @@#include "common/string-utils.h" #include "common/utils.h" #include "common/messages.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" /* * Insert a root item for temporary tree root
common/send-stream.c +1 -1
@@ -26,7 +26,7 @@#include "crypto/crc32c.h" #include "common/send-stream.h" #include "common/messages.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" struct btrfs_send_attribute {u16 tlv_type;
common/send-utils.c +1 -1
@@ -28,7 +28,7 @@#include "common/send-utils.h" #include "common/messages.h" #include "common/utils.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static int btrfs_subvolid_resolve_sub (int fd,char *path,size_t *path_len,u64 subvol_id);
common/utils.c +1 -1
@@ -38,7 +38,7 @@#include "common/messages.h" #include "cmds/commands.h" #include "mkfs/common.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static int rand_seed_initialized =0 ;static unsigned short rand_seed[3 ];
common/utils.h +1 -1
@@ -29,7 +29,7 @@#include "common/internal.h" #include "common/messages.h" #include "common/fsfeatures.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" enum exclusive_operation {BTRFS_EXCLOP_NONE ,
convert/common.c +1 -1
@@ -29,7 +29,7 @@#include "common/messages.h" #include "mkfs/common.h" #include "convert/common.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" #define BTRFS_CONVERT_META_GROUP_SIZE SZ_32M
image/main.c +1 -1
@@ -54,7 +54,7 @@#include "cmds/commands.h" #include "image/metadump.h" #include "image/sanitize.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" #define MAX_WORKER_THREADS (32)
include/kerncompat.h +1 -0
@@ -576,5 +576,6 @@ typedef struct wait_queue_head_s {#define __init#define __cold +#define __user#endif
kernel-shared/ctree.h +1 -1
@@ -25,7 +25,7 @@#include "kerncompat.h" #include "common/extent-cache.h" #include "kernel-shared/extent_io.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" struct btrfs_root ;struct btrfs_trans_handle ;
kernel-shared/uapi/btrfs.h renamed from include/ioctl.h +332 -234
902 lines not on this page · raw message
mkfs/common.c +1 -1
@@ -38,7 +38,7 @@#include "common/device-utils.h" #include "common/open-utils.h" #include "mkfs/common.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static u64 reference_root_table[] = { [MKFS_ROOT_TREE ] =BTRFS_ROOT_TREE_OBJECTID ,
tests/ioctl-test.c +1 -1
@@ -18,7 +18,7 @@#include <stdio.h> #include <stdlib.h> -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" #include "kernel-shared/ctree.h" #define LIST_32_COMPAT \
tune/change-metadata-uuid.c +1 -1
@@ -22,7 +22,7 @@#include "kernel-shared/transaction.h" #include "common/messages.h" #include "tune/tune.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" int set_metadata_uuid (struct btrfs_root *root,const char *uuid_string) {
tune/change-uuid.c +1 -1
@@ -25,7 +25,7 @@#include "kernel-shared/volumes.h" #include "common/defs.h" #include "common/messages.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h" static int change_fsid_prepare (struct btrfs_fs_info *fs_info,uuid_t new_fsid) {
Signature · 1 line
2.40.0
PATCH 2/8 btrfs-progs: sync ondisk definitions from the kernel
In reply to Josef BacikThis pulls in the kernel's btrfs_tree.h, which now has all of the ondisk definitions. Include this into ctree.h, and then yank out all the duplicate code from ctree.h.
--- kernel-shared/ctree.h | 954 +---------------------- kernel-shared/uapi/btrfs_tree.h | 1259 +++++++++++++++++++++++++++++++ 2 files changed, 1261 insertions(+), 952 deletions(-) create mode 100644 kernel-shared/uapi/btrfs_tree.h
kernel-shared/ctree.h +2 -952
@@ -26,11 +26,11 @@#include "common/extent-cache.h" #include "kernel-shared/extent_io.h" #include "kernel-shared/uapi/btrfs.h" +#include "kernel-shared/uapi/btrfs_tree.h" struct btrfs_root ;struct btrfs_trans_handle ;struct btrfs_free_space_ctl ; -#define BTRFS_MAGIC 0x4D5F53665248425FULL/* ascii _BHRfS_M, no null */ /* * Fake signature for an unfinalized filesystem, which only has barebone tree
@@ -42,272 +42,10 @@ struct btrfs_free_space_ctl;#define BTRFS_MAX_MIRRORS 3 -#define BTRFS_MAX_LEVEL 8 - -/* holds pointers to all of the tree roots */ -#define BTRFS_ROOT_TREE_OBJECTID 1ULL - -/* stores information about which extents are in use, and reference counts */ -#define BTRFS_EXTENT_TREE_OBJECTID 2ULL - -/* -* chunk tree stores translations from logical -> physical block numbering -* the super block points to the chunk tree -*/ -#define BTRFS_CHUNK_TREE_OBJECTID 3ULL - -/* -* stores information about which areas of a given device are in use. -* one per device. The tree of tree roots points to the device tree -*/ -#define BTRFS_DEV_TREE_OBJECTID 4ULL - -/* one per subvolume, storing files and directories */ -#define BTRFS_FS_TREE_OBJECTID 5ULL - -/* directory objectid inside the root tree */ -#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL -/* holds checksums of all the data extents */ -#define BTRFS_CSUM_TREE_OBJECTID 7ULL -#define BTRFS_QUOTA_TREE_OBJECTID 8ULL - -/* for storing items that use the BTRFS_UUID_KEY* */ -#define BTRFS_UUID_TREE_OBJECTID 9ULL - -/* tracks free space in block groups. */ -#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL - -/* hold the block group items. */ -#define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL - -/* device stats in the device tree */ -#define BTRFS_DEV_STATS_OBJECTID 0ULL - -/* for storing balance parameters in the root tree */ -#define BTRFS_BALANCE_OBJECTID -4ULL - -/* orphan objectid for tracking unlinked/truncated files */ -#define BTRFS_ORPHAN_OBJECTID -5ULL - -/* does write ahead logging to speed up fsyncs */ -#define BTRFS_TREE_LOG_OBJECTID -6ULL -#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL - -/* space balancing */ -#define BTRFS_TREE_RELOC_OBJECTID -8ULL -#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL - -/* -* extent checksums all have this objectid -* this allows them to share the logging tree -* for fsyncs -*/ -#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL - -/* For storing free space cache */ -#define BTRFS_FREE_SPACE_OBJECTID -11ULL - -/* -* The inode number assigned to the special inode for storing -* free ino cache -*/ -#define BTRFS_FREE_INO_OBJECTID -12ULL - -/* dummy objectid represents multiple objectids */ -#define BTRFS_MULTIPLE_OBJECTIDS -255ULL - -/* -* All files have objectids in this range. -*/ -#define BTRFS_FIRST_FREE_OBJECTID 256ULL -#define BTRFS_LAST_FREE_OBJECTID -256ULL -#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL - - - -/* -* the device items go into the chunk tree. The key is in the form -* [ 1 BTRFS_DEV_ITEM_KEY device_id ] -*/ -#define BTRFS_DEV_ITEMS_OBJECTID 1ULL - -#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2ULL - -/* -* the max metadata block size. This limit is somewhat artificial, -* but the memmove costs go through the roof for larger blocks. -*/ -#define BTRFS_MAX_METADATA_BLOCKSIZE 65536 - -/* -* we can actually store much bigger names, but lets not confuse the rest -* of linux -*/ -#define BTRFS_NAME_LEN 255 - -/* -* Theoretical limit is larger, but we keep this down to a sane -* value. That should limit greatly the possibility of collisions on -* inode ref items. -*/ -#define BTRFS_LINK_MAX 65535U - -/* 32 bytes in various csum fields */ -#define BTRFS_CSUM_SIZE 32 - -/* csum types */ -enum btrfs_csum_type { -BTRFS_CSUM_TYPE_CRC32 =0 , -BTRFS_CSUM_TYPE_XXHASH =1 , -BTRFS_CSUM_TYPE_SHA256 =2 , -BTRFS_CSUM_TYPE_BLAKE2 =3 , -}; - -#define BTRFS_EMPTY_DIR_SIZE 0 - -#define BTRFS_FT_UNKNOWN 0 -#define BTRFS_FT_REG_FILE 1 -#define BTRFS_FT_DIR 2 -#define BTRFS_FT_CHRDEV 3 -#define BTRFS_FT_BLKDEV 4 -#define BTRFS_FT_FIFO 5 -#define BTRFS_FT_SOCK 6 -#define BTRFS_FT_SYMLINK 7 -#define BTRFS_FT_XATTR 8 -#define BTRFS_FT_MAX 9 - -#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0) - -/* -* the key defines the order in the tree, and so it also defines (optimal) -* block layout. objectid corresponds to the inode number. The flags -* tells us things about the object, and is a kind of stream selector. -* so for a given inode, keys with flags of 1 might refer to the inode -* data, flags of 2 may point to file data in the btree and flags == 3 -* may point to extents. -* -* offset is the starting byte offset for this key in the stream. -* -* btrfs_disk_key is in disk byte order. struct btrfs_key is always -* in cpu native order. Otherwise they are identical and their sizes -* should be the same (ie both packed) -*/ -struct btrfs_disk_key { -__le64 objectid; -u8 type; -__le64 offset; -} __attribute__ ((__packed__ )); - -struct btrfs_key { -u64 objectid; -u8 type; -u64 offset; -} __attribute__ ((__packed__ )); -struct btrfs_mapping_tree {struct cache_tree cache_tree; }; -#define BTRFS_UUID_SIZE 16 -struct btrfs_dev_item { -/* the internal btrfs device id */ -__le64 devid; - -/* size of the device */ -__le64 total_bytes; - -/* bytes used */ -__le64 bytes_used; - -/* optimal io alignment for this device */ -__le32 io_align; - -/* optimal io width for this device */ -__le32 io_width; - -/* minimal io size for this device */ -__le32 sector_size; - -/* type and info about this device */ -__le64 type; - -/* expected generation for this device */ -__le64 generation; - -/* -* starting byte of this partition on the device, -* to allow for stripe alignment in the future -*/ -__le64 start_offset; - -/* grouping information for allocation decisions */ -__le32 dev_group; - -/* seek speed 0-100 where 100 is fastest */ -u8 seek_speed; - -/* bandwidth 0-100 where 100 is fastest */ -u8 bandwidth; - -/* btrfs generated uuid for this device */ -u8 uuid[BTRFS_UUID_SIZE ]; - -/* uuid of FS who owns this device */ -u8 fsid[BTRFS_UUID_SIZE ]; -} __attribute__ ((__packed__ )); - -struct btrfs_stripe { -__le64 devid; -__le64 offset; -u8 dev_uuid[BTRFS_UUID_SIZE ]; -} __attribute__ ((__packed__ )); - -struct btrfs_chunk { -/* size of this chunk in bytes */ -__le64 length; - -/* objectid of the root referencing this chunk */ -__le64 owner; - -__le64 stripe_len; -__le64 type; - -/* optimal io alignment for this chunk */ -__le32 io_align; - -/* optimal io width for this chunk */ -__le32 io_width; - -/* minimal io size for this chunk */ -__le32 sector_size; - -/* 2^16 stripes is quite a lot, a second limit is the size of a single -* item in the btree -*/ -__le16 num_stripes; - -/* sub stripes only matter for raid10 */ -__le16 sub_stripes; -struct btrfs_stripe stripe; -/* additional stripes go here */ -} __attribute__ ((__packed__ )); - -#define BTRFS_FREE_SPACE_EXTENT 1 -#define BTRFS_FREE_SPACE_BITMAP 2 - -struct btrfs_free_space_entry { -__le64 offset; -__le64 bytes; -u8 type; -} __attribute__ ((__packed__ )); - -struct btrfs_free_space_header { -struct btrfs_disk_key location; -__le64 generation; -__le64 num_entries; -__le64 num_bitmaps; -} __attribute__ ((__packed__ )); -static inline unsigned long btrfs_chunk_item_size (int num_stripes) {BUG_ON (num_stripes ==0 );
@@ -315,17 +53,8 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)sizeof (struct btrfs_stripe ) * (num_stripes -1 ); } -#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0) -#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) -/* Temporary flag not on-disk for blocks that have changed csum already */ -#define BTRFS_HEADER_FLAG_CSUM_NEW (1ULL << 16) - -#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32) -#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33) -#define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34) -#define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35) -#define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36) +#define BTRFS_HEADER_FLAG_CSUM_NEW (1ULL << 16)#define BTRFS_SUPER_FLAG_CHANGING_CSUM (1ULL << 37)/*
@@ -335,32 +64,6 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)*/ #define BTRFS_SUPER_FLAG_CHANGING_BG_TREE (1ULL << 38) -#define BTRFS_BACKREF_REV_MAX 256 -#define BTRFS_BACKREF_REV_SHIFT 56 -#define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \ - BTRFS_BACKREF_REV_SHIFT) - -#define BTRFS_OLD_BACKREF_REV 0 -#define BTRFS_MIXED_BACKREF_REV 1 - -/* -* every tree block (leaf or node) starts with this header. -*/ -struct btrfs_header { -/* these first four must match the super block */ -u8 csum[BTRFS_CSUM_SIZE ]; -u8 fsid[BTRFS_FSID_SIZE ];/* FS specific uuid */ -__le64 bytenr;/* which block this node is supposed to live in */ -__le64 flags; - -/* allowed to be different from the super from here on down */ -u8 chunk_tree_uuid[BTRFS_UUID_SIZE ]; -__le64 generation; -__le64 owner; -__le32 nritems; -u8 level; -} __attribute__ ((__packed__ )); -static inline u32 __BTRFS_LEAF_DATA_SIZE (u32 nodesize) {return nodesize -sizeof (struct btrfs_header );
@@ -368,160 +71,9 @@ static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize)#define BTRFS_LEAF_DATA_SIZE (fs_info) (fs_info->leaf_data_size) -/* -* this is a very generous portion of the super block, giving us -* room to translate 14 chunks with 3 stripes each. -*/ -#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 -#define BTRFS_LABEL_SIZE 256 - -/* -* just in case we somehow lose the roots and are not able to mount, -* we store an array of the roots from previous transactions -* in the super. -*/ -#define BTRFS_NUM_BACKUP_ROOTS 4 -struct btrfs_root_backup { -__le64 tree_root; -__le64 tree_root_gen; - -__le64 chunk_root; -__le64 chunk_root_gen; - -__le64 extent_root; -__le64 extent_root_gen; - -__le64 fs_root; -__le64 fs_root_gen; - -__le64 dev_root; -__le64 dev_root_gen; - -__le64 csum_root; -__le64 csum_root_gen; - -__le64 total_bytes; -__le64 bytes_used; -__le64 num_devices; -/* future */ -__le64 unsed_64[4 ]; - -u8 tree_root_level; -u8 chunk_root_level; -u8 extent_root_level; -u8 fs_root_level; -u8 dev_root_level; -u8 csum_root_level; -/* future and to align */ -u8 unused_8[10 ]; -} __attribute__ ((__packed__ )); -#define BTRFS_SUPER_INFO_OFFSET (65536)#define BTRFS_SUPER_INFO_SIZE (4096) -/* -* the super block basically lists the main trees of the FS -* it currently lacks any block count etc etc -*/ -struct btrfs_super_block { -u8 csum[BTRFS_CSUM_SIZE ]; -/* the first 3 fields must match struct btrfs_header */ -u8 fsid[BTRFS_FSID_SIZE ];/* FS specific uuid */ -__le64 bytenr;/* this block number */ -__le64 flags; - -/* allowed to be different from the btrfs_header from here own down */ -__le64 magic; -__le64 generation; -__le64 root; -__le64 chunk_root; -__le64 log_root; - -/* -* This has never been used and is 0 in all versions. We always use -* generation + 1 to read log tree root. -*/ -__le64 __unused_log_root_transid; -__le64 total_bytes; -__le64 bytes_used; -__le64 root_dir_objectid; -__le64 num_devices; -__le32 sectorsize; -__le32 nodesize; -/* Unused and must be equal to nodesize */ -__le32 __unused_leafsize; -__le32 stripesize; -__le32 sys_chunk_array_size; -__le64 chunk_root_generation; -__le64 compat_flags; -__le64 compat_ro_flags; -__le64 incompat_flags; -__le16 csum_type; -u8 root_level; -u8 chunk_root_level; -u8 log_root_level; -struct btrfs_dev_item dev_item; - -char label[BTRFS_LABEL_SIZE ]; - -__le64 cache_generation; -__le64 uuid_tree_generation; - -u8 metadata_uuid[BTRFS_FSID_SIZE ]; - -__le64 nr_global_roots; - -__le64 reserved[27 ]; -u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; -struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS ]; -/* Padded to 4096 bytes */ -u8 padding[565 ]; -} __attribute__ ((__packed__ )); -BUILD_ASSERT (sizeof (struct btrfs_super_block ) ==BTRFS_SUPER_INFO_SIZE ); - -/* -* Compat flags that we support. If any incompat flags are set other than the -* ones specified below then we will fail to mount -*/ -#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0) -/* -* Older kernels on big-endian systems produced broken free space tree bitmaps, -* and btrfs-progs also used to corrupt the free space tree. If this bit is -* clear, then the free space tree cannot be trusted. btrfs-progs can also -* intentionally clear this bit to ask the kernel to rebuild the free space -* tree. -*/ -#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1) -#define BTRFS_FEATURE_COMPAT_RO_VERITY (1ULL << 2) - -/* -* Save all block group items into a dedicated block group tree, to greatly -* reduce mount time for large fs. -*/ -#define BTRFS_FEATURE_COMPAT_RO_BLOCK_GROUP_TREE (1ULL << 3) - -#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0) -#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1) -#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2) -#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3) -#define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4) - -/* -* older kernels tried to do bigger metadata blocks, but the -* code was pretty buggy. Lets not let them try anymore. -*/ -#define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5) -#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6) -#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7) -#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8) -#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9) -#define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10) -#define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) -#define BTRFS_FEATURE_INCOMPAT_ZONED (1ULL << 12) -#define BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 (1ULL << 13) - -#define BTRFS_FEATURE_COMPAT_SUPP 0ULL -/* * The FREE_SPACE_TREE and FREE_SPACE_TREE_VALID compat_ro bits must not be * added here until read-write support for the free space tree is implemented in
@@ -566,43 +118,6 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE); BTRFS_FEATURE_INCOMPAT_ZONED)#endif -/* -* A leaf is full of items. offset and size tell us where to find -* the item in the leaf (relative to the start of the data area) -*/ -struct btrfs_item { -struct btrfs_disk_key key; -__le32 offset; -__le32 size; -} __attribute__ ((__packed__ )); - -/* -* leaves have an item area and a data area: -* [item0, item1....itemN] [free space] [dataN...data1, data0] -* -* The data is separate from the items to get the keys closer together -* during searches. -*/ -struct btrfs_leaf { -struct btrfs_header header; -struct btrfs_item items[]; -} __attribute__ ((__packed__ )); - -/* -* all non-leaf blocks are nodes, they hold only keys and pointers to -* other blocks -*/ -struct btrfs_key_ptr { -struct btrfs_disk_key key; -__le64 blockptr; -__le64 generation; -} __attribute__ ((__packed__ )); - -struct btrfs_node { -struct btrfs_header header; -struct btrfs_key_ptr ptrs[]; -} __attribute__ ((__packed__ )); -/* * btrfs_paths remember the path taken from the root down to the leaf. * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
@@ -631,98 +146,11 @@ struct btrfs_path {u8 skip_check_block; }; -/* -* items in the extent btree are used to record the objectid of the -* owner of the block and the number of references -*/ - -struct btrfs_extent_item { -__le64 refs; -__le64 generation; -__le64 flags; -} __attribute__ ((__packed__ )); - -struct btrfs_extent_item_v0 { -__le32 refs; -} __attribute__ ((__packed__ )); -#define BTRFS_MAX_EXTENT_ITEM_SIZE (r) \ ((BTRFS_LEAF_DATA_SIZE(r->fs_info) >> 4) - \ sizeof(struct btrfs_item))#define BTRFS_MAX_EXTENT_SIZE 128UL * 1024 * 1024 -#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0) -#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1) - -/* following flags only apply to tree blocks */ - -/* use full backrefs for extent pointers in the block*/ -#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8) - -struct btrfs_tree_block_info { -struct btrfs_disk_key key; -u8 level; -} __attribute__ ((__packed__ )); - -struct btrfs_extent_data_ref { -__le64 root; -__le64 objectid; -__le64 offset; -__le32 count; -} __attribute__ ((__packed__ )); - -struct btrfs_shared_data_ref { -__le32 count; -} __attribute__ ((__packed__ )); - -struct btrfs_extent_inline_ref { -u8 type; -__le64 offset; -} __attribute__ ((__packed__ )); - -struct btrfs_extent_ref_v0 { -__le64 root; -__le64 generation; -__le64 objectid; -__le32 count; -} __attribute__ ((__packed__ )); - -/* dev extents record free space on individual devices. The owner -* field points back to the chunk allocation mapping tree that allocated -* the extent. The chunk tree uuid field is a way to double check the owner -*/ -struct btrfs_dev_extent { -__le64 chunk_tree; -__le64 chunk_objectid; -__le64 chunk_offset; -__le64 length; -u8 chunk_tree_uuid[BTRFS_UUID_SIZE ]; -} __attribute__ ((__packed__ )); - -struct btrfs_inode_ref { -__le64 index; -__le16 name_len; -/* name goes here */ -} __attribute__ ((__packed__ )); - -struct btrfs_inode_extref { -__le64 parent_objectid; -__le64 index; -__le16 name_len; -__u8 name[0 ];/* name goes here */ -} __attribute__ ((__packed__ )); - -struct btrfs_timespec { -__le64 sec; -__le32 nsec; -} __attribute__ ((__packed__ )); - -/* we don't understand any encryption methods right now */ -typedef enum { -BTRFS_ENCRYPTION_NONE =0 , -BTRFS_ENCRYPTION_LAST =1 , -}btrfs_encryption_type ; -enum btrfs_tree_block_status {BTRFS_TREE_BLOCK_CLEAN ,BTRFS_TREE_BLOCK_INVALID_NRITEMS ,
@@ -734,269 +162,6 @@ enum btrfs_tree_block_status { BTRFS_TREE_BLOCK_INVALID_BLOCKPTR, }; -struct btrfs_inode_item { -/* nfs style generation number */ -__le64 generation; -/* transid that last touched this inode */ -__le64 transid; -__le64 size; -__le64 nbytes; -__le64 block_group; -__le32 nlink; -__le32 uid; -__le32 gid; -__le32 mode; -__le64 rdev; -__le64 flags; - -/* modification sequence number for NFS */ -__le64 sequence; - -/* -* a little future expansion, for more than this we can -* just grow the inode item and version it -*/ -__le64 reserved[4 ]; -struct btrfs_timespec atime; -struct btrfs_timespec ctime; -struct btrfs_timespec mtime; -struct btrfs_timespec otime; -} __attribute__ ((__packed__ )); - -struct btrfs_dir_log_item { -__le64 end; -} __attribute__ ((__packed__ )); - -struct btrfs_dir_item { -struct btrfs_disk_key location; -__le64 transid; -__le16 data_len; -__le16 name_len; -u8 type; -} __attribute__ ((__packed__ )); - -struct btrfs_root_item_v0 { -struct btrfs_inode_item inode; -__le64 generation; -__le64 root_dirid; -__le64 bytenr; -__le64 byte_limit; -__le64 bytes_used; -__le64 last_snapshot; -__le64 flags; -__le32 refs; -struct btrfs_disk_key drop_progress; -u8 drop_level; -u8 level; -} __attribute__ ((__packed__ )); - -struct btrfs_root_item { -struct btrfs_inode_item inode; -__le64 generation; -__le64 root_dirid; -__le64 bytenr; -__le64 byte_limit; -__le64 bytes_used; -__le64 last_snapshot; -__le64 flags; -__le32 refs; -struct btrfs_disk_key drop_progress; -u8 drop_level; -u8 level; - -/* -* The following fields appear after subvol_uuids+subvol_times -* were introduced. -*/ - -/* -* This generation number is used to test if the new fields are valid -* and up to date while reading the root item. Every time the root item -* is written out, the "generation" field is copied into this field. If -* anyone ever mounted the fs with an older kernel, we will have -* mismatching generation values here and thus must invalidate the -* new fields. See btrfs_update_root and btrfs_find_last_root for -* details. -* the offset of generation_v2 is also used as the start for the memset -* when invalidating the fields. -*/ -__le64 generation_v2; -u8 uuid[BTRFS_UUID_SIZE ]; -u8 parent_uuid[BTRFS_UUID_SIZE ]; -u8 received_uuid[BTRFS_UUID_SIZE ]; -__le64 ctransid;/* updated when an inode changes */ -__le64 otransid;/* trans when created */ -__le64 stransid;/* trans when sent. non-zero for received subvol */ -__le64 rtransid;/* trans when received. non-zero for received subvol */ -struct btrfs_timespec ctime; -struct btrfs_timespec otime; -struct btrfs_timespec stime; -struct btrfs_timespec rtime; - -/* -* If we want to use a specific set of fst/checksum/extent roots for -* this root. -*/ -__le64 global_tree_id; -__le64 reserved[7 ];/* for future */ -} __attribute__ ((__packed__ )); - -/* -* this is used for both forward and backward root refs -*/ -struct btrfs_root_ref { -__le64 dirid; -__le64 sequence; -__le16 name_len; -} __attribute__ ((__packed__ )); - -struct btrfs_disk_balance_args { -/* -* profiles to operate on, single is denoted by -* BTRFS_AVAIL_ALLOC_BIT_SINGLE -*/ -__le64 profiles; - -/* -* usage filter -* BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N' -* BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max -*/ -union { -__le64 usage; -struct { -__le32 usage_min; -__le32 usage_max; - }; - }; - -/* devid filter */ -__le64 devid; - -/* devid subset filter [pstart..pend) */ -__le64 pstart; -__le64 pend; - -/* btrfs virtual address space subset filter [vstart..vend) */ -__le64 vstart; -__le64 vend; - -/* -* profile to convert to, single is denoted by -* BTRFS_AVAIL_ALLOC_BIT_SINGLE -*/ -__le64 target; - -/* BTRFS_BALANCE_ARGS_* */ -__le64 flags; - -/* -* BTRFS_BALANCE_ARGS_LIMIT with value 'limit' -* BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum -* and maximum -*/ -union { -__le64 limit; -struct { -__le32 limit_min; -__le32 limit_max; - }; - }; - -/* -* Process chunks that cross stripes_min..stripes_max devices, -* BTRFS_BALANCE_ARGS_STRIPES_RANGE -*/ -__le32 stripes_min; -__le32 stripes_max; - -__le64 unused[6 ]; -} __attribute__ ((__packed__ )); - -/* -* store balance parameters to disk so that balance can be properly -* resumed after crash or unmount -*/ -struct btrfs_balance_item { -/* BTRFS_BALANCE_* */ -__le64 flags; - -struct btrfs_disk_balance_args data; -struct btrfs_disk_balance_args meta; -struct btrfs_disk_balance_args sys; - -__le64 unused[4 ]; -} __attribute__ ((__packed__ )); - -#define BTRFS_FILE_EXTENT_INLINE 0 -#define BTRFS_FILE_EXTENT_REG 1 -#define BTRFS_FILE_EXTENT_PREALLOC 2 - -struct btrfs_file_extent_item { -/* -* transaction id that created this extent -*/ -__le64 generation; -/* -* max number of bytes to hold this extent in ram -* when we split a compressed extent we can't know how big -* each of the resulting pieces will be. So, this is -* an upper limit on the size of the extent in ram instead of -* an exact limit. -*/ -__le64 ram_bytes; - -/* -* 32 bits for the various ways we might encode the data, -* including compression and encryption. If any of these -* are set to something a given disk format doesn't understand -* it is treated like an incompat flag for reading and writing, -* but not for stat. -*/ -u8 compression; -u8 encryption; -__le16 other_encoding;/* spare for later use */ - -/* are we inline data or a real extent? */ -u8 type; - -/* -* Disk space consumed by the data extent -* Data checksum is stored in csum tree, thus no bytenr/length takes -* csum into consideration. -* -* The inline extent data starts at this offset in the structure. -*/ -__le64 disk_bytenr; -__le64 disk_num_bytes; -/* -* The logical offset in file blocks. -* this extent record is for. This allows a file extent to point -* into the middle of an existing extent on disk, sharing it -* between two snapshots (useful if some bytes in the middle of the -* extent have changed -*/ -__le64 offset; -/* -* The logical number of file blocks. This always reflects the size -* uncompressed and without encoding. -*/ -__le64 num_bytes; - -} __attribute__ ((__packed__ )); - -struct btrfs_dev_stats_item { -/* -* grow this item struct at the end for future enhancements and keep -* the existing values unchanged -*/ -__le64 values[BTRFS_DEV_STAT_VALUES_MAX ]; -} __attribute__ ((__packed__ )); - -struct btrfs_csum_item { -u8 csum; -} __attribute__ ((__packed__ )); -/* * We don't want to overwrite 1M at the beginning of device, even though * there is our 1st superblock at 64k. Some possible reasons:
@@ -1005,20 +170,6 @@ struct btrfs_csum_item {*/ #define BTRFS_BLOCK_RESERVED_1M_FOR_SUPER ((u64)1 * 1024 * 1024) -#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0) -#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1) -#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2) -#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3) -#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4) -#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5) -#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6) -#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7) -#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8) -#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9) -#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10) -#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \ - BTRFS_SPACE_INFO_GLOBAL_RSV) -enum btrfs_raid_types {BTRFS_RAID_RAID10 ,BTRFS_RAID_RAID1 ,
@@ -1032,32 +183,6 @@ enum btrfs_raid_types { BTRFS_NR_RAID_TYPES }; -#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \ - BTRFS_BLOCK_GROUP_SYSTEM | \ - BTRFS_BLOCK_GROUP_METADATA) - -#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ - BTRFS_BLOCK_GROUP_RAID1 | \ - BTRFS_BLOCK_GROUP_RAID5 | \ - BTRFS_BLOCK_GROUP_RAID6 | \ - BTRFS_BLOCK_GROUP_RAID1C3 | \ - BTRFS_BLOCK_GROUP_RAID1C4 | \ - BTRFS_BLOCK_GROUP_DUP | \ - BTRFS_BLOCK_GROUP_RAID10) - -#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \ - BTRFS_BLOCK_GROUP_RAID6) - -#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \ - BTRFS_BLOCK_GROUP_RAID1C3 | \ - BTRFS_BLOCK_GROUP_RAID1C4) - -/* used in struct btrfs_balance_args fields */ -#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48) - -#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \ - BTRFS_AVAIL_ALLOC_BIT_SINGLE) -/* * GLOBAL_RSV does not exist as a on-disk block group type and is used * internally for exporting info about global block reserve from space infos
@@ -1066,65 +191,11 @@ enum btrfs_raid_types {#define BTRFS_QGROUP_LEVEL_SHIFT 48 -static inline __u16 btrfs_qgroup_level (u64 qgroupid) -{ -return qgroupid >>BTRFS_QGROUP_LEVEL_SHIFT ; -} -static inline u64 btrfs_qgroup_subvolid (u64 qgroupid) {return qgroupid & ((1ULL <<BTRFS_QGROUP_LEVEL_SHIFT ) -1 ); } -#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0) -#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1) -#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2) - -struct btrfs_qgroup_status_item { -__le64 version; -__le64 generation; -__le64 flags; -__le64 rescan;/* progress during scanning */ -} __attribute__ ((__packed__ )); - -#define BTRFS_QGROUP_STATUS_VERSION 1 -struct btrfs_block_group_item { -__le64 used; -__le64 chunk_objectid; -__le64 flags; -} __attribute__ ((__packed__ )); - -struct btrfs_free_space_info { -__le32 extent_count; -__le32 flags; -} __attribute__ ((__packed__ )); - -#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0) - -struct btrfs_qgroup_info_item { -__le64 generation; -__le64 rfer; -__le64 rfer_cmpr; -__le64 excl; -__le64 excl_cmpr; -} __attribute__ ((__packed__ )); - -/* flags definition for qgroup limits */ -#define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0) -#define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1) -#define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2) -#define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3) -#define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4) -#define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5) - -struct btrfs_qgroup_limit_item { -__le64 flags; -__le64 max_rfer; -__le64 max_excl; -__le64 rsv_rfer; -__le64 rsv_excl; -} __attribute__ ((__packed__ )); -struct btrfs_space_info {u64 flags;u64 total_bytes;
@@ -1564,21 +635,6 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)* data in the FS */ #define BTRFS_STRING_ITEM_KEY 253 -/* -* Inode flags -*/ -#define BTRFS_INODE_NODATASUM (1 << 0) -#define BTRFS_INODE_NODATACOW (1 << 1) -#define BTRFS_INODE_READONLY (1 << 2) -#define BTRFS_INODE_NOCOMPRESS (1 << 3) -#define BTRFS_INODE_PREALLOC (1 << 4) -#define BTRFS_INODE_SYNC (1 << 5) -#define BTRFS_INODE_IMMUTABLE (1 << 6) -#define BTRFS_INODE_APPEND (1 << 7) -#define BTRFS_INODE_NODUMP (1 << 8) -#define BTRFS_INODE_NOATIME (1 << 9) -#define BTRFS_INODE_DIRSYNC (1 << 10) -#define BTRFS_INODE_COMPRESS (1 << 11)#define read_eb_member (eb, ptr, type, member, result) ( \ read_extent_buffer(eb, (char *)(result), \
@@ -1948,12 +1004,6 @@ static inline u32 btrfs_extent_inline_ref_size(int type)return 0 ; } -BTRFS_SETGET_FUNCS(ref_root_v0, struct btrfs_extent_ref_v0, root, 64); -BTRFS_SETGET_FUNCS(ref_generation_v0, struct btrfs_extent_ref_v0, - generation,64 ); -BTRFS_SETGET_FUNCS(ref_objectid_v0, struct btrfs_extent_ref_v0, objectid, 64); -BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32); -/* struct btrfs_node */ BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
kernel-shared/uapi/btrfs_tree.h new file +1259 -0
1,259 lines not on this page · raw message
Signature · 1 line
2.40.0
PATCH 6/8 btrfs-progs: sync file-item.h into progs
In reply to Josef BacikThis patch syncs file-item.h into btrfs-progs. This carries with it an API change for btrfs_del_csums, which takes a root argument in the kernel, so all callsites have been updated accordingly.
I didn't sync file-item.c because it carries with it a bunch of bio related helpers which are difficult to adapt to the kernel. Additionally there's a few helpers in the local copy of file-item.c that aren't in the kernel that are required for different tools.
This requires more cleanups in both the kernel and progs in order to sync file-item.c, so for now just do file-item.h in order to pull things out of ctree.h.
--- btrfs-corrupt-block.c | 3 +- check/clear-cache.c | 7 ++- check/main.c | 1 + check/mode-common.c | 6 ++- check/mode-lowmem.c | 1 + cmds/inspect-tree-stats.c | 1 + cmds/restore.c | 1 + convert/main.c | 1 + convert/source-ext2.c | 1 + image/main.c | 1 + kernel-shared/ctree.h | 45 ------------------- kernel-shared/extent-tree.c | 7 ++- kernel-shared/file-item.c | 13 +++--- kernel-shared/file-item.h | 89 +++++++++++++++++++++++++++++++++++++ kernel-shared/file.c | 1 + kernel-shared/print-tree.c | 1 + mkfs/rootdir.c | 1 + 17 files changed, 124 insertions(+), 56 deletions(-) create mode 100644 kernel-shared/file-item.h
btrfs-corrupt-block.c +2 -1
@@ -28,6 +28,7 @@#include "kernel-shared/disk-io.h" #include "kernel-shared/transaction.h" #include "kernel-shared/extent_io.h" +#include "kernel-shared/file-item.h" #include "common/utils.h" #include "common/help.h" #include "common/extent-cache.h"
@@ -1098,7 +1099,7 @@ static int delete_csum(struct btrfs_root *root, u64 bytenr, u64 bytes)return ret; } - ret =btrfs_del_csums (trans, bytenr, bytes); + ret =btrfs_del_csums (trans, root, bytenr, bytes);if (ret)error ("error deleting csums %d" , ret);btrfs_commit_transaction (trans, root);
check/clear-cache.c +6 -1
@@ -21,6 +21,7 @@#include "kernel-shared/free-space-tree.h" #include "kernel-shared/volumes.h" #include "kernel-shared/transaction.h" +#include "kernel-shared/file-item.h" #include "common/internal.h" #include "common/messages.h" #include "check/common.h"
@@ -462,6 +463,7 @@ int truncate_free_ino_items(struct btrfs_root *root)while (1 ) {struct extent_buffer *leaf;struct btrfs_file_extent_item *fi; +struct btrfs_root *csum_root;struct btrfs_key found_key;u8 found_type;
@@ -520,7 +522,10 @@ int truncate_free_ino_items(struct btrfs_root *root) goto out; } - ret =btrfs_del_csums (trans, extent_disk_bytenr, + csum_root =btrfs_csum_root (trans->fs_info, + extent_disk_bytenr); + ret =btrfs_del_csums (trans, csum_root, + extent_disk_bytenr, extent_num_bytes);if (ret <0 ) {btrfs_abort_transaction (trans, ret);
check/main.c +1 -0
@@ -41,6 +41,7 @@#include "kernel-shared/free-space-tree.h" #include "kernel-shared/backref.h" #include "kernel-shared/ulist.h" +#include "kernel-shared/file-item.h" #include "common/defs.h" #include "common/extent-cache.h" #include "common/internal.h"
check/mode-common.c +4 -2
@@ -28,6 +28,7 @@#include "kernel-shared/volumes.h" #include "kernel-shared/backref.h" #include "kernel-shared/compression.h" +#include "kernel-shared/file-item.h" #include "common/internal.h" #include "common/messages.h" #include "common/utils.h"
@@ -1311,7 +1312,7 @@ static int fill_csum_tree_from_one_fs_root(struct btrfs_trans_handle *trans,if (type ==BTRFS_FILE_EXTENT_PREALLOC ) { start +=btrfs_file_extent_offset (node, fi); len =btrfs_file_extent_num_bytes (node, fi); - ret =btrfs_del_csums (trans, start, len); + ret =btrfs_del_csums (trans, csum_root, start, len);if (ret <0 ) goto out; }
@@ -1473,7 +1474,8 @@ static int remove_csum_for_file_extent(u64 ino, u64 offset, u64 rootid, void *ctbtrfs_release_path (&path);/* Now delete the csum for the preallocated or nodatasum range */ - ret =btrfs_del_csums (trans, disk_bytenr, disk_len); + root =btrfs_csum_root (fs_info, disk_bytenr); + ret =btrfs_del_csums (trans, root, disk_bytenr, disk_len); out:btrfs_release_path (&path);return ret;
check/mode-lowmem.c +1 -0
@@ -30,6 +30,7 @@#include "kernel-shared/backref.h" #include "kernel-shared/compression.h" #include "kernel-shared/volumes.h" +#include "kernel-shared/file-item.h" #include "common/messages.h" #include "common/internal.h" #include "common/utils.h"
cmds/inspect-tree-stats.c +1 -0
@@ -28,6 +28,7 @@#include "kernel-shared/ctree.h" #include "kernel-shared/disk-io.h" #include "kernel-shared/extent_io.h" +#include "kernel-shared/file-item.h" #include "common/utils.h" #include "common/help.h" #include "common/messages.h"
cmds/restore.c +1 -0
@@ -44,6 +44,7 @@#include "kernel-shared/volumes.h" #include "kernel-shared/extent_io.h" #include "kernel-shared/compression.h" +#include "kernel-shared/file-item.h" #include "common/utils.h" #include "common/help.h" #include "common/open-utils.h"
convert/main.c +1 -0
@@ -99,6 +99,7 @@#include "kernel-shared/disk-io.h" #include "kernel-shared/volumes.h" #include "kernel-shared/transaction.h" +#include "kernel-shared/file-item.h" #include "crypto/hash.h" #include "common/defs.h" #include "common/extent-cache.h"
convert/source-ext2.c +1 -0
@@ -27,6 +27,7 @@#include <string.h> #include "kernel-lib/sizes.h" #include "kernel-shared/transaction.h" +#include "kernel-shared/file-item.h" #include "common/extent-cache.h" #include "common/messages.h" #include "convert/common.h"
image/main.c +1 -0
@@ -39,6 +39,7 @@#include "kernel-shared/transaction.h" #include "kernel-shared/volumes.h" #include "kernel-shared/extent_io.h" +#include "kernel-shared/file-item.h" #include "crypto/crc32c.h" #include "crypto/hash.h" #include "common/internal.h"
kernel-shared/ctree.h +0 -45
69 lines not on this page · raw message
kernel-shared/extent-tree.c +6 -1
@@ -33,6 +33,7 @@#include "kernel-shared/free-space-tree.h" #include "kernel-shared/zoned.h" #include "common/utils.h" +#include "file-item.h" #define PENDING_EXTENT_INSERT 0#define PENDING_EXTENT_DELETE 1
@@ -2115,7 +2116,11 @@ static int __free_extent(struct btrfs_trans_handle *trans,btrfs_release_path (path);if (is_data) { - ret =btrfs_del_csums (trans, bytenr, num_bytes); +struct btrfs_root *csum_root; + + csum_root =btrfs_csum_root (trans->fs_info, bytenr); + ret =btrfs_del_csums (trans, csum_root, bytenr, + num_bytes);BUG_ON (ret); }
kernel-shared/file-item.c +7 -6
@@ -25,6 +25,7 @@#include "kernel-shared/print-tree.h" #include "crypto/crc32c.h" #include "common/internal.h" +#include "file-item.h" #define MAX_CSUM_ITEMS (r, size) ((((BTRFS_LEAF_DATA_SIZE(r->fs_info) - \ sizeof(struct btrfs_item) * 2) / \
@@ -400,7 +401,8 @@ static noinline int truncate_one_csum(struct btrfs_root *root,* deletes the csum items from the csum tree for a given * range of bytes. */ -int btrfs_del_csums (struct btrfs_trans_handle *trans,u64 bytenr,u64 len) +int btrfs_del_csums (struct btrfs_trans_handle *trans,struct btrfs_root *root, +u64 bytenr,u64 len) {struct btrfs_path *path;struct btrfs_key key;
@@ -410,7 +412,6 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)int ret;u16 csum_size = trans->fs_info->csum_size;int blocksize = trans->fs_info->sectorsize; -struct btrfs_root *csum_root =btrfs_csum_root (trans->fs_info, bytenr); path =btrfs_alloc_path ();if (!path)
@@ -421,7 +422,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len) key.offset = end_byte -1 ; key.type =BTRFS_EXTENT_CSUM_KEY ; - ret =btrfs_search_slot (trans, csum_root, &key, path,-1 ,1 ); + ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 );if (ret >0 ) {if (path->slots[0 ] ==0 ) goto out;
@@ -448,7 +449,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)/* delete the entire item, it is inside our range */ if (key.offset >= bytenr && csum_end <= end_byte) { - ret =btrfs_del_item (trans, csum_root, path); + ret =btrfs_del_item (trans, root, path);BUG_ON (ret); }else if (key.offset < bytenr && csum_end > end_byte) {unsigned long offset;
@@ -488,13 +489,13 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)* btrfs_split_item returns -EAGAIN when the * item changed size or key */ - ret =btrfs_split_item (trans, csum_root, path, &key, + ret =btrfs_split_item (trans, root, path, &key, offset);BUG_ON (ret && ret != -EAGAIN ); key.offset = end_byte -1 ; }else { - ret =truncate_one_csum (csum_root, path, &key, bytenr, + ret =truncate_one_csum (root, path, &key, bytenr, len);BUG_ON (ret); }
kernel-shared/file-item.h new file +89 -0
89 lines not on this page · raw message
kernel-shared/file.c +1 -0
@@ -22,6 +22,7 @@#include "kernel-shared/disk-io.h" #include "kernel-shared/transaction.h" #include "kernel-shared/compression.h" +#include "kernel-shared/file-item.h" #include "common/utils.h" /*
kernel-shared/print-tree.c +1 -0
@@ -28,6 +28,7 @@#include "kernel-shared/compression.h" #include "common/utils.h" #include "accessors.h" +#include "file-item.h" static void print_dir_item_type (struct extent_buffer *eb,struct btrfs_dir_item *di)
mkfs/rootdir.c +1 -0
@@ -35,6 +35,7 @@#include "kernel-shared/volumes.h" #include "kernel-shared/disk-io.h" #include "kernel-shared/transaction.h" +#include "kernel-shared/file-item.h" #include "common/internal.h" #include "common/messages.h" #include "common/path-utils.h"
Signature · 1 line
2.40.0
PATCH 5/8 btrfs-progs: sync accessors.[ch] from the kernel
In reply to Josef BacikThis syncs accessors.[ch] from the kernel. For the most part accessors.h will remain the same, there's just some helpers that need to be adjusted for eb->data instead of eb->pages. Additionally accessors.c needed to be completely updated to deal with this as well.
This is a set of files where we will likely only sync the header going forward, and leave the c file in place as it needs to be specific to btrfs-progs.
This forced a few "unrelated" changes
- Using btrfs_dir_item_ftype() instead of btrfs_dir_item_type(). This is due to the encryption changes, and was simpler to just do in this patch.
- Adjusting some of the print tree code to use the actual helpers and not the btrfs-progs ones.
--- Makefile | 1 + check/main.c | 4 +- check/mode-common.c | 4 +- check/mode-lowmem.c | 6 +- cmds/restore.c | 2 +- include/kerncompat.h | 6 +- kernel-shared/accessors.c | 117 ++++ kernel-shared/accessors.h | 1087 ++++++++++++++++++++++++++++++++++++ kernel-shared/ctree.h | 886 +---------------------------- kernel-shared/dir-item.c | 8 +- kernel-shared/inode.c | 2 +- kernel-shared/print-tree.c | 16 +- mkfs/common.c | 1 + 13 files changed, 1241 insertions(+), 899 deletions(-) create mode 100644 kernel-shared/accessors.c create mode 100644 kernel-shared/accessors.h
Makefile +1 -0
@@ -166,6 +166,7 @@ objects = \ kernel-lib/raid56.o \ kernel-lib/rbtree.o \ kernel-lib/tables.o \ + kernel-shared/accessors.o \ kernel-shared/backref.o \ kernel-shared/ctree.o \ kernel-shared/delayed-ref.o \
check/main.c +2 -2
@@ -1434,7 +1434,7 @@ static int process_dir_item(struct extent_buffer *eb,btrfs_dir_item_key_to_cpu (eb, di, &location); name_len =btrfs_dir_name_len (eb, di); data_len =btrfs_dir_data_len (eb, di); - filetype =btrfs_dir_type (eb, di); + filetype =btrfs_dir_ftype (eb, di); rec->found_size += name_len; if (cur + sizeof(*di) + name_len > total ||
@@ -2135,7 +2135,7 @@ static int add_missing_dir_index(struct btrfs_root *root, disk_key.offset =0 ;btrfs_set_dir_item_key (leaf, dir_item, &disk_key); -btrfs_set_dir_type (leaf, dir_item,imode_to_type (rec->imode)); +btrfs_set_dir_flags (leaf, dir_item,imode_to_type (rec->imode));btrfs_set_dir_data_len (leaf, dir_item,0 );btrfs_set_dir_name_len (leaf, dir_item, backref->namelen); name_ptr = (unsigned long )(dir_item +1 );
check/mode-common.c +2 -2
@@ -764,7 +764,7 @@ static int find_file_type_dir_index(struct btrfs_root *root, u64 ino, u64 dirid,if (location.objectid != ino || location.type !=BTRFS_INODE_ITEM_KEY || location.offset !=0 ) goto out; - filetype =btrfs_dir_type (path.nodes[0 ], di); + filetype =btrfs_dir_ftype (path.nodes[0 ], di);if (filetype >=BTRFS_FT_MAX || filetype ==BTRFS_FT_UNKNOWN ) goto out; len = min_t(u32, BTRFS_NAME_LEN,
@@ -823,7 +823,7 @@ static int find_file_type_dir_item(struct btrfs_root *root, u64 ino, u64 dirid, location.type !=BTRFS_INODE_ITEM_KEY || location.offset != 0) continue; - filetype =btrfs_dir_type (path.nodes[0 ], di); + filetype =btrfs_dir_ftype (path.nodes[0 ], di);if (filetype >=BTRFS_FT_MAX || filetype ==BTRFS_FT_UNKNOWN )continue ; len = min_t(u32, BTRFS_NAME_LEN,
check/mode-lowmem.c +3 -3
@@ -868,7 +868,7 @@ loop: location.offset != 0) goto next; - filetype =btrfs_dir_type (node, di); + filetype =btrfs_dir_ftype (node, di);if (file_type != filetype) goto next;
@@ -966,7 +966,7 @@ static int find_dir_item(struct btrfs_root *root, struct btrfs_key *key, location.offset != location_key->offset) goto next; - filetype =btrfs_dir_type (node, di); + filetype =btrfs_dir_ftype (node, di);if (file_type != filetype) goto next;
@@ -1759,7 +1759,7 @@ begin: (*size) += name_len;read_extent_buffer (node, namebuf, (unsigned long )(di +1 ), len); - filetype =btrfs_dir_type (node, di); + filetype =btrfs_dir_ftype (node, di);if (di_key->type ==BTRFS_DIR_ITEM_KEY && di_key->offset !=btrfs_name_hash (namebuf, len)) {
cmds/restore.c +1 -1
@@ -993,7 +993,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, name_len =btrfs_dir_name_len (leaf, dir_item);read_extent_buffer (leaf, filename, name_ptr, name_len); filename[name_len] ='\0' ; - type =btrfs_dir_type (leaf, dir_item); + type =btrfs_dir_ftype (leaf, dir_item);btrfs_dir_item_key_to_cpu (leaf, dir_item, &location);/* full path from root of btrfs being restored */
include/kerncompat.h +2 -4
@@ -505,10 +505,6 @@ struct __una_u16 { __le16 x; } __attribute__((__packed__));struct __una_u32 {__le32 x; } __attribute__((__packed__ ));struct __una_u64 {__le64 x; } __attribute__((__packed__ )); -#define get_unaligned_le8 (p) (*((u8 *)(p))) -#define get_unaligned_8 (p) (*((u8 *)(p))) -#define put_unaligned_le8 (val,p) ((*((u8 *)(p))) = (val)) -#define put_unaligned_8 (val,p) ((*((u8 *)(p))) = (val))#define get_unaligned_le16 (p) le16_to_cpu(((const struct __una_u16 *)(p))->x)#define get_unaligned_16 (p) (((const struct __una_u16 *)(p))->x)#define put_unaligned_le16 (val,p) (((struct __una_u16 *)(p))->x = cpu_to_le16(val))
@@ -582,4 +578,6 @@ static inline bool sb_rdonly(struct super_block *sb) return false; } +#define unlikely (cond) (cond) +#endif
kernel-shared/accessors.c new file +117 -0
117 lines not on this page · raw message
kernel-shared/accessors.h new file +1087 -0
1,087 lines not on this page · raw message
kernel-shared/ctree.h +9 -877
937 lines not on this page · raw message
kernel-shared/dir-item.c +4 -4
@@ -89,7 +89,7 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, leaf = path->nodes[0 ];btrfs_cpu_key_to_disk (&disk_key, &location);btrfs_set_dir_item_key (leaf, dir_item, &disk_key); -btrfs_set_dir_type (leaf, dir_item,BTRFS_FT_XATTR ); +btrfs_set_dir_flags (leaf, dir_item,BTRFS_FT_XATTR );btrfs_set_dir_name_len (leaf, dir_item, name_len);btrfs_set_dir_data_len (leaf, dir_item, data_len); name_ptr = (unsigned long )(dir_item +1 );
@@ -141,7 +141,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root leaf = path->nodes[0 ];btrfs_cpu_key_to_disk (&disk_key, location);btrfs_set_dir_item_key (leaf, dir_item, &disk_key); -btrfs_set_dir_type (leaf, dir_item, type); +btrfs_set_dir_flags (leaf, dir_item, type);btrfs_set_dir_data_len (leaf, dir_item,0 );btrfs_set_dir_name_len (leaf, dir_item, name_len); name_ptr = (unsigned long )(dir_item +1 );
@@ -170,7 +170,7 @@ insert: leaf = path->nodes[0 ];btrfs_cpu_key_to_disk (&disk_key, location);btrfs_set_dir_item_key (leaf, dir_item, &disk_key); -btrfs_set_dir_type (leaf, dir_item, type); +btrfs_set_dir_flags (leaf, dir_item, type);btrfs_set_dir_data_len (leaf, dir_item,0 );btrfs_set_dir_name_len (leaf, dir_item, name_len); name_ptr = (unsigned long )(dir_item +1 );
@@ -292,7 +292,7 @@ static int verify_dir_item(struct btrfs_root *root, struct btrfs_dir_item *dir_item) {u16 namelen =BTRFS_NAME_LEN ; -u8 type =btrfs_dir_type (leaf, dir_item); +u8 type =btrfs_dir_ftype (leaf, dir_item);if (type ==BTRFS_FT_XATTR ) namelen =XATTR_NAME_MAX ;
kernel-shared/inode.c +1 -1
@@ -548,7 +548,7 @@ int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root,*/ btrfs_dir_item_key_to_cpu (path->nodes[0 ], dir_item, &found_key); ret_ino = found_key.objectid; -if (btrfs_dir_type (path->nodes[0 ], dir_item) !=BTRFS_FT_DIR ) +if (btrfs_dir_ftype (path->nodes[0 ], dir_item) !=BTRFS_FT_DIR ) ret = -EEXIST ; goto out; }
kernel-shared/print-tree.c +11 -5
@@ -27,11 +27,12 @@#include "kernel-shared/volumes.h" #include "kernel-shared/compression.h" #include "common/utils.h" +#include "accessors.h" static void print_dir_item_type (struct extent_buffer *eb,struct btrfs_dir_item *di) { -u8 type =btrfs_dir_type (eb, di); +u8 type =btrfs_dir_ftype (eb, di);static const char * dir_item_str[] = { [BTRFS_FT_REG_FILE ] ="FILE" , [BTRFS_FT_DIR ] ="DIR" ,
@@ -959,15 +960,20 @@ static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)static void print_balance_item (struct extent_buffer *eb,struct btrfs_balance_item *bi) { +struct btrfs_disk_balance_args ba; +printf ("\t\tbalance status flags %llu\n" , -btrfs_balance_item_flags (eb, bi)); +btrfs_balance_flags (eb, bi));printf ("\t\tDATA\n" ); -print_disk_balance_args (btrfs_balance_item_data (eb, bi)); +btrfs_balance_data (eb, bi, &ba); +print_disk_balance_args (&ba);printf ("\t\tMETADATA\n" ); -print_disk_balance_args (btrfs_balance_item_meta (eb, bi)); +btrfs_balance_meta (eb, bi, &ba); +print_disk_balance_args (&ba);printf ("\t\tSYSTEM\n" ); -print_disk_balance_args (btrfs_balance_item_sys (eb, bi)); +btrfs_balance_sys (eb, bi, &ba); +print_disk_balance_args (&ba); } static void print_dev_stats(struct extent_buffer *eb,
mkfs/common.c +1 -0
@@ -39,6 +39,7 @@#include "common/open-utils.h" #include "mkfs/common.h" #include "kernel-shared/uapi/btrfs.h" +#include "kernel-shared/accessors.h" static u64 reference_root_table[] = { [MKFS_ROOT_TREE ] =BTRFS_ROOT_TREE_OBJECTID ,
Signature · 1 line
2.40.0
PATCH 7/8 btrfs-progs: sync async-thread.[ch] from the kernel
In reply to Josef BacikWe won't actually use the async code in progs, however we call the helpers and such all over the normal code, so sync this into btrfs-progs to make syncing other parts of the kernel easier.
--- Makefile | 1 + common/internal.h | 4 + include/kerncompat.h | 79 ++++++++ kernel-lib/bitops.h | 12 ++ kernel-lib/trace.h | 29 +++ kernel-shared/async-thread.c | 339 +++++++++++++++++++++++++++++++++++ kernel-shared/async-thread.h | 46 +++++ 7 files changed, 510 insertions(+) create mode 100644 kernel-lib/trace.h create mode 100644 kernel-shared/async-thread.c create mode 100644 kernel-shared/async-thread.h
Makefile +1 -0
@@ -167,6 +167,7 @@ objects = \ kernel-lib/rbtree.o \ kernel-lib/tables.o \ kernel-shared/accessors.o \ + kernel-shared/async-thread.o \ kernel-shared/backref.o \ kernel-shared/ctree.o \ kernel-shared/delayed-ref.o \
common/internal.h +4 -0
@@ -39,4 +39,8 @@#define max_t (type,x,y) \ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) +#define clamp_t (type, val, lo, hi) min_t(type, max_t(type, val, lo), hi) + +#define clamp_val (val, lo, hi) clamp_t(typeof(val), val, lo, hi) +#endif
include/kerncompat.h +79 -0
110 lines not on this page · raw message
kernel-lib/bitops.h +12 -0
@@ -12,6 +12,8 @@#define BITS_TO_LONGS (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))#define BITS_TO_U64 (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))#define BITS_TO_U32 (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG)#define for_each_set_bit (bit, addr, size) \ for ((bit) = find_first_bit((addr), (size)); \
@@ -34,6 +36,16 @@ static inline void clear_bit(int nr, unsigned long *addr) addr[nr /BITS_PER_LONG ] &= ~(1UL << (nr %BITS_PER_LONG )); } +static inline bool test_and_set_bit (unsigned long nr,unsigned long *addr) +{ +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); +unsigned long old = *p; + + *p = old | mask; +return (old & mask) !=0 ; +} +/** * hweightN - returns the hamming weight of a N-bit word * @x: the word to weigh
kernel-lib/trace.h new file +29 -0
@@ -0,0 +1,29 @@ +#ifndef __PROGS_TRACE_H__ +#define __PROGS_TRACE_H__ + +static inline void trace_btrfs_workqueue_alloc (void *ret,const char *name) +{ +} + +static inline void trace_btrfs_ordered_sched (struct btrfs_work *work) +{ +} + +static inline void trace_btrfs_all_work_done (struct btrfs_fs_info *fs_info, +struct btrfs_work *work) +{ +} + +static inline void trace_btrfs_work_sched (struct btrfs_work *work) +{ +} + +static inline void trace_btrfs_work_queued (struct btrfs_work *work) +{ +} + +static inline void trace_btrfs_workqueue_destroy (void *wq) +{ +} + +#endif /* __PROGS_TRACE_H__ */
kernel-shared/async-thread.c new file +339 -0
339 lines not on this page · raw message
kernel-shared/async-thread.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.40.0
PATCH 8/8 btrfs-progs: sync extent-io-tree.[ch] and misc.h from the kernel
In reply to Josef BacikThis is a bit larger than the previous syncs, because we use extent_io_tree's everywhere. There's a lot of stuff added to kerncompat.h, and then I went through and cleaned up all the API changes, which were
- extent_io_tree_init takes an fs_info and an owner now.
- extent_io_tree_cleanup is now extent_io_tree_release.
- set_extent_dirty takes a gfpmask.
- clear_extent_dirty takes a cached_state.
- find_first_extent_bit takes a cached_state.
The diffstat looks insane for this, but keep in mind extent-io-tree.c and extent-io-tree.h are ~2000 loc just by themselves.
--- Makefile | 1 + check/clear-cache.c | 8 +- check/common.h | 2 +- check/main.c | 27 +- check/mode-common.c | 9 +- check/mode-lowmem.c | 4 +- check/repair.c | 16 +- cmds/rescue-chunk-recover.c | 2 +- image/main.c | 9 +- include/kerncompat.h | 161 ++- kernel-lib/trace.h | 26 + kernel-shared/ctree.h | 1 + kernel-shared/disk-io.c | 16 +- kernel-shared/extent-io-tree.c | 1733 ++++++++++++++++++++++++++++++++ kernel-shared/extent-io-tree.h | 239 +++++ kernel-shared/extent-tree.c | 45 +- kernel-shared/extent_io.c | 473 +-------- kernel-shared/extent_io.h | 39 +- kernel-shared/misc.h | 143 +++ kernel-shared/transaction.c | 5 +- 20 files changed, 2387 insertions(+), 572 deletions(-) create mode 100644 kernel-shared/extent-io-tree.c create mode 100644 kernel-shared/extent-io-tree.h create mode 100644 kernel-shared/misc.h
Makefile +1 -0
@@ -173,6 +173,7 @@ objects = \ kernel-shared/delayed-ref.o \ kernel-shared/dir-item.o \ kernel-shared/disk-io.o \ + kernel-shared/extent-io-tree.o \ kernel-shared/extent-tree.o \ kernel-shared/extent_io.o \ kernel-shared/file-item.o \
check/clear-cache.c +4 -4
@@ -310,7 +310,7 @@ static int verify_space_cache(struct btrfs_root *root,while (start < bg_end) { ret =find_first_extent_bit (used, cache->start, &start, &end, -EXTENT_DIRTY ); +EXTENT_DIRTY ,NULL );if (ret || start >= bg_end) { ret =0 ;break ;
@@ -322,7 +322,7 @@ static int verify_space_cache(struct btrfs_root *root,return ret; } end =min (end, bg_end -1 ); -clear_extent_dirty (used, start, end); +clear_extent_dirty (used, start, end,NULL ); start = end +1 ; last_end = start; }
@@ -349,7 +349,7 @@ static int check_space_cache(struct btrfs_root *root)int ret;int error =0 ; -extent_io_tree_init (&used); +extent_io_tree_init (root->fs_info, &used,0 ); ret =btrfs_mark_used_blocks (gfs_info, &used);if (ret)return ret;
@@ -405,7 +405,7 @@ static int check_space_cache(struct btrfs_root *root) error++; } } -extent_io_tree_cleanup (&used); +extent_io_tree_release (&used);return error ? -EINVAL :0 ; }
check/common.h +1 -1
@@ -147,7 +147,7 @@ u64 calc_stripe_length(u64 type, u64 length, int num_stripes);static inline void block_group_tree_init (struct block_group_tree *tree) {cache_tree_init (&tree->tree); -extent_io_tree_init (&tree->pending_extents); +extent_io_tree_init (NULL , &tree->pending_extents,0 );INIT_LIST_HEAD (&tree->block_groups); }
check/main.c +16 -11
@@ -5200,7 +5200,7 @@ static void free_block_group_record(struct cache_extent *cache)void free_block_group_tree (struct block_group_tree *tree) { -extent_io_tree_cleanup (&tree->pending_extents); +extent_io_tree_release (&tree->pending_extents);cache_tree_free_extents (&tree->tree, free_block_group_record); }
@@ -5213,7 +5213,7 @@ static void update_block_group_used(struct block_group_tree *tree, bg_item =lookup_cache_extent (&tree->tree, bytenr, num_bytes);if (!bg_item) {set_extent_dirty (&tree->pending_extents, bytenr, - bytenr + num_bytes -1 ); + bytenr + num_bytes -1 ,GFP_NOFS );return ; } bg_rec = container_of(bg_item, struct block_group_record, cache);
@@ -5452,7 +5452,8 @@ static int process_block_group_item(struct block_group_tree *block_group_cache, }while (!find_first_extent_bit (&block_group_cache->pending_extents, - rec->objectid, &start, &end,EXTENT_DIRTY )) { + rec->objectid, &start, &end,EXTENT_DIRTY , +NULL )) {u64 len;if (start >= rec->objectid + rec->offset)
@@ -5461,7 +5462,7 @@ static int process_block_group_item(struct block_group_tree *block_group_cache, len =min (end - start +1 , rec->objectid + rec->offset - start); rec->actual_used += len;clear_extent_dirty (&block_group_cache->pending_extents, start, - start + len -1 ); + start + len -1 ,NULL ); }return ret;
@@ -8057,7 +8058,8 @@ static int check_extent_refs(struct btrfs_root *root, rec = container_of(cache, struct extent_record, cache);set_extent_dirty (gfs_info->excluded_extents, rec->start, - rec->start + rec->max_size -1 ); + rec->start + rec->max_size -1 , +GFP_NOFS ); cache =next_cache_extent (cache); }
@@ -8066,7 +8068,8 @@ static int check_extent_refs(struct btrfs_root *root,while (cache) {set_extent_dirty (gfs_info->excluded_extents, cache->start, - cache->start + cache->size -1 ); + cache->start + cache->size -1 , +GFP_NOFS ); cache =next_cache_extent (cache); }prune_corrupt_blocks ();
@@ -8221,7 +8224,8 @@ next:if (!init_extent_tree && opt_check_repair && (!cur_err || fix))clear_extent_dirty (gfs_info->excluded_extents, rec->start, - rec->start + rec->max_size -1 ); + rec->start + rec->max_size -1 , +NULL );free (rec); } repair_abort:
@@ -8927,7 +8931,7 @@ static int check_chunks_and_extents(void)cache_tree_init (&nodes);cache_tree_init (&reada);cache_tree_init (&corrupt_blocks); -extent_io_tree_init (&excluded_extents); +extent_io_tree_init (gfs_info, &excluded_extents,0 );INIT_LIST_HEAD (&dropping_trees);INIT_LIST_HEAD (&normal_trees);
@@ -9015,7 +9019,7 @@ again: out:if (opt_check_repair) {free_corrupt_blocks_tree (gfs_info->corrupt_blocks); -extent_io_tree_cleanup (&excluded_extents); +extent_io_tree_release (&excluded_extents); gfs_info->fsck_extent_cache =NULL ; gfs_info->free_extent_hook =NULL ; gfs_info->corrupt_blocks =NULL ;
@@ -9046,7 +9050,7 @@ loop:free_extent_record_cache (&extent_cache);free_root_item_list (&normal_trees);free_root_item_list (&dropping_trees); -extent_io_tree_cleanup (&excluded_extents); +extent_io_tree_release (&excluded_extents); goto again; }
@@ -9215,7 +9219,8 @@ static int reset_block_groups(void)btrfs_chunk_type (leaf, chunk), key.offset, btrfs_chunk_length(leaf, chunk));set_extent_dirty (&gfs_info->free_space_cache, key.offset, - key.offset +btrfs_chunk_length (leaf, chunk)); + key.offset +btrfs_chunk_length (leaf, chunk), +GFP_NOFS ); path.slots[0 ]++; } start =0 ;
check/mode-common.c +5 -4
@@ -596,10 +596,11 @@ void reset_cached_block_groups()while (1 ) { ret =find_first_extent_bit (&gfs_info->free_space_cache,0 , - &start, &end,EXTENT_DIRTY ); + &start, &end,EXTENT_DIRTY ,NULL );if (ret)break ; -clear_extent_dirty (&gfs_info->free_space_cache, start, end); +clear_extent_dirty (&gfs_info->free_space_cache, start, end, +NULL ); } start =0 ;
@@ -626,7 +627,7 @@ int exclude_metadata_blocks(void) excluded_extents =malloc (sizeof (*excluded_extents));if (!excluded_extents)return -ENOMEM ; -extent_io_tree_init (excluded_extents); +extent_io_tree_init (gfs_info, excluded_extents,0 ); gfs_info->excluded_extents = excluded_extents;return btrfs_mark_used_tree_blocks (gfs_info, excluded_extents);
@@ -635,7 +636,7 @@ int exclude_metadata_blocks(void)void cleanup_excluded_extents (void ) {if (gfs_info->excluded_extents) { -extent_io_tree_cleanup (gfs_info->excluded_extents); +extent_io_tree_release (gfs_info->excluded_extents);free (gfs_info->excluded_extents); } gfs_info->excluded_extents =NULL ;
check/mode-lowmem.c +2 -2
@@ -260,12 +260,12 @@ static int modify_block_group_cache(struct btrfs_block_group *block_group, int cif (cache && !block_group->cached) { block_group->cached =1 ; -clear_extent_dirty (free_space_cache, start, end -1 ); +clear_extent_dirty (free_space_cache, start, end -1 ,NULL ); }if (!cache && block_group->cached) { block_group->cached =0 ; -clear_extent_dirty (free_space_cache, start, end -1 ); +clear_extent_dirty (free_space_cache, start, end -1 ,NULL ); }return 0 ; }
check/repair.c +8 -8
@@ -79,13 +79,13 @@ static int traverse_tree_blocks(struct extent_io_tree *tree,* This can not only avoid forever loop with broken filesystem * but also give us some speedups. */ -if (test_range_bit (tree, eb->start, end -1 ,EXTENT_DIRTY ,0 )) +if (test_range_bit (tree, eb->start, end -1 ,EXTENT_DIRTY ,0 ,NULL ))return 0 ;if (pin)btrfs_pin_extent (fs_info, eb->start, eb->len);else -set_extent_dirty (tree, eb->start, end -1 ); +set_extent_dirty (tree, eb->start, end -1 ,GFP_NOFS ); nritems =btrfs_header_nritems (eb);for (i =0 ; i < nritems; i++) {
@@ -129,7 +129,7 @@ static int traverse_tree_blocks(struct extent_io_tree *tree,btrfs_pin_extent (fs_info, bytenr, fs_info->nodesize); else -set_extent_dirty (tree ,bytenr ,end ); +set_extent_dirty (tree ,bytenr ,end ,GFP_NOFS );continue ; }
@@ -211,7 +211,7 @@ static int populate_used_from_extent_root(struct btrfs_root *root, ret = -EINVAL ;break ; } -set_extent_dirty (io_tree, start, end); +set_extent_dirty (io_tree, start, end,GFP_NOFS ); } path.slots[0 ]++;
@@ -260,7 +260,7 @@ int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans)if (ret)return ret; -extent_io_tree_init (&used); +extent_io_tree_init (fs_info, &used,0 ); ret =btrfs_mark_used_blocks (fs_info, &used);if (ret)
@@ -282,7 +282,7 @@ int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans) start =0 ;while (1 ) { ret =find_first_extent_bit (&used,0 , &start, &end, -EXTENT_DIRTY ); +EXTENT_DIRTY ,NULL );if (ret)break ;
@@ -291,12 +291,12 @@ int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans) 1, 0);if (ret) goto out; -clear_extent_dirty (&used, start, end); +clear_extent_dirty (&used, start, end,NULL ); }btrfs_set_super_bytes_used (fs_info->super_copy, bytes_used); ret =0 ; out: -extent_io_tree_cleanup (&used); +extent_io_tree_release (&used);return ret; }
cmds/rescue-chunk-recover.c +1 -1
@@ -1099,7 +1099,7 @@ static int block_group_free_all_extent(struct btrfs_trans_handle *trans,if (list_empty (&cache->dirty_list))list_add_tail (&cache->dirty_list, &trans->dirty_bgs); -set_extent_dirty (&info->free_space_cache, start, end); +set_extent_dirty (&info->free_space_cache, start, end,GFP_NOFS ); cache->used =0 ;
image/main.c +5 -4
@@ -475,7 +475,7 @@ static void metadump_destroy(struct metadump_struct *md, int num_threads)free (name->sub);free (name); } -extent_io_tree_cleanup (&md->seen); +extent_io_tree_release (&md->seen); } static int metadump_init(struct metadump_struct *md, struct btrfs_root *root,
@@ -491,7 +491,7 @@ static int metadump_init(struct metadump_struct *md, struct btrfs_root *root,memset (md,0 ,sizeof (*md));INIT_LIST_HEAD (&md->list);INIT_LIST_HEAD (&md->ordered); -extent_io_tree_init (&md->seen); +extent_io_tree_init (NULL , &md->seen,0 ); md->root = root; md->out = out; md->pending_start = (u64)-1 ;
@@ -784,11 +784,12 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb, bytenr =btrfs_header_bytenr (eb);if (test_range_bit (&metadump->seen, bytenr, - bytenr + fs_info->nodesize -1 ,EXTENT_DIRTY ,1 )) + bytenr + fs_info->nodesize -1 ,EXTENT_DIRTY ,1 , +NULL ))return 0 ;set_extent_dirty (&metadump->seen, bytenr, - bytenr + fs_info->nodesize -1 ); + bytenr + fs_info->nodesize -1 ,GFP_NOFS ); ret =add_extent (btrfs_header_bytenr (eb), fs_info->nodesize, metadump,0 );
include/kerncompat.h +159 -2
212 lines not on this page · raw message
kernel-lib/trace.h +26 -0
@@ -26,4 +26,30 @@ static inline void trace_btrfs_workqueue_destroy(void *wq) { } +static inline void trace_alloc_extent_state (struct extent_state *state, +gfp_t mask,unsigned long ip) +{ +} + +static inline void trace_free_extent_state (struct extent_state *state, +unsigned long ip) +{ +} + +static inline void trace_btrfs_clear_extent_bit (struct extent_io_tree *tree, +u64 start,u64 end,u32 bits) +{ +} + +static inline void trace_btrfs_set_extent_bit (struct extent_io_tree *tree, +u64 start,u64 end,u32 bits) +{ +} + +static inline void trace_btrfs_convert_extent_bit (struct extent_io_tree *tree, +u64 start,u64 end,u32 bits, +u32 clear_bits) +{ +} +#endif /* __PROGS_TRACE_H__ */
kernel-shared/ctree.h +1 -0
@@ -28,6 +28,7 @@#include "kernel-shared/uapi/btrfs.h" #include "kernel-shared/uapi/btrfs_tree.h" #include "accessors.h" +#include "extent-io-tree.h" struct btrfs_root ;struct btrfs_trans_handle ;
kernel-shared/disk-io.c +8 -8
@@ -866,10 +866,10 @@ struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr) goto free_all;extent_buffer_init_cache (fs_info); -extent_io_tree_init (&fs_info->dirty_buffers); -extent_io_tree_init (&fs_info->free_space_cache); -extent_io_tree_init (&fs_info->pinned_extents); -extent_io_tree_init (&fs_info->extent_ins); +extent_io_tree_init (fs_info, &fs_info->dirty_buffers,0 ); +extent_io_tree_init (fs_info, &fs_info->free_space_cache,0 ); +extent_io_tree_init (fs_info, &fs_info->pinned_extents,0 ); +extent_io_tree_init (fs_info, &fs_info->extent_ins,0 ); fs_info->block_group_cache_tree =RB_ROOT ; fs_info->excluded_extents =NULL ;
@@ -1350,11 +1350,11 @@ void btrfs_cleanup_all_caches(struct btrfs_fs_info *fs_info)free_extent_buffer (eb); }free_mapping_cache_tree (&fs_info->mapping_tree.cache_tree); -extent_io_tree_cleanup (&fs_info->dirty_buffers); +extent_io_tree_release (&fs_info->dirty_buffers);extent_buffer_free_cache (fs_info); -extent_io_tree_cleanup (&fs_info->free_space_cache); -extent_io_tree_cleanup (&fs_info->pinned_extents); -extent_io_tree_cleanup (&fs_info->extent_ins); +extent_io_tree_release (&fs_info->free_space_cache); +extent_io_tree_release (&fs_info->pinned_extents); +extent_io_tree_release (&fs_info->extent_ins); } int btrfs_scan_fs_devices(int fd, const char *path,
kernel-shared/extent-io-tree.c new file +1733 -0
1,733 lines not on this page · raw message
kernel-shared/extent-io-tree.h new file +239 -0
239 lines not on this page · raw message
kernel-shared/extent-tree.c +27 -18
142 lines not on this page · raw message
kernel-shared/extent_io.c +4 -469
326 lines not on this page · raw message
kernel-shared/misc.h new file +143 -0
143 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.40.0
Part of the diff is not shown here. View the raw message.
Re: [PATCH 1/8] btrfs-progs: sync uapi/btrfs.h into btrfs-progs
In reply to Josef BacikQuoted 11 lines · Josef Bacik
We want to keep this file locally as we want to be uptodate with upstream, so we can build btrfs-progs regardless of which kernel is currently installed. Sync this with the upstream version and put it in kernel-shared/uapi to maintain some semblance of where this file comes from.
Signed-off-by Josef Bacik <[email protected]>---
btrfs-fragments.c line 34
Quoted 5 lines
btrfs-fragments.c +1
-1@@ -31,7 +31,7 @@#include <gd.h> #include "kernel-shared/ctree.h" #include "common/utils.h" -#include "ioctl.h" +#include "kernel-shared/uapi/btrfs.h"
The includes are now sorted in sections so I moved the uapi header to the beginning of kernel-shared/ .
include/kerncompat.h typedef struct wait_queue_head_s { · line 579
Quoted 8 lines
include/kerncompat.h +1
-0@@ -576,5 +576,6 @@ typedef struct wait_queue_head_s {#define __init#define __cold +#define __user
I got a compilation error
In file included from common/send-stream.c:24:./kernel-shared/uapi/btrfs.h:141:60: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘*’ token
141 | struct btrfs_qgroup_inherit __user *qgroup_inherit;
| ^
I did a hotfix to conditionally define __user in uapi.h so the whole kerncompat.h is not included.
Re: [PATCH 1/8] btrfs-progs: sync uapi/btrfs.h into btrfs-progs
In reply to Josef BacikQuoted 9 lines · Josef Bacik
We want to keep this file locally as we want to be uptodate with upstream, so we can build btrfs-progs regardless of which kernel is currently installed. Sync this with the upstream version and put it in kernel-shared/uapi to maintain some semblance of where this file comes from.
Signed-off-by Josef Bacik <[email protected]>--- include/ioctl.h => kernel-shared/uapi/btrfs.h | 566 ++++++++++--------
When files are moved it's good to do a
$ git grep ioctl.h Makefile:ioctl-test.o: tests/ioctl-test.c include/ioctl.h include/kerncompat.h kernel-shared/ctree.h Makefile:ioctl-test-32.o: tests/ioctl-test.c include/ioctl.h include/kerncompat.h kernel-shared/ctree.h Makefile:ioctl-test-64.o: tests/ioctl-test.c include/ioctl.h include/kerncompat.h kernel-shared/ctree.h
to see if there's something using it which is not built by default. In this case library-test, the ioctl test, so path updated in Makefile.
Re: [PATCH 3/8] btrfs-progs: sync messages.* from the kernel
In reply to Josef Bacikkernel-shared/backref.c line 26
Quoted 7 lines · Josef Bacik
kernel-shared/backref.c +1
-0@@ -23,6 +23,7 @@#include "kernel-shared/ulist.h" #include "kernel-shared/transaction.h" #include "common/internal.h" +#include "messages.h"
The includes should be specified by the path though there's the -Idir/ for the toplevel directories so it works. In case of messages.h we have two, common/ and kernel-shared/ so this needs to be the kernel-shared one. Updated.
Re: [PATCH 4/8] btrfs-progs: add struct va_format support to our btrfs_no_printk helper
In reply to Josef BacikQuoted 15 lines · Josef Bacik
We use the struct
va_formatto do nested printk's internally with our message handling. Add the appropriate user space code to make this work properly so when we start copying this code into btrfs-progs we get the proper messages.Signed-off-by Josef Bacik <[email protected]>--- common/messages.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)common/messages.c +0
-0
common/messages.c line 19
Quoted 4 lines
common/messages.c +1
-0@@ -16,6 +16,7 @@#include <stdio.h> #include <stdarg.h> +#include <printf.h>
This header is not available on musl libc
[CC] common/messages.ocommon/messages.c:19:10: fatal error: printf.h: No such file or directory
19 | #include <printf.h>
| ^~~~~~~~~~
but for sake of merging all the patches I'll leave it temporarily broken. We can either insert a fixup patch or update this one with some stub/ifdef once we figure it out.
Quoted 15 lines · Josef Bacik
Hello,
This series copies the easier to sync files from the kernel into btrfs-progs and updates all the users to include the appropriate headers. There's an extra change in here to deal with
va_format, which we'll need for future syncs. I put it in here because it's related to the messages sync, so it seemed appropriate.This depends on the series
btrfs-progs: prep work for syncing files into kernel-shared
Thanks,
Josef
Quoted 10 lines
Josef Bacik (8):
btrfs-progs: syncuapi/btrfs.hinto btrfs-progs
btrfs-progs: sync ondisk definitions from the kernel
btrfs-progs: sync messages.* from the kernel
btrfs-progs: add structva_formatsupport to ourbtrfs_no_printk
helper
btrfs-progs: sync accessors.[ch] from the kernel
btrfs-progs: syncfile-item.hinto progs
btrfs-progs: sync async-thread.[ch] from the kernel
btrfs-progs: sync extent-io-tree.[ch] andmisc.hfrom the kernel
Added to devel, thanks. There were random compilation problems due to the paths or missing forward declarations. I did only minimal changes to make it build, we'll need to do another pass once all the patches land.
Re: [PATCH 1/8] btrfs-progs: sync uapi/btrfs.h into btrfs-progs
In reply to Josef BacikQuoted 19 lines · Josef Bacik
kernel-shared/uapi/btrfs.h renamed from include/ioctl.h +2
-10-#include <stddef.h> - -#ifndef __user -#define __user -#endif - -/* We don't want to include entire kerncompat.h */ -#ifndef BUILD_ASSERT -#define BUILD_ASSERT (x) -#endif +#include <linux/fs.h> #define BTRFS_IOCTL_MAGIC 0x94#define BTRFS_VOL_NAME_MAX 255 +#define BTRFS_LABEL_SIZE 256/* this should be 4k */ #define BTRFS_PATH_NAME_MAX 4087
kernel-shared/uapi/btrfs.h struct btrfs_ioctl_vol_args { · line 52
Quoted 8 lines
kernel-shared/uapi/btrfs.h renamed from include/ioctl.h +0
-3@@ -45,18 +38,20 @@ struct btrfs_ioctl_vol_args {__s64 fd;char name[BTRFS_PATH_NAME_MAX +1 ]; }; -BUILD_ASSERT (sizeof (struct btrfs_ioctl_vol_args ) ==4096 ); -BUILD_ASSERT (sizeof (struct btrfs_qgroup_limit ) ==40 ); -BUILD_ASSERT (sizeof (struct btrfs_qgroup_inherit ) ==72 );
You removed all the BUILD_ASSERTS, I vaguely remember that this was mentined in some previous iteration of the uapi sync that this should stay and be synced back to kernel rather than removed.
I'll keep the commit as-is for now, there are probably more lost changes like that, for later.