You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9 KiB

3 months ago
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/mount_pb"
  7. "github.com/seaweedfs/seaweedfs/weed/util"
  8. "google.golang.org/grpc"
  9. "google.golang.org/grpc/credentials/insecure"
  10. _ "google.golang.org/grpc/resolver/passthrough"
  11. "io"
  12. )
  13. func init() {
  14. Commands = append(Commands, &commandMountConfigure{})
  15. }
  16. type commandMountConfigure struct {
  17. }
  18. func (c *commandMountConfigure) Name() string {
  19. return "mount.configure"
  20. }
  21. func (c *commandMountConfigure) Help() string {
  22. return `configure the mount on current server
  23. mount.configure -dir=<mount_directory>
  24. This command connects with local mount via unix socket, so it can only run locally.
  25. The "mount_directory" value needs to be exactly the same as how mount was started in "weed mount -dir=<mount_directory>"
  26. `
  27. }
  28. func (c *commandMountConfigure) HasTag(CommandTag) bool {
  29. return false
  30. }
  31. func (c *commandMountConfigure) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  32. mountConfigureCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  33. mountDir := mountConfigureCommand.String("dir", "", "the mount directory same as how \"weed mount -dir=<mount_directory>\" was started")
  34. mountQuota := mountConfigureCommand.Int("quotaMB", 0, "the quota in MB")
  35. if err = mountConfigureCommand.Parse(args); err != nil {
  36. return nil
  37. }
  38. mountDirHash := util.HashToInt32([]byte(*mountDir))
  39. if mountDirHash < 0 {
  40. mountDirHash = -mountDirHash
  41. }
  42. localSocket := fmt.Sprintf("/tmp/seaweedfs-mount-%d.sock", mountDirHash)
  43. clientConn, err := grpc.Dial("passthrough:///unix://"+localSocket, grpc.WithTransportCredentials(insecure.NewCredentials()))
  44. if err != nil {
  45. return
  46. }
  47. defer clientConn.Close()
  48. client := mount_pb.NewSeaweedMountClient(clientConn)
  49. _, err = client.Configure(context.Background(), &mount_pb.ConfigureRequest{
  50. CollectionCapacity: int64(*mountQuota) * 1024 * 1024,
  51. })
  52. return
  53. }