// newNSLock - return a new name space lock map.
516730
func newNSLock(isDistXL bool) *nsLockMap {
	nsMutex := nsLockMap{
		isDistXL: isDistXL,
	}
	if isDistXL {
		return &nsMutex
	}
	nsMutex.lockMap = make(map[nsParam]*nsLock)
	return &nsMutex
}
374180
func NewNamespace(name string) Namespace {
	return Namespace{
		Kind:    KindNamespace,
		Version: V2,
		Metadata: Metadata{
			Name: name,
		},
	}
}
893685
func (c *NamespaceSCCAllocationController) syncNamespace(key string) error {
	ns, err := c.nsLister.Get(key)
	if apierrors.IsNotFound(err) {
		return nil
	}
	if err != nil {
		return err
	}
	if _, ok := ns.Annotations[security.UIDRangeAnnotation]; ok {
		return nil
	}

	return c.allocate(ns)
}
63882
func NewLockUnspentCmd(unlock bool, transactions []TransactionInput) *LockUnspentCmd {
	return &LockUnspentCmd{
		Unlock:       unlock,
		Transactions: transactions,
	}
}
1191935
func New(client *consul.Client) *ConsulLocker {
	return &ConsulLocker{
		Client: client,
		locks:  make(map[string]*consul.Lock),
		mutex:  new(sync.RWMutex),
	}
}
948256
func New(options LockStoreOptions) LockStore {
	testTryLockCallback := options.testTryLockCallback
	if testTryLockCallback == nil {
		testTryLockCallback = func() {}
	}

	lock := _LockStoreImp{
		granularity:         options.Granularity,
		testTryLockCallback: testTryLockCallback,
	}

	switch options.Granularity {
	case PerKeyGranularity:
		lock.perKeyLocks = make(map[string]*_LockImp)
	case ShardedGranularity:
		lock.shardedLocks = make([]*sync.RWMutex, options.LockCount)
		for i := range lock.shardedLocks {
			lock.shardedLocks[i] = &sync.RWMutex{}
		}
	}

	return &lock
}
471521
func NewNamespace(ns ...string) Namespace {
	n := make([]NamespaceElement, len(ns))
	for i, ns := range ns {
		n[i] = NamespaceElement{Value: ns}
	}
	return n
}
1120388
func NewUnlock(g *libkb.GlobalContext) *Unlock {
	return &Unlock{
		Contextified: libkb.NewContextified(g),
	}
}
1358195
func New(config Config) (*lock, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}
	lock := &lock{
		agent:       config.AgentName,
		clock:       config.Clock,
		logger:      config.Logger,
		logFilename: config.LogFilename,
		acquire:     mutex.Acquire,
		spec: mutex.Spec{
			Name:  "machine-lock",
			Clock: config.Clock,
			Delay: 250 * time.Millisecond,
			// Cancel is added in Acquire.
		},
		waiting: make(map[int]*info),
		history: deque.NewWithMaxLen(1000),
	}
	lock.setStartMessage()
	return lock, nil
}
932290
func NewDRWMutex(name string, clnt *Dsync) *DRWMutex {
	return &DRWMutex{
		Name:       name,
		writeLocks: make([]string, clnt.dNodeCount),
		clnt:       clnt,
	}
}
923451
func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocator.NetworkAllocator, error) {
	na := &cnmNetworkAllocator{
		networks: make(map[string]*network),
		services: make(map[string]struct{}),
		tasks:    make(map[string]struct{}),
		nodes:    make(map[string]map[string]struct{}),
	}

	// There are no driver configurations and notification
	// functions as of now.
	reg, err := drvregistry.New(nil, nil, nil, nil, pg)
	if err != nil {
		return nil, err
	}

	if err := initializeDrivers(reg); err != nil {
		return nil, err
	}

	if err = initIPAMDrivers(reg, netConfig); err != nil {
		return nil, err
	}

	pa, err := newPortAllocator()
	if err != nil {
		return nil, err
	}

	na.portAllocator = pa
	na.drvRegistry = reg
	return na, nil
}
773875
func (s *Sandbox) NetNsJoin(nspath, name string) error {
	if s.netns != nil {
		return fmt.Errorf("sandbox already has a network namespace, cannot join another")
	}

	netNS, err := s.NetNsGet(nspath, name)
	if err != nil {
		return err
	}

	s.netns = netNS

	return nil
}
1330176
func (z *zones) New(name string) (dnsprovider.Zone, error) {
	return &zone{
		name:   name,
		client: z.client,
	}, nil

}
139003
func NewUUID(namespace, name string) ([]byte, error) {
	hash := md5.New()
	_, err := hash.Write([]byte(namespace))
	if err != nil {
		return nil, errors.Wrapf(err, "could not compute hash value for namespace %q", namespace)
	}
	_, err = hash.Write([]byte(name))
	if err != nil {
		return nil, errors.Wrapf(err, "could not compute hash value for name %q", name)
	}

	sum := hash.Sum(nil)

	uuid := make([]byte, 16)
	copy(uuid, sum)

	// set version(v3)
	internal.SetVersion(uuid, internal.VersionNameBasedMD5)
	// set layout(RFC4122)
	internal.SetLayout(uuid, internal.LayoutRFC4122)

	return uuid, nil
}
716373
func NewLockInfo() *LockInfo {
	id, err := uuid.GenerateUUID()
	if err != nil {
		// this of course shouldn't happen
		panic(err)
	}

	// don't error out on user and hostname, as we don't require them
	userName := ""
	if userInfo, err := user.Current(); err == nil {
		userName = userInfo.Username
	}
	host, _ := os.Hostname()

	info := &LockInfo{
		ID:      id,
		Who:     fmt.Sprintf("%s@%s", userName, host),
		Version: version.Version,
		Created: time.Now().UTC(),
	}
	return info
}
535277
func (c *Connection) NewLock(p string) (client.Lock, error) {
	c.RLock()
	defer c.RUnlock()
	if err := c.isClosed(); err != nil {
		return nil, err
	}
	lock := &Lock{
		lock: zklib.NewLock(c.conn, path.Join(c.basePath, p), zklib.WorldACL(zklib.PermAll)),
	}
	return lock, nil
}
452581
func (r *HashRing) copyServersNoLock() []string {
	servers := make([]string, 0, len(r.serverSet))
	for server := range r.serverSet {
		servers = append(servers, server)
	}
	return servers
}