1 /* Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
2 * Portions Copyright © 1997-1999 Vita Nuova Limited
3 * Portions Copyright © 2000-2007 Vita Nuova Holdings Limited
5 * Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
7 * Modified for the Akaros operating system:
8 * Copyright (c) 2013-2014 The Regents of the University of California
9 * Copyright (c) 2013-2015 Google Inc.
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 /* TODO: (ID) need a unique ID service. These will loop around... */
46 #define NEXT_ID(x) (__sync_add_and_fetch(&(x), 1))
48 void closepgrp(struct pgrp *p)
50 struct mhead **h, **e, *f, *next;
55 e = &p->mnthash[MNTHASH];
56 for (h = p->mnthash; h < e; h++) {
57 for (f = *h; f; f = next) {
73 static void freepgrp(struct kref *k)
75 struct pgrp *p = container_of(k, struct pgrp, ref);
79 struct pgrp *newpgrp(void)
83 p = kzmalloc(sizeof(struct pgrp), MEM_WAIT);
84 kref_init(&p->ref, freepgrp, 1);
85 p->pgrpid = NEXT_ID(pgrpid);
87 qlock_init(&p->debug);
93 void pgrpinsert(struct mount **order, struct mount *m)
102 for (f = *order; f; f = f->order) {
103 if (m->mountid < f->mountid) {
114 * pgrpcpy MUST preserve the mountid allocation order of the parent group
116 void pgrpcpy(struct pgrp *to, struct pgrp *from)
120 struct mount *n, *m, **link, *order;
121 struct mhead *f, **tom, **l, *mh;
130 for (i = 0; i < MNTHASH; i++) {
132 for (f = from->mnthash[i]; f; f = f->hash) {
138 mh = newmhead(f->from);
140 error(ENOMEM, ERROR_FIXME);
144 for (m = f->mount; m; m = m->next) {
145 n = newmount(mh, m->to, m->mflag, m->spec);
147 pgrpinsert(&order, m);
156 * Allocate mount ids in the same sequence as the parent group
158 /* should probably protect with a spinlock and be done with it */
159 for (m = order; m; m = m->order) {
160 m->copy->mountid = NEXT_ID(mountid);
163 to->progmode = from->progmode;
164 to->slash = cclone(from->slash);
165 to->dot = cclone(from->dot);
166 to->nodevs = from->nodevs;
172 struct mount *newmount(struct mhead *mh, struct chan *to, int flag, char *spec)
176 m = kzmalloc(sizeof(struct mount), 0);
180 m->mountid = NEXT_ID(mountid);
183 kstrdup(&m->spec, spec);
188 void mountfree(struct mount *m)
203 almost certainly not needed.void resrcwait(char *reason)
212 up->psstate = reason;
213 printd("%s\n", reason);
216 kthread_usleep(300 * 1000);
221 /* TODO: We don't have any alloc / initializer methods for skeyset or signerkey
222 * yet. When we do, use these releases for their kref_init. */
223 static void __sigs_release(struct kref *kref)
225 struct skeyset *s = container_of(kref, struct skeyset, ref);
227 for (i = 0; i < s->nkey; i++)
228 freeskey(s->keys[i]);
232 void closesigs(struct skeyset *s)
239 static void __key_release(struct kref *kref)
241 struct signerkey *key = container_of(kref, struct signerkey, ref);
243 (*key->pkfree) (key->pk);
247 void freeskey(struct signerkey *key)