Move the posix pending close functionality down into the VFS layer.
authorMichael Adam <obnox@samba.org>
Fri, 11 Jan 2008 11:18:33 +0000 (12:18 +0100)
committerMichael Adam <obnox@samba.org>
Sun, 20 Apr 2008 22:21:23 +0000 (00:21 +0200)
This hides the pending close fds from the outside. Call order
of SMB_VFS_CLOSE is reversed. Originally, it was:

fd_close -> fd_close_posix -> SMB_VFS_CLOSE -> close

And now it is:

fd_close -> SMB_VFS_CLOSE -> fd_close_posix -> close

This is in preparation of removing the fd parameter
from the SMB_VFS_CLOSE function. But it is also the right
place for the pending close calls anyways.

Michael
(This used to be commit 3cf56b124a2886c6260455bba4bf77d08e9a4f77)

source3/locking/posix.c
source3/modules/vfs_default.c
source3/smbd/open.c

index 1b88c472b0ea9492d7342f30ef0154077f8fcfc7..f42d1ec6f8a513cf04c75ade19a2bb3bef5c7815 100644 (file)
@@ -620,7 +620,7 @@ NTSTATUS fd_close_posix(struct files_struct *fsp)
                 * which will lose all locks on all fd's open on this dev/inode,
                 * just close.
                 */
-               ret = SMB_VFS_CLOSE(fsp,fsp->fh->fd);
+               ret = close(fsp->fh->fd);
                fsp->fh->fd = -1;
                if (ret == -1) {
                        return map_nt_error_from_unix(errno);
@@ -651,7 +651,7 @@ NTSTATUS fd_close_posix(struct files_struct *fsp)
                DEBUG(10,("fd_close_posix: doing close on %u fd's.\n", (unsigned int)count ));
 
                for(i = 0; i < count; i++) {
-                       if (SMB_VFS_CLOSE(fsp,fd_array[i]) == -1) {
+                       if (close(fd_array[i]) == -1) {
                                saved_errno = errno;
                        }
                }
@@ -673,7 +673,7 @@ NTSTATUS fd_close_posix(struct files_struct *fsp)
         * Finally close the fd associated with this fsp.
         */
 
-       ret = SMB_VFS_CLOSE(fsp,fsp->fh->fd);
+       ret = close(fsp->fh->fd);
 
        if (ret == 0 && saved_errno != 0) {
                errno = saved_errno;
index 31ebb6352a179d5631c588aab69b9714e068d7f7..9887b309f95fd0a6b49764f50ff42b14e986cb80 100644 (file)
@@ -210,13 +210,13 @@ static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
 
 static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
 {
-       int result;
+       NTSTATUS result;
 
        START_PROFILE(syscall_close);
-
-       result = close(fd);
+       result = fd_close_posix(fsp);
        END_PROFILE(syscall_close);
-       return result;
+
+       return NT_STATUS_IS_OK(result) ? 0 : -1;
 }
 
 static ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, void *data, size_t n)
index f3ed234c87eb4c923d6c3c7b52f383ea01fc38f7..7a13b3ae381a989853299bbc4f2a9c0f3b08cb16 100644 (file)
@@ -72,13 +72,21 @@ static NTSTATUS fd_open(struct connection_struct *conn,
 
 NTSTATUS fd_close(files_struct *fsp)
 {
+       int ret;
+
        if (fsp->fh->fd == -1) {
                return NT_STATUS_OK; /* What we used to call a stat open. */
        }
        if (fsp->fh->ref_count > 1) {
                return NT_STATUS_OK; /* Shared handle. Only close last reference. */
        }
-       return fd_close_posix(fsp);
+
+       ret = SMB_VFS_CLOSE(fsp, fsp->fh->fd);
+       fsp->fh->fd = -1;
+       if (ret == -1) {
+               return map_nt_error_from_unix(errno);
+       }
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************