command_mount_configure.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  29. mountConfigureCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  30. mountDir := mountConfigureCommand.String("dir", "", "the mount directory same as how \"weed mount -dir=<mount_directory>\" was started")
  31. mountQuota := mountConfigureCommand.Int("quotaMB", 0, "the quota in MB")
  32. if err = mountConfigureCommand.Parse(args); err != nil {
  33. return nil
  34. }
  35. mountDirHash := util.HashToInt32([]byte(*mountDir))
  36. if mountDirHash < 0 {
  37. mountDirHash = -mountDirHash
  38. }
  39. localSocket := fmt.Sprintf("/tmp/seaweedfs-mount-%d.sock", mountDirHash)
  40. clientConn, err := grpc.Dial("passthrough:///unix://"+localSocket, grpc.WithTransportCredentials(insecure.NewCredentials()))
  41. if err != nil {
  42. return
  43. }
  44. defer clientConn.Close()
  45. client := mount_pb.NewSeaweedMountClient(clientConn)
  46. _, err = client.Configure(context.Background(), &mount_pb.ConfigureRequest{
  47. CollectionCapacity: int64(*mountQuota) * 1024 * 1024,
  48. })
  49. return
  50. }