create_conn_struct_tos() and connection re-use

Jeremy Allison jra at samba.org
Fri Jun 22 21:15:35 UTC 2018


On Sat, Jun 23, 2018 at 08:57:35AM +1200, Andrew Bartlett via samba-technical wrote:
> On Fri, 2018-06-22 at 09:34 -0700, Jeremy Allison via samba-technical
> wrote:
> > On Fri, Jun 22, 2018 at 07:36:38AM +0200, Stefan Metzmacher via samba-technical wrote:
> > > Am 22.06.2018 um 07:25 schrieb Andrew Bartlett via samba-technical:
> > > > 
> > > > Why do we have functions like create_conn_struct_tos() then?
> > > 
> > > This is a special case! The code we had before was much worse
> > > it created connection_struct which did sometime chdir and forgot to
> > > chdir back and call VFS_DISCONNECT when done.
> > > 
> > > create_conn_struct_[cwd]_tos() is now only usable in one code block
> > > that starts with frame = talloc_stackframe() and ends with
> > > TALLOC_FREE(frame). This implements a restriction similar to
> > > become_root()/unbecome_root() which always be used as pair
> > > wrapping a specific shortterm section.
> > > 
> > > It's intended that the caller only have a change to control the lifetime
> > > of the connection_struct by using this pattern and hopefully don't
> > > find a ways to skip the destructor from being called.
> > 
> > Yes. I wrote the original (horrible) create_conn_struct() code
> > and Metze's changes are a *significant* improvement on that.
> > 
> > The original idea as Metze says was to create a temporary
> > conn struct valid only within a call stack to allow functions
> > to be called from the msdfs code.
> > 
> > It's much clearer using a talloc_tos() context.
> 
> OK.  I recently got asked to make samba-tool ntacl sysvolreset faster. 
> (Folks do this once after every rsync to keep their sysvol permissions
> in line, so it is really important to make fast). 
> 
> One thing that code did is call create_conn_struct() for every python
> function call, now replaced by create_conn_struct_tos(). 
> 
> Assuming this repeated setup is part of what is making this so slow
> (I've not checked yet, that will be step 0), what is the right way to
> set up a connection only once for this use case?

Looking at the python wrappers:

Each call does:

       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|z", discard_const_p(char *, kwnames),
                                         &fname, &security_info_wanted, &service)) {
                TALLOC_FREE(frame);
                return NULL;
        }

        conn = get_conn_tos(service);

so the char *service parameter can be different for
each call.

You'd have to create varients of the python wrappers that
guarantee a constant server name and hold the frame across
multiple calls.

Jeremy.




More information about the samba-technical mailing list