samba shares access issue in Solaris from a MT program
Narayana Pattipati
narayana.pattipati at wipro.com
Fri Sep 24 15:36:53 GMT 2004
Hi,
I have issues in accessing samba shares from an MT application in
Solaris.
The program architecture is something like this:
Nautilus (GNOME file manager)
|
gnome-vfs (GNOME virtual file system library)
|
libsmbclient.so (samba libraries)
Nautilus and gnome-vfs are MT enabled and they depend on threads heavily
to show any file system contents. I am facing an issue when gnome-vfs is
trying to connect to a samba server to access shares. The problem is
seen in Solaris only. Its not seen in Linux, as thread implementation is
different there. The issue is:
When gnome-vfs tries to open any samba share by calling opendir function
of samba context, samba library give the following error on the command
line:
Error connecting to xxx.xxx.xxx.xxx (Error 0)
Error connecting to xxx.xxx.xxx.xxx (Error 0)
Where xxx.xxx.xxx.xxx is the ip address of master server in the windows
domain. This error comes because of socket connection failure in the code
samba/sources/lib/util_sock.c:open_socket_out()
ret = connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out));
/* Some systems return EAGAIN when they mean EINPROGRESS */
if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
errno == EAGAIN) && (connect_loop < timeout) ) {
smb_msleep(connect_loop);
timeout -= connect_loop;
connect_loop += increment;
if (increment < 250) {
/* After 8 rounds we end up at a max of 255 msec */
increment *= 1.5;
}
goto connect_again;
}
In the above code, socket is set to non-blocking before connect. Since
it is non-blocking, while connecting, first try will give "operation in
progress" (EINPROGRESS) error. But when the code makes comparison of
errno with the error codes, it is failing to match EINPROGRESS. This is
because errno is set to "0". Hence, the code does not attempt to connect
again and fails to connect to any windows server permanently.
Root cause for this is that samba libraries are linked from
nautilus/gnome-vfs, which is a multi-threaded program. Since samba is not
built with "-mt" compiler flag, accessing errno gives inconsistent values.
The thread which calls samba code can only update its thread specific
"errno", not the global "errno". Since the samba library is not built
for MT, the errno will point to global errno, which a thread can't
update.
If samba is build with "-mt" flags, then the errno will be pointed
to __errno() macro, instead of global errno, and thread executing samba
code will be able to access correct errno.
I have few open questions based on this:
a) I read from samba site that its not MT safe. But since the code runs in
one thread only, is it OK to build samba with "-mt" compiler flags ?
What would be the side effects if samba is build with -mt compiler
flags ?
b) One workaround to fix this issue is to define errno as __errno() in the
file samba/sources/lib/util_sock.c file. Again what would be the side
affects of this change ?
c) There is a mention that in samba 4.0.0, the libraries will be made
thread compliant so that they can be called from MT applications.
Is that correct ? If so, what would be the time frame for samba 4
release.
Any inputs in solving the issue would be highly appreciated.
Thanks for reading the mail,
Narayana
Confidentiality Notice
The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or Mailadmin at wipro.com immediately
and destroy all copies of this message and any attachments.
More information about the samba-technical
mailing list