pvfs_open: pass O_NONBLOCK to open() so that we'll not block with kernel oplocks
[samba.git] / source4 / ntvfs / posix / pvfs_open.c
index 1ed517c7194d7668b1ea343b87a30a3d6e5be2fc..8a949daa87a9ac18a40e5290a11cbb244fdf417f 100644 (file)
@@ -299,10 +299,8 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs,
                }
 
                /* now really mark the file as open */
-               status = odb_open_file(lck, f->handle, name->full_name, name->stream_id,
-                                      share_access, access_mask, del_on_close, 
-                                      io->generic.in.open_disposition,
-                                      false, false, OPLOCK_NONE, NULL);
+               status = odb_open_file(lck, f->handle, name->full_name,
+                                      NULL, false, OPLOCK_NONE, NULL);
 
                if (!NT_STATUS_IS_OK(status)) {
                        talloc_free(lck);
@@ -361,10 +359,8 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs,
                        goto cleanup_delete;
                }
 
-               status = odb_open_file(lck, f->handle, name->full_name, name->stream_id,
-                                      share_access, access_mask, del_on_close, 
-                                      io->generic.in.open_disposition,
-                                      false, false, OPLOCK_NONE, NULL);
+               status = odb_open_file(lck, f->handle, name->full_name,
+                                      NULL, false, OPLOCK_NONE, NULL);
 
                if (!NT_STATUS_IS_OK(status)) {
                        goto cleanup_delete;
@@ -604,7 +600,7 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs,
        mode = pvfs_fileperms(pvfs, attrib);
 
        /* create the file */
-       fd = open(name->full_name, flags | O_CREAT | O_EXCL, mode);
+       fd = open(name->full_name, flags | O_CREAT | O_EXCL| O_NONBLOCK, mode);
        if (fd == -1) {
                return pvfs_map_errno(pvfs, errno);
        }
@@ -692,21 +688,6 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs,
                return status;
        }
 
-       status = odb_open_file(lck, f->handle, name->full_name, name->stream_id,
-                              share_access, access_mask, del_on_close, 
-                              io->generic.in.open_disposition,
-                              false, allow_level_II_oplock,
-                              oplock_level, &oplock_granted);
-       talloc_free(lck);
-       if (!NT_STATUS_IS_OK(status)) {
-               /* bad news, we must have hit a race - we don't delete the file
-                  here as the most likely scenario is that someone else created 
-                  the file at the same time */
-               close(fd);
-               return status;
-       }
-
-
        f->ntvfs             = h;
        f->pvfs              = pvfs;
        f->pending_list      = NULL;
@@ -729,6 +710,18 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs,
        f->handle->sticky_write_time = false;
        f->handle->open_completed    = false;
 
+       status = odb_open_file(lck, f->handle, name->full_name,
+                              &f->handle->fd, allow_level_II_oplock,
+                              oplock_level, &oplock_granted);
+       talloc_free(lck);
+       if (!NT_STATUS_IS_OK(status)) {
+               /* bad news, we must have hit a race - we don't delete the file
+                  here as the most likely scenario is that someone else created
+                  the file at the same time */
+               close(fd);
+               return status;
+       }
+
        DLIST_ADD(pvfs->files.list, f);
 
        /* setup a destructor to avoid file descriptor leaks on
@@ -1303,11 +1296,24 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs,
                return status;
        }
 
+       if (access_mask & (SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA)) {
+               flags |= O_RDWR;
+       } else {
+               flags |= O_RDONLY;
+       }
+
+       /* do the actual open */
+       fd = open(f->handle->name->full_name, flags | O_NONBLOCK);
+       if (fd == -1) {
+               talloc_free(lck);
+               return pvfs_map_errno(f->pvfs, errno);
+       }
+
+       f->handle->fd = fd;
+
        /* now really mark the file as open */
-       status = odb_open_file(lck, f->handle, name->full_name, name->stream_id,
-                              share_access, access_mask, del_on_close,
-                              io->generic.in.open_disposition,
-                              false, allow_level_II_oplock,
+       status = odb_open_file(lck, f->handle, name->full_name,
+                              &f->handle->fd, allow_level_II_oplock,
                               oplock_level, &oplock_granted);
 
        if (!NT_STATUS_IS_OK(status)) {
@@ -1327,21 +1333,6 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs,
 
        f->handle->have_opendb_entry = true;
 
-       if (access_mask & (SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA)) {
-               flags |= O_RDWR;
-       } else {
-               flags |= O_RDONLY;
-       }
-
-       /* do the actual open */
-       fd = open(f->handle->name->full_name, flags);
-       if (fd == -1) {
-               talloc_free(lck);
-               return pvfs_map_errno(f->pvfs, errno);
-       }
-
-       f->handle->fd = fd;
-
        stream_existed = name->stream_exists;
 
        /* if this was a stream create then create the stream as well */