All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Jason Andryuk <jandryuk@gmail.com>
Cc: xen-devel@lists.xenproject.org, Wei Liu <wl@xen.org>,
	Anthony PERARD <anthony.perard@citrix.com>
Subject: Re: [PATCH 03/29] tools/xenlogd: connect to frontend
Date: Thu, 2 Nov 2023 09:23:17 +0100	[thread overview]
Message-ID: <30b8cb38-ecc8-4d4e-bf18-512e893de153@suse.com> (raw)
In-Reply-To: <CAKf6xptkUPBSTsij=CAWaiYxTCtGH4zpZWiLuvb=teX3i_sjrA@mail.gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 4921 bytes --]

On 01.11.23 20:21, Jason Andryuk wrote:
> On Wed, Nov 1, 2023 at 5:34 AM Juergen Gross <jgross@suse.com> wrote:
>>
>> Add the code for connecting to frontends to xenlogd.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> 
>> diff --git a/tools/xenlogd/xenlogd.c b/tools/xenlogd/xenlogd.c
>> index 792d1026a3..da0a09a122 100644
>> --- a/tools/xenlogd/xenlogd.c
>> +++ b/tools/xenlogd/xenlogd.c
> 
>> +static void connect_device(device *device)
>> +{
>> +    unsigned int val;
>> +    xenevtchn_port_or_error_t evtchn;
> 1.> +
>> +    val = read_frontend_node_uint(device, "version", 0);
>> +    if ( val != 1 )
>> +        return connect_err(device, "frontend specifies illegal version");
>> +    val = read_frontend_node_uint(device, "num-rings", 0);
>> +    if ( val != 1 )
>> +        return connect_err(device, "frontend specifies illegal ring number");
> 
> Linux uses 2 rings (XEN_9PFS_NUM_RINGS), and it doesn't connect when
> max-rings is less than that.
> 
> max_rings = xenbus_read_unsigned(dev->otherend, "max-rings", 0);
> if (max_rings < XEN_9PFS_NUM_RINGS)
>      return -EINVAL;
> 
> new_device() writes max-rings as 1.  So this works for mini-os, but
> not Linux.  I'm not requesting you to change it - just noting it.

Thanks for the note. I'll change it to allow more rings.

> 
>> +
>> +    val = read_frontend_node_uint(device, "event-channel-0", 0);
>> +    if ( val == 0 )
>> +        return connect_err(device, "frontend specifies illegal evtchn");
>> +    evtchn = xenevtchn_bind_interdomain(xe, device->domid, val);
>> +    if ( evtchn < 0 )
>> +        return connect_err(device, "could not bind to event channel");
>> +    device->evtchn = evtchn;
>> +
>> +    val = read_frontend_node_uint(device, "ring-ref0", 0);
>> +    if ( val == 0 )
>> +        return connect_err(device, "frontend specifies illegal grant for ring");
>> +    device->intf = xengnttab_map_grant_ref(xg, device->domid, val,
>> +                                           PROT_READ | PROT_WRITE);
>> +    if ( !device->intf )
>> +        return connect_err(device, "could not map interface page");
>> +    device->ring_order = device->intf->ring_order;
>> +    if ( device->ring_order > 9 || device->ring_order < 1 )
>> +        return connect_err(device, "frontend specifies illegal ring order");
>> +    device->ring_size = XEN_FLEX_RING_SIZE(device->ring_order);
>> +    device->data.in = xengnttab_map_domain_grant_refs(xg,
>> +                                                      1 << device->ring_order,
>> +                                                      device->domid,
>> +                                                      device->intf->ref,
>> +                                                      PROT_READ | PROT_WRITE);
>> +    if ( !device->data.in )
>> +        return connect_err(device, "could not map ring pages");
>> +    device->data.out = device->data.in + device->ring_size;
>> +
>> +    if ( pthread_create(&device->thread, NULL, io_thread, device) )
>> +       return connect_err(device, "could not start I/O thread");
>> +    device->thread_active = true;
>> +
>> +    write_backend_state(device, XenbusStateConnected);
>> +}
>> +
> 
>> @@ -122,6 +669,11 @@ int main(int argc, char *argv[])
>>       int syslog_mask = LOG_MASK(LOG_WARNING) | LOG_MASK(LOG_ERR) |
>>                         LOG_MASK(LOG_CRIT) | LOG_MASK(LOG_ALERT) |
>>                         LOG_MASK(LOG_EMERG);
>> +    char **watch;
>> +    struct pollfd p[2] = {
>> +        { .events = POLLIN, .revents = POLLIN },
> 
> Are you intentionally setting revents to enter the loop initially?
> Shouldn't the watch registration trigger it to fire anyway?

I don't remember where I got this from. Probably I really wanted to use
the first loop iteration already for processing the first response.

I think I can drop setting revents.

> 
>> +        { .events = POLLIN }
>> +    };
>>
>>       umask(027);
>>       if ( getenv("XENLOGD_VERBOSE") )
>> @@ -134,9 +686,26 @@ int main(int argc, char *argv[])
>>
>>       xen_connect();
>>
>> +    if ( !xs_watch(xs, "backend/xen_9pfs", "main") )
>> +        do_err("xs_watch() in main thread failed");
>> +    p[0].fd = xs_fileno(xs);
>> +    p[1].fd = xenevtchn_fd(xe);
>> +
>> +    scan_backend();
>> +
>>       while ( !stop_me )
>>       {
>> -        sleep(60);
>> +        while ( (p[0].revents & POLLIN) &&
>> +                (watch = xs_check_watch(xs)) != NULL )
>> +        {
>> +            handle_watch(watch[XS_WATCH_PATH], watch[XS_WATCH_TOKEN]);
>> +            free(watch);
>> +        }
>> +
>> +        if ( p[1].revents & POLLIN )
>> +            handle_event();
>> +
>> +        poll(p, 2, 10000);
> 
> Can you just use an infinite timeout and rely on the signal
> interrupting the system call?

Yes, probably.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  reply	other threads:[~2023-11-02  8:23 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01  9:32 [PATCH 00/29] tools: enable xenstore-stubdom to use 9pfs Juergen Gross
2023-11-01  9:32 ` [PATCH 01/29] xen/public: add some more 9pfs xenstore paths Juergen Gross
2023-11-01 18:31   ` Jason Andryuk
2023-11-02  7:15     ` Juergen Gross
2023-11-01  9:32 ` [PATCH 02/29] tools: add a new xen logging daemon Juergen Gross
2023-11-01 18:36   ` Jason Andryuk
2023-11-02  7:44     ` Juergen Gross
2023-11-02 19:15       ` Andrew Cooper
2023-11-03  7:36         ` Juergen Gross
2023-11-01  9:32 ` [PATCH 03/29] tools/xenlogd: connect to frontend Juergen Gross
2023-11-01 19:21   ` Jason Andryuk
2023-11-02  8:23     ` Juergen Gross [this message]
2023-11-03  1:42       ` Jason Andryuk
2023-11-03  7:37         ` Juergen Gross
2023-11-01  9:33 ` [PATCH 04/29] tools/xenlogd: add transport layer Juergen Gross
2023-11-02 18:30   ` Jason Andryuk
2023-11-03  7:50     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 05/29] tools/xenlogd: add 9pfs response generation support Juergen Gross
2023-11-02 18:48   ` Jason Andryuk
2023-11-03  7:52     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 06/29] tools/xenlogd: add 9pfs version request support Juergen Gross
2023-11-02 19:25   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 07/29] tools/xenlogd: add 9pfs attach " Juergen Gross
2023-11-03 15:13   ` Jason Andryuk
2023-11-06  7:52     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 08/29] tools/xenlogd: add 9pfs walk " Juergen Gross
2023-11-03 19:48   ` Jason Andryuk
2023-11-06  7:53     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 09/29] tools/xenlogd: add 9pfs open " Juergen Gross
2023-11-06 19:33   ` Jason Andryuk
2023-11-07  7:03     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 10/29] tools/xenlogd: add 9pfs clunk " Juergen Gross
2023-11-06 19:35   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 11/29] tools/xenlogd: add 9pfs create " Juergen Gross
2023-11-06 19:53   ` Jason Andryuk
2023-11-07  7:15     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 12/29] tools/xenlogd: add 9pfs stat " Juergen Gross
2023-11-07 14:04   ` Jason Andryuk
2023-11-07 14:42     ` Juergen Gross
2023-11-07 14:48       ` Jason Andryuk
2023-11-07 15:20         ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 13/29] tools/xenlogd: add 9pfs write " Juergen Gross
2023-11-07 14:10   ` Jason Andryuk
2023-11-07 14:43     ` Juergen Gross
2023-11-07 15:21       ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 14/29] tools/xenlogd: add 9pfs read " Juergen Gross
2023-11-07 14:31   ` Jason Andryuk
2023-11-07 14:49     ` Juergen Gross
2023-11-07 15:23       ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 15/29] tools/libs/light: add backend type for 9pfs PV devices Juergen Gross
2023-11-07 15:46   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 16/29] tools/xl: support new 9pfs backend xenlogd Juergen Gross
2023-11-07 16:55   ` Jason Andryuk
2023-11-08  6:54     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 17/29] tools/helpers: allocate xenstore event channel for xenstore stubdom Juergen Gross
2023-11-07 18:23   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 18/29] tools/xenstored: rename xenbus_evtchn() Juergen Gross
2023-11-01 10:44   ` Julien Grall
2023-11-01 11:08     ` Juergen Gross
2023-11-01 11:14       ` Julien Grall
2023-11-01  9:33 ` [PATCH 19/29] stubdom: extend xenstore stubdom configs Juergen Gross
2023-11-07 18:24   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 20/29] tools: add 9pfs device to xenstore-stubdom Juergen Gross
2023-11-07 19:18   ` Jason Andryuk
2023-11-08  6:54     ` Juergen Gross
2023-11-01  9:33 ` [PATCH 21/29] tools: tell xenstore-stubdom its own domid Juergen Gross
2023-11-01 16:51   ` Andrew Cooper
2023-11-01  9:33 ` [PATCH 22/29] tools/xenstored: Juergen Gross
2023-11-07 19:23   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 23/29] tools/xenstored: split domain_init() Juergen Gross
2023-11-01  9:33 ` [PATCH 24/29] tools/xenstored: map stubdom interface Juergen Gross
2023-11-01  9:33 ` [PATCH 25/29] tools/xenstored: mount 9pfs device in stubdom Juergen Gross
2023-11-07 20:32   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 26/29] tools/xenstored: add helpers for filename handling Juergen Gross
2023-11-07 20:34   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 27/29] tools/xenstored: add daemon_init() function Juergen Gross
2023-11-07 20:34   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 28/29] tools/xenstored: support complete log capabilities in stubdom Juergen Gross
2023-11-07 20:36   ` Jason Andryuk
2023-11-01  9:33 ` [PATCH 29/29] tools/xenstored: have a single do_control_memreport() Juergen Gross
2023-11-07 20:40   ` Jason Andryuk

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=30b8cb38-ecc8-4d4e-bf18-512e893de153@suse.com \
    --to=jgross@suse.com \
    --cc=anthony.perard@citrix.com \
    --cc=jandryuk@gmail.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /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 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.