seaweedfs/weed/shell/command_volume_mark.go

57 lines
1.5 KiB
Go
Raw Normal View History

2020-10-28 17:47:09 +00:00
package shell
import (
"flag"
2020-10-28 18:17:03 +00:00
"fmt"
"github.com/chrislusf/seaweedfs/weed/pb"
2020-10-28 17:47:09 +00:00
"io"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
)
func init() {
Commands = append(Commands, &commandVolumeMark{})
}
type commandVolumeMark struct {
}
func (c *commandVolumeMark) Name() string {
return "volume.mark"
}
func (c *commandVolumeMark) Help() string {
2020-10-28 18:17:03 +00:00
return `Mark volume writable or readonly from one volume server
2020-10-28 17:47:09 +00:00
2020-10-28 18:17:03 +00:00
volume.mark -node <volume server host:port> -volumeId <volume id> -writable or -readonly
2020-10-28 17:47:09 +00:00
`
}
func (c *commandVolumeMark) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
if err = commandEnv.confirmIsLocked(); err != nil {
return
}
volMarkCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
volumeIdInt := volMarkCommand.Int("volumeId", 0, "the volume id")
nodeStr := volMarkCommand.String("node", "", "the volume server <host>:<port>")
2020-10-28 18:17:03 +00:00
writable := volMarkCommand.Bool("writable", false, "volume mark writable")
readonly := volMarkCommand.Bool("readonly", false, "volume mark readonly")
2020-10-28 17:47:09 +00:00
if err = volMarkCommand.Parse(args); err != nil {
return nil
}
2020-10-28 18:17:03 +00:00
markWritable := false
if (*writable && *readonly) || (!*writable && !*readonly) {
return fmt.Errorf("use -readonly or -writable")
} else if *writable {
markWritable = true
}
2020-10-28 17:47:09 +00:00
sourceVolumeServer := pb.ServerAddress(*nodeStr)
2020-10-28 17:47:09 +00:00
volumeId := needle.VolumeId(*volumeIdInt)
2020-10-28 18:17:03 +00:00
return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable)
2020-10-28 17:47:09 +00:00
}