On Fri, 23 Feb 2024 11:41:58 -0600
John Groves <j...@groves.net> wrote:

> This commit introduces the famfs file_operations. We call
> thp_get_unmapped_area() to force PMD page alignment. Our read and
> write handlers (famfs_dax_read_iter() and famfs_dax_write_iter())
> call dax_iomap_rw() to do the work.
> 
> famfs_file_invalid() checks for various ways a famfs file can be
> in an invalid state so we can fail I/O or fault resolution in those
> cases. Those cases include the following:
> 
> * No famfs metadata
> * file i_size does not match the originally allocated size
> * file is not flagged as DAX
> * errors were detected previously on the file
> 
> An invalid file can often be fixed by replaying the log, or by
> umount/mount/log replay - all of which are user space operations.
> 
> Signed-off-by: John Groves <j...@groves.net>
> ---
>  fs/famfs/famfs_file.c | 136 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 136 insertions(+)
> 
> diff --git a/fs/famfs/famfs_file.c b/fs/famfs/famfs_file.c
> index fc667d5f7be8..5228e9de1e3b 100644
> --- a/fs/famfs/famfs_file.c
> +++ b/fs/famfs/famfs_file.c
> @@ -19,6 +19,142 @@
>  #include <uapi/linux/famfs_ioctl.h>
>  #include "famfs_internal.h"
>  
> +/*********************************************************************
> + * file_operations
> + */
> +
> +/* Reject I/O to files that aren't in a valid state */
> +static ssize_t
> +famfs_file_invalid(struct inode *inode)
> +{
> +     size_t i_size       = i_size_read(inode);
> +     struct famfs_file_meta *meta = inode->i_private;
> +
> +     if (!meta) {
> +             pr_err("%s: un-initialized famfs file\n", __func__);
> +             return -EIO;
> +     }
> +     if (i_size != meta->file_size) {
> +             pr_err("%s: something changed the size from  %ld to %ld\n",
> +                    __func__, meta->file_size, i_size);
> +             meta->error = 1;
> +             return -ENXIO;
> +     }
> +     if (!IS_DAX(inode)) {
> +             pr_err("%s: inode %llx IS_DAX is false\n", __func__, 
> (u64)inode);
> +             meta->error = 1;
> +             return -ENXIO;
> +     }
> +     if (meta->error) {
> +             pr_err("%s: previously detected metadata errors\n", __func__);
> +             meta->error = 1;

Already set?  If treating it as only a boolean, maybe make it one?

> +             return -EIO;
> +     }
> +     return 0;
> +}


Reply via email to