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.

64 lines
1.7 KiB

  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "github.com/chrislusf/seaweedfs/weed/pb"
  6. "io"
  7. "github.com/chrislusf/seaweedfs/weed/operation"
  8. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  9. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  10. "google.golang.org/grpc"
  11. )
  12. func init() {
  13. Commands = append(Commands, &commandVolumeMount{})
  14. }
  15. type commandVolumeMount struct {
  16. }
  17. func (c *commandVolumeMount) Name() string {
  18. return "volume.mount"
  19. }
  20. func (c *commandVolumeMount) Help() string {
  21. return `mount a volume from one volume server
  22. volume.mount -node <volume server host:port> -volumeId <volume id>
  23. This command mounts a volume from one volume server.
  24. `
  25. }
  26. func (c *commandVolumeMount) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  27. volMountCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  28. volumeIdInt := volMountCommand.Int("volumeId", 0, "the volume id")
  29. nodeStr := volMountCommand.String("node", "", "the volume server <host>:<port>")
  30. if err = volMountCommand.Parse(args); err != nil {
  31. return nil
  32. }
  33. if err = commandEnv.confirmIsLocked(args); err != nil {
  34. return
  35. }
  36. sourceVolumeServer := pb.ServerAddress(*nodeStr)
  37. volumeId := needle.VolumeId(*volumeIdInt)
  38. return mountVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)
  39. }
  40. func mountVolume(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sourceVolumeServer pb.ServerAddress) (err error) {
  41. return operation.WithVolumeServerClient(false, sourceVolumeServer, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
  42. _, mountErr := volumeServerClient.VolumeMount(context.Background(), &volume_server_pb.VolumeMountRequest{
  43. VolumeId: uint32(volumeId),
  44. })
  45. return mountErr
  46. })
  47. }