From: "Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: arun@linux.vnet.ibm.com, aliguori@us.ibm.com,
qemu-devel@nongnu.org, aneesh.kumar@linux.vnet.ibm.com
Subject: [Qemu-devel] Re: [v1 PATCH 3/3]: Convert v9fs_stat to threaded model.
Date: Wed, 16 Mar 2011 07:33:24 -0700 [thread overview]
Message-ID: <4D80CA34.6040205@linux.vnet.ibm.com> (raw)
In-Reply-To: <AANLkTik4fJtYJMr9y6CQOc8f+2tdAs4k+PJ-D+MSkv3_@mail.gmail.com>
On 3/16/2011 3:23 AM, Stefan Hajnoczi wrote:
> On Tue, Mar 15, 2011 at 10:39 AM, Arun R Bharadwaj
> <arun@linux.vnet.ibm.com> wrote:
>> -static void v9fs_stat_post_lstat(V9fsState *s, V9fsStatState *vs, int err)
>> +static void v9fs_stat_post_lstat(void *opaque)
>> {
>> - if (err == -1) {
>> - err = -errno;
>> + V9fsStatState *vs = (V9fsStatState *)opaque;
>
> No need to cast void* in C.
>
>> + if (vs->err == -1) {
>> + vs->err = -(vs->v9fs_errno);
>
> How about the thread worker function puts the -errno into a vs->ret field:
>
> static void v9fs_stat_do_lstat(V9fsRequest *request)
> {
> V9fsStatState *vs = container_of(request, V9fsStatState, request);
>
> vs->ret = v9fs_do_lstat(vs->s, &vs->fidp->fsmap.path, &vs->stbuf);
> if (vs->ret != 0) {
> vs->ret = -errno;
> }
> }
>
> Then v9fs_stat_post_lstat() can use vs->ret directly and does not need
> to juggle around the two fields, vs->err and vs->v9fs_errno.
>
>> goto out;
>> }
>>
>> - err = stat_to_v9stat(s, &vs->fidp->fsmap.path, &vs->stbuf, &vs->v9stat);
>> - if (err) {
>> + vs->err = stat_to_v9stat(vs->s, &vs->fidp->fsmap.path, &vs->stbuf, &vs->v9stat);
>
> This function can block in v9fs_do_readlink(). Needs to be done
> asynchronously to avoid blocking QEMU.
>
>> + if (vs->err) {
>> goto out;
>> }
>> vs->offset += pdu_marshal(vs->pdu, vs->offset, "wS", 0, &vs->v9stat);
>> - err = vs->offset;
>> + vs->err = vs->offset;
>>
>> out:
>> - complete_pdu(s, vs->pdu, err);
>> + complete_pdu(vs->s, vs->pdu, vs->err);
>> v9fs_stat_free(&vs->v9stat);
>> qemu_free(vs);
>> }
>>
>> +static void v9fs_stat_do_lstat(V9fsRequest *request)
>> +{
>> + V9fsStatState *vs = container_of(request, V9fsStatState, request);
>
> Nice. Could container_of() be used for v9fs_post_lstat() too? I'm
> suggesting making post op functions take the V9fsRequest* instead of a
> void* opaque pointer.
>
>> +
>> + vs->err = v9fs_do_lstat(vs->s, &vs->fidp->fsmap.path, &vs->stbuf);
>
> This is not threadsafe since rpath still uses a static buffer in
> qemu.git. Please ensure that rpath() is thread-safe before pushing
> this patch.
There is another patch on the internal list to make rpath thread safe.
>
>> + vs->v9fs_errno = errno;
>> +}
>> +
>> static void v9fs_stat(V9fsState *s, V9fsPDU *pdu)
>> {
>> int32_t fid;
>> @@ -1487,6 +1496,10 @@ static void v9fs_stat(V9fsState *s, V9fsPDU *pdu)
>> vs = qemu_malloc(sizeof(*vs));
>> vs->pdu = pdu;
>> vs->offset = 7;
>> + vs->s = s;
>> + vs->request.func = v9fs_stat_do_lstat;
>> + vs->request.post_op.func = v9fs_stat_post_lstat;
>> + vs->request.post_op.arg = vs;
>>
>> memset(&vs->v9stat, 0, sizeof(vs->v9stat));
>>
>> @@ -1498,8 +1511,11 @@ static void v9fs_stat(V9fsState *s, V9fsPDU *pdu)
>> goto out;
>> }
>>
>> + /*
>> err = v9fs_do_lstat(s, &vs->fidp->fsmap.path, &vs->stbuf);
>> v9fs_stat_post_lstat(s, vs, err);
>> + */
>
> Please remove unused code, it quickly becomes out-of-date and confuses readers.
>
>> + v9fs_qemu_submit_request(&vs->request);
>
> What happens when another PDU is handled next that uses the same fid?
> The worst case is if the client sends TCLUNK and fid is freed while
> the worker thread and later the post op still access the memory.
> There needs to be some kind of guard (like a reference count) to
> prevent this.
As per the protocol this should not happen. Client is the controls the fid,
and the fid is created or destroyed per the directive of the client.
It should not send clunk until the response is received on that fid
based operation(if there is any).
- JV
>
> Stefan
next prev parent reply other threads:[~2011-03-16 14:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-15 10:34 [Qemu-devel] [v1 PATCH 0/3]: Use GLib threadpool in 9pfs Arun R Bharadwaj
2011-03-15 10:36 ` [Qemu-devel] [v1 PATCH 1/3]: Move the paio_signal_handler to a generic location Arun R Bharadwaj
2011-03-15 11:38 ` [Qemu-devel] " Stefan Hajnoczi
2011-03-15 15:27 ` Arun R Bharadwaj
2011-03-15 10:38 ` [Qemu-devel] [v1 PATCH 2/3]: Helper routines to use GLib threadpool infrastructure in 9pfs Arun R Bharadwaj
2011-03-15 11:45 ` Harsh Bora
2011-03-15 15:30 ` Arun R Bharadwaj
2011-03-15 13:13 ` [Qemu-devel] " Anthony Liguori
2011-03-15 15:33 ` Arun R Bharadwaj
2011-03-16 9:20 ` Stefan Hajnoczi
2011-03-16 13:10 ` Anthony Liguori
2011-03-16 14:20 ` Venkateswararao Jujjuri (JV)
2011-03-16 17:03 ` Stefan Hajnoczi
2011-03-15 10:39 ` [Qemu-devel] [v1 PATCH 3/3]: Convert v9fs_stat to threaded model Arun R Bharadwaj
2011-03-16 10:23 ` [Qemu-devel] " Stefan Hajnoczi
2011-03-16 14:33 ` Venkateswararao Jujjuri (JV) [this message]
2011-03-16 17:10 ` Stefan Hajnoczi
2011-03-17 4:26 ` Venkateswararao Jujjuri (JV)
2011-03-17 7:19 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D80CA34.6040205@linux.vnet.ibm.com \
--to=jvrao@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=arun@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).