Re: explanation of some pieces of code?

2010-02-02 Thread Jack Z
Hi Mike,

Thank you so much for your help!

Regards,
Jack

On Jan 29, 11:56 am, Mike Christie  wrote:
> On 01/27/2010 02:41 AM, Jack Z wrote:
>
>
>
> > Hi group,
>
> > I'm looking at the following code and come up with some questions
>
> > In this function,
>
> > static void iscsi_sw_tcp_write_space(struct sock *sk)
> > {
> >    struct iscsi_conn *conn = (struct iscsi_conn*)sk->sk_user_data;
> >    struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
> >    struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
>
> >    tcp_sw_conn->old_write_space(sk);
> >    ISCSI_SW_TCP_DBG(conn, "iscsi_write_space\n");
> >    iscsi_conn_queue_work(conn);
> > }
>
> > tcp_sw_conn->old_write_space() is called. And in the following
> > function, tcp_sw_conn->old_write_space() seems to be assigned to the
> > original value of "sk->sk_write_space"...
>
> > Could anyone show me which function does "sk->sk_write_space" point to
> > before it is assigned to "iscsi_sw_tcp_write_space;" later in the same
> > function?
>
> I believe it is sk_stream_write_space. For tcp v4 sockets see
> tcp_v4_init_sock.
>
>
>
>
>
> > static void iscsi_sw_tcp_conn_set_callbacks(struct iscsi_conn *conn)
> > {
> >    struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
> >    struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
> >    struct sock *sk = tcp_sw_conn->sock->sk;
>
> >    /* assign new callbacks */
> >    ..
> >    tcp_sw_conn->old_write_space = sk->sk_write_space;
>
> > // assignment of "sk->sk_write_space" but after its value was assigned
> > to "tcp_sw_conn->old_write_space"...
>
> >    sk->sk_write_space = iscsi_sw_tcp_write_space;
> >    write_unlock_bh(&sk->sk_callback_lock);
> > }
>
> > Another question is: Now that we have "sk->sk_write_space =
> > iscsi_sw_tcp_write_space" why do we have to call "tcp_sw_conn-
> >> old_write_space(sk);" in "iscsi_sw_tcp_write_space()"? Which function
>
> We override it so the iscsi layer can start up its send code if needed,
> and we call the old tcp function so it can do its processing (possibly
> wake up threads waiting for space to open up).
>
>
>
> > is actually called when we do "tcp_sw_conn->old_write_space(sk);"?
>
> > And also in fuction "static void iscsi_sw_tcp_write_space(struct sock
> > *sk)", the last instruction is "iscsi_conn_queue_work(conn);". When I
> > trace down I found
>
> > inline void iscsi_conn_queue_work(struct iscsi_conn *conn)
> > {
> >    struct Scsi_Host *shost = conn->session->host;
> >    struct iscsi_host *ihost = shost_priv(shost);
>
> >    if (ihost->workq)
> >            queue_work(ihost->workq,&conn->xmitwork);
> > }
>
> > But I couldn't find more details about "queue_work(ihost->workq,&conn-
> >> xmitwork);" in the source code (ver 2.0.871). Could anyone maybe
> > point me to the code of "queu_work"?
>
> It is in the kernel source. Get the kernel and look at
> kernel/workqueue.c. It basically wakes up a thread and has it process
> some work. For iscsi it wakes up our xmit thread in case it had slept
> due to there not being any write space.

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



Re: explanation of some pieces of code?

2010-01-29 Thread Mike Christie

On 01/27/2010 02:41 AM, Jack Z wrote:

Hi group,

I'm looking at the following code and come up with some questions

In this function,

static void iscsi_sw_tcp_write_space(struct sock *sk)
{
struct iscsi_conn *conn = (struct iscsi_conn*)sk->sk_user_data;
struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;

tcp_sw_conn->old_write_space(sk);
ISCSI_SW_TCP_DBG(conn, "iscsi_write_space\n");
iscsi_conn_queue_work(conn);
}

tcp_sw_conn->old_write_space() is called. And in the following
function, tcp_sw_conn->old_write_space() seems to be assigned to the
original value of "sk->sk_write_space"...

Could anyone show me which function does "sk->sk_write_space" point to
before it is assigned to "iscsi_sw_tcp_write_space;" later in the same
function?


I believe it is sk_stream_write_space. For tcp v4 sockets see
tcp_v4_init_sock.




static void iscsi_sw_tcp_conn_set_callbacks(struct iscsi_conn *conn)
{
struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
struct sock *sk = tcp_sw_conn->sock->sk;

/* assign new callbacks */
..
tcp_sw_conn->old_write_space = sk->sk_write_space;

// assignment of "sk->sk_write_space" but after its value was assigned
to "tcp_sw_conn->old_write_space"...

sk->sk_write_space = iscsi_sw_tcp_write_space;
write_unlock_bh(&sk->sk_callback_lock);
}

Another question is: Now that we have "sk->sk_write_space =
iscsi_sw_tcp_write_space" why do we have to call "tcp_sw_conn-

old_write_space(sk);" in "iscsi_sw_tcp_write_space()"? Which function


We override it so the iscsi layer can start up its send code if needed, 
and we call the old tcp function so it can do its processing (possibly 
wake up threads waiting for space to open up).




is actually called when we do "tcp_sw_conn->old_write_space(sk);"?

And also in fuction "static void iscsi_sw_tcp_write_space(struct sock
*sk)", the last instruction is "iscsi_conn_queue_work(conn);". When I
trace down I found

inline void iscsi_conn_queue_work(struct iscsi_conn *conn)
{
struct Scsi_Host *shost = conn->session->host;
struct iscsi_host *ihost = shost_priv(shost);

if (ihost->workq)
queue_work(ihost->workq,&conn->xmitwork);
}

But I couldn't find more details about "queue_work(ihost->workq,&conn-

xmitwork);" in the source code (ver 2.0.871). Could anyone maybe

point me to the code of "queu_work"?


It is in the kernel source. Get the kernel and look at 
kernel/workqueue.c. It basically wakes up a thread and has it process 
some work. For iscsi it wakes up our xmit thread in case it had slept 
due to there not being any write space.


--
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



RE: explanation of some pieces of code?

2010-01-28 Thread Lin, Johnny
How to quit this group?

-Original Message-
From: open-iscsi@googlegroups.com [mailto:open-is...@googlegroups.com] On 
Behalf Of Jack Z
Sent: 2010年1月28日 15:53
To: open-iscsi
Subject: Re: explanation of some pieces of code?

Hi Ulrich,

Thanks for your reply.

That for sure increased my understanding about the "hook"s a lot.

I think what I really want to know is the latter one, i.e. " what the
routine is supposed to do?". To reorganize the question, what is sk-
>sk_write_space usually supposed to do?



On Jan 28, 12:16 am, "Ulrich Windl"  wrote:
> On 27 Jan 2010 at 9:59, Jack Z wrote:
>
> > Hi Ulrich,
>
> > Thanks for your comment.
>
> > So by "implement polymorphism", do you mean sk->sw_write_space is
> > platform dependent or it does different jobs when called from
> > different functions in the open-iscsi code?
>
> Hi,
>
> I mean: If you call a routine indirect through a function pointer, the
> reason is that you want to call different routines at runtime.
> Otherwise this is unnecessary and shows poor performance.
>
> So if calling different routines through a pointer, there must exist a
> common expectation what the code being called does (i.e. the common
> subset of expectations that every possible routine fulfills).
>
> [If you want to look it up somewhere else, try "dynamic binding",
> "polymorphism" or Bertrand Meyers "Object-Oriented software
> construction"]
>
> Therefore you should not ask which specific routine will be called
> through the pointer at some moment in time, but what the routine
> (whatever it is) is expected to do.
>
> (I know it's theoretical, but just introducing "hooks" (as function
> pointers are frequently called) can be a source of errors unless the
> semantics of such a hook are well defined).
>
> Now: Do you really want to know which specific routine is called, or do
> you want to know what the routine is supposed to do?
>
> [...]
>
> Regards,
> Ulrich

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



Re: explanation of some pieces of code?

2010-01-27 Thread Jack Z
Hi Ulrich,

Thanks for your reply.

That for sure increased my understanding about the "hook"s a lot.

I think what I really want to know is the latter one, i.e. " what the
routine is supposed to do?". To reorganize the question, what is sk-
>sk_write_space usually supposed to do?



On Jan 28, 12:16 am, "Ulrich Windl"  wrote:
> On 27 Jan 2010 at 9:59, Jack Z wrote:
>
> > Hi Ulrich,
>
> > Thanks for your comment.
>
> > So by "implement polymorphism", do you mean sk->sw_write_space is
> > platform dependent or it does different jobs when called from
> > different functions in the open-iscsi code?
>
> Hi,
>
> I mean: If you call a routine indirect through a function pointer, the
> reason is that you want to call different routines at runtime.
> Otherwise this is unnecessary and shows poor performance.
>
> So if calling different routines through a pointer, there must exist a
> common expectation what the code being called does (i.e. the common
> subset of expectations that every possible routine fulfills).
>
> [If you want to look it up somewhere else, try "dynamic binding",
> "polymorphism" or Bertrand Meyers "Object-Oriented software
> construction"]
>
> Therefore you should not ask which specific routine will be called
> through the pointer at some moment in time, but what the routine
> (whatever it is) is expected to do.
>
> (I know it's theoretical, but just introducing "hooks" (as function
> pointers are frequently called) can be a source of errors unless the
> semantics of such a hook are well defined).
>
> Now: Do you really want to know which specific routine is called, or do
> you want to know what the routine is supposed to do?
>
> [...]
>
> Regards,
> Ulrich

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



Re: explanation of some pieces of code?

2010-01-27 Thread Ulrich Windl
On 27 Jan 2010 at 9:59, Jack Z wrote:

> Hi Ulrich,
> 
> Thanks for your comment.
> 
> So by "implement polymorphism", do you mean sk->sw_write_space is
> platform dependent or it does different jobs when called from
> different functions in the open-iscsi code?

Hi,

I mean: If you call a routine indirect through a function pointer, the 
reason is that you want to call different routines at runtime. 
Otherwise this is unnecessary and shows poor performance.

So if calling different routines through a pointer, there must exist a 
common expectation what the code being called does (i.e. the common 
subset of expectations that every possible routine fulfills).

[If you want to look it up somewhere else, try "dynamic binding", 
"polymorphism" or Bertrand Meyers "Object-Oriented software 
construction"]

Therefore you should not ask which specific routine will be called 
through the pointer at some moment in time, but what the routine 
(whatever it is) is expected to do.

(I know it's theoretical, but just introducing "hooks" (as function 
pointers are frequently called) can be a source of errors unless the 
semantics of such a hook are well defined).

Now: Do you really want to know which specific routine is called, or do 
you want to know what the routine is supposed to do?

[...]

Regards,
Ulrich

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



Re: explanation of some pieces of code?

2010-01-27 Thread Jack Z
Hi Ulrich,

Thanks for your comment.

So by "implement polymorphism", do you mean sk->sw_write_space is
platform dependent or it does different jobs when called from
different functions in the open-iscsi code?

Thanks a lot!

Jack

On Jan 27, 2:10 am, "Ulrich Windl" 
wrote:
> On 27 Jan 2010 at 0:41, Jack Z wrote:
>
> [...]
>
> > Another question is: Now that we have "sk->sk_write_space =
> > iscsi_sw_tcp_write_space" why do we have to call "tcp_sw_conn-
> > >old_write_space(sk);" in "iscsi_sw_tcp_write_space()"? Which function
> > is actually called when we do "tcp_sw_conn->old_write_space(sk);"?
>
> [...]
>
> Hi,
>
> I cannot answer your question, but I'd like to place a remark on it:
> The way you ask is a very low level question (which function is
> actually called?). As this mechanism seems to implement polymorphism,
> the high-level question probably is: "What is the fuction call supposed
> to do (at that point)?"
>
> Sorry, but I had to say.
>
> Regards,
> Ulrich

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.



Re: explanation of some pieces of code?

2010-01-27 Thread Ulrich Windl
On 27 Jan 2010 at 0:41, Jack Z wrote:

[...]
> Another question is: Now that we have "sk->sk_write_space =
> iscsi_sw_tcp_write_space" why do we have to call "tcp_sw_conn-
> >old_write_space(sk);" in "iscsi_sw_tcp_write_space()"? Which function
> is actually called when we do "tcp_sw_conn->old_write_space(sk);"?
> 

[...]

Hi,

I cannot answer your question, but I'd like to place a remark on it: 
The way you ask is a very low level question (which function is 
actually called?). As this mechanism seems to implement polymorphism, 
the high-level question probably is: "What is the fuction call supposed 
to do (at that point)?"

Sorry, but I had to say.

Regards,
Ulrich

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.