command_volume_mark.go 1.4 KB

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