bcachefs-in-userspace improvements

Got rid of the stupid shim file hack
This commit is contained in:
Kent Overstreet 2017-03-19 21:39:19 -08:00
parent 54e00cf016
commit c0ad33c126
28 changed files with 279 additions and 280 deletions

View File

@ -1 +1 @@
4fef29d8dad00d8e6192016631c5108e5e537c3c
217509029551f8b40024d7fcd6e311be1fb6410c

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ bcachefs
*.a
tags
cscope*
bcachefs-tools

View File

@ -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)

View File

@ -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);

View 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);
}

View 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) {

View 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: */

View 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)

View 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>

View 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)
{

View 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;

View File

@ -210,8 +210,10 @@
#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, ...) \

View 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,

View 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)

View 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)
{

View 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, \

View 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 }

View 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;

View 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) \

View 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 */

View 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>

View 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>
@ -49,12 +50,33 @@
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);

View 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 */

View File

@ -25,6 +25,101 @@
#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);

View File

@ -1,103 +1,39 @@
#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_ */

View File

@ -9,13 +9,14 @@
#include <linux/blkdev.h>
#include <linux/ctype.h>
#include <linux/debugfs.h>
#include <linux/module.h>
#include <linux/random.h>
#include <linux/seq_file.h>
#include <linux/types.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 "util.h"

View 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>

View 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>