-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAOS-9584 chk: Add srv handlers for checker upcalls
Implement control plane handlers for the following engine checker dRPC upcalls: * CheckerListPools * CheckerRegisterPool * CheckerDeregisterPool Signed-off-by: Michael MacDonald <[email protected]>
- Loading branch information
Showing
7 changed files
with
504 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// | ||
// (C) Copyright 2022 Intel Corporation. | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
// | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
"google.golang.org/protobuf/proto" | ||
|
||
srvpb "github.com/daos-stack/daos/src/control/common/proto/srv" | ||
"github.com/daos-stack/daos/src/control/drpc" | ||
"github.com/daos-stack/daos/src/control/system" | ||
) | ||
|
||
func (mod *srvModule) handleCheckerListPools(_ context.Context, reqb []byte) (out []byte, outErr error) { | ||
// TODO: Remove if we never add request fields? | ||
req := new(srvpb.CheckListPoolReq) | ||
if err := proto.Unmarshal(reqb, req); err != nil { | ||
return nil, drpc.UnmarshalingPayloadFailure() | ||
} | ||
mod.log.Debugf("handling CheckerListPools: %+v", req) | ||
|
||
resp := new(srvpb.CheckListPoolResp) | ||
defer func() { | ||
mod.log.Debugf("CheckerListPools resp: %+v", resp) | ||
out, outErr = proto.Marshal(resp) | ||
}() | ||
|
||
pools, err := mod.poolDB.PoolServiceList(true) | ||
if err != nil { | ||
mod.log.Errorf("failed to list pools: %s", err) | ||
resp.Status = int32(drpc.DaosMiscError) | ||
return | ||
} | ||
|
||
for _, ps := range pools { | ||
resp.Pools = append(resp.Pools, &srvpb.CheckListPoolResp_OnePool{ | ||
Uuid: ps.PoolUUID.String(), | ||
Label: ps.PoolLabel, | ||
Svcreps: system.RanksToUint32(ps.Replicas), | ||
}) | ||
} | ||
|
||
return | ||
} | ||
|
||
func (mod *srvModule) handleCheckerRegisterPool(_ context.Context, reqb []byte) (out []byte, outErr error) { | ||
req := new(srvpb.CheckRegPoolReq) | ||
if err := proto.Unmarshal(reqb, req); err != nil { | ||
return nil, drpc.UnmarshalingPayloadFailure() | ||
} | ||
mod.log.Debugf("handling CheckerRegisterPool: %+v", req) | ||
|
||
resp := new(srvpb.CheckRegPoolResp) | ||
defer func() { | ||
mod.log.Debugf("CheckerRegisterPool resp: %+v", resp) | ||
out, outErr = proto.Marshal(resp) | ||
}() | ||
|
||
uuid, err := uuid.Parse(req.Uuid) | ||
if err != nil { | ||
mod.log.Errorf("invalid pool UUID %q: %s", req.Uuid, err) | ||
resp.Status = int32(drpc.DaosInvalidInput) | ||
return | ||
} | ||
if !drpc.LabelIsValid(req.Label) { | ||
mod.log.Errorf("bad pool label %q", req.Label) | ||
resp.Status = int32(drpc.DaosInvalidInput) | ||
return | ||
} | ||
if len(req.Svcreps) == 0 { | ||
mod.log.Errorf("pool %q has zero svcreps", req.Uuid) | ||
resp.Status = int32(drpc.DaosInvalidInput) | ||
return | ||
} | ||
if _, err := mod.poolDB.FindPoolServiceByUUID(uuid); err == nil { | ||
mod.log.Errorf("pool with uuid %q already exists", req.Uuid) | ||
resp.Status = int32(drpc.DaosExists) | ||
return | ||
} | ||
if _, err := mod.poolDB.FindPoolServiceByLabel(req.Label); err == nil { | ||
mod.log.Errorf("pool with label %q already exists", req.Label) | ||
resp.Status = int32(drpc.DaosExists) | ||
return | ||
} | ||
|
||
ps := &system.PoolService{ | ||
PoolUUID: uuid, | ||
PoolLabel: req.Label, | ||
State: system.PoolServiceStateReady, | ||
Replicas: system.RanksFromUint32(req.Svcreps), | ||
} | ||
|
||
if err := mod.poolDB.AddPoolService(ps); err != nil { | ||
mod.log.Errorf("failed to register pool: %s", err) | ||
resp.Status = int32(drpc.DaosMiscError) | ||
return | ||
} | ||
|
||
return | ||
} | ||
|
||
func (mod *srvModule) handleCheckerDeregisterPool(_ context.Context, reqb []byte) (out []byte, outErr error) { | ||
req := new(srvpb.CheckDeregPoolReq) | ||
if err := proto.Unmarshal(reqb, req); err != nil { | ||
return nil, drpc.UnmarshalingPayloadFailure() | ||
} | ||
mod.log.Debugf("handling CheckerDeregisterPool: %+v", req) | ||
|
||
resp := new(srvpb.CheckDeregPoolResp) | ||
defer func() { | ||
mod.log.Debugf("CheckerDeregisterPool resp: %+v", resp) | ||
out, outErr = proto.Marshal(resp) | ||
}() | ||
|
||
uuid, err := uuid.Parse(req.Uuid) | ||
if err != nil { | ||
mod.log.Errorf("invalid pool UUID %q: %s", req.Uuid, err) | ||
resp.Status = int32(drpc.DaosInvalidInput) | ||
return | ||
} | ||
|
||
if _, err := mod.poolDB.FindPoolServiceByUUID(uuid); err != nil { | ||
if system.IsPoolNotFound(err) { | ||
mod.log.Errorf("pool with uuid %q does not exist", req.Uuid) | ||
resp.Status = int32(drpc.DaosNonexistant) | ||
} else { | ||
mod.log.Errorf("failed to check pool uuid: %s", err) | ||
resp.Status = int32(drpc.DaosMiscError) | ||
} | ||
return | ||
} | ||
|
||
if err := mod.poolDB.RemovePoolService(uuid); err != nil { | ||
mod.log.Errorf("failed to remove pool: %s", err) | ||
resp.Status = int32(drpc.DaosMiscError) | ||
return | ||
} | ||
|
||
return | ||
} |
Oops, something went wrong.