[PATCH RFC 6/8] fs: sandboxfs: add sandbox_fs_get_blocksize()

Qu Wenruo wqu at suse.com
Thu Jun 30 12:12:21 CEST 2022



On 2022/6/30 18:06, Simon Glass wrote:
> On Tue, 28 Jun 2022 at 01:28, Qu Wenruo <wqu at suse.com> wrote:
>>
>> This is to make sandboxfs to report blocksize it supports for
>> _fs_read() to handle unaligned read.
>>
>> Unlike all other fses, sandboxfs can handle unaligned read/write without
>> any problem since it's calling read()/write(), which doesn't bother the
>> blocksize at all.
>>
>> This change is mostly to make testing of _fs_read() much easier.
>>
>> Cc: Simon Glass <sjg at chromium.org>
>> Signed-off-by: Qu Wenruo <wqu at suse.com>
>> ---
>>   arch/sandbox/cpu/os.c  | 11 +++++++++++
>>   fs/fs.c                |  2 +-
>>   fs/sandbox/sandboxfs.c | 14 ++++++++++++++
>>   include/os.h           |  8 ++++++++
>>   include/sandboxfs.h    |  1 +
>>   5 files changed, 35 insertions(+), 1 deletion(-)
> 
> Reviewed-by: Simon Glass <sjg at chromium.org>
> 
> with a comment as requested below
> 
>>
>> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
>> index 5ea54179176c..6c29f29bdd9b 100644
>> --- a/arch/sandbox/cpu/os.c
>> +++ b/arch/sandbox/cpu/os.c
>> @@ -46,6 +46,17 @@ ssize_t os_read(int fd, void *buf, size_t count)
>>          return read(fd, buf, count);
>>   }
>>
>> +ssize_t os_get_blocksize(int fd)
>> +{
>> +       struct stat stat = {0};
>> +       int ret;
>> +
>> +       ret = fstat(fd, &stat);
>> +       if (ret < 0)
>> +               return -errno;
>> +       return stat.st_blksize;
>> +}
>> +
>>   ssize_t os_write(int fd, const void *buf, size_t count)
>>   {
>>          return write(fd, buf, count);
>> diff --git a/fs/fs.c b/fs/fs.c
>> index 7e4ead9b790b..337d5711c28c 100644
>> --- a/fs/fs.c
>> +++ b/fs/fs.c
>> @@ -261,7 +261,7 @@ static struct fstype_info fstypes[] = {
>>                  .exists = sandbox_fs_exists,
>>                  .size = sandbox_fs_size,
>>                  .read = fs_read_sandbox,
>> -               .get_blocksize = fs_get_blocksize_unsupported,
>> +               .get_blocksize = sandbox_fs_get_blocksize,
>>                  .write = fs_write_sandbox,
>>                  .uuid = fs_uuid_unsupported,
>>                  .opendir = fs_opendir_unsupported,
>> diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c
>> index 4ae41d5b4db1..130fee088621 100644
>> --- a/fs/sandbox/sandboxfs.c
>> +++ b/fs/sandbox/sandboxfs.c
>> @@ -55,6 +55,20 @@ int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer,
>>          return ret;
>>   }
>>
>> +int sandbox_fs_get_blocksize(const char *filename)
>> +{
>> +       int fd;
>> +       int ret;
>> +
>> +       fd = os_open(filename, OS_O_RDONLY);
>> +       if (fd < 0)
>> +               return fd;
>> +
>> +       ret = os_get_blocksize(fd);
>> +       os_close(fd);
>> +       return ret;
>> +}
>> +
>>   int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
>>                          loff_t towrite, loff_t *actwrite)
>>   {
>> diff --git a/include/os.h b/include/os.h
>> index 10e198cf503e..a864d9ca39b2 100644
>> --- a/include/os.h
>> +++ b/include/os.h
>> @@ -26,6 +26,14 @@ struct sandbox_state;
>>    */
>>   ssize_t os_read(int fd, void *buf, size_t count);
>>
>> +/**
>> + * Get the optimial blocksize through stat() call.
>> + *
>> + * @fd:                File descriptor as returned by os_open()
>> + * Return:     >=0 for the blocksize. <0 for error.
>> + */
>> +ssize_t os_get_blocksize(int fd);
>> +
>>   /**
>>    * Access to the OS write() system call
>>    *
>> diff --git a/include/sandboxfs.h b/include/sandboxfs.h
>> index 783dd5c88a73..6937068f7b82 100644
>> --- a/include/sandboxfs.h
>> +++ b/include/sandboxfs.h
>> @@ -32,6 +32,7 @@ void sandbox_fs_close(void);
>>   int sandbox_fs_ls(const char *dirname);
>>   int sandbox_fs_exists(const char *filename);
>>   int sandbox_fs_size(const char *filename, loff_t *size);
>> +int sandbox_fs_get_blocksize(const char *filename);
> 
> Please add a full comment.

This is already removed in the formal version:
https://patchwork.kernel.org/project/linux-btrfs/list/?series=654990

As sandbox is just calling host OS read() to handle IO, thus it doesn't 
need to bother the alignment at all.

Thanks,
Qu

> 
>>   int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len,
>>                      loff_t *actread);
>>   int fs_write_sandbox(const char *filename, void *buf, loff_t offset,
>> --
>> 2.36.1
>>
> 
> Regards,
> Simon


More information about the U-Boot mailing list