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.

61 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
3 months ago
4 years ago
4 years ago
  1. package shell
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. "github.com/seaweedfs/seaweedfs/weed/pb"
  7. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandVolumeMark{})
  11. }
  12. type commandVolumeMark struct {
  13. }
  14. func (c *commandVolumeMark) Name() string {
  15. return "volume.mark"
  16. }
  17. func (c *commandVolumeMark) Help() string {
  18. return `Mark volume writable or readonly from one volume server
  19. volume.mark -node <volume server host:port> -volumeId <volume id> -writable or -readonly
  20. `
  21. }
  22. func (c *commandVolumeMark) HasTag(CommandTag) bool {
  23. return false
  24. }
  25. func (c *commandVolumeMark) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  26. volMarkCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  27. volumeIdInt := volMarkCommand.Int("volumeId", 0, "the volume id")
  28. nodeStr := volMarkCommand.String("node", "", "the volume server <host>:<port>")
  29. writable := volMarkCommand.Bool("writable", false, "volume mark writable")
  30. readonly := volMarkCommand.Bool("readonly", false, "volume mark readonly")
  31. if err = volMarkCommand.Parse(args); err != nil {
  32. return nil
  33. }
  34. markWritable := false
  35. if (*writable && *readonly) || (!*writable && !*readonly) {
  36. return fmt.Errorf("use -readonly or -writable")
  37. } else if *writable {
  38. markWritable = true
  39. }
  40. if err = commandEnv.confirmIsLocked(args); err != nil {
  41. return
  42. }
  43. sourceVolumeServer := pb.ServerAddress(*nodeStr)
  44. volumeId := needle.VolumeId(*volumeIdInt)
  45. return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable, true)
  46. }