From a39eea4b646da92b2e4df6ceb05980c4849164e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Sat, 25 Aug 2018 12:57:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=87=E6=BB=A4=E5=8F=AF?= =?UTF-8?q?=E7=94=A8storage=E6=97=B6=EF=BC=8C=E5=87=BA=E7=8E=B0=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=95=B0=E6=8D=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/storages.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 7990188dd8..769a76612d 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -664,12 +664,15 @@ func (manager *SStorageManager) ListItemFilter(ctx context.Context, q *sqlchemy. } if jsonutils.QueryBoolean(query, "usable", false) { - hostStorage := HoststorageManager.Query().SubQuery() - q = q.Join(hostStorage, sqlchemy.AND( - sqlchemy.Equals(hostStorage.Field("storage_id"), q.Field("id")), - sqlchemy.In(q.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE}), - sqlchemy.IsTrue(q.Field("enabled")), - )) + hostStorageTable := HoststorageManager.Query().SubQuery() + hostTable := HostManager.Query().SubQuery() + sq := hostStorageTable.Query(hostStorageTable.Field("storage_id")).Join(hostTable, + sqlchemy.Equals(hostTable.Field("id"), hostStorageTable.Field("host_id"))). + Filter(sqlchemy.Equals(hostTable.Field("host_status"), HOST_ONLINE)) + + q = q.Filter(sqlchemy.In(q.Field("id"), sq)). + Filter(sqlchemy.In(q.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE})). + Filter(sqlchemy.IsTrue(q.Field("enabled"))) } managerStr := jsonutils.GetAnyString(query, []string{"manager", "provider", "manager_id", "provider_id"})