From 884db215a14258d73e5744ae32fdb97e6f3cb09b Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev Date: Wed, 28 Oct 2020 22:47:09 +0500 Subject: add shell command volume mark writable --- weed/shell/command_volume_mark.go | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 weed/shell/command_volume_mark.go (limited to 'weed/shell/command_volume_mark.go') diff --git a/weed/shell/command_volume_mark.go b/weed/shell/command_volume_mark.go new file mode 100644 index 000000000..cb3e5c0bc --- /dev/null +++ b/weed/shell/command_volume_mark.go @@ -0,0 +1,47 @@ +package shell + +import ( + "flag" + "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 { + return `Mark volume readonly from one volume server + + volume.mark -node -volumeId -readonly true +` +} + +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 :") + writable := volMarkCommand.Bool("writable", true, "volume mark writable/readonly") + if err = volMarkCommand.Parse(args); err != nil { + return nil + } + + sourceVolumeServer := *nodeStr + + volumeId := needle.VolumeId(*volumeIdInt) + + return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, *writable) +} -- cgit v1.2.3 From fab01f9d8d7f191c8830423611544eebfeb5213c Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev Date: Wed, 28 Oct 2020 23:17:03 +0500 Subject: add readonly --- weed/shell/command_volume_mark.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'weed/shell/command_volume_mark.go') diff --git a/weed/shell/command_volume_mark.go b/weed/shell/command_volume_mark.go index cb3e5c0bc..19b614310 100644 --- a/weed/shell/command_volume_mark.go +++ b/weed/shell/command_volume_mark.go @@ -2,6 +2,7 @@ package shell import ( "flag" + "fmt" "io" "github.com/chrislusf/seaweedfs/weed/storage/needle" @@ -19,9 +20,9 @@ func (c *commandVolumeMark) Name() string { } func (c *commandVolumeMark) Help() string { - return `Mark volume readonly from one volume server + return `Mark volume writable or readonly from one volume server - volume.mark -node -volumeId -readonly true + volume.mark -node -volumeId -writable or -readonly ` } @@ -34,14 +35,21 @@ func (c *commandVolumeMark) Do(args []string, commandEnv *CommandEnv, writer io. volMarkCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) volumeIdInt := volMarkCommand.Int("volumeId", 0, "the volume id") nodeStr := volMarkCommand.String("node", "", "the volume server :") - writable := volMarkCommand.Bool("writable", true, "volume mark writable/readonly") + 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 + } sourceVolumeServer := *nodeStr volumeId := needle.VolumeId(*volumeIdInt) - return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, *writable) + return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable) } -- cgit v1.2.3