^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2019 Google LLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #ifndef _INCFS_DATA_MGMT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #define _INCFS_DATA_MGMT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/zstd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <crypto/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <uapi/linux/incrementalfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "pseudo_files.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define SEGMENTS_PER_FILE 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) enum LOG_RECORD_TYPE {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) FULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) SAME_FILE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) SAME_FILE_CLOSE_BLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) SAME_FILE_CLOSE_BLOCK_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) SAME_FILE_NEXT_BLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) SAME_FILE_NEXT_BLOCK_SHORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct full_record {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) enum LOG_RECORD_TYPE type : 3; /* FULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u32 block_index : 29;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) incfs_uuid_t file_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u64 absolute_ts_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) uid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) } __packed; /* 32 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct same_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) enum LOG_RECORD_TYPE type : 3; /* SAME_FILE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u32 block_index : 29;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) uid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u16 relative_ts_us; /* max 2^16 us ~= 64 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) } __packed; /* 10 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct same_file_close_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) enum LOG_RECORD_TYPE type : 3; /* SAME_FILE_CLOSE_BLOCK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u16 relative_ts_us : 13; /* max 2^13 us ~= 8 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) s16 block_index_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) } __packed; /* 4 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct same_file_close_block_short {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) enum LOG_RECORD_TYPE type : 3; /* SAME_FILE_CLOSE_BLOCK_SHORT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u8 relative_ts_tens_us : 5; /* max 2^5*10 us ~= 320 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) s8 block_index_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) } __packed; /* 2 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct same_file_next_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) enum LOG_RECORD_TYPE type : 3; /* SAME_FILE_NEXT_BLOCK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u16 relative_ts_us : 13; /* max 2^13 us ~= 8 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) } __packed; /* 2 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct same_file_next_block_short {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) enum LOG_RECORD_TYPE type : 3; /* SAME_FILE_NEXT_BLOCK_SHORT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 relative_ts_tens_us : 5; /* max 2^5*10 us ~= 320 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) } __packed; /* 1 byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) union log_record {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct full_record full_record;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct same_file same_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct same_file_close_block same_file_close_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct same_file_close_block_short same_file_close_block_short;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct same_file_next_block same_file_next_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct same_file_next_block_short same_file_next_block_short;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct read_log_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* Log buffer generation id, incremented on configuration changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u32 generation_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Offset in rl_ring_buf to write into. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 next_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* Current number of writer passes over rl_ring_buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u32 current_pass_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Current full_record to diff against */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct full_record base_record;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* Current record number counting from configuration change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u64 current_record_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* A ring buffer to save records about data blocks which were recently read. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct read_log {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void *rl_ring_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int rl_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct read_log_state rl_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct read_log_state rl_tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* A lock to protect the above fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) spinlock_t rl_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* A queue of waiters who want to be notified about reads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) wait_queue_head_t ml_notif_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* A work item to wake up those waiters without slowing down readers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct delayed_work ml_wakeup_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct mount_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int read_timeout_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned int readahead_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) unsigned int read_log_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) unsigned int read_log_wakeup_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) bool report_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) char *sysfs_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct mount_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct super_block *mi_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct path mi_backing_dir_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct dentry *mi_index_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* For stacking mounts, if true, this indicates if the index dir needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * to be freed for this SB otherwise it was created by lower level SB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) bool mi_index_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct dentry *mi_incomplete_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* For stacking mounts, if true, this indicates if the incomplete dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * needs to be freed for this SB. Similar to mi_index_free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) bool mi_incomplete_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) const struct cred *mi_owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct mount_options mi_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* This mutex is to be taken before create, rename, delete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct mutex mi_dir_struct_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * A queue of waiters who want to be notified about new pending reads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) wait_queue_head_t mi_pending_reads_notif_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * Protects - RCU safe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * - reads_list_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * - mi_pending_reads_count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * - mi_last_pending_read_number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * - data_file_segment.reads_list_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) spinlock_t pending_read_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* List of active pending_read objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct list_head mi_reads_list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Total number of items in reads_list_head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int mi_pending_reads_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Last serial number that was assigned to a pending read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * 0 means no pending reads have been seen yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int mi_last_pending_read_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* Temporary buffer for read logger. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct read_log mi_log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* SELinux needs special xattrs on our pseudo files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct mem_range pseudo_file_xattr[PSEUDO_FILE_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* A queue of waiters who want to be notified about blocks_written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) wait_queue_head_t mi_blocks_written_notif_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Number of blocks written since mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) atomic_t mi_blocks_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Per UID read timeouts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) spinlock_t mi_per_uid_read_timeouts_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct incfs_per_uid_read_timeouts *mi_per_uid_read_timeouts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int mi_per_uid_read_timeouts_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* zstd workspace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct mutex mi_zstd_workspace_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) void *mi_zstd_workspace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ZSTD_DStream *mi_zstd_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct delayed_work mi_zstd_cleanup_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* sysfs node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct incfs_sysfs_node *mi_sysfs_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Last error information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct mutex mi_le_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) incfs_uuid_t mi_le_file_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) u64 mi_le_time_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) u32 mi_le_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) u32 mi_le_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) uid_t mi_le_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Number of reads timed out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) u32 mi_reads_failed_timed_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Number of reads failed because hash verification failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) u32 mi_reads_failed_hash_verification;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Number of reads failed for another reason */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) u32 mi_reads_failed_other;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Number of reads delayed because page had to be fetched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) u32 mi_reads_delayed_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Total time waiting for pages to be fetched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) u64 mi_reads_delayed_pending_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * Number of reads delayed because of per-uid min_time_us or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * min_pending_time_us settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) u32 mi_reads_delayed_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* Total time waiting because of per-uid min_time_us or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * min_pending_time_us settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Note that if a read is initially delayed because we have to wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * the page, then further delayed because of min_pending_time_us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * setting, this counter gets incremented by only the further delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) u64 mi_reads_delayed_min_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct data_file_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) loff_t db_backing_file_data_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) size_t db_stored_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) enum incfs_compression_alg db_comp_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct pending_read {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) incfs_uuid_t file_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) s64 timestamp_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) atomic_t done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int block_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) int serial_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) uid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct list_head mi_reads_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct list_head segment_reads_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct data_file_segment {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) wait_queue_head_t new_data_arrival_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* Protects reads and writes from the blockmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct rw_semaphore rwsem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* List of active pending_read objects belonging to this segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* Protected by mount_info.pending_reads_mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct list_head reads_list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * Extra info associated with a file. Just a few bytes set by a user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct file_attr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) loff_t fa_value_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) size_t fa_value_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) u32 fa_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct data_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct backing_file_context *df_backing_file_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct mount_info *df_mount_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) incfs_uuid_t df_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * Array of segments used to reduce lock contention for the file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * Segment is chosen for a block depends on the block's index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct data_file_segment df_segments[SEGMENTS_PER_FILE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* Base offset of the first metadata record. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) loff_t df_metadata_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* Base offset of the block map. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) loff_t df_blockmap_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* File size in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) loff_t df_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* File header flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) u32 df_header_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* File size in DATA_FILE_BLOCK_SIZE blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) int df_data_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* Total number of blocks, data + hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) int df_total_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* For mapped files, the offset into the actual file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) loff_t df_mapped_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* Number of data blocks written to file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) atomic_t df_data_blocks_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* Number of data blocks in the status block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) u32 df_initial_data_blocks_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* Number of hash blocks written to file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) atomic_t df_hash_blocks_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* Number of hash blocks in the status block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) u32 df_initial_hash_blocks_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /* Offset to status metadata header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) loff_t df_status_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * Mutex acquired while enabling verity. Note that df_hash_tree is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * by enable verity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * The backing file mutex bc_mutex may be taken while this mutex is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct mutex df_enable_verity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * Set either at construction time or during enabling verity. In the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * latter case, set via smp_store_release, so use smp_load_acquire to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * read it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct mtree *df_hash_tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Guaranteed set if df_hash_tree is set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct incfs_df_signature *df_signature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * The verity file digest, set when verity is enabled and the file has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * been opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct mem_range df_verity_file_digest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct incfs_df_verity_signature *df_verity_signature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct dir_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct mount_info *mount_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct file *backing_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct inode_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct mount_info *n_mount_info; /* A mount, this file belongs to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct inode *n_backing_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct data_file *n_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct inode n_vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct dentry_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct path backing_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) enum FILL_PERMISSION {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) CANT_FILL = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) CAN_FILL = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct incfs_file_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /* Does this file handle have INCFS_IOC_FILL_BLOCKS permission */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) enum FILL_PERMISSION fd_fill_permission;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* If INCFS_IOC_GET_FILLED_BLOCKS has been called, where are we */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int fd_get_block_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* And how many filled blocks are there up to that point */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int fd_filled_data_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) int fd_filled_hash_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct mount_info *incfs_alloc_mount_info(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct mount_options *options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct path *backing_dir_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int incfs_realloc_mount_info(struct mount_info *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct mount_options *options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) void incfs_free_mount_info(struct mount_info *mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) char *file_id_to_str(incfs_uuid_t id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct dentry *incfs_lookup_dentry(struct dentry *parent, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct data_file *incfs_open_data_file(struct mount_info *mi, struct file *bf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) void incfs_free_data_file(struct data_file *df);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct dir_file *incfs_open_dir_file(struct mount_info *mi, struct file *bf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) void incfs_free_dir_file(struct dir_file *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct incfs_read_data_file_timeouts {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) u32 min_time_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) u32 min_pending_time_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) u32 max_pending_time_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ssize_t incfs_read_data_file_block(struct mem_range dst, struct file *f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int index, struct mem_range tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct incfs_read_data_file_timeouts *timeouts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) ssize_t incfs_read_merkle_tree_blocks(struct mem_range dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct data_file *df, size_t offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) int incfs_get_filled_blocks(struct data_file *df,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct incfs_file_data *fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct incfs_get_filled_blocks_args *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int incfs_read_file_signature(struct data_file *df, struct mem_range dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) int incfs_process_new_data_block(struct data_file *df,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct incfs_fill_block *block, u8 *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int incfs_process_new_hash_block(struct data_file *df,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct incfs_fill_block *block, u8 *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) bool incfs_fresh_pending_reads_exist(struct mount_info *mi, int last_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * Collects pending reads and saves them into the array (reads/reads_size).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * Only reads with serial_number > sn_lowerbound are reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * Returns how many reads were saved into the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) int incfs_collect_pending_reads(struct mount_info *mi, int sn_lowerbound,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct incfs_pending_read_info *reads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct incfs_pending_read_info2 *reads2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) int reads_size, int *new_max_sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) int incfs_collect_logged_reads(struct mount_info *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct read_log_state *start_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct incfs_pending_read_info *reads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct incfs_pending_read_info2 *reads2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int reads_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct read_log_state incfs_get_log_state(struct mount_info *mi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) int incfs_get_uncollected_logs_count(struct mount_info *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) const struct read_log_state *state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static inline struct inode_info *get_incfs_node(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (inode->i_sb->s_magic != INCFS_MAGIC_NUMBER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /* This inode doesn't belong to us. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) pr_warn_once("incfs: %s on an alien inode.", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return container_of(inode, struct inode_info, n_vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static inline struct data_file *get_incfs_data_file(struct file *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct inode_info *node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (!f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (!S_ISREG(f->f_inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) node = get_incfs_node(f->f_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return node->n_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static inline struct dir_file *get_incfs_dir_file(struct file *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (!f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (!S_ISDIR(f->f_inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return (struct dir_file *)f->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * Make sure that inode_info.n_file is initialized and inode can be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * for reading and writing data from/to the backing file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) int make_inode_ready_for_data_ops(struct mount_info *mi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct file *backing_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static inline struct dentry_info *get_incfs_dentry(const struct dentry *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (!d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return (struct dentry_info *)d->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static inline void get_incfs_backing_path(const struct dentry *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) struct dentry_info *di = get_incfs_dentry(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (!di) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) *path = (struct path) {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) *path = di->backing_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) path_get(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static inline int get_blocks_count_for_size(u64 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) return 1 + (size - 1) / INCFS_DATA_FILE_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) #endif /* _INCFS_DATA_MGMT_H */