s3:smbd: keep 'num_connections' and 'connections' directly under smbd_server_connection
authorStefan Metzmacher <metze@samba.org>
Sat, 3 Mar 2012 04:43:31 +0000 (05:43 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 6 Mar 2012 20:26:05 +0000 (21:26 +0100)
The plan is to have connection_struct as some kind of low level
abstraction for a smb1/smb2 tree connects, that can be used by SMB_VFS modules.

metze

source3/smbd/conn.c
source3/smbd/conn_idle.c
source3/smbd/globals.h
source3/smbd/msdfs.c
source3/smbd/smb2_tcon.c

index e17d374..12002e3 100644 (file)
@@ -37,7 +37,6 @@
 
 void conn_init(struct smbd_server_connection *sconn)
 {
-       sconn->smb1.tcons.Connections = NULL;
        sconn->smb1.tcons.bmap = bitmap_talloc(sconn, BITMAP_BLOCK_SZ);
 }
 
@@ -47,7 +46,7 @@ void conn_init(struct smbd_server_connection *sconn)
 
 int conn_num_open(struct smbd_server_connection *sconn)
 {
-       return sconn->num_tcons_open;
+       return sconn->num_connections;
 }
 
 /****************************************************************************
@@ -57,29 +56,14 @@ int conn_num_open(struct smbd_server_connection *sconn)
 bool conn_snum_used(struct smbd_server_connection *sconn,
                    int snum)
 {
-       if (sconn->using_smb2) {
-               /* SMB2 */
-               struct smbd_smb2_session *sess;
-               for (sess = sconn->smb2.sessions.list; sess; sess = sess->next) {
-                       struct smbd_smb2_tcon *ptcon;
-
-                       for (ptcon = sess->tcons.list; ptcon; ptcon = ptcon->next) {
-                               if (ptcon->compat_conn &&
-                                               ptcon->compat_conn->params &&
-                                               (ptcon->compat_conn->params->service == snum)) {
-                                       return true;
-                               }
-                       }
-               }
-       } else {
-               /* SMB1 */
-               connection_struct *conn;
-               for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next) {
-                       if (conn->params->service == snum) {
-                               return true;
-                       }
+       struct connection_struct *conn;
+
+       for (conn=sconn->connections; conn; conn=conn->next) {
+               if (conn->params->service == snum) {
+                       return true;
                }
        }
+
        return false;
 }
 
@@ -89,31 +73,15 @@ bool conn_snum_used(struct smbd_server_connection *sconn,
 
 connection_struct *conn_find(struct smbd_server_connection *sconn,unsigned cnum)
 {
-       if (sconn->using_smb2) {
-               /* SMB2 */
-               struct smbd_smb2_session *sess;
-               for (sess = sconn->smb2.sessions.list; sess; sess = sess->next) {
-                       struct smbd_smb2_tcon *ptcon;
-
-                       for (ptcon = sess->tcons.list; ptcon; ptcon = ptcon->next) {
-                               if (ptcon->compat_conn &&
-                                               ptcon->compat_conn->cnum == cnum) {
-                                       return ptcon->compat_conn;
-                               }
-                       }
-               }
-       } else {
-               /* SMB1 */
-               int count=0;
-               connection_struct *conn;
-               for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next,count++) {
-                       if (conn->cnum == cnum) {
-                               if (count > 10) {
-                                       DLIST_PROMOTE(sconn->smb1.tcons.Connections,
-                                               conn);
-                               }
-                               return conn;
+       size_t count=0;
+       struct connection_struct *conn;
+
+       for (conn=sconn->connections; conn; conn=conn->next,count++) {
+               if (conn->cnum == cnum) {
+                       if (count > 10) {
+                               DLIST_PROMOTE(sconn->connections, conn);
                        }
+                       return conn;
                }
        }
 
@@ -141,6 +109,10 @@ connection_struct *conn_new(struct smbd_server_connection *sconn)
                        return NULL;
                }
                conn->sconn = sconn;
+
+               DLIST_ADD(sconn->connections, conn);
+               sconn->num_connections++;
+
                return conn;
        }
 
@@ -201,12 +173,11 @@ find_again:
 
        bitmap_set(sconn->smb1.tcons.bmap, i);
 
-       sconn->num_tcons_open++;
-
        string_set(&conn->connectpath,"");
        string_set(&conn->origpath,"");
 
-       DLIST_ADD(sconn->smb1.tcons.Connections, conn);
+       DLIST_ADD(sconn->connections, conn);
+       sconn->num_connections++;
 
        return conn;
 }
@@ -264,29 +235,11 @@ void conn_clear_vuid_caches(struct smbd_server_connection *sconn,uint16_t vuid)
 {
        connection_struct *conn;
 
-       if (sconn->using_smb2) {
-               /* SMB2 */
-               struct smbd_smb2_session *sess;
-               for (sess = sconn->smb2.sessions.list; sess; sess = sess->next) {
-                       struct smbd_smb2_tcon *ptcon;
-
-                       for (ptcon = sess->tcons.list; ptcon; ptcon = ptcon->next) {
-                               if (ptcon->compat_conn) {
-                                       if (ptcon->compat_conn->vuid == vuid) {
-                                               ptcon->compat_conn->vuid = UID_FIELD_INVALID;
-                                       }
-                                       conn_clear_vuid_cache(ptcon->compat_conn, vuid);
-                               }
-                       }
-               }
-       } else {
-               /* SMB1 */
-               for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next) {
-                       if (conn->vuid == vuid) {
-                               conn->vuid = UID_FIELD_INVALID;
-                       }
-                       conn_clear_vuid_cache(conn, vuid);
+       for (conn=sconn->connections; conn;conn=conn->next) {
+               if (conn->vuid == vuid) {
+                       conn->vuid = UID_FIELD_INVALID;
                }
+               conn_clear_vuid_cache(conn, vuid);
        }
 }
 
@@ -339,16 +292,8 @@ void conn_free(connection_struct *conn)
                return;
        }
 
-       if (conn->sconn->using_smb2) {
-               /* SMB2 */
-               conn_free_internal(conn);
-               return;
-       }
-
-       /* SMB1 */
-       DLIST_REMOVE(conn->sconn->smb1.tcons.Connections, conn);
-
-       if (conn->sconn->smb1.tcons.bmap != NULL) {
+       if (!conn->sconn->using_smb2 &&
+           conn->sconn->smb1.tcons.bmap != NULL) {
                /*
                 * Can be NULL for fake connections created by
                 * create_conn_struct()
@@ -356,8 +301,9 @@ void conn_free(connection_struct *conn)
                bitmap_clear(conn->sconn->smb1.tcons.bmap, conn->cnum);
        }
 
-       SMB_ASSERT(conn->sconn->num_tcons_open > 0);
-       conn->sconn->num_tcons_open--;
+       DLIST_REMOVE(conn->sconn->connections, conn);
+       SMB_ASSERT(conn->sconn->num_connections > 0);
+       conn->sconn->num_connections--;
 
        conn_free_internal(conn);
 }
index c1949d3..dc213ea 100644 (file)
 
 static void conn_lastused_update(struct smbd_server_connection *sconn,time_t t)
 {
-       if (sconn->using_smb2) {
-               /* SMB2 */
-               struct smbd_smb2_session *sess;
-               for (sess = sconn->smb2.sessions.list; sess; sess = sess->next) {
-                       struct smbd_smb2_tcon *ptcon;
-
-                       for (ptcon = sess->tcons.list; ptcon; ptcon = ptcon->next) {
-                               connection_struct *conn = ptcon->compat_conn;
-                               /* Update if connection wasn't idle. */
-                               if (conn && conn->lastused != conn->lastused_count) {
-                                       conn->lastused = t;
-                                       conn->lastused_count = t;
-                               }
-                       }
-               }
-       } else {
-               /* SMB1 */
-               connection_struct *conn;
-               for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next) {
-                       /* Update if connection wasn't idle. */
-                       if (conn->lastused != conn->lastused_count) {
-                               conn->lastused = t;
-                               conn->lastused_count = t;
-                       }
+       struct connection_struct *conn;
+
+       for (conn=sconn->connections; conn; conn=conn->next) {
+               /* Update if connection wasn't idle. */
+               if (conn->lastused != conn->lastused_count) {
+                       conn->lastused = t;
+                       conn->lastused_count = t;
                }
        }
 }
@@ -65,6 +48,7 @@ static void conn_lastused_update(struct smbd_server_connection *sconn,time_t t)
 bool conn_idle_all(struct smbd_server_connection *sconn, time_t t)
 {
        int deadtime = lp_deadtime()*60;
+       struct connection_struct *conn;
 
        conn_lastused_update(sconn, t);
 
@@ -72,45 +56,16 @@ bool conn_idle_all(struct smbd_server_connection *sconn, time_t t)
                deadtime = DEFAULT_SMBD_TIMEOUT;
        }
 
-       if (sconn->using_smb2) {
-               /* SMB2 */
-               struct smbd_smb2_session *sess;
-               for (sess = sconn->smb2.sessions.list; sess; sess = sess->next) {
-                       struct smbd_smb2_tcon *ptcon;
-
-                       for (ptcon = sess->tcons.list; ptcon; ptcon = ptcon->next) {
-                               time_t age;
-                               connection_struct *conn = ptcon->compat_conn;
-
-                               if (conn == NULL) {
-                                       continue;
-                               }
+       for (conn=sconn->connections;conn;conn=conn->next) {
+               time_t age = t - conn->lastused;
 
-                               age = t - conn->lastused;
-                               /* close dirptrs on connections that are idle */
-                               if (age > DPTR_IDLE_TIMEOUT) {
-                                       dptr_idlecnum(conn);
-                               }
-
-                               if (conn->num_files_open > 0 || age < deadtime) {
-                                       return false;
-                               }
-                       }
+               /* close dirptrs on connections that are idle */
+               if (age > DPTR_IDLE_TIMEOUT) {
+                       dptr_idlecnum(conn);
                }
-       } else {
-               /* SMB1 */
-               connection_struct *conn;
-               for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next) {
-                       time_t age = t - conn->lastused;
 
-                       /* close dirptrs on connections that are idle */
-                       if (age > DPTR_IDLE_TIMEOUT) {
-                               dptr_idlecnum(conn);
-                       }
-
-                       if (conn->num_files_open > 0 || age < deadtime) {
-                               return false;
-                       }
+               if (conn->num_files_open > 0 || age < deadtime) {
+                       return false;
                }
        }
 
@@ -149,7 +104,7 @@ bool conn_close_all(struct smbd_server_connection *sconn)
                /* SMB1 */
                connection_struct *conn, *next;
 
-               for (conn=sconn->smb1.tcons.Connections;conn;conn=next) {
+               for (conn=sconn->connections;conn;conn=next) {
                        next=conn->next;
                        set_current_service(conn, 0, True);
                        close_cnum(conn, conn->vuid);
@@ -195,7 +150,7 @@ void conn_force_tdis(struct smbd_server_connection *sconn, const char *sharename
                }
        } else {
                /* SMB1 */
-               for (conn=sconn->smb1.tcons.Connections;conn;conn=next) {
+               for (conn=sconn->connections;conn;conn=next) {
                        next=conn->next;
                        if (strequal(lp_servicename(SNUM(conn)), sharename)) {
                                DEBUG(1,("Forcing close of share %s cnum=%d\n",
index b927e16..a47879f 100644 (file)
@@ -455,6 +455,9 @@ struct smbd_server_connection {
        size_t num_users;
        struct user_struct *users;
 
+       size_t num_connections;
+       struct connection_struct *connections;
+
        struct files_struct *files;
        struct bitmap *file_bmap;
        int real_max_open_files;
@@ -463,9 +466,6 @@ struct smbd_server_connection {
        unsigned long file_gen_counter;
        int first_file;
 
-       /* number of open connections (tcons) */
-       int num_tcons_open;
-
        struct pending_message_list *deferred_open_queue;
 
 
@@ -541,7 +541,6 @@ struct smbd_server_connection {
                        uint16_t next_vuid;
                } sessions;
                struct {
-                       connection_struct *Connections;
                        /* number of open connections */
                        struct bitmap *bmap;
                } tcons;
index 162b6df..7dc604c 100644 (file)
@@ -266,7 +266,8 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
        conn->cnum = (unsigned)-1;
 
        conn->sconn = sconn;
-       conn->sconn->num_tcons_open++;
+       DLIST_ADD(sconn->connections, conn);
+       conn->sconn->num_connections++;
 
        if (session_info != NULL) {
                conn->session_info = copy_session_info(conn, session_info);
index 56c4288..5f75e5e 100644 (file)
@@ -131,8 +131,6 @@ static int smbd_smb2_tcon_destructor(struct smbd_smb2_tcon *tcon)
 
        idr_remove(tcon->session->tcons.idtree, tcon->tid);
        DLIST_REMOVE(tcon->session->tcons.list, tcon);
-       SMB_ASSERT(tcon->session->sconn->num_tcons_open > 0);
-       tcon->session->sconn->num_tcons_open--;
 
        if (tcon->compat_conn) {
                set_current_service(tcon->compat_conn, 0, true);
@@ -226,7 +224,6 @@ static NTSTATUS smbd_smb2_tree_connect(struct smbd_smb2_request *req,
        DLIST_ADD_END(req->session->tcons.list, tcon,
                      struct smbd_smb2_tcon *);
        tcon->session = req->session;
-       tcon->session->sconn->num_tcons_open++;
        talloc_set_destructor(tcon, smbd_smb2_tcon_destructor);
 
        compat_conn = make_connection_smb2(req->sconn,