]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
bcachefs-in-userspace improvements
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 20 Mar 2017 05:39:19 +0000 (21:39 -0800)
committerKent Overstreet <kent.overstreet@gmail.com>
Mon, 20 Mar 2017 05:39:19 +0000 (21:39 -0800)
Got rid of the stupid shim file hack

28 files changed:
.bcachefs_revision
.gitignore
Makefile
bcachefs-userspace-shim.c [deleted file]
bcachefs.c
cmd_debug.c
cmd_fsck.c
cmd_migrate.c
include/linux/kernel.h
include/linux/sysfs.h
libbcachefs.h
libbcachefs/bcachefs.h
libbcachefs/btree_cache.c
libbcachefs/btree_iter.c
libbcachefs/clock.c
libbcachefs/error.h
libbcachefs/fs-gc.c
libbcachefs/fs.h
libbcachefs/io.h
libbcachefs/movinggc.c
libbcachefs/six.c
libbcachefs/super.c
libbcachefs/super.h
libbcachefs/sysfs.c
libbcachefs/sysfs.h
libbcachefs/util.c
libbcachefs/xattr.c
linux/kstrtox.c

index e3d90e2ff57164b5dd29379899b6ee65a42add91..398cb4aceb4932e406c863f326e7cf7da6cc148d 100644 (file)
@@ -1 +1 @@
-4fef29d8dad00d8e6192016631c5108e5e537c3c
+217509029551f8b40024d7fcd6e311be1fb6410c
index ecf040c10d8fd5fc0f3d304e7bd026de9681f2ec..7357d5518f686d345c7ea016a73f8545bd8c4f2e 100644 (file)
@@ -5,3 +5,4 @@ bcachefs
 *.a
 tags
 cscope*
+bcachefs-tools
index dd2e66985618e867a7f5c3c395733442b6a970ca..7e00baad9e2a13b6d1c1daf6f200358eaf37d50b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,12 +10,9 @@ CFLAGS+=-std=gnu99 -O2 -g -MMD -Wall                         \
        -D_GNU_SOURCE                                           \
        -D_LGPL_SOURCE                                          \
        -DRCU_MEMBARRIER                                        \
-       -DNO_BCACHE_ACCOUNTING                                  \
-       -DNO_BCACHE_BLOCKDEV                                    \
        -DNO_BCACHE_CHARDEV                                     \
        -DNO_BCACHE_FS                                          \
-       -DNO_BCACHE_NOTIFY                                      \
-       -DNO_BCACHE_WRITEBACK                                   \
+       -DNO_BCACHE_SYSFS                                       \
        $(EXTRA_CFLAGS)
 LDFLAGS+=-O2 -g
 
@@ -41,7 +38,6 @@ endif
 all: bcachefs
 
 SRCS=bcachefs.c                                \
-     bcachefs-userspace-shim.c         \
      cmd_assemble.c                    \
      cmd_debug.c                       \
      cmd_device.c                      \
@@ -55,6 +51,40 @@ SRCS=bcachefs.c                              \
      libbcachefs.c                     \
      qcow2.c                           \
      tools-util.c                      \
+     libbcachefs/alloc.c               \
+     libbcachefs/bkey.c                        \
+     libbcachefs/bkey_methods.c                \
+     libbcachefs/bset.c                        \
+     libbcachefs/btree_cache.c         \
+     libbcachefs/btree_gc.c            \
+     libbcachefs/btree_io.c            \
+     libbcachefs/btree_iter.c          \
+     libbcachefs/btree_update.c                \
+     libbcachefs/buckets.c             \
+     libbcachefs/checksum.c            \
+     libbcachefs/clock.c               \
+     libbcachefs/compress.c            \
+     libbcachefs/debug.c               \
+     libbcachefs/dirent.c              \
+     libbcachefs/error.c               \
+     libbcachefs/extents.c             \
+     libbcachefs/fs-gc.c               \
+     libbcachefs/inode.c               \
+     libbcachefs/io.c                  \
+     libbcachefs/journal.c             \
+     libbcachefs/keylist.c             \
+     libbcachefs/migrate.c             \
+     libbcachefs/move.c                        \
+     libbcachefs/movinggc.c            \
+     libbcachefs/opts.c                        \
+     libbcachefs/siphash.c             \
+     libbcachefs/six.c                 \
+     libbcachefs/super.c               \
+     libbcachefs/super-io.c            \
+     libbcachefs/tier.c                        \
+     libbcachefs/trace.c               \
+     libbcachefs/util.c                        \
+     libbcachefs/xattr.c               \
      $(wildcard linux/*.c linux/*/*.c) \
      $(wildcard ccan/*/*.c)
 
diff --git a/bcachefs-userspace-shim.c b/bcachefs-userspace-shim.c
deleted file mode 100644 (file)
index 9fd62cd..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-
-#include <errno.h>
-#include <linux/types.h>
-
-#define bch2_fmt(_c, fmt)      fmt "\n"
-
-#include "libbcachefs.h"
-#include "tools-util.h"
-
-enum fsck_err_opts fsck_err_opt;
-
-/* Returns true if error should be fixed: */
-
-/* XXX: flag if we ignore errors */
-
-/*
- * If it's an error that we can't ignore, and we're running non
- * interactively - return true and have the error fixed so that we don't have to
- * bail out and stop the fsck early, so that the user can see all the errors
- * present:
- */
-#define __fsck_err(c, _can_fix, _can_ignore, _nofix_msg, msg, ...)     \
-({                                                                     \
-       bool _fix = false;                                              \
-                                                                       \
-       if (_can_fix) {                                                 \
-               switch (fsck_err_opt) {                                 \
-               case FSCK_ERR_ASK:                                      \
-                       printf(msg ": fix?", ##__VA_ARGS__);            \
-                       _fix = ask_yn();                                \
-                                                                       \
-                       break;                                          \
-               case FSCK_ERR_YES:                                      \
-                       bch_err(c, msg ", fixing", ##__VA_ARGS__);      \
-                       _fix = true;                                    \
-                       break;                                          \
-               case FSCK_ERR_NO:                                       \
-                       bch_err(c, msg, ##__VA_ARGS__);                 \
-                       _fix = false;                                   \
-                       break;                                          \
-               }                                                       \
-       } else if (_can_ignore) {                                       \
-               bch_err(c, msg, ##__VA_ARGS__);                         \
-       }                                                               \
-                                                                       \
-       if (_can_fix && !_can_ignore && fsck_err_opt == FSCK_ERR_NO)    \
-               _fix = true;                                            \
-                                                                       \
-       if (!_fix && !_can_ignore) {                                    \
-               printf("Fatal filesystem inconsistency, halting\n");    \
-               ret = BCH_FSCK_ERRORS_NOT_FIXED;                        \
-               goto fsck_err;                                          \
-       }                                                               \
-                                                                       \
-       _fix;                                                           \
-})
-
-//#include "acl.c"
-#include "alloc.c"
-#include "bkey.c"
-#include "bkey_methods.c"
-#include "bset.c"
-#include "btree_cache.c"
-#include "btree_gc.c"
-#include "btree_io.c"
-#include "btree_iter.c"
-#include "btree_update.c"
-#include "buckets.c"
-//#include "chardev.c"
-#include "checksum.c"
-#include "clock.c"
-#include "compress.c"
-#include "debug.c"
-#include "dirent.c"
-#include "error.c"
-#include "extents.c"
-//#include "fs.c"
-#include "fs-gc.c"
-//#include "fs-io.c"
-#include "inode.c"
-#include "io.c"
-#include "journal.c"
-#include "keylist.c"
-#include "migrate.c"
-#include "move.c"
-#include "movinggc.c"
-#include "opts.c"
-#include "siphash.c"
-#include "six.c"
-#include "super.c"
-#include "super-io.c"
-//#include "sysfs.c"
-#include "tier.c"
-#include "trace.c"
-#include "util.c"
-#include "xattr.c"
-
-#define SHIM_KTYPE(type)                                               \
-struct kobj_type type ## _ktype = { .release = type ## _release, }
-
-static void bch2_fs_internal_release(struct kobject *k) {}
-
-static void bch2_fs_opts_dir_release(struct kobject *k) {}
-
-static void bch2_fs_time_stats_release(struct kobject *k) {}
-
-SHIM_KTYPE(bch2_dev);
-SHIM_KTYPE(bch2_fs);
-SHIM_KTYPE(bch2_fs_internal);
-SHIM_KTYPE(bch2_fs_time_stats);
-SHIM_KTYPE(bch2_fs_opts_dir);
index 945d6df3695f2fcc0c95e5c7a45c2108523c1d97..9b6b057f85c8f450824ae83e0d20356ffd5d7cc5 100644 (file)
@@ -160,6 +160,7 @@ int main(int argc, char *argv[])
        if (!strcmp(cmd, "list"))
                return cmd_list(argc, argv);
 
+       printf("Unknown command %s\n", cmd);
        usage();
-       return 0;
+       exit(EXIT_FAILURE);
 }
index a8c534ba505768710ae5ccd3d02e460acca64e31..02f4b49d2f963797eb89c05891a9977f2ab9c592 100644 (file)
@@ -95,7 +95,6 @@ int cmd_dump(int argc, char *argv[])
        opts.nochanges  = true;
        opts.noreplay   = true;
        opts.errors     = BCH_ON_ERROR_CONTINUE;
-       fsck_err_opt    = FSCK_ERR_NO;
 
        while ((opt = getopt(argc, argv, "o:fh")) != -1)
                switch (opt) {
@@ -235,7 +234,6 @@ int cmd_list(int argc, char *argv[])
        opts.nochanges  = true;
        opts.norecovery = true;
        opts.errors     = BCH_ON_ERROR_CONTINUE;
-       fsck_err_opt    = FSCK_ERR_NO;
 
        while ((opt = getopt(argc, argv, "b:s:e:m:h")) != -1)
                switch (opt) {
index c8a8df6d8bf019697b64c8d5f6c7ce076cdc66f6..17750675ffe5dbb8a2b6270ee304f1f4ec67a7e0 100644 (file)
@@ -1,5 +1,6 @@
 
 #include "cmds.h"
+#include "error.h"
 #include "libbcachefs.h"
 #include "super.h"
 #include "tools-util.h"
@@ -29,14 +30,14 @@ int cmd_fsck(int argc, char *argv[])
        while ((opt = getopt(argc, argv, "pynfvh")) != -1)
                switch (opt) {
                case 'p':
-                       fsck_err_opt = FSCK_ERR_YES;
+                       opts.fix_errors = FSCK_ERR_YES;
                        break;
                case 'y':
-                       fsck_err_opt = FSCK_ERR_YES;
+                       opts.fix_errors = FSCK_ERR_YES;
                        break;
                case 'n':
                        opts.nochanges = true;
-                       fsck_err_opt = FSCK_ERR_NO;
+                       opts.fix_errors = FSCK_ERR_NO;
                        break;
                case 'f':
                        /* force check, even if filesystem marked clean: */
index 62ef04c6c728118d397d630c59b551572b725e2f..2810dc23a6c6aa0df2e7fa0ee1c52ad56ef99b33 100644 (file)
@@ -760,7 +760,6 @@ int cmd_migrate(int argc, char *argv[])
        printf("Migrate complete, running fsck:\n");
        opts.nostart    = false;
        opts.nochanges  = true;
-       fsck_err_opt    = FSCK_ERR_NO;
 
        err = bch2_fs_open(path, 1, opts, &c);
        if (err)
index 741e0ba46f24cbc0b1e387f6a77438ece1a94fac..dc778f1c88408656ff77ae6405448ebc8555a5f1 100644 (file)
@@ -2,6 +2,7 @@
 #define __TOOLS_LINUX_KERNEL_H
 
 #include <assert.h>
+#include <errno.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
index 0be85b70f1db7a75289638d3f8d6d8ff05c775ab..dde169221d7290c2edd8008623b0fc28f738ba38 100644 (file)
@@ -17,6 +17,11 @@ struct attribute {
        .store  = _store,                                               \
 }
 
+struct sysfs_ops {
+       ssize_t (*show)(struct kobject *, struct attribute *, char *);
+       ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
+};
+
 static inline int sysfs_create_files(struct kobject *kobj,
                                    const struct attribute **attr)
 {
index f9cf8fe40350412063b14dc839c3b411a03730ca..2e677aef375e01199c55b48cd3f4fa9d4f46bd4c 100644 (file)
@@ -8,16 +8,6 @@
 #include "tools-util.h"
 #include "vstructs.h"
 
-struct cache_sb;
-
-enum fsck_err_opts {
-       FSCK_ERR_ASK,
-       FSCK_ERR_YES,
-       FSCK_ERR_NO,
-};
-
-extern enum fsck_err_opts fsck_err_opt;
-
 struct format_opts {
        char            *label;
        uuid_le         uuid;
index 6e08947ca0b2af73bf8acde62b6c7f1b8b4d97b7..9bc6210f55d7c7ca817853e5e33d757d3088e28f 100644 (file)
 #define bch2_meta_write_fault(name)                                    \
         dynamic_fault("bcachefs:meta:write:" name)
 
-#ifndef bch2_fmt
+#ifdef __KERNEL__
 #define bch2_fmt(_c, fmt)      "bcachefs (%s): " fmt "\n", ((_c)->name)
+#else
+#define bch2_fmt(_c, fmt)      fmt "\n"
 #endif
 
 #define bch_info(c, fmt, ...) \
index c4cc26f9138bd5c8143ce9aafb3f3f0b9f68cf86..e98d9c16c9e8cfe759982153b60623638e3d08fb 100644 (file)
@@ -7,6 +7,7 @@
 #include "debug.h"
 #include "extents.h"
 
+#include <linux/prefetch.h>
 #include <trace/events/bcachefs.h>
 
 #define DEF_BTREE_ID(kwd, val, name) name,
index fb5c507e9bcebf90ae666a0aaec0bec7d3313bc0..55303f09e51517052fea562dc530c9adb8f4c2ba 100644 (file)
@@ -7,6 +7,7 @@
 #include "debug.h"
 #include "extents.h"
 
+#include <linux/prefetch.h>
 #include <trace/events/bcachefs.h>
 
 #define BTREE_ITER_NOT_END     ((struct btree *) 1)
index 3c3649f0862c8779307ef2ce8271ba8eee79c460..68ac62b4c9a7922ddff8e07afe47a798d4297495 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/freezer.h>
 #include <linux/kthread.h>
+#include <linux/preempt.h>
 
 static inline bool io_timer_cmp(struct io_timer *l, struct io_timer *r)
 {
index 83d3a6274eb72e899ad759d9c6f39b1abc8031c5..5f81c346db9152e97c9361870dd98a10098d6b2b 100644 (file)
@@ -5,6 +5,7 @@
 
 struct bch_dev;
 struct bch_fs;
+struct work_struct;
 
 /*
  * XXX: separate out errors that indicate on disk data is inconsistent, and flag
@@ -98,28 +99,65 @@ enum {
 
 /* XXX: mark in superblock that filesystem contains errors, if we ignore: */
 
-#ifndef __fsck_err
-#define __fsck_err(c, _can_fix, _can_ignore, _nofix_msg, msg, ...)     \
+enum fsck_err_opts {
+       FSCK_ERR_NO,
+       FSCK_ERR_YES,
+       FSCK_ERR_ASK,
+};
+
+#ifdef __KERNEL__
+#define __fsck_err_should_fix(c, msg, ...)                             \
+({                                                                     \
+       bool _fix = (c)->opts.fix_errors;                               \
+       bch_err(c, msg ", %sfixing", ##__VA_ARGS__, _fix ? "" : "not ");\
+       _fix;                                                           \
+})
+#else
+#include "tools-util.h"
+
+#define __fsck_err_should_fix(c, msg, ...)                             \
 ({                                                                     \
        bool _fix = false;                                              \
-                                                                       \
-       if (_can_fix && (c)->opts.fix_errors) {                         \
+       switch ((c)->opts.fix_errors) {                                 \
+       case FSCK_ERR_ASK:                                              \
+               printf(msg ": fix?", ##__VA_ARGS__);                    \
+               _fix = ask_yn();                                        \
+               break;                                                  \
+       case FSCK_ERR_YES:                                              \
                bch_err(c, msg ", fixing", ##__VA_ARGS__);              \
-               set_bit(BCH_FS_FSCK_FIXED_ERRORS, &(c)->flags); \
                _fix = true;                                            \
-       } else if (_can_ignore &&                                       \
-                  (c)->opts.errors == BCH_ON_ERROR_CONTINUE) {         \
-               bch_err(c, msg " (ignoring)", ##__VA_ARGS__);           \
+               break;                                                  \
+       case FSCK_ERR_NO:                                               \
+               bch_err(c, msg, ##__VA_ARGS__);                         \
+               _fix = false;                                           \
+               break;                                                  \
+       }                                                               \
+       _fix;                                                           \
+})
+#endif
+
+#define __fsck_err(c, _can_fix, _can_ignore, _nofix_msg, msg, ...)     \
+({                                                                     \
+       bool _fix;                                                      \
+                                                                       \
+       if (_can_fix) {                                                 \
+               _fix = __fsck_err_should_fix(c, msg, ##__VA_ARGS__);    \
        } else {                                                        \
                bch_err(c, msg " ("_nofix_msg")", ##__VA_ARGS__);       \
+               _fix = false;                                           \
+       }                                                               \
+                                                                       \
+       if (_fix)                                                       \
+               set_bit(BCH_FS_FSCK_FIXED_ERRORS, &(c)->flags);         \
+                                                                       \
+       if (!_fix && !_can_ignore) {                                    \
+               bch_err(c, "Unable to continue, halting");              \
                ret = BCH_FSCK_ERRORS_NOT_FIXED;                        \
                goto fsck_err;                                          \
        }                                                               \
                                                                        \
-       BUG_ON(!_fix && !_can_ignore);                                  \
        _fix;                                                           \
 })
-#endif
 
 #define __fsck_err_on(cond, c, _can_fix, _can_ignore, _nofix_msg, ...) \
        ((cond) ? __fsck_err(c, _can_fix, _can_ignore,                  \
index 20f552d2c97d4a3f477dfee44f274876fdd0dad7..1a03b7ea8ef494f943cf663166741ed18e7fec16 100644 (file)
@@ -9,6 +9,7 @@
 #include "keylist.h"
 #include "super.h"
 
+#include <linux/dcache.h> /* struct qstr */
 #include <linux/generic-radix-tree.h>
 
 #define QSTR(n) { { { .len = strlen(n) } }, .name = n }
index f7cad296388c38eb1f58e56680264bf35c826ba8..38a349d0cc74ee5f0a0b2ab39479ee3334d6fcc0 100644 (file)
@@ -4,6 +4,7 @@
 #include "str_hash.h"
 
 #include <linux/seqlock.h>
+#include <linux/stat.h>
 
 struct bch_inode_info {
        struct inode            vfs_inode;
index 253316a4be998d1a78fa84e14cc83332a7cb743c..fb6f3005ef96447c095a97ad5aa1e5a8a8ba5eb0 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _BCACHE_IO_H
 #define _BCACHE_IO_H
 
+#include <linux/hash.h>
 #include "io_types.h"
 
 #define to_wbio(_bio)                  \
index 8804dbb32a69b64192770026d285d258e142a577..cc7d3f68302034b6b5e41a6dbac444fe9d1f970e 100644 (file)
@@ -17,6 +17,7 @@
 #include <trace/events/bcachefs.h>
 #include <linux/freezer.h>
 #include <linux/kthread.h>
+#include <linux/math64.h>
 #include <linux/wait.h>
 
 /* Moving GC - IO loop */
index 1bb8bfcccd6992def44c3edc189140f388c48448..328378550bf7255acbb00e8b9a4b2b8d6dbb4370 100644 (file)
@@ -1,4 +1,7 @@
 
+#include <linux/log2.h>
+#include <linux/preempt.h>
+#include <linux/rcupdate.h>
 #include <linux/sched.h>
 #include <linux/sched/rt.h>
 
index 8aa5cc00b25e50a44b57f0a8bc80886ff39dc33b..1977bdc49df8f254982c0d653e985b6c0427c0ad 100644 (file)
@@ -29,6 +29,7 @@
 #include "movinggc.h"
 #include "super.h"
 #include "super-io.h"
+#include "sysfs.h"
 #include "tier.h"
 
 #include <linux/backing-dev.h>
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Kent Overstreet <kent.overstreet@gmail.com>");
 
-static const uuid_le invalid_uuid = {
-       .b = {
-               0xa0, 0x3e, 0xf8, 0xed, 0x3e, 0xe1, 0xb8, 0x78,
-               0xc8, 0x50, 0xfc, 0x5e, 0xcb, 0x16, 0xcd, 0x99
-       }
-};
+#define KTYPE(type)                                                    \
+struct kobj_type type ## _ktype = {                                    \
+       .release        = type ## _release,                             \
+       .sysfs_ops      = &type ## _sysfs_ops,                          \
+       .default_attrs  = type ## _files                                \
+}
+
+static void bch2_fs_release(struct kobject *);
+static void bch2_dev_release(struct kobject *);
+
+static void bch2_fs_internal_release(struct kobject *k)
+{
+}
+
+static void bch2_fs_opts_dir_release(struct kobject *k)
+{
+}
+
+static void bch2_fs_time_stats_release(struct kobject *k)
+{
+}
+
+static KTYPE(bch2_fs);
+static KTYPE(bch2_fs_internal);
+static KTYPE(bch2_fs_opts_dir);
+static KTYPE(bch2_fs_time_stats);
+static KTYPE(bch2_dev);
 
 static struct kset *bcachefs_kset;
 static LIST_HEAD(bch_fs_list);
@@ -417,7 +439,7 @@ static void bch2_fs_offline(struct bch_fs *c)
        __bch2_fs_read_only(c);
 }
 
-void bch2_fs_release(struct kobject *kobj)
+static void bch2_fs_release(struct kobject *kobj)
 {
        struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
 
@@ -913,7 +935,7 @@ static const char *bch2_dev_in_fs(struct bch_sb *fs, struct bch_sb *sb)
 
 /* Device startup/shutdown: */
 
-void bch2_dev_release(struct kobject *kobj)
+static void bch2_dev_release(struct kobject *kobj)
 {
        struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
 
index 944244149e2e48ff017cdaedecbf0544f814c9d0..700344a99919f3b4a31751000d20c0cc8df52095 100644 (file)
@@ -93,8 +93,6 @@ struct bch_fs *bch2_bdev_to_fs(struct block_device *);
 struct bch_fs *bch2_uuid_to_fs(uuid_le);
 int bch2_congested(struct bch_fs *, int);
 
-void bch2_dev_release(struct kobject *);
-
 bool bch2_dev_state_allowed(struct bch_fs *, struct bch_dev *,
                           enum bch_member_state, int);
 int __bch2_dev_set_state(struct bch_fs *, struct bch_dev *,
@@ -113,7 +111,6 @@ bool bch2_fs_emergency_read_only(struct bch_fs *);
 void bch2_fs_read_only(struct bch_fs *);
 const char *bch2_fs_read_write(struct bch_fs *);
 
-void bch2_fs_release(struct kobject *);
 void bch2_fs_stop(struct bch_fs *);
 
 const char *bch2_fs_start(struct bch_fs *);
@@ -121,10 +118,4 @@ const char *bch2_fs_open(char * const *, unsigned, struct bch_opts,
                        struct bch_fs **);
 const char *bch2_fs_open_incremental(const char *path);
 
-extern struct kobj_type bch2_fs_ktype;
-extern struct kobj_type bch2_fs_internal_ktype;
-extern struct kobj_type bch2_fs_time_stats_ktype;
-extern struct kobj_type bch2_fs_opts_dir_ktype;
-extern struct kobj_type bch2_dev_ktype;
-
 #endif /* _BCACHE_SUPER_H */
index 11c6cdcc8577a00fb4d61f7e77e18ee21313b737..a0b9faeb96b25db679604898cd49d7ac6b59e451 100644 (file)
 #include <linux/blkdev.h>
 #include <linux/sort.h>
 
+#include "util.h"
+
+#define SYSFS_OPS(type)                                                        \
+struct sysfs_ops type ## _sysfs_ops = {                                        \
+       .show   = type ## _show,                                        \
+       .store  = type ## _store                                        \
+}
+
+#define SHOW(fn)                                                       \
+static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
+                          char *buf)                                   \
+
+#define STORE(fn)                                                      \
+static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
+                           const char *buf, size_t size)               \
+
+#define __sysfs_attribute(_name, _mode)                                        \
+       static struct attribute sysfs_##_name =                         \
+               { .name = #_name, .mode = _mode }
+
+#define write_attribute(n)     __sysfs_attribute(n, S_IWUSR)
+#define read_attribute(n)      __sysfs_attribute(n, S_IRUGO)
+#define rw_attribute(n)                __sysfs_attribute(n, S_IRUGO|S_IWUSR)
+
+#define sysfs_printf(file, fmt, ...)                                   \
+do {                                                                   \
+       if (attr == &sysfs_ ## file)                                    \
+               return snprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__); \
+} while (0)
+
+#define sysfs_print(file, var)                                         \
+do {                                                                   \
+       if (attr == &sysfs_ ## file)                                    \
+               return snprint(buf, PAGE_SIZE, var);                    \
+} while (0)
+
+#define sysfs_hprint(file, val)                                                \
+do {                                                                   \
+       if (attr == &sysfs_ ## file) {                                  \
+               ssize_t ret = bch2_hprint(buf, val);                    \
+               strcat(buf, "\n");                                      \
+               return ret + 1;                                         \
+       }                                                               \
+} while (0)
+
+#define var_printf(_var, fmt)  sysfs_printf(_var, fmt, var(_var))
+#define var_print(_var)                sysfs_print(_var, var(_var))
+#define var_hprint(_var)       sysfs_hprint(_var, var(_var))
+
+#define sysfs_strtoul(file, var)                                       \
+do {                                                                   \
+       if (attr == &sysfs_ ## file)                                    \
+               return strtoul_safe(buf, var) ?: (ssize_t) size;        \
+} while (0)
+
+#define sysfs_strtoul_clamp(file, var, min, max)                       \
+do {                                                                   \
+       if (attr == &sysfs_ ## file)                                    \
+               return strtoul_safe_clamp(buf, var, min, max)           \
+                       ?: (ssize_t) size;                              \
+} while (0)
+
+#define strtoul_or_return(cp)                                          \
+({                                                                     \
+       unsigned long _v;                                               \
+       int _r = kstrtoul(cp, 10, &_v);                                 \
+       if (_r)                                                         \
+               return _r;                                              \
+       _v;                                                             \
+})
+
+#define strtoul_restrict_or_return(cp, min, max)                       \
+({                                                                     \
+       unsigned long __v = 0;                                          \
+       int _r = strtoul_safe_restrict(cp, __v, min, max);              \
+       if (_r)                                                         \
+               return _r;                                              \
+       __v;                                                            \
+})
+
+#define strtoi_h_or_return(cp)                                         \
+({                                                                     \
+       u64 _v;                                                         \
+       int _r = strtoi_h(cp, &_v);                                     \
+       if (_r)                                                         \
+               return _r;                                              \
+       _v;                                                             \
+})
+
+#define sysfs_hatoi(file, var)                                         \
+do {                                                                   \
+       if (attr == &sysfs_ ## file)                                    \
+               return strtoi_h(buf, &var) ?: (ssize_t) size;           \
+} while (0)
+
 write_attribute(trigger_btree_coalesce);
 write_attribute(trigger_gc);
 write_attribute(prune_cache);
@@ -461,8 +556,9 @@ STORE(bch2_fs)
 
        return size;
 }
+SYSFS_OPS(bch2_fs);
 
-static struct attribute *bch2_fs_files[] = {
+struct attribute *bch2_fs_files[] = {
        &sysfs_journal_write_delay_ms,
        &sysfs_journal_reclaim_delay_ms,
        &sysfs_journal_entry_size_max,
@@ -488,7 +584,6 @@ static struct attribute *bch2_fs_files[] = {
        &sysfs_journal_flush,
        NULL
 };
-KTYPE(bch2_fs);
 
 /* internal dir - just a wrapper */
 
@@ -503,12 +598,9 @@ STORE(bch2_fs_internal)
        struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
        return bch2_fs_store(&c->kobj, attr, buf, size);
 }
+SYSFS_OPS(bch2_fs_internal);
 
-static void bch2_fs_internal_release(struct kobject *k)
-{
-}
-
-static struct attribute *bch2_fs_internal_files[] = {
+struct attribute *bch2_fs_internal_files[] = {
        &sysfs_journal_debug,
 
        &sysfs_alloc_debug,
@@ -537,7 +629,6 @@ static struct attribute *bch2_fs_internal_files[] = {
 
        NULL
 };
-KTYPE(bch2_fs_internal);
 
 /* options */
 
@@ -582,12 +673,9 @@ STORE(bch2_fs_opts_dir)
 
        return size;
 }
+SYSFS_OPS(bch2_fs_opts_dir);
 
-static void bch2_fs_opts_dir_release(struct kobject *k)
-{
-}
-
-static struct attribute *bch2_fs_opts_dir_files[] = {
+struct attribute *bch2_fs_opts_dir_files[] = {
 #define BCH_OPT(_name, ...)                                            \
        &sysfs_opt_##_name,
 
@@ -596,7 +684,6 @@ static struct attribute *bch2_fs_opts_dir_files[] = {
 
        NULL
 };
-KTYPE(bch2_fs_opts_dir);
 
 /* time stats */
 
@@ -624,12 +711,9 @@ STORE(bch2_fs_time_stats)
 
        return size;
 }
+SYSFS_OPS(bch2_fs_time_stats);
 
-static void bch2_fs_time_stats_release(struct kobject *k)
-{
-}
-
-static struct attribute *bch2_fs_time_stats_files[] = {
+struct attribute *bch2_fs_time_stats_files[] = {
 #define BCH_TIME_STAT(name, frequency_units, duration_units)           \
        sysfs_time_stats_attribute_list(name, frequency_units, duration_units)
        BCH_TIME_STATS()
@@ -637,7 +721,6 @@ static struct attribute *bch2_fs_time_stats_files[] = {
 
        NULL
 };
-KTYPE(bch2_fs_time_stats);
 
 typedef unsigned (bucket_map_fn)(struct bch_dev *, struct bucket *, void *);
 
@@ -894,8 +977,9 @@ STORE(bch2_dev)
 
        return size;
 }
+SYSFS_OPS(bch2_dev);
 
-static struct attribute *bch2_dev_files[] = {
+struct attribute *bch2_dev_files[] = {
        &sysfs_uuid,
        &sysfs_bucket_size,
        &sysfs_bucket_size_bytes,
@@ -932,4 +1016,3 @@ static struct attribute *bch2_dev_files[] = {
        sysfs_pd_controller_files(copy_gc),
        NULL
 };
-KTYPE(bch2_dev);
index d1f17cff2a3254852e1523f8ca67f0c5405c93b1..c0b8034ef207a8eff3f8e0c433bc90660649386a 100644 (file)
 #ifndef _BCACHE_SYSFS_H_
 #define _BCACHE_SYSFS_H_
 
-#include "util.h"
+#include <linux/sysfs.h>
 
-#define KTYPE(type)                                                    \
-struct kobj_type type ## _ktype = {                                    \
-       .release        = type ## _release,                             \
-       .sysfs_ops      = &((const struct sysfs_ops) {                  \
-               .show   = type ## _show,                                \
-               .store  = type ## _store                                \
-       }),                                                             \
-       .default_attrs  = type ## _files                                \
-}
+#ifndef NO_BCACHE_SYSFS
 
-#define SHOW(fn)                                                       \
-static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
-                          char *buf)                                   \
+struct attribute;
+struct sysfs_ops;
 
-#define STORE(fn)                                                      \
-static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
-                           const char *buf, size_t size)               \
+extern struct attribute *bch2_fs_files[];
+extern struct attribute *bch2_fs_internal_files[];
+extern struct attribute *bch2_fs_opts_dir_files[];
+extern struct attribute *bch2_fs_time_stats_files[];
+extern struct attribute *bch2_dev_files[];
 
-#define __sysfs_attribute(_name, _mode)                                        \
-       static struct attribute sysfs_##_name =                         \
-               { .name = #_name, .mode = _mode }
+extern struct sysfs_ops bch2_fs_sysfs_ops;
+extern struct sysfs_ops bch2_fs_internal_sysfs_ops;
+extern struct sysfs_ops bch2_fs_opts_dir_sysfs_ops;
+extern struct sysfs_ops bch2_fs_time_stats_sysfs_ops;
+extern struct sysfs_ops bch2_dev_sysfs_ops;
 
-#define write_attribute(n)     __sysfs_attribute(n, S_IWUSR)
-#define read_attribute(n)      __sysfs_attribute(n, S_IRUGO)
-#define rw_attribute(n)                __sysfs_attribute(n, S_IRUGO|S_IWUSR)
+#else
 
-#define sysfs_printf(file, fmt, ...)                                   \
-do {                                                                   \
-       if (attr == &sysfs_ ## file)                                    \
-               return snprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__); \
-} while (0)
+static struct attribute *bch2_fs_files[] = {};
+static struct attribute *bch2_fs_internal_files[] = {};
+static struct attribute *bch2_fs_opts_dir_files[] = {};
+static struct attribute *bch2_fs_time_stats_files[] = {};
+static struct attribute *bch2_dev_files[] = {};
 
-#define sysfs_print(file, var)                                         \
-do {                                                                   \
-       if (attr == &sysfs_ ## file)                                    \
-               return snprint(buf, PAGE_SIZE, var);                    \
-} while (0)
+static const struct sysfs_ops bch2_fs_sysfs_ops;
+static const struct sysfs_ops bch2_fs_internal_sysfs_ops;
+static const struct sysfs_ops bch2_fs_opts_dir_sysfs_ops;
+static const struct sysfs_ops bch2_fs_time_stats_sysfs_ops;
+static const struct sysfs_ops bch2_dev_sysfs_ops;
 
-#define sysfs_hprint(file, val)                                                \
-do {                                                                   \
-       if (attr == &sysfs_ ## file) {                                  \
-               ssize_t ret = bch2_hprint(buf, val);                    \
-               strcat(buf, "\n");                                      \
-               return ret + 1;                                         \
-       }                                                               \
-} while (0)
-
-#define var_printf(_var, fmt)  sysfs_printf(_var, fmt, var(_var))
-#define var_print(_var)                sysfs_print(_var, var(_var))
-#define var_hprint(_var)       sysfs_hprint(_var, var(_var))
-
-#define sysfs_strtoul(file, var)                                       \
-do {                                                                   \
-       if (attr == &sysfs_ ## file)                                    \
-               return strtoul_safe(buf, var) ?: (ssize_t) size;        \
-} while (0)
-
-#define sysfs_strtoul_clamp(file, var, min, max)                       \
-do {                                                                   \
-       if (attr == &sysfs_ ## file)                                    \
-               return strtoul_safe_clamp(buf, var, min, max)           \
-                       ?: (ssize_t) size;                              \
-} while (0)
-
-#define strtoul_or_return(cp)                                          \
-({                                                                     \
-       unsigned long _v;                                               \
-       int _r = kstrtoul(cp, 10, &_v);                                 \
-       if (_r)                                                         \
-               return _r;                                              \
-       _v;                                                             \
-})
-
-#define strtoul_restrict_or_return(cp, min, max)                       \
-({                                                                     \
-       unsigned long __v = 0;                                          \
-       int _r = strtoul_safe_restrict(cp, __v, min, max);              \
-       if (_r)                                                         \
-               return _r;                                              \
-       __v;                                                            \
-})
-
-#define strtoi_h_or_return(cp)                                         \
-({                                                                     \
-       u64 _v;                                                         \
-       int _r = strtoi_h(cp, &_v);                                     \
-       if (_r)                                                         \
-               return _r;                                              \
-       _v;                                                             \
-})
-
-#define sysfs_hatoi(file, var)                                         \
-do {                                                                   \
-       if (attr == &sysfs_ ## file)                                    \
-               return strtoi_h(buf, &var) ?: (ssize_t) size;           \
-} while (0)
+#endif
 
 #endif  /* _BCACHE_SYSFS_H_ */
index e4cd6317497484a659c14c60de02d8d9ffbc9f97..f2e6ec4dfa94748eeec38485e57dd6f104a9ec2f 100644 (file)
@@ -9,14 +9,15 @@
 #include <linux/blkdev.h>
 #include <linux/ctype.h>
 #include <linux/debugfs.h>
-#include <linux/module.h>
+#include <linux/freezer.h>
+#include <linux/kthread.h>
+#include <linux/log2.h>
+#include <linux/math64.h>
 #include <linux/random.h>
 #include <linux/seq_file.h>
+#include <linux/string.h>
 #include <linux/types.h>
 
-#include <linux/freezer.h>
-#include <linux/kthread.h>
-
 #include "util.h"
 
 #define simple_strtoint(c, end, base)  simple_strtol(c, end, base)
index 62a08897dc880bd6222b6f90eb853bfa6637885c..488d5369e1f55d4830cd8f165d7b626fe7d94f45 100644 (file)
@@ -7,6 +7,7 @@
 #include "str_hash.h"
 #include "xattr.h"
 
+#include <linux/dcache.h>
 #include <linux/posix_acl_xattr.h>
 #include <linux/xattr.h>
 
index af6b22218b3e28460a7e3624bcbf405e822cf04a..193726514c4218cfc3450ee1625ad88a446a698d 100644 (file)
@@ -11,8 +11,8 @@
  *
  * If -E is returned, result is not touched.
  */
+#include <errno.h>
 #include <linux/ctype.h>
-#include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/math64.h>
 #include <linux/export.h>