2017-03-17 06:18:50 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2023-09-10 22:05:17 +00:00
|
|
|
#ifndef _BCACHEFS_IO_WRITE_TYPES_H
|
|
|
|
#define _BCACHEFS_IO_WRITE_TYPES_H
|
2017-03-17 06:18:50 +00:00
|
|
|
|
|
|
|
#include "alloc_types.h"
|
|
|
|
#include "btree_types.h"
|
|
|
|
#include "buckets_types.h"
|
|
|
|
#include "extents_types.h"
|
|
|
|
#include "keylist_types.h"
|
|
|
|
#include "opts.h"
|
|
|
|
#include "super_types.h"
|
|
|
|
|
|
|
|
#include <linux/llist.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
|
|
|
|
struct bch_write_bio {
|
|
|
|
struct_group(wbio,
|
|
|
|
struct bch_fs *c;
|
|
|
|
struct bch_write_bio *parent;
|
|
|
|
|
|
|
|
u64 submit_time;
|
2022-11-16 01:25:08 +00:00
|
|
|
u64 inode_offset;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
|
|
|
struct bch_devs_list failed;
|
|
|
|
u8 dev;
|
|
|
|
|
|
|
|
unsigned split:1,
|
|
|
|
bounce:1,
|
|
|
|
put_bio:1,
|
|
|
|
have_ioref:1,
|
bcachefs: Nocow support
This adds support for nocow mode, where we do writes in-place when
possible. Patch components:
- New boolean filesystem and inode option, nocow: note that when nocow
is enabled, data checksumming and compression are implicitly disabled
- To prevent in-place writes from racing with data moves
(data_update.c) or bucket reuse (i.e. a bucket being reused and
re-allocated while a nocow write is in flight, we have a new locking
mechanism.
Buckets can be locked for either data update or data move, using a
fixed size hash table of two_state_shared locks. We don't have any
chaining, meaning updates and moves to different buckets that hash to
the same lock will wait unnecessarily - we'll want to watch for this
becoming an issue.
- The allocator path also needs to check for in-place writes in flight
to a given bucket before giving it out: thus we add another counter
to bucket_alloc_state so we can track this.
- Fsync now may need to issue cache flushes to block devices instead of
flushing the journal. We add a device bitmask to bch_inode_info,
ei_devs_need_flush, which tracks devices that need to have flushes
issued - note that this will lead to unnecessary flushes when other
codepaths have already issued flushes, we may want to replace this with
a sequence number.
- New nocow write path: look up extents, and if they're writable write
to them - otherwise fall back to the normal COW write path.
XXX: switch to sequence numbers instead of bitmask for devs needing
journal flush
XXX: ei_quota_lock being a mutex means bch2_nocow_write_done() needs to
run in process context - see if we can improve this
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2022-11-02 21:12:00 +00:00
|
|
|
nocow:1,
|
2021-07-10 17:44:42 +00:00
|
|
|
used_mempool:1,
|
|
|
|
first_btree_write:1;
|
2017-03-17 06:18:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
struct bio bio;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bch_write_op {
|
|
|
|
struct closure cl;
|
|
|
|
struct bch_fs *c;
|
2019-11-02 01:16:51 +00:00
|
|
|
void (*end_io)(struct bch_write_op *);
|
2017-03-17 06:18:50 +00:00
|
|
|
u64 start_time;
|
|
|
|
|
|
|
|
unsigned written; /* sectors */
|
|
|
|
u16 flags;
|
|
|
|
s16 error; /* dio write path expects it to hold -ERESTARTSYS... */
|
|
|
|
|
2023-07-13 02:27:16 +00:00
|
|
|
unsigned compression_opt:8;
|
2017-03-17 06:18:50 +00:00
|
|
|
unsigned csum_type:4;
|
|
|
|
unsigned nr_replicas:4;
|
|
|
|
unsigned nr_replicas_required:4;
|
2023-06-24 23:30:10 +00:00
|
|
|
unsigned watermark:3;
|
2018-02-23 21:26:10 +00:00
|
|
|
unsigned incompressible:1;
|
2023-03-11 22:21:30 +00:00
|
|
|
unsigned stripe_waited:1;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
|
|
|
struct bch_devs_list devs_have;
|
|
|
|
u16 target;
|
|
|
|
u16 nonce;
|
|
|
|
struct bch_io_opts opts;
|
|
|
|
|
2021-03-13 01:30:39 +00:00
|
|
|
u32 subvol;
|
2017-03-17 06:18:50 +00:00
|
|
|
struct bpos pos;
|
|
|
|
struct bversion version;
|
|
|
|
|
|
|
|
/* For BCH_WRITE_DATA_ENCODED: */
|
|
|
|
struct bch_extent_crc_unpacked crc;
|
|
|
|
|
|
|
|
struct write_point_specifier write_point;
|
|
|
|
|
2022-10-31 20:13:05 +00:00
|
|
|
struct write_point *wp;
|
|
|
|
struct list_head wp_list;
|
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
struct disk_reservation res;
|
|
|
|
|
2018-10-06 08:12:42 +00:00
|
|
|
struct open_buckets open_buckets;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2019-10-09 16:50:39 +00:00
|
|
|
u64 new_i_size;
|
|
|
|
s64 i_sectors_delta;
|
2017-03-17 06:18:50 +00:00
|
|
|
|
|
|
|
struct bch_devs_mask failed;
|
|
|
|
|
|
|
|
struct keylist insert_keys;
|
|
|
|
u64 inline_keys[BKEY_EXTENT_U64s_MAX * 2];
|
|
|
|
|
bcachefs: Nocow support
This adds support for nocow mode, where we do writes in-place when
possible. Patch components:
- New boolean filesystem and inode option, nocow: note that when nocow
is enabled, data checksumming and compression are implicitly disabled
- To prevent in-place writes from racing with data moves
(data_update.c) or bucket reuse (i.e. a bucket being reused and
re-allocated while a nocow write is in flight, we have a new locking
mechanism.
Buckets can be locked for either data update or data move, using a
fixed size hash table of two_state_shared locks. We don't have any
chaining, meaning updates and moves to different buckets that hash to
the same lock will wait unnecessarily - we'll want to watch for this
becoming an issue.
- The allocator path also needs to check for in-place writes in flight
to a given bucket before giving it out: thus we add another counter
to bucket_alloc_state so we can track this.
- Fsync now may need to issue cache flushes to block devices instead of
flushing the journal. We add a device bitmask to bch_inode_info,
ei_devs_need_flush, which tracks devices that need to have flushes
issued - note that this will lead to unnecessary flushes when other
codepaths have already issued flushes, we may want to replace this with
a sequence number.
- New nocow write path: look up extents, and if they're writable write
to them - otherwise fall back to the normal COW write path.
XXX: switch to sequence numbers instead of bitmask for devs needing
journal flush
XXX: ei_quota_lock being a mutex means bch2_nocow_write_done() needs to
run in process context - see if we can improve this
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2022-11-02 21:12:00 +00:00
|
|
|
/*
|
|
|
|
* Bitmask of devices that have had nocow writes issued to them since
|
|
|
|
* last flush:
|
|
|
|
*/
|
|
|
|
struct bch_devs_mask *devs_need_flush;
|
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
/* Must be last: */
|
|
|
|
struct bch_write_bio wbio;
|
|
|
|
};
|
|
|
|
|
2023-09-10 22:05:17 +00:00
|
|
|
#endif /* _BCACHEFS_IO_WRITE_TYPES_H */
|