s3: VFS: Use SMB_VFS_FCNTL to set fd flags in open_file()
authorAnoop C S <anoopcs@redhat.com>
Fri, 27 Sep 2019 06:37:40 +0000 (12:07 +0530)
committerRalph Boehme <slow@samba.org>
Tue, 8 Oct 2019 09:57:19 +0000 (09:57 +0000)
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Tue Oct  8 09:57:19 UTC 2019 on sn-devel-184

source3/smbd/open.c
source3/smbd/proto.h
source3/smbd/vfs.c

index 5860155263b5a1bb8d7f50fbcc51702e3259c299..9493021c48dc1147fb29a8f6a24c42b392473ed5 100644 (file)
@@ -1327,7 +1327,7 @@ static NTSTATUS open_file(files_struct *fsp,
                         * too. With blocking file descriptors this
                         * does not happen.
                         */
-                       ret = set_blocking(fsp->fh->fd, true);
+                       ret = vfs_set_blocking(fsp, true);
                        if (ret == -1) {
                                status = map_nt_error_from_unix(errno);
                                DBG_WARNING("Could not set fd to blocking: "
index 11c9dc0f8b17e9c8872386fb236477bc9ef6f8d3..e9d04474df656795db383f6e1e94838c0f1bdb6e 100644 (file)
@@ -1230,6 +1230,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len);
 int vfs_set_filelen(files_struct *fsp, off_t len);
 int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len);
 int vfs_fill_sparse(files_struct *fsp, off_t len);
+int vfs_set_blocking(files_struct *fsp, bool set);
 off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n);
 const char *vfs_readdirname(connection_struct *conn, void *p,
                            SMB_STRUCT_STAT *sbuf, char **talloced);
index bef79e4c64e32f35ad34dcd6ab731669ccddb856..5332f00e876291bf8c7129b15a663464a717d12c 100644 (file)
@@ -711,6 +711,37 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
        return ret;
 }
 
+/*******************************************************************************
+ Set a fd into blocking/nonblocking mode through VFS
+*******************************************************************************/
+
+int vfs_set_blocking(files_struct *fsp, bool set)
+{
+       int val;
+#ifdef O_NONBLOCK
+#define FLAG_TO_SET O_NONBLOCK
+#else
+#ifdef SYSV
+#define FLAG_TO_SET O_NDELAY
+#else /* BSD */
+#define FLAG_TO_SET FNDELAY
+#endif
+#endif
+       val = SMB_VFS_FCNTL(fsp, F_GETFL, 0);
+       if (val == -1) {
+               return -1;
+       }
+
+       if (set) {
+               val &= ~FLAG_TO_SET;
+       } else {
+               val |= FLAG_TO_SET;
+       }
+
+       return SMB_VFS_FCNTL(fsp, F_SETFL, val);
+#undef FLAG_TO_SET
+}
+
 /****************************************************************************
  Transfer some data (n bytes) between two file_struct's.
 ****************************************************************************/