command_volume_mark.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package shell
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "io"
  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) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  23. volMarkCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  24. volumeIdInt := volMarkCommand.Int("volumeId", 0, "the volume id")
  25. nodeStr := volMarkCommand.String("node", "", "the volume server <host>:<port>")
  26. writable := volMarkCommand.Bool("writable", false, "volume mark writable")
  27. readonly := volMarkCommand.Bool("readonly", false, "volume mark readonly")
  28. if err = volMarkCommand.Parse(args); err != nil {
  29. return nil
  30. }
  31. markWritable := false
  32. if (*writable && *readonly) || (!*writable && !*readonly) {
  33. return fmt.Errorf("use -readonly or -writable")
  34. } else if *writable {
  35. markWritable = true
  36. }
  37. if err = commandEnv.confirmIsLocked(args); err != nil {
  38. return
  39. }
  40. sourceVolumeServer := pb.ServerAddress(*nodeStr)
  41. volumeId := needle.VolumeId(*volumeIdInt)
  42. return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable)
  43. }