Finding OCB while in io_open()

Hi,

I have managed to make myself a resource manager that is a thread
running in an io-net shared object. It mainly works, but I am now
stumbling.

I want to save the msg->connect.ioflag value (O_RDONLY, etc) in the
[extended] OCB while still in the io_open() function, but am not sure
how to find the proper, and newly created OCB (by ocb_calloc()). I have
been using iofunc_open_default() and I know that a valid OCB has been
created.

I thought I would try using the sequence suggested in the doc for
iofunc_open_default() instead. This is basically calls to iofunc_open(),
iofunc_ocb_calloc(), iofunc_ocb_attach(), and resmgr_open_bind(). This
results in a failure by io-net to load the shared object when I try to
mount it.

Can someone please let me know what the recommended way to create and
gain access to a new OCB while still in the io_open() function is? I’m
probably missing something simple here…

Thanks,

Geoff Roberts.

I would suggest you to attach a couple of ocb_calloc()/ocb_free() funcs
where you could anything you need in your ocb.

/* necessary HERE for correct io_func prototypes */
struct my_ocb_s;
#define IOFUNC_OCB_T struct my_ocb_s

#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>

typedef struct my_ocb_s
{
iofunc_ocb_t ocb;
unsigned my_flag;
}my_ocb_t;


static iofunc_funcs_t my_ocb_funcs = {
_IOFUNC_NFUNCS,
my_ocb_calloc,
my_ocb_free
};

static iofunc_mount_t my_mount = {0, 0, 0, 0, &my_ocb_funcs};

my_init_resmgr(void){

my_resmgr_attr[numDev].attr.mount = &my_mount;

if (resmgr_attach(dpp, &resmgr_attr, “my_resmgr”, _FTYPE_ANY,
_RESMGR_FLAG_SELF, &my_connect_funcs, &my_io_funcs, &my_server_attr) ==
-1) {
puts(“Gloups!!”);
exit(errno);
}

}

my_ocb_t *
my_ocb_calloc (resmgr_context_t *ctp, my_resmgr_attr_t *tattr)
{
my_ocb_t *tocb;

if ((tocb = calloc (1, sizeof (my_ocb_t))) == NULL) {
puts(“gloups!!”);
return(0);
}

tocb->my_flag = my_value;


// do anything else to the ocb
return(tocb);
}


void
my_ocb_free (my_ocb_t *tocb)
{

free (tocb);
}


Hope I didn’t forget anything!

Regards,
Alain.

Geoff Roberts a écrit:

Hi,

I have managed to make myself a resource manager that is a thread
running in an io-net shared object. It mainly works, but I am now
stumbling.

I want to save the msg->connect.ioflag value (O_RDONLY, etc) in the
[extended] OCB while still in the io_open() function, but am not sure
how to find the proper, and newly created OCB (by ocb_calloc()). I have
been using iofunc_open_default() and I know that a valid OCB has been
created.

I thought I would try using the sequence suggested in the doc for
iofunc_open_default() instead. This is basically calls to iofunc_open(),
iofunc_ocb_calloc(), iofunc_ocb_attach(), and resmgr_open_bind(). This
results in a failure by io-net to load the shared object when I try to
mount it.

Can someone please let me know what the recommended way to create and
gain access to a new OCB while still in the io_open() function is? I’m
probably missing something simple here…

Thanks,

Geoff Roberts.

Yes, I have done all that.

My problem is that while in the ocb_calloc() function, where I have the
perfect opportunity to save away the ioflag value, I don’t know (while
in this function) where to find it. The only place I know where the
ioflag field exists is in the connect message, and sometime later, in
the ocb.attr structure. Presumably, the ocb.attr stucture is loaded
sometime after my ocb_calloc() function, and is therefore
theoretically there by the time iofunc_open_default() returns back to
the io_open(). But as I said, from within the io_open() function, I
don’t know how to find that particular OCB.

Doing it all manually (that is, not using iofunc_open_default()) doesn’t
work for me.

I need this open mode value at this point do that I can pass it to
another object in the resource manager.

I had thought of waiting until a first read, write, devctl, or something
to catch the OCB there. But I feel this approach is somewhat ugly, even
if it worked! Besides, I need that value prior to the client accessing
the device.

Geoff.

Alain Bonnefoy wrote:

I would suggest you to attach a couple of ocb_calloc()/ocb_free() funcs
where you could anything you need in your ocb.

/* necessary HERE for correct io_func prototypes */
struct my_ocb_s;
#define IOFUNC_OCB_T struct my_ocb_s

#include <sys/iofunc.h
#include <sys/dispatch.h
#include <sys/neutrino.h

typedef struct my_ocb_s
{
iofunc_ocb_t ocb;
unsigned my_flag;
}my_ocb_t;

static iofunc_funcs_t my_ocb_funcs = {
_IOFUNC_NFUNCS,
my_ocb_calloc,
my_ocb_free
};

static iofunc_mount_t my_mount = {0, 0, 0, 0, &my_ocb_funcs};

my_init_resmgr(void){

my_resmgr_attr[numDev].attr.mount = &my_mount;

if (resmgr_attach(dpp, &resmgr_attr, “my_resmgr”, _FTYPE_ANY,
_RESMGR_FLAG_SELF, &my_connect_funcs, &my_io_funcs, &my_server_attr) ==
-1) {
puts(“Gloups!!”);
exit(errno);
}

}

my_ocb_t *
my_ocb_calloc (resmgr_context_t *ctp, my_resmgr_attr_t *tattr)
{
my_ocb_t *tocb;

if ((tocb = calloc (1, sizeof (my_ocb_t))) == NULL) {
puts(“gloups!!”);
return(0);
}

tocb->my_flag = my_value;

// do anything else to the ocb
return(tocb);
}

void
my_ocb_free (my_ocb_t *tocb)
{

free (tocb);
}

Hope I didn’t forget anything!

Regards,
Alain.

Geoff Roberts a écrit:

Hi,

I have managed to make myself a resource manager that is a thread
running in an io-net shared object. It mainly works, but I am now
stumbling.

I want to save the msg->connect.ioflag value (O_RDONLY, etc) in the
[extended] OCB while still in the io_open() function, but am not sure
how to find the proper, and newly created OCB (by ocb_calloc()). I have
been using iofunc_open_default() and I know that a valid OCB has been
created.

I thought I would try using the sequence suggested in the doc for
iofunc_open_default() instead. This is basically calls to iofunc_open(),
iofunc_ocb_calloc(), iofunc_ocb_attach(), and resmgr_open_bind(). This
results in a failure by io-net to load the shared object when I try to
mount it.

Can someone please let me know what the recommended way to create and
gain access to a new OCB while still in the io_open() function is? I’m
probably missing something simple here…

Thanks,

Geoff Roberts.

Realtime Technology Systems Pty Ltd
2 Hadleigh Circuit
Isabella Plains
ACT 2905
AUSTRALIA

Phone: 61-2-6291 3833
Fax: 61-2-6291 3838
Mobile: 0408 673 993
Email: ger2@rtts.com.au

Hum, I wonder if I really understand your problem.

You said that you don’t know where to find your flag in ocb_calloc()?

Dou you want to talk about ctp->msg->connect.ioflag ?

Alain.

Geoff Roberts a écrit:

Yes, I have done all that.

My problem is that while in the ocb_calloc() function, where I have the
perfect opportunity to save away the ioflag value, I don’t know (while
in this function) where to find it. The only place I know where the
ioflag field exists is in the connect message, and sometime later, in
the ocb.attr structure. Presumably, the ocb.attr stucture is loaded
sometime after my ocb_calloc() function, and is therefore
theoretically there by the time iofunc_open_default() returns back to
the io_open(). But as I said, from within the io_open() function, I
don’t know how to find that particular OCB.

Doing it all manually (that is, not using iofunc_open_default()) doesn’t
work for me.

I need this open mode value at this point do that I can pass it to
another object in the resource manager.

I had thought of waiting until a first read, write, devctl, or something
to catch the OCB there. But I feel this approach is somewhat ugly, even
if it worked! Besides, I need that value prior to the client accessing
the device.

Geoff.

Alain Bonnefoy wrote:


I would suggest you to attach a couple of ocb_calloc()/ocb_free() funcs
where you could anything you need in your ocb.

/* necessary HERE for correct io_func prototypes */
struct my_ocb_s;
#define IOFUNC_OCB_T struct my_ocb_s

#include <sys/iofunc.h
#include <sys/dispatch.h
#include <sys/neutrino.h

typedef struct my_ocb_s
{
iofunc_ocb_t ocb;
unsigned my_flag;
}my_ocb_t;

static iofunc_funcs_t my_ocb_funcs = {
_IOFUNC_NFUNCS,
my_ocb_calloc,
my_ocb_free
};

static iofunc_mount_t my_mount = {0, 0, 0, 0, &my_ocb_funcs};

my_init_resmgr(void){

my_resmgr_attr[numDev].attr.mount = &my_mount;

if (resmgr_attach(dpp, &resmgr_attr, “my_resmgr”, _FTYPE_ANY,
_RESMGR_FLAG_SELF, &my_connect_funcs, &my_io_funcs, &my_server_attr) ==
-1) {
puts(“Gloups!!”);
exit(errno);
}

}

my_ocb_t *
my_ocb_calloc (resmgr_context_t *ctp, my_resmgr_attr_t *tattr)
{
my_ocb_t *tocb;

if ((tocb = calloc (1, sizeof (my_ocb_t))) == NULL) {
puts(“gloups!!”);
return(0);
}

tocb->my_flag = my_value;

// do anything else to the ocb
return(tocb);
}

void
my_ocb_free (my_ocb_t *tocb)
{

free (tocb);
}

Hope I didn’t forget anything!

Regards,
Alain.

Geoff Roberts a écrit:



Hi,

I have managed to make myself a resource manager that is a thread
running in an io-net shared object. It mainly works, but I am now
stumbling.

I want to save the msg->connect.ioflag value (O_RDONLY, etc) in the
[extended] OCB while still in the io_open() function, but am not sure
how to find the proper, and newly created OCB (by ocb_calloc()). I have
been using iofunc_open_default() and I know that a valid OCB has been
created.

I thought I would try using the sequence suggested in the doc for
iofunc_open_default() instead. This is basically calls to iofunc_open(),
iofunc_ocb_calloc(), iofunc_ocb_attach(), and resmgr_open_bind(). This
results in a failure by io-net to load the shared object when I try to
mount it.

Can someone please let me know what the recommended way to create and
gain access to a new OCB while still in the io_open() function is? I’m
probably missing something simple here…

Thanks,

Geoff Roberts.



\

Geoff Roberts <ger2@rtts.com.au> wrote:

Hi,

I have managed to make myself a resource manager that is a thread
running in an io-net shared object. It mainly works, but I am now
stumbling.

I want to save the msg->connect.ioflag value (O_RDONLY, etc) in the
[extended] OCB while still in the io_open() function, but am not sure
how to find the proper, and newly created OCB (by ocb_calloc()). I have
been using iofunc_open_default() and I know that a valid OCB has been
created.

That information is, already, stored in the standard OCB, do you need
it in the extended OCB as well?

ocb.ioflag holds that information. (According to the comments,
ocb.ioflag is the oflag from open() +1.

I thought I would try using the sequence suggested in the doc for
iofunc_open_default() instead. This is basically calls to iofunc_open(),
iofunc_ocb_calloc(), iofunc_ocb_attach(), and resmgr_open_bind(). This
results in a failure by io-net to load the shared object when I try to
mount it.

That doesn’t sound right. Can you try your replacement io_open() call
in a simple resource manager and make sure it links & runs properly
in that environment?

If so, but still fails in io-net, can you run io-net with DL_DEBUG=1
before loading your shared object to see if any useful errors are
spit out?

Can someone please let me know what the recommended way to create and
gain access to a new OCB while still in the io_open() function is? I’m
probably missing something simple here…

As far as I know, unwinding the iofunc_open_default() as you tried to
do is the recommended way.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

I managed to figure it all out a while after I posted to this newsgroup

  • at about 1am and after many hours of head scratching.

And the answer was as I suspected, simple. It clicked that the handle of
type RESMGR_HANDLE_T was in fact the attribute structure set up and
initialised earlier, and passed as the last argument to resmgr_attach().

So once I cast it appropriately the “expanded” iofunc_open() routine
worked for me. All the OCB information was available to me after the
resmgr_open_bind().

I did notice that the ioflag values seemed to be different to those
passed into the open(). For example, O_RDONLY is defined in fcntl.h as
0x0000 but appears in the resmgr as 0x0001, and so on. I suspect I know
why they are incremented, and it is convenient that this is the case!

However, I find that working with a C++ based resmgr within the io-net
framework an extremely frustrating exercise. Basically the resmgr is a
thread created from the io-net shared object entry function (the SO is a
down producer). I find the whole thing extremely fragile - io-net dies
at the drop of a hat and takes the whole system down with it - I have to
reboot a lot. The behaviour of the io-net resmgr is not the same as a
“stand-alone” resmgr, and this threw me around a lot, as when things go
off the rails, it’s pretty had to figure out why. For example, making a
variable static will break it by simply not being able to load.The
DL_DEBUG flag might help with this but presumably it writes to a console
under which io-net runs rather than my pterm shell. And from within
photon I’m having difficulty viewing a console (it was so easy in QNX4
where we had ditto (hint hint)). A memory violation requires a re-boot.

Bottom line is that I’m now pretty pleased to be able to write to this
resource manager and be able to throw raw ethernet packets to the wire,
and get some back. I still have some issues and I’ll probably raise them
here later if I can’t sort them out myself.

Thanks,

Geoff.

Regarding the value of ioflag
David Gibbs wrote:

Geoff Roberts <> ger2@rtts.com.au> > wrote:
Hi,

I have managed to make myself a resource manager that is a thread
running in an io-net shared object. It mainly works, but I am now
stumbling.

I want to save the msg->connect.ioflag value (O_RDONLY, etc) in the
[extended] OCB while still in the io_open() function, but am not sure
how to find the proper, and newly created OCB (by ocb_calloc()). I have
been using iofunc_open_default() and I know that a valid OCB has been
created.

That information is, already, stored in the standard OCB, do you need
it in the extended OCB as well?

ocb.ioflag holds that information. (According to the comments,
ocb.ioflag is the oflag from open() +1.

I thought I would try using the sequence suggested in the doc for
iofunc_open_default() instead. This is basically calls to iofunc_open(),
iofunc_ocb_calloc(), iofunc_ocb_attach(), and resmgr_open_bind(). This
results in a failure by io-net to load the shared object when I try to
mount it.

That doesn’t sound right. Can you try your replacement io_open() call
in a simple resource manager and make sure it links & runs properly
in that environment?

If so, but still fails in io-net, can you run io-net with DL_DEBUG=1
before loading your shared object to see if any useful errors are
spit out?

Can someone please let me know what the recommended way to create and
gain access to a new OCB while still in the io_open() function is? I’m
probably missing something simple here…

As far as I know, unwinding the iofunc_open_default() as you tried to
do is the recommended way.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Realtime Technology Systems Pty Ltd
2 Hadleigh Circuit
Isabella Plains
ACT 2905
AUSTRALIA

Phone: 61-2-6291 3833
Fax: 61-2-6291 3838
Mobile: 0408 673 993
Email: ger2@rtts.com.au