浏览代码

cluster: avoid recursive readlock on swarm info

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi 7 年之前
父节点
当前提交
ee1be71e9d
共有 1 个文件被更改,包括 12 次插入4 次删除
  1. 12 4
      daemon/cluster/swarm.go

+ 12 - 4
daemon/cluster/swarm.go

@@ -198,9 +198,9 @@ func (c *Cluster) Join(req types.JoinRequest) error {
 
 
 // Inspect retrieves the configuration properties of a managed swarm cluster.
 // Inspect retrieves the configuration properties of a managed swarm cluster.
 func (c *Cluster) Inspect() (types.Swarm, error) {
 func (c *Cluster) Inspect() (types.Swarm, error) {
-	var swarm *swarmapi.Cluster
+	var swarm types.Swarm
 	if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
 	if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
-		s, err := getSwarm(ctx, state.controlClient)
+		s, err := c.inspect(ctx, state)
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
@@ -209,7 +209,15 @@ func (c *Cluster) Inspect() (types.Swarm, error) {
 	}); err != nil {
 	}); err != nil {
 		return types.Swarm{}, err
 		return types.Swarm{}, err
 	}
 	}
-	return convert.SwarmFromGRPC(*swarm), nil
+	return swarm, nil
+}
+
+func (c *Cluster) inspect(ctx context.Context, state nodeState) (types.Swarm, error) {
+	s, err := getSwarm(ctx, state.controlClient)
+	if err != nil {
+		return types.Swarm{}, err
+	}
+	return convert.SwarmFromGRPC(*s), nil
 }
 }
 
 
 // Update updates configuration of a managed swarm cluster.
 // Update updates configuration of a managed swarm cluster.
@@ -413,7 +421,7 @@ func (c *Cluster) Info() types.Info {
 
 
 	if state.IsActiveManager() {
 	if state.IsActiveManager() {
 		info.ControlAvailable = true
 		info.ControlAvailable = true
-		swarm, err := c.Inspect()
+		swarm, err := c.inspect(ctx, state)
 		if err != nil {
 		if err != nil {
 			info.Error = err.Error()
 			info.Error = err.Error()
 		}
 		}