command_volume_mark.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }