Multiple mount_smbfs commands fail in bash script

Bernard Scharp freebsd-questions at itsacon.net
Thu Sep 2 13:52:27 UTC 2010


On 02/09/2010 15:29, Polytropon wrote:
> On Thu, 02 Sep 2010 14:02:35 +0200, Bernard Scharp <freebsd-questions at itsacon.net> wrote:
>>
>>>
>>> Could you post the script? Anything else would be pure guess work. You
>>
>> Well, I can recreate it with something as simple as:
>>
>> #!/usr/local/bin/bash
>> mount_smbfs //user at remotehost/share1/ /tmp/mnt/
>> mount_smbfs //user at remotehost/share2/ /tmp/mnt2/
> 
> Excuse me, it may just be a stupid question... but... why do
> you use bash for this purpose? Do you require any special
> bash feature that cannot be done using the standard shell,
> sh? I often see the urge to use bash for scripting as a
> typical "Linuxism", which is usually non-portable (if that
> was your goal). FreeBSD's standard scripting shell is sh,
> so why not use it until you reach the ends of its functionality?

The script above is a (heavily) reduced version, used to isolate the
problem. The real script is much longer, and uses a bunch of logic to
walk through a list of different systems (each with their own lists of
shares, loaded from external files), taking snapshots of the previous
backup, logging which systems were backed up, rolling back operations if
a backup fails, etc.

> Just a guess, regarding your initial question, as I don't have
> experience with "Windows" related things: Did you have the
> chance to monitor correct operations of your script in the
> past? Did the mound and umount (!) calls work properly? Have
> you checked your commands running them in the standard dialog
> shell (csh)? I assume you're running them as root (or at least
> with sufficient permissions), so I don't think the problem
> is there, as the error message
> 
> mount_smbfs: can't get handle to requester (no /dev/nsmb* device)
> 
> doesn't look like refering to that problem.

I am running it as root, and I just tried running the (test)script
(without the bash reference) under a csh shell, and got the same error,
so it's not a bash problem.

As for monitoring the operations of the script, it has worked fine
before (for several years), so I'm pretty sure the code is correct.

> 
> The error message originates from /usr/src/contrib/smbfs/lib/smb/ctx.c;
> having a look around, and remembering that you said
> 
>> [...] there are (by last count) 1170 /dev/nsmb* devices
>> in /dev/ (is that normal?)
> 
> I found smb_ctx_gethandle() near line 600 (version 7 OS here):
> 
>         /*
>          * well, no clone capabilities available - we have to scan
>          * all devices in order to get free one
>          */
>          for (i = 0; i < 1024; i++) {
>                  snprintf(buf, sizeof(buf), "/dev/%s%d", NSMB_NAME, i);
>                  fd = open(buf, O_RDWR);
>                  if (fd >= 0) {
>                         ctx->ct_fd = fd;
>                         return 0;
>                  }
>          }
> 
> The limit seems to be 1024, if I read that correctly - allthough
> I'm considered a "C hacker", I'm no "OS-level C hacker". :-)

Neither am I. Hadn't even thought of grepping in /usr/src for the error
message :-)

> 
> Afterwards, smb_ctx_lookup() fails and gives the error message
> mentioned earlier.
> 
> Remove the /dev/nsmb* devices and try again. Make sure no other
> SMB stuff is currently mounted, just to be sure, as I don't have
> any idea what could fail.
> 

Can I just `rm /dev/nsmbX` them? (messing in /dev/ is a level of FreeBSD
I'm not familiar with)

Thanks for all your help!

Bernard


More information about the freebsd-questions mailing list