[Pkg-samba-maint] Bug#798532: samba: wrong file block size if 'strict allocate' is enabled for samba

Andrew Bartlett abartlet at samba.org
Thu Sep 24 08:33:45 UTC 2015


On Thu, 2015-09-10 at 18:52 +0800, nelson wrote:
> Package: samba
> Version: 2:4.1.17+dfsg-2
> Severity: normal
> Tags: patch
> 
> Dear Maintainer,
> 
> 
>    When I add 'strict  allocate = yes' to /etc/samba/smb.conf, then
> copy file via samba, the block usage of the file will be greater than
> its real size. For example, copy a 8KB file via samba, you will find
> the block usage is 1MB. But if remove 'strict allocate = yes' from
> /etc/samba/smb.conf and do the same test, file size is correct(of
> cause, 4KB roundup for EXT4).
> 
>   # hdparm --fibmap 8k.bin 
> 
>   8k.bin:
>    filesystem blocksize 4096, begins at LBA 195311616; assuming 512
> byte sectors.
>    byte_offset  begin_LBA    end_LBA    sectors
>              0  202758144  202758159         16
>           8192  202758160  202760191       2032
> 
>   # du -sh 8k.bin 
>   1.0M    8k.bin
> 
>   # ls -l 8k.bin 
>   -rwx------ 1 nelson nelson 8192 Aug 21 10:58 8k.bin
> 
>   By tracing samba daemon, it shows that these functions be called
> (pseudo-code) : 
> 
>   open(8k.bin) 
>   ...
>   fallocate(8k.bin, 1, 0, 1048576)
>   ...
>   fallocate(8k.bin, 0, 0, 8192)  // -> here should be
> truncate(8k.bin, 8192)
>   ...
>   write()
>   ...
>   close(8k.bin).
> 
>   Here is my patch for this bug. Please check, thanks.
> 
> *** vfs_default.c.ori   2015-09-10 17:55:09.172488319 +0800
> --- vfs_default.c       2015-09-10 17:57:08.104484805 +0800
> ***************
> *** 1807,1813 ****
>                 return 0;
>   
>         /* Shrink - just ftruncate. */
> !       if (pst->st_ex_size > len)
>                 return ftruncate(fsp->fh->fd, len);
>   
>         space_to_write = len - pst->st_ex_size;
> --- 1807,1813 ----
>                 return 0;
>   
>         /* Shrink - just ftruncate. */
> !       if (pst->st_ex_blocks * 512 > len)
>                 return ftruncate(fsp->fh->fd, len);
>   
>         space_to_write = len - pst->st_ex_size;
> 
> 

This kind of change needs to be submitted via samba-technical or
Samba's github page.  Also, the test should be for both cases, not just
changing one for the other.  Finally, is the 512 in this really
constant (it may need to be another variable, from the file system)?

Thanks,

Andrew Bartlett

-- 
Andrew Bartlett                       http://samba.org/~abartlet/
Authentication Developer, Samba Team  http://samba.org
Samba Developer, Catalyst IT          http://catalyst.net.nz/services/samba



More information about the Pkg-samba-maint mailing list