/* * Add process to the pid table and the task table. * This routine assumes pid and task data has been already initialized. */ void p_add(struct proc *p) { list_insert(&pid_table[IDHASH(p->p_pid)], &p->p_pid_link); list_insert(&task_table[IDHASH(p->p_task)], &p->p_task_link); }
/* * Add process to the pid table and the task table. * This routine assumes pid and task data has been already initialized. */ void proc_add(struct proc *p) { list_insert(&pid_hash[IDHASH(p->p_pid)], &p->p_pid_link); list_insert(&task_hash[IDHASH(p->p_task)], &p->p_task_link); }
/* glock: LOCKED */ inodedata* write_find_inodedata(uint32_t inode) { uint32_t idh = IDHASH(inode); inodedata *id; for (id=idhash[idh] ; id ; id=id->next) { if (id->inode == inode) { return id; } } return NULL; }
/* * Locate a process group by number */ struct pgrp * pg_find(pid_t pgid) { list_t head, n; struct pgrp *g = NULL; head = &pgid_table[IDHASH(pgid)]; n = list_first(head); while (n != head) { g = list_entry(n, struct pgrp, pg_link); if (g->pg_pgid == pgid) return g; n = list_next(n); } return NULL; }
/* * Locate a process by number */ struct proc * p_find(pid_t pid) { list_t head, n; struct proc *p = NULL; head = &pid_table[IDHASH(pid)]; n = list_first(head); while (n != head) { p = list_entry(n, struct proc, p_pid_link); if (p->p_pid == pid) return p; n = list_next(n); } return NULL; }
/* * Find process by task ID. */ struct proc * task_to_proc(task_t task) { list_t head, n; struct proc *p = NULL; head = &task_table[IDHASH(task)]; n = list_first(head); while (n != head) { p = list_entry(n, struct proc, p_task_link); if (p->p_task == task) return p; n = list_next(n); } return NULL; }
/* glock: LOCKED */ void write_free_inodedata(inodedata *fid) {//释放inodedata uint32_t idh = IDHASH(fid->inode); inodedata *id,**idp; idp = &(idhash[idh]); while ((id=*idp)) { if (id==fid) { *idp = id->next; pthread_cond_destroy(&(id->flushcond)); pthread_cond_destroy(&(id->writecond)); pthread_cond_destroy(&(id->cachecond)); close(id->pipe[0]); close(id->pipe[1]); free(id); return; } idp = &(id->next); } }
/* glock: LOCKED */ inodedata* write_get_inodedata(uint32_t inode) { uint32_t idh = IDHASH(inode); inodedata *id; int pfd[2]; for (id=idhash[idh] ; id ; id=id->next) { if (id->inode == inode) { return id; } } if (pipe(pfd)<0) { syslog(LOG_WARNING,"pipe error: %m"); return NULL; } id = malloc(sizeof(inodedata)); id->inode = inode; id->cacheblocks = 0; id->maxfleng = 0; id->status = 0; id->trycnt = 0; id->pipe[0] = pfd[0]; id->pipe[1] = pfd[1]; id->datachainhead = NULL; id->datachaintail = NULL; id->waitingworker = 0; id->inqueue = 0; id->flushwaiting = 0; id->writewaiting = 0; id->cachewaiting = 0; id->lcnt = 0; pthread_cond_init(&(id->flushcond),NULL); pthread_cond_init(&(id->writecond),NULL); pthread_cond_init(&(id->cachecond),NULL); id->next = idhash[idh]; idhash[idh] = id; return id; }
/* * Add process group to table. * This routine assumes pgid has been already initialized. */ void pg_add(struct pgrp *pgrp) { list_insert(&pgid_table[IDHASH(pgrp->pg_pgid)], &pgrp->pg_link); }