You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package weed_server
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. "pack.ag/tftp"
  5. )
  6. func (vs *VolumeServer) ServeTFTP(r tftp.ReadRequest) {
  7. filename := r.Name()
  8. volumeId, n, err := vs.parseFileId(filename)
  9. if err != nil {
  10. glog.Errorf("parse file id %s: %v", filename, err)
  11. return
  12. }
  13. hasVolume := vs.store.HasVolume(volumeId)
  14. _, hasEcVolume := vs.store.FindEcVolume(volumeId)
  15. if hasVolume {
  16. if _, err = vs.store.ReadVolumeNeedle(volumeId, n, nil); err != nil {
  17. glog.Errorf("ReadVolumeNeedle %s: %v", filename, err)
  18. return
  19. }
  20. }
  21. if hasEcVolume {
  22. if _, err = vs.store.ReadEcShardNeedle(volumeId, n); err != nil {
  23. glog.Errorf("ReadEcShardNeedle %s: %v", filename, err)
  24. return
  25. }
  26. }
  27. if _, err = r.Write(n.Data); err != nil {
  28. glog.Errorf("UDP Write data %s: %v", filename, err)
  29. return
  30. }
  31. }
  32. func (vs *VolumeServer) ReceiveTFTP(w tftp.WriteRequest) {
  33. filename := w.Name()
  34. // Get the file size
  35. size, err := w.Size()
  36. // Note: The size value is sent by the client, the client could send more data than
  37. // it indicated in the size option. To be safe we'd want to allocate a buffer
  38. // with the size we're expecting and use w.Read(buf) rather than ioutil.ReadAll.
  39. if filename[0] == '-' {
  40. err = vs.handleTcpDelete(filename[1:])
  41. if err != nil {
  42. glog.Errorf("handleTcpDelete %s: %v", filename, err)
  43. return
  44. }
  45. }
  46. volumeId, n, err := vs.parseFileId(filename)
  47. if err != nil {
  48. glog.Errorf("parse file id %s: %v", filename, err)
  49. return
  50. }
  51. volume := vs.store.GetVolume(volumeId)
  52. if volume == nil {
  53. glog.Errorf("volume %d not found", volumeId)
  54. return
  55. }
  56. err = volume.StreamWrite(n, w, uint32(size))
  57. if err != nil {
  58. glog.Errorf("StreamWrite %s: %v", filename, err)
  59. return
  60. }
  61. }