Merge "ref: Persist discharges."
diff --git a/cmd/servicerunner/main.go b/cmd/servicerunner/main.go
index 34b7fe4..76e12e8 100644
--- a/cmd/servicerunner/main.go
+++ b/cmd/servicerunner/main.go
@@ -69,7 +69,7 @@
ctx, shutdown := v23.Init()
defer shutdown()
- mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
}
diff --git a/examples/rps/rpsbot/impl_test.go b/examples/rps/rpsbot/impl_test.go
index ec2d3da..2e93780 100644
--- a/examples/rps/rpsbot/impl_test.go
+++ b/examples/rps/rpsbot/impl_test.go
@@ -33,7 +33,7 @@
ctx, shutdown := test.V23Init()
defer shutdown()
- mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
}
diff --git a/runtime/internal/naming/namespace/all_test.go b/runtime/internal/naming/namespace/all_test.go
index 58be9fa..a27c68e 100644
--- a/runtime/internal/naming/namespace/all_test.go
+++ b/runtime/internal/naming/namespace/all_test.go
@@ -212,7 +212,7 @@
}
func runMT(t *testing.T, ctx *context.T, mountPoint string) *serverEntry {
- mtd, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mtd, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
boom(t, "NewMountTableDispatcher returned error: %v", err)
}
diff --git a/runtime/internal/rpc/resolve_test.go b/runtime/internal/rpc/resolve_test.go
index 2c33e04..da3649f 100644
--- a/runtime/internal/rpc/resolve_test.go
+++ b/runtime/internal/rpc/resolve_test.go
@@ -72,7 +72,7 @@
defer shutdown()
mp := ""
- mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
}
diff --git a/runtime/internal/rpc/test/client_test.go b/runtime/internal/rpc/test/client_test.go
index e131796..c886455 100644
--- a/runtime/internal/rpc/test/client_test.go
+++ b/runtime/internal/rpc/test/client_test.go
@@ -52,7 +52,7 @@
ctx, shutdown := v23.Init()
defer shutdown()
- mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
}
diff --git a/runtime/internal/vtrace/vtrace_test.go b/runtime/internal/vtrace/vtrace_test.go
index dbdb299..2a12083 100644
--- a/runtime/internal/vtrace/vtrace_test.go
+++ b/runtime/internal/vtrace/vtrace_test.go
@@ -43,7 +43,7 @@
t.Fatalf("Could not bless initial principal %v", err)
}
// Start a local mounttable.
- disp, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ disp, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
t.Fatalf("Could not create mt dispatcher %v", err)
}
diff --git a/services/binary/binaryd/main.go b/services/binary/binaryd/main.go
index 71916c0..f7788af 100644
--- a/services/binary/binaryd/main.go
+++ b/services/binary/binaryd/main.go
@@ -89,13 +89,13 @@
}
vlog.Infof("Binary repository HTTP server at: %q", rootURL)
go func() {
- if err := http.Serve(listener, http.FileServer(binarylib.NewHTTPRoot(state))); err != nil {
+ if err := http.Serve(listener, http.FileServer(binarylib.NewHTTPRoot(ctx, state))); err != nil {
vlog.Errorf("Serve() failed: %v", err)
os.Exit(1)
}
}()
- dis, err := binarylib.NewDispatcher(v23.GetPrincipal(ctx), state)
+ dis, err := binarylib.NewDispatcher(ctx, state)
if err != nil {
return fmt.Errorf("NewDispatcher() failed: %v\n", err)
}
diff --git a/services/device/internal/impl/dispatcher.go b/services/device/internal/impl/dispatcher.go
index 16f81d0..d4621a8 100644
--- a/services/device/internal/impl/dispatcher.go
+++ b/services/device/internal/impl/dispatcher.go
@@ -12,7 +12,6 @@
"strings"
"sync"
- "v.io/v23"
"v.io/v23/context"
"v.io/v23/naming"
"v.io/v23/rpc"
@@ -99,7 +98,7 @@
func NewClaimableDispatcher(ctx *context.T, config *config.State, pairingToken string) (rpc.Dispatcher, <-chan struct{}) {
var (
permsDir = PermsDir(config)
- permsStore = pathperms.NewPathStore(v23.GetPrincipal(ctx))
+ permsStore = pathperms.NewPathStore(ctx)
)
if _, _, err := permsStore.Get(permsDir); !os.IsNotExist(err) {
return nil, nil
diff --git a/services/device/internal/impl/utiltest/helpers.go b/services/device/internal/impl/utiltest/helpers.go
index 0f1260d..0e93a36 100644
--- a/services/device/internal/impl/utiltest/helpers.go
+++ b/services/device/internal/impl/utiltest/helpers.go
@@ -771,7 +771,7 @@
if err != nil {
t.Fatalf("binarylib.NewState failed: %v", err)
}
- d, err := binarylib.NewDispatcher(v23.GetPrincipal(ctx), state)
+ d, err := binarylib.NewDispatcher(ctx, state)
if err != nil {
t.Fatalf("server.NewDispatcher failed: %v", err)
}
diff --git a/services/device/internal/starter/starter.go b/services/device/internal/starter/starter.go
index 977567e..e6d6b97 100644
--- a/services/device/internal/starter/starter.go
+++ b/services/device/internal/starter/starter.go
@@ -153,6 +153,7 @@
cancel()
return "", nil, err
}
+ ctx = v23.WithListenSpec(ctx, args.Device.ListenSpec)
server, err := xrpc.NewDispatchingServer(ctx, "", dispatcher)
if err != nil {
cancel()
@@ -215,7 +216,7 @@
}
func startClaimedDevice(ctx *context.T, args Args) (func(), error) {
- permStore := pathperms.NewPathStore(v23.GetPrincipal(ctx))
+ permStore := pathperms.NewPathStore(ctx)
permsdir := impl.PermsDir(args.Device.ConfigState)
debugAuth, err := pathperms.NewHierarchicalAuthorizer(permsdir, permsdir, permStore)
if err != nil {
diff --git a/services/internal/binarylib/client.go b/services/internal/binarylib/client.go
index c04156a..2219e34 100644
--- a/services/internal/binarylib/client.go
+++ b/services/internal/binarylib/client.go
@@ -24,7 +24,6 @@
"v.io/v23/services/binary"
"v.io/v23/services/repository"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
"v.io/x/ref/services/internal/packages"
)
@@ -41,7 +40,7 @@
func Delete(ctx *context.T, name string) error {
if err := repository.BinaryClient(name).Delete(ctx); err != nil {
- vlog.Errorf("Delete() failed: %v", err)
+ ctx.Errorf("Delete() failed: %v", err)
return err
}
return nil
@@ -58,12 +57,12 @@
defer cancel()
if _, err := w.Seek(ip.offset, 0); err != nil {
- vlog.Errorf("Seek(%v, 0) failed: %v", ip.offset, err)
+ ctx.Errorf("Seek(%v, 0) failed: %v", ip.offset, err)
return false
}
stream, err := client.Download(ctx, int32(ip.index))
if err != nil {
- vlog.Errorf("Download(%v) failed: %v", ip.index, err)
+ ctx.Errorf("Download(%v) failed: %v", ip.index, err)
return false
}
h, nreceived := md5.New(), 0
@@ -71,7 +70,7 @@
for rStream.Advance() {
bytes := rStream.Value()
if _, err := w.Write(bytes); err != nil {
- vlog.Errorf("Write() failed: %v", err)
+ ctx.Errorf("Write() failed: %v", err)
return false
}
h.Write(bytes)
@@ -79,19 +78,19 @@
}
if err := rStream.Err(); err != nil {
- vlog.Errorf("Advance() failed: %v", err)
+ ctx.Errorf("Advance() failed: %v", err)
return false
}
if err := stream.Finish(); err != nil {
- vlog.Errorf("Finish() failed: %v", err)
+ ctx.Errorf("Finish() failed: %v", err)
return false
}
if expected, got := ip.part.Checksum, hex.EncodeToString(h.Sum(nil)); expected != got {
- vlog.Errorf("Unexpected checksum: expected %v, got %v", expected, got)
+ ctx.Errorf("Unexpected checksum: expected %v, got %v", expected, got)
return false
}
if expected, got := ip.part.Size, int64(nreceived); expected != got {
- vlog.Errorf("Unexpected size: expected %v, got %v", expected, got)
+ ctx.Errorf("Unexpected size: expected %v, got %v", expected, got)
return false
}
return true
@@ -110,7 +109,7 @@
client := repository.BinaryClient(von)
parts, mediaInfo, err := client.Stat(ctx)
if err != nil {
- vlog.Errorf("Stat() failed: %v", err)
+ ctx.Errorf("Stat() failed: %v", err)
return repository.MediaInfo{}, err
}
for _, part := range parts {
@@ -133,7 +132,7 @@
dir, prefix := "", ""
file, err := ioutil.TempFile(dir, prefix)
if err != nil {
- vlog.Errorf("TempFile(%v, %v) failed: %v", dir, prefix, err)
+ ctx.Errorf("TempFile(%v, %v) failed: %v", dir, prefix, err)
return nil, repository.MediaInfo{}, verror.New(errOperationFailed, ctx)
}
defer os.Remove(file.Name())
@@ -144,7 +143,7 @@
}
bytes, err := ioutil.ReadFile(file.Name())
if err != nil {
- vlog.Errorf("ReadFile(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("ReadFile(%v) failed: %v", file.Name(), err)
return nil, repository.MediaInfo{}, verror.New(errOperationFailed, ctx)
}
return bytes, mediaInfo, nil
@@ -155,36 +154,36 @@
prefix := fmt.Sprintf(".download.%s.", filepath.Base(path))
file, err := ioutil.TempFile(dir, prefix)
if err != nil {
- vlog.Errorf("TempFile(%v, %v) failed: %v", dir, prefix, err)
+ ctx.Errorf("TempFile(%v, %v) failed: %v", dir, prefix, err)
return verror.New(errOperationFailed, ctx)
}
defer file.Close()
mediaInfo, err := download(ctx, file, von)
if err != nil {
if err := os.Remove(file.Name()); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("Remove(%v) failed: %v", file.Name(), err)
}
return verror.New(errOperationFailed, ctx)
}
perm := os.FileMode(0600)
if err := file.Chmod(perm); err != nil {
- vlog.Errorf("Chmod(%v) failed: %v", perm, err)
+ ctx.Errorf("Chmod(%v) failed: %v", perm, err)
if err := os.Remove(file.Name()); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("Remove(%v) failed: %v", file.Name(), err)
}
return verror.New(errOperationFailed, ctx)
}
if err := os.Rename(file.Name(), path); err != nil {
- vlog.Errorf("Rename(%v, %v) failed: %v", file.Name(), path, err)
+ ctx.Errorf("Rename(%v, %v) failed: %v", file.Name(), path, err)
if err := os.Remove(file.Name()); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("Remove(%v) failed: %v", file.Name(), err)
}
return verror.New(errOperationFailed, ctx)
}
if err := packages.SaveMediaInfo(path, mediaInfo); err != nil {
- vlog.Errorf("packages.SaveMediaInfo(%v, %v) failed: %v", path, mediaInfo, err)
+ ctx.Errorf("packages.SaveMediaInfo(%v, %v) failed: %v", path, mediaInfo, err)
if err := os.Remove(path); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", path, err)
+ ctx.Errorf("Remove(%v) failed: %v", path, err)
}
return verror.New(errOperationFailed, ctx)
}
@@ -194,7 +193,7 @@
func DownloadUrl(ctx *context.T, von string) (string, int64, error) {
url, ttl, err := repository.BinaryClient(von).DownloadUrl(ctx)
if err != nil {
- vlog.Errorf("DownloadUrl() failed: %v", err)
+ ctx.Errorf("DownloadUrl() failed: %v", err)
return "", 0, err
}
return url, ttl, nil
@@ -206,12 +205,12 @@
offset := int64(part * partSize)
if _, err := r.Seek(offset, 0); err != nil {
- vlog.Errorf("Seek(%v, 0) failed: %v", offset, err)
+ ctx.Errorf("Seek(%v, 0) failed: %v", offset, err)
return false, nil
}
stream, err := client.Upload(ctx, int32(part))
if err != nil {
- vlog.Errorf("Upload(%v) failed: %v", part, err)
+ ctx.Errorf("Upload(%v) failed: %v", part, err)
return false, nil
}
bufferSize := partSize
@@ -225,7 +224,7 @@
n, err := r.Read(buffer[nread:])
nread += n
if err != nil && (err != io.EOF || nread < len(buffer)) {
- vlog.Errorf("Read() failed: %v", err)
+ ctx.Errorf("Read() failed: %v", err)
return false, nil
}
}
@@ -236,19 +235,19 @@
to = len(buffer)
}
if err := sender.Send(buffer[from:to]); err != nil {
- vlog.Errorf("Send() failed: %v", err)
+ ctx.Errorf("Send() failed: %v", err)
return false, nil
}
}
// TODO(gauthamt): To detect corruption, the upload checksum needs
// to be computed here rather than on the binary server.
if err := sender.Close(); err != nil {
- vlog.Errorf("Close() failed: %v", err)
+ ctx.Errorf("Close() failed: %v", err)
parts, _, statErr := client.Stat(ctx)
if statErr != nil {
- vlog.Errorf("Stat() failed: %v", statErr)
+ ctx.Errorf("Stat() failed: %v", statErr)
if deleteErr := client.Delete(ctx); err != nil {
- vlog.Errorf("Delete() failed: %v", deleteErr)
+ ctx.Errorf("Delete() failed: %v", deleteErr)
}
return false, err
}
@@ -257,12 +256,12 @@
}
}
if err := stream.Finish(); err != nil {
- vlog.Errorf("Finish() failed: %v", err)
+ ctx.Errorf("Finish() failed: %v", err)
parts, _, statErr := client.Stat(ctx)
if statErr != nil {
- vlog.Errorf("Stat() failed: %v", statErr)
+ ctx.Errorf("Stat() failed: %v", statErr)
if deleteErr := client.Delete(ctx); err != nil {
- vlog.Errorf("Delete() failed: %v", deleteErr)
+ ctx.Errorf("Delete() failed: %v", deleteErr)
}
return false, err
}
@@ -288,12 +287,12 @@
offset, whence := int64(0), 2
size, err := r.Seek(offset, whence)
if err != nil {
- vlog.Errorf("Seek(%v, %v) failed: %v", offset, whence, err)
+ ctx.Errorf("Seek(%v, %v) failed: %v", offset, whence, err)
return nil, verror.New(errOperationFailed, ctx)
}
nparts := (size-1)/partSize + 1
if err := client.Create(ctx, int32(nparts), mediaInfo); err != nil {
- vlog.Errorf("Create() failed: %v", err)
+ ctx.Errorf("Create() failed: %v", err)
return nil, err
}
h := sha256.New()
@@ -309,7 +308,7 @@
hash := h.Sum(nil)
sig, err := v23.GetPrincipal(ctx).Sign(hash[:])
if err != nil {
- vlog.Errorf("Sign() of hash failed:%v", err)
+ ctx.Errorf("Sign() of hash failed:%v", err)
return nil, err
}
return &sig, nil
@@ -331,7 +330,7 @@
func UploadFromFile(ctx *context.T, von, path string) (*security.Signature, error) {
file, err := os.Open(path)
if err != nil {
- vlog.Errorf("Open(%v) failed: %v", path, err)
+ ctx.Errorf("Open(%v) failed: %v", path, err)
return nil, verror.New(errOperationFailed, ctx)
}
defer file.Close()
diff --git a/services/internal/binarylib/client_test.go b/services/internal/binarylib/client_test.go
index 48e6820..e06b912 100644
--- a/services/internal/binarylib/client_test.go
+++ b/services/internal/binarylib/client_test.go
@@ -17,7 +17,6 @@
"v.io/v23/context"
"v.io/v23/naming"
"v.io/v23/services/repository"
- "v.io/x/lib/vlog"
"v.io/x/ref/lib/xrpc"
"v.io/x/ref/test"
@@ -38,7 +37,7 @@
}
path, perm := filepath.Join(rootDir, VersionFile), os.FileMode(0600)
if err := ioutil.WriteFile(path, []byte(Version), perm); err != nil {
- vlog.Fatalf("WriteFile(%v, %v, %v) failed: %v", path, Version, perm, err)
+ ctx.Fatalf("WriteFile(%v, %v, %v) failed: %v", path, Version, perm, err)
}
// Setup and start the binary repository server.
depth := 2
@@ -46,7 +45,7 @@
if err != nil {
t.Fatalf("NewState(%v, %v) failed: %v", rootDir, depth, err)
}
- dispatcher, err := NewDispatcher(v23.GetPrincipal(ctx), state)
+ dispatcher, err := NewDispatcher(ctx, state)
if err != nil {
t.Fatalf("NewDispatcher() failed: %v\n", err)
}
diff --git a/services/internal/binarylib/dispatcher.go b/services/internal/binarylib/dispatcher.go
index 3a138c7..f6e7dea 100644
--- a/services/internal/binarylib/dispatcher.go
+++ b/services/internal/binarylib/dispatcher.go
@@ -7,6 +7,7 @@
import (
"path/filepath"
+ "v.io/v23/context"
"v.io/v23/rpc"
"v.io/v23/security"
"v.io/v23/services/repository"
@@ -25,10 +26,10 @@
}
// NewDispatcher is the dispatcher factory.
-func NewDispatcher(principal security.Principal, state *state) (rpc.Dispatcher, error) {
+func NewDispatcher(ctx *context.T, state *state) (rpc.Dispatcher, error) {
return &dispatcher{
state: state,
- permsStore: pathperms.NewPathStore(principal),
+ permsStore: pathperms.NewPathStore(ctx),
}, nil
}
diff --git a/services/internal/binarylib/fs_utils.go b/services/internal/binarylib/fs_utils.go
index 4165a87..6545a6b 100644
--- a/services/internal/binarylib/fs_utils.go
+++ b/services/internal/binarylib/fs_utils.go
@@ -12,8 +12,8 @@
"strconv"
"strings"
+ "v.io/v23/context"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
)
const (
@@ -29,12 +29,12 @@
// the path dir to determine whether the part is valid, and the
// existence of checksum to determine whether the binary part
// exists.
-func checksumExists(path string) error {
+func checksumExists(ctx *context.T, path string) error {
switch _, err := os.Stat(path); {
case os.IsNotExist(err):
return verror.New(ErrInvalidPart, nil, path)
case err != nil:
- vlog.Errorf("Stat(%v) failed: %v", path, err)
+ ctx.Errorf("Stat(%v) failed: %v", path, err)
return verror.New(ErrOperationFailed, nil, path)
}
checksumFile := filepath.Join(path, checksumFileName)
@@ -43,7 +43,7 @@
case os.IsNotExist(err):
return verror.New(verror.ErrNoExist, nil, path)
case err != nil:
- vlog.Errorf("Stat(%v) failed: %v", checksumFile, err)
+ ctx.Errorf("Stat(%v) failed: %v", checksumFile, err)
return verror.New(ErrOperationFailed, nil, path)
default:
return nil
@@ -60,10 +60,10 @@
}
// getParts returns a collection of paths to the parts of the binary.
-func getParts(path string) ([]string, error) {
+func getParts(ctx *context.T, path string) ([]string, error) {
infos, err := ioutil.ReadDir(path)
if err != nil {
- vlog.Errorf("ReadDir(%v) failed: %v", path, err)
+ ctx.Errorf("ReadDir(%v) failed: %v", path, err)
return []string{}, verror.New(ErrOperationFailed, nil, path)
}
nDirs := 0
@@ -78,7 +78,7 @@
partName := info.Name()
idx, err := strconv.Atoi(partName)
if err != nil {
- vlog.Errorf("Atoi(%v) failed: %v", partName, err)
+ ctx.Errorf("Atoi(%v) failed: %v", partName, err)
return []string{}, verror.New(ErrOperationFailed, nil, path)
}
if idx < 0 || idx >= len(infos) || result[idx] != "" {
diff --git a/services/internal/binarylib/http.go b/services/internal/binarylib/http.go
index 7d53bf3..a7e10d8 100644
--- a/services/internal/binarylib/http.go
+++ b/services/internal/binarylib/http.go
@@ -10,19 +10,19 @@
"path/filepath"
"strings"
+ "v.io/v23/context"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
-
"v.io/x/ref/services/internal/multipart"
)
// NewHTTPRoot returns an implementation of http.FileSystem that can be used
// to serve the content in the binary service.
-func NewHTTPRoot(state *state) http.FileSystem {
- return &httpRoot{state}
+func NewHTTPRoot(ctx *context.T, state *state) http.FileSystem {
+ return &httpRoot{ctx: ctx, state: state}
}
type httpRoot struct {
+ ctx *context.T
state *state
}
@@ -33,20 +33,20 @@
// to wrap the content parts into one logical file.
func (r httpRoot) Open(name string) (http.File, error) {
name = strings.TrimPrefix(name, "/")
- vlog.Infof("HTTP handler opening %s", name)
- parts, err := getParts(r.state.dir(name))
+ r.ctx.Infof("HTTP handler opening %s", name)
+ parts, err := getParts(r.ctx, r.state.dir(name))
if err != nil {
return nil, err
}
partFiles := make([]*os.File, len(parts))
for i, part := range parts {
- if err := checksumExists(part); err != nil {
+ if err := checksumExists(r.ctx, part); err != nil {
return nil, err
}
dataPath := filepath.Join(part, dataFileName)
var err error
if partFiles[i], err = os.Open(dataPath); err != nil {
- vlog.Errorf("Open(%v) failed: %v", dataPath, err)
+ r.ctx.Errorf("Open(%v) failed: %v", dataPath, err)
return nil, verror.New(ErrOperationFailed, nil, dataPath)
}
}
diff --git a/services/internal/binarylib/impl_test.go b/services/internal/binarylib/impl_test.go
index e80062a..e46bcbf 100644
--- a/services/internal/binarylib/impl_test.go
+++ b/services/internal/binarylib/impl_test.go
@@ -19,7 +19,6 @@
"v.io/v23/naming"
"v.io/v23/services/repository"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
"v.io/x/ref/lib/xrpc"
_ "v.io/x/ref/runtime/factories/static"
@@ -48,13 +47,13 @@
t.Fatalf("NewState(%v, %v, %v) failed: %v", rootDir, listener.Addr().String(), depth, err)
}
go func() {
- if err := http.Serve(listener, http.FileServer(binarylib.NewHTTPRoot(state))); err != nil {
- vlog.Fatalf("Serve() failed: %v", err)
+ if err := http.Serve(listener, http.FileServer(binarylib.NewHTTPRoot(ctx, state))); err != nil {
+ ctx.Fatalf("Serve() failed: %v", err)
}
}()
// Setup and start the binary repository server.
- dispatcher, err := binarylib.NewDispatcher(v23.GetPrincipal(ctx), state)
+ dispatcher, err := binarylib.NewDispatcher(ctx, state)
if err != nil {
t.Fatalf("NewDispatcher failed: %v", err)
}
diff --git a/services/internal/binarylib/perms_test.go b/services/internal/binarylib/perms_test.go
index 9d3308d..b627b1a 100644
--- a/services/internal/binarylib/perms_test.go
+++ b/services/internal/binarylib/perms_test.go
@@ -18,7 +18,6 @@
"v.io/v23/security/access"
"v.io/v23/services/repository"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
vsecurity "v.io/x/ref/lib/security"
"v.io/x/ref/lib/signals"
"v.io/x/ref/lib/xrpc"
@@ -32,32 +31,31 @@
//go:generate v23 test generate
var binaryd = modules.Register(func(env *modules.Env, args ...string) error {
+ ctx, shutdown := test.V23Init()
if len(args) < 2 {
- vlog.Fatalf("binaryd expected at least name and store arguments and optionally AccessList flags per PermissionsFromFlag")
+ ctx.Fatalf("binaryd expected at least name and store arguments and optionally AccessList flags per PermissionsFromFlag")
}
publishName := args[0]
storedir := args[1]
- ctx, shutdown := test.V23Init()
-
defer fmt.Fprintf(env.Stdout, "%v terminating\n", publishName)
- defer vlog.VI(1).Infof("%v terminating", publishName)
+ defer ctx.VI(1).Infof("%v terminating", publishName)
defer shutdown()
depth := 2
state, err := binarylib.NewState(storedir, "", depth)
if err != nil {
- vlog.Fatalf("NewState(%v, %v, %v) failed: %v", storedir, "", depth, err)
+ ctx.Fatalf("NewState(%v, %v, %v) failed: %v", storedir, "", depth, err)
}
- dispatcher, err := binarylib.NewDispatcher(v23.GetPrincipal(ctx), state)
+ dispatcher, err := binarylib.NewDispatcher(ctx, state)
if err != nil {
- vlog.Fatalf("Failed to create binaryd dispatcher: %v", err)
+ ctx.Fatalf("Failed to create binaryd dispatcher: %v", err)
}
server, err := xrpc.NewDispatchingServer(ctx, publishName, dispatcher)
if err != nil {
- vlog.Fatalf("NewDispatchingServer(%v) failed: %v", publishName, err)
+ ctx.Fatalf("NewDispatchingServer(%v) failed: %v", publishName, err)
}
- vlog.VI(1).Infof("binaryd name: %v", server.Status().Endpoints[0].Name())
+ ctx.VI(1).Infof("binaryd name: %v", server.Status().Endpoints[0].Name())
fmt.Fprintf(env.Stdout, "ready:%d\n", os.Getpid())
<-signals.ShutdownOnSignals(ctx)
@@ -111,7 +109,7 @@
pid := servicetest.ReadPID(t, nmh)
defer syscall.Kill(pid, syscall.SIGINT)
- vlog.VI(2).Infof("Self uploads a shared and private binary.")
+ ctx.VI(2).Infof("Self uploads a shared and private binary.")
if err := b("bini/private").Create(childCtx, 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed %v", err)
}
@@ -120,7 +118,7 @@
t.Fatalf("invokeUpload() failed %v, %v", err, streamErr)
}
- vlog.VI(2).Infof("Validate that the AccessList also allows Self")
+ ctx.VI(2).Infof("Validate that the AccessList also allows Self")
perms, _, err := b("bini/private").GetPermissions(selfCtx)
if err != nil {
t.Fatalf("GetPermissions failed: %v", err)
@@ -168,7 +166,7 @@
pid := servicetest.ReadPID(t, nmh)
defer syscall.Kill(pid, syscall.SIGINT)
- vlog.VI(2).Infof("Self uploads a shared and private binary.")
+ ctx.VI(2).Infof("Self uploads a shared and private binary.")
if err := b("bini/private").Create(selfCtx, 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed %v", err)
}
@@ -185,7 +183,7 @@
t.Fatalf("invokeUpload() failed %v, %v", err, streamErr)
}
- vlog.VI(2).Infof("Verify that in the beginning other can't access bini/private or bini/shared")
+ ctx.VI(2).Infof("Verify that in the beginning other can't access bini/private or bini/shared")
if _, _, err := b("bini/private").Stat(otherCtx); verror.ErrorID(err) != verror.ErrNoAccess.ID {
t.Fatalf("Stat() should have failed but didn't: %v", err)
}
@@ -193,7 +191,7 @@
t.Fatalf("Stat() should have failed but didn't: %v", err)
}
- vlog.VI(2).Infof("Validate the AccessList file on bini/private.")
+ ctx.VI(2).Infof("Validate the AccessList file on bini/private.")
perms, _, err := b("bini/private").GetPermissions(selfCtx)
if err != nil {
t.Fatalf("GetPermissions failed: %v", err)
@@ -209,7 +207,7 @@
t.Errorf("got %#v, expected %#v ", got, want)
}
- vlog.VI(2).Infof("Validate the AccessList file on bini/private.")
+ ctx.VI(2).Infof("Validate the AccessList file on bini/private.")
perms, version, err := b("bini/private").GetPermissions(selfCtx)
if err != nil {
t.Fatalf("GetPermissions failed: %v", err)
@@ -218,7 +216,7 @@
t.Errorf("got %#v, expected %#v ", got, want)
}
- vlog.VI(2).Infof("self blesses other as self/other and locks the bini/private binary to itself.")
+ ctx.VI(2).Infof("self blesses other as self/other and locks the bini/private binary to itself.")
selfBlessing := selfPrincipal.BlessingStore().Default()
otherBlessing, err := selfPrincipal.Bless(otherPrincipal.PublicKey(), selfBlessing, "other", security.UnconstrainedUse())
if err != nil {
@@ -228,7 +226,7 @@
t.Fatalf("otherPrincipal.BlessingStore() failed: %v", err)
}
- vlog.VI(2).Infof("Self modifies the AccessList file on bini/private.")
+ ctx.VI(2).Infof("Self modifies the AccessList file on bini/private.")
for _, tag := range access.AllTypicalTags() {
perms.Clear("self", string(tag))
perms.Add("self/$", string(tag))
@@ -237,7 +235,7 @@
t.Fatalf("SetPermissions failed: %v", err)
}
- vlog.VI(2).Infof(" Verify that bini/private's perms are updated.")
+ ctx.VI(2).Infof(" Verify that bini/private's perms are updated.")
updated := access.Permissions{
"Admin": access.AccessList{In: []security.BlessingPattern{"self/$"}},
"Read": access.AccessList{In: []security.BlessingPattern{"self/$"}},
@@ -256,12 +254,12 @@
// Other still can't access bini/shared because there's no AccessList file at the
// root level. Self has to set one explicitly to enable sharing. This way, self
// can't accidentally expose the server without setting a root AccessList.
- vlog.VI(2).Infof(" Verify that other still can't access bini/shared.")
+ ctx.VI(2).Infof(" Verify that other still can't access bini/shared.")
if _, _, err := b("bini/shared").Stat(otherCtx); verror.ErrorID(err) != verror.ErrNoAccess.ID {
t.Fatalf("Stat() should have failed but didn't: %v", err)
}
- vlog.VI(2).Infof("Self sets a root AccessList.")
+ ctx.VI(2).Infof("Self sets a root AccessList.")
newRootAccessList := make(access.Permissions)
for _, tag := range access.AllTypicalTags() {
newRootAccessList.Add("self/$", string(tag))
@@ -270,7 +268,7 @@
t.Fatalf("SetPermissions failed: %v", err)
}
- vlog.VI(2).Infof("Verify that other can access bini/shared now but not access bini/private.")
+ ctx.VI(2).Infof("Verify that other can access bini/shared now but not access bini/private.")
if _, _, err := b("bini/shared").Stat(otherCtx); err != nil {
t.Fatalf("Stat() shouldn't have failed: %v", err)
}
@@ -278,7 +276,7 @@
t.Fatalf("Stat() should have failed but didn't: %v", err)
}
- vlog.VI(2).Infof("Other still can't create so Self gives Other right to Create.")
+ ctx.VI(2).Infof("Other still can't create so Self gives Other right to Create.")
perms, tag, err := b("bini").GetPermissions(selfCtx)
if err != nil {
t.Fatalf("GetPermissions() failed: %v", err)
@@ -303,7 +301,7 @@
t.Fatalf("SetPermissions() failed: %v", err)
}
- vlog.VI(2).Infof("Other creates bini/otherbinary")
+ ctx.VI(2).Infof("Other creates bini/otherbinary")
if err := b("bini/otherbinary").Create(otherCtx, 1, repository.MediaInfo{Type: "application/octet-stream"}); err != nil {
t.Fatalf("Create() failed %v", err)
}
@@ -312,7 +310,7 @@
t.FailNow()
}
- vlog.VI(2).Infof("Other can read perms for bini/otherbinary.")
+ ctx.VI(2).Infof("Other can read perms for bini/otherbinary.")
updated = access.Permissions{
"Admin": access.AccessList{In: []security.BlessingPattern{"self/$", "self/other"}},
"Read": access.AccessList{In: []security.BlessingPattern{"self/$", "self/other"}},
@@ -328,7 +326,7 @@
t.Errorf("got %#v, expected %#v ", got, want)
}
- vlog.VI(2).Infof("Other tries to exclude self by removing self from the AccessList set")
+ ctx.VI(2).Infof("Other tries to exclude self by removing self from the AccessList set")
perms, tag, err = b("bini/otherbinary").GetPermissions(otherCtx)
if err != nil {
t.Fatalf("GetPermissions() failed: %v", err)
@@ -339,7 +337,7 @@
t.Fatalf("SetPermissions() failed: %v", err)
}
- vlog.VI(2).Infof("Verify that other can make this change.")
+ ctx.VI(2).Infof("Verify that other can make this change.")
updated = access.Permissions{
"Admin": access.AccessList{In: []security.BlessingPattern{"self/other"}},
"Read": access.AccessList{In: []security.BlessingPattern{"self/other"}},
@@ -355,12 +353,12 @@
t.Errorf("got %#v, expected %#v ", got, want)
}
- vlog.VI(2).Infof("But self's rights are inherited from root so self can still access despite this.")
+ ctx.VI(2).Infof("But self's rights are inherited from root so self can still access despite this.")
if _, _, err := b("bini/otherbinary").Stat(selfCtx); err != nil {
t.Fatalf("Stat() shouldn't have failed: %v", err)
}
- vlog.VI(2).Infof("Self petulantly blacklists other back.")
+ ctx.VI(2).Infof("Self petulantly blacklists other back.")
perms, tag, err = b("bini").GetPermissions(selfCtx)
if err != nil {
t.Fatalf("GetPermissions() failed: %v", err)
@@ -373,17 +371,17 @@
t.Fatalf("SetPermissions() failed: %v", err)
}
- vlog.VI(2).Infof("And now other can do nothing at affecting the root. Other should be penitent.")
+ ctx.VI(2).Infof("And now other can do nothing at affecting the root. Other should be penitent.")
if err := b("bini/nototherbinary").Create(otherCtx, 1, repository.MediaInfo{Type: "application/octet-stream"}); verror.ErrorID(err) != verror.ErrNoAccess.ID {
t.Fatalf("Create() should have failed %v", err)
}
- vlog.VI(2).Infof("But other can still access shared.")
+ ctx.VI(2).Infof("But other can still access shared.")
if _, _, err := b("bini/shared").Stat(otherCtx); err != nil {
t.Fatalf("Stat() should not have failed but did: %v", err)
}
- vlog.VI(2).Infof("Self petulantly blacklists other's binary too.")
+ ctx.VI(2).Infof("Self petulantly blacklists other's binary too.")
perms, tag, err = b("bini/shared").GetPermissions(selfCtx)
if err != nil {
t.Fatalf("GetPermissions() failed: %v", err)
@@ -395,14 +393,14 @@
if err != nil {
t.Fatalf("SetPermissions() failed: %v", err)
}
- vlog.VI(2).Infof("And now other can't access shared either.")
+ ctx.VI(2).Infof("And now other can't access shared either.")
if _, _, err := b("bini/shared").Stat(otherCtx); verror.ErrorID(err) != verror.ErrNoAccess.ID {
t.Fatalf("Stat() should have failed but didn't: %v", err)
}
// TODO(rjkroege): Extend the test with a third principal and verify that
// new principals can be given Admin perimission at the root.
- vlog.VI(2).Infof("Self feels guilty for petulance and disempowers itself")
+ ctx.VI(2).Infof("Self feels guilty for petulance and disempowers itself")
// TODO(rjkroege,caprita): This is a one-way transition for self. Perhaps it
// should not be. Consider adding a factory-reset facility.
perms, tag, err = b("bini").GetPermissions(selfCtx)
@@ -415,7 +413,7 @@
t.Fatalf("SetPermissions() failed: %v", err)
}
- vlog.VI(2).Info("Self can't access other's binary now")
+ ctx.VI(2).Info("Self can't access other's binary now")
if _, _, err := b("bini/otherbinary").Stat(selfCtx); err == nil {
t.Fatalf("Stat() should have failed but didn't")
}
diff --git a/services/internal/binarylib/service.go b/services/internal/binarylib/service.go
index 75e6718..e9bf201 100644
--- a/services/internal/binarylib/service.go
+++ b/services/internal/binarylib/service.go
@@ -47,7 +47,6 @@
"v.io/v23/services/binary"
"v.io/v23/services/repository"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
"v.io/x/ref/services/internal/pathperms"
)
@@ -94,24 +93,24 @@
const BufferLength = 4096
func (i *binaryService) Create(ctx *context.T, call rpc.ServerCall, nparts int32, mediaInfo repository.MediaInfo) error {
- vlog.Infof("%v.Create(%v, %v)", i.suffix, nparts, mediaInfo)
+ ctx.Infof("%v.Create(%v, %v)", i.suffix, nparts, mediaInfo)
if nparts < 1 {
return verror.New(ErrInvalidParts, ctx)
}
parent, perm := filepath.Dir(i.path), os.FileMode(0700)
if err := os.MkdirAll(parent, perm); err != nil {
- vlog.Errorf("MkdirAll(%v, %v) failed: %v", parent, perm, err)
+ ctx.Errorf("MkdirAll(%v, %v) failed: %v", parent, perm, err)
return verror.New(ErrOperationFailed, ctx)
}
prefix := "creating-"
tmpDir, err := ioutil.TempDir(parent, prefix)
if err != nil {
- vlog.Errorf("TempDir(%v, %v) failed: %v", parent, prefix, err)
+ ctx.Errorf("TempDir(%v, %v) failed: %v", parent, prefix, err)
return verror.New(ErrOperationFailed, ctx)
}
nameFile := filepath.Join(tmpDir, nameFileName)
if err := ioutil.WriteFile(nameFile, []byte(i.suffix), os.FileMode(0600)); err != nil {
- vlog.Errorf("WriteFile(%q) failed: %v", nameFile, err)
+ ctx.Errorf("WriteFile(%q) failed: %v", nameFile, err)
return verror.New(ErrOperationFailed, ctx)
}
@@ -121,26 +120,26 @@
return verror.New(ErrNotAuthorized, ctx)
}
if err := i.permsStore.Set(permsPath(i.state.rootDir, i.suffix), pathperms.PermissionsForBlessings(rb), ""); err != nil {
- vlog.Errorf("insertPermissions(%v) failed: %v", rb, err)
+ ctx.Errorf("insertPermissions(%v) failed: %v", rb, err)
return verror.New(ErrOperationFailed, ctx)
}
infoFile := filepath.Join(tmpDir, mediaInfoFileName)
jInfo, err := json.Marshal(mediaInfo)
if err != nil {
- vlog.Errorf("json.Marshal(%v) failed: %v", mediaInfo, err)
+ ctx.Errorf("json.Marshal(%v) failed: %v", mediaInfo, err)
return verror.New(ErrOperationFailed, ctx)
}
if err := ioutil.WriteFile(infoFile, jInfo, os.FileMode(0600)); err != nil {
- vlog.Errorf("WriteFile(%q) failed: %v", infoFile, err)
+ ctx.Errorf("WriteFile(%q) failed: %v", infoFile, err)
return verror.New(ErrOperationFailed, ctx)
}
for j := 0; j < int(nparts); j++ {
partPath, partPerm := generatePartPath(tmpDir, j), os.FileMode(0700)
if err := os.MkdirAll(partPath, partPerm); err != nil {
- vlog.Errorf("MkdirAll(%v, %v) failed: %v", partPath, partPerm, err)
+ ctx.Errorf("MkdirAll(%v, %v) failed: %v", partPath, partPerm, err)
if err := os.RemoveAll(tmpDir); err != nil {
- vlog.Errorf("RemoveAll(%v) failed: %v", tmpDir, err)
+ ctx.Errorf("RemoveAll(%v) failed: %v", tmpDir, err)
}
return verror.New(ErrOperationFailed, ctx)
}
@@ -150,36 +149,36 @@
if err := os.Rename(tmpDir, i.path); err != nil {
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
- vlog.Errorf("RemoveAll(%v) failed: %v", tmpDir, err)
+ ctx.Errorf("RemoveAll(%v) failed: %v", tmpDir, err)
}
}()
if linkErr, ok := err.(*os.LinkError); ok && linkErr.Err == syscall.ENOTEMPTY {
return verror.New(verror.ErrExist, ctx, i.path)
}
- vlog.Errorf("Rename(%v, %v) failed: %v", tmpDir, i.path, err)
+ ctx.Errorf("Rename(%v, %v) failed: %v", tmpDir, i.path, err)
return verror.New(ErrOperationFailed, ctx, i.path)
}
return nil
}
func (i *binaryService) Delete(ctx *context.T, _ rpc.ServerCall) error {
- vlog.Infof("%v.Delete()", i.suffix)
+ ctx.Infof("%v.Delete()", i.suffix)
if _, err := os.Stat(i.path); err != nil {
if os.IsNotExist(err) {
return verror.New(verror.ErrNoExist, ctx, i.path)
}
- vlog.Errorf("Stat(%v) failed: %v", i.path, err)
+ ctx.Errorf("Stat(%v) failed: %v", i.path, err)
return verror.New(ErrOperationFailed, ctx)
}
// Use os.Rename() to atomically remove the binary directory
// structure.
path := filepath.Join(filepath.Dir(i.path), "removing-"+filepath.Base(i.path))
if err := os.Rename(i.path, path); err != nil {
- vlog.Errorf("Rename(%v, %v) failed: %v", i.path, path, err)
+ ctx.Errorf("Rename(%v, %v) failed: %v", i.path, path, err)
return verror.New(ErrOperationFailed, ctx, i.path)
}
if err := os.RemoveAll(path); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", path, err)
+ ctx.Errorf("Remove(%v) failed: %v", path, err)
return verror.New(ErrOperationFailed, ctx)
}
for {
@@ -193,7 +192,7 @@
if err.(*os.PathError).Err.Error() == syscall.ENOTEMPTY.Error() {
break
}
- vlog.Errorf("Remove(%v) failed: %v", path, err)
+ ctx.Errorf("Remove(%v) failed: %v", path, err)
return verror.New(ErrOperationFailed, ctx)
}
}
@@ -201,15 +200,15 @@
}
func (i *binaryService) Download(ctx *context.T, call repository.BinaryDownloadServerCall, part int32) error {
- vlog.Infof("%v.Download(%v)", i.suffix, part)
+ ctx.Infof("%v.Download(%v)", i.suffix, part)
path := i.generatePartPath(int(part))
- if err := checksumExists(path); err != nil {
+ if err := checksumExists(ctx, path); err != nil {
return err
}
dataPath := filepath.Join(path, dataFileName)
file, err := os.Open(dataPath)
if err != nil {
- vlog.Errorf("Open(%v) failed: %v", dataPath, err)
+ ctx.Errorf("Open(%v) failed: %v", dataPath, err)
return verror.New(ErrOperationFailed, ctx)
}
defer file.Close()
@@ -218,14 +217,14 @@
for {
n, err := file.Read(buffer)
if err != nil && err != io.EOF {
- vlog.Errorf("Read() failed: %v", err)
+ ctx.Errorf("Read() failed: %v", err)
return verror.New(ErrOperationFailed, ctx)
}
if n == 0 {
break
}
if err := sender.Send(buffer[:n]); err != nil {
- vlog.Errorf("Send() failed: %v", err)
+ ctx.Errorf("Send() failed: %v", err)
return verror.New(ErrOperationFailed, ctx)
}
}
@@ -234,15 +233,15 @@
// TODO(jsimsa): Design and implement an access control mechanism for
// the URL-based downloads.
-func (i *binaryService) DownloadUrl(*context.T, rpc.ServerCall) (string, int64, error) {
- vlog.Infof("%v.DownloadUrl()", i.suffix)
+func (i *binaryService) DownloadUrl(ctx *context.T, _ rpc.ServerCall) (string, int64, error) {
+ ctx.Infof("%v.DownloadUrl()", i.suffix)
return i.state.rootURL + "/" + i.suffix, 0, nil
}
func (i *binaryService) Stat(ctx *context.T, _ rpc.ServerCall) ([]binary.PartInfo, repository.MediaInfo, error) {
- vlog.Infof("%v.Stat()", i.suffix)
+ ctx.Infof("%v.Stat()", i.suffix)
result := make([]binary.PartInfo, 0)
- parts, err := getParts(i.path)
+ parts, err := getParts(ctx, i.path)
if err != nil {
return []binary.PartInfo{}, repository.MediaInfo{}, err
}
@@ -254,7 +253,7 @@
result = append(result, MissingPart)
continue
}
- vlog.Errorf("ReadFile(%v) failed: %v", checksumFile, err)
+ ctx.Errorf("ReadFile(%v) failed: %v", checksumFile, err)
return []binary.PartInfo{}, repository.MediaInfo{}, verror.New(ErrOperationFailed, ctx)
}
dataFile := filepath.Join(part, dataFileName)
@@ -264,7 +263,7 @@
result = append(result, MissingPart)
continue
}
- vlog.Errorf("Stat(%v) failed: %v", dataFile, err)
+ ctx.Errorf("Stat(%v) failed: %v", dataFile, err)
return []binary.PartInfo{}, repository.MediaInfo{}, verror.New(ErrOperationFailed, ctx)
}
result = append(result, binary.PartInfo{Checksum: string(bytes), Size: fi.Size()})
@@ -272,21 +271,21 @@
infoFile := filepath.Join(i.path, mediaInfoFileName)
jInfo, err := ioutil.ReadFile(infoFile)
if err != nil {
- vlog.Errorf("ReadFile(%q) failed: %v", infoFile, err)
+ ctx.Errorf("ReadFile(%q) failed: %v", infoFile, err)
return []binary.PartInfo{}, repository.MediaInfo{}, verror.New(ErrOperationFailed, ctx)
}
var mediaInfo repository.MediaInfo
if err := json.Unmarshal(jInfo, &mediaInfo); err != nil {
- vlog.Errorf("json.Unmarshal(%v) failed: %v", jInfo, err)
+ ctx.Errorf("json.Unmarshal(%v) failed: %v", jInfo, err)
return []binary.PartInfo{}, repository.MediaInfo{}, verror.New(ErrOperationFailed, ctx)
}
return result, mediaInfo, nil
}
func (i *binaryService) Upload(ctx *context.T, call repository.BinaryUploadServerCall, part int32) error {
- vlog.Infof("%v.Upload(%v)", i.suffix, part)
+ ctx.Infof("%v.Upload(%v)", i.suffix, part)
path, suffix := i.generatePartPath(int(part)), ""
- err := checksumExists(path)
+ err := checksumExists(ctx, path)
if err == nil {
return verror.New(verror.ErrExist, ctx, path)
} else if verror.ErrorID(err) != verror.ErrNoExist.ID {
@@ -299,14 +298,14 @@
if os.IsExist(err) {
return verror.New(ErrInProgress, ctx, path)
}
- vlog.Errorf("OpenFile(%v, %v, %v) failed: %v", lockPath, flags, suffix, err)
+ ctx.Errorf("OpenFile(%v, %v, %v) failed: %v", lockPath, flags, suffix, err)
return verror.New(ErrOperationFailed, ctx)
}
defer os.Remove(lockFile.Name())
defer lockFile.Close()
file, err := ioutil.TempFile(path, suffix)
if err != nil {
- vlog.Errorf("TempFile(%v, %v) failed: %v", path, suffix, err)
+ ctx.Errorf("TempFile(%v, %v) failed: %v", path, suffix, err)
return verror.New(ErrOperationFailed, ctx)
}
defer file.Close()
@@ -315,9 +314,9 @@
for rStream.Advance() {
bytes := rStream.Value()
if _, err := file.Write(bytes); err != nil {
- vlog.Errorf("Write() failed: %v", err)
+ ctx.Errorf("Write() failed: %v", err)
if err := os.Remove(file.Name()); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("Remove(%v) failed: %v", file.Name(), err)
}
return verror.New(ErrOperationFailed, ctx)
}
@@ -325,9 +324,9 @@
}
if err := rStream.Err(); err != nil {
- vlog.Errorf("Advance() failed: %v", err)
+ ctx.Errorf("Advance() failed: %v", err)
if err := os.Remove(file.Name()); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("Remove(%v) failed: %v", file.Name(), err)
}
return verror.New(ErrOperationFailed, ctx)
}
@@ -335,17 +334,17 @@
hash := hex.EncodeToString(h.Sum(nil))
checksumFile, perm := filepath.Join(path, checksumFileName), os.FileMode(0600)
if err := ioutil.WriteFile(checksumFile, []byte(hash), perm); err != nil {
- vlog.Errorf("WriteFile(%v, %v, %v) failed: %v", checksumFile, hash, perm, err)
+ ctx.Errorf("WriteFile(%v, %v, %v) failed: %v", checksumFile, hash, perm, err)
if err := os.Remove(file.Name()); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("Remove(%v) failed: %v", file.Name(), err)
}
return verror.New(ErrOperationFailed, ctx)
}
dataFile := filepath.Join(path, dataFileName)
if err := os.Rename(file.Name(), dataFile); err != nil {
- vlog.Errorf("Rename(%v, %v) failed: %v", file.Name(), dataFile, err)
+ ctx.Errorf("Rename(%v, %v) failed: %v", file.Name(), dataFile, err)
if err := os.Remove(file.Name()); err != nil {
- vlog.Errorf("Remove(%v) failed: %v", file.Name(), err)
+ ctx.Errorf("Remove(%v) failed: %v", file.Name(), err)
}
return verror.New(ErrOperationFailed, ctx)
}
diff --git a/services/internal/binarylib/setup.go b/services/internal/binarylib/setup.go
index aad59eb..e01ab2b 100644
--- a/services/internal/binarylib/setup.go
+++ b/services/internal/binarylib/setup.go
@@ -9,7 +9,7 @@
"os"
"path/filepath"
- "v.io/x/lib/vlog"
+ "v.io/x/ref/internal/logger"
)
const defaultRootPrefix = "veyron_binary_repository"
@@ -20,12 +20,12 @@
if root == "" {
var err error
if root, err = ioutil.TempDir("", defaultRootPrefix); err != nil {
- vlog.Errorf("TempDir() failed: %v\n", err)
+ logger.Global().Errorf("TempDir() failed: %v\n", err)
return "", err
}
path, perm := filepath.Join(root, VersionFile), os.FileMode(0600)
if err := ioutil.WriteFile(path, []byte(Version), perm); err != nil {
- vlog.Errorf("WriteFile(%v, %v, %v) failed: %v", path, Version, perm, err)
+ logger.Global().Errorf("WriteFile(%v, %v, %v) failed: %v", path, Version, perm, err)
return "", err
}
return root, nil
@@ -37,16 +37,16 @@
case os.IsNotExist(err):
perm := os.FileMode(0700)
if err := os.MkdirAll(root, perm); err != nil {
- vlog.Errorf("MkdirAll(%v, %v) failed: %v", root, perm, err)
+ logger.Global().Errorf("MkdirAll(%v, %v) failed: %v", root, perm, err)
return "", err
}
path, perm := filepath.Join(root, VersionFile), os.FileMode(0600)
if err := ioutil.WriteFile(path, []byte(Version), perm); err != nil {
- vlog.Errorf("WriteFile(%v, %v, %v) failed: %v", path, Version, perm, err)
+ logger.Global().Errorf("WriteFile(%v, %v, %v) failed: %v", path, Version, perm, err)
return "", err
}
default:
- vlog.Errorf("Stat(%v) failed: %v", root, err)
+ logger.Global().Errorf("Stat(%v) failed: %v", root, err)
return "", err
}
return root, nil
diff --git a/services/internal/logreaderlib/logfile.go b/services/internal/logreaderlib/logfile.go
index dafd11d..3f24a21 100644
--- a/services/internal/logreaderlib/logfile.go
+++ b/services/internal/logreaderlib/logfile.go
@@ -19,7 +19,6 @@
"v.io/v23/rpc"
"v.io/v23/services/logreader"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
)
const pkgPath = "v.io/x/ref/services/internal/logreaderlib"
@@ -58,7 +57,7 @@
// Size returns the size of the log file, in bytes.
func (i *logfileService) Size(ctx *context.T, _ rpc.ServerCall) (int64, error) {
- vlog.VI(1).Infof("%v.Size()", i.suffix)
+ ctx.VI(1).Infof("%v.Size()", i.suffix)
fname, err := translateNameToFilename(i.root, i.suffix)
if err != nil {
return 0, err
@@ -68,7 +67,7 @@
if os.IsNotExist(err) {
return 0, verror.New(verror.ErrNoExist, ctx, fname)
}
- vlog.Errorf("Stat(%v) failed: %v", fname, err)
+ ctx.Errorf("Stat(%v) failed: %v", fname, err)
return 0, verror.New(errOperationFailed, ctx, fname)
}
if fi.IsDir() {
@@ -79,7 +78,7 @@
// ReadLog returns log entries from the log file.
func (i *logfileService) ReadLog(ctx *context.T, call logreader.LogFileReadLogServerCall, startpos int64, numEntries int32, follow bool) (int64, error) {
- vlog.VI(1).Infof("%v.ReadLog(%v, %v, %v)", i.suffix, startpos, numEntries, follow)
+ ctx.VI(1).Infof("%v.ReadLog(%v, %v, %v)", i.suffix, startpos, numEntries, follow)
fname, err := translateNameToFilename(i.root, i.suffix)
if err != nil {
return 0, err
@@ -116,7 +115,7 @@
// GlobChildren__ returns the list of files in a directory streamed on a
// channel. The list is empty if the object is a file.
func (i *logfileService) GlobChildren__(ctx *context.T, _ rpc.ServerCall) (<-chan string, error) {
- vlog.VI(1).Infof("%v.GlobChildren__()", i.suffix)
+ ctx.VI(1).Infof("%v.GlobChildren__()", i.suffix)
dirName, err := translateNameToFilename(i.root, i.suffix)
if err != nil {
return nil, err
diff --git a/services/internal/pathperms/hierarchical_authorizer.go b/services/internal/pathperms/hierarchical_authorizer.go
index 3d6c5f1..617ef11 100644
--- a/services/internal/pathperms/hierarchical_authorizer.go
+++ b/services/internal/pathperms/hierarchical_authorizer.go
@@ -8,7 +8,6 @@
"v.io/v23/context"
"v.io/v23/security"
"v.io/v23/security/access"
- "v.io/x/lib/vlog"
)
// hierarchicalAuthorizer contains the state needed to implement
@@ -45,7 +44,7 @@
if err != nil {
return err
} else if intentionallyEmpty {
- vlog.VI(2).Infof("PermsForPath(%s) is intentionally empty", ha.rootDir)
+ ctx.VI(2).Infof("PermsForPath(%s) is intentionally empty", ha.rootDir)
return security.DefaultAuthorizer().Authorize(ctx, call)
}
diff --git a/services/internal/pathperms/permsaccess.go b/services/internal/pathperms/permsaccess.go
index 006a717..4a5eede 100644
--- a/services/internal/pathperms/permsaccess.go
+++ b/services/internal/pathperms/permsaccess.go
@@ -14,11 +14,12 @@
"path/filepath"
"sync"
+ "v.io/v23"
"v.io/v23/context"
"v.io/v23/security"
"v.io/v23/security/access"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
+
"v.io/x/ref/lib/security/serialization"
)
@@ -43,13 +44,14 @@
type PathStore struct {
pthlks map[string]*pathEntry
lk sync.Mutex
+ ctx *context.T
principal security.Principal
}
// NewPathStore creates a new instance of the lock map that uses
// principal to sign stored Permissions files.
-func NewPathStore(principal security.Principal) *PathStore {
- return &PathStore{pthlks: make(map[string]*pathEntry), principal: principal}
+func NewPathStore(ctx *context.T) *PathStore {
+ return &PathStore{pthlks: make(map[string]*pathEntry), ctx: ctx, principal: v23.GetPrincipal(ctx)}
}
// Get returns the Permissions from the data file in dir.
@@ -57,7 +59,7 @@
permspath := filepath.Join(dir, permsName)
sigpath := filepath.Join(dir, sigName)
defer store.lockPath(dir)()
- return getCore(store.principal, permspath, sigpath)
+ return getCore(store.ctx, permspath, sigpath)
}
// TODO(rjkroege): Improve lock handling.
@@ -83,18 +85,19 @@
}
}
-func getCore(principal security.Principal, permspath, sigpath string) (access.Permissions, string, error) {
+func getCore(ctx *context.T, permspath, sigpath string) (access.Permissions, string, error) {
+ principal := v23.GetPrincipal(ctx)
f, err := os.Open(permspath)
if err != nil {
// This path is rarely a fatal error so log informationally only.
- vlog.VI(2).Infof("os.Open(%s) failed: %v", permspath, err)
+ ctx.VI(2).Infof("os.Open(%s) failed: %v", permspath, err)
return nil, "", err
}
defer f.Close()
s, err := os.Open(sigpath)
if err != nil {
- vlog.Errorf("Signatures for Permissions are required: %s unavailable: %v", permspath, err)
+ ctx.Errorf("Signatures for Permissions are required: %s unavailable: %v", permspath, err)
return nil, "", verror.New(ErrOperationFailed, nil)
}
defer s.Close()
@@ -102,18 +105,18 @@
// read and verify the signature of the perms file
vf, err := serialization.NewVerifyingReader(f, s, principal.PublicKey())
if err != nil {
- vlog.Errorf("NewVerifyingReader() failed: %v (perms=%s, sig=%s)", err, permspath, sigpath)
+ ctx.Errorf("NewVerifyingReader() failed: %v (perms=%s, sig=%s)", err, permspath, sigpath)
return nil, "", verror.New(ErrOperationFailed, nil)
}
perms, err := access.ReadPermissions(vf)
if err != nil {
- vlog.Errorf("ReadPermissions(%s) failed: %v", permspath, err)
+ ctx.Errorf("ReadPermissions(%s) failed: %v", permspath, err)
return nil, "", err
}
version, err := ComputeVersion(perms)
if err != nil {
- vlog.Errorf("pathperms.ComputeVersion failed: %v", err)
+ ctx.Errorf("pathperms.ComputeVersion failed: %v", err)
return nil, "", err
}
return perms, version, nil
@@ -133,19 +136,20 @@
permspath := filepath.Join(dir, permsName)
sigpath := filepath.Join(dir, sigName)
defer store.lockPath(dir)()
- _, oversion, err := getCore(store.principal, permspath, sigpath)
+ _, oversion, err := getCore(store.ctx, permspath, sigpath)
if err != nil && !os.IsNotExist(err) {
return verror.New(ErrOperationFailed, nil)
}
if len(version) > 0 && version != oversion {
return verror.NewErrBadVersion(nil)
}
- return write(store.principal, permspath, sigpath, dir, perms, shareable)
+ return write(store.ctx, permspath, sigpath, dir, perms, shareable)
}
// write writes the specified Permissions to the permsFile with a
// signature in sigFile.
-func write(principal security.Principal, permsFile, sigFile, dir string, perms access.Permissions, shareable bool) error {
+func write(ctx *context.T, permsFile, sigFile, dir string, perms access.Permissions, shareable bool) error {
+ principal := v23.GetPrincipal(ctx)
filemode := os.FileMode(0600)
dirmode := os.FileMode(0700)
if shareable {
@@ -159,43 +163,43 @@
// those files to the actual data and signature file.
data, err := ioutil.TempFile(dir, permsName)
if err != nil {
- vlog.Errorf("Failed to open tmpfile data:%v", err)
+ ctx.Errorf("Failed to open tmpfile data:%v", err)
return verror.New(ErrOperationFailed, nil)
}
defer os.Remove(data.Name())
sig, err := ioutil.TempFile(dir, sigName)
if err != nil {
- vlog.Errorf("Failed to open tmpfile sig:%v", err)
+ ctx.Errorf("Failed to open tmpfile sig:%v", err)
return verror.New(ErrOperationFailed, nil)
}
defer os.Remove(sig.Name())
writer, err := serialization.NewSigningWriteCloser(data, sig, principal, nil)
if err != nil {
- vlog.Errorf("Failed to create NewSigningWriteCloser:%v", err)
+ ctx.Errorf("Failed to create NewSigningWriteCloser:%v", err)
return verror.New(ErrOperationFailed, nil)
}
if err = perms.WriteTo(writer); err != nil {
- vlog.Errorf("Failed to SavePermissions:%v", err)
+ ctx.Errorf("Failed to SavePermissions:%v", err)
return verror.New(ErrOperationFailed, nil)
}
if err = writer.Close(); err != nil {
- vlog.Errorf("Failed to Close() SigningWriteCloser:%v", err)
+ ctx.Errorf("Failed to Close() SigningWriteCloser:%v", err)
return verror.New(ErrOperationFailed, nil)
}
if err := os.Rename(data.Name(), permsFile); err != nil {
- vlog.Errorf("os.Rename() failed:%v", err)
+ ctx.Errorf("os.Rename() failed:%v", err)
return verror.New(ErrOperationFailed, nil)
}
if err := os.Chmod(permsFile, filemode); err != nil {
- vlog.Errorf("os.Chmod() failed:%v", err)
+ ctx.Errorf("os.Chmod() failed:%v", err)
return verror.New(ErrOperationFailed, nil)
}
if err := os.Rename(sig.Name(), sigFile); err != nil {
- vlog.Errorf("os.Rename() failed:%v", err)
+ ctx.Errorf("os.Rename() failed:%v", err)
return verror.New(ErrOperationFailed, nil)
}
if err := os.Chmod(sigFile, filemode); err != nil {
- vlog.Errorf("os.Chmod() failed:%v", err)
+ ctx.Errorf("os.Chmod() failed:%v", err)
return verror.New(ErrOperationFailed, nil)
}
return nil
diff --git a/services/internal/servicetest/modules.go b/services/internal/servicetest/modules.go
index dcd226b..ee13fa5 100644
--- a/services/internal/servicetest/modules.go
+++ b/services/internal/servicetest/modules.go
@@ -16,8 +16,8 @@
"v.io/v23/context"
"v.io/v23/options"
"v.io/v23/security"
- "v.io/x/lib/vlog"
"v.io/x/ref"
+ "v.io/x/ref/internal/logger"
"v.io/x/ref/lib/xrpc"
"v.io/x/ref/services/mounttable/mounttablelib"
"v.io/x/ref/test/modules"
@@ -36,7 +36,7 @@
ctx, shutdown := v23.Init()
defer shutdown()
- mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
return fmt.Errorf("mounttablelib.NewMountTableDispatcher failed: %s", err)
}
@@ -88,20 +88,20 @@
sh.ClearVar(ref.EnvCredentials)
mtName, _ := startRootMT(t, sh)
- vlog.VI(1).Infof("Started shell mounttable with name %v", mtName)
+ ctx.VI(1).Infof("Started shell mounttable with name %v", mtName)
// TODO(caprita): Define a GetNamespaceRootsCommand in modules/core and
// use that?
oldNamespaceRoots := v23.GetNamespace(ctx).Roots()
fn := func() {
- vlog.VI(1).Info("------------ CLEANUP ------------")
- vlog.VI(1).Info("---------------------------------")
- vlog.VI(1).Info("--(cleaning up shell)------------")
+ ctx.VI(1).Info("------------ CLEANUP ------------")
+ ctx.VI(1).Info("---------------------------------")
+ ctx.VI(1).Info("--(cleaning up shell)------------")
if err := sh.Cleanup(os.Stdout, os.Stderr); err != nil {
t.Errorf(testutil.FormatLogLine(2, "sh.Cleanup failed with %v", err))
}
- vlog.VI(1).Info("--(done cleaning up shell)-------")
+ ctx.VI(1).Info("--(done cleaning up shell)-------")
setNSRoots(t, ctx, oldNamespaceRoots...)
}
setNSRoots(t, ctx, mtName)
@@ -147,7 +147,7 @@
// evaluate the symlink.
rootDir, err = filepath.EvalSymlinks(rootDir)
if err != nil {
- vlog.Fatalf("EvalSymlinks(%v) failed: %v", rootDir, err)
+ logger.Global().Fatalf("EvalSymlinks(%v) failed: %v", rootDir, err)
}
return rootDir, func() {
diff --git a/services/internal/statslib/stats.go b/services/internal/statslib/stats.go
index e2d375e..6fc9b49 100644
--- a/services/internal/statslib/stats.go
+++ b/services/internal/statslib/stats.go
@@ -17,7 +17,6 @@
"v.io/v23/services/watch"
"v.io/v23/vdl"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
libstats "v.io/x/ref/lib/stats"
)
@@ -40,7 +39,7 @@
// Glob__ returns the name of all objects that match pattern.
func (i *statsService) Glob__(ctx *context.T, call rpc.ServerCall, pattern string) (<-chan naming.GlobReply, error) {
- vlog.VI(1).Infof("%v.Glob__(%q)", i.suffix, pattern)
+ ctx.VI(1).Infof("%v.Glob__(%q)", i.suffix, pattern)
ch := make(chan naming.GlobReply)
go func() {
@@ -50,7 +49,7 @@
ch <- naming.GlobReplyEntry{naming.MountEntry{Name: it.Value().Key}}
}
if err := it.Err(); err != nil {
- vlog.VI(1).Infof("libstats.Glob(%q, %q) failed: %v", i.suffix, pattern, err)
+ ctx.VI(1).Infof("libstats.Glob(%q, %q) failed: %v", i.suffix, pattern, err)
}
}()
return ch, nil
@@ -59,7 +58,7 @@
// WatchGlob returns the name and value of the objects that match the request,
// followed by periodic updates when values change.
func (i *statsService) WatchGlob(ctx *context.T, call watch.GlobWatcherWatchGlobServerCall, req watch.GlobRequest) error {
- vlog.VI(1).Infof("%v.WatchGlob(%+v)", i.suffix, req)
+ ctx.VI(1).Infof("%v.WatchGlob(%+v)", i.suffix, req)
var t time.Time
Loop:
@@ -99,7 +98,7 @@
// Value returns the value of the receiver object.
func (i *statsService) Value(ctx *context.T, _ rpc.ServerCall) (*vdl.Value, error) {
- vlog.VI(1).Infof("%v.Value()", i.suffix)
+ ctx.VI(1).Infof("%v.Value()", i.suffix)
rv, err := libstats.Value(i.suffix)
switch {
diff --git a/services/mounttable/mounttabled/mounttable.go b/services/mounttable/mounttabled/mounttable.go
index 2bc4363..72b8cef 100644
--- a/services/mounttable/mounttabled/mounttable.go
+++ b/services/mounttable/mounttabled/mounttable.go
@@ -13,7 +13,6 @@
"v.io/v23"
"v.io/v23/context"
"v.io/x/lib/cmdline"
- "v.io/x/lib/vlog"
"v.io/x/ref/lib/signals"
"v.io/x/ref/lib/v23cmd"
_ "v.io/x/ref/runtime/factories/roaming"
@@ -54,6 +53,6 @@
fmt.Printf("NAME=%s\n", name)
// Wait until signal is received.
- vlog.Info("Received signal ", <-signals.ShutdownOnSignals(ctx))
+ ctx.Info("Received signal ", <-signals.ShutdownOnSignals(ctx))
return nil
}
diff --git a/services/mounttable/mounttablelib/mounttable.go b/services/mounttable/mounttablelib/mounttable.go
index 2885228..358c57f 100644
--- a/services/mounttable/mounttablelib/mounttable.go
+++ b/services/mounttable/mounttablelib/mounttable.go
@@ -21,8 +21,6 @@
"v.io/v23/services/mounttable"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
-
"v.io/x/ref/lib/glob"
"v.io/x/ref/lib/stats"
)
@@ -62,6 +60,7 @@
// mountTable represents a namespace. One exists per server instance.
type mountTable struct {
sync.Mutex
+ ctx *context.T
root *node
superUsers access.AccessList
persisting bool
@@ -114,8 +113,9 @@
// persistDir is the directory for persisting Permissions.
//
// statsPrefix is the prefix for for exported statistics objects.
-func NewMountTableDispatcher(permsFile, persistDir, statsPrefix string) (rpc.Dispatcher, error) {
+func NewMountTableDispatcher(ctx *context.T, permsFile, persistDir, statsPrefix string) (rpc.Dispatcher, error) {
mt := &mountTable{
+ ctx: ctx,
root: new(node),
nodeCounter: stats.NewInteger(naming.Join(statsPrefix, "num-nodes")),
serverCounter: stats.NewInteger(naming.Join(statsPrefix, "num-mounted-servers")),
@@ -124,10 +124,10 @@
}
mt.root.parent = mt.newNode() // just for its lock
if persistDir != "" {
- mt.persist = newPersistentStore(mt, persistDir)
+ mt.persist = newPersistentStore(ctx, mt, persistDir)
mt.persisting = mt.persist != nil
}
- if err := mt.parsePermFile(permsFile); err != nil && !os.IsNotExist(err) {
+ if err := mt.parsePermFile(ctx, permsFile); err != nil && !os.IsNotExist(err) {
return nil, err
}
return mt, nil
@@ -178,7 +178,7 @@
// Lookup implements rpc.Dispatcher.Lookup.
func (mt *mountTable) Lookup(name string) (interface{}, security.Authorizer, error) {
- vlog.VI(2).Infof("*********************Lookup %s", name)
+ mt.ctx.VI(2).Infof("*********************Lookup %s", name)
ms := &mountContext{
name: name,
mt: mt,
@@ -292,7 +292,7 @@
cur.parent.Lock()
cur.Lock()
for i, e := range elems {
- vlog.VI(2).Infof("satisfying %v %v", elems[0:i], *cur)
+ ctx.VI(2).Infof("satisfying %v %v", elems[0:i], *cur)
if call != nil {
if err := cur.satisfies(mt, ctx, call, traverseTags); err != nil {
cur.parent.Unlock()
@@ -413,7 +413,7 @@
// If we removed the node, see if we can remove any of its
// ascendants.
if removed && len(elems) > 0 {
- mt.removeUselessRecursive(elems[:len(elems)-1])
+ mt.removeUselessRecursive(ctx, elems[:len(elems)-1])
}
return nil, nil, nil
}
@@ -429,7 +429,7 @@
// ResolveStep returns the next server in a resolution in the form of a MountEntry. The name
// in the mount entry is the name relative to the server's root.
func (ms *mountContext) ResolveStep(ctx *context.T, call rpc.ServerCall) (entry naming.MountEntry, err error) {
- vlog.VI(2).Infof("ResolveStep %q", ms.name)
+ ctx.VI(2).Infof("ResolveStep %q", ms.name)
mt := ms.mt
// Find the next mount point for the name.
n, elems, werr := mt.findMountPoint(ctx, call.Security(), ms.elems)
@@ -480,7 +480,7 @@
if ttlsecs == 0 {
ttlsecs = 10 * 365 * 24 * 60 * 60 // a really long time
}
- vlog.VI(2).Infof("*********************Mount %q -> %s", ms.name, server)
+ ctx.VI(2).Infof("*********************Mount %q -> %s", ms.name, server)
// Make sure the server address is reasonable.
epString := server
@@ -561,9 +561,9 @@
}
// removeUselessRecursive removes any useless nodes on the tail of the path.
-func (mt *mountTable) removeUselessRecursive(elems []string) {
+func (mt *mountTable) removeUselessRecursive(ctx *context.T, elems []string) {
for i := len(elems); i > 0; i-- {
- n, nelems, _ := mt.traverse(nil, nil, elems[:i], false)
+ n, nelems, _ := mt.traverse(ctx, nil, elems[:i], false)
if n == nil {
break
}
@@ -584,7 +584,7 @@
// Unmount removes servers from the name in the receiver. If server is specified, only that
// server is removed.
func (ms *mountContext) Unmount(ctx *context.T, call rpc.ServerCall, server string) error {
- vlog.VI(2).Infof("*********************Unmount %q, %s", ms.name, server)
+ ctx.VI(2).Infof("*********************Unmount %q, %s", ms.name, server)
mt := ms.mt
n, err := mt.findNode(ctx, call.Security(), ms.elems, false, mountTags, nil)
if err != nil {
@@ -606,14 +606,14 @@
if removed {
// If we removed the node, see if we can also remove
// any of its ascendants.
- mt.removeUselessRecursive(ms.elems[:len(ms.elems)-1])
+ mt.removeUselessRecursive(ctx, ms.elems[:len(ms.elems)-1])
}
return nil
}
// Delete removes the receiver. If all is true, any subtree is also removed.
func (ms *mountContext) Delete(ctx *context.T, call rpc.ServerCall, deleteSubTree bool) error {
- vlog.VI(2).Infof("*********************Delete %q, %v", ms.name, deleteSubTree)
+ ctx.VI(2).Infof("*********************Delete %q, %v", ms.name, deleteSubTree)
if len(ms.elems) == 0 {
// We can't delete the root.
return verror.New(errCantDeleteRoot, ctx)
@@ -648,7 +648,7 @@
// globStep is called with n and n.parent locked. Returns with both unlocked.
func (mt *mountTable) globStep(ctx *context.T, call security.Call, n *node, name string, pattern *glob.Glob, ch chan<- naming.GlobReply) {
- vlog.VI(2).Infof("globStep(%s, %s)", name, pattern)
+ ctx.VI(2).Infof("globStep(%s, %s)", name, pattern)
// If this is a mount point, we're done.
if m := n.mount; m != nil {
@@ -753,7 +753,7 @@
// adds a/b while a Glob is in progress, the Glob may return a set of nodes that includes both
// c/d and a/b.
func (ms *mountContext) Glob__(ctx *context.T, call rpc.ServerCall, pattern string) (<-chan naming.GlobReply, error) {
- vlog.VI(2).Infof("mt.Glob %v", ms.elems)
+ ctx.VI(2).Infof("mt.Glob %v", ms.elems)
scall := call.Security()
g, err := glob.Parse(pattern)
@@ -797,7 +797,7 @@
}
func (ms *mountContext) SetPermissions(ctx *context.T, call rpc.ServerCall, perms access.Permissions, version string) error {
- vlog.VI(2).Infof("SetPermissions %q", ms.name)
+ ctx.VI(2).Infof("SetPermissions %q", ms.name)
mt := ms.mt
// Find/create node in namespace and add the mount.
@@ -843,7 +843,7 @@
}
func (ms *mountContext) GetPermissions(ctx *context.T, call rpc.ServerCall) (access.Permissions, string, error) {
- vlog.VI(2).Infof("GetPermissions %q", ms.name)
+ ctx.VI(2).Infof("GetPermissions %q", ms.name)
mt := ms.mt
// Find node in namespace and add the mount.
diff --git a/services/mounttable/mounttablelib/mounttable_test.go b/services/mounttable/mounttablelib/mounttable_test.go
index 4e08341..9d9df27 100644
--- a/services/mounttable/mounttablelib/mounttable_test.go
+++ b/services/mounttable/mounttablelib/mounttable_test.go
@@ -25,8 +25,8 @@
"v.io/v23/security/access"
"v.io/v23/services/stats"
"v.io/v23/vdl"
- "v.io/x/lib/vlog"
+ "v.io/x/ref/internal/logger"
libstats "v.io/x/ref/lib/stats"
"v.io/x/ref/lib/xrpc"
"v.io/x/ref/services/debug/debuglib"
@@ -187,11 +187,11 @@
}
func newMT(t *testing.T, permsFile, persistDir, statsDir string, rootCtx *context.T) (func() error, string) {
- reservedDisp := debuglib.NewDispatcher(vlog.Log.LogDir, nil)
+ reservedDisp := debuglib.NewDispatcher(logger.Manager(logger.Global()).LogDir, nil)
ctx := v23.WithReservedNameDispatcher(rootCtx, reservedDisp)
// Add mount table service.
- mt, err := mounttablelib.NewMountTableDispatcher(permsFile, persistDir, statsDir)
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, permsFile, persistDir, statsDir)
if err != nil {
boom(t, "mounttablelib.NewMountTableDispatcher: %v", err)
}
@@ -231,15 +231,15 @@
collectionName := naming.JoinAddressName(collectionAddr, "collection")
// Mount the collection server into the mount table.
- vlog.Infof("Mount the collection server into the mount table.")
+ rootCtx.Infof("Mount the collection server into the mount table.")
doMount(t, rootCtx, mtAddr, "stuff", collectionName, true)
// Create a few objects and make sure we can read them.
- vlog.Infof("Create a few objects.")
+ rootCtx.Infof("Create a few objects.")
export(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/the/rain"), "the rain")
export(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/in/spain"), "in spain")
export(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/falls"), "falls mainly on the plain")
- vlog.Infof("Make sure we can read them.")
+ rootCtx.Infof("Make sure we can read them.")
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/the/rain"), "the rain", true)
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/in/spain"), "in spain", true)
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/falls"), "falls mainly on the plain", true)
@@ -249,11 +249,11 @@
checkContents(t, aliceCtx, naming.JoinAddressName(mtAddr, "stuff/the/rain"), "the rain", false)
// Test multiple mounts.
- vlog.Infof("Multiple mounts.")
+ rootCtx.Infof("Multiple mounts.")
doMount(t, rootCtx, mtAddr, "a/b", collectionName, true)
doMount(t, rootCtx, mtAddr, "x/y", collectionName, true)
doMount(t, rootCtx, mtAddr, "alpha//beta", collectionName, true)
- vlog.Infof("Make sure we can read them.")
+ rootCtx.Infof("Make sure we can read them.")
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuff/falls"), "falls mainly on the plain", true)
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "a/b/falls"), "falls mainly on the plain", true)
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "x/y/falls"), "falls mainly on the plain", true)
@@ -296,18 +296,18 @@
}
// Test generic unmount.
- vlog.Info("Test generic unmount.")
+ rootCtx.Info("Test generic unmount.")
doUnmount(t, rootCtx, mtAddr, "a/b", "", true)
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "a/b/falls"), "falls mainly on the plain", false)
// Test specific unmount.
- vlog.Info("Test specific unmount.")
+ rootCtx.Info("Test specific unmount.")
doMount(t, rootCtx, mtAddr, "a/b", collectionName, true)
doUnmount(t, rootCtx, mtAddr, "a/b", collectionName, true)
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "a/b/falls"), "falls mainly on the plain", false)
// Try timing out a mount.
- vlog.Info("Try timing out a mount.")
+ rootCtx.Info("Try timing out a mount.")
ft := mounttablelib.NewFakeTimeClock()
mounttablelib.SetServerListClock(ft)
doMount(t, rootCtx, mtAddr, "stuffWithTTL", collectionName, true)
@@ -316,7 +316,7 @@
checkContents(t, rootCtx, naming.JoinAddressName(mtAddr, "stuffWithTTL/the/rain"), "the rain", false)
// Test unauthorized mount.
- vlog.Info("Test unauthorized mount.")
+ rootCtx.Info("Test unauthorized mount.")
doMount(t, bobCtx, mtAddr, "/a/b", collectionName, false)
doMount(t, aliceCtx, mtAddr, "/a/b", collectionName, false)
@@ -648,11 +648,13 @@
}
func TestBadAccessLists(t *testing.T) {
- _, err := mounttablelib.NewMountTableDispatcher("testdata/invalid.perms", "", "mounttable")
+ ctx, shutdown := test.V23InitWithParams(test.InitParams{})
+ defer shutdown()
+ _, err := mounttablelib.NewMountTableDispatcher(ctx, "testdata/invalid.perms", "", "mounttable")
if err == nil {
boom(t, "Expected json parse error in permissions file")
}
- _, err = mounttablelib.NewMountTableDispatcher("testdata/doesntexist.perms", "", "mounttable")
+ _, err = mounttablelib.NewMountTableDispatcher(ctx, "testdata/doesntexist.perms", "", "mounttable")
if err != nil {
boom(t, "Missing permissions file should not cause an error")
}
diff --git a/services/mounttable/mounttablelib/neighborhood.go b/services/mounttable/mounttablelib/neighborhood.go
index ac82af2..ef5b672 100644
--- a/services/mounttable/mounttablelib/neighborhood.go
+++ b/services/mounttable/mounttablelib/neighborhood.go
@@ -22,7 +22,8 @@
"v.io/v23/services/mounttable"
vdltime "v.io/v23/vdlroot/time"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
+
+ "v.io/x/ref/internal/logger"
mdns "github.com/presotto/go-mdns-sd"
)
@@ -110,10 +111,10 @@
// Start up MDNS, subscribe to the vanadium service, and add us as a vanadium service provider.
mdns, err := mdns.NewMDNS(host, "", "", loopback, false)
if err != nil {
- vlog.Errorf("mdns startup failed: %s", err)
+ logger.Global().Errorf("mdns startup failed: %s", err)
return nil, err
}
- vlog.VI(2).Infof("listening for service vanadium on port %d", port)
+ logger.Global().VI(2).Infof("listening for service vanadium on port %d", port)
mdns.SubscribeToService("vanadium")
if host != AnonymousNeighbor {
mdns.AddService("vanadium", "", port, txt...)
@@ -128,7 +129,7 @@
// interfaces when the network changes.
nh.nw, err = netconfig.NewNetConfigWatcher()
if err != nil {
- vlog.Errorf("nighborhood can't watch network: %s", err)
+ logger.Global().Errorf("nighborhood can't watch network: %s", err)
return nh, nil
}
go func() {
@@ -136,7 +137,7 @@
return
}
if _, err := nh.mdns.ScanInterfaces(); err != nil {
- vlog.Errorf("nighborhood can't scan interfaces: %s", err)
+ logger.Global().Errorf("nighborhood can't scan interfaces: %s", err)
}
}()
@@ -157,7 +158,7 @@
// Lookup implements rpc.Dispatcher.Lookup.
func (nh *neighborhood) Lookup(name string) (interface{}, security.Authorizer, error) {
- vlog.VI(1).Infof("*********************LookupServer '%s'\n", name)
+ logger.Global().VI(1).Infof("*********************LookupServer '%s'\n", name)
elems := strings.Split(name, "/")[nh.nelems:]
if name == "" {
elems = nil
@@ -225,14 +226,14 @@
neighbors[m.Name] = neighbor
}
}
- vlog.VI(2).Infof("members %v neighbors %v", members, neighbors)
+ logger.Global().VI(2).Infof("members %v neighbors %v", members, neighbors)
return neighbors
}
// ResolveStep implements ResolveStep
func (ns *neighborhoodService) ResolveStep(ctx *context.T, _ rpc.ServerCall) (entry naming.MountEntry, err error) {
nh := ns.nh
- vlog.VI(2).Infof("ResolveStep %v\n", ns.elems)
+ ctx.VI(2).Infof("ResolveStep %v\n", ns.elems)
if len(ns.elems) == 0 {
//nothing can be mounted at the root
err = verror.New(naming.ErrNoSuchNameRoot, ctx, ns.elems)
diff --git a/services/mounttable/mounttablelib/neighborhood_test.go b/services/mounttable/mounttablelib/neighborhood_test.go
index bf0c918..b5c1ff1 100644
--- a/services/mounttable/mounttablelib/neighborhood_test.go
+++ b/services/mounttable/mounttablelib/neighborhood_test.go
@@ -14,7 +14,6 @@
"v.io/v23"
"v.io/v23/naming"
"v.io/v23/options"
- "v.io/x/lib/vlog"
_ "v.io/x/ref/runtime/factories/generic"
"v.io/x/ref/services/mounttable/mounttablelib"
@@ -37,7 +36,7 @@
rootCtx, shutdown := test.V23Init()
defer shutdown()
- vlog.Infof("TestNeighborhood")
+ rootCtx.Infof("TestNeighborhood")
server, err := v23.NewServer(rootCtx)
if err != nil {
boom(t, "r.NewServer: %s", err)
diff --git a/services/mounttable/mounttablelib/persistentstore.go b/services/mounttable/mounttablelib/persistentstore.go
index a96eb19..3132e59 100644
--- a/services/mounttable/mounttablelib/persistentstore.go
+++ b/services/mounttable/mounttablelib/persistentstore.go
@@ -12,7 +12,9 @@
"strings"
"sync"
- "v.io/x/lib/vlog"
+ "v.io/v23/context"
+
+ "v.io/x/ref/internal/logger"
)
type store struct {
@@ -43,7 +45,7 @@
// it will be renamed persistent.perms becoming the new log.
// old.permslog - the previous version of persistent.perms. This is left around primarily for debugging
// and as an emergency backup.
-func newPersistentStore(mt *mountTable, dir string) persistence {
+func newPersistentStore(ctx *context.T, mt *mountTable, dir string) persistence {
s := &store{mt: mt, dir: dir}
file := path.Join(dir, "persistent.permslog")
tmp := path.Join(dir, "tmp.permslog")
@@ -53,11 +55,11 @@
f, err := os.Open(file)
if err != nil {
if !os.IsNotExist(err) {
- vlog.Fatalf("cannot open %s: %s", file, err)
+ logger.Global().Fatalf("cannot open %s: %s", file, err)
}
os.Rename(tmp, file)
if f, err = os.Open(file); err != nil && !os.IsNotExist(err) {
- vlog.Fatalf("cannot open %s: %s", file, err)
+ logger.Global().Fatalf("cannot open %s: %s", file, err)
}
} else {
os.Remove(tmp)
@@ -65,10 +67,10 @@
// Parse the permissions file and apply it to the in memory tree.
if f != nil {
- if err := s.parseLogFile(f); err != nil {
+ if err := s.parseLogFile(ctx, f); err != nil {
f.Close()
// Log the error but keep going. There's not much else we can do.
- vlog.Infof("parsing old persistent permissions file %s: %s", file, err)
+ logger.Global().Infof("parsing old persistent permissions file %s: %s", file, err)
}
f.Close()
}
@@ -78,9 +80,9 @@
f, err = os.OpenFile(tmp, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
if err != nil {
// Log the error but keep going, don't compress, just append to the current file.
- vlog.Infof("can't rewrite persistent permissions file %s: %s", file, err)
+ logger.Global().Infof("can't rewrite persistent permissions file %s: %s", file, err)
if f, err = os.OpenFile(file, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600); err != nil {
- vlog.Fatalf("can't append to log %s: %s", file, err)
+ logger.Global().Fatalf("can't append to log %s: %s", file, err)
}
f.Seek(0, 2)
s.enc = json.NewEncoder(f)
@@ -92,13 +94,13 @@
// Switch names and remove the old file.
if err := os.Remove(old); err != nil {
- vlog.Infof("removing %s: %s", old, err)
+ ctx.Infof("removing %s: %s", old, err)
}
if err := os.Rename(file, old); err != nil {
- vlog.Infof("renaming %s to %s: %s", file, old, err)
+ ctx.Infof("renaming %s to %s: %s", file, old, err)
}
if err := os.Rename(tmp, file); err != nil {
- vlog.Fatalf("renaming %s to %s: %s", tmp, file, err)
+ ctx.Fatalf("renaming %s to %s: %s", tmp, file, err)
}
// Reopen the new log file. We could have just kept around the encoder used
@@ -106,7 +108,7 @@
// points to the same file. Only true on Unix like file systems.
f, err = os.OpenFile(file, os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
- vlog.Fatalf("can't open %s: %s", file, err)
+ ctx.Fatalf("can't open %s: %s", file, err)
}
f.Seek(0, 2)
s.enc = json.NewEncoder(f)
@@ -114,11 +116,11 @@
}
// parseLogFile reads a file and parses the contained VersionedPermissions .
-func (s *store) parseLogFile(f *os.File) error {
+func (s *store) parseLogFile(ctx *context.T, f *os.File) error {
if f == nil {
return nil
}
- vlog.VI(2).Infof("parseLogFile(%s)", f.Name())
+ ctx.VI(2).Infof("parseLogFile(%s)", f.Name())
mt := s.mt
decoder := json.NewDecoder(f)
for {
@@ -131,16 +133,16 @@
}
elems := strings.Split(e.N, "/")
- n, err := mt.findNode(nil, nil, elems, true, nil, nil)
+ n, err := mt.findNode(ctx, nil, elems, true, nil, nil)
if n != nil || err == nil {
n.creator = e.C
if e.D {
mt.deleteNode(n.parent, elems[len(elems)-1])
- vlog.VI(2).Infof("deleted %s", e.N)
+ ctx.VI(2).Infof("deleted %s", e.N)
} else {
n.vPerms = &e.V
n.explicitPermissions = true
- vlog.VI(2).Infof("added versions permissions %v to %s", e.V, e.N)
+ ctx.VI(2).Infof("added versions permissions %v to %s", e.V, e.N)
}
}
n.parent.Unlock()
diff --git a/services/mounttable/mounttablelib/servers.go b/services/mounttable/mounttablelib/servers.go
index ef8c550..9b84375 100644
--- a/services/mounttable/mounttablelib/servers.go
+++ b/services/mounttable/mounttablelib/servers.go
@@ -12,6 +12,7 @@
"v.io/v23/naming"
"v.io/v23/options"
"v.io/v23/rpc"
+
"v.io/x/lib/vlog"
"v.io/x/ref/lib/xrpc"
)
@@ -24,20 +25,22 @@
}
}
- mt, err := NewMountTableDispatcher(permsFile, persistDir, debugPrefix)
+ mt, err := NewMountTableDispatcher(ctx, permsFile, persistDir, debugPrefix)
if err != nil {
vlog.Errorf("NewMountTable failed: %v", err)
return "", nil, err
}
+ ctx = v23.WithListenSpec(ctx, listenSpec)
mtServer, err := xrpc.NewDispatchingServer(ctx, mountName, mt, options.ServesMountTable(true))
if err != nil {
- vlog.Errorf("v23.NewServer failed: %v", err)
+
+ ctx.Errorf("v23.NewServer failed: %v", err)
return "", nil, err
}
stopFuncs = append(stopFuncs, mtServer.Stop)
mtEndpoints := mtServer.Status().Endpoints
mtName := mtEndpoints[0].Name()
- vlog.Infof("Mount table service at: %q endpoint: %s", mountName, mtName)
+ ctx.Infof("Mount table service at: %q endpoint: %s", mountName, mtName)
if len(nhName) > 0 {
// The ListenSpec code ensures that we have a valid address here.
@@ -61,7 +64,7 @@
nhServer, err := xrpc.NewDispatchingServer(ctx, naming.Join(mtName, "nh"), nh, options.ServesMountTable(true))
if err != nil {
- vlog.Errorf("v23.NewServer failed: %v", err)
+ ctx.Errorf("v23.NewServer failed: %v", err)
stop()
return "", nil, err
}
diff --git a/services/mounttable/mounttablelib/versionedpermissions.go b/services/mounttable/mounttablelib/versionedpermissions.go
index d4da750..661f9bb 100644
--- a/services/mounttable/mounttablelib/versionedpermissions.go
+++ b/services/mounttable/mounttablelib/versionedpermissions.go
@@ -18,7 +18,6 @@
"v.io/v23/security/access"
"v.io/v23/services/mounttable"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
)
// Blessings can't include a comma so we use them in made up user ids. The following distinctions are
@@ -89,8 +88,8 @@
}
// parsePermFile reads a file and parses the contained permissions.
-func (mt *mountTable) parsePermFile(path string) error {
- vlog.VI(2).Infof("parsePermFile(%s)", path)
+func (mt *mountTable) parsePermFile(ctx *context.T, path string) error {
+ ctx.VI(2).Infof("parsePermFile(%s)", path)
if path == "" {
return nil
}
@@ -143,9 +142,9 @@
}
// Create name and add the Permissions map to it.
- n, err := mt.findNode(nil, nil, elems, true, nil, nil)
+ n, err := mt.findNode(ctx, nil, elems, true, nil, nil)
if n != nil || err == nil {
- vlog.VI(2).Infof("added perms %v to %s", perms, name)
+ ctx.VI(2).Infof("added perms %v to %s", perms, name)
if isPattern {
n.permsTemplate = perms
} else {
diff --git a/services/profile/profile/impl_test.go b/services/profile/profile/impl_test.go
index e3695fb..98debf6 100644
--- a/services/profile/profile/impl_test.go
+++ b/services/profile/profile/impl_test.go
@@ -17,7 +17,6 @@
"v.io/v23/services/build"
"v.io/x/lib/cmdline"
- "v.io/x/lib/vlog"
"v.io/x/ref/lib/v23cmd"
"v.io/x/ref/lib/xrpc"
_ "v.io/x/ref/runtime/factories/generic"
@@ -44,37 +43,37 @@
suffix string
}
-func (s *server) Label(*context.T, rpc.ServerCall) (string, error) {
- vlog.VI(2).Infof("%v.Label() was called", s.suffix)
+func (s *server) Label(ctx *context.T, _ rpc.ServerCall) (string, error) {
+ ctx.VI(2).Infof("%v.Label() was called", s.suffix)
if s.suffix != "exists" {
return "", fmt.Errorf("profile doesn't exist: %v", s.suffix)
}
return spec.Label, nil
}
-func (s *server) Description(*context.T, rpc.ServerCall) (string, error) {
- vlog.VI(2).Infof("%v.Description() was called", s.suffix)
+func (s *server) Description(ctx *context.T, _ rpc.ServerCall) (string, error) {
+ ctx.VI(2).Infof("%v.Description() was called", s.suffix)
if s.suffix != "exists" {
return "", fmt.Errorf("profile doesn't exist: %v", s.suffix)
}
return spec.Description, nil
}
-func (s *server) Specification(*context.T, rpc.ServerCall) (profile.Specification, error) {
- vlog.VI(2).Infof("%v.Specification() was called", s.suffix)
+func (s *server) Specification(ctx *context.T, _ rpc.ServerCall) (profile.Specification, error) {
+ ctx.VI(2).Infof("%v.Specification() was called", s.suffix)
if s.suffix != "exists" {
return profile.Specification{}, fmt.Errorf("profile doesn't exist: %v", s.suffix)
}
return spec, nil
}
-func (s *server) Put(_ *context.T, _ rpc.ServerCall, _ profile.Specification) error {
- vlog.VI(2).Infof("%v.Put() was called", s.suffix)
+func (s *server) Put(ctx *context.T, _ rpc.ServerCall, _ profile.Specification) error {
+ ctx.VI(2).Infof("%v.Put() was called", s.suffix)
return nil
}
-func (s *server) Remove(*context.T, rpc.ServerCall) error {
- vlog.VI(2).Infof("%v.Remove() was called", s.suffix)
+func (s *server) Remove(ctx *context.T, _ rpc.ServerCall) error {
+ ctx.VI(2).Infof("%v.Remove() was called", s.suffix)
if s.suffix != "exists" {
return fmt.Errorf("profile doesn't exist: %v", s.suffix)
}
diff --git a/services/profile/profiled/main.go b/services/profile/profiled/main.go
index 72518f7..93cf635 100644
--- a/services/profile/profiled/main.go
+++ b/services/profile/profiled/main.go
@@ -12,7 +12,6 @@
"v.io/v23/context"
"v.io/x/lib/cmdline"
- "v.io/x/lib/vlog"
"v.io/x/ref/lib/security/securityflag"
"v.io/x/ref/lib/signals"
"v.io/x/ref/lib/v23cmd"
@@ -54,7 +53,7 @@
if err != nil {
return fmt.Errorf("NewServer() failed: %v", err)
}
- vlog.Infof("Profile repository running at endpoint=%v", server.Status().Endpoints[0])
+ ctx.Infof("Profile repository running at endpoint=%v", server.Status().Endpoints[0])
// Wait until shutdown.
<-signals.ShutdownOnSignals(ctx)
diff --git a/services/profile/profiled/service.go b/services/profile/profiled/service.go
index d30613f..9f8f689 100644
--- a/services/profile/profiled/service.go
+++ b/services/profile/profiled/service.go
@@ -14,7 +14,6 @@
"v.io/v23/context"
"v.io/v23/naming"
"v.io/v23/rpc"
- "v.io/x/lib/vlog"
)
// profileService implements the Profile server interface.
@@ -40,7 +39,7 @@
// STORE MANAGEMENT INTERFACE IMPLEMENTATION
func (i *profileService) Put(ctx *context.T, call rpc.ServerCall, profile profile.Specification) error {
- vlog.VI(0).Infof("%v.Put(%v)", i.suffix, profile)
+ ctx.VI(0).Infof("%v.Put(%v)", i.suffix, profile)
// Transaction is rooted at "", so tname == tid.
i.store.Lock()
defer i.store.Unlock()
@@ -60,7 +59,7 @@
}
func (i *profileService) Remove(ctx *context.T, call rpc.ServerCall) error {
- vlog.VI(0).Infof("%v.Remove()", i.suffix)
+ ctx.VI(0).Infof("%v.Remove()", i.suffix)
i.store.Lock()
defer i.store.Unlock()
// Transaction is rooted at "", so tname == tid.
@@ -107,7 +106,7 @@
}
func (i *profileService) Label(ctx *context.T, call rpc.ServerCall) (string, error) {
- vlog.VI(0).Infof("%v.Label()", i.suffix)
+ ctx.VI(0).Infof("%v.Label()", i.suffix)
s, err := i.lookup(call)
if err != nil {
return "", err
@@ -116,7 +115,7 @@
}
func (i *profileService) Description(ctx *context.T, call rpc.ServerCall) (string, error) {
- vlog.VI(0).Infof("%v.Description()", i.suffix)
+ ctx.VI(0).Infof("%v.Description()", i.suffix)
s, err := i.lookup(call)
if err != nil {
return "", err
@@ -125,6 +124,6 @@
}
func (i *profileService) Specification(ctx *context.T, call rpc.ServerCall) (profile.Specification, error) {
- vlog.VI(0).Infof("%v.Specification()", i.suffix)
+ ctx.VI(0).Infof("%v.Specification()", i.suffix)
return i.lookup(call)
}
diff --git a/services/proxy/proxyd/main.go b/services/proxy/proxyd/main.go
index 42053e9..1333581 100644
--- a/services/proxy/proxyd/main.go
+++ b/services/proxy/proxyd/main.go
@@ -14,13 +14,15 @@
"net/http"
"time"
+ "v.io/x/lib/cmdline"
+
"v.io/v23"
"v.io/v23/context"
+ "v.io/v23/logging"
"v.io/v23/rpc"
"v.io/v23/security"
"v.io/v23/security/access"
- "v.io/x/lib/cmdline"
- "v.io/x/lib/vlog"
+
"v.io/x/ref/lib/signals"
"v.io/x/ref/lib/v23cmd"
"v.io/x/ref/lib/xrpc"
@@ -66,7 +68,7 @@
// Always add ourselves, for the the reserved methods server
// started below.
list.In = append(list.In, security.DefaultBlessingPatterns(v23.GetPrincipal(ctx))...)
- vlog.Infof("Using access list to control proxy use: %v", list)
+ ctx.Infof("Using access list to control proxy use: %v", list)
authorizer = list
}
@@ -85,7 +87,7 @@
}
if len(healthzAddr) != 0 {
- go startHealthzServer(healthzAddr)
+ go startHealthzServer(ctx, healthzAddr)
}
// Start an RPC Server that listens through the proxy itself. This
@@ -120,7 +122,7 @@
// startHealthzServer starts a HTTP server that simply returns "ok" to every
// request. This is needed to let the load balancer know that the proxy server
// is running.
-func startHealthzServer(addr string) {
+func startHealthzServer(logger logging.Logger, addr string) {
s := http.Server{
Addr: addr,
Handler: healthzHandler{},
@@ -128,6 +130,6 @@
WriteTimeout: 10 * time.Second,
}
if err := s.ListenAndServe(); err != nil {
- vlog.Fatal(err)
+ logger.Fatal(err)
}
}
diff --git a/services/role/roled/internal/discharger.go b/services/role/roled/internal/discharger.go
index 2a624cc..d6db009 100644
--- a/services/role/roled/internal/discharger.go
+++ b/services/role/roled/internal/discharger.go
@@ -14,13 +14,11 @@
"v.io/v23/verror"
"v.io/x/ref/services/discharger"
-
- "v.io/x/lib/vlog"
)
func init() {
- security.RegisterCaveatValidator(LoggingCaveat, func(_ *context.T, _ security.Call, params []string) error {
- vlog.Infof("Params: %#v", params)
+ security.RegisterCaveatValidator(LoggingCaveat, func(ctx *context.T, _ security.Call, params []string) error {
+ ctx.Infof("Params: %#v", params)
return nil
})
@@ -39,7 +37,7 @@
return security.Discharge{}, err
}
// TODO(rthellend,ashankar): Do proper logging when the API allows it.
- vlog.Infof("Discharge() impetus: %#v", impetus)
+ ctx.Infof("Discharge() impetus: %#v", impetus)
expiry, err := security.NewExpiryCaveat(time.Now().Add(5 * time.Minute))
if err != nil {
diff --git a/services/role/roled/internal/dispatcher.go b/services/role/roled/internal/dispatcher.go
index 475beb5..f741d34 100644
--- a/services/role/roled/internal/dispatcher.go
+++ b/services/role/roled/internal/dispatcher.go
@@ -16,10 +16,9 @@
"v.io/v23/security"
"v.io/v23/verror"
+ "v.io/x/ref/internal/logger"
"v.io/x/ref/services/discharger"
"v.io/x/ref/services/role"
-
- "v.io/x/lib/vlog"
)
const requiredSuffix = security.ChainSeparator + role.RoleSuffix
@@ -58,7 +57,7 @@
if err != nil && !os.IsNotExist(err) {
// The config file exists, but we failed to read it for some
// reason. This is likely a server configuration error.
- vlog.Errorf("loadConfig(%q, %q): %v", d.config.root, suffix, err)
+ logger.Global().Errorf("loadConfig(%q, %q): %v", d.config.root, suffix, err)
return nil, nil, verror.Convert(verror.ErrInternal, nil, err)
}
obj := &roleService{serverConfig: d.config, role: suffix, roleConfig: roleConfig}
@@ -112,7 +111,6 @@
f := filepath.Join(parentDir, filepath.FromSlash(imp+".conf"))
ic, err := loadExpandedConfig(f, seenFiles)
if err != nil {
- vlog.Errorf("loadExpandedConfig(%q) failed: %v", f, err)
continue
}
if ic == nil {
diff --git a/services/role/roled/internal/role.go b/services/role/roled/internal/role.go
index 9d0e332..a46a31d 100644
--- a/services/role/roled/internal/role.go
+++ b/services/role/roled/internal/role.go
@@ -14,8 +14,6 @@
"v.io/v23/security"
"v.io/v23/verror"
- "v.io/x/lib/vlog"
-
"v.io/x/ref/services/role"
)
@@ -31,7 +29,7 @@
func (i *roleService) SeekBlessings(ctx *context.T, call rpc.ServerCall) (security.Blessings, error) {
remoteBlessingNames, _ := security.RemoteBlessingNames(ctx, call.Security())
- vlog.Infof("%q.SeekBlessings() called by %q", i.role, remoteBlessingNames)
+ ctx.Infof("%q.SeekBlessings() called by %q", i.role, remoteBlessingNames)
members := i.filterNonMembers(remoteBlessingNames)
if len(members) == 0 {
diff --git a/services/wspr/internal/app/app_test.go b/services/wspr/internal/app/app_test.go
index b9d242f..69cc32e 100644
--- a/services/wspr/internal/app/app_test.go
+++ b/services/wspr/internal/app/app_test.go
@@ -315,7 +315,7 @@
}
func serveServer(ctx *context.T, writer lib.ClientWriter, setController func(*Controller)) (*runningTest, error) {
- mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
return nil, fmt.Errorf("unable to start mounttable: %v", err)
}
diff --git a/services/wspr/internal/browspr/browspr_test.go b/services/wspr/internal/browspr/browspr_test.go
index 270d263..5841efa 100644
--- a/services/wspr/internal/browspr/browspr_test.go
+++ b/services/wspr/internal/browspr/browspr_test.go
@@ -77,7 +77,7 @@
}
defer proxyShutdown()
- mt, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ mt, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
t.Fatalf("Failed to create mounttable: %v", err)
}
diff --git a/test/init.go b/test/init.go
index fae8ba3..0dc5cf7 100644
--- a/test/init.go
+++ b/test/init.go
@@ -39,7 +39,7 @@
}
// Init sets up state for running tests: Adjusting GOMAXPROCS,
-// configuring the vlog logging library, setting up the random number generator
+// configuring the logging library, setting up the random number generator
// etc.
//
// Doing so requires flags to be parsed, so this function explicitly parses
@@ -96,7 +96,7 @@
}
}
if params.CreateMounttable {
- disp, err := mounttablelib.NewMountTableDispatcher("", "", "mounttable")
+ disp, err := mounttablelib.NewMountTableDispatcher(ctx, "", "", "mounttable")
if err != nil {
panic(err)
}