Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

remove same file copying rage limitation

chrislu63fbf281c764
diff --git a/weed/mount/weedfs_file_copy_range.go b/weed/mount/weedfs_file_copy_range.go
index c85d5f9c4f..0620b7dabc 100644
--- a/weed/mount/weedfs_file_copy_range.go
+++ b/weed/mount/weedfs_file_copy_range.go
@@ -65,35 +65,15 @@ func (wfs *WFS) CopyFileRange(cancel <-chan struct{}, in *fuse.CopyFileRangeIn)
return 0, fuse.EISDIR
}
- // cannot copy data to an overlapping range of the same file
- offInEnd := in.OffIn + in.Len - 1
- offOutEnd := in.OffOut + in.Len - 1
-
- if fhIn.inode == fhOut.inode && in.OffIn <= offOutEnd && offInEnd >= in.OffOut {
- return 0, fuse.EINVAL
- }
-
glog.V(4).Infof(
- "CopyFileRange %s fhIn %d -> %s fhOut %d, %d:%d -> %d:%d",
+ "CopyFileRange %s fhIn %d -> %s fhOut %d, [%d,%d) -> [%d,%d)",
fhIn.FullPath(), fhIn.fh,
fhOut.FullPath(), fhOut.fh,
- in.OffIn, offInEnd,
- in.OffOut, offOutEnd,
+ in.OffIn, in.OffIn+in.Len,
+ in.OffOut, in.OffOut+in.Len,
)
- // read data from source file
- fhIn.lockForRead(int64(in.OffIn), int(in.Len))
- defer fhIn.unlockForRead(int64(in.OffIn), int(in.Len))
-
- data := make([]byte, int(in.Len))
- totalRead, err := fhIn.readFromChunks(data, int64(in.OffIn))
- if err == nil || err == io.EOF {
- maxStop := fhIn.readFromDirtyPages(data, int64(in.OffIn))
- totalRead = max(maxStop-int64(in.OffIn), totalRead)
- }
- if err == io.EOF {
- err = nil
- }
+ data, totalRead, err := readDataByFileHandle(fhIn, in)
if err != nil {
glog.Warningf("file handle read %s %d: %v", fhIn.FullPath(), totalRead, err)
return 0, fuse.EIO
@@ -106,7 +86,7 @@ func (wfs *WFS) CopyFileRange(cancel <-chan struct{}, in *fuse.CopyFileRangeIn)
// put data at the specified offset in target file
fhOut.dirtyPages.writerPattern.MonitorWriteAt(int64(in.OffOut), int(in.Len))
fhOut.entry.Content = nil
- fhOut.dirtyPages.AddPage(int64(in.OffOut), data, fhOut.dirtyPages.writerPattern.IsSequentialMode())
+ fhOut.dirtyPages.AddPage(int64(in.OffOut), data[:totalRead], fhOut.dirtyPages.writerPattern.IsSequentialMode())
fhOut.entry.Attributes.FileSize = uint64(max(int64(in.OffOut)+totalRead, int64(fhOut.entry.Attributes.FileSize)))
fhOut.dirtyMetadata = true
written = uint32(totalRead)
@@ -118,3 +98,20 @@ func (wfs *WFS) CopyFileRange(cancel <-chan struct{}, in *fuse.CopyFileRangeIn)
return written, fuse.OK
}
+
+func readDataByFileHandle(fhIn *FileHandle, in *fuse.CopyFileRangeIn) ([]byte, int64, error) {
+ // read data from source file
+ fhIn.lockForRead(int64(in.OffIn), int(in.Len))
+ defer fhIn.unlockForRead(int64(in.OffIn), int(in.Len))
+
+ data := make([]byte, int(in.Len))
+ totalRead, err := fhIn.readFromChunks(data, int64(in.OffIn))
+ if err == nil || err == io.EOF {
+ maxStop := fhIn.readFromDirtyPages(data, int64(in.OffIn))
+ totalRead = max(maxStop-int64(in.OffIn), totalRead)
+ }
+ if err == io.EOF {
+ err = nil
+ }
+ return data, totalRead, err
+}