コード例 #1
0
ファイル: sv.c プロジェクト: dduval/kernel-rhel3
int sv_test(void) 
{
	spinlock_t s = SPIN_LOCK_UNLOCKED;

	sv_init(&sv, &s, SV_MON_SPIN);
	printk("sv_test: starting sv_test_1_w.\n");
	kernel_thread(sv_test_1_w, &s, 0);
	printk("sv_test: starting sv_test_1_s.\n");
	kernel_thread(sv_test_1_s, &s, 0);

	printk("sv_test: waiting for talkback.\n");
	down(&talkback); down(&talkback);
	printk("sv_test: talkback happened, sv_destroying.\n");
	sv_destroy(&sv);

	count = 0;

	printk("sv_test: beginning big_test on sv.\n");

	sv_init(&sv, &monitor, SV_MON_SEMA);
	big_test(&sv);
	sv_destroy(&sv);

	printk("sv_test: beginning big_test on sv_filo.\n");
	sv_init(&sv_filo, &monitor, SV_MON_SEMA | SV_ORDER_FILO);
	big_test(&sv_filo);
	sv_destroy(&sv_filo);

	interrupt_test();

	printk("sv_test: done.\n");
	return 0;
}
コード例 #2
0
/*
 * This is called to free all the memory associated with a dquot
 */
void
xfs_qm_dqdestroy(
	xfs_dquot_t	*dqp)
{
	ASSERT(! XFS_DQ_IS_ON_FREELIST(dqp));

	mutex_destroy(&dqp->q_qlock);
	sv_destroy(&dqp->q_pinwait);

#ifdef XFS_DQUOT_TRACE
	if (dqp->q_trace)
	     ktrace_free(dqp->q_trace);
	dqp->q_trace = NULL;
#endif
	kmem_zone_free(xfs_Gqm->qm_dqzone, dqp);
	atomic_dec(&xfs_Gqm->qm_totaldquots);
}
コード例 #3
0
void
dm_remove_fsys_entry(
	vfs_t		*vfsp)
{
	dm_fsreg_t	**fsrpp;
	dm_fsreg_t	*fsrp;
	int		lc;			/* lock cookie */

	/* Find the filesystem referenced by the vfsp's fsid_t and dequeue
	   it after verifying that the fr_state shows a filesystem that is
	   either mounting or unmounted.
	*/

	lc = mutex_spinlock(&dm_reg_lock);

	fsrpp = &dm_registers;
	while ((fsrp = *fsrpp) != NULL) {
		if (!bcmp(&fsrp->fr_fsid, vfsp->vfs_altfsid, sizeof(fsrp->fr_fsid)))
			break;
		fsrpp = &fsrp->fr_next;
	}
	if (fsrp == NULL) {
		mutex_spinunlock(&dm_reg_lock, lc);
		panic("dm_remove_fsys_entry: can't find DMAPI fsrp for "
			"vfsp %p\n", vfsp);
	}

	nested_spinlock(&fsrp->fr_lock);

	/* Verify that it makes sense to remove this entry. */

	if (fsrp->fr_state != DM_STATE_MOUNTING &&
	    fsrp->fr_state != DM_STATE_UNMOUNTED) {
		nested_spinunlock(&fsrp->fr_lock);
		mutex_spinunlock(&dm_reg_lock, lc);
		panic("dm_remove_fsys_entry: DMAPI sequence error: old state "
			"%d, fsrp %p\n", fsrp->fr_state, fsrp);
	}

	*fsrpp = fsrp->fr_next;
	dm_fsys_cnt--;

	nested_spinunlock(&dm_reg_lock);

	/* Since the filesystem is about to finish unmounting, we must be sure
	   that no vnodes are being referenced within the filesystem before we
	   let this event thread continue.  If the filesystem is currently in
	   state DM_STATE_MOUNTING, then we know by definition that there can't
	   be any references.  If the filesystem is DM_STATE_UNMOUNTED, then
	   any application threads referencing handles with DM_NO_TOKEN should
	   have already been awakened by dm_change_fsys_entry and should be
	   long gone by now.  Just in case they haven't yet left, sleep here
	   until they are really gone.
	*/

	while (fsrp->fr_hdlcnt) {
		fsrp->fr_unmount++;
		sv_wait(&fsrp->fr_queue, 1, &fsrp->fr_lock, lc);
		lc = mutex_spinlock(&fsrp->fr_lock);
		fsrp->fr_unmount--;
	}
	mutex_spinunlock(&fsrp->fr_lock, lc);

	/* Release all memory. */

#ifdef CONFIG_PROC_FS
	{
	char buf[100];
	sprintf(buf, DMAPI_DBG_PROCFS "/fsreg/0x%p", fsrp);
	remove_proc_entry(buf, NULL);
	}
#endif
	sv_destroy(&fsrp->fr_dispq);
	sv_destroy(&fsrp->fr_queue);
	spinlock_destroy(&fsrp->fr_lock);
	kmem_free(fsrp->fr_msg, fsrp->fr_msgsize);
	kmem_free(fsrp, sizeof(*fsrp));
}
コード例 #4
0
int
dm_add_fsys_entry(
	vfs_t		*vfsp,
	dm_tokevent_t	*tevp)
{
	dm_fsreg_t	*fsrp;
	int		msgsize;
	void		*msg;
	int		lc;			/* lock cookie */

	/* Allocate and initialize a dm_fsreg_t structure for the filesystem. */

	msgsize = tevp->te_allocsize - offsetof(dm_tokevent_t, te_event);
	msg = kmem_alloc(msgsize, KM_SLEEP);
	bcopy(&tevp->te_event, msg, msgsize);

	fsrp = kmem_zalloc(sizeof(*fsrp), KM_SLEEP);
	fsrp->fr_vfsp = vfsp;
	fsrp->fr_tevp = tevp;
	fsrp->fr_fsid = *vfsp->vfs_altfsid;
	fsrp->fr_msg = msg;
	fsrp->fr_msgsize = msgsize;
	fsrp->fr_state = DM_STATE_MOUNTING;
	sv_init(&fsrp->fr_dispq, SV_DEFAULT, "fr_dispq");
	sv_init(&fsrp->fr_queue, SV_DEFAULT, "fr_queue");
	spinlock_init(&fsrp->fr_lock, "fr_lock");

	/* If no other mounted DMAPI filesystem already has this same
	   fsid_t, then add this filesystem to the list.
	*/

	lc = mutex_spinlock(&dm_reg_lock);

	if (!dm_find_fsreg(vfsp->vfs_altfsid)) {
		fsrp->fr_next = dm_registers;
		dm_registers = fsrp;
		dm_fsys_cnt++;
#ifdef CONFIG_PROC_FS
		{
		char buf[100];
		struct proc_dir_entry *entry;

		sprintf(buf, DMAPI_DBG_PROCFS "/fsreg/0x%p", fsrp);
		entry = create_proc_read_entry(buf, 0, 0, fsreg_read_pfs, fsrp);
		entry->owner = THIS_MODULE;
		}
#endif
		mutex_spinunlock(&dm_reg_lock, lc);
		return(0);
	}

	/* A fsid_t collision occurred, so prevent this new filesystem from
	   mounting.
	*/

	mutex_spinunlock(&dm_reg_lock, lc);

	sv_destroy(&fsrp->fr_dispq);
	sv_destroy(&fsrp->fr_queue);
	spinlock_destroy(&fsrp->fr_lock);
	kmem_free(fsrp->fr_msg, fsrp->fr_msgsize);
	kmem_free(fsrp, sizeof(*fsrp));
	return(EBUSY);
}
コード例 #5
0
ファイル: dmapi_session.c プロジェクト: crossmeta/sgi
void
dm_uninit(void)
{
	int lc;
	dm_session_t *s;

	static void unlink_session( dm_session_t *s);

	if(dm_sessions_active) {
		printk(KERN_ERR "xfs dmapi is being unloaded while there are active sessions\n");

		while( dm_sessions_active ) {
			/* this for-loop mostly from dm_find_session_and_lock() */
			for (;;) {
				s = dm_sessions;
				lc = mutex_spinlock(&dm_session_lock);

				if (nested_spintrylock(&s->sn_qlock)) {
					nested_spinunlock(&dm_session_lock);
					break; /* success */
				}
				mutex_spinunlock(&dm_session_lock, lc);
			}/* for */

			/* this cleanup stuff mostly from dm_destroy_session() */
			if (s->sn_newq.eq_head || s->sn_readercnt || s->sn_delq.eq_head) {
				/* busy session */
				printk(KERN_ERR "   sessid %d (%s) is busy\n", s->sn_sessid, s->sn_info);
				nested_spinunlock(&s->sn_qlock);
				mutex_spinunlock(&dm_session_lock, lc);
				break; /* do not continue */
			}
			else {
				unlink_session(s);
				nested_spinunlock(&s->sn_qlock);
				mutex_spinunlock(&dm_session_lock, lc);
				dm_clear_fsreg(s);
				spinlock_destroy(&s->sn_qlock);
				sv_destroy(&s->sn_readerq);
				sv_destroy(&s->sn_writerq);
				kmem_free(s, sizeof *s);
				printk(KERN_ERR "   sessid %d (%s) destroyed\n", s->sn_sessid, s->sn_info);
			}
		}/*while*/
	}

	/* If any of these are still locked, then we should not allow
	 * an unload.
	 * XXX can any of these be held when no sessions exist?
	 *   - yes, dm_session_lock is acquired prior to adding a new session
	 *   - no, dm_token_lock is only held when a session is locked
	 *   - ?, dm_reg_lock (XXX lookup this one)
	 */

	if( spin_is_locked(&dm_session_lock) )
		printk(KERN_ERR "xfs dmapi is being unloaded while dm_session_lock is held\n");
	if( spin_is_locked(&dm_token_lock) )
		printk(KERN_ERR "xfs dmapi is being unloaded while dm_token_lock is held\n");
	if( spin_is_locked(&dm_reg_lock) )
		printk(KERN_ERR "xfs dmapi is being unloaded while dm_reg_lock is held\n");

	spinlock_destroy(&dm_session_lock);
	spinlock_destroy(&dm_token_lock);
	spinlock_destroy(&dm_reg_lock);
}