static Path _path_alloc (Npsrv *srv, char *s, int len) { PathPool pp = srv->srvaux; Path path; xpthread_mutex_lock (&pp->lock); path = hash_find (pp->hash, s); if (path) { path_incref (path); free (s); } else { NP_ASSERT (errno == 0); if (!(path = malloc (sizeof (*path)))) { free (s); goto error; } path->refcount = 1; pthread_mutex_init (&path->lock, NULL); path->s = s; path->len = len; path->ioctx = NULL; if (!hash_insert (pp->hash, path->s, path)) { NP_ASSERT (errno == ENOMEM); goto error; } } xpthread_mutex_unlock (&pp->lock); return path; error: xpthread_mutex_unlock (&pp->lock); if (path) _path_free (path); return NULL; }
/* Clone newfid->aux from fid->aux. */ Fid * diod_fidclone (Npfid *newfid, Npfid *fid) { Fid *f = fid->aux; Fid *nf = malloc (sizeof (*f)); NP_ASSERT (newfid->aux == NULL); if (nf) { nf->flags = f->flags; nf->ioctx = NULL; nf->path = path_incref (f->path); } newfid->aux = nf; return nf; }