aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-08-21 17:16:21 -0700
committerchrislu <chris.lu@gmail.com>2022-08-21 17:16:21 -0700
commit63fbf281c764d8f62ee8d75a4c9cf5aee438ff56 (patch)
tree3c40e6e5b1ccef55ca8386acca3d55771dabfd2f
parent3a75d7f7aaaf7d7102f6ead38a221f60cbec5652 (diff)
downloadseaweedfs-63fbf281c764d8f62ee8d75a4c9cf5aee438ff56.tar.xz
seaweedfs-63fbf281c764d8f62ee8d75a4c9cf5aee438ff56.zip
remove same file copying rage limitation
-rw-r--r--weed/mount/weedfs_file_copy_range.go47
1 files changed, 22 insertions, 25 deletions
diff --git a/weed/mount/weedfs_file_copy_range.go b/weed/mount/weedfs_file_copy_range.go
index c85d5f9c4..0620b7dab 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
+}