Where to find working example of name_attach() - name_open()

Where I can find working example of name_attach() - name_open()? They should
be called from two diffrent nodes

where both of them have running qnet.

Let say that server process is running on a node “server1” and client is
running on a node “consumer”.

Which call should I use, name_attach() or ChannelCreate()? name_open() or
ConnectAttach()?

Thanks,

Janusz.

Janusz Ruszel <janusz_ruszel@baxter.com> wrote:

Where I can find working example of name_attach() - name_open()? They should
be called from two diffrent nodes

They aren’t (officially) supported accross the network.

xtang posted a a replacement for name_open() that does a
search of /net/…/dev/name/… for names and handles the
open that way.

I’ll include it at the end of this post.

where both of them have running qnet.

Let say that server process is running on a node “server1” and client is
running on a node “consumer”.

Which call should I use, name_attach() or ChannelCreate()? name_open() or
ConnectAttach()?

resmgr_attach() and open()

or

name_attach(), and network_name_open()

would be my preferences.

[include from xtang]
Since I’ve been asked for this question several times, and giving the fact
that the implementation won’t get out soon, I attach a function so you can
use to work arround the problem.

-xtang

#include <sys/dispatch.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <share.h>

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, flags)) != -1 || (flags & NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net/") + strlen(dent->d_name) +
strlen("/dev/name/global/") + strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}
sprintf(newname, “/net/%s/dev/name/global/%s”, dent->d_name, name);
fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR, SH_DENYNO,
_IO_CONNECT_OPEN, 1, _IO_FLAG_RD | _IO_FLAG_WR,
_FTYPE_NAME, 0, 0, 0, 0, 0, 0);
if (fd != -1) {
closedir(dir);
return fd;
}
}

closedir(dir);
errno = ENOENT;
return -1;
}
[end include from xtang]


-David

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

Thank you David and Xtang. It works!
How to “remount” /net without slaying io-net or how to do it from the
application?

Thanks,
Janusz.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:b7mfhd$8r2$1@nntp.qnx.com

Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote:
Where I can find working example of name_attach() - name_open()? They
should
be called from two diffrent nodes

They aren’t (officially) supported accross the network.

xtang posted a a replacement for name_open() that does a
search of /net/…/dev/name/… for names and handles the
open that way.

I’ll include it at the end of this post.

where both of them have running qnet.

Let say that server process is running on a node “server1” and client is
running on a node “consumer”.

Which call should I use, name_attach() or ChannelCreate()? name_open()
or
ConnectAttach()?

resmgr_attach() and open()

or

name_attach(), and network_name_open()

would be my preferences.

[include from xtang]
Since I’ve been asked for this question several times, and giving the fact
that the implementation won’t get out soon, I attach a function so you can
use to work arround the problem.

-xtang

#include <sys/dispatch.h
#include <dirent.h
#include <errno.h
#include <fcntl.h
#include <share.h

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, flags)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net/") + strlen(dent->d_name) +

strlen("/dev/name/global/") + strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}
sprintf(newname, “/net/%s/dev/name/global/%s”,
dent->d_name, name);
fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR,
SH_DENYNO,
_IO_CONNECT_OPEN, 1, _IO_FLAG_RD
| _IO_FLAG_WR,
_FTYPE_NAME, 0, 0, 0, 0, 0, 0);
if (fd != -1) {
closedir(dir);
return fd;
}
}

closedir(dir);
errno = ENOENT;
return -1;
}
[end include from xtang]


-David

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

Janusz Ruszel <janusz_ruszel@baxter.com> wrote in message
news:b7n3in$p13$1@inn.qnx.com

Thank you David and Xtang. It works!
How to “remount” /net without slaying io-net or how to do it from the
application?

mount -Tio-net npm-qnet.so

and (in C):

if (mount(“npm-qnet.so”, “/”, _MFLAG_OCB, “tcpip”, 0, -1) == -1) {
fprintf(“The mount is faild\n”);
}


-xtang

Thanks,
Janusz.

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:b7mfhd$8r2$> 1@nntp.qnx.com> …
Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote:
Where I can find working example of name_attach() - name_open()? They
should
be called from two diffrent nodes

They aren’t (officially) supported accross the network.

xtang posted a a replacement for name_open() that does a
search of /net/…/dev/name/… for names and handles the
open that way.

I’ll include it at the end of this post.

where both of them have running qnet.

Let say that server process is running on a node “server1” and client
is
running on a node “consumer”.

Which call should I use, name_attach() or ChannelCreate()?
name_open()
or
ConnectAttach()?

resmgr_attach() and open()

or

name_attach(), and network_name_open()

would be my preferences.

[include from xtang]
Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so you
can
use to work arround the problem.

-xtang

#include <sys/dispatch.h
#include <dirent.h
#include <errno.h
#include <fcntl.h
#include <share.h

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, flags)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net/") + strlen(dent->d_name)
+

strlen("/dev/name/global/") + strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}
sprintf(newname, “/net/%s/dev/name/global/%s”,
dent->d_name, name);
fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR,
SH_DENYNO,
_IO_CONNECT_OPEN, 1,
_IO_FLAG_RD
| _IO_FLAG_WR,
_FTYPE_NAME, 0, 0, 0, 0, 0,
0);
if (fd != -1) {
closedir(dir);
return fd;
}
}

closedir(dir);
errno = ENOENT;
return -1;
}
[end include from xtang]


-David

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

Scenario is like that: Network cable was disconnected after mount. At the
same time new computers show up on the net and cable is back. How to
“refresh” /net directory?

Janusz.

“Xiaodan Tang” <xtang@qnx.com> wrote in message
news:b7n4n2$m7n$1@nntp.qnx.com

Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote in message
news:b7n3in$p13$> 1@inn.qnx.com> …
Thank you David and Xtang. It works!
How to “remount” /net without slaying io-net or how to do it from the
application?

mount -Tio-net npm-qnet.so

and (in C):

if (mount(“npm-qnet.so”, “/”, _MFLAG_OCB, “tcpip”, 0, -1) == -1) {
fprintf(“The mount is faild\n”);
}


-xtang

Thanks,
Janusz.

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:b7mfhd$8r2$> 1@nntp.qnx.com> …
Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote:
Where I can find working example of name_attach() - name_open()?
They
should
be called from two diffrent nodes

They aren’t (officially) supported accross the network.

xtang posted a a replacement for name_open() that does a
search of /net/…/dev/name/… for names and handles the
open that way.

I’ll include it at the end of this post.

where both of them have running qnet.

Let say that server process is running on a node “server1” and
client
is
running on a node “consumer”.

Which call should I use, name_attach() or ChannelCreate()?
name_open()
or
ConnectAttach()?

resmgr_attach() and open()

or

name_attach(), and network_name_open()

would be my preferences.

[include from xtang]
Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so you
can
use to work arround the problem.

-xtang

#include <sys/dispatch.h
#include <dirent.h
#include <errno.h
#include <fcntl.h
#include <share.h

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, flags)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net/") +
strlen(dent->d_name)
+

strlen("/dev/name/global/") + strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}
sprintf(newname, “/net/%s/dev/name/global/%s”,
dent->d_name, name);
fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR,
SH_DENYNO,
_IO_CONNECT_OPEN, 1,
_IO_FLAG_RD
| _IO_FLAG_WR,
_FTYPE_NAME, 0, 0, 0, 0, 0,
0);
if (fd != -1) {
closedir(dir);
return fd;
}
}

closedir(dir);
errno = ENOENT;
return -1;
}
[end include from xtang]


-David

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

Janusz Ruszel <janusz_ruszel@baxter.com> wrote:

Scenario is like that: Network cable was disconnected after mount. At the
same time new computers show up on the net and cable is back. How to
“refresh” /net directory?

I think io-net is supposed to “refresh” them automatically with NDP.
This does, though, take a little while.

Using the search below… closing the directory, then reopening it
might do, or rewinddir() might do it.

(And, since it closes, and re-opens, that will happen automatically.)

What you may want to do, though, is put a re-try loop with delay
around the global_name_open() if you’re worried about that case.

-David


Janusz.

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:b7n4n2$m7n$> 1@nntp.qnx.com> …

Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote in message
news:b7n3in$p13$> 1@inn.qnx.com> …
Thank you David and Xtang. It works!
How to “remount” /net without slaying io-net or how to do it from the
application?

mount -Tio-net npm-qnet.so

and (in C):

if (mount(“npm-qnet.so”, “/”, _MFLAG_OCB, “tcpip”, 0, -1) == -1) {
fprintf(“The mount is faild\n”);
}


-xtang

Thanks,
Janusz.

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:b7mfhd$8r2$> 1@nntp.qnx.com> …
Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote:
Where I can find working example of name_attach() - name_open()?
They
should
be called from two diffrent nodes

They aren’t (officially) supported accross the network.

xtang posted a a replacement for name_open() that does a
search of /net/…/dev/name/… for names and handles the
open that way.

I’ll include it at the end of this post.

where both of them have running qnet.

Let say that server process is running on a node “server1” and
client
is
running on a node “consumer”.

Which call should I use, name_attach() or ChannelCreate()?
name_open()
or
ConnectAttach()?

resmgr_attach() and open()

or

name_attach(), and network_name_open()

would be my preferences.

[include from xtang]
Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so you
can
use to work arround the problem.

-xtang

#include <sys/dispatch.h
#include <dirent.h
#include <errno.h
#include <fcntl.h
#include <share.h

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, flags)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net/") +
strlen(dent->d_name)
+

strlen("/dev/name/global/") + strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}
sprintf(newname, “/net/%s/dev/name/global/%s”,
dent->d_name, name);
fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR,
SH_DENYNO,
_IO_CONNECT_OPEN, 1,
_IO_FLAG_RD
| _IO_FLAG_WR,
_FTYPE_NAME, 0, 0, 0, 0, 0,
0);
if (fd != -1) {
closedir(dir);
return fd;
}
}

closedir(dir);
errno = ENOENT;
return -1;
}
[end include from xtang]


-David

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

\


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

Janusz Ruszel <janusz_ruszel@baxter.com> wrote in message
news:b7n55o$qgr$1@inn.qnx.com

Scenario is like that: Network cable was disconnected after mount. At the
same time new computers show up on the net and cable is back. How to
“refresh” /net directory?

That’s the problem of the code below. If a name is not show up in /net,
unless you know him and enforce a “ls /net/remote”, it won’t show up.

You can try to load QNET with “broadcast” option. (Note this is
un-documented
option that could be change in feature).

mount -Tio-net -o “broadcast=0x0003003c” npm-qnet.so

What this option does is force QNET do a “heartbeat” broadcasting, every
0x3c seconds.

-xtang

Janusz.

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:b7n4n2$m7n$> 1@nntp.qnx.com> …

Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote in message
news:b7n3in$p13$> 1@inn.qnx.com> …
Thank you David and Xtang. It works!
How to “remount” /net without slaying io-net or how to do it from the
application?

mount -Tio-net npm-qnet.so

and (in C):

if (mount(“npm-qnet.so”, “/”, _MFLAG_OCB, “tcpip”, 0, -1) == -1) {
fprintf(“The mount is faild\n”);
}


-xtang

Thanks,
Janusz.

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:b7mfhd$8r2$> 1@nntp.qnx.com> …
Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote:
Where I can find working example of name_attach() - name_open()?
They
should
be called from two diffrent nodes

They aren’t (officially) supported accross the network.

xtang posted a a replacement for name_open() that does a
search of /net/…/dev/name/… for names and handles the
open that way.

I’ll include it at the end of this post.

where both of them have running qnet.

Let say that server process is running on a node “server1” and
client
is
running on a node “consumer”.

Which call should I use, name_attach() or ChannelCreate()?
name_open()
or
ConnectAttach()?

resmgr_attach() and open()

or

name_attach(), and network_name_open()

would be my preferences.

[include from xtang]
Since I’ve been asked for this question several times, and giving
the
fact
that the implementation won’t get out soon, I attach a function so
you
can
use to work arround the problem.

-xtang

#include <sys/dispatch.h
#include <dirent.h
#include <errno.h
#include <fcntl.h
#include <share.h

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, flags)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net/") +
strlen(dent->d_name)
+

strlen("/dev/name/global/") + strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}
sprintf(newname, “/net/%s/dev/name/global/%s”,
dent->d_name, name);
fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR,
SH_DENYNO,
_IO_CONNECT_OPEN, 1,
_IO_FLAG_RD
| _IO_FLAG_WR,
_FTYPE_NAME, 0, 0, 0, 0,
0,
0);
if (fd != -1) {
closedir(dir);
return fd;
}
}

closedir(dir);
errno = ENOENT;
return -1;
}
[end include from xtang]


-David

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


\