vault: use RWMutex on MountTable itself

This commit is contained in:
Mitchell Hashimoto 2015-03-17 15:28:01 -07:00
parent 99abc11ec5
commit abe0859aa5
3 changed files with 13 additions and 10 deletions

View File

@ -113,8 +113,7 @@ type Core struct {
// mounts is loaded after unseal since it is a protected
// configuration
mounts *MountTable
mountsLock sync.RWMutex
mounts *MountTable
// systemView is the barrier view for the system backend
systemView *BarrierView

View File

@ -140,8 +140,8 @@ type SystemBackend struct {
// handleMountTable handles the "mounts" endpoint to provide the mount table
func (b *SystemBackend) handleMountTable(
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
b.Core.mountsLock.RLock()
defer b.Core.mountsLock.RUnlock()
b.Core.mounts.Lock()
defer b.Core.mounts.Unlock()
resp := &logical.Response{
IsSecret: false,

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
"github.com/hashicorp/vault/logical"
)
@ -36,6 +37,9 @@ var (
// MountTable is used to represent the internal mount table
type MountTable struct {
// This lock should be held whenever modifying the Entries field.
sync.RWMutex
Entries []*MountEntry `json:"entries"`
}
@ -70,8 +74,8 @@ func (e *MountEntry) Clone() *MountEntry {
// Mount is used to mount a new backend to the mount table.
func (c *Core) mount(me *MountEntry) error {
c.mountsLock.Lock()
defer c.mountsLock.Unlock()
c.mounts.Lock()
defer c.mounts.Unlock()
// Ensure we end the path in a slash
if !strings.HasSuffix(me.Path, "/") {
@ -113,8 +117,8 @@ func (c *Core) mount(me *MountEntry) error {
//
// TODO: document what happens to all secrets currently out for this path.
func (c *Core) unmount(path string) error {
c.mountsLock.Lock()
defer c.mountsLock.Unlock()
c.mounts.Lock()
defer c.mounts.Unlock()
// Ensure we end the path in a slash
if !strings.HasSuffix(path, "/") {
@ -157,8 +161,8 @@ func (c *Core) unmount(path string) error {
// Remount is used to remount a path at a new mount point.
func (c *Core) remount(src, dst string) error {
c.mountsLock.Lock()
defer c.mountsLock.Unlock()
c.mounts.Lock()
defer c.mounts.Unlock()
// Ensure we end the path in a slash
if !strings.HasSuffix(src, "/") {