예제 #1
0
static g_cache_ptr
get_g_cache(void)
{
	g_cache_ptr gc;

	/* always enter with a READ LOCK and exit with one too */
	ASSERT(RW_READ_HELD(&g_cache_lock));
	if ((gc = groups_cache) != 0) {
		return (gc);
	}
	(void) rw_unlock(&g_cache_lock);

	/* write lock the cache and try again */
	(void) rw_wrlock(&g_cache_lock);
	if ((gc = groups_cache) != 0) {
		(void) rw_unlock(&g_cache_lock);
		(void) rw_rdlock(&g_cache_lock);
		return (gc);
	}

	gc = groups_cache = calloc(1, sizeof (*groups_cache));
	if (groups_cache == 0) {
		(void) rw_unlock(&g_cache_lock);
		(void) rw_rdlock(&g_cache_lock);
		return (0);
	}
	(void) rw_unlock(&g_cache_lock);
	(void) rw_rdlock(&g_cache_lock);
	return (gc);
}
예제 #2
0
파일: th-lock.c 프로젝트: asb/frankenlibc
void solaris_locking_callback(int mode, int type, char *file, int line)
{
# if 0
    fprintf(stderr, "thread=%4d mode=%s lock=%s %s:%d\n",
            CRYPTO_thread_id(),
            (mode & CRYPTO_LOCK) ? "l" : "u",
            (type & CRYPTO_READ) ? "r" : "w", file, line);
# endif

# if 0
    if (CRYPTO_LOCK_SSL_CERT == type)
        fprintf(stderr, "(t,m,f,l) %ld %d %s %d\n",
                CRYPTO_thread_id(), mode, file, line);
# endif
    if (mode & CRYPTO_LOCK) {
# ifdef USE_MUTEX
        mutex_lock(&(lock_cs[type]));
# else
        if (mode & CRYPTO_READ)
            rw_rdlock(&(lock_cs[type]));
        else
            rw_wrlock(&(lock_cs[type]));
# endif
        lock_count[type]++;
    } else {
# ifdef USE_MUTEX
        mutex_unlock(&(lock_cs[type]));
# else
        rw_unlock(&(lock_cs[type]));
# endif
    }
}
FOREIGN_SERVER *get_server_by_name(MEM_ROOT *mem, const char *server_name,
                                   FOREIGN_SERVER *buff)
{
  size_t server_name_length;
  FOREIGN_SERVER *server;
  DBUG_ENTER("get_server_by_name");
  DBUG_PRINT("info", ("server_name %s", server_name));

  server_name_length= strlen(server_name);

  if (! server_name || !strlen(server_name))
  {
    DBUG_PRINT("info", ("server_name not defined!"));
    DBUG_RETURN((FOREIGN_SERVER *)NULL);
  }

  DBUG_PRINT("info", ("locking servers_cache"));
  rw_rdlock(&THR_LOCK_servers);
  if (!(server= (FOREIGN_SERVER *) hash_search(&servers_cache,
                                               (uchar*) server_name,
                                               server_name_length)))
  {
    DBUG_PRINT("info", ("server_name %s length %u not found!",
                        server_name, (unsigned) server_name_length));
    server= (FOREIGN_SERVER *) NULL;
  }
  /* otherwise, make copy of server */
  else
    server= clone_server(mem, server, buff);

  DBUG_PRINT("info", ("unlocking servers_cache"));
  rw_unlock(&THR_LOCK_servers);
  DBUG_RETURN(server);

}
예제 #4
0
파일: mttest.c 프로젝트: dhaley/dcp
void
resolve_symbols()
{
	void *foo;
	global_cond_flag = TRUE;
#ifdef SOLARIS
	mutex_lock(&queue_lock);
	mutex_trylock(&queue_lock);
	mutex_unlock(&queue_lock);
	foo = (void *)&cond_signal;
	foo = (void *)&cond_wait;
	foo = (void *)&cond_timedwait;
	sema_post(&global_sema_lock);
	sema_wait(&global_sema_lock); 
	rw_rdlock(&global_rw_lock);
	rw_unlock(&global_rw_lock);
	rw_wrlock(&global_rw_lock);
	rw_unlock(&global_rw_lock);
#endif
#ifdef POSIX
	pthread_mutex_lock(&queue_lock);
	pthread_mutex_trylock(&queue_lock);
	pthread_mutex_unlock(&queue_lock);
	foo = (void *)&pthread_cond_signal;
	foo = (void *)&pthread_cond_wait;
	foo = (void *)&pthread_cond_timedwait;
	sem_post(&global_sema_lock);
	sem_wait(&global_sema_lock); 
#endif
}
예제 #5
0
void
smb_ipc_get_user(char *buf, size_t buflen)
{
	(void) rw_rdlock(&smb_ipc_lock);
	(void) strlcpy(buf, ipc_info.user, buflen);
	(void) rw_unlock(&smb_ipc_lock);
}
예제 #6
0
파일: smb_nic.c 프로젝트: bahamas10/openzfs
/*
 * smb_nic_getnext
 *
 * Returns the next NIC information based on the passed
 * iterator (ni). The iterator must have previously been
 * initialized by calling smb_nic_getfirst().
 *
 * Returns SMB_NIC_SUCCESS upon successfully finding the specified NIC
 * or the following:
 * 	SMB_NIC_INVALID_ARG - the specified iterator is invalid
 * 	SMB_NIC_NO_MORE - reaches the end of the NIC list
 * 	SMB_NIC_CHANGED - sequence number in the iterator is different from
 *	  the sequence number in the NIC list which means
 *	  the list has been changed between getfirst/getnext
 *	  calls.
 */
int
smb_nic_getnext(smb_niciter_t *ni)
{
	int rc = SMB_NIC_SUCCESS;

	if ((ni == NULL) || (ni->ni_cookie < 1))
		return (SMB_NIC_INVALID_ARG);

	(void) rw_rdlock(&smb_niclist.nl_rwl);

	if ((smb_niclist.nl_cnt > ni->ni_cookie) &&
	    (smb_niclist.nl_seqnum == ni->ni_seqnum)) {
		ni->ni_nic = smb_niclist.nl_nics[ni->ni_cookie];
		ni->ni_cookie++;
	} else {
		if (smb_niclist.nl_seqnum != ni->ni_seqnum)
			rc = SMB_NIC_CHANGED;
		else
			rc = SMB_NIC_NO_MORE;
	}

	(void) rw_unlock(&smb_niclist.nl_rwl);

	return (rc);
}
예제 #7
0
int 
mi_rsame(MI_INFO * info, byte * record, int inx)
{
	DBUG_ENTER("mi_rsame");

	if (inx != -1 && !(((ulonglong) 1 << inx) & info->s->state.key_map)) {
		DBUG_RETURN(my_errno = HA_ERR_WRONG_INDEX);
	}
	if (info->lastpos == HA_OFFSET_ERROR || info->update & HA_STATE_DELETED) {
		DBUG_RETURN(my_errno = HA_ERR_KEY_NOT_FOUND);	/* No current record */
	}
	info->update &= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);

	/* Read row from data file */
	if (_mi_readinfo(info, F_RDLCK, 1))
		DBUG_RETURN(my_errno);

	if (inx >= 0) {
		info->lastinx = inx;
		info->lastkey_length = _mi_make_key(info, (uint) inx, info->lastkey, record,
						    info->lastpos);
		if (info->s->concurrent_insert)
			rw_rdlock(&info->s->key_root_lock[inx]);
		VOID(_mi_search(info, info->s->keyinfo + inx, info->lastkey, 0, SEARCH_SAME,
				info->s->state.key_root[inx]));
		if (info->s->concurrent_insert)
			rw_unlock(&info->s->key_root_lock[inx]);
	}
	if (!(*info->read_record) (info, info->lastpos, record))
		DBUG_RETURN(0);
	if (my_errno == HA_ERR_RECORD_DELETED)
		my_errno = HA_ERR_KEY_NOT_FOUND;
	DBUG_RETURN(my_errno);
}				/* mi_rsame */
예제 #8
0
파일: rwlock.c 프로젝트: bahamas10/openzfs
void
rw_downgrade(krwlock_t *rwlp)
{
	ASSERT(rwlp->rw_owner == _curthread());
	rwlp->rw_owner = _KTHREAD_INVALID;
	VERIFY(rw_unlock(&rwlp->rw_lock) == 0);
	VERIFY(rw_rdlock(&rwlp->rw_lock) == 0);
}
예제 #9
0
int
mi_rprev(MI_INFO * info, byte * buf, int inx)
{
    int		error     , changed;
    register uint	flag;
    MYISAM_SHARE   *share = info->s;
    DBUG_ENTER("mi_rprev");

    if ((inx = _mi_check_index(info, inx)) < 0)
        DBUG_RETURN(my_errno);
    flag = SEARCH_SMALLER;	/* Read previous */
    if (info->lastpos == HA_OFFSET_ERROR && info->update & HA_STATE_NEXT_FOUND)
        flag = 0;	/* Read last */

    if (_mi_readinfo(info, F_RDLCK, 1))
        DBUG_RETURN(my_errno);
    changed = _mi_test_if_changed(info);
    if (share->concurrent_insert)
        rw_rdlock(&share->key_root_lock[inx]);
    if (!flag)
        error = _mi_search_last(info, share->keyinfo + inx,
                                share->state.key_root[inx]);
    else if (!changed)
        error = _mi_search_next(info, share->keyinfo + inx, info->lastkey,
                                info->lastkey_length, flag,
                                share->state.key_root[inx]);
    else
        error = _mi_search(info, share->keyinfo + inx, info->lastkey,
                           info->lastkey_length, flag, share->state.key_root[inx]);

    if (!error) {
        while (info->lastpos >= info->state->data_file_length) {
            /*
             * Skip rows that are inserted by other threads since
             * we got a lock
             */
            if ((error = _mi_search_next(info, share->keyinfo + inx, info->lastkey,
                                         info->lastkey_length,
                                         SEARCH_SMALLER,
                                         share->state.key_root[inx])))
                break;
        }
    }
    if (share->concurrent_insert)
        rw_unlock(&share->key_root_lock[inx]);
    info->update &= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
    info->update |= HA_STATE_PREV_FOUND;
    if (error) {
        if (my_errno == HA_ERR_KEY_NOT_FOUND)
            my_errno = HA_ERR_END_OF_FILE;
    } else if (!buf) {
        DBUG_RETURN(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0);
    } else if (!(*info->read_record) (info, info->lastpos, buf)) {
        info->update |= HA_STATE_AKTIV;	/* Record is read */
        DBUG_RETURN(0);
    }
    DBUG_RETURN(my_errno);
}				/* mi_rprev */
예제 #10
0
/*
 * Notifies lockd specified by name that state has changed for this server.
 */
void
sm_notify_svc(stat_chge *ntfp)
{
	rw_rdlock(&thr_rwlock);
	if (debug)
		(void) printf("sm_notify: %s state =%d\n",
		    ntfp->mon_name, ntfp->state);
	send_notice(ntfp->mon_name, ntfp->state);
	rw_unlock(&thr_rwlock);
}
예제 #11
0
void
smb_ipc_get_passwd(uint8_t *buf, size_t buflen)
{
	if (buflen < SMBAUTH_HASH_SZ)
		return;

	(void) rw_rdlock(&smb_ipc_lock);
	(void) memcpy(buf, ipc_info.passwd, SMBAUTH_HASH_SZ);
	(void) rw_unlock(&smb_ipc_lock);
}
예제 #12
0
파일: rmtab.c 프로젝트: CoryXie/opensolaris
void
mntlist_send(SVCXPRT *transp)
{
    (void) rw_rdlock(&rmtab_lock);

    errno = 0;
    if (!svc_sendreply(transp, xdr_mntlistencode, (char *)&mntlist))
        log_cant_reply(transp);

    (void) rw_unlock(&rmtab_lock);
}
예제 #13
0
P_LIB_API pboolean
p_rwlock_reader_lock (PRWLock *lock)
{
	if (P_UNLIKELY (lock == NULL))
		return FALSE;

	if (P_UNLIKELY (rw_rdlock (&lock->hdl) == 0))
		return TRUE;
	else {
		P_ERROR ("PRWLock::p_rwlock_reader_lock: rw_rdlock() failed");
		return FALSE;
	}
}
예제 #14
0
파일: rwlock.c 프로젝트: bahamas10/openzfs
void
rw_enter(krwlock_t *rwlp, krw_t rw)
{
	int rc;

	if (rw == RW_READER) {
		rc = rw_rdlock(&rwlp->rw_lock);
	} else {
		rc = rw_wrlock(&rwlp->rw_lock);
		rwlp->rw_owner = _curthread();
	}
	VERIFY(rc == 0);
}
예제 #15
0
/* ARGSUSED */
void
sm_unmon_all_svc(my_id *myidp, sm_stat *resp)
{
	rw_rdlock(&thr_rwlock);
	if (debug)
		(void) printf("proc sm_unmon_all: [%s, %d, %d, %d]\n",
		    myidp->my_name,
		    myidp->my_prog, myidp->my_vers,
		    myidp->my_proc);
	delete_mon((char *)NULL, myidp);
	pr_mon(NULL);
	resp->state = local_state;
	rw_unlock(&thr_rwlock);
}
예제 #16
0
파일: mttest.c 프로젝트: dhaley/dcp
/* read_write: use a global Reader/Writer lock to process array's data */
void
read_write(Workblk *array, struct scripttab *k)
{

#ifdef SOLARIS
	switch (array->tid % NUM_OF_THREADS) {
	case 0:
	case 1:
	default:
	    rw_rdlock(&global_rw_lock);

	    array->ready = gethrtime();
	    array->vready = gethrvtime();

	    array->compute_ready = array->ready;
	    array->compute_vready = array->vready;

	    (k->called_func)(&array->list[0]);
	    array->compute_done = gethrtime();
	    array->compute_vdone = gethrvtime();

	    rw_unlock(&global_rw_lock);
	    break;

	case 2:
	    rw_wrlock(&global_rw_lock);

	    array->ready = gethrtime();
	    array->vready = gethrvtime();

	    array->compute_ready = array->ready;
	    array->compute_vready = array->vready;

	    (k->called_func)(&array->list[0]);

	    array->compute_done = gethrtime();
	    array->compute_vdone = gethrvtime();

	    rw_unlock(&global_rw_lock);
	    break;
	}
#endif

	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
예제 #17
0
/*
 * Search the list of devices from /etc/mnttab to find the mount point
 * for the specified device.
 */
int
inuse_mnt(char *slice, nvlist_t *attrs, int *errp)
{
	struct mntpnt_list	*listp;
	int			found = 0;

	*errp = 0;
	if (slice == NULL) {
	    return (found);
	}

	(void) mutex_lock(&init_lock);
	if (!initialized) {
	    thread_t	mnttab_thread;

	    /* load the mntpnt cache */
	    *errp = load_mnttab(B_FALSE);

	    if (*errp == 0) {
		/* start a thread to monitor the mnttab */
		*errp = thr_create(NULL, NULL, (void *(*)(void *))watch_mnttab,
		    NULL, THR_NEW_LWP | THR_DAEMON, &mnttab_thread);
	    }

	    if (*errp == 0) {
		initialized = 1;
	    }
	}
	(void) mutex_unlock(&init_lock);

	(void) rw_rdlock(&mntpoint_lock);
	listp = mntpoint_listp;
	while (listp != NULL) {
	    if (libdiskmgt_str_eq(slice, listp->special)) {
		libdiskmgt_add_str(attrs, DM_USED_BY, DM_USE_MOUNT, errp);
		libdiskmgt_add_str(attrs, DM_USED_NAME, listp->mountp, errp);
		found = 1;
		break;
	    }
	    listp = listp->next;
	}
	(void) rw_unlock(&mntpoint_lock);

	return (found);
}
예제 #18
0
파일: smb_nic.c 프로젝트: bahamas10/openzfs
boolean_t
smb_nic_is_same_subnet(smb_inaddr_t *ipaddr)
{
	smb_nic_t *cfg;
	int i;

	(void) rw_rdlock(&smb_niclist.nl_rwl);

	for (i = 0; i < smb_niclist.nl_cnt; i++) {
		cfg = &smb_niclist.nl_nics[i];
		if (smb_inet_same_subnet(ipaddr, &cfg->nic_ip, cfg->nic_mask)) {
			(void) rw_unlock(&smb_niclist.nl_rwl);
			return (B_TRUE);
		}
	}
	(void) rw_unlock(&smb_niclist.nl_rwl);
	return (B_FALSE);
}
예제 #19
0
/* Interface for rpc.nisd and anyone else who wants to know */
int
__nis_group_cache_stats(int *grpcachecall, int *grpcachehits,
    int *grpcachemisses)
{
	(void) rw_rdlock(&g_cache_lock);
	if (groups_cache == 0) {
		*grpcachecall = 0;
		*grpcachehits = 0;
		*grpcachemisses = 0;
		(void) rw_unlock(&g_cache_lock);
		return (0);
	}
	*grpcachecall = groups_cache->ncalls;
	*grpcachehits = groups_cache->nhits;
	*grpcachemisses = groups_cache->nmisses;
	(void) rw_unlock(&g_cache_lock);
	return (1);
}
예제 #20
0
/* ARGSUSED */
void
sm_unmon_svc(mon_id *monidp, sm_stat *resp)
{
	rw_rdlock(&thr_rwlock);
	if (debug) {
		(void) printf(
		    "proc sm_unmon: mon_name = %s, [%s, %d, %d, %d]\n",
		    monidp->mon_name, monidp->my_id.my_name,
		    monidp->my_id.my_prog, monidp->my_id.my_vers,
		    monidp->my_id.my_proc);
		pr_mon(monidp->mon_name);
	}

	delete_mon(monidp->mon_name, &monidp->my_id);
	pr_mon(monidp->mon_name);
	resp->state = local_state;
	rw_unlock(&thr_rwlock);
}
예제 #21
0
/*
 * FUNCTION: _nscd_is_getent_ctx
 *
 * Check to see if a getent context can be found in the internal
 * getent context database.
 */
nscd_getent_context_t *
_nscd_is_getent_ctx(
    nscd_cookie_num_t	cookie_num)
{
    char			ptrstr[32];
    const nscd_db_entry_t	*db_entry;
    nscd_getent_context_t	*ret = NULL;
    char			*me = "_nscd_is_getent_ctx";

    (void) snprintf(ptrstr, sizeof (ptrstr), "%lld", cookie_num);

    (void) rw_rdlock(&getent_ctxDB_rwlock);

    db_entry = _nscd_get_db_entry(getent_ctxDB, NSCD_DATA_CTX_ADDR,
                                  (const char *)ptrstr, NSCD_GET_FIRST_DB_ENTRY, 0);

    if (db_entry != NULL) {
        nscd_getent_ctx_t *gnctx;

        gnctx = (nscd_getent_ctx_t *)*(db_entry->data_array);
        _NSCD_LOG(NSCD_LOG_GETENT_CTX, NSCD_LOG_LEVEL_DEBUG)
        (me, "getent context %p, cookie# %lld, to_delete %d\n",
         gnctx->ptr, gnctx->cookie_num, gnctx->to_delete);

        /*
         * If the ctx is not to be deleted and the cookie numbers
         * match, return the ctx if not aborted and not in use.
         * Otherwise return NULL.
         */
        if (gnctx->to_delete == 0 && gnctx->cookie_num == cookie_num) {
            ret = gnctx->ptr;
            (void) mutex_lock(&gnctx->ptr->getent_mutex);
            if (ret->aborted == 1 || ret->in_use == 1)
                ret = NULL;
            else
                ret->in_use = 1;
            (void) mutex_unlock(&gnctx->ptr->getent_mutex);
        }
    }

    (void) rw_unlock(&getent_ctxDB_rwlock);

    return (ret);
}
예제 #22
0
/*
 * Find a document by RPC handle in the spool list and return the fd.
 */
static int
spoolss_find_document(ndr_hdid_t *handle)
{
	smb_spooldoc_t *sp;

	(void) rw_rdlock(&spoolss_splist.sp_rwl);

	sp = list_head(&spoolss_splist.sp_list);
	while (sp != NULL) {
		if (!memcmp(handle, &(sp->sd_handle), sizeof (ndr_hdid_t))) {
			(void) rw_unlock(&spoolss_splist.sp_rwl);
			return (sp->sd_fd);
		}
		sp = list_next(&spoolss_splist.sp_list, sp);
	}

	(void) rw_unlock(&spoolss_splist.sp_rwl);
	return (-1);
}
예제 #23
0
/*
 * Lock the cache with the specified mode.
 * If the cache is in updating state and a read lock is
 * requested, the lock won't be granted until either the
 * update is finished or SMB_CACHE_UPDATE_WAIT has passed.
 *
 * Whenever a lock is granted, the number of inflight cache
 * operations is incremented.
 */
static int
smb_cache_lock(smb_cache_t *chandle, int mode)
{
	(void) mutex_lock(&chandle->ch_mtx);
	switch (chandle->ch_state) {
	case SMB_CACHE_STATE_NOCACHE:
	case SMB_CACHE_STATE_DESTROYING:
		(void) mutex_unlock(&chandle->ch_mtx);
		return (ENODATA);

	case SMB_CACHE_STATE_REFRESHING:
		/*
		 * Read operations should wait until the update
		 * is completed.
		 */
		if (mode == SMB_CACHE_RDLOCK) {
			if (!smb_cache_wait(chandle)) {
				(void) mutex_unlock(&chandle->ch_mtx);
				return (ETIME);
			}
		}
	/* FALLTHROUGH */
	case SMB_CACHE_STATE_READY:
		chandle->ch_nops++;
		break;

	default:
		assert(0);
	}
	(void) mutex_unlock(&chandle->ch_mtx);

	/*
	 * Lock has to be taken outside the mutex otherwise
	 * there could be a deadlock
	 */
	if (mode == SMB_CACHE_RDLOCK)
		(void) rw_rdlock(&chandle->ch_cache_lck);
	else
		(void) rw_wrlock(&chandle->ch_cache_lck);

	return (0);
}
예제 #24
0
/*
 * smb_lucache_lock
 *
 * Locks the user cache for reading and also
 * increment the handle reference count.
 */
static int
smb_lucache_lock(void)
{
	(void) mutex_lock(&smb_uch.uc_mtx);
	switch (smb_uch.uc_state) {
	case SMB_UCHS_NOCACHE:
		assert(0);
		(void) mutex_unlock(&smb_uch.uc_mtx);
		return (SMB_PWE_DENIED);

	case SMB_UCHS_DESTROYING:
		(void) mutex_unlock(&smb_uch.uc_mtx);
		return (SMB_PWE_DENIED);
	}
	smb_uch.uc_refcnt++;
	(void) mutex_unlock(&smb_uch.uc_mtx);

	(void) rw_rdlock(&smb_uch.uc_cache_lck);
	return (SMB_PWE_SUCCESS);
}
예제 #25
0
파일: dfs.c 프로젝트: bahamas10/openzfs
/*
 * Retrieves the information of the root specified by its path.
 *
 * Info level (1) only needs the UNC path which is not stored,
 * it is constructed so the function will return without
 * accessing the backend storage.
 */
uint32_t
dfs_root_getinfo(const char *rootdir, dfs_info_t *info, uint32_t infolvl)
{
	uint32_t status = ERROR_INTERNAL_ERROR;
	int xfd;

	bzero(info, sizeof (dfs_info_t));
	info->i_type = DFS_OBJECT_ROOT;

	if (infolvl == 1)
		return (ERROR_SUCCESS);

	(void) rw_rdlock(&dfs_root_rwl);
	if ((xfd = dfs_root_xopen(rootdir, O_RDONLY)) > 0) {
		status = dfs_root_xread(xfd, info, infolvl);
		dfs_root_xclose(xfd);
	}
	(void) rw_unlock(&dfs_root_rwl);

	return (status);
}
예제 #26
0
nscd_rc_t
_nscd_init_getent_ctx_base(
    int			dbi,
    int			lock)
{
    nscd_getent_ctx_base_t	*base = NULL;
    char			*me = "_nscd_init_getent_ctx_base";

    if (lock)
        (void) rw_rdlock(&nscd_getent_ctx_base_lock);

    base = (nscd_getent_ctx_base_t *)_nscd_alloc(
               NSCD_DATA_GETENT_CTX_BASE,
               sizeof (nscd_getent_ctx_base_t),
               _nscd_free_getent_ctx_base,
               NSCD_ALLOC_MUTEX | NSCD_ALLOC_COND);

    if (base == NULL) {
        if (lock)
            (void) rw_unlock(&nscd_getent_ctx_base_lock);
        return (NSCD_NO_MEMORY);
    }
    _NSCD_LOG(NSCD_LOG_GETENT_CTX | NSCD_LOG_CONFIG, NSCD_LOG_LEVEL_DEBUG)
    (me, "base %p allocated\n", base);

    /*
     * initialize and activate the new getent_ctx base
     */
    base->dbi = dbi;
    base->max_getent_ctx = NSCD_SW_CFG(dbi).max_getent_ctx_per_db;
    nscd_getent_ctx_base[dbi] =
        (nscd_getent_ctx_base_t *)_nscd_set(
            (nscd_acc_data_t *)nscd_getent_ctx_base[dbi],
            (nscd_acc_data_t *)base);

    if (lock)
        (void) rw_unlock(&nscd_getent_ctx_base_lock);

    return (NSCD_SUCCESS);
}
예제 #27
0
파일: smb_nic.c 프로젝트: bahamas10/openzfs
/*
 * smb_nic_getfirst
 *
 * Returns the first NIC in the interface list and
 * initializes the given iterator. To get the rest of
 * NICs smb_nic_getnext() must be called.
 *
 * Returns SMB_NIC_SUCCESS upon success or the following:
 *	SMB_NIC_NOT_FOUND - there's no interface available
 *	SMB_NIC_INVALID_ARG - 'ni' is NULL
 */
int
smb_nic_getfirst(smb_niciter_t *ni)
{
	int rc = SMB_NIC_SUCCESS;

	if (ni == NULL)
		return (SMB_NIC_INVALID_ARG);

	(void) rw_rdlock(&smb_niclist.nl_rwl);

	if (smb_niclist.nl_cnt > 0) {
		ni->ni_nic = smb_niclist.nl_nics[0];
		ni->ni_cookie = 1;
		ni->ni_seqnum = smb_niclist.nl_seqnum;
	} else {
		rc = SMB_NIC_NOT_FOUND;
	}

	(void) rw_unlock(&smb_niclist.nl_rwl);

	return (rc);
}
예제 #28
0
파일: smb_nic.c 프로젝트: bahamas10/openzfs
/*
 * smb_nic_getnum
 *
 * Gets the number of interfaces for the specified host.
 * if host is NULL then total number of interfaces
 * is returned. It's assumed that given name is a NetBIOS
 * encoded name.
 */
int
smb_nic_getnum(char *nb_hostname)
{
	int n = 0, i;

	(void) rw_rdlock(&smb_niclist.nl_rwl);

	if (nb_hostname != NULL) {
		for (i = 0; i < smb_niclist.nl_cnt; i++) {
			/* ignore the suffix */
			if (strncasecmp(smb_niclist.nl_nics[i].nic_nbname,
			    nb_hostname, NETBIOS_NAME_SZ - 1) == 0)
				n++;
		}
	} else {
		n = smb_niclist.nl_cnt;
	}

	(void) rw_unlock(&smb_niclist.nl_rwl);

	return (n);
}
예제 #29
0
/*
 * FUNCTION: _nscd_del_getent_ctx
 *
 * Delete a getent context from the internal getent context database.
 */
static void
_nscd_del_getent_ctx(
    nscd_getent_context_t	*ptr,
    nscd_cookie_num_t	cookie_num)
{
    char			ptrstr[32];
    nscd_getent_ctx_t	*gnctx;
    const nscd_db_entry_t	*db_entry;

    if (ptr == NULL)
        return;

    (void) snprintf(ptrstr, sizeof (ptrstr), "%lld", cookie_num);

    (void) rw_rdlock(&getent_ctxDB_rwlock);
    /*
     * first find the db entry and make sure the
     * sequence number matched, then delete it from
     * the database.
     */
    db_entry = _nscd_get_db_entry(getent_ctxDB,
                                  NSCD_DATA_CTX_ADDR,
                                  (const char *)ptrstr,
                                  NSCD_GET_FIRST_DB_ENTRY, 0);
    if (db_entry != NULL) {
        gnctx = (nscd_getent_ctx_t *)*(db_entry->data_array);
        if (gnctx->ptr == ptr && gnctx->cookie_num  == cookie_num) {

            (void) rw_unlock(&getent_ctxDB_rwlock);
            (void) rw_wrlock(&getent_ctxDB_rwlock);

            (void) _nscd_delete_db_entry(getent_ctxDB,
                                         NSCD_DATA_CTX_ADDR,
                                         (const char *)ptrstr,
                                         NSCD_DEL_FIRST_DB_ENTRY, 0);
        }
    }
    (void) rw_unlock(&getent_ctxDB_rwlock);
}
예제 #30
0
/*
 * smb_lucache_num
 *
 * Returns the number of cache entries
 */
static int
smb_lucache_num(void)
{
	int num;

	(void) mutex_lock(&smb_uch.uc_mtx);
	switch (smb_uch.uc_state) {
	case SMB_UCHS_NOCACHE:
		assert(0);
		(void) mutex_unlock(&smb_uch.uc_mtx);
		return (0);

	case SMB_UCHS_DESTROYING:
		(void) mutex_unlock(&smb_uch.uc_mtx);
		return (0);
	}
	(void) mutex_unlock(&smb_uch.uc_mtx);

	(void) rw_rdlock(&smb_uch.uc_cache_lck);
	num = (int)avl_numnodes(&smb_uch.uc_cache);
	(void) rw_unlock(&smb_uch.uc_cache_lck);

	return (num);
}