Server-side copy with sendfile system call

Teng-Feng Yang shinrairis at gmail.com
Wed May 14 21:39:26 MDT 2014


Hi David,

2014-05-12 17:04 GMT+08:00 David Disseldorp <ddiss at suse.de>:
> On Mon, 12 May 2014 16:18:11 +0800, Teng-Feng Yang wrote:
>
>> I recently noticed that samba now supports server-side copy feature.
>> For BTRFS, the btrfs VFS module will override the copy_chunk_send/recv
>> to utilize the copy_range ioctl to improve the copy performance
>> further. For other filesystem such as ext4, it will fallback to
>> default copy_chunk behavior which pread the file data and pwrite them
>> to the copy destination.
>>
>> This makes me wonder if we can replace the read-then-write procedure
>> with sendfile system call which claims to outperform the file copy in
>> userspace.
>
> Yes...
>
> 1347 static struct tevent_req *vfswrap_copy_chunk_send(struct vfs_handle_struct *handle,
> ...
> 1387         /* could use 2.6.33+ sendfile here to do this in kernel */

Sorry, I totally miss this line

>
> We most certainly could, with appropriate sendfile support checks in
> place of course. One thing to watch-out for would be sendfile when
> out_fd == in_fd. The protocol allows for overlapping ranges in
> copy-chunk requests.
>
> Cheers, David

Thanks for the tips.
I write a small program to test sendfile, and it turns out that
sendfile will do nothing when out_fd == in_fd.
Does this mean that we should fallback to read-then-write procedure to
deal with this condition?

Best Regards,
Dennis


More information about the samba-technical mailing list