Skip to content

Commit

Permalink
Revert "ANDROID: Incremental fs: Fix filled block count from get fill…
Browse files Browse the repository at this point in the history
…ed blocks"

This reverts commit 29e40c2.

Set incfs back to rvc shipping incfs

Bug: 178509184
Test: incfs_test passes
Signed-off-by: Paul Lawrence <[email protected]>
Change-Id: I4587d44b5baa59a879e8ab42ab65bb70ade086ed
  • Loading branch information
PaulLawrenceGoogle committed Jan 26, 2021
1 parent 0499239 commit 2f9d5f8
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 281 deletions.
69 changes: 36 additions & 33 deletions fs/incfs/data_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,36 @@ static int copy_one_range(struct incfs_filled_range *range, void __user *buffer,
return 0;
}

static int update_file_header_flags(struct data_file *df, u32 bits_to_reset,
u32 bits_to_set)
{
int result;
u32 new_flags;
struct backing_file_context *bfc;

if (!df)
return -EFAULT;
bfc = df->df_backing_file_context;
if (!bfc)
return -EFAULT;

result = mutex_lock_interruptible(&bfc->bc_mutex);
if (result)
return result;

new_flags = (df->df_header_flags & ~bits_to_reset) | bits_to_set;
if (new_flags != df->df_header_flags) {
df->df_header_flags = new_flags;
result = incfs_write_file_header_flags(bfc, new_flags);
}

mutex_unlock(&bfc->bc_mutex);

return result;
}

#define READ_BLOCKMAP_ENTRIES 512
int incfs_get_filled_blocks(struct data_file *df,
struct incfs_file_data *fd,
struct incfs_get_filled_blocks_args *arg)
{
int error = 0;
Expand All @@ -702,17 +729,14 @@ int incfs_get_filled_blocks(struct data_file *df,
int i = READ_BLOCKMAP_ENTRIES - 1;
int entries_read = 0;
struct incfs_blockmap_entry *bme;
int data_blocks_filled = 0;
int hash_blocks_filled = 0;

*size_out = 0;
if (end_index > df->df_total_block_count)
end_index = df->df_total_block_count;
arg->total_blocks_out = df->df_total_block_count;
arg->data_blocks_out = df->df_data_block_count;

if (atomic_read(&df->df_data_blocks_written) ==
df->df_data_block_count) {
if (df->df_header_flags & INCFS_FILE_COMPLETE) {
pr_debug("File marked full, fast get_filled_blocks");
if (arg->start_index > end_index) {
arg->index_out = arg->start_index;
Expand Down Expand Up @@ -765,12 +789,6 @@ int incfs_get_filled_blocks(struct data_file *df,

convert_data_file_block(bme + i, &dfb);

if (is_data_block_present(&dfb))
if (arg->index_out >= df->df_data_block_count)
++hash_blocks_filled;
else
++data_blocks_filled;

if (is_data_block_present(&dfb) == in_range)
continue;

Expand Down Expand Up @@ -800,28 +818,13 @@ int incfs_get_filled_blocks(struct data_file *df,
arg->index_out = range.begin;
}

if (arg->start_index == 0) {
fd->fd_get_block_pos = 0;
fd->fd_filled_data_blocks = 0;
fd->fd_filled_hash_blocks = 0;
}

if (arg->start_index == fd->fd_get_block_pos) {
fd->fd_get_block_pos = arg->index_out + 1;
fd->fd_filled_data_blocks += data_blocks_filled;
fd->fd_filled_hash_blocks += hash_blocks_filled;
}

if (fd->fd_get_block_pos == df->df_total_block_count + 1) {
if (fd->fd_filled_data_blocks >
atomic_read(&df->df_data_blocks_written))
atomic_set(&df->df_data_blocks_written,
fd->fd_filled_data_blocks);

if (fd->fd_filled_hash_blocks >
atomic_read(&df->df_hash_blocks_written))
atomic_set(&df->df_hash_blocks_written,
fd->fd_filled_hash_blocks);
if (!error && in_range && arg->start_index == 0 &&
end_index == df->df_total_block_count &&
*size_out == sizeof(struct incfs_filled_range)) {
int result =
update_file_header_flags(df, 0, INCFS_FILE_COMPLETE);
/* Log failure only, since it's just a failed optimization */
pr_debug("Marked file full with result %d", result);
}

kfree(bme);
Expand Down
19 changes: 1 addition & 18 deletions fs/incfs/data_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ struct mount_info {

/* Number of blocks written since mount */
atomic_t mi_blocks_written;

};

struct data_file_block {
Expand Down Expand Up @@ -288,23 +289,6 @@ struct dentry_info {
struct path backing_path;
};

enum FILL_PERMISSION {
CANT_FILL = 0,
CAN_FILL = 1,
};

struct incfs_file_data {
/* Does this file handle have INCFS_IOC_FILL_BLOCKS permission */
enum FILL_PERMISSION fd_fill_permission;

/* If INCFS_IOC_GET_FILLED_BLOCKS has been called, where are we */
int fd_get_block_pos;

/* And how many filled blocks are there up to that point */
int fd_filled_data_blocks;
int fd_filled_hash_blocks;
};

struct mount_info *incfs_alloc_mount_info(struct super_block *sb,
struct mount_options *options,
struct path *backing_dir_path);
Expand All @@ -329,7 +313,6 @@ ssize_t incfs_read_data_file_block(struct mem_range dst, struct file *f,
struct mem_range tmp);

int incfs_get_filled_blocks(struct data_file *df,
struct incfs_file_data *fd,
struct incfs_get_filled_blocks_args *arg);

int incfs_read_file_signature(struct data_file *df, struct mem_range dst);
Expand Down
9 changes: 9 additions & 0 deletions fs/incfs/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ static int append_md_to_backing_file(struct backing_file_context *bfc,
return result;
}

int incfs_write_file_header_flags(struct backing_file_context *bfc, u32 flags)
{
if (!bfc)
return -EFAULT;

return write_to_bf(bfc, &flags, sizeof(flags),
offsetof(struct incfs_file_header, fh_flags));
}

/*
* Reserve 0-filled space for the blockmap body, and append
* incfs_blockmap metadata record pointing to it.
Expand Down
5 changes: 4 additions & 1 deletion fs/incfs/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ enum incfs_metadata_type {
};

enum incfs_file_header_flags {
INCFS_FILE_COMPLETE = 1 << 0,
INCFS_FILE_MAPPED = 1 << 1,
};

Expand Down Expand Up @@ -253,7 +254,7 @@ struct incfs_status {
__le32 is_hash_blocks_written; /* Number of hash blocks written */

__le32 is_dummy[6]; /* Spare fields */
} __packed;
};

/* State of the backing file. */
struct backing_file_context {
Expand Down Expand Up @@ -329,6 +330,8 @@ int incfs_write_status_to_backing_file(struct backing_file_context *bfc,
u32 data_blocks_written,
u32 hash_blocks_written);

int incfs_write_file_header_flags(struct backing_file_context *bfc, u32 flags);

int incfs_make_empty_backing_file(struct backing_file_context *bfc,
incfs_uuid_t *uuid, u64 file_size);

Expand Down
7 changes: 2 additions & 5 deletions fs/incfs/pseudo_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ static long ioctl_permit_fill(struct file *f, void __user *arg)
struct incfs_permit_fill permit_fill;
long error = 0;
struct file *file = NULL;
struct incfs_file_data *fd;

if (copy_from_user(&permit_fill, usr_permit_fill, sizeof(permit_fill)))
return -EFAULT;
Expand All @@ -293,11 +292,9 @@ static long ioctl_permit_fill(struct file *f, void __user *arg)
goto out;
}

fd = file->private_data;

switch (fd->fd_fill_permission) {
switch ((uintptr_t)file->private_data) {
case CANT_FILL:
fd->fd_fill_permission = CAN_FILL;
file->private_data = (void *)CAN_FILL;
break;

case CAN_FILL:
Expand Down
45 changes: 11 additions & 34 deletions fs/incfs/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ static long ioctl_fill_blocks(struct file *f, void __user *arg)
struct incfs_fill_blocks fill_blocks;
struct incfs_fill_block __user *usr_fill_block_array;
struct data_file *df = get_incfs_data_file(f);
struct incfs_file_data *fd = f->private_data;
const ssize_t data_buf_size = 2 * INCFS_DATA_FILE_BLOCK_SIZE;
u8 *data_buf = NULL;
ssize_t error = 0;
Expand All @@ -534,7 +533,7 @@ static long ioctl_fill_blocks(struct file *f, void __user *arg)
if (!df)
return -EBADF;

if (!fd || fd->fd_fill_permission != CAN_FILL)
if ((uintptr_t)f->private_data != CAN_FILL)
return -EPERM;

if (copy_from_user(&fill_blocks, usr_fill_blocks, sizeof(fill_blocks)))
Expand Down Expand Up @@ -643,19 +642,18 @@ static long ioctl_get_filled_blocks(struct file *f, void __user *arg)
struct incfs_get_filled_blocks_args __user *args_usr_ptr = arg;
struct incfs_get_filled_blocks_args args = {};
struct data_file *df = get_incfs_data_file(f);
struct incfs_file_data *fd = f->private_data;
int error;

if (!df || !fd)
if (!df)
return -EINVAL;

if (fd->fd_fill_permission != CAN_FILL)
if ((uintptr_t)f->private_data != CAN_FILL)
return -EPERM;

if (copy_from_user(&args, args_usr_ptr, sizeof(args)) > 0)
return -EINVAL;

error = incfs_get_filled_blocks(df, fd, &args);
error = incfs_get_filled_blocks(df, &args);

if (copy_to_user(args_usr_ptr, &args, sizeof(args)))
return -EFAULT;
Expand Down Expand Up @@ -1117,8 +1115,6 @@ static int file_open(struct inode *inode, struct file *file)
int flags = O_NOATIME | O_LARGEFILE |
(S_ISDIR(inode->i_mode) ? O_RDONLY : O_RDWR);

WARN_ON(file->private_data);

if (!mi)
return -EBADF;

Expand All @@ -1136,20 +1132,8 @@ static int file_open(struct inode *inode, struct file *file)
}

if (S_ISREG(inode->i_mode)) {
struct incfs_file_data *fd = kzalloc(sizeof(*fd), GFP_NOFS);

if (!fd) {
err = -ENOMEM;
goto out;
}

*fd = (struct incfs_file_data) {
.fd_fill_permission = CANT_FILL,
};
file->private_data = fd;

err = make_inode_ready_for_data_ops(mi, inode, backing_file);

file->private_data = (void *)CANT_FILL;
} else if (S_ISDIR(inode->i_mode)) {
struct dir_file *dir = NULL;

Expand All @@ -1162,17 +1146,9 @@ static int file_open(struct inode *inode, struct file *file)
err = -EBADF;

out:
if (err) {
pr_debug("name:%s err: %d\n",
file->f_path.dentry->d_name.name, err);
if (S_ISREG(inode->i_mode))
kfree(file->private_data);
else if (S_ISDIR(inode->i_mode))
incfs_free_dir_file(file->private_data);

file->private_data = NULL;
}

if (err)
pr_debug("incfs: %s name:%s err: %d\n", __func__,
file->f_path.dentry->d_name.name, err);
if (backing_file)
fput(backing_file);
return err;
Expand All @@ -1181,8 +1157,9 @@ static int file_open(struct inode *inode, struct file *file)
static int file_release(struct inode *inode, struct file *file)
{
if (S_ISREG(inode->i_mode)) {
kfree(file->private_data);
file->private_data = NULL;
/* Do nothing.
* data_file is released only by inode eviction.
*/
} else if (S_ISDIR(inode->i_mode)) {
struct dir_file *dir = get_incfs_dir_file(file);

Expand Down
5 changes: 5 additions & 0 deletions fs/incfs/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#ifndef _INCFS_VFS_H
#define _INCFS_VFS_H

enum FILL_PERMISSION {
CANT_FILL = 0,
CAN_FILL = 1,
};

extern const struct file_operations incfs_file_ops;
extern const struct inode_operations incfs_file_inode_ops;

Expand Down
Loading

0 comments on commit 2f9d5f8

Please sign in to comment.