seaweedfs/weed/server/volume_server_udp_handlers.go

82 lines
1.8 KiB
Go
Raw Normal View History

2021-03-13 18:16:32 +00:00
package weed_server
import (
2021-03-13 18:59:29 +00:00
"github.com/chrislusf/seaweedfs/weed/glog"
"pack.ag/tftp"
2021-03-13 18:16:32 +00:00
)
2021-03-13 18:59:29 +00:00
func (vs *VolumeServer) ServeTFTP(r tftp.ReadRequest) {
filename := r.Name()
2021-03-13 18:16:32 +00:00
volumeId, n, err := vs.parseFileId(filename)
if err != nil {
2021-03-13 18:59:29 +00:00
glog.Errorf("parse file id %s: %v", filename, err)
return
2021-03-13 18:16:32 +00:00
}
hasVolume := vs.store.HasVolume(volumeId)
_, hasEcVolume := vs.store.FindEcVolume(volumeId)
if hasVolume {
if _, err = vs.store.ReadVolumeNeedle(volumeId, n, nil); err != nil {
2021-03-13 18:59:29 +00:00
glog.Errorf("ReadVolumeNeedle %s: %v", filename, err)
return
2021-03-13 18:16:32 +00:00
}
}
if hasEcVolume {
if _, err = vs.store.ReadEcShardNeedle(volumeId, n); err != nil {
2021-03-13 18:59:29 +00:00
glog.Errorf("ReadEcShardNeedle %s: %v", filename, err)
return
2021-03-13 18:16:32 +00:00
}
}
2021-03-13 18:59:29 +00:00
if _, err = r.Write(n.Data); err != nil {
glog.Errorf("UDP Write data %s: %v", filename, err)
return
2021-03-13 18:16:32 +00:00
}
}
2021-03-13 18:59:29 +00:00
func (vs *VolumeServer) ReceiveTFTP(w tftp.WriteRequest) {
filename := w.Name()
2021-03-13 20:05:04 +00:00
println("+ ", filename)
2021-03-13 18:59:29 +00:00
// Get the file size
size, err := w.Size()
// Note: The size value is sent by the client, the client could send more data than
// it indicated in the size option. To be safe we'd want to allocate a buffer
// with the size we're expecting and use w.Read(buf) rather than ioutil.ReadAll.
2021-03-13 18:16:32 +00:00
if filename[0] == '-' {
2021-03-13 18:59:29 +00:00
err = vs.handleTcpDelete(filename[1:])
if err != nil {
glog.Errorf("handleTcpDelete %s: %v", filename, err)
return
}
2021-03-13 18:16:32 +00:00
}
volumeId, n, err := vs.parseFileId(filename)
if err != nil {
2021-03-13 18:59:29 +00:00
glog.Errorf("parse file id %s: %v", filename, err)
return
2021-03-13 18:16:32 +00:00
}
volume := vs.store.GetVolume(volumeId)
if volume == nil {
2021-03-13 18:59:29 +00:00
glog.Errorf("volume %d not found", volumeId)
return
2021-03-13 18:16:32 +00:00
}
2021-03-13 18:59:29 +00:00
err = volume.StreamWrite(n, w, uint32(size))
2021-03-13 18:16:32 +00:00
if err != nil {
2021-03-13 18:59:29 +00:00
glog.Errorf("StreamWrite %s: %v", filename, err)
return
2021-03-13 18:16:32 +00:00
}
2021-03-13 20:05:04 +00:00
println("- ", filename)
2021-03-13 18:16:32 +00:00
}