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; }
struct nvclock *nvclock_alloc(void) { struct nvclock *clock; clock = umem_cache_alloc(vclock_cache, 0); if (clock) memset(clock, 0, sizeof(struct nvclock)); return clock; }
struct pipeline *pipestage_to_pipeline(struct pipestage *stage) { struct pipeline *line; line = umem_cache_alloc(pipeline_cache, 0); ASSERT(line); list_create(&line->pipe, sizeof(struct pipestage), offsetof(struct pipestage, pipe)); pipeline_append(line, stage); return line; }
struct pipestage *pipestage_alloc(char *name) { struct pipestage *pipe; int i; pipe = umem_cache_alloc(pipestage_cache, 0); ASSERT(pipe); pipe->stage = &nop; for (i = 0; stages[i].name; i++) { if (!strcmp(name, stages[i].name)) { pipe->stage = &stages[i]; break; } } return pipe; }
struct objstore_vol *objstore_vol_create(struct objstore *vg, const char *path, enum objstore_mode mode) { struct objstore_vol *s; int ret; if (!backend->def->vol_ops->create) return ERR_PTR(ENOTSUP); s = umem_cache_alloc(vol_cache, 0); if (!s) return ERR_PTR(ENOMEM); s->def = backend->def; s->mode = mode; s->path = strdup(path); if (!s->path) { ret = ENOMEM; goto err; } ret = s->def->vol_ops->create(s); if (ret) goto err_path; vg_add_vol(vg, s); return s; err_path: free((char *) s->path); err: umem_cache_free(vol_cache, s); return ERR_PTR(ret); }
/* * Entry: a single line without the NEWLINE * Return: the package entry with the path determined. */ static pkgentry_t * parse_line(char *buf, int blen, boolean_t full) { char *t; pkgentry_t *p; int nfields; p = umem_cache_alloc(ecache, UMEM_NOFAIL); buf = p->line = mystrcpy(buf, blen + 1); p->len = blen + 1; t = buf; while (!IS_ST0Q[(unsigned char)*t++]) ; p->pathlen = t - buf - 1; if (p->pathlen == 0 || p->pathlen >= PATH_MAX) { progerr("bad entry read in contents file"); logerr("pathname: Unknown"); logerr("problem: unable to read pathname field"); if (one_shot) exit(2); } if (t[-1] == '=') while (!IS_ST0[(unsigned char)*t++]) ; /* Partial as found in the "-" entries for log */ if (t[-1] == '\0') { if (full) goto badline; p->pkgoff = -1; return (p); } switch (*t) { case '?': nfields = 0; break; case 's': case 'l': /* Fields: class */ nfields = 1; break; case 'p': case 'x': case 'd': /* class mode owner group */ nfields = 4; break; case 'f': case 'e': case 'v': /* class mode owner group size csum time */ nfields = 7; break; case 'c': case 'b': /* class major minor mode owner group */ nfields = 6; break; default: progerr("bad entry read in contents file"); logerr("pathname: %.*s", p->pathlen, p->line); logerr("problem: unknown ftype"); freeentry(p); if (one_shot) exit(2); return (NULL); } p->pkgoff = t + fieldoff(t, nfields + 1) - buf; if (p->line[p->pkgoff] != '\0' || p->pkgoff == p->len - 1) return (p); badline: progerr(gettext("bad entry read in contents file")); logerr(gettext("pathname: Unknown")); logerr(gettext("problem: unknown ftype")); freeentry(p); if (one_shot) exit(2); return (NULL); }