Compare commits
48 Commits
v3.4.0-rc.
...
v3.4.1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a14579fbfb | ||
![]() |
ade66a5722 | ||
![]() |
67cc70926d | ||
![]() |
21dcadc83c | ||
![]() |
c7c379e52e | ||
![]() |
9ed5f76dc0 | ||
![]() |
994865c89e | ||
![]() |
ccbbb2f8d6 | ||
![]() |
d5f79adc9c | ||
![]() |
8b053b0f44 | ||
![]() |
11980f8165 | ||
![]() |
41d4e2b276 | ||
![]() |
898bd1351f | ||
![]() |
d04d96c9ac | ||
![]() |
21edf98fdb | ||
![]() |
a4f7c65ef8 | ||
![]() |
c3a9eec843 | ||
![]() |
e5528acf57 | ||
![]() |
9977550ae9 | ||
![]() |
4d7a6e2755 | ||
![]() |
5e8757c3c5 | ||
![]() |
012e38fef3 | ||
![]() |
41a2cfa122 | ||
![]() |
9f8a1edf38 | ||
![]() |
165ba72593 | ||
![]() |
9c850ccef0 | ||
![]() |
61d6efda4c | ||
![]() |
b76f149c35 | ||
![]() |
5e33bb1a95 | ||
![]() |
83bf125d93 | ||
![]() |
d23af41bca | ||
![]() |
67d0c21bb0 | ||
![]() |
18a077d3d3 | ||
![]() |
fb6d870e89 | ||
![]() |
e00224f87e | ||
![]() |
2af1caf1a5 | ||
![]() |
0777eab766 | ||
![]() |
0ecc0d0542 | ||
![]() |
982a8c9bc3 | ||
![]() |
b8e3e4e7cb | ||
![]() |
4090edfb5b | ||
![]() |
078caccce5 | ||
![]() |
d177b7f6b4 | ||
![]() |
2c1a1d8c32 | ||
![]() |
0fc108428e | ||
![]() |
df489e7a2c | ||
![]() |
f13a5102ec | ||
![]() |
c9465f51d2 |
@@ -6,7 +6,7 @@ sudo: required
|
||||
services: docker
|
||||
|
||||
go:
|
||||
- 1.12.8
|
||||
- 1.12.9
|
||||
|
||||
notifications:
|
||||
on_success: never
|
||||
@@ -27,9 +27,9 @@ env:
|
||||
matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- go: 1.12.8
|
||||
- go: 1.12.9
|
||||
env: TARGET=linux-amd64-grpcproxy
|
||||
- go: 1.12.8
|
||||
- go: 1.12.9
|
||||
env: TARGET=linux-386-unit
|
||||
|
||||
before_install:
|
||||
|
@@ -271,7 +271,10 @@ etcdctl --endpoints=$ENDPOINTS endpoint health
|
||||
|
||||
<img src="https://storage.googleapis.com/etcd/demo/11_etcdctl_snapshot_2016051001.gif" alt="11_etcdctl_snapshot_2016051001"/>
|
||||
|
||||
Snapshot can only be requested from one etcd node, so `--endpoints` flag should contain only one endpoint.
|
||||
|
||||
```
|
||||
ENDPOINTS=$HOST_1:2379
|
||||
etcdctl --endpoints=$ENDPOINTS snapshot save my.db
|
||||
|
||||
Snapshot saved at my.db
|
||||
|
@@ -72,7 +72,7 @@ etcdctl provides a `snapshot` command to create backups. See [backup][backup] fo
|
||||
|
||||
When replacing an etcd node, it's important to remove the member first and then add its replacement.
|
||||
|
||||
etcd employs distributed consensus based on a quorum model; (n+1)/2 members, a majority, must agree on a proposal before it can be committed to the cluster. These proposals include key-value updates and membership changes. This model totally avoids any possibility of split brain inconsistency. The downside is permanent quorum loss is catastrophic.
|
||||
etcd employs distributed consensus based on a quorum model; (n/2)+1 members, a majority, must agree on a proposal before it can be committed to the cluster. These proposals include key-value updates and membership changes. This model totally avoids any possibility of split brain inconsistency. The downside is permanent quorum loss is catastrophic.
|
||||
|
||||
How this applies to membership: If a 3-member cluster has 1 downed member, it can still make forward progress because the quorum is 2 and 2 members are still live. However, adding a new member to a 3-member cluster will increase the quorum to 3 because 3 votes are required for a majority of 4 members. Since the quorum increased, this extra member buys nothing in terms of fault tolerance; the cluster is still one node failure away from being unrecoverable.
|
||||
|
||||
|
@@ -13,26 +13,34 @@ Background
|
||||
|
||||
Membership reconfiguration has been one of the biggest operational challenges. Let’s review common challenges.
|
||||
|
||||
### 1. New Cluster member overloads Leader
|
||||
A newly joined etcd member starts with no data, thus demanding more updates from leader until it catches up with leader’s logs. Then leader’s network is more likely to be overloaded, blocking or dropping leader heartbeats to followers. In such case, a follower may election-timeout to start a new leader election. That is, a cluster with a new member is more vulnerable to leader election. Both leader election and the subsequent update propagation to the new member are prone to causing periods of cluster unavailability (see *Figure 1*).
|
||||
|
||||

|
||||
|
||||
### 2. Network Partitions scenarios
|
||||
What if network partition happens? It depends on leader partition. If the leader still maintains the active quorum, the cluster would continue to operate (see *Figure 2*).
|
||||
|
||||

|
||||
|
||||
#### 2.1 Leader isolation
|
||||
What if the leader becomes isolated from the rest of the cluster? Leader monitors progress of each follower. When leader loses connectivity from the quorum, it reverts back to follower which will affect the cluster availability (see *Figure 3*).
|
||||
|
||||

|
||||
|
||||
When a new node is added to 3 node cluster, the cluster size becomes 4 and the quorum size becomes 3. What if a new node had joined the cluster, and then network partition happens? It depends on which partition the new member gets located after partition. If the new node happens to be located in the same partition as leader’s, the leader still maintains the active quorum of 3. No leadership election happens, and no cluster availability gets affected (see *Figure 4*).
|
||||
When a new node is added to 3 node cluster, the cluster size becomes 4 and the quorum size becomes 3. What if a new node had joined the cluster, and then network partition happens? It depends on which partition the new member gets located after partition.
|
||||
|
||||
#### 2.2 Cluster Split 3+1
|
||||
If the new node happens to be located in the same partition as leader’s, the leader still maintains the active quorum of 3. No leadership election happens, and no cluster availability gets affected (see *Figure 4*).
|
||||
|
||||

|
||||
|
||||
#### 2.3 Cluster Split 2+2
|
||||
If the cluster is 2-and-2 partitioned, then neither of partition maintains the quorum of 3. In this case, leadership election happens (see *Figure 5*).
|
||||
|
||||

|
||||
|
||||
#### 2.4 Quorum Lost
|
||||
What if network partition happens first, and then a new member gets added? A partitioned 3-node cluster already has one disconnected follower. When a new member is added, the quorum changes from 2 to 3. Now, this cluster has only 2 active nodes out 4, thus losing quorum and starting a new leadership election (see *Figure 6*).
|
||||
|
||||

|
||||
@@ -43,6 +51,7 @@ Adding a new member to a 1-node cluster changes the quorum size to 2, immediatel
|
||||
|
||||

|
||||
|
||||
### 3. Cluster Misconfigurations
|
||||
An even worse case is when an added member is misconfigured. Membership reconfiguration is a two-step process: “etcdctl member add” and starting an etcd server process with the given peer URL. That is, “member add” command is applied regardless of URL, even when the URL value is invalid. If the first step is applied with invalid URLs, the second step cannot even start the new etcd. Once the cluster loses quorum, there is no way to revert the membership change (see *Figure 8*).
|
||||
|
||||

|
||||
|
@@ -369,6 +369,52 @@ After
|
||||
docker pull gcr.io/etcd-development/etcd:v3.3.0
|
||||
```
|
||||
|
||||
### Upgrades to >= v3.3.14
|
||||
|
||||
[v3.3.14](https://github.com/etcd-io/etcd/releases/tag/v3.3.14) had to include some features from 3.4, while trying to minimize the difference between client balancer implementation. This release fixes ["kube-apiserver 1.13.x refuses to work when first etcd-server is not available" (kubernetes#72102)](https://github.com/kubernetes/kubernetes/issues/72102).
|
||||
|
||||
`grpc.ErrClientConnClosing` has been [deprecated in gRPC >= 1.10](https://github.com/grpc/grpc-go/pull/1854).
|
||||
|
||||
```diff
|
||||
import (
|
||||
+ "go.etcd.io/etcd/clientv3"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
+ "google.golang.org/grpc/codes"
|
||||
+ "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
_, err := kvc.Get(ctx, "a")
|
||||
-if err == grpc.ErrClientConnClosing {
|
||||
+if clientv3.IsConnCanceled(err) {
|
||||
|
||||
// or
|
||||
+s, ok := status.FromError(err)
|
||||
+if ok {
|
||||
+ if s.Code() == codes.Canceled
|
||||
```
|
||||
|
||||
[The new client balancer](https://github.com/etcd-io/etcd/blob/master/Documentation/learning/design-client.md) uses an asynchronous resolver to pass endpoints to the gRPC dial function. As a result, [v3.3.14](https://github.com/etcd-io/etcd/releases/tag/v3.3.14) or later requires `grpc.WithBlock` dial option to wait until the underlying connection is up.
|
||||
|
||||
```diff
|
||||
import (
|
||||
"time"
|
||||
"go.etcd.io/etcd/clientv3"
|
||||
+ "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
+// "grpc.WithBlock()" to block until the underlying connection is up
|
||||
ccfg := clientv3.Config{
|
||||
Endpoints: []string{"localhost:2379"},
|
||||
DialTimeout: time.Second,
|
||||
+ DialOptions: []grpc.DialOption{grpc.WithBlock()},
|
||||
DialKeepAliveTime: time.Second,
|
||||
DialKeepAliveTimeout: 500 * time.Millisecond,
|
||||
}
|
||||
```
|
||||
|
||||
Please see [CHANGELOG](https://github.com/etcd-io/etcd/blob/master/CHANGELOG-3.3.md) for a full list of changes.
|
||||
|
||||
### Server upgrade checklists
|
||||
|
||||
#### Upgrade requirements
|
||||
|
@@ -89,9 +89,7 @@ _, err := kvc.Get(ctx, "a")
|
||||
|
||||
#### Require `grpc.WithBlock` for client dial
|
||||
|
||||
[The new client balancer][client-design] uses an asynchronous resolver to pass endpoints to the gRPC dial function.
|
||||
|
||||
In order to create a client object synchronously with gRPC connection, pass `grpc.WithBlock` to dial options:
|
||||
[The new client balancer](https://github.com/etcd-io/etcd/blob/master/Documentation/learning/design-client.md) uses an asynchronous resolver to pass endpoints to the gRPC dial function. As a result, v3.4 client requires `grpc.WithBlock` dial option to wait until the underlying connection is up.
|
||||
|
||||
```diff
|
||||
import (
|
||||
@@ -603,4 +601,3 @@ COMMENT
|
||||
```
|
||||
|
||||
[etcd-contact]: https://groups.google.com/forum/#!forum/etcd-dev
|
||||
[client-design]: https://github.com/etcd-io/etcd/blob/master/Documentation/learning/design-client.md
|
||||
|
6
Makefile
6
Makefile
@@ -51,7 +51,7 @@ docker-remove:
|
||||
|
||||
|
||||
|
||||
GO_VERSION ?= 1.12.8
|
||||
GO_VERSION ?= 1.12.9
|
||||
ETCD_VERSION ?= $(shell git rev-parse --short HEAD || echo "GitNotFound")
|
||||
|
||||
TEST_SUFFIX = $(shell date +%s | base64 | head -c 15)
|
||||
@@ -65,11 +65,11 @@ endif
|
||||
|
||||
|
||||
# Example:
|
||||
# GO_VERSION=1.12.8 make build-docker-test
|
||||
# GO_VERSION=1.12.9 make build-docker-test
|
||||
# make build-docker-test
|
||||
#
|
||||
# gcloud docker -- login -u _json_key -p "$(cat /etc/gcp-key-etcd-development.json)" https://gcr.io
|
||||
# GO_VERSION=1.12.8 make push-docker-test
|
||||
# GO_VERSION=1.12.9 make push-docker-test
|
||||
# make push-docker-test
|
||||
#
|
||||
# gsutil -m acl ch -u allUsers:R -r gs://artifacts.etcd-development.appspot.com
|
||||
|
@@ -388,7 +388,7 @@ func (as *authStore) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse,
|
||||
var hashed []byte
|
||||
var err error
|
||||
|
||||
if !r.Options.NoPassword {
|
||||
if r.Options != nil && !r.Options.NoPassword {
|
||||
hashed, err = bcrypt.GenerateFromPassword([]byte(r.Password), as.bcryptCost)
|
||||
if err != nil {
|
||||
if as.lg != nil {
|
||||
|
@@ -129,8 +129,12 @@ func NewFromURLs(urls []string) (*Client, error) {
|
||||
// Close shuts down the client's etcd connections.
|
||||
func (c *Client) Close() error {
|
||||
c.cancel()
|
||||
c.Watcher.Close()
|
||||
c.Lease.Close()
|
||||
if c.Watcher != nil {
|
||||
c.Watcher.Close()
|
||||
}
|
||||
if c.Lease != nil {
|
||||
c.Lease.Close()
|
||||
}
|
||||
if c.resolverGroup != nil {
|
||||
c.resolverGroup.Close()
|
||||
}
|
||||
|
@@ -156,3 +156,13 @@ func TestIsHaltErr(t *testing.T) {
|
||||
t.Errorf("cancel on context should be Halted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseCtxClient(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
c := NewCtxClient(ctx)
|
||||
err := c.Close()
|
||||
// Close returns ctx.toErr, a nil error means an open Done channel
|
||||
if err == nil {
|
||||
t.Errorf("failed to Close the client. %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -276,8 +276,7 @@ func TestMemberPromote(t *testing.T) {
|
||||
select {
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
case <-timeout:
|
||||
t.Errorf("failed all attempts to promote learner member, last error: %v", err)
|
||||
break
|
||||
t.Fatalf("failed all attempts to promote learner member, last error: %v", err)
|
||||
}
|
||||
|
||||
_, err = capi.MemberPromote(context.Background(), learnerID)
|
||||
|
@@ -37,8 +37,8 @@ func TestKVPutError(t *testing.T) {
|
||||
defer testutil.AfterTest(t)
|
||||
|
||||
var (
|
||||
maxReqBytes = 1.5 * 1024 * 1024 // hard coded max in v3_server.go
|
||||
quota = int64(int(maxReqBytes) + 8*os.Getpagesize())
|
||||
maxReqBytes = 1.5 * 1024 * 1024 // hard coded max in v3_server.go
|
||||
quota = int64(int(maxReqBytes*1.2) + 8*os.Getpagesize()) // make sure we have enough overhead in backend quota. See discussion in #6486.
|
||||
)
|
||||
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1, QuotaBackendBytes: quota, ClientMaxCallSendMsgSize: 100 * 1024 * 1024})
|
||||
defer clus.Terminate(t)
|
||||
|
@@ -303,8 +303,8 @@ type Config struct {
|
||||
// It can be multiple when "Logger" is zap.
|
||||
LogOutputs []string `json:"log-outputs"`
|
||||
|
||||
// zapLoggerBuilder is used to build the zap logger.
|
||||
zapLoggerBuilder func(*Config) error
|
||||
// ZapLoggerBuilder is used to build the zap logger.
|
||||
ZapLoggerBuilder func(*Config) error
|
||||
|
||||
// logger logs server-side operations. The default is nil,
|
||||
// and "setupLogging" must be called before starting server.
|
||||
|
@@ -170,7 +170,10 @@ func (cfg *Config) setupLogging() error {
|
||||
}
|
||||
|
||||
if !isJournal {
|
||||
copied := logutil.AddOutputPaths(logutil.DefaultZapLoggerConfig, outputPaths, errOutputPaths)
|
||||
copied := logutil.DefaultZapLoggerConfig
|
||||
copied.OutputPaths = outputPaths
|
||||
copied.ErrorOutputPaths = errOutputPaths
|
||||
copied = logutil.MergeOutputPaths(copied)
|
||||
copied.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel))
|
||||
if cfg.Debug || cfg.LogLevel == "debug" {
|
||||
// enable tracing even when "--debug --log-level info"
|
||||
@@ -178,8 +181,8 @@ func (cfg *Config) setupLogging() error {
|
||||
// TODO: remove "Debug" check in v3.5
|
||||
grpc.EnableTracing = true
|
||||
}
|
||||
if cfg.zapLoggerBuilder == nil {
|
||||
cfg.zapLoggerBuilder = func(c *Config) error {
|
||||
if cfg.ZapLoggerBuilder == nil {
|
||||
cfg.ZapLoggerBuilder = func(c *Config) error {
|
||||
var err error
|
||||
c.logger, err = copied.Build()
|
||||
if err != nil {
|
||||
@@ -232,8 +235,8 @@ func (cfg *Config) setupLogging() error {
|
||||
syncer,
|
||||
lvl,
|
||||
)
|
||||
if cfg.zapLoggerBuilder == nil {
|
||||
cfg.zapLoggerBuilder = func(c *Config) error {
|
||||
if cfg.ZapLoggerBuilder == nil {
|
||||
cfg.ZapLoggerBuilder = func(c *Config) error {
|
||||
c.logger = zap.New(cr, zap.AddCaller(), zap.ErrorOutput(syncer))
|
||||
c.loggerMu.Lock()
|
||||
defer c.loggerMu.Unlock()
|
||||
@@ -249,7 +252,7 @@ func (cfg *Config) setupLogging() error {
|
||||
}
|
||||
}
|
||||
|
||||
err := cfg.zapLoggerBuilder(cfg)
|
||||
err := cfg.ZapLoggerBuilder(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -189,7 +189,7 @@ func (sctx *serveCtx) serve(
|
||||
sctx.serversC <- &servers{secure: true, grpc: gs, http: srv}
|
||||
if sctx.lg != nil {
|
||||
sctx.lg.Info(
|
||||
"serving client traffic insecurely",
|
||||
"serving client traffic securely",
|
||||
zap.String("address", sctx.l.Addr().String()),
|
||||
)
|
||||
} else {
|
||||
|
@@ -200,12 +200,14 @@ Experimental feature:
|
||||
Duration of time between cluster corruption check passes.
|
||||
--experimental-enable-v2v3 ''
|
||||
Serve v2 requests through the v3 backend under a given prefix.
|
||||
--experimental-backend-bbolt-freelist-type
|
||||
--experimental-backend-bbolt-freelist-type 'array'
|
||||
ExperimentalBackendFreelistType specifies the type of freelist that boltdb backend uses(array and map are supported types).
|
||||
--experimental-enable-lease-checkpoint
|
||||
--experimental-enable-lease-checkpoint 'false'
|
||||
ExperimentalEnableLeaseCheckpoint enables primary lessor to persist lease remainingTTL to prevent indefinite auto-renewal of long lived leases.
|
||||
--experimental-compaction-batch-limit
|
||||
--experimental-compaction-batch-limit 1000
|
||||
ExperimentalCompactionBatchLimit sets the maximum revisions deleted in each compaction batch.
|
||||
--experimental-peer-skip-client-san-verification 'false'
|
||||
Skip verification of SAN field in client certificate for peer connections.
|
||||
|
||||
Unsafe feature:
|
||||
--force-new-cluster 'false'
|
||||
|
@@ -207,7 +207,7 @@ func monitorFileDescriptor(lg *zap.Logger, done <-chan struct{}) {
|
||||
}
|
||||
if used >= limit/5*4 {
|
||||
if lg != nil {
|
||||
lg.Warn("80%% of file descriptors are used", zap.Uint64("used", used), zap.Uint64("limit", limit))
|
||||
lg.Warn("80% of file descriptors are used", zap.Uint64("used", used), zap.Uint64("limit", limit))
|
||||
} else {
|
||||
plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit)
|
||||
}
|
||||
|
@@ -382,7 +382,7 @@ func (srv *Server) loadAutoTLSAssets() error {
|
||||
fdir := filepath.Join(srv.Member.Etcd.DataDir, "fixtures", "peer")
|
||||
|
||||
srv.lg.Info(
|
||||
"loading client auto TLS assets",
|
||||
"loading peer auto TLS assets",
|
||||
zap.String("dir", fdir),
|
||||
zap.String("endpoint", srv.EtcdClientEndpoint),
|
||||
)
|
||||
@@ -450,10 +450,10 @@ func (srv *Server) loadAutoTLSAssets() error {
|
||||
|
||||
srv.lg.Info(
|
||||
"loaded client TLS assets",
|
||||
zap.String("peer-cert-path", certPath),
|
||||
zap.Int("peer-cert-length", len(certData)),
|
||||
zap.String("peer-key-path", keyPath),
|
||||
zap.Int("peer-key-length", len(keyData)),
|
||||
zap.String("client-cert-path", certPath),
|
||||
zap.Int("client-cert-length", len(certData)),
|
||||
zap.String("client-key-path", keyPath),
|
||||
zap.Int("client-key-length", len(keyData)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,7 @@ if ! [[ "${0}" =~ "scripts/docker-local-agent.sh" ]]; then
|
||||
fi
|
||||
|
||||
if [[ -z "${GO_VERSION}" ]]; then
|
||||
GO_VERSION=1.12.8
|
||||
GO_VERSION=1.12.9
|
||||
fi
|
||||
echo "Running with GO_VERSION:" ${GO_VERSION}
|
||||
|
||||
|
@@ -6,7 +6,7 @@ if ! [[ "${0}" =~ "scripts/docker-local-tester.sh" ]]; then
|
||||
fi
|
||||
|
||||
if [[ -z "${GO_VERSION}" ]]; then
|
||||
GO_VERSION=1.12.8
|
||||
GO_VERSION=1.12.9
|
||||
fi
|
||||
echo "Running with GO_VERSION:" ${GO_VERSION}
|
||||
|
||||
|
5
go.mod
5
go.mod
@@ -40,9 +40,10 @@ require (
|
||||
go.uber.org/multierr v1.1.0 // indirect
|
||||
go.uber.org/zap v1.10.0
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
|
||||
golang.org/x/net v0.0.0-20190813000000-74dc4d7220e7
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 // indirect
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2
|
||||
google.golang.org/grpc v1.23.0
|
||||
google.golang.org/grpc v1.23.1
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.25
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
sigs.k8s.io/yaml v1.1.0
|
||||
|
10
go.sum
10
go.sum
@@ -153,8 +153,8 @@ golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73r
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190813000000-74dc4d7220e7 h1:HOTjhHFecQCpFnEhQ4MAH6Gf7yGklZnqaHvtezTKqnQ=
|
||||
golang.org/x/net v0.0.0-20190813000000-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA=
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -167,6 +167,8 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5 h1:mzjBh+S5frKOsOBobWIMAbXav
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 h1:ng0gs1AKnRRuEMZoTLLlbOd+C17zUDepwGQBb/n+JVg=
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM=
|
||||
@@ -179,8 +181,8 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.1 h1:q4XQuHFC6I28BKZpo6IYyb3mNO+l7lSOxRuYTCiDfXk=
|
||||
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
@@ -355,19 +355,7 @@ func (s *store) Restore(b backend.Backend) error {
|
||||
}
|
||||
|
||||
func (s *store) restore() error {
|
||||
b := s.b
|
||||
reportDbTotalSizeInBytesMu.Lock()
|
||||
reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) }
|
||||
reportDbTotalSizeInBytesMu.Unlock()
|
||||
reportDbTotalSizeInBytesDebugMu.Lock()
|
||||
reportDbTotalSizeInBytesDebug = func() float64 { return float64(b.Size()) }
|
||||
reportDbTotalSizeInBytesDebugMu.Unlock()
|
||||
reportDbTotalSizeInUseInBytesMu.Lock()
|
||||
reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) }
|
||||
reportDbTotalSizeInUseInBytesMu.Unlock()
|
||||
reportDbOpenReadTxNMu.Lock()
|
||||
reportDbOpenReadTxN = func() float64 { return float64(b.OpenReadTxN()) }
|
||||
reportDbOpenReadTxNMu.Unlock()
|
||||
s.setupMetricsReporter()
|
||||
|
||||
min, max := newRevBytes(), newRevBytes()
|
||||
revToBytes(revision{main: 1}, min)
|
||||
@@ -579,6 +567,36 @@ func (s *store) ConsistentIndex() uint64 {
|
||||
return v
|
||||
}
|
||||
|
||||
func (s *store) setupMetricsReporter() {
|
||||
b := s.b
|
||||
reportDbTotalSizeInBytesMu.Lock()
|
||||
reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) }
|
||||
reportDbTotalSizeInBytesMu.Unlock()
|
||||
reportDbTotalSizeInBytesDebugMu.Lock()
|
||||
reportDbTotalSizeInBytesDebug = func() float64 { return float64(b.Size()) }
|
||||
reportDbTotalSizeInBytesDebugMu.Unlock()
|
||||
reportDbTotalSizeInUseInBytesMu.Lock()
|
||||
reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) }
|
||||
reportDbTotalSizeInUseInBytesMu.Unlock()
|
||||
reportDbOpenReadTxNMu.Lock()
|
||||
reportDbOpenReadTxN = func() float64 { return float64(b.OpenReadTxN()) }
|
||||
reportDbOpenReadTxNMu.Unlock()
|
||||
reportCurrentRevMu.Lock()
|
||||
reportCurrentRev = func() float64 {
|
||||
s.revMu.RLock()
|
||||
defer s.revMu.RUnlock()
|
||||
return float64(s.currentRev)
|
||||
}
|
||||
reportCurrentRevMu.Unlock()
|
||||
reportCompactRevMu.Lock()
|
||||
reportCompactRev = func() float64 {
|
||||
s.revMu.RLock()
|
||||
defer s.revMu.RUnlock()
|
||||
return float64(s.compactMainRev)
|
||||
}
|
||||
reportCompactRevMu.Unlock()
|
||||
}
|
||||
|
||||
// appendMarkTombstone appends tombstone mark to normal revision bytes.
|
||||
func appendMarkTombstone(lg *zap.Logger, b []byte) []byte {
|
||||
if len(b) != revBytesLen {
|
||||
|
@@ -264,6 +264,38 @@ var (
|
||||
// highest bucket start of 0.01 sec * 2^14 == 163.84 sec
|
||||
Buckets: prometheus.ExponentialBuckets(.01, 2, 15),
|
||||
})
|
||||
|
||||
currentRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: "etcd_debugging",
|
||||
Subsystem: "mvcc",
|
||||
Name: "current_revision",
|
||||
Help: "The current revision of store.",
|
||||
},
|
||||
func() float64 {
|
||||
reportCurrentRevMu.RLock()
|
||||
defer reportCurrentRevMu.RUnlock()
|
||||
return reportCurrentRev()
|
||||
},
|
||||
)
|
||||
// overridden by mvcc initialization
|
||||
reportCurrentRevMu sync.RWMutex
|
||||
reportCurrentRev = func() float64 { return 0 }
|
||||
|
||||
compactRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: "etcd_debugging",
|
||||
Subsystem: "mvcc",
|
||||
Name: "compact_revision",
|
||||
Help: "The revision of the last compaction in store.",
|
||||
},
|
||||
func() float64 {
|
||||
reportCompactRevMu.RLock()
|
||||
defer reportCompactRevMu.RUnlock()
|
||||
return reportCompactRev()
|
||||
},
|
||||
)
|
||||
// overridden by mvcc initialization
|
||||
reportCompactRevMu sync.RWMutex
|
||||
reportCompactRev = func() float64 { return 0 }
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -291,6 +323,8 @@ func init() {
|
||||
prometheus.MustRegister(dbOpenReadTxN)
|
||||
prometheus.MustRegister(hashSec)
|
||||
prometheus.MustRegister(hashRevSec)
|
||||
prometheus.MustRegister(currentRev)
|
||||
prometheus.MustRegister(compactRev)
|
||||
}
|
||||
|
||||
// ReportEventReceived reports that an event is received.
|
||||
|
@@ -53,15 +53,12 @@ var DefaultZapLoggerConfig = zap.Config{
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
}
|
||||
|
||||
// AddOutputPaths adds output paths to the existing output paths, resolving conflicts.
|
||||
func AddOutputPaths(cfg zap.Config, outputPaths, errorOutputPaths []string) zap.Config {
|
||||
// MergeOutputPaths merges logging output paths, resolving conflicts.
|
||||
func MergeOutputPaths(cfg zap.Config) zap.Config {
|
||||
outputs := make(map[string]struct{})
|
||||
for _, v := range cfg.OutputPaths {
|
||||
outputs[v] = struct{}{}
|
||||
}
|
||||
for _, v := range outputPaths {
|
||||
outputs[v] = struct{}{}
|
||||
}
|
||||
outputSlice := make([]string, 0)
|
||||
if _, ok := outputs["/dev/null"]; ok {
|
||||
// "/dev/null" to discard all
|
||||
@@ -78,9 +75,6 @@ func AddOutputPaths(cfg zap.Config, outputPaths, errorOutputPaths []string) zap.
|
||||
for _, v := range cfg.ErrorOutputPaths {
|
||||
errOutputs[v] = struct{}{}
|
||||
}
|
||||
for _, v := range errorOutputPaths {
|
||||
errOutputs[v] = struct{}{}
|
||||
}
|
||||
errOutputSlice := make([]string, 0)
|
||||
if _, ok := errOutputs["/dev/null"]; ok {
|
||||
// "/dev/null" to discard all
|
||||
|
@@ -257,11 +257,15 @@ func (c Changer) initProgress(cfg *tracker.Config, prs tracker.ProgressMap, id u
|
||||
nilAwareAdd(&cfg.Learners, id)
|
||||
}
|
||||
prs[id] = &tracker.Progress{
|
||||
// We initialize Progress.Next with lastIndex+1 so that the peer will be
|
||||
// probed without an index first.
|
||||
// Initializing the Progress with the last index means that the follower
|
||||
// can be probed (with the last index).
|
||||
//
|
||||
// TODO(tbg): verify that, this is just my best guess.
|
||||
Next: c.LastIndex + 1,
|
||||
// TODO(tbg): seems awfully optimistic. Using the first index would be
|
||||
// better. The general expectation here is that the follower has no log
|
||||
// at all (and will thus likely need a snapshot), though the app may
|
||||
// have applied a snapshot out of band before adding the replica (thus
|
||||
// making the first index the better choice).
|
||||
Next: c.LastIndex,
|
||||
Match: 0,
|
||||
Inflights: tracker.NewInflights(c.Tracker.MaxInflight),
|
||||
IsLearner: isLearner,
|
||||
|
14
raft/confchange/testdata/joint_autoleave.txt
vendored
14
raft/confchange/testdata/joint_autoleave.txt
vendored
@@ -5,16 +5,16 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
||||
# Autoleave is reflected in the config.
|
||||
enter-joint autoleave=true
|
||||
v2 v3
|
||||
----
|
||||
voters=(1 2 3)&&(1) autoleave
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
3: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
3: StateProbe match=0 next=1
|
||||
|
||||
# Can't enter-joint twice, even if autoleave changes.
|
||||
enter-joint autoleave=false
|
||||
@@ -24,6 +24,6 @@ config is already joint
|
||||
leave-joint
|
||||
----
|
||||
voters=(1 2 3)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
3: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
3: StateProbe match=0 next=1
|
||||
|
14
raft/confchange/testdata/joint_idempotency.txt
vendored
14
raft/confchange/testdata/joint_idempotency.txt
vendored
@@ -5,19 +5,19 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
||||
enter-joint
|
||||
r1 r2 r9 v2 v3 v4 v2 v3 v4 l2 l2 r4 r4 l1 l1
|
||||
----
|
||||
voters=(3)&&(1) learners=(2) learners_next=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2 learner
|
||||
3: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1 learner
|
||||
3: StateProbe match=0 next=1
|
||||
|
||||
leave-joint
|
||||
----
|
||||
voters=(3) learners=(1 2)
|
||||
1: StateProbe match=0 next=1 learner
|
||||
2: StateProbe match=0 next=2 learner
|
||||
3: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0 learner
|
||||
2: StateProbe match=0 next=1 learner
|
||||
3: StateProbe match=0 next=1
|
||||
|
10
raft/confchange/testdata/joint_learners_next.txt
vendored
10
raft/confchange/testdata/joint_learners_next.txt
vendored
@@ -8,17 +8,17 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
||||
enter-joint
|
||||
v2 l1
|
||||
----
|
||||
voters=(2)&&(1) learners_next=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
|
||||
leave-joint
|
||||
----
|
||||
voters=(2) learners=(1)
|
||||
1: StateProbe match=0 next=1 learner
|
||||
2: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0 learner
|
||||
2: StateProbe match=0 next=1
|
||||
|
28
raft/confchange/testdata/joint_safety.txt
vendored
28
raft/confchange/testdata/joint_safety.txt
vendored
@@ -15,7 +15,7 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=4
|
||||
1: StateProbe match=0 next=3
|
||||
|
||||
leave-joint
|
||||
----
|
||||
@@ -25,7 +25,7 @@ can't leave a non-joint config
|
||||
enter-joint
|
||||
----
|
||||
voters=(1)&&(1)
|
||||
1: StateProbe match=0 next=4
|
||||
1: StateProbe match=0 next=3
|
||||
|
||||
enter-joint
|
||||
----
|
||||
@@ -34,7 +34,7 @@ config is already joint
|
||||
leave-joint
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=4
|
||||
1: StateProbe match=0 next=3
|
||||
|
||||
leave-joint
|
||||
----
|
||||
@@ -45,10 +45,10 @@ enter-joint
|
||||
r1 v2 v3 l4
|
||||
----
|
||||
voters=(2 3)&&(1) learners=(4)
|
||||
1: StateProbe match=0 next=4
|
||||
2: StateProbe match=0 next=10
|
||||
3: StateProbe match=0 next=10
|
||||
4: StateProbe match=0 next=10 learner
|
||||
1: StateProbe match=0 next=3
|
||||
2: StateProbe match=0 next=9
|
||||
3: StateProbe match=0 next=9
|
||||
4: StateProbe match=0 next=9 learner
|
||||
|
||||
enter-joint
|
||||
----
|
||||
@@ -67,15 +67,15 @@ can't apply simple config change in joint config
|
||||
leave-joint
|
||||
----
|
||||
voters=(2 3) learners=(4)
|
||||
2: StateProbe match=0 next=10
|
||||
3: StateProbe match=0 next=10
|
||||
4: StateProbe match=0 next=10 learner
|
||||
2: StateProbe match=0 next=9
|
||||
3: StateProbe match=0 next=9
|
||||
4: StateProbe match=0 next=9 learner
|
||||
|
||||
simple
|
||||
l9
|
||||
----
|
||||
voters=(2 3) learners=(4 9)
|
||||
2: StateProbe match=0 next=10
|
||||
3: StateProbe match=0 next=10
|
||||
4: StateProbe match=0 next=10 learner
|
||||
9: StateProbe match=0 next=15 learner
|
||||
2: StateProbe match=0 next=9
|
||||
3: StateProbe match=0 next=9
|
||||
4: StateProbe match=0 next=9 learner
|
||||
9: StateProbe match=0 next=14 learner
|
||||
|
30
raft/confchange/testdata/simple_idempotency.txt
vendored
30
raft/confchange/testdata/simple_idempotency.txt
vendored
@@ -2,68 +2,68 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
||||
simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
||||
simple
|
||||
v2
|
||||
----
|
||||
voters=(1 2)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=2
|
||||
|
||||
simple
|
||||
l1
|
||||
----
|
||||
voters=(2) learners=(1)
|
||||
1: StateProbe match=0 next=1 learner
|
||||
2: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0 learner
|
||||
2: StateProbe match=0 next=2
|
||||
|
||||
simple
|
||||
l1
|
||||
----
|
||||
voters=(2) learners=(1)
|
||||
1: StateProbe match=0 next=1 learner
|
||||
2: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0 learner
|
||||
2: StateProbe match=0 next=2
|
||||
|
||||
simple
|
||||
r1
|
||||
----
|
||||
voters=(2)
|
||||
2: StateProbe match=0 next=3
|
||||
2: StateProbe match=0 next=2
|
||||
|
||||
simple
|
||||
r1
|
||||
----
|
||||
voters=(2)
|
||||
2: StateProbe match=0 next=3
|
||||
2: StateProbe match=0 next=2
|
||||
|
||||
simple
|
||||
v3
|
||||
----
|
||||
voters=(2 3)
|
||||
2: StateProbe match=0 next=3
|
||||
3: StateProbe match=0 next=8
|
||||
2: StateProbe match=0 next=2
|
||||
3: StateProbe match=0 next=7
|
||||
|
||||
simple
|
||||
r3
|
||||
----
|
||||
voters=(2)
|
||||
2: StateProbe match=0 next=3
|
||||
2: StateProbe match=0 next=2
|
||||
|
||||
simple
|
||||
r3
|
||||
----
|
||||
voters=(2)
|
||||
2: StateProbe match=0 next=3
|
||||
2: StateProbe match=0 next=2
|
||||
|
||||
simple
|
||||
r4
|
||||
----
|
||||
voters=(2)
|
||||
2: StateProbe match=0 next=3
|
||||
2: StateProbe match=0 next=2
|
||||
|
@@ -4,22 +4,22 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
||||
simple
|
||||
v2
|
||||
----
|
||||
voters=(1 2)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
|
||||
simple
|
||||
v3
|
||||
----
|
||||
voters=(1 2 3)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
3: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
3: StateProbe match=0 next=2
|
||||
|
||||
# Can atomically demote and promote without a hitch.
|
||||
# This is pointless, but possible.
|
||||
@@ -27,18 +27,18 @@ simple
|
||||
l1 v1
|
||||
----
|
||||
voters=(1 2 3)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
3: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
3: StateProbe match=0 next=2
|
||||
|
||||
# Can demote a voter.
|
||||
simple
|
||||
l2
|
||||
----
|
||||
voters=(1 3) learners=(2)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2 learner
|
||||
3: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1 learner
|
||||
3: StateProbe match=0 next=2
|
||||
|
||||
# Can atomically promote and demote the same voter.
|
||||
# This is pointless, but possible.
|
||||
@@ -46,15 +46,15 @@ simple
|
||||
v2 l2
|
||||
----
|
||||
voters=(1 3) learners=(2)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2 learner
|
||||
3: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1 learner
|
||||
3: StateProbe match=0 next=2
|
||||
|
||||
# Can promote a voter.
|
||||
simple
|
||||
v2
|
||||
----
|
||||
voters=(1 2 3)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
3: StateProbe match=0 next=3
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
3: StateProbe match=0 next=2
|
||||
|
20
raft/confchange/testdata/simple_safety.txt
vendored
20
raft/confchange/testdata/simple_safety.txt
vendored
@@ -7,15 +7,15 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=1
|
||||
|
||||
simple
|
||||
v2 l3
|
||||
----
|
||||
voters=(1 2) learners=(3)
|
||||
1: StateProbe match=0 next=2
|
||||
2: StateProbe match=0 next=3
|
||||
3: StateProbe match=0 next=3 learner
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
3: StateProbe match=0 next=2 learner
|
||||
|
||||
simple
|
||||
r1 v5
|
||||
@@ -46,11 +46,11 @@ simple
|
||||
l2 l3 l4 l5
|
||||
----
|
||||
voters=(1) learners=(2 3 4 5)
|
||||
1: StateProbe match=0 next=2
|
||||
2: StateProbe match=0 next=3 learner
|
||||
3: StateProbe match=0 next=3 learner
|
||||
4: StateProbe match=0 next=9 learner
|
||||
5: StateProbe match=0 next=9 learner
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2 learner
|
||||
3: StateProbe match=0 next=2 learner
|
||||
4: StateProbe match=0 next=8 learner
|
||||
5: StateProbe match=0 next=8 learner
|
||||
|
||||
simple
|
||||
r1
|
||||
@@ -61,4 +61,4 @@ simple
|
||||
r2 r3 r4 r5
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=1
|
||||
|
10
raft/confchange/testdata/update.txt
vendored
10
raft/confchange/testdata/update.txt
vendored
@@ -6,18 +6,18 @@ simple
|
||||
v1
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
||||
simple
|
||||
v2 u1
|
||||
----
|
||||
voters=(1 2)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
|
||||
simple
|
||||
u1 u2 u3 u1 u2 u3
|
||||
----
|
||||
voters=(1 2)
|
||||
1: StateProbe match=0 next=1
|
||||
2: StateProbe match=0 next=2
|
||||
1: StateProbe match=0 next=0
|
||||
2: StateProbe match=0 next=1
|
||||
|
2
raft/confchange/testdata/zero.txt
vendored
2
raft/confchange/testdata/zero.txt
vendored
@@ -3,4 +3,4 @@ simple
|
||||
v1 r0 v0 l0
|
||||
----
|
||||
voters=(1)
|
||||
1: StateProbe match=0 next=1
|
||||
1: StateProbe match=0 next=0
|
||||
|
@@ -22,6 +22,9 @@ import (
|
||||
)
|
||||
|
||||
func TestInteraction(t *testing.T) {
|
||||
// NB: if this test fails, run `go test ./raft -rewrite` and inspect the
|
||||
// diff. Only commit the changes if you understand what caused them and if
|
||||
// they are desired.
|
||||
datadriven.Walk(t, "testdata", func(t *testing.T, path string) {
|
||||
env := rafttest.NewInteractionEnv(nil)
|
||||
datadriven.RunTest(t, path, func(d *datadriven.TestData) string {
|
||||
|
@@ -265,7 +265,7 @@ func TestLogMaybeAppend(t *testing.T) {
|
||||
t.Fatalf("unexpected error %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(tt.ents, gents) {
|
||||
t.Errorf("%d: appended entries = %v, want %v", i, gents, tt.ents)
|
||||
t.Errorf("#%d: appended entries = %v, want %v", i, gents, tt.ents)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -426,7 +426,7 @@ func TestUnstableEnts(t *testing.T) {
|
||||
|
||||
ents := raftLog.unstableEntries()
|
||||
if l := len(ents); l > 0 {
|
||||
raftLog.stableTo(ents[l-1].Index, ents[l-i].Term)
|
||||
raftLog.stableTo(ents[l-1].Index, ents[l-1].Term)
|
||||
}
|
||||
if !reflect.DeepEqual(ents, tt.wents) {
|
||||
t.Errorf("#%d: unstableEnts = %+v, want %+v", i, ents, tt.wents)
|
||||
@@ -671,13 +671,13 @@ func TestIsOutOfBounds(t *testing.T) {
|
||||
}()
|
||||
err := l.mustCheckOutOfBounds(tt.lo, tt.hi)
|
||||
if tt.wpanic {
|
||||
t.Errorf("%d: panic = %v, want %v", i, false, true)
|
||||
t.Errorf("#%d: panic = %v, want %v", i, false, true)
|
||||
}
|
||||
if tt.wErrCompacted && err != ErrCompacted {
|
||||
t.Errorf("%d: err = %v, want %v", i, err, ErrCompacted)
|
||||
t.Errorf("#%d: err = %v, want %v", i, err, ErrCompacted)
|
||||
}
|
||||
if !tt.wErrCompacted && err != nil {
|
||||
t.Errorf("%d: unexpected err %v", i, err)
|
||||
t.Errorf("#%d: unexpected err %v", i, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@@ -55,10 +55,7 @@ func (u *unstable) maybeLastIndex() (uint64, bool) {
|
||||
// is any.
|
||||
func (u *unstable) maybeTerm(i uint64) (uint64, bool) {
|
||||
if i < u.offset {
|
||||
if u.snapshot == nil {
|
||||
return 0, false
|
||||
}
|
||||
if u.snapshot.Metadata.Index == i {
|
||||
if u.snapshot != nil && u.snapshot.Metadata.Index == i {
|
||||
return u.snapshot.Metadata.Term, true
|
||||
}
|
||||
return 0, false
|
||||
@@ -71,6 +68,7 @@ func (u *unstable) maybeTerm(i uint64) (uint64, bool) {
|
||||
if i > last {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return u.entries[i-u.offset].Term, true
|
||||
}
|
||||
|
||||
|
50
raft/raft.go
50
raft/raft.go
@@ -367,7 +367,7 @@ func newRaft(c *Config) *raft {
|
||||
}
|
||||
assertConfStatesEquivalent(r.logger, cs, r.switchToConfig(cfg, prs))
|
||||
|
||||
if !isHardStateEqual(hs, emptyState) {
|
||||
if !IsEmptyHardState(hs) {
|
||||
r.loadState(hs)
|
||||
}
|
||||
if c.Applied > 0 {
|
||||
@@ -1036,10 +1036,36 @@ func stepLeader(r *raft, m pb.Message) error {
|
||||
|
||||
for i := range m.Entries {
|
||||
e := &m.Entries[i]
|
||||
if e.Type == pb.EntryConfChange || e.Type == pb.EntryConfChangeV2 {
|
||||
if r.pendingConfIndex > r.raftLog.applied {
|
||||
r.logger.Infof("%x propose conf %s ignored since pending unapplied configuration [index %d, applied %d]",
|
||||
r.id, e, r.pendingConfIndex, r.raftLog.applied)
|
||||
var cc pb.ConfChangeI
|
||||
if e.Type == pb.EntryConfChange {
|
||||
var ccc pb.ConfChange
|
||||
if err := ccc.Unmarshal(e.Data); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cc = ccc
|
||||
} else if e.Type == pb.EntryConfChangeV2 {
|
||||
var ccc pb.ConfChangeV2
|
||||
if err := ccc.Unmarshal(e.Data); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cc = ccc
|
||||
}
|
||||
if cc != nil {
|
||||
alreadyPending := r.pendingConfIndex > r.raftLog.applied
|
||||
alreadyJoint := len(r.prs.Config.Voters[1]) > 0
|
||||
wantsLeaveJoint := len(cc.AsV2().Changes) == 0
|
||||
|
||||
var refused string
|
||||
if alreadyPending {
|
||||
refused = fmt.Sprintf("possible unapplied conf change at index %d (applied to %d)", r.pendingConfIndex, r.raftLog.applied)
|
||||
} else if alreadyJoint && !wantsLeaveJoint {
|
||||
refused = "must transition out of joint config first"
|
||||
} else if !alreadyJoint && wantsLeaveJoint {
|
||||
refused = "not in joint state; refusing empty conf change"
|
||||
}
|
||||
|
||||
if refused != "" {
|
||||
r.logger.Infof("%x ignoring conf change %v at config %s: %s", r.id, cc, r.prs.Config, refused)
|
||||
m.Entries[i] = pb.Entry{Type: pb.EntryNormal}
|
||||
} else {
|
||||
r.pendingConfIndex = r.raftLog.lastIndex() + uint64(i) + 1
|
||||
@@ -1073,7 +1099,7 @@ func stepLeader(r *raft, m pb.Message) error {
|
||||
case ReadOnlyLeaseBased:
|
||||
ri := r.raftLog.committed
|
||||
if m.From == None || m.From == r.id { // from local member
|
||||
r.readStates = append(r.readStates, ReadState{Index: r.raftLog.committed, RequestCtx: m.Entries[0].Data})
|
||||
r.readStates = append(r.readStates, ReadState{Index: ri, RequestCtx: m.Entries[0].Data})
|
||||
} else {
|
||||
r.send(pb.Message{To: m.From, Type: pb.MsgReadIndexResp, Index: ri, Entries: m.Entries})
|
||||
}
|
||||
@@ -1527,10 +1553,18 @@ func (r *raft) switchToConfig(cfg tracker.Config, prs tracker.ProgressMap) pb.Co
|
||||
if r.state != StateLeader || len(cs.Voters) == 0 {
|
||||
return cs
|
||||
}
|
||||
|
||||
if r.maybeCommit() {
|
||||
// The quorum size may have been reduced (but not to zero), so see if
|
||||
// any pending entries can be committed.
|
||||
// If the configuration change means that more entries are committed now,
|
||||
// broadcast/append to everyone in the updated config.
|
||||
r.bcastAppend()
|
||||
} else {
|
||||
// Otherwise, still probe the newly added replicas; there's no reason to
|
||||
// let them wait out a heartbeat interval (or the next incoming
|
||||
// proposal).
|
||||
r.prs.Visit(func(id uint64, pr *tracker.Progress) {
|
||||
r.maybeSendAppend(id, false /* sendIfEmpty */)
|
||||
})
|
||||
}
|
||||
// If the the leadTransferee was removed, abort the leadership transfer.
|
||||
if _, tOK := r.prs.Progress[r.leadTransferee]; !tOK && r.leadTransferee != 0 {
|
||||
|
@@ -30,6 +30,16 @@ func (env *InteractionEnv) Handle(t *testing.T, d datadriven.TestData) string {
|
||||
env.Output.Reset()
|
||||
var err error
|
||||
switch d.Cmd {
|
||||
case "_breakpoint":
|
||||
// This is a helper case to attach a debugger to when a problem needs
|
||||
// to be investigated in a longer test file. In such a case, add the
|
||||
// following stanza immediately before the interesting behavior starts:
|
||||
//
|
||||
// _breakpoint:
|
||||
// ----
|
||||
// ok
|
||||
//
|
||||
// and set a breakpoint on the `case` above.
|
||||
case "add-nodes":
|
||||
// Example:
|
||||
//
|
||||
@@ -94,6 +104,13 @@ func (env *InteractionEnv) Handle(t *testing.T, d datadriven.TestData) string {
|
||||
//
|
||||
// tick-heartbeat 3
|
||||
err = env.handleTickHeartbeat(t, d)
|
||||
case "propose":
|
||||
// Propose an entry.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// propose 1 foo
|
||||
err = env.handlePropose(t, d)
|
||||
case "propose-conf-change":
|
||||
// Propose a configuration change.
|
||||
//
|
||||
|
@@ -15,8 +15,8 @@
|
||||
package rafttest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/cockroachdb/datadriven"
|
||||
@@ -25,34 +25,70 @@ import (
|
||||
)
|
||||
|
||||
func (env *InteractionEnv) handleDeliverMsgs(t *testing.T, d datadriven.TestData) error {
|
||||
if len(env.Messages) == 0 {
|
||||
return errors.New("no messages to deliver")
|
||||
var rs []Recipient
|
||||
for _, arg := range d.CmdArgs {
|
||||
if len(arg.Vals) == 0 {
|
||||
id, err := strconv.ParseUint(arg.Key, 10, 64)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rs = append(rs, Recipient{ID: id})
|
||||
}
|
||||
for i := range arg.Vals {
|
||||
switch arg.Key {
|
||||
case "drop":
|
||||
var id uint64
|
||||
arg.Scan(t, i, &id)
|
||||
var found bool
|
||||
for _, r := range rs {
|
||||
if r.ID == id {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
t.Fatalf("can't both deliver and drop msgs to %d", id)
|
||||
}
|
||||
rs = append(rs, Recipient{ID: id, Drop: true})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msgs := env.Messages
|
||||
env.Messages = nil
|
||||
|
||||
return env.DeliverMsgs(msgs)
|
||||
}
|
||||
|
||||
// DeliverMsgs delivers the supplied messages typically taken from env.Messages.
|
||||
func (env *InteractionEnv) DeliverMsgs(msgs []raftpb.Message) error {
|
||||
for _, msg := range msgs {
|
||||
toIdx := int(msg.To - 1)
|
||||
var drop bool
|
||||
if toIdx >= len(env.Nodes) {
|
||||
// Drop messages for peers that don't exist yet.
|
||||
drop = true
|
||||
env.Output.WriteString("dropped: ")
|
||||
}
|
||||
fmt.Fprintln(env.Output, raft.DescribeMessage(msg, defaultEntryFormatter))
|
||||
if drop {
|
||||
continue
|
||||
}
|
||||
if err := env.Nodes[toIdx].Step(msg); err != nil {
|
||||
env.Output.WriteString(err.Error())
|
||||
continue
|
||||
}
|
||||
if n := env.DeliverMsgs(rs...); n == 0 {
|
||||
env.Output.WriteString("no messages\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Recipient struct {
|
||||
ID uint64
|
||||
Drop bool
|
||||
}
|
||||
|
||||
// DeliverMsgs goes through env.Messages and, depending on the Drop flag,
|
||||
// delivers or drops messages to the specified Recipients. Returns the
|
||||
// number of messages handled (i.e. delivered or dropped). A handled message
|
||||
// is removed from env.Messages.
|
||||
func (env *InteractionEnv) DeliverMsgs(rs ...Recipient) int {
|
||||
var n int
|
||||
for _, r := range rs {
|
||||
var msgs []raftpb.Message
|
||||
msgs, env.Messages = splitMsgs(env.Messages, r.ID)
|
||||
n += len(msgs)
|
||||
for _, msg := range msgs {
|
||||
if r.Drop {
|
||||
fmt.Fprint(env.Output, "dropped: ")
|
||||
}
|
||||
fmt.Fprintln(env.Output, raft.DescribeMessage(msg, defaultEntryFormatter))
|
||||
if r.Drop {
|
||||
// NB: it's allowed to drop messages to nodes that haven't been instantiated yet,
|
||||
// we haven't used msg.To yet.
|
||||
continue
|
||||
}
|
||||
toIdx := int(msg.To - 1)
|
||||
if err := env.Nodes[toIdx].Step(msg); err != nil {
|
||||
env.Output.WriteString(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
"github.com/cockroachdb/datadriven"
|
||||
"go.etcd.io/etcd/raft"
|
||||
"go.etcd.io/etcd/raft/quorum"
|
||||
"go.etcd.io/etcd/raft/raftpb"
|
||||
)
|
||||
|
||||
@@ -33,6 +32,7 @@ func (env *InteractionEnv) ProcessReady(idx int) error {
|
||||
// TODO(tbg): Allow simulating crashes here.
|
||||
rn, s := env.Nodes[idx].RawNode, env.Nodes[idx].Storage
|
||||
rd := rn.Ready()
|
||||
env.Output.WriteString(raft.DescribeReady(rd, defaultEntryFormatter))
|
||||
// TODO(tbg): the order of operations here is not necessarily safe. See:
|
||||
// https://github.com/etcd-io/etcd/pull/10861
|
||||
if !raft.IsEmptyHardState(rd.HardState) {
|
||||
@@ -50,6 +50,7 @@ func (env *InteractionEnv) ProcessReady(idx int) error {
|
||||
}
|
||||
for _, ent := range rd.CommittedEntries {
|
||||
var update []byte
|
||||
var cs *raftpb.ConfState
|
||||
switch ent.Type {
|
||||
case raftpb.EntryConfChange:
|
||||
var cc raftpb.ConfChange
|
||||
@@ -57,13 +58,13 @@ func (env *InteractionEnv) ProcessReady(idx int) error {
|
||||
return err
|
||||
}
|
||||
update = cc.Context
|
||||
rn.ApplyConfChange(cc)
|
||||
cs = rn.ApplyConfChange(cc)
|
||||
case raftpb.EntryConfChangeV2:
|
||||
var cc raftpb.ConfChangeV2
|
||||
if err := cc.Unmarshal(ent.Data); err != nil {
|
||||
return err
|
||||
}
|
||||
rn.ApplyConfChange(cc)
|
||||
cs = rn.ApplyConfChange(cc)
|
||||
update = cc.Context
|
||||
default:
|
||||
update = ent.Data
|
||||
@@ -78,19 +79,16 @@ func (env *InteractionEnv) ProcessReady(idx int) error {
|
||||
snap.Data = append(snap.Data, update...)
|
||||
snap.Metadata.Index = ent.Index
|
||||
snap.Metadata.Term = ent.Term
|
||||
cfg := rn.Status().Config
|
||||
snap.Metadata.ConfState = raftpb.ConfState{
|
||||
Voters: cfg.Voters[0].Slice(),
|
||||
VotersOutgoing: cfg.Voters[1].Slice(),
|
||||
Learners: quorum.MajorityConfig(cfg.Learners).Slice(),
|
||||
LearnersNext: quorum.MajorityConfig(cfg.LearnersNext).Slice(),
|
||||
if cs == nil {
|
||||
sl := env.Nodes[idx].History
|
||||
cs = &sl[len(sl)-1].Metadata.ConfState
|
||||
}
|
||||
snap.Metadata.ConfState = *cs
|
||||
env.Nodes[idx].History = append(env.Nodes[idx].History, snap)
|
||||
}
|
||||
for _, msg := range rd.Messages {
|
||||
env.Messages = append(env.Messages, msg)
|
||||
}
|
||||
rn.Advance(rd)
|
||||
env.Output.WriteString(raft.DescribeReady(rd, defaultEntryFormatter))
|
||||
return nil
|
||||
}
|
||||
|
34
raft/rafttest/interaction_env_handler_propose.go
Normal file
34
raft/rafttest/interaction_env_handler_propose.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2019 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package rafttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cockroachdb/datadriven"
|
||||
)
|
||||
|
||||
func (env *InteractionEnv) handlePropose(t *testing.T, d datadriven.TestData) error {
|
||||
idx := firstAsNodeIdx(t, d)
|
||||
if len(d.CmdArgs) != 2 || len(d.CmdArgs[1].Vals) > 0 {
|
||||
t.Fatalf("expected exactly one key with no vals: %+v", d.CmdArgs[1:])
|
||||
}
|
||||
return env.Propose(idx, []byte(d.CmdArgs[1].Key))
|
||||
}
|
||||
|
||||
// Propose a regular entry.
|
||||
func (env *InteractionEnv) Propose(idx int, data []byte) error {
|
||||
return env.Nodes[idx].Propose(data)
|
||||
}
|
@@ -65,22 +65,24 @@ func (env *InteractionEnv) Stabilize(idxs ...int) error {
|
||||
withIndent(func() { env.ProcessReady(idx) })
|
||||
}
|
||||
}
|
||||
var msgs []raftpb.Message
|
||||
for _, rn := range nodes {
|
||||
msgs, env.Messages = splitMsgs(env.Messages, rn.Status().ID)
|
||||
if len(msgs) > 0 {
|
||||
fmt.Fprintf(env.Output, "> delivering messages\n")
|
||||
withIndent(func() { env.DeliverMsgs(msgs) })
|
||||
id := rn.Status().ID
|
||||
// NB: we grab the messages just to see whether to print the header.
|
||||
// DeliverMsgs will do it again.
|
||||
if msgs, _ := splitMsgs(env.Messages, id); len(msgs) > 0 {
|
||||
fmt.Fprintf(env.Output, "> %d receiving messages\n", id)
|
||||
withIndent(func() { env.DeliverMsgs(Recipient{ID: id}) })
|
||||
done = false
|
||||
}
|
||||
if done {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if done {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func splitMsgs(msgs []raftpb.Message, to uint64) (toMsgs []raftpb.Message, rmdr []raftpb.Message) {
|
||||
// NB: this method does not reorder messages.
|
||||
for _, msg := range msgs {
|
||||
if msg.To == to {
|
||||
toMsgs = append(toMsgs, msg)
|
||||
|
@@ -106,7 +106,7 @@ func TestStorageLastIndex(t *testing.T) {
|
||||
t.Errorf("err = %v, want nil", err)
|
||||
}
|
||||
if last != 5 {
|
||||
t.Errorf("term = %d, want %d", last, 5)
|
||||
t.Errorf("last = %d, want %d", last, 5)
|
||||
}
|
||||
|
||||
s.Append([]pb.Entry{{Index: 6, Term: 5}})
|
||||
@@ -115,7 +115,7 @@ func TestStorageLastIndex(t *testing.T) {
|
||||
t.Errorf("err = %v, want nil", err)
|
||||
}
|
||||
if last != 6 {
|
||||
t.Errorf("last = %d, want %d", last, 5)
|
||||
t.Errorf("last = %d, want %d", last, 6)
|
||||
}
|
||||
}
|
||||
|
||||
|
18
raft/testdata/campaign.txt
vendored
18
raft/testdata/campaign.txt
vendored
@@ -31,12 +31,12 @@ stabilize
|
||||
Messages:
|
||||
1->2 MsgVote Term:1 Log:1/2
|
||||
1->3 MsgVote Term:1 Log:1/2
|
||||
> delivering messages
|
||||
> 2 receiving messages
|
||||
1->2 MsgVote Term:1 Log:1/2
|
||||
INFO 2 [term: 0] received a MsgVote message with higher term from 1 [term: 1]
|
||||
INFO 2 became follower at term 1
|
||||
INFO 2 [logterm: 1, index: 2, vote: 0] cast MsgVote for 1 [logterm: 1, index: 2] at term 1
|
||||
> delivering messages
|
||||
> 3 receiving messages
|
||||
1->3 MsgVote Term:1 Log:1/2
|
||||
INFO 3 [term: 0] received a MsgVote message with higher term from 1 [term: 1]
|
||||
INFO 3 became follower at term 1
|
||||
@@ -51,7 +51,7 @@ stabilize
|
||||
HardState Term:1 Vote:1 Commit:2
|
||||
Messages:
|
||||
3->1 MsgVoteResp Term:1 Log:0/0
|
||||
> delivering messages
|
||||
> 1 receiving messages
|
||||
2->1 MsgVoteResp Term:1 Log:0/0
|
||||
INFO 1 received MsgVoteResp from 2 at term 1
|
||||
INFO 1 has received 2 MsgVoteResp votes and 0 vote rejections
|
||||
@@ -65,9 +65,9 @@ stabilize
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/2 Commit:2 Entries:[1/3 EntryNormal ""]
|
||||
1->3 MsgApp Term:1 Log:1/2 Commit:2 Entries:[1/3 EntryNormal ""]
|
||||
> delivering messages
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/2 Commit:2 Entries:[1/3 EntryNormal ""]
|
||||
> delivering messages
|
||||
> 3 receiving messages
|
||||
1->3 MsgApp Term:1 Log:1/2 Commit:2 Entries:[1/3 EntryNormal ""]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
@@ -83,7 +83,7 @@ stabilize
|
||||
1/3 EntryNormal ""
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/3
|
||||
> delivering messages
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/3
|
||||
3->1 MsgAppResp Term:1 Log:0/3
|
||||
> 1 handling Ready
|
||||
@@ -94,9 +94,9 @@ stabilize
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:3
|
||||
1->3 MsgApp Term:1 Log:1/3 Commit:3
|
||||
> delivering messages
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:3
|
||||
> delivering messages
|
||||
> 3 receiving messages
|
||||
1->3 MsgApp Term:1 Log:1/3 Commit:3
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
@@ -112,6 +112,6 @@ stabilize
|
||||
1/3 EntryNormal ""
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/3
|
||||
> delivering messages
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/3
|
||||
3->1 MsgAppResp Term:1 Log:0/3
|
||||
|
152
raft/testdata/campaign_learner_must_vote.txt
vendored
Normal file
152
raft/testdata/campaign_learner_must_vote.txt
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
# Regression test that verifies that learners can vote. This holds only in the
|
||||
# sense that if a learner is asked to vote, a candidate believes that they are a
|
||||
# voter based on its current config, which may be more recent than that of the
|
||||
# learner. If learners which are actually voters but don't know it yet don't
|
||||
# vote in that situation, the raft group may end up unavailable despite a quorum
|
||||
# of voters (as of the latest config) being available.
|
||||
#
|
||||
# See:
|
||||
# https://github.com/etcd-io/etcd/pull/10998
|
||||
|
||||
# Turn output off during boilerplate.
|
||||
log-level none
|
||||
----
|
||||
ok
|
||||
|
||||
# Bootstrap three nodes.
|
||||
add-nodes 3 voters=(1,2) learners=(3) index=2
|
||||
----
|
||||
ok
|
||||
|
||||
# n1 gets to be leader.
|
||||
campaign 1
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize
|
||||
----
|
||||
ok (quiet)
|
||||
|
||||
# Propose a conf change on n1 that promotes n3 to voter.
|
||||
propose-conf-change 1
|
||||
v3
|
||||
----
|
||||
ok
|
||||
|
||||
# Commit and fully apply said conf change. n1 and n2 now consider n3 a voter.
|
||||
stabilize 1 2
|
||||
----
|
||||
ok (quiet)
|
||||
|
||||
# Drop all inflight messages to 3. We don't want it to be caught up when it is
|
||||
# asked to vote.
|
||||
deliver-msgs drop=(3)
|
||||
----
|
||||
ok (quiet)
|
||||
|
||||
# We now pretend that n1 is dead, and n2 is trying to become leader.
|
||||
|
||||
log-level debug
|
||||
----
|
||||
ok
|
||||
|
||||
campaign 2
|
||||
----
|
||||
INFO 2 is starting a new election at term 1
|
||||
INFO 2 became candidate at term 2
|
||||
INFO 2 received MsgVoteResp from 2 at term 2
|
||||
INFO 2 [logterm: 1, index: 4] sent MsgVote request to 1 at term 2
|
||||
INFO 2 [logterm: 1, index: 4] sent MsgVote request to 3 at term 2
|
||||
|
||||
# Send out the MsgVote requests.
|
||||
process-ready 2
|
||||
----
|
||||
Ready MustSync=true:
|
||||
Lead:0 State:StateCandidate
|
||||
HardState Term:2 Vote:2 Commit:4
|
||||
Messages:
|
||||
2->1 MsgVote Term:2 Log:1/4
|
||||
2->3 MsgVote Term:2 Log:1/4
|
||||
|
||||
# n2 is now campaigning while n1 is down (does not respond). The latest config
|
||||
# has n3 as a voter, but n3 doesn't even have the corresponding conf change in
|
||||
# its log. Still, it casts a vote for n2 which can in turn become leader and
|
||||
# catches up n3.
|
||||
stabilize 3
|
||||
----
|
||||
> 3 receiving messages
|
||||
2->3 MsgVote Term:2 Log:1/4
|
||||
INFO 3 [term: 1] received a MsgVote message with higher term from 2 [term: 2]
|
||||
INFO 3 became follower at term 2
|
||||
INFO 3 [logterm: 1, index: 3, vote: 0] cast MsgVote for 2 [logterm: 1, index: 4] at term 2
|
||||
> 3 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:0 State:StateFollower
|
||||
HardState Term:2 Vote:2 Commit:3
|
||||
Messages:
|
||||
3->2 MsgVoteResp Term:2 Log:0/0
|
||||
|
||||
stabilize 2 3
|
||||
----
|
||||
> 2 receiving messages
|
||||
3->2 MsgVoteResp Term:2 Log:0/0
|
||||
INFO 2 received MsgVoteResp from 3 at term 2
|
||||
INFO 2 has received 2 MsgVoteResp votes and 0 vote rejections
|
||||
INFO 2 became leader at term 2
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:2 State:StateLeader
|
||||
Entries:
|
||||
2/5 EntryNormal ""
|
||||
Messages:
|
||||
2->1 MsgApp Term:2 Log:1/4 Commit:4 Entries:[2/5 EntryNormal ""]
|
||||
2->3 MsgApp Term:2 Log:1/4 Commit:4 Entries:[2/5 EntryNormal ""]
|
||||
> 3 receiving messages
|
||||
2->3 MsgApp Term:2 Log:1/4 Commit:4 Entries:[2/5 EntryNormal ""]
|
||||
DEBUG 3 [logterm: 0, index: 4] rejected MsgApp [logterm: 1, index: 4] from 2
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
Lead:2 State:StateFollower
|
||||
Messages:
|
||||
3->2 MsgAppResp Term:2 Log:0/4 Rejected (Hint: 3)
|
||||
> 2 receiving messages
|
||||
3->2 MsgAppResp Term:2 Log:0/4 Rejected (Hint: 3)
|
||||
DEBUG 2 received MsgAppResp(MsgApp was rejected, lastindex: 3) from 3 for index 4
|
||||
DEBUG 2 decreased progress of 3 to [StateProbe match=0 next=4]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
2->3 MsgApp Term:2 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v3, 2/5 EntryNormal ""]
|
||||
> 3 receiving messages
|
||||
2->3 MsgApp Term:2 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v3, 2/5 EntryNormal ""]
|
||||
> 3 handling Ready
|
||||
Ready MustSync=true:
|
||||
HardState Term:2 Vote:2 Commit:4
|
||||
Entries:
|
||||
1/4 EntryConfChangeV2 v3
|
||||
2/5 EntryNormal ""
|
||||
CommittedEntries:
|
||||
1/4 EntryConfChangeV2 v3
|
||||
Messages:
|
||||
3->2 MsgAppResp Term:2 Log:0/5
|
||||
INFO 3 switched to configuration voters=(1 2 3)
|
||||
> 2 receiving messages
|
||||
3->2 MsgAppResp Term:2 Log:0/5
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:2 Vote:2 Commit:5
|
||||
CommittedEntries:
|
||||
2/5 EntryNormal ""
|
||||
Messages:
|
||||
2->3 MsgApp Term:2 Log:2/5 Commit:5
|
||||
> 3 receiving messages
|
||||
2->3 MsgApp Term:2 Log:2/5 Commit:5
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:2 Vote:2 Commit:5
|
||||
CommittedEntries:
|
||||
2/5 EntryNormal ""
|
||||
Messages:
|
||||
3->2 MsgAppResp Term:2 Log:0/5
|
||||
> 2 receiving messages
|
||||
3->2 MsgAppResp Term:2 Log:0/5
|
78
raft/testdata/confchange_v1.txt
vendored
78
raft/testdata/confchange_v1.txt
vendored
@@ -1,78 +0,0 @@
|
||||
add-nodes 1 voters=(1) index=2
|
||||
----
|
||||
INFO 1 switched to configuration voters=(1)
|
||||
INFO 1 became follower at term 0
|
||||
INFO newRaft 1 [peers: [1], term: 0, commit: 2, applied: 2, lastindex: 2, lastterm: 1]
|
||||
|
||||
campaign 1
|
||||
----
|
||||
INFO 1 is starting a new election at term 0
|
||||
INFO 1 became candidate at term 1
|
||||
INFO 1 received MsgVoteResp from 1 at term 1
|
||||
INFO 1 became leader at term 1
|
||||
|
||||
propose-conf-change 1
|
||||
v2 v3
|
||||
----
|
||||
ok
|
||||
|
||||
add-nodes 2
|
||||
|
||||
process-ready 1
|
||||
----
|
||||
INFO 2 switched to configuration voters=()
|
||||
INFO 2 became follower at term 0
|
||||
INFO newRaft 2 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
INFO 3 switched to configuration voters=()
|
||||
INFO 3 became follower at term 0
|
||||
INFO newRaft 3 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
|
||||
stabilize 1
|
||||
----
|
||||
> 1 handling Ready
|
||||
INFO 1 switched to configuration voters=(1 2 3)&&(1) autoleave
|
||||
INFO initiating automatic transition out of joint configuration voters=(1 2 3)&&(1) autoleave
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateLeader
|
||||
HardState Term:1 Vote:1 Commit:4
|
||||
Entries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2 v3
|
||||
CommittedEntries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2 v3
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryConfChangeV2
|
||||
|
||||
# NB: this test is broken from here on because the leader doesn't propagate the
|
||||
# commit index proactively, see the buglet #11002.
|
||||
|
||||
stabilize 2
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize 1
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize 2
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize 1
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize 2
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize 1
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize 2
|
||||
----
|
||||
ok
|
97
raft/testdata/confchange_v1_add_single.txt
vendored
Normal file
97
raft/testdata/confchange_v1_add_single.txt
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
# Run a V1 membership change that adds a single voter.
|
||||
|
||||
# Bootstrap n1.
|
||||
add-nodes 1 voters=(1) index=2
|
||||
----
|
||||
INFO 1 switched to configuration voters=(1)
|
||||
INFO 1 became follower at term 0
|
||||
INFO newRaft 1 [peers: [1], term: 0, commit: 2, applied: 2, lastindex: 2, lastterm: 1]
|
||||
|
||||
campaign 1
|
||||
----
|
||||
INFO 1 is starting a new election at term 0
|
||||
INFO 1 became candidate at term 1
|
||||
INFO 1 received MsgVoteResp from 1 at term 1
|
||||
INFO 1 became leader at term 1
|
||||
|
||||
# Add v2 (with an auto transition).
|
||||
propose-conf-change 1 v1=true
|
||||
v2
|
||||
----
|
||||
ok
|
||||
|
||||
# Pull n2 out of thin air.
|
||||
add-nodes 1
|
||||
----
|
||||
INFO 2 switched to configuration voters=()
|
||||
INFO 2 became follower at term 0
|
||||
INFO newRaft 2 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
|
||||
# n1 commits the conf change using itself as commit quorum, immediately transitions into
|
||||
# the final config, and catches up n2. Note that it's using an EntryConfChange, not an
|
||||
# EntryConfChangeV2, so this is compatible with nodes that don't know about V2 conf changes.
|
||||
stabilize
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateLeader
|
||||
HardState Term:1 Vote:1 Commit:4
|
||||
Entries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChange v2
|
||||
CommittedEntries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChange v2
|
||||
INFO 1 switched to configuration voters=(1 2)
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChange v2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChange v2]
|
||||
INFO 2 [term: 0] received a MsgApp message with higher term from 1 [term: 1]
|
||||
INFO 2 became follower at term 1
|
||||
DEBUG 2 [logterm: 0, index: 3] rejected MsgApp [logterm: 1, index: 3] from 1
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateFollower
|
||||
HardState Term:1 Commit:0
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
DEBUG 1 received MsgAppResp(MsgApp was rejected, lastindex: 0) from 2 for index 3
|
||||
DEBUG 1 decreased progress of 2 to [StateProbe match=0 next=1]
|
||||
DEBUG 1 [firstindex: 3, commit: 4] sent snapshot[index: 4, term: 1] to 2 [StateProbe match=0 next=1]
|
||||
DEBUG 1 paused sending replication messages to 2 [StateSnapshot match=0 next=1 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
> 2 receiving messages
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
INFO log [committed=0, applied=0, unstable.offset=1, len(unstable.Entries)=0] starts to restore snapshot [index: 4, term: 1]
|
||||
INFO 2 switched to configuration voters=(1 2)
|
||||
INFO 2 [commit: 4, lastindex: 4, lastterm: 1] restored snapshot [index: 4, term: 1]
|
||||
INFO 2 [commit: 4] restored snapshot [index: 4, term: 1]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:4
|
||||
Snapshot Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
DEBUG 1 recovered from needing snapshot, resumed sending replication messages to 2 [StateSnapshot match=4 next=5 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
224
raft/testdata/confchange_v1_remove_leader.txt
vendored
Normal file
224
raft/testdata/confchange_v1_remove_leader.txt
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
# We'll turn this back on after the boilerplate.
|
||||
log-level none
|
||||
----
|
||||
ok
|
||||
|
||||
# Run a V1 membership change that removes the leader.
|
||||
# Bootstrap n1, n2, n3.
|
||||
add-nodes 3 voters=(1,2,3) index=2
|
||||
----
|
||||
ok
|
||||
|
||||
campaign 1
|
||||
----
|
||||
ok
|
||||
|
||||
stabilize
|
||||
----
|
||||
ok (quiet)
|
||||
|
||||
log-level debug
|
||||
----
|
||||
ok
|
||||
|
||||
# Start removing n1.
|
||||
propose-conf-change 1 v1=true
|
||||
r1
|
||||
----
|
||||
ok
|
||||
|
||||
# Propose an extra entry which will be sent out together with the conf change.
|
||||
propose 1 foo
|
||||
----
|
||||
ok
|
||||
|
||||
# Send out the corresponding appends.
|
||||
process-ready 1
|
||||
----
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/4 EntryConfChange r1
|
||||
1/5 EntryNormal "foo"
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:3 Entries:[1/4 EntryConfChange r1]
|
||||
1->3 MsgApp Term:1 Log:1/3 Commit:3 Entries:[1/4 EntryConfChange r1]
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:3 Entries:[1/5 EntryNormal "foo"]
|
||||
1->3 MsgApp Term:1 Log:1/4 Commit:3 Entries:[1/5 EntryNormal "foo"]
|
||||
|
||||
# Send response from n2 (which is enough to commit the entries so far next time
|
||||
# n1 runs).
|
||||
stabilize 2
|
||||
----
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:3 Entries:[1/4 EntryConfChange r1]
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:3 Entries:[1/5 EntryNormal "foo"]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/4 EntryConfChange r1
|
||||
1/5 EntryNormal "foo"
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
|
||||
# Put another entry in n1's log.
|
||||
propose 1 bar
|
||||
----
|
||||
ok
|
||||
|
||||
# n1 applies the conf change, so it has now removed itself. But it still has
|
||||
# an uncommitted entry in the log. If the leader unconditionally counted itself
|
||||
# as part of the commit quorum, we'd be in trouble. In the block below, we see
|
||||
# it send out appends to the other nodes for the 'bar' entry.
|
||||
stabilize 1
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/6 EntryNormal "bar"
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:3 Entries:[1/6 EntryNormal "bar"]
|
||||
1->3 MsgApp Term:1 Log:1/5 Commit:3 Entries:[1/6 EntryNormal "bar"]
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:5
|
||||
CommittedEntries:
|
||||
1/4 EntryConfChange r1
|
||||
1/5 EntryNormal "foo"
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:4
|
||||
1->3 MsgApp Term:1 Log:1/6 Commit:4
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:5
|
||||
1->3 MsgApp Term:1 Log:1/6 Commit:5
|
||||
INFO 1 switched to configuration voters=(2 3)
|
||||
|
||||
# n2 responds, n3 doesn't yet. Quorum for 'bar' should not be reached...
|
||||
stabilize 2
|
||||
----
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:3 Entries:[1/6 EntryNormal "bar"]
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:4
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:5
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
HardState Term:1 Vote:1 Commit:5
|
||||
Entries:
|
||||
1/6 EntryNormal "bar"
|
||||
CommittedEntries:
|
||||
1/4 EntryConfChange r1
|
||||
1/5 EntryNormal "foo"
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
INFO 2 switched to configuration voters=(2 3)
|
||||
|
||||
# ... which thankfully is what we see on the leader.
|
||||
stabilize 1
|
||||
----
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
|
||||
# When n3 responds, quorum is reached and everything falls into place.
|
||||
stabilize
|
||||
----
|
||||
> 3 receiving messages
|
||||
1->3 MsgApp Term:1 Log:1/3 Commit:3 Entries:[1/4 EntryConfChange r1]
|
||||
1->3 MsgApp Term:1 Log:1/4 Commit:3 Entries:[1/5 EntryNormal "foo"]
|
||||
1->3 MsgApp Term:1 Log:1/5 Commit:3 Entries:[1/6 EntryNormal "bar"]
|
||||
1->3 MsgApp Term:1 Log:1/6 Commit:4
|
||||
1->3 MsgApp Term:1 Log:1/6 Commit:5
|
||||
> 3 handling Ready
|
||||
Ready MustSync=true:
|
||||
HardState Term:1 Vote:1 Commit:5
|
||||
Entries:
|
||||
1/4 EntryConfChange r1
|
||||
1/5 EntryNormal "foo"
|
||||
1/6 EntryNormal "bar"
|
||||
CommittedEntries:
|
||||
1/4 EntryConfChange r1
|
||||
1/5 EntryNormal "foo"
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/4
|
||||
3->1 MsgAppResp Term:1 Log:0/5
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
INFO 3 switched to configuration voters=(2 3)
|
||||
> 1 receiving messages
|
||||
3->1 MsgAppResp Term:1 Log:0/4
|
||||
3->1 MsgAppResp Term:1 Log:0/5
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:6
|
||||
CommittedEntries:
|
||||
1/6 EntryNormal "bar"
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6
|
||||
1->3 MsgApp Term:1 Log:1/6 Commit:6
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6
|
||||
> 3 receiving messages
|
||||
1->3 MsgApp Term:1 Log:1/6 Commit:6
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:6
|
||||
CommittedEntries:
|
||||
1/6 EntryNormal "bar"
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:6
|
||||
CommittedEntries:
|
||||
1/6 EntryNormal "bar"
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
3->1 MsgAppResp Term:1 Log:0/6
|
||||
|
||||
# However not all is well. n1 is still leader but unconditionally drops all
|
||||
# proposals on the floor, so we're effectively stuck if it still heartbeats
|
||||
# its followers...
|
||||
propose 1 baz
|
||||
----
|
||||
raft proposal dropped
|
||||
|
||||
tick-heartbeat 1
|
||||
----
|
||||
ok
|
||||
|
||||
# ... which, uh oh, it does.
|
||||
# TODO(tbg): change behavior so that a leader that is removed immediately steps
|
||||
# down, and initiates an optimistic handover.
|
||||
stabilize
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgHeartbeat Term:1 Log:0/0 Commit:6
|
||||
1->3 MsgHeartbeat Term:1 Log:0/0 Commit:6
|
||||
> 2 receiving messages
|
||||
1->2 MsgHeartbeat Term:1 Log:0/0 Commit:6
|
||||
> 3 receiving messages
|
||||
1->3 MsgHeartbeat Term:1 Log:0/0 Commit:6
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
2->1 MsgHeartbeatResp Term:1 Log:0/0
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
3->1 MsgHeartbeatResp Term:1 Log:0/0
|
||||
> 1 receiving messages
|
||||
2->1 MsgHeartbeatResp Term:1 Log:0/0
|
||||
3->1 MsgHeartbeatResp Term:1 Log:0/0
|
197
raft/testdata/confchange_v2_add_double_auto.txt
vendored
Normal file
197
raft/testdata/confchange_v2_add_double_auto.txt
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
# Run a V2 membership change that adds two voters at once and auto-leaves the
|
||||
# joint configuration. (This is the same as specifying an explicit transition
|
||||
# since more than one change is being made atomically).
|
||||
|
||||
# Bootstrap n1.
|
||||
add-nodes 1 voters=(1) index=2
|
||||
----
|
||||
INFO 1 switched to configuration voters=(1)
|
||||
INFO 1 became follower at term 0
|
||||
INFO newRaft 1 [peers: [1], term: 0, commit: 2, applied: 2, lastindex: 2, lastterm: 1]
|
||||
|
||||
campaign 1
|
||||
----
|
||||
INFO 1 is starting a new election at term 0
|
||||
INFO 1 became candidate at term 1
|
||||
INFO 1 received MsgVoteResp from 1 at term 1
|
||||
INFO 1 became leader at term 1
|
||||
|
||||
propose-conf-change 1 transition=auto
|
||||
v2 v3
|
||||
----
|
||||
ok
|
||||
|
||||
# Add two "empty" nodes to the cluster, n2 and n3.
|
||||
add-nodes 2
|
||||
----
|
||||
INFO 2 switched to configuration voters=()
|
||||
INFO 2 became follower at term 0
|
||||
INFO newRaft 2 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
INFO 3 switched to configuration voters=()
|
||||
INFO 3 became follower at term 0
|
||||
INFO newRaft 3 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
|
||||
# n1 immediately gets to commit & apply the conf change using only itself. We see that
|
||||
# it starts transitioning out of that joint configuration (though we will only see that
|
||||
# proposal in the next ready handling loop, when it is emitted). We also see that this
|
||||
# is using joint consensus, which it has to since we're carrying out two additions at
|
||||
# once.
|
||||
process-ready 1
|
||||
----
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateLeader
|
||||
HardState Term:1 Vote:1 Commit:4
|
||||
Entries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2 v3
|
||||
CommittedEntries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2 v3
|
||||
INFO 1 switched to configuration voters=(1 2 3)&&(1) autoleave
|
||||
INFO initiating automatic transition out of joint configuration voters=(1 2 3)&&(1) autoleave
|
||||
|
||||
# n1 immediately probes n2 and n3.
|
||||
stabilize 1
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2 v3]
|
||||
1->3 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2 v3]
|
||||
|
||||
# First, play out the whole interaction between n1 and n2. We see n1's probe to
|
||||
# n2 get rejected (since n2 needs a snapshot); the snapshot is delivered at which
|
||||
# point n2 switches to the correct config, and n1 catches it up. This notably
|
||||
# includes the empty conf change which gets committed and applied by both and
|
||||
# which transitions them out of their joint configuration into the final one (1 2 3).
|
||||
stabilize 1 2
|
||||
----
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2 v3]
|
||||
INFO 2 [term: 0] received a MsgApp message with higher term from 1 [term: 1]
|
||||
INFO 2 became follower at term 1
|
||||
DEBUG 2 [logterm: 0, index: 3] rejected MsgApp [logterm: 1, index: 3] from 1
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateFollower
|
||||
HardState Term:1 Commit:0
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
DEBUG 1 received MsgAppResp(MsgApp was rejected, lastindex: 0) from 2 for index 3
|
||||
DEBUG 1 decreased progress of 2 to [StateProbe match=0 next=1]
|
||||
DEBUG 1 [firstindex: 3, commit: 4] sent snapshot[index: 4, term: 1] to 2 [StateProbe match=0 next=1]
|
||||
DEBUG 1 paused sending replication messages to 2 [StateSnapshot match=0 next=1 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:true
|
||||
> 2 receiving messages
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:true
|
||||
INFO log [committed=0, applied=0, unstable.offset=1, len(unstable.Entries)=0] starts to restore snapshot [index: 4, term: 1]
|
||||
INFO 2 switched to configuration voters=(1 2 3)&&(1) autoleave
|
||||
INFO 2 [commit: 4, lastindex: 4, lastterm: 1] restored snapshot [index: 4, term: 1]
|
||||
INFO 2 [commit: 4] restored snapshot [index: 4, term: 1]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:4
|
||||
Snapshot Index:4 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:true
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
DEBUG 1 recovered from needing snapshot, resumed sending replication messages to 2 [StateSnapshot match=4 next=5 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryConfChangeV2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryConfChangeV2]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:5
|
||||
CommittedEntries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:5
|
||||
INFO 1 switched to configuration voters=(1 2 3)
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:5
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:5
|
||||
CommittedEntries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
INFO 2 switched to configuration voters=(1 2 3)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
|
||||
# n3 immediately receives a snapshot in the final configuration.
|
||||
stabilize 1 3
|
||||
----
|
||||
> 3 receiving messages
|
||||
1->3 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2 v3]
|
||||
INFO 3 [term: 0] received a MsgApp message with higher term from 1 [term: 1]
|
||||
INFO 3 became follower at term 1
|
||||
DEBUG 3 [logterm: 0, index: 3] rejected MsgApp [logterm: 1, index: 3] from 1
|
||||
> 3 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateFollower
|
||||
HardState Term:1 Commit:0
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
> 1 receiving messages
|
||||
3->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
DEBUG 1 received MsgAppResp(MsgApp was rejected, lastindex: 0) from 3 for index 3
|
||||
DEBUG 1 decreased progress of 3 to [StateProbe match=0 next=1]
|
||||
DEBUG 1 [firstindex: 3, commit: 5] sent snapshot[index: 5, term: 1] to 3 [StateProbe match=0 next=1]
|
||||
DEBUG 1 paused sending replication messages to 3 [StateSnapshot match=0 next=1 paused pendingSnap=5]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->3 MsgSnap Term:1 Log:0/0 Snapshot: Index:5 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
> 3 receiving messages
|
||||
1->3 MsgSnap Term:1 Log:0/0 Snapshot: Index:5 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
INFO log [committed=0, applied=0, unstable.offset=1, len(unstable.Entries)=0] starts to restore snapshot [index: 5, term: 1]
|
||||
INFO 3 switched to configuration voters=(1 2 3)
|
||||
INFO 3 [commit: 5, lastindex: 5, lastterm: 1] restored snapshot [index: 5, term: 1]
|
||||
INFO 3 [commit: 5] restored snapshot [index: 5, term: 1]
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:5
|
||||
Snapshot Index:5 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/5
|
||||
> 1 receiving messages
|
||||
3->1 MsgAppResp Term:1 Log:0/5
|
||||
DEBUG 1 recovered from needing snapshot, resumed sending replication messages to 3 [StateSnapshot match=5 next=6 paused pendingSnap=5]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->3 MsgApp Term:1 Log:1/5 Commit:5
|
||||
> 3 receiving messages
|
||||
1->3 MsgApp Term:1 Log:1/5 Commit:5
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/5
|
||||
> 1 receiving messages
|
||||
3->1 MsgAppResp Term:1 Log:0/5
|
||||
|
||||
# Nothing else happens.
|
||||
stabilize
|
||||
----
|
||||
ok
|
125
raft/testdata/confchange_v2_add_double_implicit.txt
vendored
Normal file
125
raft/testdata/confchange_v2_add_double_implicit.txt
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
# Run a V2 membership change that adds a single voter but explicitly asks for the
|
||||
# use of joint consensus (with auto-leaving).
|
||||
|
||||
# TODO(tbg): also verify that if the leader changes while in the joint state, the
|
||||
# new leader will auto-transition out of the joint state just the same.
|
||||
|
||||
# Bootstrap n1.
|
||||
add-nodes 1 voters=(1) index=2
|
||||
----
|
||||
INFO 1 switched to configuration voters=(1)
|
||||
INFO 1 became follower at term 0
|
||||
INFO newRaft 1 [peers: [1], term: 0, commit: 2, applied: 2, lastindex: 2, lastterm: 1]
|
||||
|
||||
campaign 1
|
||||
----
|
||||
INFO 1 is starting a new election at term 0
|
||||
INFO 1 became candidate at term 1
|
||||
INFO 1 received MsgVoteResp from 1 at term 1
|
||||
INFO 1 became leader at term 1
|
||||
|
||||
propose-conf-change 1 transition=implicit
|
||||
v2
|
||||
----
|
||||
ok
|
||||
|
||||
# Add n2.
|
||||
add-nodes 1
|
||||
----
|
||||
INFO 2 switched to configuration voters=()
|
||||
INFO 2 became follower at term 0
|
||||
INFO newRaft 2 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
|
||||
# n1 commits the conf change using itself as commit quorum, then starts catching up n2.
|
||||
# When that's done, it starts auto-transitioning out. Note that the snapshots propagating
|
||||
# the joint config have the AutoLeave flag set in their config.
|
||||
stabilize 1 2
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateLeader
|
||||
HardState Term:1 Vote:1 Commit:4
|
||||
Entries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2
|
||||
CommittedEntries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2
|
||||
INFO 1 switched to configuration voters=(1 2)&&(1) autoleave
|
||||
INFO initiating automatic transition out of joint configuration voters=(1 2)&&(1) autoleave
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2]
|
||||
INFO 2 [term: 0] received a MsgApp message with higher term from 1 [term: 1]
|
||||
INFO 2 became follower at term 1
|
||||
DEBUG 2 [logterm: 0, index: 3] rejected MsgApp [logterm: 1, index: 3] from 1
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateFollower
|
||||
HardState Term:1 Commit:0
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
DEBUG 1 received MsgAppResp(MsgApp was rejected, lastindex: 0) from 2 for index 3
|
||||
DEBUG 1 decreased progress of 2 to [StateProbe match=0 next=1]
|
||||
DEBUG 1 [firstindex: 3, commit: 4] sent snapshot[index: 4, term: 1] to 2 [StateProbe match=0 next=1]
|
||||
DEBUG 1 paused sending replication messages to 2 [StateSnapshot match=0 next=1 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:true
|
||||
> 2 receiving messages
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:true
|
||||
INFO log [committed=0, applied=0, unstable.offset=1, len(unstable.Entries)=0] starts to restore snapshot [index: 4, term: 1]
|
||||
INFO 2 switched to configuration voters=(1 2)&&(1) autoleave
|
||||
INFO 2 [commit: 4, lastindex: 4, lastterm: 1] restored snapshot [index: 4, term: 1]
|
||||
INFO 2 [commit: 4] restored snapshot [index: 4, term: 1]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:4
|
||||
Snapshot Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:true
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
DEBUG 1 recovered from needing snapshot, resumed sending replication messages to 2 [StateSnapshot match=4 next=5 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryConfChangeV2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryConfChangeV2]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:5
|
||||
CommittedEntries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:5
|
||||
INFO 1 switched to configuration voters=(1 2)
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:5
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:5
|
||||
CommittedEntries:
|
||||
1/5 EntryConfChangeV2
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
INFO 2 switched to configuration voters=(1 2)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
198
raft/testdata/confchange_v2_add_single_auto.txt
vendored
Normal file
198
raft/testdata/confchange_v2_add_single_auto.txt
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
# Run a V2 membership change that adds a single voter in auto mode, which means
|
||||
# that joint consensus is not used but a direct transition into the new config
|
||||
# takes place.
|
||||
|
||||
# Bootstrap n1.
|
||||
add-nodes 1 voters=(1) index=2
|
||||
----
|
||||
INFO 1 switched to configuration voters=(1)
|
||||
INFO 1 became follower at term 0
|
||||
INFO newRaft 1 [peers: [1], term: 0, commit: 2, applied: 2, lastindex: 2, lastterm: 1]
|
||||
|
||||
campaign 1
|
||||
----
|
||||
INFO 1 is starting a new election at term 0
|
||||
INFO 1 became candidate at term 1
|
||||
INFO 1 received MsgVoteResp from 1 at term 1
|
||||
INFO 1 became leader at term 1
|
||||
|
||||
# Add v2 (with an auto transition).
|
||||
propose-conf-change 1
|
||||
v2
|
||||
----
|
||||
ok
|
||||
|
||||
# Pull n2 out of thin air.
|
||||
add-nodes 1
|
||||
----
|
||||
INFO 2 switched to configuration voters=()
|
||||
INFO 2 became follower at term 0
|
||||
INFO newRaft 2 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
|
||||
# n1 commits the conf change using itself as commit quorum, immediately transitions into
|
||||
# the final config, and catches up n2.
|
||||
stabilize
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateLeader
|
||||
HardState Term:1 Vote:1 Commit:4
|
||||
Entries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2
|
||||
CommittedEntries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2
|
||||
INFO 1 switched to configuration voters=(1 2)
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2]
|
||||
INFO 2 [term: 0] received a MsgApp message with higher term from 1 [term: 1]
|
||||
INFO 2 became follower at term 1
|
||||
DEBUG 2 [logterm: 0, index: 3] rejected MsgApp [logterm: 1, index: 3] from 1
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateFollower
|
||||
HardState Term:1 Commit:0
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
DEBUG 1 received MsgAppResp(MsgApp was rejected, lastindex: 0) from 2 for index 3
|
||||
DEBUG 1 decreased progress of 2 to [StateProbe match=0 next=1]
|
||||
DEBUG 1 [firstindex: 3, commit: 4] sent snapshot[index: 4, term: 1] to 2 [StateProbe match=0 next=1]
|
||||
DEBUG 1 paused sending replication messages to 2 [StateSnapshot match=0 next=1 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
> 2 receiving messages
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
INFO log [committed=0, applied=0, unstable.offset=1, len(unstable.Entries)=0] starts to restore snapshot [index: 4, term: 1]
|
||||
INFO 2 switched to configuration voters=(1 2)
|
||||
INFO 2 [commit: 4, lastindex: 4, lastterm: 1] restored snapshot [index: 4, term: 1]
|
||||
INFO 2 [commit: 4] restored snapshot [index: 4, term: 1]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:4
|
||||
Snapshot Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
DEBUG 1 recovered from needing snapshot, resumed sending replication messages to 2 [StateSnapshot match=4 next=5 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
|
||||
# Check that we're not allowed to change membership again while in the joint state.
|
||||
# This leads to an empty entry being proposed instead (index 5 in the stabilize block
|
||||
# below).
|
||||
propose-conf-change 1
|
||||
v3 v4 v5
|
||||
----
|
||||
ok
|
||||
|
||||
# Propose a transition out of the joint config. We'll see this at index 6 below.
|
||||
propose-conf-change 1
|
||||
----
|
||||
INFO 1 ignoring conf change {ConfChangeTransitionAuto [] [] []} at config voters=(1 2): possible unapplied conf change at index 5 (applied to 4)
|
||||
|
||||
# The group commits the command and everyone switches to the final config.
|
||||
stabilize
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryConfChangeV2 v3 v4 v5
|
||||
1/6 EntryNormal ""
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryConfChangeV2 v3 v4 v5]
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:4 Entries:[1/6 EntryNormal ""]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryConfChangeV2 v3 v4 v5]
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:4 Entries:[1/6 EntryNormal ""]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryConfChangeV2 v3 v4 v5
|
||||
1/6 EntryNormal ""
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:6
|
||||
CommittedEntries:
|
||||
1/5 EntryConfChangeV2 v3 v4 v5
|
||||
1/6 EntryNormal ""
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:5
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6
|
||||
INFO 1 switched to configuration voters=(1 2 3 4 5)&&(1 2) autoleave
|
||||
INFO initiating automatic transition out of joint configuration voters=(1 2 3 4 5)&&(1 2) autoleave
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:5
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/7 EntryConfChangeV2
|
||||
Messages:
|
||||
1->3 MsgApp Term:1 Log:1/5 Commit:6 Entries:[1/6 EntryNormal ""]
|
||||
1->4 MsgApp Term:1 Log:1/5 Commit:6 Entries:[1/6 EntryNormal ""]
|
||||
1->5 MsgApp Term:1 Log:1/5 Commit:6 Entries:[1/6 EntryNormal ""]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:6
|
||||
CommittedEntries:
|
||||
1/5 EntryConfChangeV2 v3 v4 v5
|
||||
1/6 EntryNormal ""
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
INFO 2 switched to configuration voters=(1 2 3 4 5)&&(1 2) autoleave
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
|
||||
# Check that trying to transition out again won't do anything.
|
||||
propose-conf-change 1
|
||||
----
|
||||
ok
|
||||
|
||||
# Finishes work for the empty entry we just proposed.
|
||||
stabilize
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/8 EntryConfChangeV2
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6 Entries:[1/7 EntryConfChangeV2, 1/8 EntryConfChangeV2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6 Entries:[1/7 EntryConfChangeV2, 1/8 EntryConfChangeV2]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/7 EntryConfChangeV2
|
||||
1/8 EntryConfChangeV2
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/8
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/8
|
206
raft/testdata/confchange_v2_add_single_explicit.txt
vendored
Normal file
206
raft/testdata/confchange_v2_add_single_explicit.txt
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
# Run a V2 membership change that adds a single voter but explicitly asks for the
|
||||
# use of joint consensus, including wanting to transition out of the joint config
|
||||
# manually.
|
||||
|
||||
# Bootstrap n1.
|
||||
add-nodes 1 voters=(1) index=2
|
||||
----
|
||||
INFO 1 switched to configuration voters=(1)
|
||||
INFO 1 became follower at term 0
|
||||
INFO newRaft 1 [peers: [1], term: 0, commit: 2, applied: 2, lastindex: 2, lastterm: 1]
|
||||
|
||||
campaign 1
|
||||
----
|
||||
INFO 1 is starting a new election at term 0
|
||||
INFO 1 became candidate at term 1
|
||||
INFO 1 received MsgVoteResp from 1 at term 1
|
||||
INFO 1 became leader at term 1
|
||||
|
||||
# Add v2 with an explicit transition.
|
||||
propose-conf-change 1 transition=explicit
|
||||
v2
|
||||
----
|
||||
ok
|
||||
|
||||
# Pull n2 out of thin air.
|
||||
add-nodes 1
|
||||
----
|
||||
INFO 2 switched to configuration voters=()
|
||||
INFO 2 became follower at term 0
|
||||
INFO newRaft 2 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
|
||||
|
||||
# n1 commits the conf change using itself as commit quorum, then starts catching up n2.
|
||||
# Everyone remains in the joint config. Note that the snapshot below has AutoLeave unset.
|
||||
stabilize 1 2
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateLeader
|
||||
HardState Term:1 Vote:1 Commit:4
|
||||
Entries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2
|
||||
CommittedEntries:
|
||||
1/3 EntryNormal ""
|
||||
1/4 EntryConfChangeV2 v2
|
||||
INFO 1 switched to configuration voters=(1 2)&&(1)
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v2]
|
||||
INFO 2 [term: 0] received a MsgApp message with higher term from 1 [term: 1]
|
||||
INFO 2 became follower at term 1
|
||||
DEBUG 2 [logterm: 0, index: 3] rejected MsgApp [logterm: 1, index: 3] from 1
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Lead:1 State:StateFollower
|
||||
HardState Term:1 Commit:0
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/3 Rejected (Hint: 0)
|
||||
DEBUG 1 received MsgAppResp(MsgApp was rejected, lastindex: 0) from 2 for index 3
|
||||
DEBUG 1 decreased progress of 2 to [StateProbe match=0 next=1]
|
||||
DEBUG 1 [firstindex: 3, commit: 4] sent snapshot[index: 4, term: 1] to 2 [StateProbe match=0 next=1]
|
||||
DEBUG 1 paused sending replication messages to 2 [StateSnapshot match=0 next=1 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
> 2 receiving messages
|
||||
1->2 MsgSnap Term:1 Log:0/0 Snapshot: Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
INFO log [committed=0, applied=0, unstable.offset=1, len(unstable.Entries)=0] starts to restore snapshot [index: 4, term: 1]
|
||||
INFO 2 switched to configuration voters=(1 2)&&(1)
|
||||
INFO 2 [commit: 4, lastindex: 4, lastterm: 1] restored snapshot [index: 4, term: 1]
|
||||
INFO 2 [commit: 4] restored snapshot [index: 4, term: 1]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:4
|
||||
Snapshot Index:4 Term:1 ConfState:Voters:[1 2] VotersOutgoing:[1] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
DEBUG 1 recovered from needing snapshot, resumed sending replication messages to 2 [StateSnapshot match=4 next=5 paused pendingSnap=4]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/4
|
||||
|
||||
# Check that we're not allowed to change membership again while in the joint state.
|
||||
# This leads to an empty entry being proposed instead (index 5 in the stabilize block
|
||||
# below).
|
||||
propose-conf-change 1
|
||||
v3 v4 v5
|
||||
----
|
||||
INFO 1 ignoring conf change {ConfChangeTransitionAuto [{ConfChangeAddNode 3 []} {ConfChangeAddNode 4 []} {ConfChangeAddNode 5 []}] [] []} at config voters=(1 2)&&(1): must transition out of joint config first
|
||||
|
||||
# Propose a transition out of the joint config. We'll see this at index 6 below.
|
||||
propose-conf-change 1
|
||||
----
|
||||
ok
|
||||
|
||||
# The group commits the command and everyone switches to the final config.
|
||||
stabilize
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryNormal ""
|
||||
1/6 EntryConfChangeV2
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryNormal ""]
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:4 Entries:[1/6 EntryConfChangeV2]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/4 Commit:4 Entries:[1/5 EntryNormal ""]
|
||||
1->2 MsgApp Term:1 Log:1/5 Commit:4 Entries:[1/6 EntryConfChangeV2]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/5 EntryNormal ""
|
||||
1/6 EntryConfChangeV2
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/5
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:6
|
||||
CommittedEntries:
|
||||
1/5 EntryNormal ""
|
||||
1/6 EntryConfChangeV2
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:5
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6
|
||||
INFO 1 switched to configuration voters=(1 2)
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:5
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:6
|
||||
CommittedEntries:
|
||||
1/5 EntryNormal ""
|
||||
1/6 EntryConfChangeV2
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
INFO 2 switched to configuration voters=(1 2)
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
2->1 MsgAppResp Term:1 Log:0/6
|
||||
|
||||
# Check that trying to transition out again won't do anything.
|
||||
propose-conf-change 1
|
||||
----
|
||||
INFO 1 ignoring conf change {ConfChangeTransitionAuto [] [] []} at config voters=(1 2): not in joint state; refusing empty conf change
|
||||
|
||||
# Finishes work for the empty entry we just proposed.
|
||||
stabilize
|
||||
----
|
||||
> 1 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/7 EntryNormal ""
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6 Entries:[1/7 EntryNormal ""]
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/6 Commit:6 Entries:[1/7 EntryNormal ""]
|
||||
> 2 handling Ready
|
||||
Ready MustSync=true:
|
||||
Entries:
|
||||
1/7 EntryNormal ""
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/7
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/7
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Vote:1 Commit:7
|
||||
CommittedEntries:
|
||||
1/7 EntryNormal ""
|
||||
Messages:
|
||||
1->2 MsgApp Term:1 Log:1/7 Commit:7
|
||||
> 2 receiving messages
|
||||
1->2 MsgApp Term:1 Log:1/7 Commit:7
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:7
|
||||
CommittedEntries:
|
||||
1/7 EntryNormal ""
|
||||
Messages:
|
||||
2->1 MsgAppResp Term:1 Log:0/7
|
||||
> 1 receiving messages
|
||||
2->1 MsgAppResp Term:1 Log:0/7
|
33
raft/testdata/snapshot_succeed_via_app_resp.txt
vendored
33
raft/testdata/snapshot_succeed_via_app_resp.txt
vendored
@@ -30,7 +30,7 @@ compact 1 11
|
||||
ok (quiet)
|
||||
|
||||
# Drop inflight messages to n3.
|
||||
deliver-msgs 3
|
||||
deliver-msgs drop=(3)
|
||||
----
|
||||
ok (quiet)
|
||||
|
||||
@@ -70,7 +70,7 @@ Messages:
|
||||
# and responds.
|
||||
stabilize 3
|
||||
----
|
||||
> delivering messages
|
||||
> 3 receiving messages
|
||||
1->3 MsgHeartbeat Term:1 Log:0/0
|
||||
INFO 3 [term: 0] received a MsgHeartbeat message with higher term from 1 [term: 1]
|
||||
INFO 3 became follower at term 1
|
||||
@@ -84,14 +84,14 @@ stabilize 3
|
||||
# The leader in turn will realize that n3 needs a snapshot, which it initiates.
|
||||
stabilize 1
|
||||
----
|
||||
> delivering messages
|
||||
> 1 receiving messages
|
||||
3->1 MsgHeartbeatResp Term:1 Log:0/0
|
||||
DEBUG 1 [firstindex: 12, commit: 11] sent snapshot[index: 11, term: 1] to 3 [StateProbe match=0 next=11]
|
||||
DEBUG 1 paused sending replication messages to 3 [StateSnapshot match=0 next=11 paused pendingSnap=11]
|
||||
> 1 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
1->3 MsgSnap Term:1 Log:0/0 Snapshot: Index:11 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[]
|
||||
1->3 MsgSnap Term:1 Log:0/0 Snapshot: Index:11 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
|
||||
status 1
|
||||
----
|
||||
@@ -105,8 +105,8 @@ status 1
|
||||
# was now fully caught up.
|
||||
stabilize 3
|
||||
----
|
||||
> delivering messages
|
||||
1->3 MsgSnap Term:1 Log:0/0 Snapshot: Index:11 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[]
|
||||
> 3 receiving messages
|
||||
1->3 MsgSnap Term:1 Log:0/0 Snapshot: Index:11 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
INFO log [committed=0, applied=0, unstable.offset=1, len(unstable.Entries)=0] starts to restore snapshot [index: 11, term: 1]
|
||||
INFO 3 switched to configuration voters=(1 2 3)
|
||||
INFO 3 [commit: 11, lastindex: 11, lastterm: 1] restored snapshot [index: 11, term: 1]
|
||||
@@ -114,7 +114,7 @@ stabilize 3
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
HardState Term:1 Commit:11
|
||||
Snapshot Index:11 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[]
|
||||
Snapshot Index:11 Term:1 ConfState:Voters:[1 2 3] VotersOutgoing:[] Learners:[] LearnersNext:[] AutoLeave:false
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/11
|
||||
|
||||
@@ -122,7 +122,7 @@ stabilize 3
|
||||
# Leader sends another MsgAppResp, to communicate the updated commit index.
|
||||
stabilize 1
|
||||
----
|
||||
> delivering messages
|
||||
> 1 receiving messages
|
||||
3->1 MsgAppResp Term:1 Log:0/11
|
||||
DEBUG 1 recovered from needing snapshot, resumed sending replication messages to 3 [StateSnapshot match=11 next=12 paused pendingSnap=11]
|
||||
> 1 handling Ready
|
||||
@@ -136,6 +136,21 @@ status 1
|
||||
2: StateReplicate match=11 next=12
|
||||
3: StateReplicate match=11 next=12
|
||||
|
||||
# Let things settle.
|
||||
stabilize
|
||||
----
|
||||
ok
|
||||
> 2 receiving messages
|
||||
1->2 MsgHeartbeat Term:1 Log:0/0 Commit:11
|
||||
> 3 receiving messages
|
||||
1->3 MsgApp Term:1 Log:1/11 Commit:11
|
||||
> 2 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
2->1 MsgHeartbeatResp Term:1 Log:0/0
|
||||
> 3 handling Ready
|
||||
Ready MustSync=false:
|
||||
Messages:
|
||||
3->1 MsgAppResp Term:1 Log:0/11
|
||||
> 1 receiving messages
|
||||
2->1 MsgHeartbeatResp Term:1 Log:0/0
|
||||
3->1 MsgAppResp Term:1 Log:0/11
|
||||
|
@@ -77,8 +77,8 @@ func DescribeSoftState(ss SoftState) string {
|
||||
|
||||
func DescribeConfState(state pb.ConfState) string {
|
||||
return fmt.Sprintf(
|
||||
"Voters:%v VotersOutgoing:%v Learners:%v LearnersNext:%v",
|
||||
state.Voters, state.VotersOutgoing, state.Learners, state.LearnersNext,
|
||||
"Voters:%v VotersOutgoing:%v Learners:%v LearnersNext:%v AutoLeave:%v",
|
||||
state.Voters, state.VotersOutgoing, state.Learners, state.LearnersNext, state.AutoLeave,
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@ set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
help() {
|
||||
echo "$(basename $0) [version]"
|
||||
echo "$(basename "$0") [version]"
|
||||
echo "Release etcd using the same approach as the etcd-release-runbook (https://goo.gl/Gxwysq)"
|
||||
echo ""
|
||||
echo "WARNING: This does not perform the 'Add API capabilities', 'Performance testing' "
|
||||
@@ -56,25 +56,28 @@ main() {
|
||||
cd "${reldir}/etcd"
|
||||
|
||||
# If a release version tag already exists, use it.
|
||||
local remote_tag_exists=$(git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -c "${RELEASE_VERSION}")
|
||||
if [ ${remote_tag_exists} -gt 0 ]; then
|
||||
local remote_tag_exists
|
||||
remote_tag_exists=$(git ls-remote origin "refs/tags/${RELEASE_VERSION}" | grep -c "${RELEASE_VERSION}")
|
||||
if [ "${remote_tag_exists}" -gt 0 ]; then
|
||||
echo "Release version tag exists on remote. Checking out refs/tags/${RELEASE_VERSION}"
|
||||
git checkout -q "tags/${RELEASE_VERSION}"
|
||||
fi
|
||||
|
||||
# Check go version.
|
||||
# download "yq" from https://github.com/mikefarah/yq
|
||||
local go_version="go$(yq read .travis.yml "go[0]")"
|
||||
local current_go_version=$(go version | awk '{ print $3 }')
|
||||
local go_version current_go_version
|
||||
go_version="go$(yq read .travis.yml "go[0]")"
|
||||
current_go_version=$(go version | awk '{ print $3 }')
|
||||
if [[ "${current_go_version}" != "${go_version}" ]]; then
|
||||
echo "Current go version is ${current_go_version}, but etcd ${RELEASE_VERSION} requires ${go_version} (see .travis.yml)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If the release tag does not already exist remotely, create it.
|
||||
if [ ${remote_tag_exists} -eq 0 ]; then
|
||||
if [ "${remote_tag_exists}" -eq 0 ]; then
|
||||
# Bump version/version.go to release version.
|
||||
local source_version=$(egrep "\s+Version\s*=" version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
|
||||
local source_version
|
||||
source_version=$(grep -E "\s+Version\s*=" version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
|
||||
if [[ "${source_version}" != "${VERSION}" ]]; then
|
||||
source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
|
||||
if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
|
||||
@@ -87,13 +90,14 @@ main() {
|
||||
|
||||
echo "Building etcd and checking --version output"
|
||||
./build
|
||||
local etcd_version=$(bin/etcd --version | grep "etcd Version" | awk '{ print $3 }')
|
||||
local etcd_version
|
||||
etcd_version=$(bin/etcd --version | grep "etcd Version" | awk '{ print $3 }')
|
||||
if [[ "${etcd_version}" != "${VERSION}" ]]; then
|
||||
echo "Wrong etcd version in version/version.go. Expected ${etcd_version} but got ${VERSION}. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -z $(git status -s) ]]; then
|
||||
if [[ -n $(git status -s) ]]; then
|
||||
echo "Committing version/version.go update."
|
||||
git add version/version.go
|
||||
git commit -m "version: bump up to ${VERSION}"
|
||||
@@ -101,14 +105,14 @@ main() {
|
||||
fi
|
||||
|
||||
# Push the version change if it's not already been pushed.
|
||||
if [ $(git rev-list --count "origin/${BRANCH}..${BRANCH}") -gt 0 ]; then
|
||||
read -p "Push version bump up to ${VERSION} to github.com/etcd-io/etcd [y/N]? " confirm
|
||||
if [ "$(git rev-list --count "origin/${BRANCH}..${BRANCH}")" -gt 0 ]; then
|
||||
read -pr "Push version bump up to ${VERSION} to github.com/etcd-io/etcd [y/N]? " confirm
|
||||
[[ "${confirm,,}" == "y" ]] || exit 1
|
||||
git push
|
||||
fi
|
||||
|
||||
# Tag release.
|
||||
if [ $(git tag --list | grep -c "${RELEASE_VERSION}") -gt 0 ]; then
|
||||
if [ "$(git tag --list | grep -c "${RELEASE_VERSION}")" -gt 0 ]; then
|
||||
echo "Skipping tag step. git tag ${RELEASE_VERSION} already exists."
|
||||
else
|
||||
echo "Tagging release..."
|
||||
@@ -116,7 +120,7 @@ main() {
|
||||
fi
|
||||
|
||||
# Push the tag change if it's not already been pushed.
|
||||
read -p "Push etcd ${RELEASE_VERSION} tag [y/N]? " confirm
|
||||
read -pr "Push etcd ${RELEASE_VERSION} tag [y/N]? " confirm
|
||||
[[ "${confirm,,}" == "y" ]] || exit 1
|
||||
git push origin "tags/${RELEASE_VERSION}"
|
||||
fi
|
||||
@@ -137,44 +141,58 @@ main() {
|
||||
fi
|
||||
|
||||
# Sanity checks.
|
||||
./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcd --version | grep -q "etcd Version: ${VERSION}" || true
|
||||
./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcdctl version | grep -q "etcdctl version: ${VERSION}" || true
|
||||
"./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcd" --version | grep -q "etcd Version: ${VERSION}" || true
|
||||
"./release/etcd-${RELEASE_VERSION}-$(go env GOOS)-amd64/etcdctl" version | grep -q "etcdctl version: ${VERSION}" || true
|
||||
|
||||
# Generate SHA256SUMS
|
||||
echo -e "Generating sha256sums of release artifacts.\n"
|
||||
pushd ./release
|
||||
grep . -E '\.tar.gz$|\.zip$' | xargs shasum -a 256 > ./SHA256SUMS
|
||||
popd
|
||||
if [ -s ./release/SHA256SUMS ]; then
|
||||
cat ./release/SHA256SUMS
|
||||
else
|
||||
echo "sha256sums is not valid. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Upload artifacts.
|
||||
if [ "${NO_UPLOAD}" == 1 ]; then
|
||||
echo "Skipping artifact upload to gs://etcd. --no-upload flat is set."
|
||||
else
|
||||
read -p "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " confirm
|
||||
read -pr "Upload etcd ${RELEASE_VERSION} release artifacts to gs://etcd [y/N]? " confirm
|
||||
[[ "${confirm,,}" == "y" ]] || exit 1
|
||||
gsutil -m cp ./release/*.zip gs://etcd/${RELEASE_VERSION}/
|
||||
gsutil -m cp ./release/*.tar.gz gs://etcd/${RELEASE_VERSION}/
|
||||
gsutil -m acl ch -u allUsers:R -r gs://etcd/${RELEASE_VERSION}/
|
||||
gsutil -m cp ./release/SHA256SUMS "gs://etcd/${RELEASE_VERSION}/"
|
||||
gsutil -m cp ./release/*.zip "gs://etcd/${RELEASE_VERSION}/"
|
||||
gsutil -m cp ./release/*.tar.gz "gs://etcd/${RELEASE_VERSION}/"
|
||||
gsutil -m acl ch -u allUsers:R -r "gs://etcd/${RELEASE_VERSION}/"
|
||||
fi
|
||||
|
||||
# Push images.
|
||||
if [ "${NO_DOCKER_PUSH}" == 1 ]; then
|
||||
echo "Skipping docker push. --no-docker-push flat is set."
|
||||
else
|
||||
read -p "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " confirm
|
||||
read -pr "Publish etcd ${RELEASE_VERSION} docker images to quay.io [y/N]? " confirm
|
||||
[[ "${confirm,,}" == "y" ]] || exit 1
|
||||
# shellcheck disable=SC2034
|
||||
for i in {1..5}; do
|
||||
docker login quay.io && break
|
||||
echo "login failed, retrying"
|
||||
done
|
||||
gcloud docker -- login -u _json_key -p "$(cat /etc/gcp-key-etcd-development.json)" https://gcr.io
|
||||
|
||||
echo "Pushing container images to quay.io" ${RELEASE_VERSION}
|
||||
docker push quay.io/coreos/etcd:${RELEASE_VERSION}
|
||||
echo "Pushing container images to quay.io ${RELEASE_VERSION}"
|
||||
docker push "quay.io/coreos/etcd:${RELEASE_VERSION}"
|
||||
|
||||
echo "Pushing container images to gcr.io" ${RELEASE_VERSION}
|
||||
gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}
|
||||
echo "Pushing container images to gcr.io ${RELEASE_VERSION}"
|
||||
gcloud docker -- push "gcr.io/etcd-development/etcd:${RELEASE_VERSION}"
|
||||
|
||||
for TARGET_ARCH in "-arm64" "-ppc64le"; do
|
||||
echo "Pushing container images to quay.io" ${RELEASE_VERSION}${TARGET_ARCH}
|
||||
docker push quay.io/coreos/etcd:${RELEASE_VERSION}${TARGET_ARCH}
|
||||
echo "Pushing container images to quay.io ${RELEASE_VERSION}${TARGET_ARCH}"
|
||||
docker push "quay.io/coreos/etcd:${RELEASE_VERSION}${TARGET_ARCH}"
|
||||
|
||||
echo "Pushing container images to gcr.io" ${RELEASE_VERSION}${TARGET_ARCH}
|
||||
gcloud docker -- push gcr.io/etcd-development/etcd:${RELEASE_VERSION}${TARGET_ARCH}
|
||||
echo "Pushing container images to gcr.io ${RELEASE_VERSION}${TARGET_ARCH}"
|
||||
gcloud docker -- push "gcr.io/etcd-development/etcd:${RELEASE_VERSION}${TARGET_ARCH}"
|
||||
done
|
||||
|
||||
echo "Setting permissions using gsutil..."
|
||||
@@ -221,4 +239,4 @@ if [[ ! $# -eq 1 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
main $1
|
||||
main "$1"
|
||||
|
@@ -16,7 +16,6 @@ package e2e
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.etcd.io/etcd/version"
|
||||
@@ -41,12 +40,6 @@ func metricsTest(cx ctlCtx) {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
ver := version.Version
|
||||
if strings.HasSuffix(ver, "-pre") {
|
||||
ver = strings.Replace(ver, "-pre", "", 1)
|
||||
}
|
||||
if strings.HasSuffix(ver, "-rc.0") {
|
||||
ver = strings.Replace(ver, "-rc.0", "", 1)
|
||||
}
|
||||
|
||||
i := 0
|
||||
for _, test := range []struct {
|
||||
|
10
vendor/github.com/creack/pty/types.go
generated
vendored
10
vendor/github.com/creack/pty/types.go
generated
vendored
@@ -1,10 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
package pty
|
||||
|
||||
import "C"
|
||||
|
||||
type (
|
||||
_C_int C.int
|
||||
_C_uint C.uint
|
||||
)
|
17
vendor/github.com/creack/pty/types_dragonfly.go
generated
vendored
17
vendor/github.com/creack/pty/types_dragonfly.go
generated
vendored
@@ -1,17 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
package pty
|
||||
|
||||
/*
|
||||
#define _KERNEL
|
||||
#include <sys/conf.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/filio.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
_C_SPECNAMELEN = C.SPECNAMELEN /* max length of devicename */
|
||||
)
|
||||
|
||||
type fiodgnameArg C.struct_fiodname_args
|
15
vendor/github.com/creack/pty/types_freebsd.go
generated
vendored
15
vendor/github.com/creack/pty/types_freebsd.go
generated
vendored
@@ -1,15 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
package pty
|
||||
|
||||
/*
|
||||
#include <sys/param.h>
|
||||
#include <sys/filio.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
_C_SPECNAMELEN = C.SPECNAMELEN /* max length of devicename */
|
||||
)
|
||||
|
||||
type fiodgnameArg C.struct_fiodgname_arg
|
14
vendor/github.com/creack/pty/types_openbsd.go
generated
vendored
14
vendor/github.com/creack/pty/types_openbsd.go
generated
vendored
@@ -1,14 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
package pty
|
||||
|
||||
/*
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/tty.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
type ptmget C.struct_ptmget
|
||||
|
||||
var ioctl_PTMGET = C.PTMGET
|
76
vendor/github.com/google/btree/btree_mem.go
generated
vendored
76
vendor/github.com/google/btree/btree_mem.go
generated
vendored
@@ -1,76 +0,0 @@
|
||||
// Copyright 2014 Google Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// This binary compares memory usage between btree and gollrb.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/google/btree"
|
||||
"github.com/petar/GoLLRB/llrb"
|
||||
)
|
||||
|
||||
var (
|
||||
size = flag.Int("size", 1000000, "size of the tree to build")
|
||||
degree = flag.Int("degree", 8, "degree of btree")
|
||||
gollrb = flag.Bool("llrb", false, "use llrb instead of btree")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
vals := rand.Perm(*size)
|
||||
var t, v interface{}
|
||||
v = vals
|
||||
var stats runtime.MemStats
|
||||
for i := 0; i < 10; i++ {
|
||||
runtime.GC()
|
||||
}
|
||||
fmt.Println("-------- BEFORE ----------")
|
||||
runtime.ReadMemStats(&stats)
|
||||
fmt.Printf("%+v\n", stats)
|
||||
start := time.Now()
|
||||
if *gollrb {
|
||||
tr := llrb.New()
|
||||
for _, v := range vals {
|
||||
tr.ReplaceOrInsert(llrb.Int(v))
|
||||
}
|
||||
t = tr // keep it around
|
||||
} else {
|
||||
tr := btree.New(*degree)
|
||||
for _, v := range vals {
|
||||
tr.ReplaceOrInsert(btree.Int(v))
|
||||
}
|
||||
t = tr // keep it around
|
||||
}
|
||||
fmt.Printf("%v inserts in %v\n", *size, time.Since(start))
|
||||
fmt.Println("-------- AFTER ----------")
|
||||
runtime.ReadMemStats(&stats)
|
||||
fmt.Printf("%+v\n", stats)
|
||||
for i := 0; i < 10; i++ {
|
||||
runtime.GC()
|
||||
}
|
||||
fmt.Println("-------- AFTER GC ----------")
|
||||
runtime.ReadMemStats(&stats)
|
||||
fmt.Printf("%+v\n", stats)
|
||||
if t == v {
|
||||
fmt.Println("to make sure vals and tree aren't GC'd")
|
||||
}
|
||||
}
|
8
vendor/golang.org/x/sys/unix/affinity_linux.go
generated
vendored
8
vendor/golang.org/x/sys/unix/affinity_linux.go
generated
vendored
@@ -91,9 +91,13 @@ func onesCount64(x uint64) int {
|
||||
const m0 = 0x5555555555555555 // 01010101 ...
|
||||
const m1 = 0x3333333333333333 // 00110011 ...
|
||||
const m2 = 0x0f0f0f0f0f0f0f0f // 00001111 ...
|
||||
const m3 = 0x00ff00ff00ff00ff // etc.
|
||||
const m4 = 0x0000ffff0000ffff
|
||||
|
||||
// Unused in this function, but definitions preserved for
|
||||
// documentation purposes:
|
||||
//
|
||||
// const m3 = 0x00ff00ff00ff00ff // etc.
|
||||
// const m4 = 0x0000ffff0000ffff
|
||||
//
|
||||
// Implementation: Parallel summing of adjacent bits.
|
||||
// See "Hacker's Delight", Chap. 5: Counting Bits.
|
||||
// The following pattern shows the general approach:
|
||||
|
54
vendor/golang.org/x/sys/unix/asm_linux_riscv64.s
generated
vendored
Normal file
54
vendor/golang.org/x/sys/unix/asm_linux_riscv64.s
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build riscv64,!gccgo
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
//
|
||||
// System calls for linux/riscv64.
|
||||
//
|
||||
// Where available, just jump to package syscall's implementation of
|
||||
// these functions.
|
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56
|
||||
JMP syscall·Syscall(SB)
|
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80
|
||||
JMP syscall·Syscall6(SB)
|
||||
|
||||
TEXT ·SyscallNoError(SB),NOSPLIT,$0-48
|
||||
CALL runtime·entersyscall(SB)
|
||||
MOV a1+8(FP), A0
|
||||
MOV a2+16(FP), A1
|
||||
MOV a3+24(FP), A2
|
||||
MOV $0, A3
|
||||
MOV $0, A4
|
||||
MOV $0, A5
|
||||
MOV $0, A6
|
||||
MOV trap+0(FP), A7 // syscall entry
|
||||
ECALL
|
||||
MOV A0, r1+32(FP) // r1
|
||||
MOV A1, r2+40(FP) // r2
|
||||
CALL runtime·exitsyscall(SB)
|
||||
RET
|
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
|
||||
JMP syscall·RawSyscall(SB)
|
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
|
||||
JMP syscall·RawSyscall6(SB)
|
||||
|
||||
TEXT ·RawSyscallNoError(SB),NOSPLIT,$0-48
|
||||
MOV a1+8(FP), A0
|
||||
MOV a2+16(FP), A1
|
||||
MOV a3+24(FP), A2
|
||||
MOV ZERO, A3
|
||||
MOV ZERO, A4
|
||||
MOV ZERO, A5
|
||||
MOV trap+0(FP), A7 // syscall entry
|
||||
ECALL
|
||||
MOV A0, r1+32(FP)
|
||||
MOV A1, r2+40(FP)
|
||||
RET
|
29
vendor/golang.org/x/sys/unix/asm_openbsd_arm64.s
generated
vendored
Normal file
29
vendor/golang.org/x/sys/unix/asm_openbsd_arm64.s
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !gccgo
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
//
|
||||
// System call support for arm64, OpenBSD
|
||||
//
|
||||
|
||||
// Just jump to package syscall's implementation for all these functions.
|
||||
// The runtime may know about them.
|
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56
|
||||
JMP syscall·Syscall(SB)
|
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80
|
||||
JMP syscall·Syscall6(SB)
|
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104
|
||||
JMP syscall·Syscall9(SB)
|
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56
|
||||
JMP syscall·RawSyscall(SB)
|
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
|
||||
JMP syscall·RawSyscall6(SB)
|
91
vendor/golang.org/x/sys/unix/dirent.go
generated
vendored
91
vendor/golang.org/x/sys/unix/dirent.go
generated
vendored
@@ -2,16 +2,101 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
||||
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package unix
|
||||
|
||||
import "syscall"
|
||||
import "unsafe"
|
||||
|
||||
// readInt returns the size-bytes unsigned integer in native byte order at offset off.
|
||||
func readInt(b []byte, off, size uintptr) (u uint64, ok bool) {
|
||||
if len(b) < int(off+size) {
|
||||
return 0, false
|
||||
}
|
||||
if isBigEndian {
|
||||
return readIntBE(b[off:], size), true
|
||||
}
|
||||
return readIntLE(b[off:], size), true
|
||||
}
|
||||
|
||||
func readIntBE(b []byte, size uintptr) uint64 {
|
||||
switch size {
|
||||
case 1:
|
||||
return uint64(b[0])
|
||||
case 2:
|
||||
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[1]) | uint64(b[0])<<8
|
||||
case 4:
|
||||
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[3]) | uint64(b[2])<<8 | uint64(b[1])<<16 | uint64(b[0])<<24
|
||||
case 8:
|
||||
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
|
||||
uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
|
||||
default:
|
||||
panic("syscall: readInt with unsupported size")
|
||||
}
|
||||
}
|
||||
|
||||
func readIntLE(b []byte, size uintptr) uint64 {
|
||||
switch size {
|
||||
case 1:
|
||||
return uint64(b[0])
|
||||
case 2:
|
||||
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[0]) | uint64(b[1])<<8
|
||||
case 4:
|
||||
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24
|
||||
case 8:
|
||||
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
|
||||
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
|
||||
default:
|
||||
panic("syscall: readInt with unsupported size")
|
||||
}
|
||||
}
|
||||
|
||||
// ParseDirent parses up to max directory entries in buf,
|
||||
// appending the names to names. It returns the number of
|
||||
// bytes consumed from buf, the number of entries added
|
||||
// to names, and the new names slice.
|
||||
func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
|
||||
return syscall.ParseDirent(buf, max, names)
|
||||
origlen := len(buf)
|
||||
count = 0
|
||||
for max != 0 && len(buf) > 0 {
|
||||
reclen, ok := direntReclen(buf)
|
||||
if !ok || reclen > uint64(len(buf)) {
|
||||
return origlen, count, names
|
||||
}
|
||||
rec := buf[:reclen]
|
||||
buf = buf[reclen:]
|
||||
ino, ok := direntIno(rec)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
if ino == 0 { // File absent in directory.
|
||||
continue
|
||||
}
|
||||
const namoff = uint64(unsafe.Offsetof(Dirent{}.Name))
|
||||
namlen, ok := direntNamlen(rec)
|
||||
if !ok || namoff+namlen > uint64(len(rec)) {
|
||||
break
|
||||
}
|
||||
name := rec[namoff : namoff+namlen]
|
||||
for i, c := range name {
|
||||
if c == 0 {
|
||||
name = name[:i]
|
||||
break
|
||||
}
|
||||
}
|
||||
// Check for useless names before allocating a string.
|
||||
if string(name) == "." || string(name) == ".." {
|
||||
continue
|
||||
}
|
||||
max--
|
||||
count++
|
||||
names = append(names, string(name))
|
||||
}
|
||||
return origlen - len(buf), count, names
|
||||
}
|
||||
|
2
vendor/golang.org/x/sys/unix/endian_little.go
generated
vendored
2
vendor/golang.org/x/sys/unix/endian_little.go
generated
vendored
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
//
|
||||
// +build 386 amd64 amd64p32 arm arm64 ppc64le mipsle mips64le
|
||||
// +build 386 amd64 amd64p32 arm arm64 ppc64le mipsle mips64le riscv64
|
||||
|
||||
package unix
|
||||
|
||||
|
61
vendor/golang.org/x/sys/unix/mkasm_darwin.go
generated
vendored
61
vendor/golang.org/x/sys/unix/mkasm_darwin.go
generated
vendored
@@ -1,61 +0,0 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go.
|
||||
//This program must be run after mksyscall.go.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in1, err := ioutil.ReadFile("syscall_darwin.go")
|
||||
if err != nil {
|
||||
log.Fatalf("can't open syscall_darwin.go: %s", err)
|
||||
}
|
||||
arch := os.Args[1]
|
||||
in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
|
||||
if err != nil {
|
||||
log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
|
||||
}
|
||||
in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
|
||||
if err != nil {
|
||||
log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
|
||||
}
|
||||
in := string(in1) + string(in2) + string(in3)
|
||||
|
||||
trampolines := map[string]bool{}
|
||||
|
||||
var out bytes.Buffer
|
||||
|
||||
fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
|
||||
fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
|
||||
fmt.Fprintf(&out, "\n")
|
||||
fmt.Fprintf(&out, "// +build go1.12\n")
|
||||
fmt.Fprintf(&out, "\n")
|
||||
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
|
||||
for _, line := range strings.Split(in, "\n") {
|
||||
if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") {
|
||||
continue
|
||||
}
|
||||
fn := line[5 : len(line)-13]
|
||||
if !trampolines[fn] {
|
||||
trampolines[fn] = true
|
||||
fmt.Fprintf(&out, "TEXT ·%s_trampoline(SB),NOSPLIT,$0-0\n", fn)
|
||||
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile(fmt.Sprintf("zsyscall_darwin_%s.s", arch), out.Bytes(), 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("can't write zsyscall_darwin_%s.s: %s", arch, err)
|
||||
}
|
||||
}
|
106
vendor/golang.org/x/sys/unix/mkpost.go
generated
vendored
106
vendor/golang.org/x/sys/unix/mkpost.go
generated
vendored
@@ -1,106 +0,0 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// mkpost processes the output of cgo -godefs to
|
||||
// modify the generated types. It is used to clean up
|
||||
// the sys API in an architecture specific manner.
|
||||
//
|
||||
// mkpost is run after cgo -godefs; see README.md.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Get the OS and architecture (using GOARCH_TARGET if it exists)
|
||||
goos := os.Getenv("GOOS")
|
||||
goarch := os.Getenv("GOARCH_TARGET")
|
||||
if goarch == "" {
|
||||
goarch = os.Getenv("GOARCH")
|
||||
}
|
||||
// Check that we are using the Docker-based build system if we should be.
|
||||
if goos == "linux" {
|
||||
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
|
||||
os.Stderr.WriteString("In the Docker-based build system, mkpost should not be called directly.\n")
|
||||
os.Stderr.WriteString("See README.md\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Intentionally export __val fields in Fsid and Sigset_t
|
||||
valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__val(\s+\S+\s+)}`)
|
||||
b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$3}"))
|
||||
|
||||
// Intentionally export __fds_bits field in FdSet
|
||||
fdSetRegex := regexp.MustCompile(`type (FdSet) struct {(\s+)X__fds_bits(\s+\S+\s+)}`)
|
||||
b = fdSetRegex.ReplaceAll(b, []byte("type $1 struct {${2}Bits$3}"))
|
||||
|
||||
// If we have empty Ptrace structs, we should delete them. Only s390x emits
|
||||
// nonempty Ptrace structs.
|
||||
ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`)
|
||||
b = ptraceRexexp.ReplaceAll(b, nil)
|
||||
|
||||
// Replace the control_regs union with a blank identifier for now.
|
||||
controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`)
|
||||
b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64"))
|
||||
|
||||
// Remove fields that are added by glibc
|
||||
// Note that this is unstable as the identifers are private.
|
||||
removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`)
|
||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Convert [65]int8 to [65]byte in Utsname members to simplify
|
||||
// conversion to string; see golang.org/issue/20753
|
||||
convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
|
||||
b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
|
||||
|
||||
// Convert [1024]int8 to [1024]byte in Ptmget members
|
||||
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
|
||||
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
|
||||
|
||||
// Remove spare fields (e.g. in Statx_t)
|
||||
spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
|
||||
b = spareFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Remove cgo padding fields
|
||||
removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`)
|
||||
b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Remove padding, hidden, or unused fields
|
||||
removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`)
|
||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Remove the first line of warning from cgo
|
||||
b = b[bytes.IndexByte(b, '\n')+1:]
|
||||
// Modify the command in the header to include:
|
||||
// mkpost, our own warning, and a build tag.
|
||||
replacement := fmt.Sprintf(`$1 | go run mkpost.go
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s,%s`, goarch, goos)
|
||||
cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`)
|
||||
b = cgoCommandRegex.ReplaceAll(b, []byte(replacement))
|
||||
|
||||
// gofmt
|
||||
b, err = format.Source(b)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
os.Stdout.Write(b)
|
||||
}
|
402
vendor/golang.org/x/sys/unix/mksyscall.go
generated
vendored
402
vendor/golang.org/x/sys/unix/mksyscall.go
generated
vendored
@@ -1,402 +0,0 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_darwin.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named errno.
|
||||
|
||||
A line beginning with //sysnb is like //sys, except that the
|
||||
goroutine will not be suspended during the execution of the system
|
||||
call. This must only be used for system calls which can never
|
||||
block, as otherwise the system call could cause all goroutines to
|
||||
hang.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
plan9 = flag.Bool("plan9", false, "plan9")
|
||||
openbsd = flag.Bool("openbsd", false, "openbsd")
|
||||
netbsd = flag.Bool("netbsd", false, "netbsd")
|
||||
dragonfly = flag.Bool("dragonfly", false, "dragonfly")
|
||||
arm = flag.Bool("arm", false, "arm") // 64-bit value should use (even, odd)-pair
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
filename = flag.String("output", "", "output file name (standard output if omitted)")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Get the OS and architecture (using GOARCH_TARGET if it exists)
|
||||
goos := os.Getenv("GOOS")
|
||||
if goos == "" {
|
||||
fmt.Fprintln(os.Stderr, "GOOS not defined in environment")
|
||||
os.Exit(1)
|
||||
}
|
||||
goarch := os.Getenv("GOARCH_TARGET")
|
||||
if goarch == "" {
|
||||
goarch = os.Getenv("GOARCH")
|
||||
}
|
||||
|
||||
// Check that we are using the Docker-based build system if we should
|
||||
if goos == "linux" {
|
||||
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
|
||||
fmt.Fprintf(os.Stderr, "In the Docker-based build system, mksyscall should not be called directly.\n")
|
||||
fmt.Fprintf(os.Stderr, "See README.md\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
libc := false
|
||||
if goos == "darwin" && strings.Contains(buildTags(), ",go1.12") {
|
||||
libc = true
|
||||
}
|
||||
trampolines := map[string]bool{}
|
||||
|
||||
text := ""
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, errno error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, sysname := f[2], f[3], f[4], f[5]
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
|
||||
// Go function header.
|
||||
outDecl := ""
|
||||
if len(out) > 0 {
|
||||
outDecl = fmt.Sprintf(" (%s)", strings.Join(out, ", "))
|
||||
}
|
||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outDecl)
|
||||
|
||||
// Check if err return available
|
||||
errvar := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare arguments to Syscall.
|
||||
var args []string
|
||||
n := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))")
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
text += fmt.Sprintf("\tvar _p%d *byte\n", n)
|
||||
text += fmt.Sprintf("\t_p%d, %s = BytePtrFromString(%s)\n", n, errvar, p.Name)
|
||||
text += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
text += fmt.Sprintf("\tvar _p%d *byte\n", n)
|
||||
text += fmt.Sprintf("\t_p%d, _ = BytePtrFromString(%s)\n", n, p.Name)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass dummy pointer in that case.
|
||||
// Used to pass nil, but some OSes or simulators reject write(fd, nil, 0).
|
||||
text += fmt.Sprintf("\tvar _p%d unsafe.Pointer\n", n)
|
||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = unsafe.Pointer(&%s[0])\n\t}", p.Name, n, p.Name)
|
||||
text += fmt.Sprintf(" else {\n\t\t_p%d = unsafe.Pointer(&_zero)\n\t}\n", n)
|
||||
args = append(args, fmt.Sprintf("uintptr(_p%d)", n), fmt.Sprintf("uintptr(len(%s))", p.Name))
|
||||
n++
|
||||
} else if p.Type == "int64" && (*openbsd || *netbsd) {
|
||||
args = append(args, "0")
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else if endianness == "little-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
} else if p.Type == "int64" && *dragonfly {
|
||||
if regexp.MustCompile(`^(?i)extp(read|write)`).FindStringSubmatch(funct) == nil {
|
||||
args = append(args, "0")
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else if endianness == "little-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
} else if p.Type == "int64" && endianness != "" {
|
||||
if len(args)%2 == 1 && *arm {
|
||||
// arm abi specifies 64-bit argument uses
|
||||
// (even, odd) pair
|
||||
args = append(args, "0")
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
}
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which form to use; pad args with zeros.
|
||||
asm := "Syscall"
|
||||
if nonblock != nil {
|
||||
if errvar == "" && goos == "linux" {
|
||||
asm = "RawSyscallNoError"
|
||||
} else {
|
||||
asm = "RawSyscall"
|
||||
}
|
||||
} else {
|
||||
if errvar == "" && goos == "linux" {
|
||||
asm = "SyscallNoError"
|
||||
}
|
||||
}
|
||||
if len(args) <= 3 {
|
||||
for len(args) < 3 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else if len(args) <= 6 {
|
||||
asm += "6"
|
||||
for len(args) < 6 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else if len(args) <= 9 {
|
||||
asm += "9"
|
||||
for len(args) < 9 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s too many arguments to system call\n", path, funct)
|
||||
}
|
||||
|
||||
// System call number.
|
||||
if sysname == "" {
|
||||
sysname = "SYS_" + funct
|
||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
||||
sysname = strings.ToUpper(sysname)
|
||||
}
|
||||
|
||||
var libcFn string
|
||||
if libc {
|
||||
asm = "syscall_" + strings.ToLower(asm[:1]) + asm[1:] // internal syscall call
|
||||
sysname = strings.TrimPrefix(sysname, "SYS_") // remove SYS_
|
||||
sysname = strings.ToLower(sysname) // lowercase
|
||||
if sysname == "getdirentries64" {
|
||||
// Special case - libSystem name and
|
||||
// raw syscall name don't match.
|
||||
sysname = "__getdirentries64"
|
||||
}
|
||||
libcFn = sysname
|
||||
sysname = "funcPC(libc_" + sysname + "_trampoline)"
|
||||
}
|
||||
|
||||
// Actual call.
|
||||
arglist := strings.Join(args, ", ")
|
||||
call := fmt.Sprintf("%s(%s, %s)", asm, sysname, arglist)
|
||||
|
||||
// Assign return values.
|
||||
body := ""
|
||||
ret := []string{"_", "_", "_"}
|
||||
doErrno := false
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" && !*plan9 {
|
||||
reg = "e1"
|
||||
ret[2] = reg
|
||||
doErrno = true
|
||||
} else if p.Name == "err" && *plan9 {
|
||||
ret[0] = "r0"
|
||||
ret[2] = "e1"
|
||||
break
|
||||
} else {
|
||||
reg = fmt.Sprintf("r%d", i)
|
||||
ret[i] = reg
|
||||
}
|
||||
if p.Type == "bool" {
|
||||
reg = fmt.Sprintf("%s != 0", reg)
|
||||
}
|
||||
if p.Type == "int64" && endianness != "" {
|
||||
// 64-bit number in r1:r0 or r0:r1.
|
||||
if i+2 > len(out) {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s not enough registers for int64 return\n", path, funct)
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i, i+1)
|
||||
} else {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i+1, i)
|
||||
}
|
||||
ret[i] = fmt.Sprintf("r%d", i)
|
||||
ret[i+1] = fmt.Sprintf("r%d", i+1)
|
||||
}
|
||||
if reg != "e1" || *plan9 {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
if ret[0] == "_" && ret[1] == "_" && ret[2] == "_" {
|
||||
text += fmt.Sprintf("\t%s\n", call)
|
||||
} else {
|
||||
if errvar == "" && goos == "linux" {
|
||||
// raw syscall without error on Linux, see golang.org/issue/22924
|
||||
text += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], call)
|
||||
} else {
|
||||
text += fmt.Sprintf("\t%s, %s, %s := %s\n", ret[0], ret[1], ret[2], call)
|
||||
}
|
||||
}
|
||||
text += body
|
||||
|
||||
if *plan9 && ret[2] == "e1" {
|
||||
text += "\tif int32(r0) == -1 {\n"
|
||||
text += "\t\terr = e1\n"
|
||||
text += "\t}\n"
|
||||
} else if doErrno {
|
||||
text += "\tif e1 != 0 {\n"
|
||||
text += "\t\terr = errnoErr(e1)\n"
|
||||
text += "\t}\n"
|
||||
}
|
||||
text += "\treturn\n"
|
||||
text += "}\n\n"
|
||||
|
||||
if libc && !trampolines[libcFn] {
|
||||
// some system calls share a trampoline, like read and readlen.
|
||||
trampolines[libcFn] = true
|
||||
// Declare assembly trampoline.
|
||||
text += fmt.Sprintf("func libc_%s_trampoline()\n", libcFn)
|
||||
// Assembly trampoline calls the libc_* function, which this magic
|
||||
// redirects to use the function from libSystem.
|
||||
text += fmt.Sprintf("//go:linkname libc_%s libc_%s\n", libcFn, libcFn)
|
||||
text += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"/usr/lib/libSystem.B.dylib\"\n", libcFn, libcFn)
|
||||
text += "\n"
|
||||
}
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), text)
|
||||
}
|
||||
|
||||
const srcTemplate = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package unix
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var _ syscall.Errno
|
||||
|
||||
%s
|
||||
`
|
404
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go
generated
vendored
404
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go
generated
vendored
@@ -1,404 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_aix.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named err.
|
||||
* If go func name needs to be different than its libc name,
|
||||
* or the function is not in libc, name could be specified
|
||||
* at the end, after "=" sign, like
|
||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
aix = flag.Bool("aix", false, "aix")
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall_aix_ppc.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
pack := ""
|
||||
text := ""
|
||||
cExtern := "/*\n#include <stdint.h>\n#include <stddef.h>\n"
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
||||
pack = p[1]
|
||||
}
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
inps = strings.Join(in, ", ")
|
||||
outps = strings.Join(out, ", ")
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
|
||||
// Check if value return, err return available
|
||||
errvar := ""
|
||||
retvar := ""
|
||||
rettype := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
} else {
|
||||
retvar = p.Name
|
||||
rettype = p.Type
|
||||
}
|
||||
}
|
||||
|
||||
// System call name.
|
||||
if sysname == "" {
|
||||
sysname = funct
|
||||
}
|
||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
||||
|
||||
cRettype := ""
|
||||
if rettype == "unsafe.Pointer" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "uintptr" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "int" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int32" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int64" {
|
||||
cRettype = "long long"
|
||||
} else if rettype == "uint32" {
|
||||
cRettype = "unsigned int"
|
||||
} else if rettype == "uint64" {
|
||||
cRettype = "unsigned long long"
|
||||
} else {
|
||||
cRettype = "int"
|
||||
}
|
||||
if sysname == "exit" {
|
||||
cRettype = "void"
|
||||
}
|
||||
|
||||
// Change p.Types to c
|
||||
var cIn []string
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "string" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t", "size_t")
|
||||
} else if p.Type == "unsafe.Pointer" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "uintptr" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "int" {
|
||||
cIn = append(cIn, "int")
|
||||
} else if p.Type == "int32" {
|
||||
cIn = append(cIn, "int")
|
||||
} else if p.Type == "int64" {
|
||||
cIn = append(cIn, "long long")
|
||||
} else if p.Type == "uint32" {
|
||||
cIn = append(cIn, "unsigned int")
|
||||
} else if p.Type == "uint64" {
|
||||
cIn = append(cIn, "unsigned long long")
|
||||
} else {
|
||||
cIn = append(cIn, "int")
|
||||
}
|
||||
}
|
||||
|
||||
if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" {
|
||||
// Imports of system calls from libc
|
||||
cExtern += fmt.Sprintf("%s %s", cRettype, sysname)
|
||||
cIn := strings.Join(cIn, ", ")
|
||||
cExtern += fmt.Sprintf("(%s);\n", cIn)
|
||||
}
|
||||
|
||||
// So file name.
|
||||
if *aix {
|
||||
if modname == "" {
|
||||
modname = "libc.a/shr_64.o"
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
strconvfunc := "C.CString"
|
||||
|
||||
// Go function header.
|
||||
if outps != "" {
|
||||
outps = fmt.Sprintf(" (%s)", outps)
|
||||
}
|
||||
if text != "" {
|
||||
text += "\n"
|
||||
}
|
||||
|
||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps)
|
||||
|
||||
// Prepare arguments to Syscall.
|
||||
var args []string
|
||||
n := 0
|
||||
argN := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, "C.uintptr_t(uintptr(unsafe.Pointer("+p.Name+")))")
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass nil in that case.
|
||||
text += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1])
|
||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(unsafe.Pointer(_p%d)))", n))
|
||||
n++
|
||||
text += fmt.Sprintf("\tvar _p%d int\n", n)
|
||||
text += fmt.Sprintf("\t_p%d = len(%s)\n", n, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.size_t(_p%d)", n))
|
||||
n++
|
||||
} else if p.Type == "int64" && endianness != "" {
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
}
|
||||
n++
|
||||
} else if p.Type == "bool" {
|
||||
text += fmt.Sprintf("\tvar _p%d uint32\n", n)
|
||||
text += fmt.Sprintf("\tif %s {\n\t\t_p%d = 1\n\t} else {\n\t\t_p%d = 0\n\t}\n", p.Name, n, n)
|
||||
args = append(args, fmt.Sprintf("_p%d", n))
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name))
|
||||
} else if p.Type == "unsafe.Pointer" {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name))
|
||||
} else if p.Type == "int" {
|
||||
if (argN == 2) && ((funct == "readlen") || (funct == "writelen")) {
|
||||
args = append(args, fmt.Sprintf("C.size_t(%s)", p.Name))
|
||||
} else if argN == 0 && funct == "fcntl" {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else if (argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt")) {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
} else if p.Type == "int32" {
|
||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
} else if p.Type == "int64" {
|
||||
args = append(args, fmt.Sprintf("C.longlong(%s)", p.Name))
|
||||
} else if p.Type == "uint32" {
|
||||
args = append(args, fmt.Sprintf("C.uint(%s)", p.Name))
|
||||
} else if p.Type == "uint64" {
|
||||
args = append(args, fmt.Sprintf("C.ulonglong(%s)", p.Name))
|
||||
} else if p.Type == "uintptr" {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
argN++
|
||||
}
|
||||
|
||||
// Actual call.
|
||||
arglist := strings.Join(args, ", ")
|
||||
call := ""
|
||||
if sysname == "exit" {
|
||||
if errvar != "" {
|
||||
call += "er :="
|
||||
} else {
|
||||
call += ""
|
||||
}
|
||||
} else if errvar != "" {
|
||||
call += "r0,er :="
|
||||
} else if retvar != "" {
|
||||
call += "r0,_ :="
|
||||
} else {
|
||||
call += ""
|
||||
}
|
||||
call += fmt.Sprintf("C.%s(%s)", sysname, arglist)
|
||||
|
||||
// Assign return values.
|
||||
body := ""
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" {
|
||||
reg = "e1"
|
||||
} else {
|
||||
reg = "r0"
|
||||
}
|
||||
if reg != "e1" {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
|
||||
// verify return
|
||||
if sysname != "exit" && errvar != "" {
|
||||
if regexp.MustCompile(`^uintptr`).FindStringSubmatch(cRettype) != nil {
|
||||
body += "\tif (uintptr(r0) ==^uintptr(0) && er != nil) {\n"
|
||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
||||
body += "\t}\n"
|
||||
} else {
|
||||
body += "\tif (r0 ==-1 && er != nil) {\n"
|
||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
||||
body += "\t}\n"
|
||||
}
|
||||
} else if errvar != "" {
|
||||
body += "\tif (er != nil) {\n"
|
||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
||||
body += "\t}\n"
|
||||
}
|
||||
|
||||
text += fmt.Sprintf("\t%s\n", call)
|
||||
text += body
|
||||
|
||||
text += "\treturn\n"
|
||||
text += "}\n"
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
imp := ""
|
||||
if pack != "unix" {
|
||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
||||
|
||||
}
|
||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, cExtern, imp, text)
|
||||
}
|
||||
|
||||
const srcTemplate = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package %s
|
||||
|
||||
|
||||
%s
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
`
|
602
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go
generated
vendored
602
vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go
generated
vendored
@@ -1,602 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_aix.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named err.
|
||||
* If go func name needs to be different than its libc name,
|
||||
* or the function is not in libc, name could be specified
|
||||
* at the end, after "=" sign, like
|
||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
||||
|
||||
|
||||
This program will generate three files and handle both gc and gccgo implementation:
|
||||
- zsyscall_aix_ppc64.go: the common part of each implementation (error handler, pointer creation)
|
||||
- zsyscall_aix_ppc64_gc.go: gc part with //go_cgo_import_dynamic and a call to syscall6
|
||||
- zsyscall_aix_ppc64_gccgo.go: gccgo part with C function and conversion to C type.
|
||||
|
||||
The generated code looks like this
|
||||
|
||||
zsyscall_aix_ppc64.go
|
||||
func asyscall(...) (n int, err error) {
|
||||
// Pointer Creation
|
||||
r1, e1 := callasyscall(...)
|
||||
// Type Conversion
|
||||
// Error Handler
|
||||
return
|
||||
}
|
||||
|
||||
zsyscall_aix_ppc64_gc.go
|
||||
//go:cgo_import_dynamic libc_asyscall asyscall "libc.a/shr_64.o"
|
||||
//go:linkname libc_asyscall libc_asyscall
|
||||
var asyscall syscallFunc
|
||||
|
||||
func callasyscall(...) (r1 uintptr, e1 Errno) {
|
||||
r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_asyscall)), "nb_args", ... )
|
||||
return
|
||||
}
|
||||
|
||||
zsyscall_aix_ppc64_ggcgo.go
|
||||
|
||||
// int asyscall(...)
|
||||
|
||||
import "C"
|
||||
|
||||
func callasyscall(...) (r1 uintptr, e1 Errno) {
|
||||
r1 = uintptr(C.asyscall(...))
|
||||
e1 = syscall.GetErrno()
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
aix = flag.Bool("aix", false, "aix")
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall_aix_ppc64.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc64.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
pack := ""
|
||||
// GCCGO
|
||||
textgccgo := ""
|
||||
cExtern := "/*\n#include <stdint.h>\n"
|
||||
// GC
|
||||
textgc := ""
|
||||
dynimports := ""
|
||||
linknames := ""
|
||||
var vars []string
|
||||
// COMMON
|
||||
textcommon := ""
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
||||
pack = p[1]
|
||||
}
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
inps = strings.Join(in, ", ")
|
||||
outps = strings.Join(out, ", ")
|
||||
|
||||
if sysname == "" {
|
||||
sysname = funct
|
||||
}
|
||||
|
||||
onlyCommon := false
|
||||
if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" {
|
||||
// This function call another syscall which is already implemented.
|
||||
// Therefore, the gc and gccgo part must not be generated.
|
||||
onlyCommon = true
|
||||
}
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
|
||||
textcommon += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
if !onlyCommon {
|
||||
textgccgo += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
textgc += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
}
|
||||
|
||||
// Check if value return, err return available
|
||||
errvar := ""
|
||||
rettype := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
} else {
|
||||
rettype = p.Type
|
||||
}
|
||||
}
|
||||
|
||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
||||
|
||||
// GCCGO Prototype return type
|
||||
cRettype := ""
|
||||
if rettype == "unsafe.Pointer" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "uintptr" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "int" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int32" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int64" {
|
||||
cRettype = "long long"
|
||||
} else if rettype == "uint32" {
|
||||
cRettype = "unsigned int"
|
||||
} else if rettype == "uint64" {
|
||||
cRettype = "unsigned long long"
|
||||
} else {
|
||||
cRettype = "int"
|
||||
}
|
||||
if sysname == "exit" {
|
||||
cRettype = "void"
|
||||
}
|
||||
|
||||
// GCCGO Prototype arguments type
|
||||
var cIn []string
|
||||
for i, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "string" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t", "size_t")
|
||||
} else if p.Type == "unsafe.Pointer" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "uintptr" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "int" {
|
||||
if (i == 0 || i == 2) && funct == "fcntl" {
|
||||
// These fcntl arguments needs to be uintptr to be able to call FcntlInt and FcntlFlock
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else {
|
||||
cIn = append(cIn, "int")
|
||||
}
|
||||
|
||||
} else if p.Type == "int32" {
|
||||
cIn = append(cIn, "int")
|
||||
} else if p.Type == "int64" {
|
||||
cIn = append(cIn, "long long")
|
||||
} else if p.Type == "uint32" {
|
||||
cIn = append(cIn, "unsigned int")
|
||||
} else if p.Type == "uint64" {
|
||||
cIn = append(cIn, "unsigned long long")
|
||||
} else {
|
||||
cIn = append(cIn, "int")
|
||||
}
|
||||
}
|
||||
|
||||
if !onlyCommon {
|
||||
// GCCGO Prototype Generation
|
||||
// Imports of system calls from libc
|
||||
cExtern += fmt.Sprintf("%s %s", cRettype, sysname)
|
||||
cIn := strings.Join(cIn, ", ")
|
||||
cExtern += fmt.Sprintf("(%s);\n", cIn)
|
||||
}
|
||||
// GC Library name
|
||||
if modname == "" {
|
||||
modname = "libc.a/shr_64.o"
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct)
|
||||
os.Exit(1)
|
||||
}
|
||||
sysvarname := fmt.Sprintf("libc_%s", sysname)
|
||||
|
||||
if !onlyCommon {
|
||||
// GC Runtime import of function to allow cross-platform builds.
|
||||
dynimports += fmt.Sprintf("//go:cgo_import_dynamic %s %s \"%s\"\n", sysvarname, sysname, modname)
|
||||
// GC Link symbol to proc address variable.
|
||||
linknames += fmt.Sprintf("//go:linkname %s %s\n", sysvarname, sysvarname)
|
||||
// GC Library proc address variable.
|
||||
vars = append(vars, sysvarname)
|
||||
}
|
||||
|
||||
strconvfunc := "BytePtrFromString"
|
||||
strconvtype := "*byte"
|
||||
|
||||
// Go function header.
|
||||
if outps != "" {
|
||||
outps = fmt.Sprintf(" (%s)", outps)
|
||||
}
|
||||
if textcommon != "" {
|
||||
textcommon += "\n"
|
||||
}
|
||||
|
||||
textcommon += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps)
|
||||
|
||||
// Prepare arguments tocall.
|
||||
var argscommon []string // Arguments in the common part
|
||||
var argscall []string // Arguments for call prototype
|
||||
var argsgc []string // Arguments for gc call (with syscall6)
|
||||
var argsgccgo []string // Arguments for gccgo call (with C.name_of_syscall)
|
||||
n := 0
|
||||
argN := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(%s))", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
||||
textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr ", n))
|
||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
||||
textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n))
|
||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass nil in that case.
|
||||
textcommon += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1])
|
||||
textcommon += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("len(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n), fmt.Sprintf("_lenp%d int", n))
|
||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n), fmt.Sprintf("uintptr(_lenp%d)", n))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n), fmt.Sprintf("C.size_t(_lenp%d)", n))
|
||||
n++
|
||||
} else if p.Type == "int64" && endianness != "" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses int64 with 32 bits mode. Case not yet implemented\n")
|
||||
} else if p.Type == "bool" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses bool. Case not yet implemented\n")
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil || p.Type == "unsafe.Pointer" {
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else if p.Type == "int" {
|
||||
if (argN == 0 || argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt") || (funct == "FcntlFlock")) {
|
||||
// These fcntl arguments need to be uintptr to be able to call FcntlInt and FcntlFlock
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
|
||||
} else {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
} else if p.Type == "int32" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s int32", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
} else if p.Type == "int64" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s int64", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.longlong(%s)", p.Name))
|
||||
} else if p.Type == "uint32" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s uint32", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uint(%s)", p.Name))
|
||||
} else if p.Type == "uint64" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s uint64", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.ulonglong(%s)", p.Name))
|
||||
} else if p.Type == "uintptr" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else {
|
||||
argscommon = append(argscommon, fmt.Sprintf("int(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
argN++
|
||||
}
|
||||
nargs := len(argsgc)
|
||||
|
||||
// COMMON function generation
|
||||
argscommonlist := strings.Join(argscommon, ", ")
|
||||
callcommon := fmt.Sprintf("call%s(%s)", sysname, argscommonlist)
|
||||
ret := []string{"_", "_"}
|
||||
body := ""
|
||||
doErrno := false
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" {
|
||||
reg = "e1"
|
||||
ret[1] = reg
|
||||
doErrno = true
|
||||
} else {
|
||||
reg = "r0"
|
||||
ret[0] = reg
|
||||
}
|
||||
if p.Type == "bool" {
|
||||
reg = fmt.Sprintf("%s != 0", reg)
|
||||
}
|
||||
if reg != "e1" {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
if ret[0] == "_" && ret[1] == "_" {
|
||||
textcommon += fmt.Sprintf("\t%s\n", callcommon)
|
||||
} else {
|
||||
textcommon += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], callcommon)
|
||||
}
|
||||
textcommon += body
|
||||
|
||||
if doErrno {
|
||||
textcommon += "\tif e1 != 0 {\n"
|
||||
textcommon += "\t\terr = errnoErr(e1)\n"
|
||||
textcommon += "\t}\n"
|
||||
}
|
||||
textcommon += "\treturn\n"
|
||||
textcommon += "}\n"
|
||||
|
||||
if onlyCommon {
|
||||
continue
|
||||
}
|
||||
|
||||
// CALL Prototype
|
||||
callProto := fmt.Sprintf("func call%s(%s) (r1 uintptr, e1 Errno) {\n", sysname, strings.Join(argscall, ", "))
|
||||
|
||||
// GC function generation
|
||||
asm := "syscall6"
|
||||
if nonblock != nil {
|
||||
asm = "rawSyscall6"
|
||||
}
|
||||
|
||||
if len(argsgc) <= 6 {
|
||||
for len(argsgc) < 6 {
|
||||
argsgc = append(argsgc, "0")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: too many arguments to system call", funct)
|
||||
os.Exit(1)
|
||||
}
|
||||
argsgclist := strings.Join(argsgc, ", ")
|
||||
callgc := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, argsgclist)
|
||||
|
||||
textgc += callProto
|
||||
textgc += fmt.Sprintf("\tr1, _, e1 = %s\n", callgc)
|
||||
textgc += "\treturn\n}\n"
|
||||
|
||||
// GCCGO function generation
|
||||
argsgccgolist := strings.Join(argsgccgo, ", ")
|
||||
callgccgo := fmt.Sprintf("C.%s(%s)", sysname, argsgccgolist)
|
||||
textgccgo += callProto
|
||||
textgccgo += fmt.Sprintf("\tr1 = uintptr(%s)\n", callgccgo)
|
||||
textgccgo += "\te1 = syscall.GetErrno()\n"
|
||||
textgccgo += "\treturn\n}\n"
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
imp := ""
|
||||
if pack != "unix" {
|
||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
||||
|
||||
}
|
||||
|
||||
// Print zsyscall_aix_ppc64.go
|
||||
err := ioutil.WriteFile("zsyscall_aix_ppc64.go",
|
||||
[]byte(fmt.Sprintf(srcTemplate1, cmdLine(), buildTags(), pack, imp, textcommon)),
|
||||
0644)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Print zsyscall_aix_ppc64_gc.go
|
||||
vardecls := "\t" + strings.Join(vars, ",\n\t")
|
||||
vardecls += " syscallFunc"
|
||||
err = ioutil.WriteFile("zsyscall_aix_ppc64_gc.go",
|
||||
[]byte(fmt.Sprintf(srcTemplate2, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, textgc)),
|
||||
0644)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Print zsyscall_aix_ppc64_gccgo.go
|
||||
err = ioutil.WriteFile("zsyscall_aix_ppc64_gccgo.go",
|
||||
[]byte(fmt.Sprintf(srcTemplate3, cmdLine(), buildTags(), pack, cExtern, imp, textgccgo)),
|
||||
0644)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
const srcTemplate1 = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package %s
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
`
|
||||
const srcTemplate2 = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
// +build !gccgo
|
||||
|
||||
package %s
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
type syscallFunc uintptr
|
||||
|
||||
var (
|
||||
%s
|
||||
)
|
||||
|
||||
// Implemented in runtime/syscall_aix.go.
|
||||
func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
|
||||
func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
|
||||
|
||||
%s
|
||||
`
|
||||
const srcTemplate3 = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
// +build gccgo
|
||||
|
||||
package %s
|
||||
|
||||
%s
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
`
|
335
vendor/golang.org/x/sys/unix/mksyscall_solaris.go
generated
vendored
335
vendor/golang.org/x/sys/unix/mksyscall_solaris.go
generated
vendored
@@ -1,335 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_solaris.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named err.
|
||||
* If go func name needs to be different than its libc name,
|
||||
* or the function is not in libc, name could be specified
|
||||
* at the end, after "=" sign, like
|
||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall_solaris.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_solaris.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
pack := ""
|
||||
text := ""
|
||||
dynimports := ""
|
||||
linknames := ""
|
||||
var vars []string
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
||||
pack = p[1]
|
||||
}
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
inps = strings.Join(in, ", ")
|
||||
outps = strings.Join(out, ", ")
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
|
||||
// So file name.
|
||||
if modname == "" {
|
||||
modname = "libc"
|
||||
}
|
||||
|
||||
// System call name.
|
||||
if sysname == "" {
|
||||
sysname = funct
|
||||
}
|
||||
|
||||
// System call pointer variable name.
|
||||
sysvarname := fmt.Sprintf("proc%s", sysname)
|
||||
|
||||
strconvfunc := "BytePtrFromString"
|
||||
strconvtype := "*byte"
|
||||
|
||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
||||
|
||||
// Runtime import of function to allow cross-platform builds.
|
||||
dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
|
||||
// Link symbol to proc address variable.
|
||||
linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
|
||||
// Library proc address variable.
|
||||
vars = append(vars, sysvarname)
|
||||
|
||||
// Go function header.
|
||||
outlist := strings.Join(out, ", ")
|
||||
if outlist != "" {
|
||||
outlist = fmt.Sprintf(" (%s)", outlist)
|
||||
}
|
||||
if text != "" {
|
||||
text += "\n"
|
||||
}
|
||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outlist)
|
||||
|
||||
// Check if err return available
|
||||
errvar := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare arguments to Syscall.
|
||||
var args []string
|
||||
n := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))")
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
text += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
text += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
||||
text += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
text += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
text += fmt.Sprintf("\t_p%d, _ = %s(%s)\n", n, strconvfunc, p.Name)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if s := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); s != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass nil in that case.
|
||||
text += fmt.Sprintf("\tvar _p%d *%s\n", n, s[1])
|
||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("uintptr(len(%s))", p.Name))
|
||||
n++
|
||||
} else if p.Type == "int64" && endianness != "" {
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
}
|
||||
} else if p.Type == "bool" {
|
||||
text += fmt.Sprintf("\tvar _p%d uint32\n", n)
|
||||
text += fmt.Sprintf("\tif %s {\n\t\t_p%d = 1\n\t} else {\n\t\t_p%d = 0\n\t}\n", p.Name, n, n)
|
||||
args = append(args, fmt.Sprintf("uintptr(_p%d)", n))
|
||||
n++
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
}
|
||||
nargs := len(args)
|
||||
|
||||
// Determine which form to use; pad args with zeros.
|
||||
asm := "sysvicall6"
|
||||
if nonblock != nil {
|
||||
asm = "rawSysvicall6"
|
||||
}
|
||||
if len(args) <= 6 {
|
||||
for len(args) < 6 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: too many arguments to system call\n", path)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Actual call.
|
||||
arglist := strings.Join(args, ", ")
|
||||
call := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, arglist)
|
||||
|
||||
// Assign return values.
|
||||
body := ""
|
||||
ret := []string{"_", "_", "_"}
|
||||
doErrno := false
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" {
|
||||
reg = "e1"
|
||||
ret[2] = reg
|
||||
doErrno = true
|
||||
} else {
|
||||
reg = fmt.Sprintf("r%d", i)
|
||||
ret[i] = reg
|
||||
}
|
||||
if p.Type == "bool" {
|
||||
reg = fmt.Sprintf("%d != 0", reg)
|
||||
}
|
||||
if p.Type == "int64" && endianness != "" {
|
||||
// 64-bit number in r1:r0 or r0:r1.
|
||||
if i+2 > len(out) {
|
||||
fmt.Fprintf(os.Stderr, "%s: not enough registers for int64 return\n", path)
|
||||
os.Exit(1)
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i, i+1)
|
||||
} else {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i+1, i)
|
||||
}
|
||||
ret[i] = fmt.Sprintf("r%d", i)
|
||||
ret[i+1] = fmt.Sprintf("r%d", i+1)
|
||||
}
|
||||
if reg != "e1" {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
if ret[0] == "_" && ret[1] == "_" && ret[2] == "_" {
|
||||
text += fmt.Sprintf("\t%s\n", call)
|
||||
} else {
|
||||
text += fmt.Sprintf("\t%s, %s, %s := %s\n", ret[0], ret[1], ret[2], call)
|
||||
}
|
||||
text += body
|
||||
|
||||
if doErrno {
|
||||
text += "\tif e1 != 0 {\n"
|
||||
text += "\t\terr = e1\n"
|
||||
text += "\t}\n"
|
||||
}
|
||||
text += "\treturn\n"
|
||||
text += "}\n"
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
imp := ""
|
||||
if pack != "unix" {
|
||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
||||
|
||||
}
|
||||
vardecls := "\t" + strings.Join(vars, ",\n\t")
|
||||
vardecls += " syscallFunc"
|
||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, text)
|
||||
}
|
||||
|
||||
const srcTemplate = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package %s
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
var (
|
||||
%s
|
||||
)
|
||||
|
||||
%s
|
||||
`
|
190
vendor/golang.org/x/sys/unix/mksysnum.go
generated
vendored
190
vendor/golang.org/x/sys/unix/mksysnum.go
generated
vendored
@@ -1,190 +0,0 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// Generate system call table for DragonFly, NetBSD,
|
||||
// FreeBSD, OpenBSD or Darwin from master list
|
||||
// (for example, /usr/src/sys/kern/syscalls.master or
|
||||
// sys/syscall.h).
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
goos, goarch string
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksysnum.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return fmt.Sprintf("%s,%s", goarch, goos)
|
||||
}
|
||||
|
||||
func checkErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// source string and substring slice for regexp
|
||||
type re struct {
|
||||
str string // source string
|
||||
sub []string // matched sub-string
|
||||
}
|
||||
|
||||
// Match performs regular expression match
|
||||
func (r *re) Match(exp string) bool {
|
||||
r.sub = regexp.MustCompile(exp).FindStringSubmatch(r.str)
|
||||
if r.sub != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// fetchFile fetches a text file from URL
|
||||
func fetchFile(URL string) io.Reader {
|
||||
resp, err := http.Get(URL)
|
||||
checkErr(err)
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
checkErr(err)
|
||||
return strings.NewReader(string(body))
|
||||
}
|
||||
|
||||
// readFile reads a text file from path
|
||||
func readFile(path string) io.Reader {
|
||||
file, err := os.Open(os.Args[1])
|
||||
checkErr(err)
|
||||
return file
|
||||
}
|
||||
|
||||
func format(name, num, proto string) string {
|
||||
name = strings.ToUpper(name)
|
||||
// There are multiple entries for enosys and nosys, so comment them out.
|
||||
nm := re{str: name}
|
||||
if nm.Match(`^SYS_E?NOSYS$`) {
|
||||
name = fmt.Sprintf("// %s", name)
|
||||
}
|
||||
if name == `SYS_SYS_EXIT` {
|
||||
name = `SYS_EXIT`
|
||||
}
|
||||
return fmt.Sprintf(" %s = %s; // %s\n", name, num, proto)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Get the OS (using GOOS_TARGET if it exist)
|
||||
goos = os.Getenv("GOOS_TARGET")
|
||||
if goos == "" {
|
||||
goos = os.Getenv("GOOS")
|
||||
}
|
||||
// Get the architecture (using GOARCH_TARGET if it exists)
|
||||
goarch = os.Getenv("GOARCH_TARGET")
|
||||
if goarch == "" {
|
||||
goarch = os.Getenv("GOARCH")
|
||||
}
|
||||
// Check if GOOS and GOARCH environment variables are defined
|
||||
if goarch == "" || goos == "" {
|
||||
fmt.Fprintf(os.Stderr, "GOARCH or GOOS not defined in environment\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
file := strings.TrimSpace(os.Args[1])
|
||||
var syscalls io.Reader
|
||||
if strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "http://") {
|
||||
// Download syscalls.master file
|
||||
syscalls = fetchFile(file)
|
||||
} else {
|
||||
syscalls = readFile(file)
|
||||
}
|
||||
|
||||
var text, line string
|
||||
s := bufio.NewScanner(syscalls)
|
||||
for s.Scan() {
|
||||
t := re{str: line}
|
||||
if t.Match(`^(.*)\\$`) {
|
||||
// Handle continuation
|
||||
line = t.sub[1]
|
||||
line += strings.TrimLeft(s.Text(), " \t")
|
||||
} else {
|
||||
// New line
|
||||
line = s.Text()
|
||||
}
|
||||
t = re{str: line}
|
||||
if t.Match(`\\$`) {
|
||||
continue
|
||||
}
|
||||
t = re{str: line}
|
||||
|
||||
switch goos {
|
||||
case "dragonfly":
|
||||
if t.Match(`^([0-9]+)\s+STD\s+({ \S+\s+(\w+).*)$`) {
|
||||
num, proto := t.sub[1], t.sub[2]
|
||||
name := fmt.Sprintf("SYS_%s", t.sub[3])
|
||||
text += format(name, num, proto)
|
||||
}
|
||||
case "freebsd":
|
||||
if t.Match(`^([0-9]+)\s+\S+\s+(?:NO)?STD\s+({ \S+\s+(\w+).*)$`) {
|
||||
num, proto := t.sub[1], t.sub[2]
|
||||
name := fmt.Sprintf("SYS_%s", t.sub[3])
|
||||
text += format(name, num, proto)
|
||||
}
|
||||
case "openbsd":
|
||||
if t.Match(`^([0-9]+)\s+STD\s+(NOLOCK\s+)?({ \S+\s+\*?(\w+).*)$`) {
|
||||
num, proto, name := t.sub[1], t.sub[3], t.sub[4]
|
||||
text += format(name, num, proto)
|
||||
}
|
||||
case "netbsd":
|
||||
if t.Match(`^([0-9]+)\s+((STD)|(NOERR))\s+(RUMP\s+)?({\s+\S+\s*\*?\s*\|(\S+)\|(\S*)\|(\w+).*\s+})(\s+(\S+))?$`) {
|
||||
num, proto, compat := t.sub[1], t.sub[6], t.sub[8]
|
||||
name := t.sub[7] + "_" + t.sub[9]
|
||||
if t.sub[11] != "" {
|
||||
name = t.sub[7] + "_" + t.sub[11]
|
||||
}
|
||||
name = strings.ToUpper(name)
|
||||
if compat == "" || compat == "13" || compat == "30" || compat == "50" {
|
||||
text += fmt.Sprintf(" %s = %s; // %s\n", name, num, proto)
|
||||
}
|
||||
}
|
||||
case "darwin":
|
||||
if t.Match(`^#define\s+SYS_(\w+)\s+([0-9]+)`) {
|
||||
name, num := t.sub[1], t.sub[2]
|
||||
name = strings.ToUpper(name)
|
||||
text += fmt.Sprintf(" SYS_%s = %s;\n", name, num)
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unrecognized GOOS=%s\n", goos)
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
}
|
||||
err := s.Err()
|
||||
checkErr(err)
|
||||
|
||||
fmt.Printf(template, cmdLine(), buildTags(), text)
|
||||
}
|
||||
|
||||
const template = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package unix
|
||||
|
||||
const(
|
||||
%s)`
|
@@ -2,9 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build openbsd
|
||||
// +build 386 amd64 arm
|
||||
|
||||
package unix
|
||||
|
||||
import (
|
12
vendor/golang.org/x/sys/unix/readdirent_getdents.go
generated
vendored
Normal file
12
vendor/golang.org/x/sys/unix/readdirent_getdents.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build aix dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package unix
|
||||
|
||||
// ReadDirent reads directory entries from fd and writes them into buf.
|
||||
func ReadDirent(fd int, buf []byte) (n int, err error) {
|
||||
return Getdents(fd, buf)
|
||||
}
|
19
vendor/golang.org/x/sys/unix/readdirent_getdirentries.go
generated
vendored
Normal file
19
vendor/golang.org/x/sys/unix/readdirent_getdirentries.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build darwin
|
||||
|
||||
package unix
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// ReadDirent reads directory entries from fd and writes them into buf.
|
||||
func ReadDirent(fd int, buf []byte) (n int, err error) {
|
||||
// Final argument is (basep *uintptr) and the syscall doesn't take nil.
|
||||
// 64 bits should be enough. (32 bits isn't even on 386). Since the
|
||||
// actual system call is getdirentries64, 64 is a good guess.
|
||||
// TODO(rsc): Can we use a single global basep for all calls?
|
||||
var base = (*uintptr)(unsafe.Pointer(new(uint64)))
|
||||
return Getdirentries(fd, buf, base)
|
||||
}
|
15
vendor/golang.org/x/sys/unix/sockcmsg_unix.go
generated
vendored
15
vendor/golang.org/x/sys/unix/sockcmsg_unix.go
generated
vendored
@@ -18,15 +18,18 @@ func cmsgAlignOf(salen int) int {
|
||||
salign := SizeofPtr
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "solaris":
|
||||
// NOTE: It seems like 64-bit Darwin, DragonFly BSD and
|
||||
// Solaris kernels still require 32-bit aligned access to
|
||||
// network subsystem.
|
||||
case "aix":
|
||||
// There is no alignment on AIX.
|
||||
salign = 1
|
||||
case "darwin", "dragonfly", "solaris", "illumos":
|
||||
// NOTE: It seems like 64-bit Darwin, DragonFly BSD,
|
||||
// illumos, and Solaris kernels still require 32-bit
|
||||
// aligned access to network subsystem.
|
||||
if SizeofPtr == 8 {
|
||||
salign = 4
|
||||
}
|
||||
case "openbsd":
|
||||
// OpenBSD armv7 requires 64-bit alignment.
|
||||
case "netbsd", "openbsd":
|
||||
// NetBSD and OpenBSD armv7 require 64-bit alignment.
|
||||
if runtime.GOARCH == "arm" {
|
||||
salign = 8
|
||||
}
|
||||
|
1
vendor/golang.org/x/sys/unix/syscall.go
generated
vendored
1
vendor/golang.org/x/sys/unix/syscall.go
generated
vendored
@@ -50,5 +50,4 @@ func BytePtrFromString(s string) (*byte, error) {
|
||||
}
|
||||
|
||||
// Single-word zero for use when we need a valid pointer to 0 bytes.
|
||||
// See mkunix.pl.
|
||||
var _zero uintptr
|
||||
|
48
vendor/golang.org/x/sys/unix/syscall_aix.go
generated
vendored
48
vendor/golang.org/x/sys/unix/syscall_aix.go
generated
vendored
@@ -280,8 +280,24 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
return -1, ENOSYS
|
||||
}
|
||||
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
reclen, ok := direntReclen(buf)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
|
||||
}
|
||||
|
||||
//sys getdirent(fd int, buf []byte) (n int, err error)
|
||||
func ReadDirent(fd int, buf []byte) (n int, err error) {
|
||||
func Getdents(fd int, buf []byte) (n int, err error) {
|
||||
return getdirent(fd, buf)
|
||||
}
|
||||
|
||||
@@ -444,8 +460,6 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
|
||||
//sysnb Times(tms *Tms) (ticks uintptr, err error)
|
||||
//sysnb Umask(mask int) (oldmask int)
|
||||
//sysnb Uname(buf *Utsname) (err error)
|
||||
//TODO umount
|
||||
// //sys Unmount(target string, flags int) (err error) = umount
|
||||
//sys Unlink(path string) (err error)
|
||||
//sys Unlinkat(dirfd int, path string, flags int) (err error)
|
||||
//sys Ustat(dev int, ubuf *Ustat_t) (err error)
|
||||
@@ -456,8 +470,8 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
|
||||
//sys Dup2(oldfd int, newfd int) (err error)
|
||||
//sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = posix_fadvise64
|
||||
//sys Fchown(fd int, uid int, gid int) (err error)
|
||||
//sys Fstat(fd int, stat *Stat_t) (err error)
|
||||
//sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = fstatat
|
||||
//sys fstat(fd int, stat *Stat_t) (err error)
|
||||
//sys fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = fstatat
|
||||
//sys Fstatfs(fd int, buf *Statfs_t) (err error)
|
||||
//sys Ftruncate(fd int, length int64) (err error)
|
||||
//sysnb Getegid() (egid int)
|
||||
@@ -466,18 +480,17 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
|
||||
//sysnb Getuid() (uid int)
|
||||
//sys Lchown(path string, uid int, gid int) (err error)
|
||||
//sys Listen(s int, n int) (err error)
|
||||
//sys Lstat(path string, stat *Stat_t) (err error)
|
||||
//sys lstat(path string, stat *Stat_t) (err error)
|
||||
//sys Pause() (err error)
|
||||
//sys Pread(fd int, p []byte, offset int64) (n int, err error) = pread64
|
||||
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = pwrite64
|
||||
//TODO Select
|
||||
// //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
|
||||
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
|
||||
//sys Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error)
|
||||
//sysnb Setregid(rgid int, egid int) (err error)
|
||||
//sysnb Setreuid(ruid int, euid int) (err error)
|
||||
//sys Shutdown(fd int, how int) (err error)
|
||||
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
|
||||
//sys Stat(path string, stat *Stat_t) (err error)
|
||||
//sys stat(path string, statptr *Stat_t) (err error)
|
||||
//sys Statfs(path string, buf *Statfs_t) (err error)
|
||||
//sys Truncate(path string, length int64) (err error)
|
||||
|
||||
@@ -493,8 +506,10 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
|
||||
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
|
||||
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
|
||||
//sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
|
||||
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
|
||||
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
|
||||
|
||||
// In order to use msghdr structure with Control, Controllen, nrecvmsg and nsendmsg must be used.
|
||||
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) = nrecvmsg
|
||||
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) = nsendmsg
|
||||
|
||||
//sys munmap(addr uintptr, length uintptr) (err error)
|
||||
|
||||
@@ -545,3 +560,14 @@ func Poll(fds []PollFd, timeout int) (n int, err error) {
|
||||
//sys gettimeofday(tv *Timeval, tzp *Timezone) (err error)
|
||||
//sysnb Time(t *Time_t) (tt Time_t, err error)
|
||||
//sys Utime(path string, buf *Utimbuf) (err error)
|
||||
|
||||
//sys Getsystemcfg(label int) (n uint64)
|
||||
|
||||
//sys umount(target string) (err error)
|
||||
func Unmount(target string, flags int) (err error) {
|
||||
if flags != 0 {
|
||||
// AIX doesn't have any flags for umount.
|
||||
return ENOSYS
|
||||
}
|
||||
return umount(target)
|
||||
}
|
||||
|
16
vendor/golang.org/x/sys/unix/syscall_aix_ppc.go
generated
vendored
16
vendor/golang.org/x/sys/unix/syscall_aix_ppc.go
generated
vendored
@@ -32,3 +32,19 @@ func (msghdr *Msghdr) SetControllen(length int) {
|
||||
func (cmsg *Cmsghdr) SetLen(length int) {
|
||||
cmsg.Len = uint32(length)
|
||||
}
|
||||
|
||||
func Fstat(fd int, stat *Stat_t) error {
|
||||
return fstat(fd, stat)
|
||||
}
|
||||
|
||||
func Fstatat(dirfd int, path string, stat *Stat_t, flags int) error {
|
||||
return fstatat(dirfd, path, stat, flags)
|
||||
}
|
||||
|
||||
func Lstat(path string, stat *Stat_t) error {
|
||||
return lstat(path, stat)
|
||||
}
|
||||
|
||||
func Stat(path string, statptr *Stat_t) error {
|
||||
return stat(path, statptr)
|
||||
}
|
||||
|
47
vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go
generated
vendored
47
vendor/golang.org/x/sys/unix/syscall_aix_ppc64.go
generated
vendored
@@ -32,3 +32,50 @@ func (msghdr *Msghdr) SetControllen(length int) {
|
||||
func (cmsg *Cmsghdr) SetLen(length int) {
|
||||
cmsg.Len = uint32(length)
|
||||
}
|
||||
|
||||
// In order to only have Timespec structure, type of Stat_t's fields
|
||||
// Atim, Mtim and Ctim is changed from StTimespec to Timespec during
|
||||
// ztypes generation.
|
||||
// On ppc64, Timespec.Nsec is an int64 while StTimespec.Nsec is an
|
||||
// int32, so the fields' value must be modified.
|
||||
func fixStatTimFields(stat *Stat_t) {
|
||||
stat.Atim.Nsec >>= 32
|
||||
stat.Mtim.Nsec >>= 32
|
||||
stat.Ctim.Nsec >>= 32
|
||||
}
|
||||
|
||||
func Fstat(fd int, stat *Stat_t) error {
|
||||
err := fstat(fd, stat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fixStatTimFields(stat)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Fstatat(dirfd int, path string, stat *Stat_t, flags int) error {
|
||||
err := fstatat(dirfd, path, stat, flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fixStatTimFields(stat)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Lstat(path string, stat *Stat_t) error {
|
||||
err := lstat(path, stat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fixStatTimFields(stat)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Stat(path string, statptr *Stat_t) error {
|
||||
err := stat(path, statptr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fixStatTimFields(statptr)
|
||||
return nil
|
||||
}
|
||||
|
12
vendor/golang.org/x/sys/unix/syscall_bsd.go
generated
vendored
12
vendor/golang.org/x/sys/unix/syscall_bsd.go
generated
vendored
@@ -63,15 +63,6 @@ func Setgroups(gids []int) (err error) {
|
||||
return setgroups(len(a), &a[0])
|
||||
}
|
||||
|
||||
func ReadDirent(fd int, buf []byte) (n int, err error) {
|
||||
// Final argument is (basep *uintptr) and the syscall doesn't take nil.
|
||||
// 64 bits should be enough. (32 bits isn't even on 386). Since the
|
||||
// actual system call is getdirentries64, 64 is a good guess.
|
||||
// TODO(rsc): Can we use a single global basep for all calls?
|
||||
var base = (*uintptr)(unsafe.Pointer(new(uint64)))
|
||||
return Getdirentries(fd, buf, base)
|
||||
}
|
||||
|
||||
// Wait status is 7 bits at bottom, either 0 (exited),
|
||||
// 0x7F (stopped), or a signal number that caused an exit.
|
||||
// The 0x80 bit is whether there was a core dump.
|
||||
@@ -86,6 +77,7 @@ const (
|
||||
shift = 8
|
||||
|
||||
exited = 0
|
||||
killed = 9
|
||||
stopped = 0x7F
|
||||
)
|
||||
|
||||
@@ -112,6 +104,8 @@ func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 }
|
||||
|
||||
func (w WaitStatus) Stopped() bool { return w&mask == stopped && syscall.Signal(w>>shift) != SIGSTOP }
|
||||
|
||||
func (w WaitStatus) Killed() bool { return w&mask == killed && syscall.Signal(w>>shift) != SIGKILL }
|
||||
|
||||
func (w WaitStatus) Continued() bool { return w&mask == stopped && syscall.Signal(w>>shift) == SIGSTOP }
|
||||
|
||||
func (w WaitStatus) StopSignal() syscall.Signal {
|
||||
|
30
vendor/golang.org/x/sys/unix/syscall_darwin.go
generated
vendored
30
vendor/golang.org/x/sys/unix/syscall_darwin.go
generated
vendored
@@ -77,7 +77,18 @@ func nametomib(name string) (mib []_C_int, err error) {
|
||||
return buf[0 : n/siz], nil
|
||||
}
|
||||
|
||||
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
|
||||
}
|
||||
|
||||
func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) }
|
||||
func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) }
|
||||
|
||||
@@ -144,6 +155,23 @@ func getAttrList(path string, attrList attrList, attrBuf []byte, options uint) (
|
||||
|
||||
//sys getattrlist(path *byte, list unsafe.Pointer, buf unsafe.Pointer, size uintptr, options int) (err error)
|
||||
|
||||
func SysctlClockinfo(name string) (*Clockinfo, error) {
|
||||
mib, err := sysctlmib(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n := uintptr(SizeofClockinfo)
|
||||
var ci Clockinfo
|
||||
if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n != SizeofClockinfo {
|
||||
return nil, EIO
|
||||
}
|
||||
return &ci, nil
|
||||
}
|
||||
|
||||
//sysnb pipe() (r int, w int, err error)
|
||||
|
||||
func Pipe(p []int) (err error) {
|
||||
|
2
vendor/golang.org/x/sys/unix/syscall_darwin_386.go
generated
vendored
2
vendor/golang.org/x/sys/unix/syscall_darwin_386.go
generated
vendored
@@ -10,6 +10,8 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
|
||||
|
||||
func setTimespec(sec, nsec int64) Timespec {
|
||||
return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
|
||||
}
|
||||
|
2
vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go
generated
vendored
2
vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go
generated
vendored
@@ -10,6 +10,8 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
|
||||
|
||||
func setTimespec(sec, nsec int64) Timespec {
|
||||
return Timespec{Sec: sec, Nsec: nsec}
|
||||
}
|
||||
|
4
vendor/golang.org/x/sys/unix/syscall_darwin_arm.go
generated
vendored
4
vendor/golang.org/x/sys/unix/syscall_darwin_arm.go
generated
vendored
@@ -8,6 +8,10 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func ptrace(request int, pid int, addr uintptr, data uintptr) error {
|
||||
return ENOTSUP
|
||||
}
|
||||
|
||||
func setTimespec(sec, nsec int64) Timespec {
|
||||
return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
|
||||
}
|
||||
|
4
vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go
generated
vendored
4
vendor/golang.org/x/sys/unix/syscall_darwin_arm64.go
generated
vendored
@@ -10,6 +10,10 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func ptrace(request int, pid int, addr uintptr, data uintptr) error {
|
||||
return ENOTSUP
|
||||
}
|
||||
|
||||
func setTimespec(sec, nsec int64) Timespec {
|
||||
return Timespec{Sec: sec, Nsec: nsec}
|
||||
}
|
||||
|
17
vendor/golang.org/x/sys/unix/syscall_dragonfly.go
generated
vendored
17
vendor/golang.org/x/sys/unix/syscall_dragonfly.go
generated
vendored
@@ -57,6 +57,22 @@ func nametomib(name string) (mib []_C_int, err error) {
|
||||
return buf[0 : n/siz], nil
|
||||
}
|
||||
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
namlen, ok := direntNamlen(buf)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return (16 + namlen + 1 + 7) &^ 7, true
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
|
||||
}
|
||||
|
||||
//sysnb pipe() (r int, w int, err error)
|
||||
|
||||
func Pipe(p []int) (err error) {
|
||||
@@ -269,6 +285,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
//sys Fstatfs(fd int, stat *Statfs_t) (err error)
|
||||
//sys Fsync(fd int) (err error)
|
||||
//sys Ftruncate(fd int, length int64) (err error)
|
||||
//sys Getdents(fd int, buf []byte) (n int, err error)
|
||||
//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
|
||||
//sys Getdtablesize() (size int)
|
||||
//sysnb Getegid() (egid int)
|
||||
|
126
vendor/golang.org/x/sys/unix/syscall_freebsd.go
generated
vendored
126
vendor/golang.org/x/sys/unix/syscall_freebsd.go
generated
vendored
@@ -82,6 +82,18 @@ func nametomib(name string) (mib []_C_int, err error) {
|
||||
return buf[0 : n/siz], nil
|
||||
}
|
||||
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
|
||||
}
|
||||
|
||||
func Pipe(p []int) (err error) {
|
||||
return Pipe2(p, 0)
|
||||
}
|
||||
@@ -362,7 +374,21 @@ func Getdents(fd int, buf []byte) (n int, err error) {
|
||||
|
||||
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
||||
if supportsABI(_ino64First) {
|
||||
return getdirentries_freebsd12(fd, buf, basep)
|
||||
if basep == nil || unsafe.Sizeof(*basep) == 8 {
|
||||
return getdirentries_freebsd12(fd, buf, (*uint64)(unsafe.Pointer(basep)))
|
||||
}
|
||||
// The freebsd12 syscall needs a 64-bit base. On 32-bit machines
|
||||
// we can't just use the basep passed in. See #32498.
|
||||
var base uint64 = uint64(*basep)
|
||||
n, err = getdirentries_freebsd12(fd, buf, &base)
|
||||
*basep = uintptr(base)
|
||||
if base>>32 != 0 {
|
||||
// We can't stuff the base back into a uintptr, so any
|
||||
// future calls would be suspect. Generate an error.
|
||||
// EIO is allowed by getdirentries.
|
||||
err = EIO
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// The old syscall entries are smaller than the new. Use 1/4 of the original
|
||||
@@ -404,22 +430,22 @@ func roundup(x, y int) int {
|
||||
|
||||
func (s *Stat_t) convertFrom(old *stat_freebsd11_t) {
|
||||
*s = Stat_t{
|
||||
Dev: uint64(old.Dev),
|
||||
Ino: uint64(old.Ino),
|
||||
Nlink: uint64(old.Nlink),
|
||||
Mode: old.Mode,
|
||||
Uid: old.Uid,
|
||||
Gid: old.Gid,
|
||||
Rdev: uint64(old.Rdev),
|
||||
Atim: old.Atim,
|
||||
Mtim: old.Mtim,
|
||||
Ctim: old.Ctim,
|
||||
Birthtim: old.Birthtim,
|
||||
Size: old.Size,
|
||||
Blocks: old.Blocks,
|
||||
Blksize: old.Blksize,
|
||||
Flags: old.Flags,
|
||||
Gen: uint64(old.Gen),
|
||||
Dev: uint64(old.Dev),
|
||||
Ino: uint64(old.Ino),
|
||||
Nlink: uint64(old.Nlink),
|
||||
Mode: old.Mode,
|
||||
Uid: old.Uid,
|
||||
Gid: old.Gid,
|
||||
Rdev: uint64(old.Rdev),
|
||||
Atim: old.Atim,
|
||||
Mtim: old.Mtim,
|
||||
Ctim: old.Ctim,
|
||||
Btim: old.Btim,
|
||||
Size: old.Size,
|
||||
Blocks: old.Blocks,
|
||||
Blksize: old.Blksize,
|
||||
Flags: old.Flags,
|
||||
Gen: uint64(old.Gen),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,6 +533,70 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
return sendfile(outfd, infd, offset, count)
|
||||
}
|
||||
|
||||
//sys ptrace(request int, pid int, addr uintptr, data int) (err error)
|
||||
|
||||
func PtraceAttach(pid int) (err error) {
|
||||
return ptrace(PTRACE_ATTACH, pid, 0, 0)
|
||||
}
|
||||
|
||||
func PtraceCont(pid int, signal int) (err error) {
|
||||
return ptrace(PTRACE_CONT, pid, 1, signal)
|
||||
}
|
||||
|
||||
func PtraceDetach(pid int) (err error) {
|
||||
return ptrace(PTRACE_DETACH, pid, 1, 0)
|
||||
}
|
||||
|
||||
func PtraceGetFpRegs(pid int, fpregsout *FpReg) (err error) {
|
||||
return ptrace(PTRACE_GETFPREGS, pid, uintptr(unsafe.Pointer(fpregsout)), 0)
|
||||
}
|
||||
|
||||
func PtraceGetFsBase(pid int, fsbase *int64) (err error) {
|
||||
return ptrace(PTRACE_GETFSBASE, pid, uintptr(unsafe.Pointer(fsbase)), 0)
|
||||
}
|
||||
|
||||
func PtraceGetRegs(pid int, regsout *Reg) (err error) {
|
||||
return ptrace(PTRACE_GETREGS, pid, uintptr(unsafe.Pointer(regsout)), 0)
|
||||
}
|
||||
|
||||
func PtraceIO(req int, pid int, addr uintptr, out []byte, countin int) (count int, err error) {
|
||||
ioDesc := PtraceIoDesc{Op: int32(req), Offs: (*byte)(unsafe.Pointer(addr)), Addr: (*byte)(unsafe.Pointer(&out[0])), Len: uint(countin)}
|
||||
err = ptrace(PTRACE_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)
|
||||
return int(ioDesc.Len), err
|
||||
}
|
||||
|
||||
func PtraceLwpEvents(pid int, enable int) (err error) {
|
||||
return ptrace(PTRACE_LWPEVENTS, pid, 0, enable)
|
||||
}
|
||||
|
||||
func PtraceLwpInfo(pid int, info uintptr) (err error) {
|
||||
return ptrace(PTRACE_LWPINFO, pid, info, int(unsafe.Sizeof(PtraceLwpInfoStruct{})))
|
||||
}
|
||||
|
||||
func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error) {
|
||||
return PtraceIO(PIOD_READ_D, pid, addr, out, SizeofLong)
|
||||
}
|
||||
|
||||
func PtracePeekText(pid int, addr uintptr, out []byte) (count int, err error) {
|
||||
return PtraceIO(PIOD_READ_I, pid, addr, out, SizeofLong)
|
||||
}
|
||||
|
||||
func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error) {
|
||||
return PtraceIO(PIOD_WRITE_D, pid, addr, data, SizeofLong)
|
||||
}
|
||||
|
||||
func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error) {
|
||||
return PtraceIO(PIOD_WRITE_I, pid, addr, data, SizeofLong)
|
||||
}
|
||||
|
||||
func PtraceSetRegs(pid int, regs *Reg) (err error) {
|
||||
return ptrace(PTRACE_SETREGS, pid, uintptr(unsafe.Pointer(regs)), 0)
|
||||
}
|
||||
|
||||
func PtraceSingleStep(pid int) (err error) {
|
||||
return ptrace(PTRACE_SINGLESTEP, pid, 1, 0)
|
||||
}
|
||||
|
||||
/*
|
||||
* Exposed directly
|
||||
*/
|
||||
@@ -555,7 +645,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
//sys Fsync(fd int) (err error)
|
||||
//sys Ftruncate(fd int, length int64) (err error)
|
||||
//sys getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
|
||||
//sys getdirentries_freebsd12(fd int, buf []byte, basep *uintptr) (n int, err error)
|
||||
//sys getdirentries_freebsd12(fd int, buf []byte, basep *uint64) (n int, err error)
|
||||
//sys Getdtablesize() (size int)
|
||||
//sysnb Getegid() (egid int)
|
||||
//sysnb Geteuid() (uid int)
|
||||
|
167
vendor/golang.org/x/sys/unix/syscall_linux.go
generated
vendored
167
vendor/golang.org/x/sys/unix/syscall_linux.go
generated
vendored
@@ -13,7 +13,6 @@ package unix
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"net"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
@@ -39,6 +38,20 @@ func Creat(path string, mode uint32) (fd int, err error) {
|
||||
return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode)
|
||||
}
|
||||
|
||||
//sys FanotifyInit(flags uint, event_f_flags uint) (fd int, err error)
|
||||
//sys fanotifyMark(fd int, flags uint, mask uint64, dirFd int, pathname *byte) (err error)
|
||||
|
||||
func FanotifyMark(fd int, flags uint, mask uint64, dirFd int, pathname string) (err error) {
|
||||
if pathname == "" {
|
||||
return fanotifyMark(fd, flags, mask, dirFd, nil)
|
||||
}
|
||||
p, err := BytePtrFromString(pathname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fanotifyMark(fd, flags, mask, dirFd, p)
|
||||
}
|
||||
|
||||
//sys fchmodat(dirfd int, path string, mode uint32) (err error)
|
||||
|
||||
func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
|
||||
@@ -95,6 +108,12 @@ func IoctlGetInt(fd int, req uint) (int, error) {
|
||||
return value, err
|
||||
}
|
||||
|
||||
func IoctlGetUint32(fd int, req uint) (uint32, error) {
|
||||
var value uint32
|
||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
||||
return value, err
|
||||
}
|
||||
|
||||
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
|
||||
var value Winsize
|
||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
||||
@@ -745,7 +764,7 @@ const px_proto_oe = 0
|
||||
|
||||
type SockaddrPPPoE struct {
|
||||
SID uint16
|
||||
Remote net.HardwareAddr
|
||||
Remote []byte
|
||||
Dev string
|
||||
raw RawSockaddrPPPoX
|
||||
}
|
||||
@@ -896,7 +915,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
|
||||
}
|
||||
sa := &SockaddrPPPoE{
|
||||
SID: binary.BigEndian.Uint16(pp[6:8]),
|
||||
Remote: net.HardwareAddr(pp[8:14]),
|
||||
Remote: pp[8:14],
|
||||
}
|
||||
for i := 14; i < 14+IFNAMSIZ; i++ {
|
||||
if pp[i] == 0 {
|
||||
@@ -990,10 +1009,50 @@ func GetsockoptString(fd, level, opt int) (string, error) {
|
||||
return string(buf[:vallen-1]), nil
|
||||
}
|
||||
|
||||
func GetsockoptTpacketStats(fd, level, opt int) (*TpacketStats, error) {
|
||||
var value TpacketStats
|
||||
vallen := _Socklen(SizeofTpacketStats)
|
||||
err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
|
||||
return &value, err
|
||||
}
|
||||
|
||||
func GetsockoptTpacketStatsV3(fd, level, opt int) (*TpacketStatsV3, error) {
|
||||
var value TpacketStatsV3
|
||||
vallen := _Socklen(SizeofTpacketStatsV3)
|
||||
err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
|
||||
return &value, err
|
||||
}
|
||||
|
||||
func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq))
|
||||
}
|
||||
|
||||
func SetsockoptPacketMreq(fd, level, opt int, mreq *PacketMreq) error {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq))
|
||||
}
|
||||
|
||||
// SetsockoptSockFprog attaches a classic BPF or an extended BPF program to a
|
||||
// socket to filter incoming packets. See 'man 7 socket' for usage information.
|
||||
func SetsockoptSockFprog(fd, level, opt int, fprog *SockFprog) error {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(fprog), unsafe.Sizeof(*fprog))
|
||||
}
|
||||
|
||||
func SetsockoptCanRawFilter(fd, level, opt int, filter []CanFilter) error {
|
||||
var p unsafe.Pointer
|
||||
if len(filter) > 0 {
|
||||
p = unsafe.Pointer(&filter[0])
|
||||
}
|
||||
return setsockopt(fd, level, opt, p, uintptr(len(filter)*SizeofCanFilter))
|
||||
}
|
||||
|
||||
func SetsockoptTpacketReq(fd, level, opt int, tp *TpacketReq) error {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(tp), unsafe.Sizeof(*tp))
|
||||
}
|
||||
|
||||
func SetsockoptTpacketReq3(fd, level, opt int, tp *TpacketReq3) error {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(tp), unsafe.Sizeof(*tp))
|
||||
}
|
||||
|
||||
// Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
|
||||
|
||||
// KeyctlInt calls keyctl commands in which each argument is an int.
|
||||
@@ -1354,8 +1413,20 @@ func Reboot(cmd int) (err error) {
|
||||
return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, "")
|
||||
}
|
||||
|
||||
func ReadDirent(fd int, buf []byte) (n int, err error) {
|
||||
return Getdents(fd, buf)
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
reclen, ok := direntReclen(buf)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
|
||||
}
|
||||
|
||||
//sys mount(source string, target string, fstype string, flags uintptr, data *byte) (err error)
|
||||
@@ -1390,6 +1461,8 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
//sys Acct(path string) (err error)
|
||||
//sys AddKey(keyType string, description string, payload []byte, ringid int) (id int, err error)
|
||||
//sys Adjtimex(buf *Timex) (state int, err error)
|
||||
//sys Capget(hdr *CapUserHeader, data *CapUserData) (err error)
|
||||
//sys Capset(hdr *CapUserHeader, data *CapUserData) (err error)
|
||||
//sys Chdir(path string) (err error)
|
||||
//sys Chroot(path string) (err error)
|
||||
//sys ClockGetres(clockid int32, res *Timespec) (err error)
|
||||
@@ -1477,9 +1550,13 @@ func Setgid(uid int) (err error) {
|
||||
return EOPNOTSUPP
|
||||
}
|
||||
|
||||
func Signalfd(fd int, sigmask *Sigset_t, flags int) (newfd int, err error) {
|
||||
return signalfd(fd, sigmask, _C__NSIG/8, flags)
|
||||
}
|
||||
|
||||
//sys Setpriority(which int, who int, prio int) (err error)
|
||||
//sys Setxattr(path string, attr string, data []byte, flags int) (err error)
|
||||
//sys Signalfd(fd int, mask *Sigset_t, flags int) = SYS_SIGNALFD4
|
||||
//sys signalfd(fd int, sigmask *Sigset_t, maskSize uintptr, flags int) (newfd int, err error) = SYS_SIGNALFD4
|
||||
//sys Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error)
|
||||
//sys Sync()
|
||||
//sys Syncfs(fd int) (err error)
|
||||
@@ -1608,6 +1685,82 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
|
||||
return EACCES
|
||||
}
|
||||
|
||||
//sys nameToHandleAt(dirFD int, pathname string, fh *fileHandle, mountID *_C_int, flags int) (err error) = SYS_NAME_TO_HANDLE_AT
|
||||
//sys openByHandleAt(mountFD int, fh *fileHandle, flags int) (fd int, err error) = SYS_OPEN_BY_HANDLE_AT
|
||||
|
||||
// fileHandle is the argument to nameToHandleAt and openByHandleAt. We
|
||||
// originally tried to generate it via unix/linux/types.go with "type
|
||||
// fileHandle C.struct_file_handle" but that generated empty structs
|
||||
// for mips64 and mips64le. Instead, hard code it for now (it's the
|
||||
// same everywhere else) until the mips64 generator issue is fixed.
|
||||
type fileHandle struct {
|
||||
Bytes uint32
|
||||
Type int32
|
||||
}
|
||||
|
||||
// FileHandle represents the C struct file_handle used by
|
||||
// name_to_handle_at (see NameToHandleAt) and open_by_handle_at (see
|
||||
// OpenByHandleAt).
|
||||
type FileHandle struct {
|
||||
*fileHandle
|
||||
}
|
||||
|
||||
// NewFileHandle constructs a FileHandle.
|
||||
func NewFileHandle(handleType int32, handle []byte) FileHandle {
|
||||
const hdrSize = unsafe.Sizeof(fileHandle{})
|
||||
buf := make([]byte, hdrSize+uintptr(len(handle)))
|
||||
copy(buf[hdrSize:], handle)
|
||||
fh := (*fileHandle)(unsafe.Pointer(&buf[0]))
|
||||
fh.Type = handleType
|
||||
fh.Bytes = uint32(len(handle))
|
||||
return FileHandle{fh}
|
||||
}
|
||||
|
||||
func (fh *FileHandle) Size() int { return int(fh.fileHandle.Bytes) }
|
||||
func (fh *FileHandle) Type() int32 { return fh.fileHandle.Type }
|
||||
func (fh *FileHandle) Bytes() []byte {
|
||||
n := fh.Size()
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
return (*[1 << 30]byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&fh.fileHandle.Type)) + 4))[:n:n]
|
||||
}
|
||||
|
||||
// NameToHandleAt wraps the name_to_handle_at system call; it obtains
|
||||
// a handle for a path name.
|
||||
func NameToHandleAt(dirfd int, path string, flags int) (handle FileHandle, mountID int, err error) {
|
||||
var mid _C_int
|
||||
// Try first with a small buffer, assuming the handle will
|
||||
// only be 32 bytes.
|
||||
size := uint32(32 + unsafe.Sizeof(fileHandle{}))
|
||||
didResize := false
|
||||
for {
|
||||
buf := make([]byte, size)
|
||||
fh := (*fileHandle)(unsafe.Pointer(&buf[0]))
|
||||
fh.Bytes = size - uint32(unsafe.Sizeof(fileHandle{}))
|
||||
err = nameToHandleAt(dirfd, path, fh, &mid, flags)
|
||||
if err == EOVERFLOW {
|
||||
if didResize {
|
||||
// We shouldn't need to resize more than once
|
||||
return
|
||||
}
|
||||
didResize = true
|
||||
size = fh.Bytes + uint32(unsafe.Sizeof(fileHandle{}))
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return FileHandle{fh}, int(mid), nil
|
||||
}
|
||||
}
|
||||
|
||||
// OpenByHandleAt wraps the open_by_handle_at system call; it opens a
|
||||
// file via a handle as previously returned by NameToHandleAt.
|
||||
func OpenByHandleAt(mountFD int, handle FileHandle, flags int) (fd int, err error) {
|
||||
return openByHandleAt(mountFD, handle.fileHandle, flags)
|
||||
}
|
||||
|
||||
/*
|
||||
* Unimplemented
|
||||
*/
|
||||
@@ -1615,8 +1768,6 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
|
||||
// Alarm
|
||||
// ArchPrctl
|
||||
// Brk
|
||||
// Capget
|
||||
// Capset
|
||||
// ClockNanosleep
|
||||
// ClockSettime
|
||||
// Clone
|
||||
|
19
vendor/golang.org/x/sys/unix/syscall_linux_arm.go
generated
vendored
19
vendor/golang.org/x/sys/unix/syscall_linux_arm.go
generated
vendored
@@ -19,12 +19,18 @@ func setTimeval(sec, usec int64) Timeval {
|
||||
return Timeval{Sec: int32(sec), Usec: int32(usec)}
|
||||
}
|
||||
|
||||
//sysnb pipe(p *[2]_C_int) (err error)
|
||||
|
||||
func Pipe(p []int) (err error) {
|
||||
if len(p) != 2 {
|
||||
return EINVAL
|
||||
}
|
||||
var pp [2]_C_int
|
||||
// Try pipe2 first for Android O, then try pipe for kernel 2.6.23.
|
||||
err = pipe2(&pp, 0)
|
||||
if err == ENOSYS {
|
||||
err = pipe(&pp)
|
||||
}
|
||||
p[0] = int(pp[0])
|
||||
p[1] = int(pp[1])
|
||||
return
|
||||
@@ -266,3 +272,16 @@ func SyncFileRange(fd int, off int64, n int64, flags int) error {
|
||||
// order of their arguments.
|
||||
return armSyncFileRange(fd, flags, off, n)
|
||||
}
|
||||
|
||||
//sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
|
||||
|
||||
func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
|
||||
cmdlineLen := len(cmdline)
|
||||
if cmdlineLen > 0 {
|
||||
// Account for the additional NULL byte added by
|
||||
// BytePtrFromString in kexecFileLoad. The kexec_file_load
|
||||
// syscall expects a NULL-terminated string.
|
||||
cmdlineLen++
|
||||
}
|
||||
return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
|
||||
}
|
||||
|
13
vendor/golang.org/x/sys/unix/syscall_linux_arm64.go
generated
vendored
13
vendor/golang.org/x/sys/unix/syscall_linux_arm64.go
generated
vendored
@@ -208,3 +208,16 @@ func Poll(fds []PollFd, timeout int) (n int, err error) {
|
||||
}
|
||||
return ppoll(&fds[0], len(fds), ts, nil)
|
||||
}
|
||||
|
||||
//sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
|
||||
|
||||
func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
|
||||
cmdlineLen := len(cmdline)
|
||||
if cmdlineLen > 0 {
|
||||
// Account for the additional NULL byte added by
|
||||
// BytePtrFromString in kexecFileLoad. The kexec_file_load
|
||||
// syscall expects a NULL-terminated string.
|
||||
cmdlineLen++
|
||||
}
|
||||
return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
|
||||
}
|
||||
|
13
vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go
generated
vendored
13
vendor/golang.org/x/sys/unix/syscall_linux_riscv64.go
generated
vendored
@@ -211,3 +211,16 @@ func Poll(fds []PollFd, timeout int) (n int, err error) {
|
||||
func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
|
||||
return Renameat2(olddirfd, oldpath, newdirfd, newpath, 0)
|
||||
}
|
||||
|
||||
//sys kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, flags int) (err error)
|
||||
|
||||
func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
|
||||
cmdlineLen := len(cmdline)
|
||||
if cmdlineLen > 0 {
|
||||
// Account for the additional NULL byte added by
|
||||
// BytePtrFromString in kexecFileLoad. The kexec_file_load
|
||||
// syscall expects a NULL-terminated string.
|
||||
cmdlineLen++
|
||||
}
|
||||
return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
|
||||
}
|
||||
|
37
vendor/golang.org/x/sys/unix/syscall_netbsd.go
generated
vendored
37
vendor/golang.org/x/sys/unix/syscall_netbsd.go
generated
vendored
@@ -94,6 +94,18 @@ func nametomib(name string) (mib []_C_int, err error) {
|
||||
return mib, nil
|
||||
}
|
||||
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
|
||||
}
|
||||
|
||||
func SysctlClockinfo(name string) (*Clockinfo, error) {
|
||||
mib, err := sysctlmib(name)
|
||||
if err != nil {
|
||||
@@ -120,9 +132,30 @@ func Pipe(p []int) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//sys getdents(fd int, buf []byte) (n int, err error)
|
||||
//sys Getdents(fd int, buf []byte) (n int, err error)
|
||||
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
||||
return getdents(fd, buf)
|
||||
n, err = Getdents(fd, buf)
|
||||
if err != nil || basep == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var off int64
|
||||
off, err = Seek(fd, 0, 1 /* SEEK_CUR */)
|
||||
if err != nil {
|
||||
*basep = ^uintptr(0)
|
||||
return
|
||||
}
|
||||
*basep = uintptr(off)
|
||||
if unsafe.Sizeof(*basep) == 8 {
|
||||
return
|
||||
}
|
||||
if off>>32 != 0 {
|
||||
// We can't stuff the offset back into a uintptr, so any
|
||||
// future calls would be suspect. Generate an error.
|
||||
// EIO is allowed by getdirentries.
|
||||
err = EIO
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const ImplementsGetwd = true
|
||||
|
54
vendor/golang.org/x/sys/unix/syscall_openbsd.go
generated
vendored
54
vendor/golang.org/x/sys/unix/syscall_openbsd.go
generated
vendored
@@ -43,6 +43,35 @@ func nametomib(name string) (mib []_C_int, err error) {
|
||||
return nil, EINVAL
|
||||
}
|
||||
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
|
||||
}
|
||||
|
||||
func SysctlClockinfo(name string) (*Clockinfo, error) {
|
||||
mib, err := sysctlmib(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n := uintptr(SizeofClockinfo)
|
||||
var ci Clockinfo
|
||||
if err := sysctl(mib, (*byte)(unsafe.Pointer(&ci)), &n, nil, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n != SizeofClockinfo {
|
||||
return nil, EIO
|
||||
}
|
||||
return &ci, nil
|
||||
}
|
||||
|
||||
func SysctlUvmexp(name string) (*Uvmexp, error) {
|
||||
mib, err := sysctlmib(name)
|
||||
if err != nil {
|
||||
@@ -72,9 +101,30 @@ func Pipe(p []int) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//sys getdents(fd int, buf []byte) (n int, err error)
|
||||
//sys Getdents(fd int, buf []byte) (n int, err error)
|
||||
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
||||
return getdents(fd, buf)
|
||||
n, err = Getdents(fd, buf)
|
||||
if err != nil || basep == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var off int64
|
||||
off, err = Seek(fd, 0, 1 /* SEEK_CUR */)
|
||||
if err != nil {
|
||||
*basep = ^uintptr(0)
|
||||
return
|
||||
}
|
||||
*basep = uintptr(off)
|
||||
if unsafe.Sizeof(*basep) == 8 {
|
||||
return
|
||||
}
|
||||
if off>>32 != 0 {
|
||||
// We can't stuff the offset back into a uintptr, so any
|
||||
// future calls would be suspect. Generate an error.
|
||||
// EIO was allowed by getdirentries.
|
||||
err = EIO
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const ImplementsGetwd = true
|
||||
|
37
vendor/golang.org/x/sys/unix/syscall_openbsd_arm64.go
generated
vendored
Normal file
37
vendor/golang.org/x/sys/unix/syscall_openbsd_arm64.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build arm64,openbsd
|
||||
|
||||
package unix
|
||||
|
||||
func setTimespec(sec, nsec int64) Timespec {
|
||||
return Timespec{Sec: sec, Nsec: nsec}
|
||||
}
|
||||
|
||||
func setTimeval(sec, usec int64) Timeval {
|
||||
return Timeval{Sec: sec, Usec: usec}
|
||||
}
|
||||
|
||||
func SetKevent(k *Kevent_t, fd, mode, flags int) {
|
||||
k.Ident = uint64(fd)
|
||||
k.Filter = int16(mode)
|
||||
k.Flags = uint16(flags)
|
||||
}
|
||||
|
||||
func (iov *Iovec) SetLen(length int) {
|
||||
iov.Len = uint64(length)
|
||||
}
|
||||
|
||||
func (msghdr *Msghdr) SetControllen(length int) {
|
||||
msghdr.Controllen = uint32(length)
|
||||
}
|
||||
|
||||
func (cmsg *Cmsghdr) SetLen(length int) {
|
||||
cmsg.Len = uint32(length)
|
||||
}
|
||||
|
||||
// SYS___SYSCTL is used by syscall_bsd.go for all BSDs, but in modern versions
|
||||
// of openbsd/amd64 the syscall is called sysctl instead of __sysctl.
|
||||
const SYS___SYSCTL = SYS_SYSCTL
|
17
vendor/golang.org/x/sys/unix/syscall_solaris.go
generated
vendored
17
vendor/golang.org/x/sys/unix/syscall_solaris.go
generated
vendored
@@ -35,6 +35,22 @@ type SockaddrDatalink struct {
|
||||
raw RawSockaddrDatalink
|
||||
}
|
||||
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
reclen, ok := direntReclen(buf)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
|
||||
}
|
||||
|
||||
//sysnb pipe(p *[2]_C_int) (n int, err error)
|
||||
|
||||
func Pipe(p []int) (err error) {
|
||||
@@ -189,6 +205,7 @@ func Setgroups(gids []int) (err error) {
|
||||
return setgroups(len(a), &a[0])
|
||||
}
|
||||
|
||||
// ReadDirent reads directory entries from fd and writes them into buf.
|
||||
func ReadDirent(fd int, buf []byte) (n int, err error) {
|
||||
// Final argument is (basep *uintptr) and the syscall doesn't take nil.
|
||||
// TODO(rsc): Can we use a single global basep for all calls?
|
||||
|
54
vendor/golang.org/x/sys/unix/syscall_unix.go
generated
vendored
54
vendor/golang.org/x/sys/unix/syscall_unix.go
generated
vendored
@@ -28,6 +28,11 @@ var (
|
||||
errENOENT error = syscall.ENOENT
|
||||
)
|
||||
|
||||
var (
|
||||
signalNameMapOnce sync.Once
|
||||
signalNameMap map[string]syscall.Signal
|
||||
)
|
||||
|
||||
// errnoErr returns common boxed Errno values, to prevent
|
||||
// allocations at runtime.
|
||||
func errnoErr(e syscall.Errno) error {
|
||||
@@ -66,6 +71,19 @@ func SignalName(s syscall.Signal) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// SignalNum returns the syscall.Signal for signal named s,
|
||||
// or 0 if a signal with such name is not found.
|
||||
// The signal name should start with "SIG".
|
||||
func SignalNum(s string) syscall.Signal {
|
||||
signalNameMapOnce.Do(func() {
|
||||
signalNameMap = make(map[string]syscall.Signal)
|
||||
for _, signal := range signalList {
|
||||
signalNameMap[signal.name] = signal.num
|
||||
}
|
||||
})
|
||||
return signalNameMap[s]
|
||||
}
|
||||
|
||||
// clen returns the index of the first NULL byte in n or len(n) if n contains no NULL byte.
|
||||
func clen(n []byte) int {
|
||||
i := bytes.IndexByte(n, 0)
|
||||
@@ -276,6 +294,13 @@ func GetsockoptTimeval(fd, level, opt int) (*Timeval, error) {
|
||||
return &tv, err
|
||||
}
|
||||
|
||||
func GetsockoptUint64(fd, level, opt int) (value uint64, err error) {
|
||||
var n uint64
|
||||
vallen := _Socklen(8)
|
||||
err = getsockopt(fd, level, opt, unsafe.Pointer(&n), &vallen)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func Recvfrom(fd int, p []byte, flags int) (n int, from Sockaddr, err error) {
|
||||
var rsa RawSockaddrAny
|
||||
var len _Socklen = SizeofSockaddrAny
|
||||
@@ -326,13 +351,21 @@ func SetsockoptLinger(fd, level, opt int, l *Linger) (err error) {
|
||||
}
|
||||
|
||||
func SetsockoptString(fd, level, opt int, s string) (err error) {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(&[]byte(s)[0]), uintptr(len(s)))
|
||||
var p unsafe.Pointer
|
||||
if len(s) > 0 {
|
||||
p = unsafe.Pointer(&[]byte(s)[0])
|
||||
}
|
||||
return setsockopt(fd, level, opt, p, uintptr(len(s)))
|
||||
}
|
||||
|
||||
func SetsockoptTimeval(fd, level, opt int, tv *Timeval) (err error) {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(tv), unsafe.Sizeof(*tv))
|
||||
}
|
||||
|
||||
func SetsockoptUint64(fd, level, opt int, value uint64) (err error) {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(&value), 8)
|
||||
}
|
||||
|
||||
func Socket(domain, typ, proto int) (fd int, err error) {
|
||||
if domain == AF_INET6 && SocketDisableIPv6 {
|
||||
return -1, EAFNOSUPPORT
|
||||
@@ -377,3 +410,22 @@ func SetNonblock(fd int, nonblocking bool) (err error) {
|
||||
func Exec(argv0 string, argv []string, envv []string) error {
|
||||
return syscall.Exec(argv0, argv, envv)
|
||||
}
|
||||
|
||||
// Lutimes sets the access and modification times tv on path. If path refers to
|
||||
// a symlink, it is not dereferenced and the timestamps are set on the symlink.
|
||||
// If tv is nil, the access and modification times are set to the current time.
|
||||
// Otherwise tv must contain exactly 2 elements, with access time as the first
|
||||
// element and modification time as the second element.
|
||||
func Lutimes(path string, tv []Timeval) error {
|
||||
if tv == nil {
|
||||
return UtimesNanoAt(AT_FDCWD, path, nil, AT_SYMLINK_NOFOLLOW)
|
||||
}
|
||||
if len(tv) != 2 {
|
||||
return EINVAL
|
||||
}
|
||||
ts := []Timespec{
|
||||
NsecToTimespec(TimevalToNsec(tv[0])),
|
||||
NsecToTimespec(TimevalToNsec(tv[1])),
|
||||
}
|
||||
return UtimesNanoAt(AT_FDCWD, path, ts, AT_SYMLINK_NOFOLLOW)
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user