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.

81 lines
1.8 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
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. println("+ ", filename)
  35. // Get the file size
  36. size, err := w.Size()
  37. // Note: The size value is sent by the client, the client could send more data than
  38. // it indicated in the size option. To be safe we'd want to allocate a buffer
  39. // with the size we're expecting and use w.Read(buf) rather than ioutil.ReadAll.
  40. if filename[0] == '-' {
  41. err = vs.handleTcpDelete(filename[1:])
  42. if err != nil {
  43. glog.Errorf("handleTcpDelete %s: %v", filename, err)
  44. return
  45. }
  46. }
  47. volumeId, n, err := vs.parseFileId(filename)
  48. if err != nil {
  49. glog.Errorf("parse file id %s: %v", filename, err)
  50. return
  51. }
  52. volume := vs.store.GetVolume(volumeId)
  53. if volume == nil {
  54. glog.Errorf("volume %d not found", volumeId)
  55. return
  56. }
  57. err = volume.StreamWrite(n, w, uint32(size))
  58. if err != nil {
  59. glog.Errorf("StreamWrite %s: %v", filename, err)
  60. return
  61. }
  62. println("- ", filename)
  63. }