-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
command_volume_mark.go
56 lines (43 loc) · 1.48 KB
/
command_volume_mark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package shell
import (
"flag"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb"
"io"
"github.com/seaweedfs/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 {
return `Mark volume writable or readonly from one volume server
volume.mark -node <volume server host:port> -volumeId <volume id> -writable or -readonly
`
}
func (c *commandVolumeMark) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
volMarkCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
volumeIdInt := volMarkCommand.Int("volumeId", 0, "the volume id")
nodeStr := volMarkCommand.String("node", "", "the volume server <host>:<port>")
writable := volMarkCommand.Bool("writable", false, "volume mark writable")
readonly := volMarkCommand.Bool("readonly", false, "volume mark readonly")
if err = volMarkCommand.Parse(args); err != nil {
return nil
}
markWritable := false
if (*writable && *readonly) || (!*writable && !*readonly) {
return fmt.Errorf("use -readonly or -writable")
} else if *writable {
markWritable = true
}
if err = commandEnv.confirmIsLocked(args); err != nil {
return
}
sourceVolumeServer := pb.ServerAddress(*nodeStr)
volumeId := needle.VolumeId(*volumeIdInt)
return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable)
}