All of lore.kernel.org
 help / color / mirror / Atom feed
* Use of list_head struct
@ 2016-06-17 10:11 Martin Houry
  2016-06-17 10:35 ` Pranay Srivastava
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Houry @ 2016-06-17 10:11 UTC (permalink / raw)
  To: kernelnewbies

Hello mailing list!
I've read some code in the NFS4.1 client. I have trouble to access
variables in a list_head.

So I have :
(include/linux/sunrpc/xprt.h line 168)
struct rpc_xprt{
    .
    .

    struct rpc_wait_queue pending; /* requests in flight */
    .
    .
}

==>

struct rpc_wait_queue {
    .
    struct list_head        tasks[RPC_NR_PRIORITY]; /* task queue for
each priority level */
    .
}

The struct "list_head" is a classical  linked list. But How do I know
the type of the struct in this list?
I can maybe guess the struct in it :

struct rpc_task {}

But how can I be certain that "struct list_head tasks" contains some
"struct rpc_task"?

I'm new here, thank you for your help!
Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Use of list_head struct
  2016-06-17 10:11 Use of list_head struct Martin Houry
@ 2016-06-17 10:35 ` Pranay Srivastava
  2016-06-20  7:57   ` Bogdan PRICOP
  0 siblings, 1 reply; 4+ messages in thread
From: Pranay Srivastava @ 2016-06-17 10:35 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Jun 17, 2016 at 3:41 PM, Martin Houry <martinhoury@gmail.com> wrote:
> Hello mailing list!
> I've read some code in the NFS4.1 client. I have trouble to access
> variables in a list_head.
>
> So I have :
> (include/linux/sunrpc/xprt.h line 168)
> struct rpc_xprt{
>     .
>     .
>
>     struct rpc_wait_queue pending; /* requests in flight */
>     .
>     .
> }
>
> ==>
>
> struct rpc_wait_queue {
>     .
>     struct list_head        tasks[RPC_NR_PRIORITY]; /* task queue for
> each priority level */
>     .
> }
>
> The struct "list_head" is a classical  linked list. But How do I know
> the type of the struct in this list?
> I can maybe guess the struct in it :
>
> struct rpc_task {}
>
> But how can I be certain that "struct list_head tasks" contains some
> "struct rpc_task"?

some magic value perhaps?

>
> I'm new here, thank you for your help!
> Martin
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
        ---P.K.S

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Use of list_head struct
  2016-06-17 10:35 ` Pranay Srivastava
@ 2016-06-20  7:57   ` Bogdan PRICOP
  2016-06-20 10:53     ` Robert P. J. Day
  0 siblings, 1 reply; 4+ messages in thread
From: Bogdan PRICOP @ 2016-06-20  7:57 UTC (permalink / raw)
  To: kernelnewbies

Bogdan PRICOP
----------------------------------------
Mobile: +353 86 075 3349
E-mail: pricopb at gmail.com
----------------------------------------

On 17 June 2016 at 11:35, Pranay Srivastava <pranjas@gmail.com> wrote:
>
> On Fri, Jun 17, 2016 at 3:41 PM, Martin Houry <martinhoury@gmail.com> wrote:
> > Hello mailing list!
> > I've read some code in the NFS4.1 client. I have trouble to access
> > variables in a list_head.
> >
> > So I have :
> > (include/linux/sunrpc/xprt.h line 168)
> > struct rpc_xprt{
> >     .
> >     .
> >
> >     struct rpc_wait_queue pending; /* requests in flight */
> >     .
> >     .
> > }
> >
> > ==>
> >
> > struct rpc_wait_queue {
> >     .
> >     struct list_head        tasks[RPC_NR_PRIORITY]; /* task queue for
> > each priority level */
> >     .
> > }
> >
> > The struct "list_head" is a classical  linked list. But How do I know
> > the type of the struct in this list?
> > I can maybe guess the struct in it :
> >
> > struct rpc_task {}
> >
> > But how can I be certain that "struct list_head tasks" contains some
> > "struct rpc_task"?
>
> some magic value perhaps?
>
> >
> > I'm new here, thank you for your help!
> > Martin
> >

Hi Martin,

I think the main idea behind Linux kernel implementation of the linked
list (struct list_head) is to work with any kind of items which need
to be linked.

Please have a look at the below links which explain the internals of
Linux kernel list and its usage:
https://isis.poly.edu/kulesh/stuff/src/klist/
http://www.makelinux.net/ldd3/chp-11-sect-5

Thanks,
Bogdan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Use of list_head struct
  2016-06-20  7:57   ` Bogdan PRICOP
@ 2016-06-20 10:53     ` Robert P. J. Day
  0 siblings, 0 replies; 4+ messages in thread
From: Robert P. J. Day @ 2016-06-20 10:53 UTC (permalink / raw)
  To: kernelnewbies

On Mon, 20 Jun 2016, Bogdan PRICOP wrote:

> Bogdan PRICOP
> ----------------------------------------
> Mobile: +353 86 075 3349
> E-mail: pricopb at gmail.com
> ----------------------------------------
>
> On 17 June 2016 at 11:35, Pranay Srivastava <pranjas@gmail.com> wrote:
> >
> > On Fri, Jun 17, 2016 at 3:41 PM, Martin Houry <martinhoury@gmail.com> wrote:
> > > Hello mailing list!
> > > I've read some code in the NFS4.1 client. I have trouble to access
> > > variables in a list_head.
> > >
> > > So I have :
> > > (include/linux/sunrpc/xprt.h line 168)
> > > struct rpc_xprt{
> > >     .
> > >     .
> > >
> > >     struct rpc_wait_queue pending; /* requests in flight */
> > >     .
> > >     .
> > > }
> > >
> > > ==>
> > >
> > > struct rpc_wait_queue {
> > >     .
> > >     struct list_head        tasks[RPC_NR_PRIORITY]; /* task queue for
> > > each priority level */
> > >     .
> > > }
> > >
> > > The struct "list_head" is a classical  linked list. But How do I know
> > > the type of the struct in this list?
> > > I can maybe guess the struct in it :
> > >
> > > struct rpc_task {}
> > >
> > > But how can I be certain that "struct list_head tasks" contains some
> > > "struct rpc_task"?
> >
> > some magic value perhaps?
> >
> > >
> > > I'm new here, thank you for your help!
> > > Martin
> > >
>
> Hi Martin,
>
> I think the main idea behind Linux kernel implementation of the linked
> list (struct list_head) is to work with any kind of items which need
> to be linked.
>
> Please have a look at the below links which explain the internals of
> Linux kernel list and its usage:
> https://isis.poly.edu/kulesh/stuff/src/klist/
> http://www.makelinux.net/ldd3/chp-11-sect-5

  i wrote a page on that way back here:

http://crashcourse.ca/introduction-linux-kernel-programming/intermission-lets-talk-about-linked-lists-and-containerof-free

as part of a kernel programming course that i *really* need to get
back to someday and update. *sigh*.

rday


-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-20 10:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-17 10:11 Use of list_head struct Martin Houry
2016-06-17 10:35 ` Pranay Srivastava
2016-06-20  7:57   ` Bogdan PRICOP
2016-06-20 10:53     ` Robert P. J. Day

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.