Browse Source
Merge pull request #1574 from kmlebedev/shell_mark_writable
add shell command volume mark writable
pull/1577/head
Chris Lu
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
62 additions and
0 deletions
-
weed/shell/command_volume_mark.go
-
weed/shell/command_volume_move.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 <volume server host:port> -volumeId <volume id> -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 <host>:<port>") |
|
|
|
|
|
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) |
|
|
|
|
|
} |
|
@ -166,3 +166,18 @@ func deleteVolume(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sour |
|
|
return deleteErr |
|
|
return deleteErr |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func markVolumeWritable(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sourceVolumeServer string, writable bool) (err error) { |
|
|
|
|
|
return operation.WithVolumeServerClient(sourceVolumeServer, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error { |
|
|
|
|
|
if writable { |
|
|
|
|
|
_, err = volumeServerClient.VolumeMarkWritable(context.Background(), &volume_server_pb.VolumeMarkWritableRequest{ |
|
|
|
|
|
VolumeId: uint32(volumeId), |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
_, err = volumeServerClient.VolumeMarkReadonly(context.Background(), &volume_server_pb.VolumeMarkReadonlyRequest{ |
|
|
|
|
|
VolumeId: uint32(volumeId), |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
return err |
|
|
|
|
|
}) |
|
|
|
|
|
} |