/** * call_usermodehelper_keys - start a usermode application * @path: pathname for the application * @argv: null-terminated argument list * @envp: null-terminated environment list * @session_keyring: session keyring for process (NULL for an empty keyring) * @wait: wait for the application to finish and return status. * * Runs a user-space application. The application is started * asynchronously if wait is not set, and runs as a child of keventd. * (ie. it runs with full root capabilities). * * Must be called from process context. Returns a negative error code * if program was not execed successfully, or 0. */ int call_usermodehelper_keys(char *path, char **argv, char **envp, struct key *session_keyring, int wait) { DECLARE_COMPLETION(done); struct subprocess_info sub_info = { .complete = &done, .path = path, .argv = argv, .envp = envp, .ring = session_keyring, .wait = wait, .retval = 0, }; DECLARE_WORK(work, __call_usermodehelper, &sub_info); OSA_REGISTER_SPINLOCK(&done.wait.lock, "wait_queue_head_t->lock", 23); if (!khelper_wq) return -EBUSY; if (path[0] == '\0') return 0; queue_work(khelper_wq, &work); wait_for_completion(&done); return sub_info.retval; } EXPORT_SYMBOL(call_usermodehelper_keys); void __init usermodehelper_init(void) { khelper_wq = create_singlethread_workqueue("khelper"); BUG_ON(!khelper_wq); }
/** * init_module() * load the module * create new kernel threads */ int init_krbtree_module( unsigned long nThreadCount, unsigned long nTargetValue, int balance, int max) { int i; gnAwakeCount = 0; gnThreadsComplete = 0; gnThreadCount = nThreadCount; gnTargetValue = nTargetValue; insert_delete_balance = balance; max_val = max; // Don't really plan to use this modulate_priority = 0; spin_lock_init( &gKrbtreeLock ); OSA_REGISTER_SPINLOCK(&gKrbtreeLock, "gKrbtreeLock", 13); printk( KERN_ERR "spinlock address: 0x%8x", (unsigned int) &gKrbtreeLock); sema_init( &sem, 1 ); sema_init( &semdone, 1 ); sema_init( &scsembarrier, 1 ); for( i=0; i<gnThreadCount; i++ ) { #ifdef KTHCBM_VERBOSE printk( KERN_ERR "Spawning thread %d\n", i ); #endif gvThreads[i] = kthread_run(krbtree_thread_proc, (void *)i, "krbtree_thread_proc"); } return 0; }
/* * initialise the semaphore */ void fastcall init_rwsem(struct rw_semaphore *sem) { sem->activity = 0; spin_lock_init(&sem->wait_lock); OSA_REGISTER_SPINLOCK(&sem->wait_lock, "rw_semaphore->wait_lock", 23); INIT_LIST_HEAD(&sem->wait_list); #if RWSEM_DEBUG sem->debug = 0; #endif }
mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn, mempool_free_t *free_fn, void *pool_data, int node_id) { mempool_t *pool; pool = kmalloc_node(sizeof(*pool), GFP_KERNEL, node_id); if (!pool) return NULL; memset(pool, 0, sizeof(*pool)); pool->elements = kmalloc_node(min_nr * sizeof(void *), GFP_KERNEL, node_id); if (!pool->elements) { kfree(pool); return NULL; } spin_lock_init(&pool->lock); OSA_REGISTER_SPINLOCK(&pool->lock, "mempool_t->lock", 15); pool->min_nr = min_nr; pool->pool_data = pool_data; init_waitqueue_head(&pool->wait); pool->alloc = alloc_fn; pool->free = free_fn; /* * First pre-allocate the guaranteed number of buffers. */ while (pool->curr_nr < pool->min_nr) { void *element; element = pool->alloc(GFP_KERNEL, pool->pool_data); if (unlikely(!element)) { free_pool(pool); return NULL; } add_element(pool, element); } return pool; }