History log of /linux-master/fs/bcachefs/chardev.c
Revision Date Author Comments
# 02bed83d 16-Apr-2024 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Fix null ptr deref in twf from BCH_IOCTL_FSCK_OFFLINE

We need to initialize the stdio redirects before they're used.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 05801b65 05-Apr-2024 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Disable errors=panic for BCH_IOCTL_FSCK_OFFLINE

BCH_IOCTL_FSCK_OFFLINE allows the userspace fsck tool to use the kernel
implementation of fsck - primarily when the kernel version is a better
version match.

It should look and act exactly like the normal userspace fsck that the
user expected to be invoking, so errors should never result in a kernel
panic.

We may want to consider further restricting errors=panic - it's only
intended for debugging in controlled test environments, it should have
no purpose it normal usage.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 374b3d38 05-Apr-2024 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Fix BCH_IOCTL_FSCK_OFFLINE for encrypted filesystems

To open an encrypted filesystem, we use request_key() to get the
encryption key from the user's keyring - but request_key() needs to
happen in the context of the process that invoked the ioctl.

This easily fixed by using bch2_fs_open() in nostart mode.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# d2554263 23-Mar-2024 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Split out recovery_passes.c

We've grown a fair amount of code for managing recovery passes; tracking
which ones we're running, which ones need to be run, and flagging in the
superblock which ones need to be run on the next recovery.

So it's worth splitting out into its own file, this code is pretty
different from the code in recovery.c.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# d6454799 02-Mar-2024 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: copy_(to|from)_user_errcode()

we've got some helpers that return errors sanely, move them to a more
common location for use in fs-ioctl.c

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# da23795e 17-Feb-2024 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: thread_with_file: add f_ops.flush

Add a flush op, to return the exit code via close().

Also update bcachefs usage to use this to return fsck exit codes.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# ab6752e2 10-Feb-2024 Darrick J. Wong <djwong@kernel.org>

bcachefs: thread_with_file: create ops structure for thread_with_stdio

Create an ops structure so we can add more file-based functionality in
the next few patches.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# a6777ca4 04-Feb-2024 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: thread_with_stdio: kill thread_with_stdio_done()

Move the cleanup code to a wrapper function, where we can call it after
the thread_with_stdio fn exits.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# d55ddf6e 31-Dec-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Online fsck can now fix errors

BCH_FS_fsck_done -> BCH_FS_fsck_running; set when we might be fixing
fsck errors. Also; set fix_errors to ask by default when fsck is
running.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 96f37eab 31-Dec-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: factor out thread_with_file, thread_with_stdio

thread_with_stdio now knows how to handle input - fsck can now prompt to
fix errors.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 9fea2274 16-Dec-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: for_each_member_device() now declares loop iter

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# ac19c4c3 18-Dec-2023 Gustavo A. R. Silva <gustavoars@kernel.org>

bcachefs: Use array_size() in call to copy_from_user()

Use array_size() helper, instead of the open-coded version in
call to copy_from_user().

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 267b801f 04-Dec-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: BCH_IOCTL_FSCK_ONLINE

This adds a new ioctl for running fsck on a mounted, in use filesystem.

This reuses the fsck_thread code from the previous patch for running
fsck on an offline, unmounted filesystem, so that log messages for the
fsck thread are redirected to userspace.

Only one running fsck instance is allowed at a time; a new semaphore
(since the lock will be taken by one thread and released by another) is
added for this.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 8408fa57 11-Jul-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: BCH_IOCTL_FSCK_OFFLINE

This adds a new ioctl for running fsck on a list of devices.

Normally, if we wish to use the kernel's implementation of fsck we'd run
it at mount time with -o fsck. This ioctl lets us run fsck without
mounting, so that userspace bcachefs-tools can transparently switch to
the kernel's implementation of fsck when appropriate - primarily if the
kernel version of bcachefs better matches the filesystem on disk.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# bbefcd91 11-Jul-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: thread_with_file

Abstract out a new helper from the data job code, for connecting a
kthread to a file descriptor.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 3c471b65 26-Nov-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: convert bch_fs_flags to x-macro

Now we can print out filesystem flags in sysfs, useful for debugging
various "what's my filesystem doing" issues.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# e6674dec 23-Nov-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: BCH_IOCTL_DEV_USAGE_V2

BCH_IOCTL_DEV_USAGE mistakenly put the per-data-type array in struct
bch_ioctl_dev_usage; since ioctl numbers encode the size of the arg,
that means adding new data types breaks the ioctl.

This adds a new version that includes the number of data types as a
parameter: the old version is fixed at 10 so as to not break when adding
new types.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 086a52f7 09-Nov-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Rename bch_replicas_entry -> bch_replicas_entry_v1

Prep work for introducing bch_replicas_entry_v2

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# d5eade93 23-Oct-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: move: convert to bbpos

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 97ecc236 19-Sep-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Fix strndup_user() error checking

strndup_user() returns an error pointer, not NULL.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 4b33a191 19-Sep-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: bch2_ioctl_disk_resize_journal(): check for integer truncation

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 4ba985b8 14-Sep-2023 Dan Carpenter <dan.carpenter@linaro.org>

bcachefs: chardev: fix an integer overflow (32 bit only)

On 32 bit systems, "sizeof(*arg) + replica_entries_bytes" can have an
integer overflow leading to memory corruption. Use size_add() to
prevent this.

Fixes: b44dd3797034 ("bcachefs: Redo filesystem usage ioctls")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 301e0237 14-Sep-2023 Dan Carpenter <dan.carpenter@linaro.org>

bcachefs: chardev: return -EFAULT if copy_to_user() fails

The copy_to_user() function returns the number of bytes remaining but
we want to return -EFAULT to the user.

Fixes: e0750d947352 ("bcachefs: Initial commit")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# e47a390a 27-May-2023 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Convert -ENOENT to private error codes

As with previous conversions, replace -ENOENT uses with more informative
private error codes.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# e2fcf7f6 25-Nov-2022 Kent Overstreet <kent.overstreet@linux.dev>

bcachefs: Fix BCH_IOCTL_DISK_SET_STATE

- Ensure we print an error message if necessary.

Ideally we'd return the precise error code to userspace and leave
printing the error message to the userspace tool, but we haven't
decided to make our private error codes ABI-stable yet.

- Return standard error code to userspace

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 822835ff 31-Mar-2022 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Fold bucket_state in to BCH_DATA_TYPES()

Previously, we were missing accounting for buckets in need_gc_gens and
need_discard states. This matters because buckets in those states need
other btree operations done before they can be used, so they can't be
conuted when checking current number of free buckets against the
allocation watermark.

Also, we weren't directly counting free buckets at all. Now, data type 0
== BCH_DATA_free, and free buckets are counted; this means we can get
rid of the separate (poorly defined) count of unavailable buckets.

This is a new on disk format version, with upgrade and fsck required for
the accounting changes.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>


# eacb2574 02-Jan-2022 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: bch_dev->dev

Add a field to bch_dev for the dev_t of the underlying block device -
this fixes a null ptr deref in tracepoints.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>


# f0412b6e 08-Jul-2021 Dan Robertson <dan@dlrobertson.com>

bcachefs: set disk state should check new_state

A new device state that is not a valid state should return -EINVAL
in the disk set state ioctl.

Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# a515d0a5 04-Jul-2021 Tobias Geerinckx-Rice <me@tobias.gr>

bcachefs: Enforce SYS_CAP_ADMIN within ioctls

bch2_fs_ioctl() didn't distinguish between unsupported ioctls and those
which the current user is unauthorised to perform. That kept the code
simple but meant that, for example, an unprivileged TIOCGWINSZ ioctl on
a bcachefs file would return -EPERM instead of the expected -ENOTTY.
The same call made by a privileged user would correctly return -ENOTTY.

Fix this discrepancy by moving the check for CAP_SYS_ADMIN into each
privileged ioctl function.

Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# faf1a5f4 05-May-2021 Dan Robertson <dan@dlrobertson.com>

bcachefs: Fix out of bounds read in fs usage ioctl

Fix a possible read out of bounds if bch2_ioctl_fs_usage is called when
replica_entries_bytes is set to a value that is smaller than the size
of bch_replicas_usage.

Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 2b25de55 12-May-2021 Dan Robertson <dan@dlrobertson.com>

bcachefs: Fix null deref in bch2_ioctl_read_super

Do not attempt to cleanup the returned value of bch2_device_lookup if
the returned value was an error pointer. We currently check to see if
the returned value is null and run the cleanup otherwise. As a result,
we attempt to run the cleanup on a error pointer.

Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 72eab8da 21-Jan-2021 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Refactor dev usage

This is to make it more amenable for serialization.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# b7a9bbfc 19-Nov-2020 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Move journal reclaim to a kthread

This is to make tracing easier.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# e8c851b3 16-Nov-2020 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Add an ioctl for resizing journal on a device

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 3d080aa5 22-Jul-2020 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Delete unused arguments

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 649a9b68 18-Jun-2020 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Track sectors of erasure coded data

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 22502ac2 16-Dec-2019 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Redo filesystem usage ioctls

When disk space accounting was changed to be tracked by replicas entry,
the ioctl interface was never update: this patch finally does that.

Aditionally, the BCH_IOCTL_USAGE ioctl is now broken out into separate
ioctls for filesystem and device usage.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 619f5bee 17-Apr-2019 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: some improvements to startup messages and options

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 5e82a9a1 10-Feb-2019 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Write out fs usage consistently

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 424eb881 25-Mar-2019 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Only get btree iters from btree transactions

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 768ac639 14-Feb-2019 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Add a mechanism for blocking the journal

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 7ef2a73a 21-Jan-2019 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Fix check for if extent update is allocating

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 06b7345c 01-Dec-2018 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Include summarized counts in fs_usage

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 5663a415 27-Nov-2018 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: refactor bch_fs_usage

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 7b3f84ea 05-Oct-2018 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Split out alloc_background.c

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 5b650fd1 24-Jul-2018 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Account for internal fragmentation better

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 09f3297a 24-Jul-2018 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: kill s_alloc, use bch_data_type

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>


# 1c6fdbd8 17-Mar-2017 Kent Overstreet <kent.overstreet@gmail.com>

bcachefs: Initial commit

Initially forked from drivers/md/bcache, bcachefs is a new copy-on-write
filesystem with every feature you could possibly want.

Website: https://bcachefs.org

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>