From 2664a43d88d91eb09f212cb26e111656a4acee49 Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Wed, 29 Jan 2020 12:47:53 -0800 Subject: [PATCH] ANDROID: Incremental fs: Fix initialization, use of bitfields Test: incfs_test passes Signed-off-by: Paul Lawrence Bug: 133435829 Change-Id: I824286b77f665d2409c5e88930057a97da82ce82 --- fs/incfs/data_mgmt.c | 17 ++++++++------- fs/incfs/data_mgmt.h | 34 ++++++++++++++++++++++++++---- include/uapi/linux/incrementalfs.h | 10 +++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/fs/incfs/data_mgmt.c b/fs/incfs/data_mgmt.c index 109329e0a180..4698f14bbdf7 100644 --- a/fs/incfs/data_mgmt.c +++ b/fs/incfs/data_mgmt.c @@ -85,11 +85,11 @@ static void data_file_segment_destroy(struct data_file_segment *segment) struct data_file *incfs_open_data_file(struct mount_info *mi, struct file *bf) { - struct data_file *df = NULL; - struct backing_file_context *bfc = NULL; + struct data_file *df; + struct backing_file_context *bfc; int md_records; u64 size; - int error = 0; + int error; int i; if (!bf || !mi) @@ -160,7 +160,7 @@ int make_inode_ready_for_data_ops(struct mount_info *mi, struct file *backing_file) { struct inode_info *node = get_incfs_node(inode); - struct data_file *df = NULL; + struct data_file *df; int err = 0; inode_lock(inode); @@ -181,7 +181,7 @@ int make_inode_ready_for_data_ops(struct mount_info *mi, struct dir_file *incfs_open_dir_file(struct mount_info *mi, struct file *bf) { - struct dir_file *dir = NULL; + struct dir_file *dir; if (!S_ISDIR(bf->f_inode->i_mode)) return ERR_PTR(-EBADF); @@ -222,11 +222,12 @@ static void log_block_read(struct mount_info *mi, incfs_uuid_t *id, s64 now_us = ktime_to_us(ktime_get()); struct read_log_record record = { .file_id = *id, - .block_index = block_index, - .timed_out = timed_out, .timestamp_us = now_us }; + set_block_index(&record, block_index); + set_timed_out(&record, timed_out); + if (log->rl_size == 0) return; @@ -1062,7 +1063,7 @@ static void fill_pending_read_from_log_record( struct read_log_state *state, u64 log_size) { dest->file_id = src->file_id; - dest->block_index = src->block_index; + dest->block_index = get_block_index(src); dest->serial_number = state->current_pass_no * log_size + state->next_index; dest->timestamp_us = src->timestamp_us; diff --git a/fs/incfs/data_mgmt.h b/fs/incfs/data_mgmt.h index 82ccab3be4bb..6722cef1608c 100644 --- a/fs/incfs/data_mgmt.h +++ b/fs/incfs/data_mgmt.h @@ -21,15 +21,41 @@ #define SEGMENTS_PER_FILE 3 struct read_log_record { - u32 block_index : 31; - - u32 timed_out : 1; + u32 bitfield; u64 timestamp_us; incfs_uuid_t file_id; } __packed; +#define RLR_BLOCK_INDEX_MASK 0x7fff +#define RLR_TIMED_OUT_MASK 0x8000 + +static inline u32 get_block_index(const struct read_log_record *rlr) +{ + return rlr->bitfield & RLR_BLOCK_INDEX_MASK; +} + +static inline void set_block_index(struct read_log_record *rlr, + u32 block_index) +{ + rlr->bitfield = (rlr->bitfield & ~RLR_BLOCK_INDEX_MASK) + | (block_index & RLR_BLOCK_INDEX_MASK); +} + +static inline bool get_timed_out(const struct read_log_record *rlr) +{ + return (rlr->bitfield & RLR_TIMED_OUT_MASK) == RLR_TIMED_OUT_MASK; +} + +static inline void set_timed_out(struct read_log_record *rlr, bool timed_out) +{ + if (timed_out) + rlr->bitfield |= RLR_TIMED_OUT_MASK; + else + rlr->bitfield &= ~RLR_TIMED_OUT_MASK; +} + struct read_log_state { /* Next slot in rl_ring_buf to write to. */ u32 next_index; @@ -271,7 +297,7 @@ static inline struct inode_info *get_incfs_node(struct inode *inode) static inline struct data_file *get_incfs_data_file(struct file *f) { - struct inode_info *node = NULL; + struct inode_info *node; if (!f) return NULL; diff --git a/include/uapi/linux/incrementalfs.h b/include/uapi/linux/incrementalfs.h index b257b9f0ec3f..787049031cca 100644 --- a/include/uapi/linux/incrementalfs.h +++ b/include/uapi/linux/incrementalfs.h @@ -107,10 +107,13 @@ struct incfs_new_data_block { /* Values from enum incfs_block_flags */ __u8 flags; + /* Reserved - must be 0 */ __u16 reserved1; + /* Reserved - must be 0 */ __u32 reserved2; + /* Reserved - must be 0 */ __aligned_u64 reserved3; }; @@ -140,6 +143,7 @@ struct incfs_file_signature_info { /* Size of additional data. */ __u32 additional_data_size; + /* Reserved - must be 0 */ __u32 reserved1; /* @@ -153,6 +157,7 @@ struct incfs_file_signature_info { /* Size of pkcs7 signature DER blob */ __u32 signature_size; + /* Reserved - must be 0 */ __u32 reserved2; /* Value from incfs_hash_tree_algorithm */ @@ -176,8 +181,10 @@ struct incfs_new_file_args { */ __u16 mode; + /* Reserved - must be 0 */ __u16 reserved1; + /* Reserved - must be 0 */ __u32 reserved2; /* @@ -210,13 +217,16 @@ struct incfs_new_file_args { */ __u32 file_attr_len; + /* Reserved - must be 0 */ __u32 reserved4; /* struct incfs_file_signature_info *signature_info; */ __aligned_u64 signature_info; + /* Reserved - must be 0 */ __aligned_u64 reserved5; + /* Reserved - must be 0 */ __aligned_u64 reserved6; };