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.8 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, &commandVolumeUnmount{})
  14. }
  15. type commandVolumeUnmount struct {
  16. }
  17. func (c *commandVolumeUnmount) Name() string {
  18. return "volume.unmount"
  19. }
  20. func (c *commandVolumeUnmount) Help() string {
  21. return `unmount a volume from one volume server
  22. volume.unmount -node <volume server host:port> -volumeId <volume id>
  23. This command unmounts a volume from one volume server.
  24. `
  25. }
  26. func (c *commandVolumeUnmount) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  27. volUnmountCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  28. volumeIdInt := volUnmountCommand.Int("volumeId", 0, "the volume id")
  29. nodeStr := volUnmountCommand.String("node", "", "the volume server <host>:<port>")
  30. if err = volUnmountCommand.Parse(args); err != nil {
  31. return nil
  32. }
  33. if err = commandEnv.confirmIsLocked(); err != nil {
  34. return
  35. }
  36. sourceVolumeServer := pb.ServerAddress(*nodeStr)
  37. volumeId := needle.VolumeId(*volumeIdInt)
  38. return unmountVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)
  39. }
  40. func unmountVolume(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sourceVolumeServer pb.ServerAddress) (err error) {
  41. return operation.WithVolumeServerClient(sourceVolumeServer, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
  42. _, unmountErr := volumeServerClient.VolumeUnmount(context.Background(), &volume_server_pb.VolumeUnmountRequest{
  43. VolumeId: uint32(volumeId),
  44. })
  45. return unmountErr
  46. })
  47. }