features.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package criu
  2. import (
  3. "fmt"
  4. "github.com/checkpoint-restore/go-criu/v5/rpc"
  5. )
  6. // Feature checking in go-criu is based on the libcriu feature checking function.
  7. // Feature checking allows the user to check if CRIU supports
  8. // certain features. There are CRIU features which do not depend
  9. // on the version of CRIU but on kernel features or architecture.
  10. //
  11. // One example is memory tracking. Memory tracking can be disabled
  12. // in the kernel or there are architectures which do not support
  13. // it (aarch64 for example). By using the feature check a libcriu
  14. // user can easily query CRIU if a certain feature is available.
  15. //
  16. // The features which should be checked can be marked in the
  17. // structure 'struct criu_feature_check'. Each structure member
  18. // that is set to true will result in CRIU checking for the
  19. // availability of that feature in the current combination of
  20. // CRIU/kernel/architecture.
  21. //
  22. // Available features will be set to true when the function
  23. // returns successfully. Missing features will be set to false.
  24. func (c *Criu) FeatureCheck(features *rpc.CriuFeatures) (*rpc.CriuFeatures, error) {
  25. resp, err := c.doSwrkWithResp(
  26. rpc.CriuReqType_FEATURE_CHECK,
  27. nil,
  28. nil,
  29. features,
  30. )
  31. if err != nil {
  32. return nil, err
  33. }
  34. if resp.GetType() != rpc.CriuReqType_FEATURE_CHECK {
  35. return nil, fmt.Errorf("Unexpected CRIU RPC response")
  36. }
  37. return features, nil
  38. }