Subject: Re: process list within p_emuldata
To: Emmanuel Dreyfus <manu@netbsd.org>
From: Chuck Silvers <chuq@chuq.com>
List: tech-kern
Date: 07/04/2002 16:14:32
hi,

I was thinking you'd do this:

struct irix_sharegroup {
	LIST_HEAD(, irix_emuldata) isg_list;
	struct lock *isg_lock;
}

struct irix_emuldata {
	LIST_ENTRY(irix_emuldata) ied_list;
	struct irix_sharegroup *ied_shgrp;
	struct proc *ied_proc;
	...
};


irix_foo()
{
	struct proc *p;
	struct irix_emuldata *ied, *cied;
	struct irix_sharegroup *isg;
	...

	ied = p->p_emuldata;
	isg = ied->ied_shgrp;
	lockmgr(&isg->isg_lock, LK_EXCLUSIVE, NULL);
	LIST_FOREACH(cied, &isg->isg_list, ied_list) {
		... do stuff to cied->ied_proc ...
	}
	lockmgr(&isg->isg_lock, LK_RELEASE, NULL);
}

then ied->ied_shgrp points to the same irix_sharegroup structure for
each proc in the share group.

you can't put the list head directly in any irix_emuldata structure,
since you don't want the list to go away when any one of the procs exits,
only when the last proc in the share group exits.  you'll have to allocate
it separately as needed (and free it when the last proc in the group exits).

-Chuck


On Thu, Jul 04, 2002 at 11:33:13PM +0200, Emmanuel Dreyfus wrote:
> While it's more a C language question than a kernel question, I don't see a
> better place for this question.
> 
> In order to emulate IRIX share groups, I'd like to maintain an emulation
> specific process list:
> 
> struct irix_emuldata {
>         LIST_ENTRY(proc) ied_list;
> }
> 
> For an IRIX process, p->p_emuldata points to a struct irix_emuldata. Hence I
> can reach the list link like this:
> 
> (struct irix_emuldata *)(p->p_emuldata)->ied_list
> 
> Now I want ot use LIST_FOREACH on this...
> 
> struct proc *pp;
> LIST_HEAD(isg_head, proc) isg_head; 
> LIST_FOREACH(pp, &isg_head, p_emuldata->ied_list)
> 
> This won't work because I am dereferencing a (void *) pointer. 
> 
> Things like this won't work either:
> LIST_FOREACH(pp, &isg_head, (struct irix_emuldata *)p_emuldata->ied_list)
> The macro expands into 
>  pp = (pp->((struct irix_emuldata *)p_emuldata)->ie_list.le_next))
> and I just get a "parse error before `('"
> 
> Now the questions: how should I do it? Is there a mysterious C syntax to get
> the work done? If not, should I define custom list operation macros? Or should
> I do a struct irix_emuldata list, with a pointer to struct proc in struct
> irix_emuldata so that I can get the struct proc?
> 
> -- 
> Emmanuel Dreyfus
> manu@netbsd.org