struct objstore *objstore_vg_create(const char *name, enum objstore_vg_type type) { struct objstore *vg; if (type != OS_VG_SIMPLE) return ERR_PTR(EINVAL); vg = umem_cache_alloc(vg_cache, 0); if (!vg) return ERR_PTR(ENOMEM); vg->name = strdup(name); if (!vg->name) { umem_cache_free(vg_cache, vg); return ERR_PTR(ENOMEM); } list_create(&vg->vols, sizeof(struct objstore_vol), offsetof(struct objstore_vol, vg_list)); mxinit(&vg->lock); mxlock(&vgs_lock); list_insert_tail(&vgs, vg); mxunlock(&vgs_lock); return vg; }
/*ARGSUSED*/ taskq_t * taskq_create(const char *name, int nthreads, int minalloc, int maxalloc, unsigned int flags) { taskq_t *tq; int t; tq = umem_zalloc(sizeof(taskq_t), 0); if (!tq) return NULL; if (flags & TASKQ_THREADS_CPU_PCT) { int pct; assert(nthreads >= 0); assert(nthreads <= taskq_cpupct_max_percent); pct = MIN(nthreads, taskq_cpupct_max_percent); pct = MAX(pct, 0); nthreads = (sysconf(_SC_NPROCESSORS_ONLN) * pct) / 100; nthreads = MAX(nthreads, 1); /* need at least 1 thread */ } else { assert(nthreads >= 1); } rwinit(&tq->tq_threadlock); mxinit(&tq->tq_lock); condinit(&tq->tq_dispatch_cv); condinit(&tq->tq_wait_cv); condinit(&tq->tq_maxalloc_cv); (void) strncpy(tq->tq_name, name, TASKQ_NAMELEN + 1); tq->tq_flags = flags | TASKQ_ACTIVE; tq->tq_active = nthreads; tq->tq_nthreads = nthreads; tq->tq_minalloc = minalloc; tq->tq_maxalloc = maxalloc; tq->tq_task.tqent_next = &tq->tq_task; tq->tq_task.tqent_prev = &tq->tq_task; tq->tq_threadlist = umem_alloc(nthreads * sizeof (pthread_t), UMEM_NOFAIL); if (flags & TASKQ_PREPOPULATE) { mxlock(&tq->tq_lock); while (minalloc-- > 0) task_free(tq, task_alloc(tq, UMEM_NOFAIL)); mxunlock(&tq->tq_lock); } for (t = 0; t < nthreads; t++) pthread_create(&tq->tq_threadlist[t], NULL, taskq_thread, tq); return (tq); }
int vg_init(void) { struct objstore *filecache; vg_cache = umem_cache_create("vg", sizeof(struct objstore), 0, NULL, NULL, NULL, NULL, NULL, 0); if (!vg_cache) return ENOMEM; mxinit(&vgs_lock); list_create(&vgs, sizeof(struct objstore), offsetof(struct objstore, node)); filecache = objstore_vg_create("file$", OS_VG_SIMPLE); if (IS_ERR(filecache)) { umem_cache_destroy(vg_cache); return PTR_ERR(filecache); } return 0; }