s3:smbd/files: split file_init_global() out of file_init()
authorStefan Metzmacher <metze@samba.org>
Thu, 24 May 2012 10:20:30 +0000 (12:20 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 24 May 2012 16:16:37 +0000 (18:16 +0200)
metze

source3/smbd/files.c
source3/smbd/proto.h

index ae340060398bf1e13ad95146522b00f3673fdce0..fcdd74029036a937ffd7766d9fe919614a3edf1e 100644 (file)
@@ -189,38 +189,59 @@ void file_close_pid(struct smbd_server_connection *sconn, uint16 smbpid,
  Initialise file structures.
 ****************************************************************************/
 
-bool file_init(struct smbd_server_connection *sconn)
+static int files_max_open_fds;
+
+bool file_init_global(void)
 {
-       int request_max_open_files = lp_max_open_files();
+       int request_max = lp_max_open_files();
        int real_lim;
+       int real_max;
+
+       if (files_max_open_fds != 0) {
+               return true;
+       }
 
        /*
         * Set the max_open files to be the requested
         * max plus a fudgefactor to allow for the extra
         * fd's we need such as log files etc...
         */
-       real_lim = set_maxfiles(request_max_open_files + MAX_OPEN_FUDGEFACTOR);
+       real_lim = set_maxfiles(request_max + MAX_OPEN_FUDGEFACTOR);
 
-       sconn->real_max_open_files = real_lim - MAX_OPEN_FUDGEFACTOR;
+       real_max = real_lim - MAX_OPEN_FUDGEFACTOR;
 
-       if (sconn->real_max_open_files + FILE_HANDLE_OFFSET + MAX_OPEN_PIPES
-           > 65536)
-               sconn->real_max_open_files =
-                       65536 - FILE_HANDLE_OFFSET - MAX_OPEN_PIPES;
+       if (real_max + FILE_HANDLE_OFFSET + MAX_OPEN_PIPES > 65536) {
+               real_max = 65536 - FILE_HANDLE_OFFSET - MAX_OPEN_PIPES;
+       }
 
-       if(sconn->real_max_open_files != request_max_open_files) {
-               DEBUG(1, ("file_init: Information only: requested %d "
+       if (real_max != request_max) {
+               DEBUG(1, ("file_init_global: Information only: requested %d "
                          "open files, %d are available.\n",
-                         request_max_open_files, sconn->real_max_open_files));
+                         request_max, real_max));
        }
 
-       SMB_ASSERT(sconn->real_max_open_files > 100);
+       SMB_ASSERT(real_max > 100);
 
-       sconn->file_bmap = bitmap_talloc(sconn, sconn->real_max_open_files);
+       files_max_open_fds = real_max;
+       return true;
+}
 
+bool file_init(struct smbd_server_connection *sconn)
+{
+       bool ok;
+
+       ok = file_init_global();
+       if (!ok) {
+               return false;
+       }
+
+       sconn->real_max_open_files = files_max_open_fds;
+
+       sconn->file_bmap = bitmap_talloc(sconn, sconn->real_max_open_files);
        if (!sconn->file_bmap) {
                return false;
        }
+
        return true;
 }
 
index 60f9a7d767f5906609c4f15c028f94015327e75e..30eed73f8dab8d3d474a5f51bfa3a8b98b0703c0 100644 (file)
@@ -369,6 +369,7 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
 void file_close_conn(connection_struct *conn);
 void file_close_pid(struct smbd_server_connection *sconn, uint16 smbpid,
                    int vuid);
+bool file_init_global(void);
 bool file_init(struct smbd_server_connection *sconn);
 void file_close_user(struct smbd_server_connection *sconn, int vuid);
 struct files_struct *files_forall(