From 127655cc888ac40332d4e8e5b94aab03f5120aae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Sat, 15 Aug 1998 07:27:34 +0000 Subject: this checkin gets rid of the global Files[] array and makes it local in files.c it should now be faily easy to expand the default MAX_OPEN_FILES to many thousands. (This used to be commit b088c804f98908eb02f05ab2f2e8a61691a0a582) --- source3/smbd/files.c | 321 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 source3/smbd/files.c (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c new file mode 100644 index 0000000000..a37d190f01 --- /dev/null +++ b/source3/smbd/files.c @@ -0,0 +1,321 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Files[] structure handling + Copyright (C) Andrew Tridgell 1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +#define MAX_OPEN_FILES 100 + +#define MAX_FNUMS (MAX_OPEN_FILES+MAX_OPEN_DIRECTORIES) +#define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < MAX_FNUMS)) + +static files_struct Files[MAX_FNUMS]; + +/* + * Indirection for file fd's. Needed as POSIX locking + * is based on file/process, not fd/process. + */ +static file_fd_struct FileFd[MAX_OPEN_FILES]; +static int max_file_fd_used = 0; + + +/**************************************************************************** + find first available file slot +****************************************************************************/ +files_struct *find_free_file(void ) +{ + int i; + static int first_file; + + /* we want to give out file handles differently on each new + connection because of a common bug in MS clients where they try to + reuse a file descriptor from an earlier smb connection. This code + increases the chance that the errant client will get an error rather + than causing corruption */ + if (first_file == 0) { + first_file = (getpid() ^ (int)time(NULL)) % MAX_FNUMS; + if (first_file == 0) first_file = 1; + } + + if (first_file >= MAX_FNUMS) + first_file = 1; + + for (i=first_file;i<MAX_FNUMS;i++) + if (!Files[i].open && !Files[i].reserved) { + memset(&Files[i], 0, sizeof(Files[i])); + first_file = i+1; + Files[i].reserved = True; + Files[i].fnum = i; + return &Files[i]; + } + + /* returning a file handle of 0 is a bad idea - so we start at 1 */ + for (i=1;i<first_file;i++) + if (!Files[i].open && !Files[i].reserved) { + memset(&Files[i], 0, sizeof(Files[i])); + first_file = i+1; + Files[i].reserved = True; + Files[i].fnum = i; + return &Files[i]; + } + + /* + * Before we give up, go through the open files + * and see if there are any files opened with a + * batch oplock. If so break the oplock and then + * re-use that entry (if it becomes closed). + * This may help as NT/95 clients tend to keep + * files batch oplocked for quite a long time + * after they have finished with them. + */ + for (i=first_file;i<MAX_FNUMS;i++) { + if(attempt_close_oplocked_file( &Files[i])) { + memset(&Files[i], 0, sizeof(Files[i])); + first_file = i+1; + Files[i].reserved = True; + Files[i].fnum = i; + return &Files[i]; + } + } + + for (i=1;i<MAX_FNUMS;i++) { + if(attempt_close_oplocked_file( &Files[i])) { + memset(&Files[i], 0, sizeof(Files[i])); + first_file = i+1; + Files[i].reserved = True; + Files[i].fnum = i; + return &Files[i]; + } + } + + DEBUG(1,("ERROR! Out of file structures - perhaps increase MAX_OPEN_FILES?\n")); + return NULL; +} + + + +/**************************************************************************** +fd support routines - attempt to find an already open file by dev +and inode - increments the ref_count of the returned file_fd_struct *. +****************************************************************************/ +file_fd_struct *fd_get_already_open(struct stat *sbuf) +{ + int i; + file_fd_struct *fd_ptr; + + if(sbuf == 0) + return 0; + + for(i = 0; i <= max_file_fd_used; i++) { + fd_ptr = &FileFd[i]; + if((fd_ptr->ref_count > 0) && + (((uint32)sbuf->st_dev) == fd_ptr->dev) && + (((uint32)sbuf->st_ino) == fd_ptr->inode)) { + fd_ptr->ref_count++; + DEBUG(3, + ("Re-used file_fd_struct %d, dev = %x, inode = %x, ref_count = %d\n", + i, fd_ptr->dev, fd_ptr->inode, fd_ptr->ref_count)); + return fd_ptr; + } + } + return 0; +} + +/**************************************************************************** +fd support routines - attempt to find a empty slot in the FileFd array. +Increments the ref_count of the returned entry. +****************************************************************************/ +file_fd_struct *fd_get_new(void) +{ + extern struct current_user current_user; + int i; + file_fd_struct *fd_ptr; + + for(i = 0; i < MAX_OPEN_FILES; i++) { + fd_ptr = &FileFd[i]; + if(fd_ptr->ref_count == 0) { + fd_ptr->dev = (uint32)-1; + fd_ptr->inode = (uint32)-1; + fd_ptr->fd = -1; + fd_ptr->fd_readonly = -1; + fd_ptr->fd_writeonly = -1; + fd_ptr->real_open_flags = -1; + fd_ptr->uid_cache_count = 0; + fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid); + fd_ptr->ref_count++; + /* Increment max used counter if neccessary, cuts down + on search time when re-using */ + if(i > max_file_fd_used) + max_file_fd_used = i; + DEBUG(3,("Allocated new file_fd_struct %d, dev = %x, inode = %x\n", + i, fd_ptr->dev, fd_ptr->inode)); + return fd_ptr; + } + } + DEBUG(1,("ERROR! Out of file_fd structures - perhaps increase MAX_OPEN_FILES?\n")); + return 0; +} + + +/**************************************************************************** +close all open files for a connection +****************************************************************************/ +void file_close_conn(connection_struct *conn) +{ + int i; + for (i=0;i<MAX_FNUMS;i++) + if (Files[i].conn == conn && Files[i].open) { + if(Files[i].is_directory) + close_directory(&Files[i]); + else + close_file(&Files[i],False); + } +} + +/**************************************************************************** +initialise file structures +****************************************************************************/ +void file_init(void) +{ + int i; + +#ifdef HAVE_GETRLIMIT +#ifdef RLIMIT_NOFILE + { + struct rlimit rlp; + getrlimit(RLIMIT_NOFILE, &rlp); + /* Set the fd limit to be MAX_OPEN_FILES + 10 to + * account for the extra fd we need to read + * directories, as well as the log files and standard + * handles etc. */ + rlp.rlim_cur = (MAX_FNUMS+10>rlp.rlim_max)? + rlp.rlim_max:MAX_FNUMS+10; + setrlimit(RLIMIT_NOFILE, &rlp); + getrlimit(RLIMIT_NOFILE, &rlp); + DEBUG(3,("Maximum number of open files per session is %d\n", + (int)rlp.rlim_cur)); + } +#endif +#endif + + + + for (i=0;i<MAX_FNUMS;i++) { + Files[i].open = False; + string_init(&Files[i].fsp_name,""); + } + + for (i=0;i<MAX_OPEN_FILES;i++) { + file_fd_struct *fd_ptr = &FileFd[i]; + fd_ptr->ref_count = 0; + fd_ptr->dev = (int32)-1; + fd_ptr->inode = (int32)-1; + fd_ptr->fd = -1; + fd_ptr->fd_readonly = -1; + fd_ptr->fd_writeonly = -1; + fd_ptr->real_open_flags = -1; + } +} + +/**************************************************************************** +find a fsp given a fnum +****************************************************************************/ +files_struct *file_fsp(int fnum) +{ + if (!VALID_FNUM(fnum)) return NULL; + return &Files[fnum]; +} + + +/**************************************************************************** +close files open by a specified vuid +****************************************************************************/ +void file_close_user(int vuid) +{ + int i; + for (i=0;i<MAX_FNUMS;i++) { + files_struct *fsp = &Files[i]; + if ((fsp->vuid == vuid) && fsp->open) { + if(!fsp->is_directory) + close_file(fsp,False); + else + close_directory(fsp); + } + } +} + + +/**************************************************************************** +find a fsp given a device, inode and timevalue +****************************************************************************/ +files_struct *file_find_dit(int dev, int inode, struct timeval *tval) +{ + int i; + for (i=0;i<MAX_FNUMS;i++) { + files_struct *fsp = &Files[i]; + if (fsp->open && + fsp->fd_ptr->dev == dev && + fsp->fd_ptr->inode == inode && + fsp->open_time.tv_sec == tval->tv_sec && + fsp->open_time.tv_usec == tval->tv_usec) { + return fsp; + } + } + return NULL; +} + +/**************************************************************************** +find a fsp that is open for printing +****************************************************************************/ +files_struct *file_find_print(void) +{ + int i; + + for (i=0;i<MAX_FNUMS;i++) { + files_struct *fsp = &Files[i]; + if (fsp->open && fsp->print_file) { + return fsp; + } + } + return NULL; +} + + +/**************************************************************************** +sync open files on a connection +****************************************************************************/ +void file_sync_all(connection_struct *conn) +{ + int i; + for (i=0;i<MAX_FNUMS;i++) { + files_struct *fsp = &Files[i]; + if (fsp->open && conn == fsp->conn) { + sync_file(conn,fsp); + } + } +} + + +void file_free(files_struct *fsp) +{ + memset(fsp, 0, sizeof(*fsp)); +} -- cgit From 6a6e8958ad86d61395d9ad47a0c2bef732d07b13 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Sun, 16 Aug 1998 02:32:55 +0000 Subject: changed find_free_file() to file_new(). (This used to be commit 3daee29636dcb2d99a0e7c08179a098befae00dc) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index a37d190f01..04aff67a15 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -41,7 +41,7 @@ static int max_file_fd_used = 0; /**************************************************************************** find first available file slot ****************************************************************************/ -files_struct *find_free_file(void ) +files_struct *file_new(void ) { int i; static int first_file; -- cgit From 739d0b1ddc58bbb792c3eebe8c545602a4fae438 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Sun, 16 Aug 1998 04:08:47 +0000 Subject: got rid of the Files[] array completely (previously I'd just made it private to files.c) It now is a doubly linked list with a bitmap for allocated file numbers. Similarly for the fd_ptr code. I also changed the default maximum number of open files to 4096. The static cost is 1 bit per file. It all seems to work, and it passes the "does Sue scream" test, but if you see weird behaviour then please investigate. With the volume of new code that has gone in there are bound to be one or two bugs lurking. note that you must do a "make clean" before building this as many data structures have changed in size. (This used to be commit 79755ce97004b787d7e83a8d18fc4c7c003b7231) --- source3/smbd/files.c | 353 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 207 insertions(+), 146 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 04aff67a15..66fbaebeb0 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -23,20 +23,23 @@ extern int DEBUGLEVEL; -#define MAX_OPEN_FILES 100 +/* the only restriction is that this must be less than PIPE_HANDLE_OFFSET */ +#define MAX_FNUMS 4096 -#define MAX_FNUMS (MAX_OPEN_FILES+MAX_OPEN_DIRECTORIES) #define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < MAX_FNUMS)) -static files_struct Files[MAX_FNUMS]; +static struct bitmap *file_bmap; +static struct bitmap *fd_bmap; + +static files_struct *Files; /* * Indirection for file fd's. Needed as POSIX locking * is based on file/process, not fd/process. */ -static file_fd_struct FileFd[MAX_OPEN_FILES]; -static int max_file_fd_used = 0; +static file_fd_struct *FileFd; +static int files_used, fd_ptr_used; /**************************************************************************** find first available file slot @@ -45,6 +48,7 @@ files_struct *file_new(void ) { int i; static int first_file; + files_struct *fsp; /* we want to give out file handles differently on each new connection because of a common bug in MS clients where they try to @@ -56,59 +60,55 @@ files_struct *file_new(void ) if (first_file == 0) first_file = 1; } - if (first_file >= MAX_FNUMS) + if (first_file >= MAX_FNUMS) { first_file = 1; + } - for (i=first_file;i<MAX_FNUMS;i++) - if (!Files[i].open && !Files[i].reserved) { - memset(&Files[i], 0, sizeof(Files[i])); - first_file = i+1; - Files[i].reserved = True; - Files[i].fnum = i; - return &Files[i]; + i = bitmap_find(file_bmap, first_file); + if (i == -1) { + /* + * Before we give up, go through the open files + * and see if there are any files opened with a + * batch oplock. If so break the oplock and then + * re-use that entry (if it becomes closed). + * This may help as NT/95 clients tend to keep + * files batch oplocked for quite a long time + * after they have finished with them. + */ + for (fsp=Files;fsp;fsp=fsp->next) { + if (attempt_close_oplocked_file(fsp)) { + return file_new(); + } } - /* returning a file handle of 0 is a bad idea - so we start at 1 */ - for (i=1;i<first_file;i++) - if (!Files[i].open && !Files[i].reserved) { - memset(&Files[i], 0, sizeof(Files[i])); - first_file = i+1; - Files[i].reserved = True; - Files[i].fnum = i; - return &Files[i]; - } + DEBUG(0,("ERROR! Out of file structures\n")); + return NULL; + } - /* - * Before we give up, go through the open files - * and see if there are any files opened with a - * batch oplock. If so break the oplock and then - * re-use that entry (if it becomes closed). - * This may help as NT/95 clients tend to keep - * files batch oplocked for quite a long time - * after they have finished with them. - */ - for (i=first_file;i<MAX_FNUMS;i++) { - if(attempt_close_oplocked_file( &Files[i])) { - memset(&Files[i], 0, sizeof(Files[i])); - first_file = i+1; - Files[i].reserved = True; - Files[i].fnum = i; - return &Files[i]; - } - } - - for (i=1;i<MAX_FNUMS;i++) { - if(attempt_close_oplocked_file( &Files[i])) { - memset(&Files[i], 0, sizeof(Files[i])); - first_file = i+1; - Files[i].reserved = True; - Files[i].fnum = i; - return &Files[i]; - } - } - - DEBUG(1,("ERROR! Out of file structures - perhaps increase MAX_OPEN_FILES?\n")); - return NULL; + fsp = (files_struct *)malloc(sizeof(*fsp)); + if (!fsp) return NULL; + + memset(fsp, 0, sizeof(*fsp)); + first_file = i+1; + fsp->fnum = i; + string_init(&fsp->fsp_name,""); + + bitmap_set(file_bmap, i); + files_used++; + + /* hook into the front of the list */ + if (!Files) { + Files = fsp; + } else { + Files->prev = fsp; + fsp->next = Files; + Files = fsp; + } + + DEBUG(5,("allocated file structure %d (%d used)\n", + i, files_used)); + + return fsp; } @@ -119,60 +119,74 @@ and inode - increments the ref_count of the returned file_fd_struct *. ****************************************************************************/ file_fd_struct *fd_get_already_open(struct stat *sbuf) { - int i; - file_fd_struct *fd_ptr; - - if(sbuf == 0) - return 0; - - for(i = 0; i <= max_file_fd_used; i++) { - fd_ptr = &FileFd[i]; - if((fd_ptr->ref_count > 0) && - (((uint32)sbuf->st_dev) == fd_ptr->dev) && - (((uint32)sbuf->st_ino) == fd_ptr->inode)) { - fd_ptr->ref_count++; - DEBUG(3, - ("Re-used file_fd_struct %d, dev = %x, inode = %x, ref_count = %d\n", - i, fd_ptr->dev, fd_ptr->inode, fd_ptr->ref_count)); - return fd_ptr; - } - } - return 0; + file_fd_struct *fd_ptr; + + if(!sbuf) return NULL; + + for (fd_ptr=FileFd;fd_ptr;fd_ptr=fd_ptr->next) { + if ((fd_ptr->ref_count > 0) && + (((uint32)sbuf->st_dev) == fd_ptr->dev) && + (((uint32)sbuf->st_ino) == fd_ptr->inode)) { + fd_ptr->ref_count++; + DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %x, ref_count = %d\n", + fd_ptr->dev, fd_ptr->inode, + fd_ptr->ref_count)); + return fd_ptr; + } + } + + return NULL; } + + /**************************************************************************** fd support routines - attempt to find a empty slot in the FileFd array. Increments the ref_count of the returned entry. ****************************************************************************/ file_fd_struct *fd_get_new(void) { - extern struct current_user current_user; - int i; - file_fd_struct *fd_ptr; - - for(i = 0; i < MAX_OPEN_FILES; i++) { - fd_ptr = &FileFd[i]; - if(fd_ptr->ref_count == 0) { - fd_ptr->dev = (uint32)-1; - fd_ptr->inode = (uint32)-1; - fd_ptr->fd = -1; - fd_ptr->fd_readonly = -1; - fd_ptr->fd_writeonly = -1; - fd_ptr->real_open_flags = -1; - fd_ptr->uid_cache_count = 0; - fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid); - fd_ptr->ref_count++; - /* Increment max used counter if neccessary, cuts down - on search time when re-using */ - if(i > max_file_fd_used) - max_file_fd_used = i; - DEBUG(3,("Allocated new file_fd_struct %d, dev = %x, inode = %x\n", - i, fd_ptr->dev, fd_ptr->inode)); - return fd_ptr; - } - } - DEBUG(1,("ERROR! Out of file_fd structures - perhaps increase MAX_OPEN_FILES?\n")); - return 0; + extern struct current_user current_user; + int i; + file_fd_struct *fd_ptr; + + i = bitmap_find(fd_bmap, 1); + if (i == -1) { + DEBUG(0,("ERROR! Out of file_fd structures\n")); + return NULL; + } + + fd_ptr = (file_fd_struct *)malloc(sizeof(*fd_ptr)); + if (!fd_ptr) return NULL; + + memset(fd_ptr, 0, sizeof(*fd_ptr)); + + fd_ptr->fdnum = i; + fd_ptr->dev = (uint32)-1; + fd_ptr->inode = (uint32)-1; + fd_ptr->fd = -1; + fd_ptr->fd_readonly = -1; + fd_ptr->fd_writeonly = -1; + fd_ptr->real_open_flags = -1; + fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid); + fd_ptr->ref_count++; + + bitmap_set(fd_bmap, i); + fd_ptr_used++; + + /* hook into the front of the list */ + if (!FileFd) { + FileFd = fd_ptr; + } else { + FileFd->prev = fd_ptr; + fd_ptr->next = FileFd; + FileFd = fd_ptr; + } + + DEBUG(5,("allocated fd_ptr structure %d (%d used)\n", + i, fd_ptr_used)); + + return fd_ptr; } @@ -181,14 +195,16 @@ close all open files for a connection ****************************************************************************/ void file_close_conn(connection_struct *conn) { - int i; - for (i=0;i<MAX_FNUMS;i++) - if (Files[i].conn == conn && Files[i].open) { - if(Files[i].is_directory) - close_directory(&Files[i]); - else - close_file(&Files[i],False); - } + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp->conn == conn && fsp->open) { + if (fsp->is_directory) + close_directory(fsp); + else + close_file(fsp,False); + } + } } /**************************************************************************** @@ -196,10 +212,14 @@ initialise file structures ****************************************************************************/ void file_init(void) { - int i; + file_bmap = bitmap_allocate(MAX_FNUMS); + fd_bmap = bitmap_allocate(MAX_FNUMS); + + if (!file_bmap || !fd_bmap) { + exit_server("out of memory in file_init"); + } -#ifdef HAVE_GETRLIMIT -#ifdef RLIMIT_NOFILE +#if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)) { struct rlimit rlp; getrlimit(RLIMIT_NOFILE, &rlp); @@ -215,34 +235,23 @@ void file_init(void) (int)rlp.rlim_cur)); } #endif -#endif - - - - for (i=0;i<MAX_FNUMS;i++) { - Files[i].open = False; - string_init(&Files[i].fsp_name,""); - } - - for (i=0;i<MAX_OPEN_FILES;i++) { - file_fd_struct *fd_ptr = &FileFd[i]; - fd_ptr->ref_count = 0; - fd_ptr->dev = (int32)-1; - fd_ptr->inode = (int32)-1; - fd_ptr->fd = -1; - fd_ptr->fd_readonly = -1; - fd_ptr->fd_writeonly = -1; - fd_ptr->real_open_flags = -1; - } } + /**************************************************************************** find a fsp given a fnum ****************************************************************************/ files_struct *file_fsp(int fnum) { + files_struct *fsp; + if (!VALID_FNUM(fnum)) return NULL; - return &Files[fnum]; + + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp->fnum == fnum) return fsp; + } + + return NULL; } @@ -251,9 +260,9 @@ close files open by a specified vuid ****************************************************************************/ void file_close_user(int vuid) { - int i; - for (i=0;i<MAX_FNUMS;i++) { - files_struct *fsp = &Files[i]; + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next) { if ((fsp->vuid == vuid) && fsp->open) { if(!fsp->is_directory) close_file(fsp,False); @@ -269,9 +278,9 @@ find a fsp given a device, inode and timevalue ****************************************************************************/ files_struct *file_find_dit(int dev, int inode, struct timeval *tval) { - int i; - for (i=0;i<MAX_FNUMS;i++) { - files_struct *fsp = &Files[i]; + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next) { if (fsp->open && fsp->fd_ptr->dev == dev && fsp->fd_ptr->inode == inode && @@ -279,22 +288,21 @@ files_struct *file_find_dit(int dev, int inode, struct timeval *tval) fsp->open_time.tv_usec == tval->tv_usec) { return fsp; } - } + } + return NULL; } + /**************************************************************************** find a fsp that is open for printing ****************************************************************************/ files_struct *file_find_print(void) { - int i; + files_struct *fsp; - for (i=0;i<MAX_FNUMS;i++) { - files_struct *fsp = &Files[i]; - if (fsp->open && fsp->print_file) { - return fsp; - } + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp->open && fsp->print_file) return fsp; } return NULL; } @@ -305,9 +313,9 @@ sync open files on a connection ****************************************************************************/ void file_sync_all(connection_struct *conn) { - int i; - for (i=0;i<MAX_FNUMS;i++) { - files_struct *fsp = &Files[i]; + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next) { if (fsp->open && conn == fsp->conn) { sync_file(conn,fsp); } @@ -315,7 +323,60 @@ void file_sync_all(connection_struct *conn) } +/**************************************************************************** +free up a fd_ptr +****************************************************************************/ +static void fd_ptr_free(file_fd_struct *fd_ptr) +{ + if (fd_ptr == FileFd) { + FileFd = fd_ptr->next; + if (FileFd) FileFd->prev = NULL; + } else { + fd_ptr->prev->next = fd_ptr->next; + if (fd_ptr->next) fd_ptr->next->prev = fd_ptr->prev; + } + + bitmap_clear(fd_bmap, fd_ptr->fdnum); + fd_ptr_used--; + + DEBUG(5,("freed fd_ptr structure %d (%d used)\n", + fd_ptr->fdnum, fd_ptr_used)); + + /* paranoia */ + memset(fd_ptr, 0, sizeof(*fd_ptr)); + + free(fd_ptr); +} + + +/**************************************************************************** +free up a fsp +****************************************************************************/ void file_free(files_struct *fsp) { + if (fsp == Files) { + Files = fsp->next; + if (Files) Files->prev = NULL; + } else { + fsp->prev->next = fsp->next; + if (fsp->next) fsp->next->prev = fsp->prev; + } + + string_free(&fsp->fsp_name); + + if (fsp->fd_ptr && fsp->fd_ptr->ref_count == 0) { + fd_ptr_free(fsp->fd_ptr); + } + + bitmap_clear(file_bmap, fsp->fnum); + files_used--; + + DEBUG(5,("freed files structure %d (%d used)\n", + fsp->fnum, files_used)); + + /* this is paranoia, just in case someone tries to reuse the + information */ memset(fsp, 0, sizeof(*fsp)); + + free(fsp); } -- cgit From b590b27b45725993335c6c1f110bf1a9bb56513b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Sun, 16 Aug 1998 06:20:18 +0000 Subject: - some tidying up in files.c - handle null fsp in DEBUG() at end of reply_ntcreate_and_X(). Jeremy, can you fix this properly? - get snum right in print queue code in ipc.c (it was broken by my connections_struct changes). (This used to be commit b3dd3785751db2d5d0a80ffac9c3df01c9909891) --- source3/smbd/files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 66fbaebeb0..8f1cefbbb6 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -223,9 +223,9 @@ void file_init(void) { struct rlimit rlp; getrlimit(RLIMIT_NOFILE, &rlp); - /* Set the fd limit to be MAX_OPEN_FILES + 10 to - * account for the extra fd we need to read - * directories, as well as the log files and standard + /* Set the fd limit to be MAX_FNUMS + 10 to + * account for the extra fd we need + * as well as the log files and standard * handles etc. */ rlp.rlim_cur = (MAX_FNUMS+10>rlp.rlim_max)? rlp.rlim_max:MAX_FNUMS+10; -- cgit From f2d538a105a61ce6d2852700fc328e15ac158827 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 17 Aug 1998 03:06:20 +0000 Subject: some cleanups from the conversion of Pipes[] to a linked list. I also removed most cases where a pnum is used and substituted a pipes_struct*. in files.c I added a offset of 0x1000 to all file handles on the wire. This makes it much less likely that bad parsing will give us the wrong field. (This used to be commit 8bc2627ff28d340db65bfa017daca2dc291d5ef7) --- source3/smbd/files.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 8f1cefbbb6..bc3ea880bf 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -28,6 +28,8 @@ extern int DEBUGLEVEL; #define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < MAX_FNUMS)) +#define FILE_HANDLE_OFFSET 0x1000 + static struct bitmap *file_bmap; static struct bitmap *fd_bmap; @@ -57,11 +59,6 @@ files_struct *file_new(void ) than causing corruption */ if (first_file == 0) { first_file = (getpid() ^ (int)time(NULL)) % MAX_FNUMS; - if (first_file == 0) first_file = 1; - } - - if (first_file >= MAX_FNUMS) { - first_file = 1; } i = bitmap_find(file_bmap, first_file); @@ -89,12 +86,14 @@ files_struct *file_new(void ) if (!fsp) return NULL; memset(fsp, 0, sizeof(*fsp)); - first_file = i+1; - fsp->fnum = i; - string_init(&fsp->fsp_name,""); + + first_file = (i+1) % MAX_FNUMS; bitmap_set(file_bmap, i); files_used++; + + fsp->fnum = i + FILE_HANDLE_OFFSET; + string_init(&fsp->fsp_name,""); /* hook into the front of the list */ if (!Files) { @@ -245,8 +244,6 @@ files_struct *file_fsp(int fnum) { files_struct *fsp; - if (!VALID_FNUM(fnum)) return NULL; - for (fsp=Files;fsp;fsp=fsp->next) { if (fsp->fnum == fnum) return fsp; } @@ -368,7 +365,7 @@ void file_free(files_struct *fsp) fd_ptr_free(fsp->fd_ptr); } - bitmap_clear(file_bmap, fsp->fnum); + bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; DEBUG(5,("freed files structure %d (%d used)\n", -- cgit From 8978aae69699ccab76fdf95037948b1cc7e7c286 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 17 Aug 1998 03:52:05 +0000 Subject: much cleaner chain pointer handling for both files and pipes. the chain pointer is now stored as a static and is set whenever a handle is created or extracted. This also makes the code less error prone. (This used to be commit 068a862982bea726e8d7b1b4065d510b9840a272) --- source3/smbd/files.c | 55 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index bc3ea880bf..e66e53e6ed 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -35,6 +35,10 @@ static struct bitmap *fd_bmap; static files_struct *Files; +/* a fsp to use when chaining */ +static files_struct *chain_fsp = NULL; + + /* * Indirection for file fd's. Needed as POSIX locking * is based on file/process, not fd/process. @@ -106,6 +110,8 @@ files_struct *file_new(void ) DEBUG(5,("allocated file structure %d (%d used)\n", i, files_used)); + + chain_fsp = fsp; return fsp; } @@ -237,21 +243,6 @@ void file_init(void) } -/**************************************************************************** -find a fsp given a fnum -****************************************************************************/ -files_struct *file_fsp(int fnum) -{ - files_struct *fsp; - - for (fsp=Files;fsp;fsp=fsp->next) { - if (fsp->fnum == fnum) return fsp; - } - - return NULL; -} - - /**************************************************************************** close files open by a specified vuid ****************************************************************************/ @@ -375,5 +366,39 @@ void file_free(files_struct *fsp) information */ memset(fsp, 0, sizeof(*fsp)); + if (fsp == chain_fsp) chain_fsp = NULL; + free(fsp); } + + +/**************************************************************************** +get a fsp from a packet given the offset of a 16 bit fnum +****************************************************************************/ +files_struct *file_fsp(char *buf, int where) +{ + int fnum; + files_struct *fsp; + + if (chain_fsp) return chain_fsp; + + fnum = SVAL(buf, where); + + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp->fnum == fnum) { + chain_fsp = fsp; + return fsp; + } + } + + return NULL; +} + + +/**************************************************************************** +reset the chained fsp - done at the start of a packet reply +****************************************************************************/ +void file_chain_reset(void) +{ + chain_fsp = NULL; +} -- cgit From 983dc71c9844675ad364f3ea59ddd04b87857b55 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 17 Aug 1998 06:13:32 +0000 Subject: moved connection_struct handling code into smbd/conn.c and changed it to a linked list with bitmap format. (This used to be commit b7aaab1b6b2d2f72b2bb7c11f5c7bf081a6093d9) --- source3/smbd/files.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e66e53e6ed..7bd5501de5 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -54,7 +54,7 @@ files_struct *file_new(void ) { int i; static int first_file; - files_struct *fsp; + files_struct *fsp, *next; /* we want to give out file handles differently on each new connection because of a common bug in MS clients where they try to @@ -76,7 +76,8 @@ files_struct *file_new(void ) * files batch oplocked for quite a long time * after they have finished with them. */ - for (fsp=Files;fsp;fsp=fsp->next) { + for (fsp=Files;fsp;fsp=next) { + next=fsp->next; if (attempt_close_oplocked_file(fsp)) { return file_new(); } @@ -200,9 +201,10 @@ close all open files for a connection ****************************************************************************/ void file_close_conn(connection_struct *conn) { - files_struct *fsp; + files_struct *fsp, *next; - for (fsp=Files;fsp;fsp=fsp->next) { + for (fsp=Files;fsp;fsp=next) { + next = fsp->next; if (fsp->conn == conn && fsp->open) { if (fsp->is_directory) close_directory(fsp); @@ -248,9 +250,10 @@ close files open by a specified vuid ****************************************************************************/ void file_close_user(int vuid) { - files_struct *fsp; + files_struct *fsp, *next; - for (fsp=Files;fsp;fsp=fsp->next) { + for (fsp=Files;fsp;fsp=next) { + next=fsp->next; if ((fsp->vuid == vuid) && fsp->open) { if(!fsp->is_directory) close_file(fsp,False); @@ -301,9 +304,10 @@ sync open files on a connection ****************************************************************************/ void file_sync_all(connection_struct *conn) { - files_struct *fsp; + files_struct *fsp, *next; - for (fsp=Files;fsp;fsp=fsp->next) { + for (fsp=Files;fsp;fsp=next) { + next=fsp->next; if (fsp->open && conn == fsp->conn) { sync_file(conn,fsp); } -- cgit From 72ed7049d88e5296ebec362189e62a384385ad34 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 17 Aug 1998 06:47:53 +0000 Subject: added some optimisation for the case where the number of open files is very large. files.c now promotes a files_struct to the top of the list if it is used when it is more than 10 elements from the top. also moved common linked list code for the 5 sets of linked lists that I've created over the past few days into dlinklist.h (I've explained to Chris why I didn't use the ubiqx code) (This used to be commit 1eb9ae2996b5a243a147f485e7e353d54f820852) --- source3/smbd/files.c | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 7bd5501de5..fa1b8f3bac 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -100,14 +100,7 @@ files_struct *file_new(void ) fsp->fnum = i + FILE_HANDLE_OFFSET; string_init(&fsp->fsp_name,""); - /* hook into the front of the list */ - if (!Files) { - Files = fsp; - } else { - Files->prev = fsp; - fsp->next = Files; - Files = fsp; - } + DLIST_ADD(Files, fsp); DEBUG(5,("allocated file structure %d (%d used)\n", i, files_used)); @@ -180,14 +173,7 @@ file_fd_struct *fd_get_new(void) bitmap_set(fd_bmap, i); fd_ptr_used++; - /* hook into the front of the list */ - if (!FileFd) { - FileFd = fd_ptr; - } else { - FileFd->prev = fd_ptr; - fd_ptr->next = FileFd; - FileFd = fd_ptr; - } + DLIST_ADD(FileFd, fd_ptr); DEBUG(5,("allocated fd_ptr structure %d (%d used)\n", i, fd_ptr_used)); @@ -269,14 +255,18 @@ find a fsp given a device, inode and timevalue ****************************************************************************/ files_struct *file_find_dit(int dev, int inode, struct timeval *tval) { + int count=0; files_struct *fsp; - for (fsp=Files;fsp;fsp=fsp->next) { + for (fsp=Files;fsp;fsp=fsp->next,count++) { if (fsp->open && fsp->fd_ptr->dev == dev && fsp->fd_ptr->inode == inode && fsp->open_time.tv_sec == tval->tv_sec && fsp->open_time.tv_usec == tval->tv_usec) { + if (count > 10) { + DLIST_PROMOTE(Files, fsp); + } return fsp; } } @@ -320,13 +310,7 @@ free up a fd_ptr ****************************************************************************/ static void fd_ptr_free(file_fd_struct *fd_ptr) { - if (fd_ptr == FileFd) { - FileFd = fd_ptr->next; - if (FileFd) FileFd->prev = NULL; - } else { - fd_ptr->prev->next = fd_ptr->next; - if (fd_ptr->next) fd_ptr->next->prev = fd_ptr->prev; - } + DLIST_REMOVE(FileFd, fd_ptr); bitmap_clear(fd_bmap, fd_ptr->fdnum); fd_ptr_used--; @@ -346,13 +330,7 @@ free up a fsp ****************************************************************************/ void file_free(files_struct *fsp) { - if (fsp == Files) { - Files = fsp->next; - if (Files) Files->prev = NULL; - } else { - fsp->prev->next = fsp->next; - if (fsp->next) fsp->next->prev = fsp->prev; - } + DLIST_REMOVE(Files, fsp); string_free(&fsp->fsp_name); @@ -381,16 +359,19 @@ get a fsp from a packet given the offset of a 16 bit fnum ****************************************************************************/ files_struct *file_fsp(char *buf, int where) { - int fnum; + int fnum, count=0; files_struct *fsp; if (chain_fsp) return chain_fsp; fnum = SVAL(buf, where); - for (fsp=Files;fsp;fsp=fsp->next) { + for (fsp=Files;fsp;fsp=fsp->next, count++) { if (fsp->fnum == fnum) { chain_fsp = fsp; + if (count > 10) { + DLIST_PROMOTE(Files, fsp); + } return fsp; } } -- cgit From b935fc086285e73203e5f3af80041489e893ee1a Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Mon, 17 Aug 1998 22:59:53 +0000 Subject: Fixed bug introduced by the recent changes where the chain_fnum could be overwritten in oplock processing code. Jeremy. (This used to be commit 908a583b48e37c5e869216f4dc92d4a587ff1238) --- source3/smbd/files.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index fa1b8f3bac..4f87802119 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -37,7 +37,8 @@ static files_struct *Files; /* a fsp to use when chaining */ static files_struct *chain_fsp = NULL; - +/* a fsp to use to save when breaking an oplock. */ +static files_struct *oplock_save_chain_fsp = NULL; /* * Indirection for file fd's. Needed as POSIX locking @@ -387,3 +388,20 @@ void file_chain_reset(void) { chain_fsp = NULL; } + +/**************************************************************************** +Save the chained fsp - done when about to do an oplock break. +****************************************************************************/ + +void file_chain_save(void) +{ + oplock_save_chain_fsp = chain_fsp; +} + +/**************************************************************************** +Restore the chained fsp - done after an oplock break. +****************************************************************************/ +void file_chain_restore(void) +{ + chain_fsp = oplock_save_chain_fsp; +} -- cgit From dc76502cd8a950f6aff84ce4eedfd9d2b30d3dcc Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Thu, 20 Aug 1998 19:28:37 +0000 Subject: Turning on blocking locking code. NB. Blocking lock requests that are not the head of an SMB request (ie. are part of a chain) will not be queued - this will be fixed when we move to the new chain code. In practice, this doesn't seem to cause much of a problem (in my admittedly limited testing) bug a debug level zero message will be placed in the log when this happens to help determine how real the problem is. smbd/locking.c: New debug messages. smbd/blocking.c: New blocking code - handles SMBlock, SMBlockread and SMBlockingX smbd/chgpasswd.c: Fix for master fd leak. smbd/files.c: Tidyup comment. smbd/nttrans.c: Added fnum to debug message. smbd/process.c: Made chain_reply() use construct_reply_common(). Added blocking lock queue processing into idle loop. smbd/reply.c: Added queue pushes for SMBlock, SMBlockread and SMBlockingX. Jeremy. (This used to be commit e1dd03ecda0bc6d7eaa31070c83774bb5679fd1b) --- source3/smbd/files.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 4f87802119..00de8dfffa 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -380,10 +380,10 @@ files_struct *file_fsp(char *buf, int where) return NULL; } - /**************************************************************************** -reset the chained fsp - done at the start of a packet reply + Reset the chained fsp - done at the start of a packet reply ****************************************************************************/ + void file_chain_reset(void) { chain_fsp = NULL; -- cgit From 693480af8bb2d3e83566af9463ca427f47a879da Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Mon, 31 Aug 1998 20:20:54 +0000 Subject: configure.in, configure: include/config.h.in: Added stropts and poll. include/smb.h: Moved old typedefs of uint8 etc. into include/includes.h where all the other defines live (changed them from typedefs to defines). Other changes : changed from using uint32 to SMB_DEV_T and SMB_INO_T in preparation for moving to size independed (ie. 64 bit clean) device and inode access. Stat call wrapper comes next :-). Jeremy. (This used to be commit 3d9ec96de5e04e83abafe9c5d980bd39eee856ea) --- source3/smbd/files.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 00de8dfffa..d098677fba 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -125,8 +125,8 @@ file_fd_struct *fd_get_already_open(struct stat *sbuf) for (fd_ptr=FileFd;fd_ptr;fd_ptr=fd_ptr->next) { if ((fd_ptr->ref_count > 0) && - (((uint32)sbuf->st_dev) == fd_ptr->dev) && - (((uint32)sbuf->st_ino) == fd_ptr->inode)) { + (sbuf->st_dev == fd_ptr->dev) && + (sbuf->st_ino == fd_ptr->inode)) { fd_ptr->ref_count++; DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %x, ref_count = %d\n", fd_ptr->dev, fd_ptr->inode, @@ -162,8 +162,8 @@ file_fd_struct *fd_get_new(void) memset(fd_ptr, 0, sizeof(*fd_ptr)); fd_ptr->fdnum = i; - fd_ptr->dev = (uint32)-1; - fd_ptr->inode = (uint32)-1; + fd_ptr->dev = (SMB_DEV_T)-1; + fd_ptr->inode = (SMB_INO_T)-1; fd_ptr->fd = -1; fd_ptr->fd_readonly = -1; fd_ptr->fd_writeonly = -1; @@ -254,7 +254,7 @@ void file_close_user(int vuid) /**************************************************************************** find a fsp given a device, inode and timevalue ****************************************************************************/ -files_struct *file_find_dit(int dev, int inode, struct timeval *tval) +files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval) { int count=0; files_struct *fsp; -- cgit From 18556274139cc5a00593471bd745354d98a35303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Tue, 1 Sep 1998 20:11:54 +0000 Subject: More abstraction of file system data types, to move to a 64 bit file interface for the NT SMB's. Created a new define, SMB_STRUCT_STAT that currently is defined to be struct stat - this wil change to a user defined type containing 64 bit info when the correct wrappers are written for 64 bit stat(), fstat() and lstat() calls. Also changed all sys_xxxx() calls that were previously just wrappers to the same call prefixed by a dos_to_unix() call into dos_xxxx() calls. This makes it explicit when a pathname translation is being done, and when it is not. Now, all sys_xxx() calls are meant to be wrappers to mask OS differences, and not silently converting filenames on the fly. Jeremy. (This used to be commit 28aa182dbffaa4ffd86047e608400de4b26e80eb) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index d098677fba..341d9946ec 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -117,7 +117,7 @@ files_struct *file_new(void ) fd support routines - attempt to find an already open file by dev and inode - increments the ref_count of the returned file_fd_struct *. ****************************************************************************/ -file_fd_struct *fd_get_already_open(struct stat *sbuf) +file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf) { file_fd_struct *fd_ptr; -- cgit From 83900f2b682c62f2b5620b29ecb710274990ac51 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 4 Sep 1998 20:53:58 +0000 Subject: Modified dev_t and ino_t code to be 64 bit clean (including changes to oplock break message passing). I think that smbd/nmbd are now inode and offset size independent (at least for 32 bit and 64 bit systems). Now to expose all this new functionality to NT clients..... Jeremy. (This used to be commit 5910d07bbf45a34d3c901461f74704c029a79474) --- source3/smbd/files.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 341d9946ec..163e4f0cf2 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -128,9 +128,15 @@ file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf) (sbuf->st_dev == fd_ptr->dev) && (sbuf->st_ino == fd_ptr->inode)) { fd_ptr->ref_count++; +#ifdef LARGE_SMB_INO_T + DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %.0f, ref_count = %d\n", + (unsigned int)fd_ptr->dev, (double)fd_ptr->inode, + fd_ptr->ref_count)); +#else /* LARGE_SMB_INO_T */ DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %x, ref_count = %d\n", - fd_ptr->dev, fd_ptr->inode, + (unsigned int)fd_ptr->dev, fd_ptr->inode, fd_ptr->ref_count)); +#endif /* LARGE_SMB_INO_T */ return fd_ptr; } } -- cgit From 98f524bde4801bd0b013a6bc79c5552ef62b59f8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Sat, 5 Sep 1998 03:14:40 +0000 Subject: Bugfix for leak in reference counted file struct. Added "nt smb support" parameter to allow NT SMB's to be turned off. Jeremy. (This used to be commit 63f65f5027d5022153fa2757b49c56829db1725b) --- source3/smbd/files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 163e4f0cf2..0b72bcf0fa 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -133,8 +133,8 @@ file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf) (unsigned int)fd_ptr->dev, (double)fd_ptr->inode, fd_ptr->ref_count)); #else /* LARGE_SMB_INO_T */ - DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %x, ref_count = %d\n", - (unsigned int)fd_ptr->dev, fd_ptr->inode, + DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %lx, ref_count = %d\n", + (unsigned int)fd_ptr->dev, (unsigned long)fd_ptr->inode, fd_ptr->ref_count)); #endif /* LARGE_SMB_INO_T */ return fd_ptr; @@ -315,7 +315,7 @@ void file_sync_all(connection_struct *conn) /**************************************************************************** free up a fd_ptr ****************************************************************************/ -static void fd_ptr_free(file_fd_struct *fd_ptr) +void fd_ptr_free(file_fd_struct *fd_ptr) { DLIST_REMOVE(FileFd, fd_ptr); -- cgit From e9ea36e4d2270bd7d32da12ef6d6e2299641582d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Sat, 5 Sep 1998 05:07:05 +0000 Subject: tridge the destroyer returns! prompted by the interpret_security() dead code that Jean-Francois pointed out I added a make target "finddead" that finds potentially dead (ie. unused) code. It spat out 304 function names ... I went through these are deleted many of them, making others static (finddead also reports functions that are used only in the local file). in doing this I have almost certainly deleted some useful code. I may have even prevented compilation with some compile options. I apologise. I decided it was better to get rid of this code now and add back the one or two functions that are needed than to keep all this baggage. So, if I have done a bit too much "destroying" then let me know. Keep the swearing to a minimum :) One bit I didn't do is the ubibt code. Chris, can you look at that? Heaps of unused functions there. Can they be made static? (This used to be commit 2204475c87f3024ea8fd1fbd7385b2def617a46f) --- source3/smbd/files.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 0b72bcf0fa..0fe6a4ebd1 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -133,8 +133,9 @@ file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf) (unsigned int)fd_ptr->dev, (double)fd_ptr->inode, fd_ptr->ref_count)); #else /* LARGE_SMB_INO_T */ - DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %lx, ref_count = %d\n", - (unsigned int)fd_ptr->dev, (unsigned long)fd_ptr->inode, + DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %x, ref_count = %d\n", + (unsigned int)fd_ptr->dev, + (unsigned int)fd_ptr->inode, fd_ptr->ref_count)); #endif /* LARGE_SMB_INO_T */ return fd_ptr; -- cgit From f6044c87c021342d68d614d59bc8dacd32d223b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Sat, 5 Sep 1998 13:24:20 +0000 Subject: some cleanups to use ZERO_STRUCT() and friends (This used to be commit 7b154dc4313324dfad6cf0117b8ce246bf12bf16) --- source3/smbd/files.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 0fe6a4ebd1..ed14b86e5f 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -91,7 +91,7 @@ files_struct *file_new(void ) fsp = (files_struct *)malloc(sizeof(*fsp)); if (!fsp) return NULL; - memset(fsp, 0, sizeof(*fsp)); + ZERO_STRUCTP(fsp); first_file = (i+1) % MAX_FNUMS; @@ -166,7 +166,7 @@ file_fd_struct *fd_get_new(void) fd_ptr = (file_fd_struct *)malloc(sizeof(*fd_ptr)); if (!fd_ptr) return NULL; - memset(fd_ptr, 0, sizeof(*fd_ptr)); + ZERO_STRUCTP(fd_ptr); fd_ptr->fdnum = i; fd_ptr->dev = (SMB_DEV_T)-1; @@ -327,7 +327,7 @@ void fd_ptr_free(file_fd_struct *fd_ptr) fd_ptr->fdnum, fd_ptr_used)); /* paranoia */ - memset(fd_ptr, 0, sizeof(*fd_ptr)); + ZERO_STRUCTP(fd_ptr); free(fd_ptr); } @@ -354,7 +354,7 @@ void file_free(files_struct *fsp) /* this is paranoia, just in case someone tries to reuse the information */ - memset(fsp, 0, sizeof(*fsp)); + ZERO_STRUCTP(fsp); if (fsp == chain_fsp) chain_fsp = NULL; -- cgit From ede44ebdf089a835ea1f3141dd00b50b7bbc54e1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Thu, 10 Sep 1998 18:57:06 +0000 Subject: smb.h: Removed fdnum from file_fd_struct. Not needed. files.c: Removed fd bitmap - not needed. Added code to do use arrays rather than linked list - disabled by default but can be enabled to check performance. Jeremy. (This used to be commit 069efc04545d5fdfc5c40467b8b7554ed5226a2e) --- source3/smbd/files.c | 138 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 109 insertions(+), 29 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index ed14b86e5f..c1bb3df57c 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -31,10 +31,13 @@ extern int DEBUGLEVEL; #define FILE_HANDLE_OFFSET 0x1000 static struct bitmap *file_bmap; -static struct bitmap *fd_bmap; +#ifdef USE_FILES_ARRAY +static files_struct *Files[MAX_FNUMS]; +#else static files_struct *Files; - +#endif + /* a fsp to use when chaining */ static files_struct *chain_fsp = NULL; /* a fsp to use to save when breaking an oplock. */ @@ -77,12 +80,21 @@ files_struct *file_new(void ) * files batch oplocked for quite a long time * after they have finished with them. */ +#ifdef USE_FILES_ARRAY + for(i = 0; i < MAX_FNUMS; i++) { + if((fsp = Files[i]) == NULL) + continue; + if (attempt_close_oplocked_file(fsp)) + return file_new(); + } +#else for (fsp=Files;fsp;fsp=next) { next=fsp->next; if (attempt_close_oplocked_file(fsp)) { return file_new(); } } +#endif DEBUG(0,("ERROR! Out of file structures\n")); return NULL; @@ -101,10 +113,14 @@ files_struct *file_new(void ) fsp->fnum = i + FILE_HANDLE_OFFSET; string_init(&fsp->fsp_name,""); +#ifdef USE_FILES_ARRAY + Files[i] = fsp; +#else DLIST_ADD(Files, fsp); +#endif - DEBUG(5,("allocated file structure %d (%d used)\n", - i, files_used)); + DEBUG(5,("allocated file structure %d, fnum = %d (%d used)\n", + i, fsp->fnum, files_used)); chain_fsp = fsp; @@ -128,16 +144,11 @@ file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf) (sbuf->st_dev == fd_ptr->dev) && (sbuf->st_ino == fd_ptr->inode)) { fd_ptr->ref_count++; -#ifdef LARGE_SMB_INO_T + DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %.0f, ref_count = %d\n", (unsigned int)fd_ptr->dev, (double)fd_ptr->inode, fd_ptr->ref_count)); -#else /* LARGE_SMB_INO_T */ - DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %x, ref_count = %d\n", - (unsigned int)fd_ptr->dev, - (unsigned int)fd_ptr->inode, - fd_ptr->ref_count)); -#endif /* LARGE_SMB_INO_T */ + return fd_ptr; } } @@ -154,21 +165,16 @@ Increments the ref_count of the returned entry. file_fd_struct *fd_get_new(void) { extern struct current_user current_user; - int i; file_fd_struct *fd_ptr; - i = bitmap_find(fd_bmap, 1); - if (i == -1) { - DEBUG(0,("ERROR! Out of file_fd structures\n")); - return NULL; - } - fd_ptr = (file_fd_struct *)malloc(sizeof(*fd_ptr)); - if (!fd_ptr) return NULL; + if (!fd_ptr) { + DEBUG(0,("ERROR! malloc fail for file_fd struct.\n")); + return NULL; + } ZERO_STRUCTP(fd_ptr); - fd_ptr->fdnum = i; fd_ptr->dev = (SMB_DEV_T)-1; fd_ptr->inode = (SMB_INO_T)-1; fd_ptr->fd = -1; @@ -178,13 +184,11 @@ file_fd_struct *fd_get_new(void) fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid); fd_ptr->ref_count++; - bitmap_set(fd_bmap, i); fd_ptr_used++; DLIST_ADD(FileFd, fd_ptr); - DEBUG(5,("allocated fd_ptr structure %d (%d used)\n", - i, fd_ptr_used)); + DEBUG(5,("allocated fd_ptr structure (%d used)\n", fd_ptr_used)); return fd_ptr; } @@ -197,6 +201,19 @@ void file_close_conn(connection_struct *conn) { files_struct *fsp, *next; +#ifdef USE_FILES_ARRAY + int i; + for (i = 0; i < MAX_FNUMS; i++) { + if((fsp = Files[i]) == NULL) + continue; + if(fsp->conn == conn && fsp->open) { + if (fsp->is_directory) + close_directory(fsp); + else + close_file(fsp,False); + } + } +#else for (fsp=Files;fsp;fsp=next) { next = fsp->next; if (fsp->conn == conn && fsp->open) { @@ -206,6 +223,7 @@ void file_close_conn(connection_struct *conn) close_file(fsp,False); } } +#endif } /**************************************************************************** @@ -214,9 +232,8 @@ initialise file structures void file_init(void) { file_bmap = bitmap_allocate(MAX_FNUMS); - fd_bmap = bitmap_allocate(MAX_FNUMS); - if (!file_bmap || !fd_bmap) { + if (!file_bmap) { exit_server("out of memory in file_init"); } @@ -246,6 +263,19 @@ void file_close_user(int vuid) { files_struct *fsp, *next; +#ifdef USE_FILES_ARRAY + int i; + for(i = 0; i < MAX_FNUMS; i++) { + if((fsp = Files[i]) == NULL) + continue; + if((fsp->vuid == vuid) && fsp->open) { + if(!fsp->is_directory) + close_file(fsp,False); + else + close_directory(fsp); + } + } +#else for (fsp=Files;fsp;fsp=next) { next=fsp->next; if ((fsp->vuid == vuid) && fsp->open) { @@ -255,6 +285,7 @@ void file_close_user(int vuid) close_directory(fsp); } } +#endif } @@ -266,6 +297,18 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval int count=0; files_struct *fsp; +#ifdef USE_FILES_ARRAY + for(count = 0; count < MAX_FNUMS; count++) { + if((fsp = Files[count]) == NULL) + continue; + if (fsp->open && + fsp->fd_ptr->dev == dev && + fsp->fd_ptr->inode == inode && + fsp->open_time.tv_sec == tval->tv_sec && + fsp->open_time.tv_usec == tval->tv_usec) + return fsp; + } +#else for (fsp=Files;fsp;fsp=fsp->next,count++) { if (fsp->open && fsp->fd_ptr->dev == dev && @@ -278,6 +321,7 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval return fsp; } } +#endif return NULL; } @@ -290,9 +334,19 @@ files_struct *file_find_print(void) { files_struct *fsp; +#ifdef USE_FILES_ARRAY + int i; + for(i = 0; i < MAX_FNUMS; i++) { + if((fsp = Files[i]) == NULL) + continue; + if (fsp->open && fsp->print_file) return fsp; + } +#else for (fsp=Files;fsp;fsp=fsp->next) { if (fsp->open && fsp->print_file) return fsp; } +#endif + return NULL; } @@ -304,12 +358,22 @@ void file_sync_all(connection_struct *conn) { files_struct *fsp, *next; +#ifdef USE_FILES_ARRAY + int i; + for(i = 0; i < MAX_FNUMS; i++) { + if((fsp = Files[i]) == NULL) + continue; + if (fsp->open && conn == fsp->conn) + sync_file(conn,fsp); + } +#else for (fsp=Files;fsp;fsp=next) { next=fsp->next; if (fsp->open && conn == fsp->conn) { sync_file(conn,fsp); } } +#endif } @@ -320,11 +384,9 @@ void fd_ptr_free(file_fd_struct *fd_ptr) { DLIST_REMOVE(FileFd, fd_ptr); - bitmap_clear(fd_bmap, fd_ptr->fdnum); fd_ptr_used--; - DEBUG(5,("freed fd_ptr structure %d (%d used)\n", - fd_ptr->fdnum, fd_ptr_used)); + DEBUG(5,("freed fd_ptr structure (%d used)\n", fd_ptr_used)); /* paranoia */ ZERO_STRUCTP(fd_ptr); @@ -338,7 +400,16 @@ free up a fsp ****************************************************************************/ void file_free(files_struct *fsp) { +#ifdef USE_FILES_ARRAY + files_struct *fsp1 = Files[fsp->fnum - FILE_HANDLE_OFFSET]; + if(fsp != fsp1) + DEBUG(0,("file_free: fnum = %d (array offset %d) <> fsp = %x, fnum = %d!\n", + fsp->fnum, fsp->fnum - FILE_HANDLE_OFFSET, fsp1, fsp1->fnum)); + SMB_ASSERT(fsp == fsp1); + Files[fsp->fnum - FILE_HANDLE_OFFSET] = NULL; +#else DLIST_REMOVE(Files, fsp); +#endif string_free(&fsp->fsp_name); @@ -374,6 +445,15 @@ files_struct *file_fsp(char *buf, int where) fnum = SVAL(buf, where); +#ifdef USE_FILES_ARRAY + fsp = Files[fnum - FILE_HANDLE_OFFSET]; + if(!fsp) + DEBUG(0,("file_fsp: fnum = %d (array offset %d) gave null fsp !\n", + fnum, fnum - FILE_HANDLE_OFFSET)); + SMB_ASSERT(fsp != NULL); + + return (chain_fsp = fsp); +#else for (fsp=Files;fsp;fsp=fsp->next, count++) { if (fsp->fnum == fnum) { chain_fsp = fsp; @@ -383,8 +463,8 @@ files_struct *file_fsp(char *buf, int where) return fsp; } } - return NULL; +#endif } /**************************************************************************** -- cgit From aab2fe021643417854451c65e564932f4ac25f10 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Wed, 23 Sep 1998 01:48:45 +0000 Subject: First cut at kernel oplocks. This should have no effect unless runnin on a machine that supports them in autoconf. Move various functions out of lib/util.c into smbd/process.c and smbd/oplock.c where they belong. Jeremy. (This used to be commit c3c5e13f85c97939746070132dad941e79c546fb) --- source3/smbd/files.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index c1bb3df57c..e8b391d117 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -290,31 +290,33 @@ void file_close_user(int vuid) /**************************************************************************** -find a fsp given a device, inode and timevalue + Find a fsp given a device, inode and timevalue + If this is from a kernel oplock break request then tval may be NULL. ****************************************************************************/ + files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval) { int count=0; files_struct *fsp; #ifdef USE_FILES_ARRAY - for(count = 0; count < MAX_FNUMS; count++) { - if((fsp = Files[count]) == NULL) - continue; - if (fsp->open && - fsp->fd_ptr->dev == dev && - fsp->fd_ptr->inode == inode && - fsp->open_time.tv_sec == tval->tv_sec && - fsp->open_time.tv_usec == tval->tv_usec) - return fsp; - } + for(count = 0; count < MAX_FNUMS; count++) { + if((fsp = Files[count]) == NULL) + continue; + if (fsp->open && + fsp->fd_ptr->dev == dev && + fsp->fd_ptr->inode == inode && + (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True) && + (tval ? (fsp->open_time.tv_usec == tval->tv_usec) : True)) + return fsp; + } #else for (fsp=Files;fsp;fsp=fsp->next,count++) { if (fsp->open && fsp->fd_ptr->dev == dev && fsp->fd_ptr->inode == inode && - fsp->open_time.tv_sec == tval->tv_sec && - fsp->open_time.tv_usec == tval->tv_usec) { + (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) && + (tval ? (fsp->open_time.tv_usec == tval->tv_usec) : True )) { if (count > 10) { DLIST_PROMOTE(Files, fsp); } -- cgit From 5b4d94e20fdb5888da1b71a7b6a30ebede6cb06a Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Wed, 30 Sep 1998 01:49:24 +0000 Subject: (Finally) implemented "max open files" as a global smb.conf parameter. Sets up the files array correctly - limited by the smb.conf parameter and by the max fd's per process as found by getrlimit(). Jeremy. (This used to be commit eca24bd24352c688cdf48c1ef14adb8ac353468f) --- source3/smbd/files.c | 66 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e8b391d117..9b58ef5b31 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -23,17 +23,16 @@ extern int DEBUGLEVEL; -/* the only restriction is that this must be less than PIPE_HANDLE_OFFSET */ -#define MAX_FNUMS 4096 +static int real_max_open_files; -#define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < MAX_FNUMS)) +#define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < real_max_open_files)) #define FILE_HANDLE_OFFSET 0x1000 static struct bitmap *file_bmap; #ifdef USE_FILES_ARRAY -static files_struct *Files[MAX_FNUMS]; +static files_struct **Files; #else static files_struct *Files; #endif @@ -66,7 +65,7 @@ files_struct *file_new(void ) increases the chance that the errant client will get an error rather than causing corruption */ if (first_file == 0) { - first_file = (getpid() ^ (int)time(NULL)) % MAX_FNUMS; + first_file = (getpid() ^ (int)time(NULL)) % real_max_open_files; } i = bitmap_find(file_bmap, first_file); @@ -81,7 +80,7 @@ files_struct *file_new(void ) * after they have finished with them. */ #ifdef USE_FILES_ARRAY - for(i = 0; i < MAX_FNUMS; i++) { + for(i = 0; i < real_max_open_files; i++) { if((fsp = Files[i]) == NULL) continue; if (attempt_close_oplocked_file(fsp)) @@ -105,7 +104,7 @@ files_struct *file_new(void ) ZERO_STRUCTP(fsp); - first_file = (i+1) % MAX_FNUMS; + first_file = (i+1) % real_max_open_files; bitmap_set(file_bmap, i); files_used++; @@ -203,7 +202,7 @@ void file_close_conn(connection_struct *conn) #ifdef USE_FILES_ARRAY int i; - for (i = 0; i < MAX_FNUMS; i++) { + for (i = 0; i < real_max_open_files; i++) { if((fsp = Files[i]) == NULL) continue; if(fsp->conn == conn && fsp->open) { @@ -229,30 +228,53 @@ void file_close_conn(connection_struct *conn) /**************************************************************************** initialise file structures ****************************************************************************/ + +#define MAX_OPEN_FUDGEFACTOR 10 + void file_init(void) { - file_bmap = bitmap_allocate(MAX_FNUMS); - - if (!file_bmap) { - exit_server("out of memory in file_init"); - } + real_max_open_files = lp_max_open_files(); #if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)) { struct rlimit rlp; getrlimit(RLIMIT_NOFILE, &rlp); - /* Set the fd limit to be MAX_FNUMS + 10 to + /* Set the fd limit to be real_max_open_files + MAX_OPEN_FUDGEFACTOR to * account for the extra fd we need * as well as the log files and standard * handles etc. */ - rlp.rlim_cur = (MAX_FNUMS+10>rlp.rlim_max)? - rlp.rlim_max:MAX_FNUMS+10; + rlp.rlim_cur = (real_max_open_files+MAX_OPEN_FUDGEFACTOR>rlp.rlim_max)? + rlp.rlim_max:real_max_open_files+MAX_OPEN_FUDGEFACTOR; setrlimit(RLIMIT_NOFILE, &rlp); getrlimit(RLIMIT_NOFILE, &rlp); - DEBUG(3,("Maximum number of open files per session is %d\n", - (int)rlp.rlim_cur)); + if(rlp.rlim_cur != (real_max_open_files + MAX_OPEN_FUDGEFACTOR)) + DEBUG(0,("file_init: Maximum number of open files requested per session \ +was %d, actual files available per session = %d\n", + real_max_open_files, (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR )); + + DEBUG(2,("Maximum number of open files per session is %d\n", + (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR)); + + real_max_open_files = (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR; } #endif + + file_bmap = bitmap_allocate(real_max_open_files); + + if (!file_bmap) { + exit_server("out of memory in file_init"); + } + +#ifdef USE_FILES_ARRAY + Files = (files_struct **)malloc( sizeof(files_struct *) * real_max_open_files); + if(Files == NULL) + exit_server("out of memory for file array in file_init"); +#endif + + /* + * Ensure that pipe_handle_oppset is set correctly. + */ + set_pipe_handle_offset(real_max_open_files); } @@ -265,7 +287,7 @@ void file_close_user(int vuid) #ifdef USE_FILES_ARRAY int i; - for(i = 0; i < MAX_FNUMS; i++) { + for(i = 0; i < real_max_open_files; i++) { if((fsp = Files[i]) == NULL) continue; if((fsp->vuid == vuid) && fsp->open) { @@ -300,7 +322,7 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval files_struct *fsp; #ifdef USE_FILES_ARRAY - for(count = 0; count < MAX_FNUMS; count++) { + for(count = 0; count < real_max_open_files; count++) { if((fsp = Files[count]) == NULL) continue; if (fsp->open && @@ -338,7 +360,7 @@ files_struct *file_find_print(void) #ifdef USE_FILES_ARRAY int i; - for(i = 0; i < MAX_FNUMS; i++) { + for(i = 0; i < real_max_open_files; i++) { if((fsp = Files[i]) == NULL) continue; if (fsp->open && fsp->print_file) return fsp; @@ -362,7 +384,7 @@ void file_sync_all(connection_struct *conn) #ifdef USE_FILES_ARRAY int i; - for(i = 0; i < MAX_FNUMS; i++) { + for(i = 0; i < real_max_open_files; i++) { if((fsp = Files[i]) == NULL) continue; if (fsp->open && conn == fsp->conn) -- cgit From eb7f62f911583028892841f8b1f0ef9a4614040e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Thu, 1 Oct 1998 03:07:09 +0000 Subject: got rid of USE_FILES_ARRAY code (it was unused) (This used to be commit f15ece53162304d855bea4f329f3faed8813a831) --- source3/smbd/files.c | 110 ++------------------------------------------------- 1 file changed, 4 insertions(+), 106 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 9b58ef5b31..4000439db0 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -31,11 +31,7 @@ static int real_max_open_files; static struct bitmap *file_bmap; -#ifdef USE_FILES_ARRAY -static files_struct **Files; -#else static files_struct *Files; -#endif /* a fsp to use when chaining */ static files_struct *chain_fsp = NULL; @@ -79,21 +75,12 @@ files_struct *file_new(void ) * files batch oplocked for quite a long time * after they have finished with them. */ -#ifdef USE_FILES_ARRAY - for(i = 0; i < real_max_open_files; i++) { - if((fsp = Files[i]) == NULL) - continue; - if (attempt_close_oplocked_file(fsp)) - return file_new(); - } -#else for (fsp=Files;fsp;fsp=next) { next=fsp->next; if (attempt_close_oplocked_file(fsp)) { return file_new(); } } -#endif DEBUG(0,("ERROR! Out of file structures\n")); return NULL; @@ -112,11 +99,7 @@ files_struct *file_new(void ) fsp->fnum = i + FILE_HANDLE_OFFSET; string_init(&fsp->fsp_name,""); -#ifdef USE_FILES_ARRAY - Files[i] = fsp; -#else DLIST_ADD(Files, fsp); -#endif DEBUG(5,("allocated file structure %d, fnum = %d (%d used)\n", i, fsp->fnum, files_used)); @@ -200,19 +183,6 @@ void file_close_conn(connection_struct *conn) { files_struct *fsp, *next; -#ifdef USE_FILES_ARRAY - int i; - for (i = 0; i < real_max_open_files; i++) { - if((fsp = Files[i]) == NULL) - continue; - if(fsp->conn == conn && fsp->open) { - if (fsp->is_directory) - close_directory(fsp); - else - close_file(fsp,False); - } - } -#else for (fsp=Files;fsp;fsp=next) { next = fsp->next; if (fsp->conn == conn && fsp->open) { @@ -222,7 +192,6 @@ void file_close_conn(connection_struct *conn) close_file(fsp,False); } } -#endif } /**************************************************************************** @@ -265,16 +234,10 @@ was %d, actual files available per session = %d\n", exit_server("out of memory in file_init"); } -#ifdef USE_FILES_ARRAY - Files = (files_struct **)malloc( sizeof(files_struct *) * real_max_open_files); - if(Files == NULL) - exit_server("out of memory for file array in file_init"); -#endif - - /* - * Ensure that pipe_handle_oppset is set correctly. - */ - set_pipe_handle_offset(real_max_open_files); + /* + * Ensure that pipe_handle_oppset is set correctly. + */ + set_pipe_handle_offset(real_max_open_files); } @@ -285,19 +248,6 @@ void file_close_user(int vuid) { files_struct *fsp, *next; -#ifdef USE_FILES_ARRAY - int i; - for(i = 0; i < real_max_open_files; i++) { - if((fsp = Files[i]) == NULL) - continue; - if((fsp->vuid == vuid) && fsp->open) { - if(!fsp->is_directory) - close_file(fsp,False); - else - close_directory(fsp); - } - } -#else for (fsp=Files;fsp;fsp=next) { next=fsp->next; if ((fsp->vuid == vuid) && fsp->open) { @@ -307,7 +257,6 @@ void file_close_user(int vuid) close_directory(fsp); } } -#endif } @@ -321,18 +270,6 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval int count=0; files_struct *fsp; -#ifdef USE_FILES_ARRAY - for(count = 0; count < real_max_open_files; count++) { - if((fsp = Files[count]) == NULL) - continue; - if (fsp->open && - fsp->fd_ptr->dev == dev && - fsp->fd_ptr->inode == inode && - (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True) && - (tval ? (fsp->open_time.tv_usec == tval->tv_usec) : True)) - return fsp; - } -#else for (fsp=Files;fsp;fsp=fsp->next,count++) { if (fsp->open && fsp->fd_ptr->dev == dev && @@ -345,7 +282,6 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval return fsp; } } -#endif return NULL; } @@ -358,18 +294,9 @@ files_struct *file_find_print(void) { files_struct *fsp; -#ifdef USE_FILES_ARRAY - int i; - for(i = 0; i < real_max_open_files; i++) { - if((fsp = Files[i]) == NULL) - continue; - if (fsp->open && fsp->print_file) return fsp; - } -#else for (fsp=Files;fsp;fsp=fsp->next) { if (fsp->open && fsp->print_file) return fsp; } -#endif return NULL; } @@ -382,22 +309,12 @@ void file_sync_all(connection_struct *conn) { files_struct *fsp, *next; -#ifdef USE_FILES_ARRAY - int i; - for(i = 0; i < real_max_open_files; i++) { - if((fsp = Files[i]) == NULL) - continue; - if (fsp->open && conn == fsp->conn) - sync_file(conn,fsp); - } -#else for (fsp=Files;fsp;fsp=next) { next=fsp->next; if (fsp->open && conn == fsp->conn) { sync_file(conn,fsp); } } -#endif } @@ -424,16 +341,7 @@ free up a fsp ****************************************************************************/ void file_free(files_struct *fsp) { -#ifdef USE_FILES_ARRAY - files_struct *fsp1 = Files[fsp->fnum - FILE_HANDLE_OFFSET]; - if(fsp != fsp1) - DEBUG(0,("file_free: fnum = %d (array offset %d) <> fsp = %x, fnum = %d!\n", - fsp->fnum, fsp->fnum - FILE_HANDLE_OFFSET, fsp1, fsp1->fnum)); - SMB_ASSERT(fsp == fsp1); - Files[fsp->fnum - FILE_HANDLE_OFFSET] = NULL; -#else DLIST_REMOVE(Files, fsp); -#endif string_free(&fsp->fsp_name); @@ -469,15 +377,6 @@ files_struct *file_fsp(char *buf, int where) fnum = SVAL(buf, where); -#ifdef USE_FILES_ARRAY - fsp = Files[fnum - FILE_HANDLE_OFFSET]; - if(!fsp) - DEBUG(0,("file_fsp: fnum = %d (array offset %d) gave null fsp !\n", - fnum, fnum - FILE_HANDLE_OFFSET)); - SMB_ASSERT(fsp != NULL); - - return (chain_fsp = fsp); -#else for (fsp=Files;fsp;fsp=fsp->next, count++) { if (fsp->fnum == fnum) { chain_fsp = fsp; @@ -488,7 +387,6 @@ files_struct *file_fsp(char *buf, int where) } } return NULL; -#endif } /**************************************************************************** -- cgit From 93bbfce02b4ad3f51cef9b057a3959f4e091529f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 5 Oct 1998 01:57:03 +0000 Subject: added a function set_maxfiles() to set our file rlimit to the max possible and return the max. (This used to be commit 7a7b5ee1689b6be57752d176c7b77a2f1b453486) --- source3/smbd/files.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 4000439db0..6afa059753 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -202,38 +202,19 @@ initialise file structures void file_init(void) { - real_max_open_files = lp_max_open_files(); - -#if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)) - { - struct rlimit rlp; - getrlimit(RLIMIT_NOFILE, &rlp); - /* Set the fd limit to be real_max_open_files + MAX_OPEN_FUDGEFACTOR to - * account for the extra fd we need - * as well as the log files and standard - * handles etc. */ - rlp.rlim_cur = (real_max_open_files+MAX_OPEN_FUDGEFACTOR>rlp.rlim_max)? - rlp.rlim_max:real_max_open_files+MAX_OPEN_FUDGEFACTOR; - setrlimit(RLIMIT_NOFILE, &rlp); - getrlimit(RLIMIT_NOFILE, &rlp); - if(rlp.rlim_cur != (real_max_open_files + MAX_OPEN_FUDGEFACTOR)) - DEBUG(0,("file_init: Maximum number of open files requested per session \ -was %d, actual files available per session = %d\n", - real_max_open_files, (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR )); - - DEBUG(2,("Maximum number of open files per session is %d\n", - (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR)); - - real_max_open_files = (int)rlp.rlim_cur - MAX_OPEN_FUDGEFACTOR; - } -#endif + int real_max_open_files, lim; - file_bmap = bitmap_allocate(real_max_open_files); + lim = set_maxfiles(); + lim = MIN(lim, lp_max_open_files()); + real_max_open_files = lim - MAX_OPEN_FUDGEFACTOR; + + file_bmap = bitmap_allocate(real_max_open_files); + if (!file_bmap) { exit_server("out of memory in file_init"); } - + /* * Ensure that pipe_handle_oppset is set correctly. */ -- cgit From 788263ba2f749c5bb1546ca6c9363fd508e94280 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Thu, 8 Oct 1998 06:21:33 +0000 Subject: - fixed a bunch of warnings and minor errors - got smbtorture to compile - removed %D from some of lukes code - Luke, what is %D? it ain't portable anyway (This used to be commit 91597c12fb593f49b23c7cea5b64dbb89a0428b3) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 6afa059753..4030ad4c49 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -202,7 +202,7 @@ initialise file structures void file_init(void) { - int real_max_open_files, lim; + int lim; lim = set_maxfiles(); lim = MIN(lim, lp_max_open_files()); -- cgit From f3793be1651c055da7cfa58afb817547df766de8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 16 Oct 1998 06:16:10 +0000 Subject: Re-added code to tell the user how many open files they have. Needed for server diagnosis purposes... Jeremy. (This used to be commit 04d79a9ae515e7259277f9980552f1d61df239f1) --- source3/smbd/files.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 4030ad4c49..c369a45bab 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -202,13 +202,23 @@ initialise file structures void file_init(void) { - int lim; + int request_max_open_files = lp_max_open_files(); + int real_lim; - lim = set_maxfiles(); - lim = MIN(lim, lp_max_open_files()); + /* + * 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_max_open_files = real_lim - MAX_OPEN_FUDGEFACTOR; + + if(real_max_open_files != request_max_open_files) { + DEBUG(1,("file_init: Information only: requested %d \ +open files, %d are available.\n", request_max_open_files, real_max_open_files)); + } - real_max_open_files = lim - MAX_OPEN_FUDGEFACTOR; - file_bmap = bitmap_allocate(real_max_open_files); if (!file_bmap) { -- cgit From 9bb7ac81b6e4d33e1be49447dbdbbb8d24259f53 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 23 Oct 1998 03:34:50 +0000 Subject: Reasonably large change to give us *exactly* correct NT delete on close semantics. This was trickier than it looks :-). Check out the new DELETE_ON_CLOSE flag in the share modes and the new code that iterates through all open files on the same device and inode in files.c and trans2.c Also changed the code that modifies share mode entries to take generic function pointers rather than doing a specific thing so this sort of change should be easier in the future. Jeremy. (This used to be commit 5e6a7cd99d29d1cf068fc517272559c1cf47ea3a) --- source3/smbd/files.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index c369a45bab..e58c3834a0 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -277,6 +277,41 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval return NULL; } +/**************************************************************************** + Find the first fsp given a device and inode. +****************************************************************************/ + +files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) +{ + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp->open && + fsp->fd_ptr->dev == dev && + fsp->fd_ptr->inode == inode ) + return fsp; + } + + return NULL; +} + +/**************************************************************************** + Find the next fsp having the same device and inode. +****************************************************************************/ + +files_struct *file_find_di_next(files_struct *start_fsp) +{ + files_struct *fsp; + + for (fsp = start_fsp->next;fsp;fsp=fsp->next) { + if (fsp->open && + fsp->fd_ptr->dev == start_fsp->fd_ptr->dev && + fsp->fd_ptr->inode == start_fsp->fd_ptr->inode ) + return fsp; + } + + return NULL; +} /**************************************************************************** find a fsp that is open for printing -- cgit From bb9622bfa6bbbe74a6e4c032cf81501bcbff999d Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Wed, 18 Nov 1998 19:06:51 +0000 Subject: Fixed crash bug which was assuming that fd_ptr was always non-null (which is not the case with open directories). Jeremy. (This used to be commit c154b1601f5891d664fc538ec8874fa8ef2061e6) --- source3/smbd/files.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e58c3834a0..3a41c83766 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -263,6 +263,7 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval for (fsp=Files;fsp;fsp=fsp->next,count++) { if (fsp->open && + fsp->fd_ptr != NULL && fsp->fd_ptr->dev == dev && fsp->fd_ptr->inode == inode && (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) && @@ -287,6 +288,7 @@ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) for (fsp=Files;fsp;fsp=fsp->next) { if (fsp->open && + fsp->fd_ptr != NULL && fsp->fd_ptr->dev == dev && fsp->fd_ptr->inode == inode ) return fsp; @@ -305,6 +307,7 @@ files_struct *file_find_di_next(files_struct *start_fsp) for (fsp = start_fsp->next;fsp;fsp=fsp->next) { if (fsp->open && + fsp->fd_ptr != NULL && fsp->fd_ptr->dev == start_fsp->fd_ptr->dev && fsp->fd_ptr->inode == start_fsp->fd_ptr->inode ) return fsp; @@ -337,7 +340,7 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if (fsp->open && conn == fsp->conn) { + if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)) { sync_file(conn,fsp); } } @@ -371,7 +374,7 @@ void file_free(files_struct *fsp) string_free(&fsp->fsp_name); - if (fsp->fd_ptr && fsp->fd_ptr->ref_count == 0) { + if ((fsp->fd_ptr != NULL) && fsp->fd_ptr->ref_count == 0) { fd_ptr_free(fsp->fd_ptr); } -- cgit From 6d5ef2e92995df1cbf5cd3d7c6a33fe55cedb311 Mon Sep 17 00:00:00 2001 From: Tim Potter <tpot@samba.org> Date: Sun, 4 Apr 1999 06:25:13 +0000 Subject: Use VFS operations for file I/O. (This used to be commit cfddbdb62485256a947a30e04c753200451cbe1c) --- source3/smbd/files.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 3a41c83766..8aca336bf8 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -340,13 +340,12 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)) { - sync_file(conn,fsp); + if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)){ + conn->vfs_ops.sync(conn, fsp); } } } - /**************************************************************************** free up a fd_ptr ****************************************************************************/ -- cgit From 1e1a52bb5f0475327d435c06032d1e6234c28bcb Mon Sep 17 00:00:00 2001 From: Tim Potter <tpot@samba.org> Date: Tue, 20 Apr 1999 03:29:05 +0000 Subject: Changed arguments to fsync() function to break dependency on connection_struct. (This used to be commit ee6f826ccc0897a4538f6f9a560127c54a4c4038) --- source3/smbd/files.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 8aca336bf8..d366fa1e1a 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -340,8 +340,9 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)){ - conn->vfs_ops.sync(conn, fsp); + if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL) + && lp_strict_sync(SNUM(conn))){ + conn->vfs_ops.sync(fsp->fd_ptr->fd); } } } -- cgit From ad000ee7dcf1c9c53f3222cb2e4c933bcc3c27b9 Mon Sep 17 00:00:00 2001 From: Luke Leighton <lkcl@samba.org> Date: Fri, 13 Aug 1999 21:11:38 +0000 Subject: spelling mistake. (This used to be commit b8ac96cd9c8efaf0e07651657f878a2dea127290) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index d366fa1e1a..7f4533e7ae 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -226,7 +226,7 @@ open files, %d are available.\n", request_max_open_files, real_max_open_files)); } /* - * Ensure that pipe_handle_oppset is set correctly. + * Ensure that pipe_handle_offset is set correctly. */ set_pipe_handle_offset(real_max_open_files); } -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/smbd/files.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 7f4533e7ae..d6203580cf 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -186,10 +186,7 @@ void file_close_conn(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next = fsp->next; if (fsp->conn == conn && fsp->open) { - if (fsp->is_directory) - close_directory(fsp); - else - close_file(fsp,False); + close_file(fsp,False); } } } @@ -226,7 +223,7 @@ open files, %d are available.\n", request_max_open_files, real_max_open_files)); } /* - * Ensure that pipe_handle_offset is set correctly. + * Ensure that pipe_handle_oppset is set correctly. */ set_pipe_handle_offset(real_max_open_files); } @@ -242,10 +239,7 @@ void file_close_user(int vuid) for (fsp=Files;fsp;fsp=next) { next=fsp->next; if ((fsp->vuid == vuid) && fsp->open) { - if(!fsp->is_directory) - close_file(fsp,False); - else - close_directory(fsp); + close_file(fsp,False); } } } @@ -340,13 +334,13 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL) - && lp_strict_sync(SNUM(conn))){ - conn->vfs_ops.sync(fsp->fd_ptr->fd); + if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)) { + sync_file(conn,fsp); } } } + /**************************************************************************** free up a fd_ptr ****************************************************************************/ -- cgit From b3b634ff4251cca647e1e545fe1e4160736d96b9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Sun, 16 Jan 2000 11:18:04 +0000 Subject: use string_set() instead of string_init() bug pointed out by Richard (This used to be commit 070f49397ff24e4d6ba7c2c1cfaef2dfa0944bd0) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index d6203580cf..dd1f7037f6 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -97,7 +97,7 @@ files_struct *file_new(void ) files_used++; fsp->fnum = i + FILE_HANDLE_OFFSET; - string_init(&fsp->fsp_name,""); + string_set(&fsp->fsp_name,""); DLIST_ADD(Files, fsp); -- cgit From 16bb009dbbe6302febf3848cee61e9927eeb0fb5 Mon Sep 17 00:00:00 2001 From: Tim Potter <tpot@samba.org> Date: Thu, 3 Feb 2000 05:17:25 +0000 Subject: Mega-VFS merge. Yeah baby! Synopsis: change every disk access function to work through a vfs_ops structure contained in the connection_struct. (This used to be commit 3aad500c0fb61232ed3431ff4b743b5d18ec852f) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index dd1f7037f6..d62950c568 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -335,7 +335,7 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)) { - sync_file(conn,fsp); + conn->vfs_ops.fsync(fsp->fd_ptr->fd); } } } -- cgit From 689ec46450a3f373b583ebe98d124ab4a99ce3ef Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 10 Apr 2000 13:05:23 +0000 Subject: the bulk of the changes to get rid of fd_ptr and move print open handling to printing/printing.c most of this was just replacing things like fsp->fd_ptr->fd with fsp->fd the changes in open.c are quite dramatic. Most of it is removing all the functions that handled the fd multiplexing (This used to be commit d1827a3648009fd0a0d165055015d9aeda7a1037) --- source3/smbd/files.c | 118 ++++++--------------------------------------------- 1 file changed, 12 insertions(+), 106 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index d62950c568..127d2fcac9 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -38,13 +38,7 @@ static files_struct *chain_fsp = NULL; /* a fsp to use to save when breaking an oplock. */ static files_struct *oplock_save_chain_fsp = NULL; -/* - * Indirection for file fd's. Needed as POSIX locking - * is based on file/process, not fd/process. - */ -static file_fd_struct *FileFd; - -static int files_used, fd_ptr_used; +static int files_used; /**************************************************************************** find first available file slot @@ -110,72 +104,6 @@ files_struct *file_new(void ) } - -/**************************************************************************** -fd support routines - attempt to find an already open file by dev -and inode - increments the ref_count of the returned file_fd_struct *. -****************************************************************************/ -file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf) -{ - file_fd_struct *fd_ptr; - - if(!sbuf) return NULL; - - for (fd_ptr=FileFd;fd_ptr;fd_ptr=fd_ptr->next) { - if ((fd_ptr->ref_count > 0) && - (sbuf->st_dev == fd_ptr->dev) && - (sbuf->st_ino == fd_ptr->inode)) { - fd_ptr->ref_count++; - - DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %.0f, ref_count = %d\n", - (unsigned int)fd_ptr->dev, (double)fd_ptr->inode, - fd_ptr->ref_count)); - - return fd_ptr; - } - } - - return NULL; -} - - - -/**************************************************************************** -fd support routines - attempt to find a empty slot in the FileFd array. -Increments the ref_count of the returned entry. -****************************************************************************/ -file_fd_struct *fd_get_new(void) -{ - extern struct current_user current_user; - file_fd_struct *fd_ptr; - - fd_ptr = (file_fd_struct *)malloc(sizeof(*fd_ptr)); - if (!fd_ptr) { - DEBUG(0,("ERROR! malloc fail for file_fd struct.\n")); - return NULL; - } - - ZERO_STRUCTP(fd_ptr); - - fd_ptr->dev = (SMB_DEV_T)-1; - fd_ptr->inode = (SMB_INO_T)-1; - fd_ptr->fd = -1; - fd_ptr->fd_readonly = -1; - fd_ptr->fd_writeonly = -1; - fd_ptr->real_open_flags = -1; - fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid); - fd_ptr->ref_count++; - - fd_ptr_used++; - - DLIST_ADD(FileFd, fd_ptr); - - DEBUG(5,("allocated fd_ptr structure (%d used)\n", fd_ptr_used)); - - return fd_ptr; -} - - /**************************************************************************** close all open files for a connection ****************************************************************************/ @@ -257,9 +185,9 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval for (fsp=Files;fsp;fsp=fsp->next,count++) { if (fsp->open && - fsp->fd_ptr != NULL && - fsp->fd_ptr->dev == dev && - fsp->fd_ptr->inode == inode && + fsp->fd != -1 && + fsp->dev == dev && + fsp->inode == inode && (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) && (tval ? (fsp->open_time.tv_usec == tval->tv_usec) : True )) { if (count > 10) { @@ -282,9 +210,9 @@ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) for (fsp=Files;fsp;fsp=fsp->next) { if (fsp->open && - fsp->fd_ptr != NULL && - fsp->fd_ptr->dev == dev && - fsp->fd_ptr->inode == inode ) + fsp->fd != -1 && + fsp->dev == dev && + fsp->inode == inode ) return fsp; } @@ -301,9 +229,9 @@ files_struct *file_find_di_next(files_struct *start_fsp) for (fsp = start_fsp->next;fsp;fsp=fsp->next) { if (fsp->open && - fsp->fd_ptr != NULL && - fsp->fd_ptr->dev == start_fsp->fd_ptr->dev && - fsp->fd_ptr->inode == start_fsp->fd_ptr->inode ) + fsp->fd != -1 && + fsp->dev == start_fsp->dev && + fsp->inode == start_fsp->inode ) return fsp; } @@ -334,31 +262,13 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)) { - conn->vfs_ops.fsync(fsp->fd_ptr->fd); + if (fsp->open && (conn == fsp->conn) && (fsp->fd != -1)) { + conn->vfs_ops.fsync(fsp->fd); } } } -/**************************************************************************** -free up a fd_ptr -****************************************************************************/ -void fd_ptr_free(file_fd_struct *fd_ptr) -{ - DLIST_REMOVE(FileFd, fd_ptr); - - fd_ptr_used--; - - DEBUG(5,("freed fd_ptr structure (%d used)\n", fd_ptr_used)); - - /* paranoia */ - ZERO_STRUCTP(fd_ptr); - - free(fd_ptr); -} - - /**************************************************************************** free up a fsp ****************************************************************************/ @@ -368,10 +278,6 @@ void file_free(files_struct *fsp) string_free(&fsp->fsp_name); - if ((fsp->fd_ptr != NULL) && fsp->fd_ptr->ref_count == 0) { - fd_ptr_free(fsp->fd_ptr); - } - bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; -- cgit From 2733f5352a384561b4df7ea14c5962f3cd079166 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Mon, 10 Apr 2000 13:12:04 +0000 Subject: initialise fsp->fd to -1 (This used to be commit 5257ff5d67632922a64266ad2ce5d5a38c701cbc) --- source3/smbd/files.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 127d2fcac9..e971de095b 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -84,6 +84,7 @@ files_struct *file_new(void ) if (!fsp) return NULL; ZERO_STRUCTP(fsp); + fsp->fd = -1; first_file = (i+1) % real_max_open_files; -- cgit From 6259f51dd9918eccc9697f3763d918f7c9b82b50 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Sat, 22 Apr 2000 00:33:16 +0000 Subject: This is a *big* checkin that may break some things, but implements the new open mechanism Andrew & I discussed. config.sub: configure: Included the QNX patch. include/vfs.h: smbd/vfs-wrap.c: smbd/vfs.c: Added ftruncate vfs call (needed). Note that we will also need locking calls in the vfs (to be added). lib/util_unistr.c: nmbd/nmbd_processlogon.c: Fix for NT domain logons causing nmbd to core dump. Also fix for sidsize DOS bug. locking/locking.c: Check value of ret before using it for memdup. printing/printing.c: Convert print_fsp_open to return an allocated fsp. rpc_server/srv_lsa.c: Fix for NT domain logons. I have removed all use of lp_share_modes() from the code (although I left the parameter in the table for backwards compatibility). It no longer makes sense for this to exist. smbd/close.c: Removed lp_share_modes(). smbd/fileio.c: Fixed parameters to unlock_share_entry call in panic code. smbd/files.c: Correctly set the unix_ERR_code to ERRnofids on fsp allocation fail. smbd/nttrans.c: smbd/reply.c: smbd/trans2.c: Changed all occurrences of open_file_shared/open_directory/ open_file_stat to return an fsp from the call. smbd/open.c: Changed all occurrences of open_file_shared/open_directory/ open_file_stat to return an fsp from the call. In addition I have fixed a long standing race condition in the deny mode processing w.r.t. two smbd's creating a file. Andrew, please note that your original idea of using open with O_EXCL in this case would not work (I went over the races very carefully) and so we must re-check deny modes *after* the open() call returns. This is because there is a race between the open with O_EXCL and the lock of the share mode entry. Imagine the case where the first smbd does the open with O_EXCL and a deny mode of DENY_ALL, but is pre-empted before it locks the share modes and creates the deny mode entry for DENY_ALL. A second smbd could then come in with O_RDONLY and a deny mode of DENY_NONE and the two opens would be allowed. The *only* way to fix this race is to lock the share modes after the open and then do the deny mode checks *after* this lock in the case where the file did not originally exist. This code will need extensive testing but seems to initially work. Jeremy. (This used to be commit ab0ecc39d688f16b9692fe90b991f0b89287070a) --- source3/smbd/files.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e971de095b..6c0465097b 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -77,11 +77,17 @@ files_struct *file_new(void ) } DEBUG(0,("ERROR! Out of file structures\n")); + unix_ERR_class = ERRSRV; + unix_ERR_code = ERRnofids; return NULL; } fsp = (files_struct *)malloc(sizeof(*fsp)); - if (!fsp) return NULL; + if (!fsp) { + unix_ERR_class = ERRSRV; + unix_ERR_code = ERRnofids; + return NULL; + } ZERO_STRUCTP(fsp); fsp->fd = -1; -- cgit From e82dbfcbe97c79b1c81915ae949bb2b1763970ba Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Mon, 24 Apr 2000 19:23:51 +0000 Subject: Now that fsp's are created on successful file open, the structure member fsp->open is no longer needed (if an fsp pointer is valid, then it's open :-). NB for Luke, this patch also did not apply to TNG. TNG is not yet identical w.r.t file serving with HEAD. This makes it impossible for me to help maintain TNG. Please fix asap. lib/substitute.c: Removed unused variable (pidstr). Jeremy. (This used to be commit 389b700a26e8a308a0dff6fc038c38068aa0119a) --- source3/smbd/files.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 6c0465097b..e644f52669 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -120,7 +120,7 @@ void file_close_conn(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next = fsp->next; - if (fsp->conn == conn && fsp->open) { + if (fsp->conn == conn) { close_file(fsp,False); } } @@ -173,7 +173,7 @@ void file_close_user(int vuid) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if ((fsp->vuid == vuid) && fsp->open) { + if (fsp->vuid == vuid) { close_file(fsp,False); } } @@ -191,8 +191,7 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next,count++) { - if (fsp->open && - fsp->fd != -1 && + if (fsp->fd != -1 && fsp->dev == dev && fsp->inode == inode && (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) && @@ -207,6 +206,22 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval return NULL; } +/**************************************************************************** + Check if an fsp still exists. +****************************************************************************/ + +files_struct *file_find_fsp(files_struct *orig_fsp) +{ + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp == orig_fsp) + return fsp; + } + + return NULL; +} + /**************************************************************************** Find the first fsp given a device and inode. ****************************************************************************/ @@ -216,8 +231,7 @@ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next) { - if (fsp->open && - fsp->fd != -1 && + if ( fsp->fd != -1 && fsp->dev == dev && fsp->inode == inode ) return fsp; @@ -235,8 +249,7 @@ files_struct *file_find_di_next(files_struct *start_fsp) files_struct *fsp; for (fsp = start_fsp->next;fsp;fsp=fsp->next) { - if (fsp->open && - fsp->fd != -1 && + if ( fsp->fd != -1 && fsp->dev == start_fsp->dev && fsp->inode == start_fsp->inode ) return fsp; @@ -253,7 +266,7 @@ files_struct *file_find_print(void) files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next) { - if (fsp->open && fsp->print_file) return fsp; + if (fsp->print_file) return fsp; } return NULL; @@ -269,7 +282,7 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if (fsp->open && (conn == fsp->conn) && (fsp->fd != -1)) { + if ((conn == fsp->conn) && (fsp->fd != -1)) { conn->vfs_ops.fsync(fsp->fd); } } -- cgit From 693ffb8466ada58ecc59fde754ba79fc6f51528d Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Tue, 2 May 2000 02:23:41 +0000 Subject: Added sys_fork() and sys_getpid() functions to stop the overhead of doing a system call every time we want to just get our pid. Jeremy. (This used to be commit 148628b616b5c29ba6340d65fc3ddbcabba6e67a) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e644f52669..5b930f9940 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -55,7 +55,7 @@ files_struct *file_new(void ) increases the chance that the errant client will get an error rather than causing corruption */ if (first_file == 0) { - first_file = (getpid() ^ (int)time(NULL)) % real_max_open_files; + first_file = (sys_getpid() ^ (int)time(NULL)) % real_max_open_files; } i = bitmap_find(file_bmap, first_file); -- cgit From c88222da0ced7edf90b68e68ec49e0fe35a512fe Mon Sep 17 00:00:00 2001 From: Herb Lewis <herb@samba.org> Date: Wed, 10 May 2000 01:31:46 +0000 Subject: Fix for misunderstanding of fsync added when vfs layer was done. Samba was doing fsync's (bleagh). Jeremy. (This used to be commit f9a52cadbf11f7afcef754a59d783964a2edb5bc) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 5b930f9940..a4837a1a8b 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -283,7 +283,7 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; if ((conn == fsp->conn) && (fsp->fd != -1)) { - conn->vfs_ops.fsync(fsp->fd); + sync_file(conn,fsp); } } } -- cgit From 49a0e6d5989656c1b3c9c063a20308ca4ee5d73b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Wed, 10 May 2000 10:41:59 +0000 Subject: more merging voodoo this adds "#define OLD_NTDOMAIN 1" in lots of places. Don't panic - this isn't permanent, it should go after another few merge steps have been done (This used to be commit 92109d7b3c06f240452d39f669ecb8c9c86ab610) --- source3/smbd/files.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index a4837a1a8b..2909d49a2a 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -1,3 +1,4 @@ +#define OLD_NTDOMAIN 1 /* Unix SMB/Netbios implementation. Version 1.9. @@ -363,3 +364,4 @@ void file_chain_restore(void) { chain_fsp = oplock_save_chain_fsp; } +#undef OLD_NTDOMAIN -- cgit From da3053048c3d224a20d6383ac6682d31059cd46c Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Sun, 11 Mar 2001 00:32:10 +0000 Subject: Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549) --- source3/smbd/files.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 2909d49a2a..a4837a1a8b 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -1,4 +1,3 @@ -#define OLD_NTDOMAIN 1 /* Unix SMB/Netbios implementation. Version 1.9. @@ -364,4 +363,3 @@ void file_chain_restore(void) { chain_fsp = oplock_save_chain_fsp; } -#undef OLD_NTDOMAIN -- cgit From 3c2c047e822b6c74ecc176d1623d5292657cde62 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 13 Apr 2001 19:33:26 +0000 Subject: Added fix from "Eric Boehm" <boehm@nortelnetworks.com> to try and set hard limit before setting soft limit. Jeremy. (This used to be commit a1eb2752a8bee9cc7d92c664c3de84e02620933d) --- source3/smbd/files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index a4837a1a8b..33243e1e94 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -134,7 +134,7 @@ initialise file structures void file_init(void) { - int request_max_open_files = lp_max_open_files(); + int request_max_open_files = lp_max_open_files(); int real_lim; /* @@ -146,8 +146,8 @@ void file_init(void) real_max_open_files = real_lim - MAX_OPEN_FUDGEFACTOR; - if(real_max_open_files != request_max_open_files) { - DEBUG(1,("file_init: Information only: requested %d \ + if(real_max_open_files != request_max_open_files) { + DEBUG(1,("file_init: Information only: requested %d \ open files, %d are available.\n", request_max_open_files, real_max_open_files)); } -- cgit From 53850c51caf1c4d53ff285b2e5505e0615beeeee Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Sat, 14 Apr 2001 00:19:12 +0000 Subject: configure: configure.in: include/config.h.in: include/profile.h: smbd/vfs-wrap.c: smbd/vfs.c: Added fchmod and fchown to VFS (sorry Gerald - but we needed them anyway). smbd/dosmode.c: smbd/files.c: printing/printfsp.c: smbd/close.c: smbd/open.c: Fixed "dos filemode" correctly so there are no race conditions. Forces test of open of file O_WRONLY before allowing fchmod as root. Afterwards, calls standard close function that preserves POSIX locks due to POSIX-me-harder braindamage. :-). Andrew please review this code. Also - in removing the tmpdir param in smbrun an extra NULL parameter was missed in each print_run_command() call (which is a varargs fn.). Now fixed. Jeremy. (This used to be commit 32397e5bc6d995ce7ca37c82d6aedc1e5b1b6fbd) --- source3/smbd/files.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 33243e1e94..27dfad7c48 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -43,7 +43,7 @@ static int files_used; /**************************************************************************** find first available file slot ****************************************************************************/ -files_struct *file_new(void ) +files_struct *file_new(connection_struct *conn) { int i; static int first_file; @@ -72,7 +72,7 @@ files_struct *file_new(void ) for (fsp=Files;fsp;fsp=next) { next=fsp->next; if (attempt_close_oplocked_file(fsp)) { - return file_new(); + return file_new(conn); } } @@ -91,6 +91,7 @@ files_struct *file_new(void ) ZERO_STRUCTP(fsp); fsp->fd = -1; + fsp->conn = conn; first_file = (i+1) % real_max_open_files; -- cgit From 61b2794968faa35dc91edce17e9b91e5366c3514 Mon Sep 17 00:00:00 2001 From: Simo Sorce <idra@samba.org> Date: Mon, 17 Sep 2001 11:25:41 +0000 Subject: move to SAFE_FREE() (This used to be commit a95943fde0ad89ae3f2deca2f7ba9cb5ab612b74) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 27dfad7c48..4273c205cd 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -311,7 +311,7 @@ void file_free(files_struct *fsp) if (fsp == chain_fsp) chain_fsp = NULL; - free(fsp); + SAFE_FREE(fsp); } -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter <tpot@samba.org> Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/smbd/files.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 4273c205cd..8c7fa930e1 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -21,8 +21,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - static int real_max_open_files; #define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < real_max_open_files)) -- cgit From 88b55f47b4914f7d390939e4394ec3edd42be91f Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Sat, 20 Oct 2001 21:59:34 +0000 Subject: Move from timestamp to gen count file id's for finding oplocked files in a tdb. Jeremy. (This used to be commit 058ae6b58f61ef46013dd076af3a84de5fbaaab1) --- source3/smbd/files.c | 77 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 20 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 8c7fa930e1..3935a12442 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -39,8 +39,22 @@ static files_struct *oplock_save_chain_fsp = NULL; static int files_used; /**************************************************************************** - find first available file slot + Return a unique number identifying this fsp over the life of this pid. ****************************************************************************/ + +static unsigned long get_gen_count(void) +{ + static unsigned long file_gen_counter; + + if ((++file_gen_counter) == 0) + return ++file_gen_counter; + return file_gen_counter; +} + +/**************************************************************************** + Find first available file slot. +****************************************************************************/ + files_struct *file_new(connection_struct *conn) { int i; @@ -90,6 +104,8 @@ files_struct *file_new(connection_struct *conn) ZERO_STRUCTP(fsp); fsp->fd = -1; fsp->conn = conn; + fsp->file_id = get_gen_count(); + GetTimeOfDay(&fsp->open_time); first_file = (i+1) % real_max_open_files; @@ -109,10 +125,10 @@ files_struct *file_new(connection_struct *conn) return fsp; } - /**************************************************************************** -close all open files for a connection + Close all open files for a connection. ****************************************************************************/ + void file_close_conn(connection_struct *conn) { files_struct *fsp, *next; @@ -126,7 +142,7 @@ void file_close_conn(connection_struct *conn) } /**************************************************************************** -initialise file structures + Initialise file structures. ****************************************************************************/ #define MAX_OPEN_FUDGEFACTOR 10 @@ -162,10 +178,10 @@ open files, %d are available.\n", request_max_open_files, real_max_open_files)); set_pipe_handle_offset(real_max_open_files); } - /**************************************************************************** -close files open by a specified vuid + Close files open by a specified vuid. ****************************************************************************/ + void file_close_user(int vuid) { files_struct *fsp, *next; @@ -178,13 +194,32 @@ void file_close_user(int vuid) } } +/**************************************************************************** + Find a fsp given a file descriptor. +****************************************************************************/ + +files_struct *file_find_fd(int fd) +{ + int count=0; + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next,count++) { + if (fsp->fd == fd) { + if (count > 10) { + DLIST_PROMOTE(Files, fsp); + } + return fsp; + } + } + + return NULL; +} /**************************************************************************** - Find a fsp given a device, inode and timevalue - If this is from a kernel oplock break request then tval may be NULL. + Find a fsp given a device, inode and file_id. ****************************************************************************/ -files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval) +files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id) { int count=0; files_struct *fsp; @@ -193,8 +228,7 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval if (fsp->fd != -1 && fsp->dev == dev && fsp->inode == inode && - (tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) && - (tval ? (fsp->open_time.tv_usec == tval->tv_usec) : True )) { + fsp->file_id == file_id ) { if (count > 10) { DLIST_PROMOTE(Files, fsp); } @@ -258,8 +292,9 @@ files_struct *file_find_di_next(files_struct *start_fsp) } /**************************************************************************** -find a fsp that is open for printing + Find a fsp that is open for printing. ****************************************************************************/ + files_struct *file_find_print(void) { files_struct *fsp; @@ -271,10 +306,10 @@ files_struct *file_find_print(void) return NULL; } - /**************************************************************************** -sync open files on a connection + Sync open files on a connection. ****************************************************************************/ + void file_sync_all(connection_struct *conn) { files_struct *fsp, *next; @@ -287,10 +322,10 @@ void file_sync_all(connection_struct *conn) } } - /**************************************************************************** -free up a fsp + Free up a fsp. ****************************************************************************/ + void file_free(files_struct *fsp) { DLIST_REMOVE(Files, fsp); @@ -312,16 +347,17 @@ void file_free(files_struct *fsp) SAFE_FREE(fsp); } - /**************************************************************************** -get a fsp from a packet given the offset of a 16 bit fnum + Get a fsp from a packet given the offset of a 16 bit fnum. ****************************************************************************/ + files_struct *file_fsp(char *buf, int where) { int fnum, count=0; files_struct *fsp; - if (chain_fsp) return chain_fsp; + if (chain_fsp) + return chain_fsp; fnum = SVAL(buf, where); @@ -338,7 +374,7 @@ files_struct *file_fsp(char *buf, int where) } /**************************************************************************** - Reset the chained fsp - done at the start of a packet reply + Reset the chained fsp - done at the start of a packet reply. ****************************************************************************/ void file_chain_reset(void) @@ -358,6 +394,7 @@ void file_chain_save(void) /**************************************************************************** Restore the chained fsp - done after an oplock break. ****************************************************************************/ + void file_chain_restore(void) { chain_fsp = oplock_save_chain_fsp; -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter <tpot@samba.org> Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/smbd/files.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 3935a12442..c055fb54eb 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. Files[] structure handling Copyright (C) Andrew Tridgell 1998 -- cgit From 83219da3028a0341a9c7b2db38738ca30288686b Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Tue, 22 Oct 2002 22:17:29 +0000 Subject: Fix for systems that allow more than 65536 open files per process. Jeremy. (This used to be commit 947a56ce00e552e8b8d2ed64435eabde6225f044) --- source3/smbd/files.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index c055fb54eb..d926718c5d 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -112,6 +112,8 @@ files_struct *file_new(connection_struct *conn) files_used++; fsp->fnum = i + FILE_HANDLE_OFFSET; + SMB_ASSERT(fsp->fnum < 65536); + string_set(&fsp->fsp_name,""); DLIST_ADD(Files, fsp); @@ -144,7 +146,7 @@ void file_close_conn(connection_struct *conn) Initialise file structures. ****************************************************************************/ -#define MAX_OPEN_FUDGEFACTOR 10 +#define MAX_OPEN_FUDGEFACTOR 20 void file_init(void) { @@ -160,11 +162,16 @@ void file_init(void) real_max_open_files = real_lim - MAX_OPEN_FUDGEFACTOR; + if (real_max_open_files + FILE_HANDLE_OFFSET + MAX_OPEN_PIPES > 65536) + real_max_open_files = 65536 - FILE_HANDLE_OFFSET - MAX_OPEN_PIPES; + if(real_max_open_files != request_max_open_files) { DEBUG(1,("file_init: Information only: requested %d \ open files, %d are available.\n", request_max_open_files, real_max_open_files)); } + SMB_ASSERT(real_max_open_files > 100); + file_bmap = bitmap_allocate(real_max_open_files); if (!file_bmap) { -- cgit From e8573c8fa928602fd979d5ac45c692e7464f0aad Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy <ab@samba.org> Date: Mon, 12 May 2003 01:20:17 +0000 Subject: Add NT quota support. Patch from Stefan (metze) Metzemacher 1. Allows to change quota settings for shared mount points from Win2K and WinXP from Explorer properties tab 2. Disabled by default and when requested, will be probed and enabled only on Linux where it works 3. Was tested for approx. two weeks now on Linux by two independent QA teams, have not found any bugs so far Documentation to follow (This used to be commit 4bf022ce9e45be85609426762ba2644ac2031326) --- source3/smbd/files.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index d926718c5d..4d1409feac 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -338,6 +338,10 @@ void file_free(files_struct *fsp) string_free(&fsp->fsp_name); + if (fsp->fake_file_handle) { + destroy_fake_file_handle(&fsp->fake_file_handle); + } + bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; -- cgit From f161839a7493602ee4e9be2459230634ddfbb2b1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Thu, 22 May 2003 20:31:35 +0000 Subject: Stat opens can have fsp->fd == -1 and will have a share entry. Ensure that file_find_dif will find them. Fixes a core dump in smbd/open.c. Jeremy. (This used to be commit 0e2165630d2ce31076fef6d7098e45c8fd327e23) --- source3/smbd/files.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 4d1409feac..f0fd6b7a73 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -231,13 +231,21 @@ files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_i files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next,count++) { - if (fsp->fd != -1 && - fsp->dev == dev && + /* We can have a fsp->fd == -1 here as it could be a stat open. */ + if (fsp->dev == dev && fsp->inode == inode && fsp->file_id == file_id ) { if (count > 10) { DLIST_PROMOTE(Files, fsp); } + /* Paranoia check. */ + if (fsp->fd == -1 && fsp->oplock_type != NO_OPLOCK) { + DEBUG(0,("file_find_dif: file %s dev = %x, inode = %.0f, file_id = %u \ +oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, (unsigned int)fsp->dev, + (double)fsp->inode, (unsigned int)fsp->file_id, + (unsigned int)fsp->oplock_type )); + smb_panic("file_find_dif\n"); + } return fsp; } } -- cgit From 3a052c9e0a62c1f8ddf4c2e509cff52a4d157d21 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Sat, 16 Aug 2003 02:34:03 +0000 Subject: Implemented the level 1010 NT rename level. Many fixes for Samba4 test correctness. Jeremy. (This used to be commit f57429befa43d63ed9a6e19b854e22fd4151db40) --- source3/smbd/files.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index f0fd6b7a73..186fa96d7d 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -200,6 +200,18 @@ void file_close_user(int vuid) } } +void file_dump_open_table(void) +{ + int count=0; + files_struct *fsp; + + for (fsp=Files;fsp;fsp=fsp->next,count++) { + DEBUG(10,("Files[%d], fnum = %d, name %s, fd = %d, fileid = %lu, dev = %x, inode = %.0f\n", + count, fsp->fnum, fsp->fsp_name, fsp->fd, (unsigned long)fsp->file_id, + (unsigned int)fsp->dev, (double)fsp->inode )); + } +} + /**************************************************************************** Find a fsp given a file descriptor. ****************************************************************************/ -- cgit From 6d6401a67a9985c8c51175db520114dc2ef421ce Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Tue, 19 Aug 2003 01:53:45 +0000 Subject: Implement SMBexit properly. Found by Samba4 tester. You must do a make clean proto all; after this commit. Jeremy. (This used to be commit 27af1f9feab12542dc538bfceac4593e644ba3b4) --- source3/smbd/files.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 186fa96d7d..1fe6f250e5 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -142,6 +142,22 @@ void file_close_conn(connection_struct *conn) } } +/**************************************************************************** + Close all open files for a pid. +****************************************************************************/ + +void file_close_pid(uint16 smbpid) +{ + files_struct *fsp, *next; + + for (fsp=Files;fsp;fsp=next) { + next = fsp->next; + if (fsp->file_pid == smbpid) { + close_file(fsp,False); + } + } +} + /**************************************************************************** Initialise file structures. ****************************************************************************/ -- cgit From 273479391f0c6e008c1e01a7f3ffa2de1862b9fd Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Wed, 17 Sep 2003 19:36:38 +0000 Subject: Fix coredump from Samba4 torture suite. Jeremy. (This used to be commit 9c1bab944526270d2ad79c75894c33f58f8e3845) --- source3/smbd/files.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 1fe6f250e5..80544c9a30 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -405,6 +405,8 @@ files_struct *file_fsp(char *buf, int where) if (chain_fsp) return chain_fsp; + if (!buf) + return NULL; fnum = SVAL(buf, where); for (fsp=Files;fsp;fsp=fsp->next, count++) { -- cgit From 8c1c918c94b443c7154d535b1f99201dc1767f97 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Mon, 18 Oct 2004 22:01:10 +0000 Subject: r3050: Steal from Samba4 :-). Make us pass most of the new lock tests (except for the cancel lock which I have to add). Jeremy. (This used to be commit cf7f89999e0c6becd4617c812400d1e71b9c0a30) --- source3/smbd/files.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 80544c9a30..580dc54545 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -289,12 +289,12 @@ files_struct *file_find_fsp(files_struct *orig_fsp) { files_struct *fsp; - for (fsp=Files;fsp;fsp=fsp->next) { - if (fsp == orig_fsp) - return fsp; - } + for (fsp=Files;fsp;fsp=fsp->next) { + if (fsp == orig_fsp) + return fsp; + } - return NULL; + return NULL; } /**************************************************************************** @@ -303,16 +303,16 @@ files_struct *file_find_fsp(files_struct *orig_fsp) files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) { - files_struct *fsp; + files_struct *fsp; - for (fsp=Files;fsp;fsp=fsp->next) { - if ( fsp->fd != -1 && - fsp->dev == dev && - fsp->inode == inode ) - return fsp; - } + for (fsp=Files;fsp;fsp=fsp->next) { + if ( fsp->fd != -1 && + fsp->dev == dev && + fsp->inode == inode ) + return fsp; + } - return NULL; + return NULL; } /**************************************************************************** @@ -321,16 +321,16 @@ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) files_struct *file_find_di_next(files_struct *start_fsp) { - files_struct *fsp; + files_struct *fsp; - for (fsp = start_fsp->next;fsp;fsp=fsp->next) { - if ( fsp->fd != -1 && - fsp->dev == start_fsp->dev && - fsp->inode == start_fsp->inode ) - return fsp; - } + for (fsp = start_fsp->next;fsp;fsp=fsp->next) { + if ( fsp->fd != -1 && + fsp->dev == start_fsp->dev && + fsp->inode == start_fsp->inode ) + return fsp; + } - return NULL; + return NULL; } /**************************************************************************** @@ -388,7 +388,9 @@ void file_free(files_struct *fsp) information */ ZERO_STRUCTP(fsp); - if (fsp == chain_fsp) chain_fsp = NULL; + if (fsp == chain_fsp) { + chain_fsp = NULL; + } SAFE_FREE(fsp); } -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 580dc54545..ecf39c2b54 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -93,7 +93,7 @@ files_struct *file_new(connection_struct *conn) return NULL; } - fsp = (files_struct *)malloc(sizeof(*fsp)); + fsp = SMB_MALLOC_P(files_struct); if (!fsp) { unix_ERR_class = ERRSRV; unix_ERR_code = ERRnofids; -- cgit From eb546db88d9d4ad8da3709b2edc4d455a88e6119 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Thu, 10 Mar 2005 01:30:14 +0000 Subject: r5720: Attempt to fix bug #2382 (Excel shared workbook stops working). Also incorporates part of the fix created by ke_miyata@itg.hitachi.co.jp for bug #2045 (MS-Office behavior of timestamp). Jeremy. (This used to be commit 4f3b12ac73487f4ccb37c17506af1abf5acc80cd) --- source3/smbd/files.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index ecf39c2b54..547206815e 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -37,6 +37,13 @@ static files_struct *oplock_save_chain_fsp = NULL; static int files_used; +/* A singleton cache to speed up searching by dev/inode. */ +static struct fsp_singleton_cache { + files_struct *fsp; + SMB_DEV_T dev; + SMB_INO_T inode; +} fsp_fi_cache; + /**************************************************************************** Return a unique number identifying this fsp over the life of this pid. ****************************************************************************/ @@ -122,6 +129,11 @@ files_struct *file_new(connection_struct *conn) i, fsp->fnum, files_used)); chain_fsp = fsp; + + /* A new fsp invalidates a negative fsp_fi_cache. */ + if (fsp_fi_cache.fsp == NULL) { + ZERO_STRUCT(fsp_fi_cache); + } return fsp; } @@ -299,19 +311,34 @@ files_struct *file_find_fsp(files_struct *orig_fsp) /**************************************************************************** Find the first fsp given a device and inode. + We use a singleton cache here to speed up searching from getfilepathinfo + calls. ****************************************************************************/ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) { files_struct *fsp; + if (fsp_fi_cache.dev == dev && fsp_fi_cache.inode == inode) { + /* Positive or negative cache hit. */ + return fsp_fi_cache.fsp; + } + + fsp_fi_cache.dev = dev; + fsp_fi_cache.inode = inode; + for (fsp=Files;fsp;fsp=fsp->next) { if ( fsp->fd != -1 && fsp->dev == dev && - fsp->inode == inode ) + fsp->inode == inode ) { + /* Setup positive cache. */ + fsp_fi_cache.fsp = fsp; return fsp; + } } + /* Setup negative cache. */ + fsp_fi_cache.fsp = NULL; return NULL; } @@ -342,12 +369,35 @@ files_struct *file_find_print(void) files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next) { - if (fsp->print_file) return fsp; + if (fsp->print_file) { + return fsp; + } } return NULL; } +/**************************************************************************** + Set a pending modtime across all files with a given dev/ino pair. +****************************************************************************/ + +void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod) +{ + files_struct *fsp; + + if (null_mtime(pmod)) { + return; + } + + for (fsp = Files;fsp;fsp=fsp->next) { + if ( fsp->fd != -1 && + fsp->dev == tfsp->dev && + fsp->inode == tfsp->inode ) { + fsp->pending_modtime = pmod; + } + } +} + /**************************************************************************** Sync open files on a connection. ****************************************************************************/ @@ -392,6 +442,11 @@ void file_free(files_struct *fsp) chain_fsp = NULL; } + /* Closing a file can invalidate the positive cache. */ + if (fsp == fsp_fi_cache.fsp) { + ZERO_STRUCT(fsp_fi_cache); + } + SAFE_FREE(fsp); } -- cgit From 95e68fa7f8c109204b3ddaeb530e192c71b40e58 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Thu, 10 Mar 2005 21:43:58 +0000 Subject: r5731: Get delayed write semantics closer to W2K3. We need to store 2 times. This may fix bug #2382. Jeremy. (This used to be commit a27c351e6beafc6609790a9bb9a3d0a1331e8f35) --- source3/smbd/files.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 547206815e..143c119693 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -379,6 +379,7 @@ files_struct *file_find_print(void) /**************************************************************************** Set a pending modtime across all files with a given dev/ino pair. + Record the owner of that modtime. ****************************************************************************/ void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod) @@ -394,8 +395,11 @@ void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod) fsp->dev == tfsp->dev && fsp->inode == tfsp->inode ) { fsp->pending_modtime = pmod; + fsp->pending_modtime_owner = False; } } + + tfsp->pending_modtime_owner = True; } /**************************************************************************** -- cgit From 0557c6cba2a21c9df547fbc8ff4db2899bc1c171 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 1 Apr 2005 23:11:28 +0000 Subject: r6172: Tidy up error processing significantly. Remove unix_ERR_XXX global nastyness. Jeremy. (This used to be commit d3379fe61bb934082b51a37adac232a96bafcf46) --- source3/smbd/files.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 143c119693..e893e9fefc 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -95,15 +95,13 @@ files_struct *file_new(connection_struct *conn) } DEBUG(0,("ERROR! Out of file structures\n")); - unix_ERR_class = ERRSRV; - unix_ERR_code = ERRnofids; + set_saved_error_triple(ERRSRV, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES); return NULL; } fsp = SMB_MALLOC_P(files_struct); if (!fsp) { - unix_ERR_class = ERRSRV; - unix_ERR_code = ERRnofids; + set_saved_error_triple(ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY); return NULL; } -- cgit From af8a691db11a5072865f8b03fd1cbd3aab5cb6d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 8 Jul 2005 04:51:27 +0000 Subject: r8219: Merge the new open code from HEAD to 3.0. Haven't yet run the torture tests on this as it's very late NY time (just wanted to get this work into the tree). I'll test this over the weekend.... Jerry - in looking at the difference between the two trees there seem to be some printing/ntprinting.c and registry changes we might want to examine to try keep in sync. Jeremy. (This used to be commit c7fe18761e2c753afbffd3a78abff46472a9b8eb) --- source3/smbd/files.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 9 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e893e9fefc..80e5b0f710 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -106,7 +106,19 @@ files_struct *file_new(connection_struct *conn) } ZERO_STRUCTP(fsp); - fsp->fd = -1; + + fsp->fh = SMB_MALLOC_P(struct fd_handle); + if (!fsp->fh) { + SAFE_FREE(fsp); + set_saved_error_triple(ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY); + return NULL; + } + + ZERO_STRUCTP(fsp->fh); + + fsp->fh->ref_count = 1; + fsp->fh->fd = -1; + fsp->conn = conn; fsp->file_id = get_gen_count(); GetTimeOfDay(&fsp->open_time); @@ -233,7 +245,7 @@ void file_dump_open_table(void) for (fsp=Files;fsp;fsp=fsp->next,count++) { DEBUG(10,("Files[%d], fnum = %d, name %s, fd = %d, fileid = %lu, dev = %x, inode = %.0f\n", - count, fsp->fnum, fsp->fsp_name, fsp->fd, (unsigned long)fsp->file_id, + count, fsp->fnum, fsp->fsp_name, fsp->fh->fd, (unsigned long)fsp->file_id, (unsigned int)fsp->dev, (double)fsp->inode )); } } @@ -248,7 +260,7 @@ files_struct *file_find_fd(int fd) files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next,count++) { - if (fsp->fd == fd) { + if (fsp->fh->fd == fd) { if (count > 10) { DLIST_PROMOTE(Files, fsp); } @@ -269,7 +281,7 @@ files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_i files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next,count++) { - /* We can have a fsp->fd == -1 here as it could be a stat open. */ + /* We can have a fsp->fh->fd == -1 here as it could be a stat open. */ if (fsp->dev == dev && fsp->inode == inode && fsp->file_id == file_id ) { @@ -277,7 +289,7 @@ files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_i DLIST_PROMOTE(Files, fsp); } /* Paranoia check. */ - if (fsp->fd == -1 && fsp->oplock_type != NO_OPLOCK) { + if (fsp->fh->fd == -1 && fsp->oplock_type != NO_OPLOCK) { DEBUG(0,("file_find_dif: file %s dev = %x, inode = %.0f, file_id = %u \ oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, (unsigned int)fsp->file_id, @@ -326,7 +338,7 @@ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) fsp_fi_cache.inode = inode; for (fsp=Files;fsp;fsp=fsp->next) { - if ( fsp->fd != -1 && + if ( fsp->fh->fd != -1 && fsp->dev == dev && fsp->inode == inode ) { /* Setup positive cache. */ @@ -349,7 +361,7 @@ files_struct *file_find_di_next(files_struct *start_fsp) files_struct *fsp; for (fsp = start_fsp->next;fsp;fsp=fsp->next) { - if ( fsp->fd != -1 && + if ( fsp->fh->fd != -1 && fsp->dev == start_fsp->dev && fsp->inode == start_fsp->inode ) return fsp; @@ -389,7 +401,7 @@ void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod) } for (fsp = Files;fsp;fsp=fsp->next) { - if ( fsp->fd != -1 && + if ( fsp->fh->fd != -1 && fsp->dev == tfsp->dev && fsp->inode == tfsp->inode ) { fsp->pending_modtime = pmod; @@ -410,7 +422,7 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; - if ((conn == fsp->conn) && (fsp->fd != -1)) { + if ((conn == fsp->conn) && (fsp->fh->fd != -1)) { sync_file(conn,fsp); } } @@ -430,6 +442,12 @@ void file_free(files_struct *fsp) destroy_fake_file_handle(&fsp->fake_file_handle); } + if (fsp->fh->ref_count == 1) { + SAFE_FREE(fsp->fh); + } else { + fsp->fh->ref_count--; + } + bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; @@ -506,3 +524,49 @@ void file_chain_restore(void) { chain_fsp = oplock_save_chain_fsp; } + +files_struct *dup_file_fsp(files_struct *fsp, + uint32 access_mask, + uint32 share_access, + uint32 create_options) +{ + files_struct *dup_fsp = file_new(fsp->conn); + + if (!dup_fsp) { + return NULL; + } + + SAFE_FREE(dup_fsp->fh); + + dup_fsp->fh = fsp->fh; + dup_fsp->fh->ref_count++; + + dup_fsp->dev = fsp->dev; + dup_fsp->inode = fsp->inode; + dup_fsp->initial_allocation_size = fsp->initial_allocation_size; + dup_fsp->mode = fsp->mode; + dup_fsp->file_pid = fsp->file_pid; + dup_fsp->vuid = fsp->vuid; + dup_fsp->open_time = fsp->open_time; + dup_fsp->access_mask = access_mask; + dup_fsp->share_access = share_access; + dup_fsp->pending_modtime_owner = fsp->pending_modtime_owner; + dup_fsp->pending_modtime = fsp->pending_modtime; + dup_fsp->last_write_time = fsp->last_write_time; + dup_fsp->oplock_type = fsp->oplock_type; + dup_fsp->can_lock = fsp->can_lock; + dup_fsp->can_read = (access_mask & (FILE_READ_DATA)) ? True : False; + if (!CAN_WRITE(fsp->conn)) { + dup_fsp->can_write = False; + } else { + dup_fsp->can_write = (access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ? True : False; + } + dup_fsp->print_file = fsp->print_file; + dup_fsp->modified = fsp->modified; + dup_fsp->is_directory = fsp->is_directory; + dup_fsp->is_stat = fsp->is_stat; + dup_fsp->aio_write_behind = fsp->aio_write_behind; + string_set(&dup_fsp->fsp_name,fsp->fsp_name); + + return dup_fsp; +} -- cgit From e24397f084282de2b88dc83995740037e8c4cf32 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Sun, 10 Jul 2005 16:40:06 +0000 Subject: r8292: Tidy up function comments. Jeremy. (This used to be commit 8de6b1592ad205f59c44ed30102a56594f65e555) --- source3/smbd/files.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 80e5b0f710..c90c2b627c 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -238,6 +238,10 @@ void file_close_user(int vuid) } } +/**************************************************************************** + Debug to enumerate all open files in the smbd. +****************************************************************************/ + void file_dump_open_table(void) { int count=0; @@ -508,7 +512,7 @@ void file_chain_reset(void) } /**************************************************************************** -Save the chained fsp - done when about to do an oplock break. + Save the chained fsp - done when about to do an oplock break. ****************************************************************************/ void file_chain_save(void) @@ -517,7 +521,7 @@ void file_chain_save(void) } /**************************************************************************** -Restore the chained fsp - done after an oplock break. + Restore the chained fsp - done after an oplock break. ****************************************************************************/ void file_chain_restore(void) @@ -525,6 +529,10 @@ void file_chain_restore(void) chain_fsp = oplock_save_chain_fsp; } +/**************************************************************************** + Duplicate the file handle part for a DOS or FCB open. +****************************************************************************/ + files_struct *dup_file_fsp(files_struct *fsp, uint32 access_mask, uint32 share_access, -- cgit From 93954d6390370331731bda5fcf251dc0a796c744 Mon Sep 17 00:00:00 2001 From: James Peach <jpeach@samba.org> Date: Sat, 3 Sep 2005 07:19:28 +0000 Subject: r9985: Move the all the strict sync logic into file_sync(). (This used to be commit cc680bbe22b8bfc5a1900f11c2cbaeca3a9f9922) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index c90c2b627c..65986e9612 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -427,7 +427,7 @@ void file_sync_all(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next=fsp->next; if ((conn == fsp->conn) && (fsp->fh->fd != -1)) { - sync_file(conn,fsp); + sync_file(conn, fsp, True /* write through */); } } } -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter <jerry@samba.org> Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/smbd/files.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 65986e9612..181e17b11f 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -65,7 +65,7 @@ files_struct *file_new(connection_struct *conn) { int i; static int first_file; - files_struct *fsp, *next; + files_struct *fsp; /* we want to give out file handles differently on each new connection because of a common bug in MS clients where they try to @@ -76,32 +76,21 @@ files_struct *file_new(connection_struct *conn) first_file = (sys_getpid() ^ (int)time(NULL)) % real_max_open_files; } + /* TODO: Port the id-tree implementation from Samba4 */ + i = bitmap_find(file_bmap, first_file); if (i == -1) { - /* - * Before we give up, go through the open files - * and see if there are any files opened with a - * batch oplock. If so break the oplock and then - * re-use that entry (if it becomes closed). - * This may help as NT/95 clients tend to keep - * files batch oplocked for quite a long time - * after they have finished with them. - */ - for (fsp=Files;fsp;fsp=next) { - next=fsp->next; - if (attempt_close_oplocked_file(fsp)) { - return file_new(conn); - } - } - DEBUG(0,("ERROR! Out of file structures\n")); - set_saved_error_triple(ERRSRV, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES); + /* TODO: We have to unconditionally return a DOS error here, + * W2k3 even returns ERRDOS/ERRnofids for ntcreate&x with + * NTSTATUS negotiated */ + set_saved_ntstatus(NT_STATUS_TOO_MANY_OPENED_FILES); return NULL; } fsp = SMB_MALLOC_P(files_struct); if (!fsp) { - set_saved_error_triple(ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY); + set_saved_ntstatus(NT_STATUS_NO_MEMORY); return NULL; } @@ -110,7 +99,7 @@ files_struct *file_new(connection_struct *conn) fsp->fh = SMB_MALLOC_P(struct fd_handle); if (!fsp->fh) { SAFE_FREE(fsp); - set_saved_error_triple(ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY); + set_saved_ntstatus(NT_STATUS_NO_MEMORY); return NULL; } @@ -293,7 +282,9 @@ files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_i DLIST_PROMOTE(Files, fsp); } /* Paranoia check. */ - if (fsp->fh->fd == -1 && fsp->oplock_type != NO_OPLOCK) { + if ((fsp->fh->fd == -1) && + (fsp->oplock_type != NO_OPLOCK) && + (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK)) { DEBUG(0,("file_find_dif: file %s dev = %x, inode = %.0f, file_id = %u \ oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, (unsigned int)fsp->file_id, -- cgit From d14af63e6ab600eb3ac705f2f425c860e927553a Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Thu, 2 Feb 2006 20:44:50 +0000 Subject: r13293: Rather a big patch I'm afraid, but this should fix bug #3347 by saving the UNIX token used to set a delete on close flag, and using it when doing the delete. libsmbsharemodes.so still needs updating to cope with this change. Samba4 torture tests to follow. Jeremy. (This used to be commit 23f16cbc2e8cde97c486831e26bcafd4ab4a9654) --- source3/smbd/files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 181e17b11f..5a545c236e 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -148,7 +148,7 @@ void file_close_conn(connection_struct *conn) for (fsp=Files;fsp;fsp=next) { next = fsp->next; if (fsp->conn == conn) { - close_file(fsp,False); + close_file(fsp,SHUTDOWN_CLOSE); } } } @@ -164,7 +164,7 @@ void file_close_pid(uint16 smbpid) for (fsp=Files;fsp;fsp=next) { next = fsp->next; if (fsp->file_pid == smbpid) { - close_file(fsp,False); + close_file(fsp,SHUTDOWN_CLOSE); } } } @@ -222,7 +222,7 @@ void file_close_user(int vuid) for (fsp=Files;fsp;fsp=next) { next=fsp->next; if (fsp->vuid == vuid) { - close_file(fsp,False); + close_file(fsp,SHUTDOWN_CLOSE); } } } -- cgit From f04d5530cc9ec849edc39c86dbe3946f054d8178 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Wed, 15 Mar 2006 22:52:59 +0000 Subject: r14460: SMBexit closes by pid and vuid. Tested with smbtorture. Jeremy. (This used to be commit 71e81580421225d5b35a25d46a7b6064a826685c) --- source3/smbd/files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 5a545c236e..ba4baa93b1 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -154,16 +154,16 @@ void file_close_conn(connection_struct *conn) } /**************************************************************************** - Close all open files for a pid. + Close all open files for a pid and a vuid. ****************************************************************************/ -void file_close_pid(uint16 smbpid) +void file_close_pid(uint16 smbpid, int vuid) { files_struct *fsp, *next; for (fsp=Files;fsp;fsp=next) { next = fsp->next; - if (fsp->file_pid == smbpid) { + if ((fsp->file_pid == smbpid) && (fsp->vuid == vuid)) { close_file(fsp,SHUTDOWN_CLOSE); } } -- cgit From cc9ea93456e594432e203e6d2d2f4dbcaac9a3dd Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Wed, 17 May 2006 23:15:53 +0000 Subject: r15668: DOS or FCB opens share one share mode entry from different fsp pointers. Ensure we cope with this to pass Samba4 DENY tests (we used to pass these, there must have been a regression with newer code). We now pass them. Jeremy (This used to be commit fd6fa1d4eaf61783df74ee2da50d331477f06998) --- source3/smbd/files.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index ba4baa93b1..53207e876e 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -109,7 +109,7 @@ files_struct *file_new(connection_struct *conn) fsp->fh->fd = -1; fsp->conn = conn; - fsp->file_id = get_gen_count(); + fsp->fh->file_id = get_gen_count(); GetTimeOfDay(&fsp->open_time); first_file = (i+1) % real_max_open_files; @@ -238,7 +238,7 @@ void file_dump_open_table(void) for (fsp=Files;fsp;fsp=fsp->next,count++) { DEBUG(10,("Files[%d], fnum = %d, name %s, fd = %d, fileid = %lu, dev = %x, inode = %.0f\n", - count, fsp->fnum, fsp->fsp_name, fsp->fh->fd, (unsigned long)fsp->file_id, + count, fsp->fnum, fsp->fsp_name, fsp->fh->fd, (unsigned long)fsp->fh->file_id, (unsigned int)fsp->dev, (double)fsp->inode )); } } @@ -277,7 +277,7 @@ files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_i /* We can have a fsp->fh->fd == -1 here as it could be a stat open. */ if (fsp->dev == dev && fsp->inode == inode && - fsp->file_id == file_id ) { + fsp->fh->file_id == file_id ) { if (count > 10) { DLIST_PROMOTE(Files, fsp); } @@ -287,7 +287,7 @@ files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_i (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK)) { DEBUG(0,("file_find_dif: file %s dev = %x, inode = %.0f, file_id = %u \ oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, (unsigned int)fsp->dev, - (double)fsp->inode, (unsigned int)fsp->file_id, + (double)fsp->inode, (unsigned int)fsp->fh->file_id, (unsigned int)fsp->oplock_type )); smb_panic("file_find_dif\n"); } -- cgit From e2a90398eca525351022b47eb1e4b864ee9e63ea Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Mon, 22 May 2006 18:52:54 +0000 Subject: r15817: Remove some unused code (This used to be commit 72f103708d17aa86e09fa7a02699f969f7ee9190) --- source3/smbd/files.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 53207e876e..e020d8e13a 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -32,8 +32,6 @@ static files_struct *Files; /* a fsp to use when chaining */ static files_struct *chain_fsp = NULL; -/* a fsp to use to save when breaking an oplock. */ -static files_struct *oplock_save_chain_fsp = NULL; static int files_used; @@ -502,24 +500,6 @@ void file_chain_reset(void) chain_fsp = NULL; } -/**************************************************************************** - Save the chained fsp - done when about to do an oplock break. -****************************************************************************/ - -void file_chain_save(void) -{ - oplock_save_chain_fsp = chain_fsp; -} - -/**************************************************************************** - Restore the chained fsp - done after an oplock break. -****************************************************************************/ - -void file_chain_restore(void) -{ - chain_fsp = oplock_save_chain_fsp; -} - /**************************************************************************** Duplicate the file handle part for a DOS or FCB open. ****************************************************************************/ -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/smbd/files.c | 70 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index e020d8e13a..7069818dee 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -59,7 +59,7 @@ static unsigned long get_gen_count(void) Find first available file slot. ****************************************************************************/ -files_struct *file_new(connection_struct *conn) +NTSTATUS file_new(connection_struct *conn, files_struct **result) { int i; static int first_file; @@ -82,14 +82,12 @@ files_struct *file_new(connection_struct *conn) /* TODO: We have to unconditionally return a DOS error here, * W2k3 even returns ERRDOS/ERRnofids for ntcreate&x with * NTSTATUS negotiated */ - set_saved_ntstatus(NT_STATUS_TOO_MANY_OPENED_FILES); - return NULL; + return NT_STATUS_TOO_MANY_OPENED_FILES; } fsp = SMB_MALLOC_P(files_struct); if (!fsp) { - set_saved_ntstatus(NT_STATUS_NO_MEMORY); - return NULL; + return NT_STATUS_NO_MEMORY; } ZERO_STRUCTP(fsp); @@ -97,8 +95,7 @@ files_struct *file_new(connection_struct *conn) fsp->fh = SMB_MALLOC_P(struct fd_handle); if (!fsp->fh) { SAFE_FREE(fsp); - set_saved_ntstatus(NT_STATUS_NO_MEMORY); - return NULL; + return NT_STATUS_NO_MEMORY; } ZERO_STRUCTP(fsp->fh); @@ -131,8 +128,9 @@ files_struct *file_new(connection_struct *conn) if (fsp_fi_cache.fsp == NULL) { ZERO_STRUCT(fsp_fi_cache); } - - return fsp; + + *result = fsp; + return NT_STATUS_OK; } /**************************************************************************** @@ -464,24 +462,16 @@ void file_free(files_struct *fsp) } /**************************************************************************** - Get a fsp from a packet given the offset of a 16 bit fnum. + Get an fsp from a 16 bit fnum. ****************************************************************************/ -files_struct *file_fsp(char *buf, int where) +files_struct *file_fnum(uint16 fnum) { - int fnum, count=0; files_struct *fsp; - - if (chain_fsp) - return chain_fsp; - - if (!buf) - return NULL; - fnum = SVAL(buf, where); + int count=0; for (fsp=Files;fsp;fsp=fsp->next, count++) { if (fsp->fnum == fnum) { - chain_fsp = fsp; if (count > 10) { DLIST_PROMOTE(Files, fsp); } @@ -491,6 +481,29 @@ files_struct *file_fsp(char *buf, int where) return NULL; } +/**************************************************************************** + Get an fsp from a packet given the offset of a 16 bit fnum. +****************************************************************************/ + +files_struct *file_fsp(char *buf, int where) +{ + files_struct *fsp; + + if (chain_fsp) { + return chain_fsp; + } + + if (!buf) { + return NULL; + } + + fsp = file_fnum(SVAL(buf, where)); + if (fsp) { + chain_fsp = fsp; + } + return fsp; +} + /**************************************************************************** Reset the chained fsp - done at the start of a packet reply. ****************************************************************************/ @@ -504,15 +517,19 @@ void file_chain_reset(void) Duplicate the file handle part for a DOS or FCB open. ****************************************************************************/ -files_struct *dup_file_fsp(files_struct *fsp, +NTSTATUS dup_file_fsp(files_struct *fsp, uint32 access_mask, uint32 share_access, - uint32 create_options) + uint32 create_options, + files_struct **result) { - files_struct *dup_fsp = file_new(fsp->conn); + NTSTATUS status; + files_struct *dup_fsp; - if (!dup_fsp) { - return NULL; + status = file_new(fsp->conn, &dup_fsp); + + if (!NT_STATUS_IS_OK(status)) { + return status; } SAFE_FREE(dup_fsp->fh); @@ -547,5 +564,6 @@ files_struct *dup_file_fsp(files_struct *fsp, dup_fsp->aio_write_behind = fsp->aio_write_behind; string_set(&dup_fsp->fsp_name,fsp->fsp_name); - return dup_fsp; + *result = dup_fsp; + return NT_STATUS_OK; } -- cgit From 98c082489bec0a0ce4db1daf4390e785381f229a Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Thu, 28 Dec 2006 21:50:31 +0000 Subject: r20394: This is a *VERY* early start of my work on notify. Checking in because Jeremy was bugging me. Potentially this becomes quite intrusive, I'm not sure if I should open a temporary branch for this. Jeremy, Jerry, do you think 3_0 is the right place for this? Volker (This used to be commit bcf5c751cbe203c00814642e26440cf88f300bce) --- source3/smbd/files.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 7069818dee..8df7a29a65 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -100,6 +100,12 @@ NTSTATUS file_new(connection_struct *conn, files_struct **result) ZERO_STRUCTP(fsp->fh); + if (!(fsp->notify = TALLOC_ZERO_P(NULL, struct notify_changes))) { + SAFE_FREE(fsp->fh); + SAFE_FREE(fsp); + return NT_STATUS_NO_MEMORY; + } + fsp->fh->ref_count = 1; fsp->fh->fd = -1; @@ -361,6 +367,35 @@ files_struct *file_find_di_next(files_struct *start_fsp) return NULL; } +/**************************************************************************** + Find the directory fsp given a device and inode with the lowest + file_id. First use is for notify actions. +****************************************************************************/ + +files_struct *file_find_dir_lowest_id(SMB_DEV_T dev, SMB_INO_T inode) +{ + files_struct *fsp; + files_struct *min_fsp = NULL; + + for (fsp = Files; fsp; fsp = fsp->next) { + if (!fsp->is_directory + || fsp->dev != dev || fsp->inode != inode) { + continue; + } + + if (min_fsp == NULL) { + min_fsp = fsp; + continue; + } + + if (fsp->fh->file_id < min_fsp->fh->file_id) { + min_fsp = fsp; + } + } + + return min_fsp; +} + /**************************************************************************** Find a fsp that is open for printing. ****************************************************************************/ @@ -439,6 +474,8 @@ void file_free(files_struct *fsp) fsp->fh->ref_count--; } + TALLOC_FREE(fsp->notify); + bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; -- cgit From 200bd10b32107b4ce8fc72cc2abbf5a247708ba6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Sun, 31 Dec 2006 17:52:24 +0000 Subject: r20442: Slight rewrite of the change notify infrastructure. This now survives the first of the raw-notify subtests, the one-level test_notify_dir without any flags around yet. The tricky part was getting the data structures right, I hope the next tests don't let that fall over. fsp->notify is now by default NULL, meaning that nobody has issued a changenotify call. This means nobody is interested in changes for this directory. If that has happened, notify_change_buf collects the changes if no current request is outstanding, and it collects the requests if no change has happened since the last request. Happy New Year, somewhere on this planet it's already 2007 :-) Volker P.S: Jeremy, there's a question for you in smbd/files.c line 367. (This used to be commit ce0ad24988075465addcac0b9afc872e909135af) --- source3/smbd/files.c | 57 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 8df7a29a65..982de4c55f 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -100,12 +100,6 @@ NTSTATUS file_new(connection_struct *conn, files_struct **result) ZERO_STRUCTP(fsp->fh); - if (!(fsp->notify = TALLOC_ZERO_P(NULL, struct notify_changes))) { - SAFE_FREE(fsp->fh); - SAFE_FREE(fsp); - return NT_STATUS_NO_MEMORY; - } - fsp->fh->ref_count = 1; fsp->fh->fd = -1; @@ -367,33 +361,48 @@ files_struct *file_find_di_next(files_struct *start_fsp) return NULL; } -/**************************************************************************** - Find the directory fsp given a device and inode with the lowest - file_id. First use is for notify actions. -****************************************************************************/ +/* + * Same as file_find_di_first/next, but also finds non-fd opens. + * + * Jeremy, do we really need the fsp->fh->fd != -1 ?? + */ -files_struct *file_find_dir_lowest_id(SMB_DEV_T dev, SMB_INO_T inode) +struct files_struct *fsp_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) { files_struct *fsp; - files_struct *min_fsp = NULL; - for (fsp = Files; fsp; fsp = fsp->next) { - if (!fsp->is_directory - || fsp->dev != dev || fsp->inode != inode) { - continue; - } + if (fsp_fi_cache.dev == dev && fsp_fi_cache.inode == inode) { + /* Positive or negative cache hit. */ + return fsp_fi_cache.fsp; + } - if (min_fsp == NULL) { - min_fsp = fsp; - continue; - } + fsp_fi_cache.dev = dev; + fsp_fi_cache.inode = inode; - if (fsp->fh->file_id < min_fsp->fh->file_id) { - min_fsp = fsp; + for (fsp=Files;fsp;fsp=fsp->next) { + if ((fsp->dev == dev) && (fsp->inode == inode)) { + /* Setup positive cache. */ + fsp_fi_cache.fsp = fsp; + return fsp; } } - return min_fsp; + /* Setup negative cache. */ + fsp_fi_cache.fsp = NULL; + return NULL; +} + +struct files_struct *fsp_find_di_next(files_struct *start_fsp) +{ + files_struct *fsp; + + for (fsp = start_fsp->next;fsp;fsp=fsp->next) { + if ( (fsp->dev == start_fsp->dev) + && (fsp->inode == start_fsp->inode) ) + return fsp; + } + + return NULL; } /**************************************************************************** -- cgit From 46fdae1b6b1b8e3285447193cb10e5a2a444d431 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Tue, 9 Jan 2007 16:12:54 +0000 Subject: r20634: A *LOT* more work is necessary before touching notify remotely starts to make sense. Until then, remove it from the tree to keep the diff between 3_0_24 and 3_0 small. Volker (This used to be commit f146a85e74c84e78a11e616a1cbeaeef4693a0e0) --- source3/smbd/files.c | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 982de4c55f..7069818dee 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -361,50 +361,6 @@ files_struct *file_find_di_next(files_struct *start_fsp) return NULL; } -/* - * Same as file_find_di_first/next, but also finds non-fd opens. - * - * Jeremy, do we really need the fsp->fh->fd != -1 ?? - */ - -struct files_struct *fsp_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) -{ - files_struct *fsp; - - if (fsp_fi_cache.dev == dev && fsp_fi_cache.inode == inode) { - /* Positive or negative cache hit. */ - return fsp_fi_cache.fsp; - } - - fsp_fi_cache.dev = dev; - fsp_fi_cache.inode = inode; - - for (fsp=Files;fsp;fsp=fsp->next) { - if ((fsp->dev == dev) && (fsp->inode == inode)) { - /* Setup positive cache. */ - fsp_fi_cache.fsp = fsp; - return fsp; - } - } - - /* Setup negative cache. */ - fsp_fi_cache.fsp = NULL; - return NULL; -} - -struct files_struct *fsp_find_di_next(files_struct *start_fsp) -{ - files_struct *fsp; - - for (fsp = start_fsp->next;fsp;fsp=fsp->next) { - if ( (fsp->dev == start_fsp->dev) - && (fsp->inode == start_fsp->inode) ) - return fsp; - } - - return NULL; -} - /**************************************************************************** Find a fsp that is open for printing. ****************************************************************************/ @@ -483,8 +439,6 @@ void file_free(files_struct *fsp) fsp->fh->ref_count--; } - TALLOC_FREE(fsp->notify); - bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; -- cgit From 940192ddcc9d23e3bec806b4419d5845eeac0fd0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Wed, 17 Jan 2007 16:23:45 +0000 Subject: r20854: Ok, now I think we're at a point where looking at notify starts to make sense again :-) Volker (This used to be commit 5533cdeec1b0cdee39b1d89e2320587dc9281ee6) --- source3/smbd/files.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 7069818dee..982de4c55f 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -361,6 +361,50 @@ files_struct *file_find_di_next(files_struct *start_fsp) return NULL; } +/* + * Same as file_find_di_first/next, but also finds non-fd opens. + * + * Jeremy, do we really need the fsp->fh->fd != -1 ?? + */ + +struct files_struct *fsp_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) +{ + files_struct *fsp; + + if (fsp_fi_cache.dev == dev && fsp_fi_cache.inode == inode) { + /* Positive or negative cache hit. */ + return fsp_fi_cache.fsp; + } + + fsp_fi_cache.dev = dev; + fsp_fi_cache.inode = inode; + + for (fsp=Files;fsp;fsp=fsp->next) { + if ((fsp->dev == dev) && (fsp->inode == inode)) { + /* Setup positive cache. */ + fsp_fi_cache.fsp = fsp; + return fsp; + } + } + + /* Setup negative cache. */ + fsp_fi_cache.fsp = NULL; + return NULL; +} + +struct files_struct *fsp_find_di_next(files_struct *start_fsp) +{ + files_struct *fsp; + + for (fsp = start_fsp->next;fsp;fsp=fsp->next) { + if ( (fsp->dev == start_fsp->dev) + && (fsp->inode == start_fsp->inode) ) + return fsp; + } + + return NULL; +} + /**************************************************************************** Find a fsp that is open for printing. ****************************************************************************/ @@ -439,6 +483,8 @@ void file_free(files_struct *fsp) fsp->fh->ref_count--; } + TALLOC_FREE(fsp->notify); + bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; -- cgit From 2852ecc67ebded7758a07d8fb72eef53bfa1c63a Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Wed, 31 Jan 2007 14:42:56 +0000 Subject: r21092: Ok, that's the one that activates the Samba4 notify backend. Now to clean up / fix lots of stuff. Volker (This used to be commit 9e7443fa1417c01be903b15073825dc4def78d99) --- source3/smbd/files.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 982de4c55f..fc1700de11 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -483,7 +483,10 @@ void file_free(files_struct *fsp) fsp->fh->ref_count--; } - TALLOC_FREE(fsp->notify); + if (fsp->notify) { + notify_remove(fsp->conn->notify_ctx, fsp); + TALLOC_FREE(fsp->notify); + } bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; -- cgit From d9a29aade0f01df1fa00ccdb8691b02b39bc1d14 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Sun, 11 Feb 2007 14:39:21 +0000 Subject: r21279: Get rid of 'aio write behind', this is broken. It should probably better be integrated with our write cache. Volker (This used to be commit 58bfd168b046a97a895aaa3384fd7af8d077a1d5) --- source3/smbd/files.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index fc1700de11..fa162711ae 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -610,7 +610,6 @@ NTSTATUS dup_file_fsp(files_struct *fsp, dup_fsp->modified = fsp->modified; dup_fsp->is_directory = fsp->is_directory; dup_fsp->is_stat = fsp->is_stat; - dup_fsp->aio_write_behind = fsp->aio_write_behind; string_set(&dup_fsp->fsp_name,fsp->fsp_name); *result = dup_fsp; -- cgit From a2f2653d9ae4e535384e925112745ed788e2422e Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Tue, 13 Feb 2007 15:57:54 +0000 Subject: r21319: Remove functions not needed anymore (This used to be commit 0c8a364aec68bc7338d034b6f8223ec4085c9e07) --- source3/smbd/files.c | 44 -------------------------------------------- 1 file changed, 44 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index fa162711ae..0706548334 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -361,50 +361,6 @@ files_struct *file_find_di_next(files_struct *start_fsp) return NULL; } -/* - * Same as file_find_di_first/next, but also finds non-fd opens. - * - * Jeremy, do we really need the fsp->fh->fd != -1 ?? - */ - -struct files_struct *fsp_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) -{ - files_struct *fsp; - - if (fsp_fi_cache.dev == dev && fsp_fi_cache.inode == inode) { - /* Positive or negative cache hit. */ - return fsp_fi_cache.fsp; - } - - fsp_fi_cache.dev = dev; - fsp_fi_cache.inode = inode; - - for (fsp=Files;fsp;fsp=fsp->next) { - if ((fsp->dev == dev) && (fsp->inode == inode)) { - /* Setup positive cache. */ - fsp_fi_cache.fsp = fsp; - return fsp; - } - } - - /* Setup negative cache. */ - fsp_fi_cache.fsp = NULL; - return NULL; -} - -struct files_struct *fsp_find_di_next(files_struct *start_fsp) -{ - files_struct *fsp; - - for (fsp = start_fsp->next;fsp;fsp=fsp->next) { - if ( (fsp->dev == start_fsp->dev) - && (fsp->inode == start_fsp->inode) ) - return fsp; - } - - return NULL; -} - /**************************************************************************** Find a fsp that is open for printing. ****************************************************************************/ -- cgit From 4952fe368a40b239140b3035db6075427d237bb9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Mon, 5 Mar 2007 23:40:03 +0000 Subject: r21714: Change the VFS interface to use struct timespec for utimes - change the call to ntimes. This preserves nsec timestamps we get from stat (if the system supports it) and only maps back down to usec or sec resolution on time set. Looks bigger than it is as I had to move lots of internal code from using time_t and struct utimebuf to struct timespec. Jeremy. (This used to be commit 8f3d530c5a748ea90f42ed8fbe68ae92178d4875) --- source3/smbd/files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 0706548334..062bebd58e 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -383,11 +383,11 @@ files_struct *file_find_print(void) Record the owner of that modtime. ****************************************************************************/ -void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod) +void fsp_set_pending_modtime(files_struct *tfsp, const struct timespec mod) { files_struct *fsp; - if (null_mtime(pmod)) { + if (null_timespec(mod)) { return; } @@ -395,7 +395,7 @@ void fsp_set_pending_modtime(files_struct *tfsp, time_t pmod) if ( fsp->fh->fd != -1 && fsp->dev == tfsp->dev && fsp->inode == tfsp->inode ) { - fsp->pending_modtime = pmod; + fsp->pending_modtime = mod; fsp->pending_modtime_owner = False; } } -- cgit From e8156439f24137b5418baad20a7f00f6949cfe29 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Tue, 29 May 2007 09:30:34 +0000 Subject: r23183: Check in a change made by Tridge: This replaces the internal explicit dev/ino file id representation by a "struct file_id". This is necessary as cluster file systems and NFS don't necessarily assign the same device number to the shared file system. With this structure in place we can now easily add different schemes to map a file to a unique 64-bit device node. Jeremy, you might note that I did not change the external interface of smb_share_modes.c. Volker (This used to be commit 9b10dbbd5de8813fc15ebbb6be9b18010ffe8139) --- source3/smbd/files.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 062bebd58e..5ee0696ef9 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -38,8 +38,7 @@ static int files_used; /* A singleton cache to speed up searching by dev/inode. */ static struct fsp_singleton_cache { files_struct *fsp; - SMB_DEV_T dev; - SMB_INO_T inode; + struct file_id id; } fsp_fi_cache; /**************************************************************************** @@ -104,7 +103,7 @@ NTSTATUS file_new(connection_struct *conn, files_struct **result) fsp->fh->fd = -1; fsp->conn = conn; - fsp->fh->file_id = get_gen_count(); + fsp->fh->gen_id = get_gen_count(); GetTimeOfDay(&fsp->open_time); first_file = (i+1) % real_max_open_files; @@ -233,9 +232,9 @@ void file_dump_open_table(void) files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next,count++) { - DEBUG(10,("Files[%d], fnum = %d, name %s, fd = %d, fileid = %lu, dev = %x, inode = %.0f\n", - count, fsp->fnum, fsp->fsp_name, fsp->fh->fd, (unsigned long)fsp->fh->file_id, - (unsigned int)fsp->dev, (double)fsp->inode )); + DEBUG(10,("Files[%d], fnum = %d, name %s, fd = %d, gen = %lu, fileid=%s\n", + count, fsp->fnum, fsp->fsp_name, fsp->fh->fd, (unsigned long)fsp->fh->gen_id, + file_id_static_string(&fsp->file_id))); } } @@ -264,16 +263,15 @@ files_struct *file_find_fd(int fd) Find a fsp given a device, inode and file_id. ****************************************************************************/ -files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id) +files_struct *file_find_dif(struct file_id id, unsigned long gen_id) { int count=0; files_struct *fsp; for (fsp=Files;fsp;fsp=fsp->next,count++) { /* We can have a fsp->fh->fd == -1 here as it could be a stat open. */ - if (fsp->dev == dev && - fsp->inode == inode && - fsp->fh->file_id == file_id ) { + if (file_id_equal(&fsp->file_id, &id) && + fsp->fh->gen_id == gen_id ) { if (count > 10) { DLIST_PROMOTE(Files, fsp); } @@ -281,10 +279,11 @@ files_struct *file_find_dif(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_i if ((fsp->fh->fd == -1) && (fsp->oplock_type != NO_OPLOCK) && (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK)) { - DEBUG(0,("file_find_dif: file %s dev = %x, inode = %.0f, file_id = %u \ -oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, (unsigned int)fsp->dev, - (double)fsp->inode, (unsigned int)fsp->fh->file_id, - (unsigned int)fsp->oplock_type )); + DEBUG(0,("file_find_dif: file %s file_id = %s, gen = %u \ +oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, + file_id_static_string(&fsp->file_id), + (unsigned int)fsp->fh->gen_id, + (unsigned int)fsp->oplock_type )); smb_panic("file_find_dif\n"); } return fsp; @@ -316,22 +315,20 @@ files_struct *file_find_fsp(files_struct *orig_fsp) calls. ****************************************************************************/ -files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode) +files_struct *file_find_di_first(struct file_id id) { files_struct *fsp; - if (fsp_fi_cache.dev == dev && fsp_fi_cache.inode == inode) { + if (file_id_equal(&fsp_fi_cache.id, &id)) { /* Positive or negative cache hit. */ return fsp_fi_cache.fsp; } - fsp_fi_cache.dev = dev; - fsp_fi_cache.inode = inode; + fsp_fi_cache.id = id; for (fsp=Files;fsp;fsp=fsp->next) { if ( fsp->fh->fd != -1 && - fsp->dev == dev && - fsp->inode == inode ) { + file_id_equal(&fsp->file_id, &id)) { /* Setup positive cache. */ fsp_fi_cache.fsp = fsp; return fsp; @@ -353,9 +350,9 @@ files_struct *file_find_di_next(files_struct *start_fsp) for (fsp = start_fsp->next;fsp;fsp=fsp->next) { if ( fsp->fh->fd != -1 && - fsp->dev == start_fsp->dev && - fsp->inode == start_fsp->inode ) + file_id_equal(&fsp->file_id, &start_fsp->file_id)) { return fsp; + } } return NULL; @@ -392,9 +389,7 @@ void fsp_set_pending_modtime(files_struct *tfsp, const struct timespec mod) } for (fsp = Files;fsp;fsp=fsp->next) { - if ( fsp->fh->fd != -1 && - fsp->dev == tfsp->dev && - fsp->inode == tfsp->inode ) { + if ( fsp->fh->fd != -1 && file_id_equal(&fsp->file_id, &tfsp->file_id)) { fsp->pending_modtime = mod; fsp->pending_modtime_owner = False; } @@ -542,8 +537,7 @@ NTSTATUS dup_file_fsp(files_struct *fsp, dup_fsp->fh = fsp->fh; dup_fsp->fh->ref_count++; - dup_fsp->dev = fsp->dev; - dup_fsp->inode = fsp->inode; + dup_fsp->file_id = fsp->file_id; dup_fsp->initial_allocation_size = fsp->initial_allocation_size; dup_fsp->mode = fsp->mode; dup_fsp->file_pid = fsp->file_pid; -- cgit From b1ce226af8b61ad7e3c37860a59c6715012e738b Mon Sep 17 00:00:00 2001 From: James Peach <jpeach@samba.org> Date: Fri, 15 Jun 2007 21:58:49 +0000 Subject: r23510: Tidy calls to smb_panic by removing trailing newlines. Print the failed expression in SMB_ASSERT. (This used to be commit 171dc060e2a576d724eed1ca65636bdafffd7713) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 5ee0696ef9..590916011b 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -284,7 +284,7 @@ oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, file_id_static_string(&fsp->file_id), (unsigned int)fsp->fh->gen_id, (unsigned int)fsp->oplock_type )); - smb_panic("file_find_dif\n"); + smb_panic("file_find_dif"); } return fsp; } -- cgit From 08a9de8927bbca982be4e566e56748045defc1c7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 22 Jun 2007 17:19:08 +0000 Subject: r23589: Ensure we will always release any timeout handler on fsp close or removal of oplock. Mulitple removals are safe. Jeremy. (This used to be commit 6de0970704b3eff2b71e6bf499c6dda45d4d5e2d) --- source3/smbd/files.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 590916011b..9994b50d15 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -439,6 +439,9 @@ void file_free(files_struct *fsp) TALLOC_FREE(fsp->notify); } + /* Ensure this event will never fire. */ + TALLOC_FREE(fsp->oplock_timeout); + bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 9994b50d15..4ed3661920 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell <tridge@samba.org> Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/smbd/files.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 4ed3661920..02e4cd9663 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "includes.h" -- cgit From 041204d1a4ec9b19287ca92fa5b291a8eb5ff10b Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Mon, 23 Jul 2007 08:20:44 +0000 Subject: r23996: One more const (This used to be commit a54fa551a4b9ffe3f29b339a54e563cdfe924959) --- source3/smbd/files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 02e4cd9663..07dec80a47 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -487,7 +487,7 @@ files_struct *file_fnum(uint16 fnum) Get an fsp from a packet given the offset of a 16 bit fnum. ****************************************************************************/ -files_struct *file_fsp(char *buf, int where) +files_struct *file_fsp(const char *buf, int where) { files_struct *fsp; -- cgit From a2d6aa829faa65df14ee566e455e807693cc2bd9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Tue, 31 Jul 2007 12:05:40 +0000 Subject: r24102: Pass the fid instead of inbuf and an offset to file_fsp. This removes the buf==NULL condition in file_fsp(), but wherever it is called we do have a buffer anyway. Volker (This used to be commit d70a1f82fed64fa332f16407bea7c6671f48c59a) --- source3/smbd/files.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 07dec80a47..9d27c69a6b 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -487,7 +487,7 @@ files_struct *file_fnum(uint16 fnum) Get an fsp from a packet given the offset of a 16 bit fnum. ****************************************************************************/ -files_struct *file_fsp(const char *buf, int where) +files_struct *file_fsp(uint16 fid) { files_struct *fsp; @@ -495,11 +495,7 @@ files_struct *file_fsp(const char *buf, int where) return chain_fsp; } - if (!buf) { - return NULL; - } - - fsp = file_fnum(SVAL(buf, where)); + fsp = file_fnum(fid); if (fsp) { chain_fsp = fsp; } -- cgit From 4ee8b2937d48308c6089fb539fdbd8625dfde360 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vlendec@samba.org> Date: Mon, 10 Sep 2007 10:56:07 +0000 Subject: r25055: Add file_id_string_tos This removes file_id_string_static and file_id_string_static2 (This used to be commit 638c848c9afe374feb30e34c494f89b2a6c64f7b) --- source3/smbd/files.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 9d27c69a6b..f3740da328 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -233,7 +233,7 @@ void file_dump_open_table(void) for (fsp=Files;fsp;fsp=fsp->next,count++) { DEBUG(10,("Files[%d], fnum = %d, name %s, fd = %d, gen = %lu, fileid=%s\n", count, fsp->fnum, fsp->fsp_name, fsp->fh->fd, (unsigned long)fsp->fh->gen_id, - file_id_static_string(&fsp->file_id))); + file_id_string_tos(&fsp->file_id))); } } @@ -280,7 +280,7 @@ files_struct *file_find_dif(struct file_id id, unsigned long gen_id) (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK)) { DEBUG(0,("file_find_dif: file %s file_id = %s, gen = %u \ oplock_type = %u is a stat open with oplock type !\n", fsp->fsp_name, - file_id_static_string(&fsp->file_id), + file_id_string_tos(&fsp->file_id), (unsigned int)fsp->fh->gen_id, (unsigned int)fsp->oplock_type )); smb_panic("file_find_dif"); -- cgit From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" <jerry@samba.org> Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/smbd/files.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index f3740da328..179963dae9 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -558,6 +558,7 @@ NTSTATUS dup_file_fsp(files_struct *fsp, dup_fsp->modified = fsp->modified; dup_fsp->is_directory = fsp->is_directory; dup_fsp->is_stat = fsp->is_stat; + dup_fsp->aio_write_behind = fsp->aio_write_behind; string_set(&dup_fsp->fsp_name,fsp->fsp_name); *result = dup_fsp; -- cgit From d2a9630a8b239118e7fc4b9dcedd860e6b7574f1 Mon Sep 17 00:00:00 2001 From: James Peach <jpeach@apple.com> Date: Mon, 15 Oct 2007 13:59:37 -0700 Subject: Release per-fsp data on file closure. (This used to be commit 9fead46b54519b3df78a869dbc99207046587d6a) --- source3/smbd/files.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 179963dae9..95f01b88ce 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -460,6 +460,11 @@ void file_free(files_struct *fsp) ZERO_STRUCT(fsp_fi_cache); } + /* Drop all remaining extensions. */ + while (fsp->vfs_extension) { + vfs_remove_fsp_extension(fsp->vfs_extension->owner, fsp); + } + SAFE_FREE(fsp); } -- cgit From d03453864ab1bc5fd3b4a3abaf96176a006c102b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher <metze@samba.org> Date: Wed, 12 Mar 2008 15:39:38 +0100 Subject: smbd: implement the strange write time update logic We now never call file_ntimes() directly, every update is done via smb_set_file_time(). This let samba3 pass the BASE-DELAYWRITE test. The write time is only updated 2 seconds after the first write() on any open handle to the current time (not the time of the first write). Each handle which had write requests updates the write time to the current time on close(). If the write time is set explicit via setfileinfo or setpathinfo the write time is visible directly and a following close on the same handle doesn't update the write time. metze (This used to be commit 2eab212ea2e1bfd8fa716c2c89b2c042f7ba12ea) --- source3/smbd/files.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 95f01b88ce..d6e91c67be 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -374,29 +374,6 @@ files_struct *file_find_print(void) return NULL; } -/**************************************************************************** - Set a pending modtime across all files with a given dev/ino pair. - Record the owner of that modtime. -****************************************************************************/ - -void fsp_set_pending_modtime(files_struct *tfsp, const struct timespec mod) -{ - files_struct *fsp; - - if (null_timespec(mod)) { - return; - } - - for (fsp = Files;fsp;fsp=fsp->next) { - if ( fsp->fh->fd != -1 && file_id_equal(&fsp->file_id, &tfsp->file_id)) { - fsp->pending_modtime = mod; - fsp->pending_modtime_owner = False; - } - } - - tfsp->pending_modtime_owner = True; -} - /**************************************************************************** Sync open files on a connection. ****************************************************************************/ @@ -441,6 +418,9 @@ void file_free(files_struct *fsp) /* Ensure this event will never fire. */ TALLOC_FREE(fsp->oplock_timeout); + /* Ensure this event will never fire. */ + TALLOC_FREE(fsp->update_write_time_event); + bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET); files_used--; @@ -548,9 +528,6 @@ NTSTATUS dup_file_fsp(files_struct *fsp, dup_fsp->open_time = fsp->open_time; dup_fsp->access_mask = access_mask; dup_fsp->share_access = share_access; - dup_fsp->pending_modtime_owner = fsp->pending_modtime_owner; - dup_fsp->pending_modtime = fsp->pending_modtime; - dup_fsp->last_write_time = fsp->last_write_time; dup_fsp->oplock_type = fsp->oplock_type; dup_fsp->can_lock = fsp->can_lock; dup_fsp->can_read = (access_mask & (FILE_READ_DATA)) ? True : False; -- cgit From b430b382202858a6c52c1cacbb91910b2dd7e16c Mon Sep 17 00:00:00 2001 From: Jeremy Allison <jra@samba.org> Date: Fri, 2 May 2008 17:22:10 -0700 Subject: Remove the "stat_open()" function, flag, and all associated code. It was only being (correctly) used in the can_read/can_write checks for hide unreadable/unwritable and this is more properly done using the functions in smbd/file_access.c. Preparing to do NT access checks on all file access. Jeremy. (This used to be commit 6bfb06ad95963ae2acb67c4694a98282d3b29faa) --- source3/smbd/files.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/smbd/files.c') diff --git a/source3/smbd/files.c b/source3/smbd/files.c index d6e91c67be..17c473f028 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -539,7 +539,6 @@ NTSTATUS dup_file_fsp(files_struct *fsp, dup_fsp->print_file = fsp->print_file; dup_fsp->modified = fsp->modified; dup_fsp->is_directory = fsp->is_directory; - dup_fsp->is_stat = fsp->is_stat; dup_fsp->aio_write_behind = fsp->aio_write_behind; string_set(&dup_fsp->fsp_name,fsp->fsp_name); -- cgit