The branch, master has been updated
       via  2845e1c s3: modules: Fix *allocate* calls to follow POSIX error 
return convention.
       via  cc1f91c s3: smbd: Fix *allocate* calls to follow POSIX error return 
convention.
       via  c9235de s3: smbd: Fix *allocate* calls to follow POSIX error return 
convention.
       via  e60433e lib: Simplify load_case_tables_library()
      from  49e208c smbd: Use read_data() in notify_inotify

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 2845e1c29f8bce6306a73d546184c401bf89cfea
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Dec 5 15:37:11 2014 -0800

    s3: modules: Fix *allocate* calls to follow POSIX error return convention.
    
    Fix up the ceph, fruit, time_audit and streams_xattr modules to follow
    the -1,errno convention for errors.
    
    Reported by Jones <jones.k...@gmail.com> who provided the
    initial patch. This patch tested and confirmed working
    by him as well.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: David Disseldorp <dd...@suse.de>
    
    Autobuild-User(master): Jeremy Allison <j...@samba.org>
    Autobuild-Date(master): Mon Dec  8 02:59:43 CET 2014 on sn-devel-104

commit cc1f91cec627cb3e4fc89b96aae1e7e4c539cd1c
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Dec 5 15:34:12 2014 -0800

    s3: smbd: Fix *allocate* calls to follow POSIX error return convention.
    
    Fix vfs_allocate_file_space(), vfs_slow_fallocate(),
    vfs_fill_sparse() to follow the -1,errno convention
    for errors.
    
    Standardize on the -1,errno convention.
    
    Reported by Jones <jones.k...@gmail.com> who provided the
    initial patch. This patch tested and confirmed working
    by him as well.
    
    https://bugzilla.samba.org/show_bug.cgi?id=10982
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: David Disseldorp <dd...@suse.de>

commit c9235deee0fc49c99cfaf2329b7af526d9dd12d0
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Dec 5 15:31:19 2014 -0800

    s3: smbd: Fix *allocate* calls to follow POSIX error return convention.
    
    vfswrap_fallocate() is broken in that it can call posix_fallocate()
    which returns an int error (and doesn't set errno) but can also
    call Linux fallocate() which returns -1 and sets errno.
    
    Standardize on the -1,errno convention.
    
    Reported by Jones <jones.k...@gmail.com> who provided the
    initial patch. This patch tested and confirmed working
    by him as well.
    
    https://bugzilla.samba.org/show_bug.cgi?id=10982
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: David Disseldorp <dd...@suse.de>

commit e60433efa182484c9fd480d831a21970775e0c99
Author: Volker Lendecke <v...@samba.org>
Date:   Sun Dec 7 12:08:55 2014 +0100

    lib: Simplify load_case_tables_library()
    
    We don't really need a talloc context here
    
    Signed-off-by: Volker Lendecke <v...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/charset/codepoints.c       | 17 +++++++++--------
 source3/modules/vfs_ceph.c          | 13 +++----------
 source3/modules/vfs_default.c       | 17 ++++++++++++-----
 source3/modules/vfs_fruit.c         |  5 +++--
 source3/modules/vfs_streams_xattr.c |  5 +++--
 source3/modules/vfs_time_audit.c    |  8 +++++++-
 source3/smbd/vfs.c                  | 22 +++++++++++-----------
 7 files changed, 48 insertions(+), 39 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/charset/codepoints.c b/lib/util/charset/codepoints.c
index 0984164..499cea4 100644
--- a/lib/util/charset/codepoints.c
+++ b/lib/util/charset/codepoints.c
@@ -47,15 +47,16 @@ This is the function that should be called from library 
code.
 ********************************************************************/
 void load_case_tables_library(void)
 {
-       TALLOC_CTX *mem_ctx;
+       const char *codepagedir = get_dyn_CODEPAGEDIR();
+       size_t codepagedir_len = strlen(codepagedir);
+       char buf[codepagedir_len+13];
+
+       snprintf(buf, sizeof(buf), "%s/upcase.dat", codepagedir);
+       upcase_table = map_file(buf, 0x20000);
+
+       snprintf(buf, sizeof(buf), "%s/lowcase.dat", codepagedir);
+       lowcase_table = map_file(buf, 0x20000);
 
-       mem_ctx = talloc_init("load_case_tables");
-       if (!mem_ctx) {
-               smb_panic("No memory for case_tables");
-       }
-       upcase_table = map_file(talloc_asprintf(mem_ctx, "%s/upcase.dat", 
get_dyn_CODEPAGEDIR()), 0x20000);
-       lowcase_table = map_file(talloc_asprintf(mem_ctx, "%s/lowcase.dat", 
get_dyn_CODEPAGEDIR()), 0x20000);
-       talloc_free(mem_ctx);
        if (upcase_table == NULL) {
                DEBUG(1, ("Failed to load upcase.dat, will use lame ASCII-only 
case sensitivity rules\n"));
                upcase_table = (void *)-1;
diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c
index e402ff1..b0a0024 100644
--- a/source3/modules/vfs_ceph.c
+++ b/source3/modules/vfs_ceph.c
@@ -795,15 +795,14 @@ static int strict_allocate_ftruncate(struct 
vfs_handle_struct *handle, files_str
           return ENOTSUP or EINVAL in cases like that. */
        ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_EXTEND_SIZE,
                                pst->st_ex_size, space_to_write);
-       if (ret == ENOSPC) {
-               errno = ENOSPC;
+       if (ret == -1 && errno == ENOSPC) {
                return -1;
        }
        if (ret == 0) {
                return 0;
        }
        DEBUG(10,("[CEPH] strict_allocate_ftruncate: SMB_VFS_FALLOCATE failed 
with "
-               "error %d. Falling back to slow manual allocation\n", ret));
+               "error %d. Falling back to slow manual allocation\n", errno));
 
        /* available disk space is enough or not? */
        space_avail = get_dfree_info(fsp->conn,
@@ -817,13 +816,7 @@ static int strict_allocate_ftruncate(struct 
vfs_handle_struct *handle, files_str
        }
 
        /* Write out the real space on disk. */
-       ret = vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
-       if (ret != 0) {
-               errno = ret;
-               ret = -1;
-       }
-
-       return 0;
+       return vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
 }
 
 static int cephwrap_ftruncate(struct vfs_handle_struct *handle, files_struct 
*fsp, off_t len)
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 1e1c318..f5b8f9b 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -1864,15 +1864,14 @@ static int strict_allocate_ftruncate(vfs_handle_struct 
*handle, files_struct *fs
           return ENOTSUP or EINVAL in cases like that. */
        ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_EXTEND_SIZE,
                                pst->st_ex_size, space_to_write);
-       if (ret == ENOSPC) {
-               errno = ENOSPC;
+       if (ret == -1 && errno == ENOSPC) {
                return -1;
        }
        if (ret == 0) {
                return 0;
        }
        DEBUG(10,("strict_allocate_ftruncate: SMB_VFS_FALLOCATE failed with "
-               "error %d. Falling back to slow manual allocation\n", ret));
+               "error %d. Falling back to slow manual allocation\n", errno));
 
        /* available disk space is enough or not? */
        space_avail = get_dfree_info(fsp->conn,
@@ -1888,8 +1887,7 @@ static int strict_allocate_ftruncate(vfs_handle_struct 
*handle, files_struct *fs
        /* Write out the real space on disk. */
        ret = vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
        if (ret != 0) {
-               errno = ret;
-               ret = -1;
+               return -1;
        }
 
        return 0;
@@ -1974,6 +1972,15 @@ static int vfswrap_fallocate(vfs_handle_struct *handle,
        START_PROFILE(syscall_fallocate);
        if (mode == VFS_FALLOCATE_EXTEND_SIZE) {
                result = sys_posix_fallocate(fsp->fh->fd, offset, len);
+               /*
+                * posix_fallocate returns 0 on success, errno on error
+                * and doesn't set errno. Make it behave like fallocate()
+                * which returns -1, and sets errno on failure.
+                */
+               if (result != 0) {
+                       errno = result;
+                       result = -1;
+               }
        } else if (mode == VFS_FALLOCATE_KEEP_SIZE) {
                result = sys_fallocate(fsp->fh->fd, mode, offset, len);
        } else {
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index 18a6823..a8bf7b4 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -3050,11 +3050,12 @@ static int fruit_fallocate(struct vfs_handle_struct 
*handle,
        }
 
        if (!fruit_fsp_recheck(ad, fsp)) {
-               return errno;
+               return -1;
        }
 
        /* Let the pwrite code path handle it. */
-       return ENOSYS;
+       errno = ENOSYS;
+       return -1;
 }
 
 static int fruit_ftruncate(struct vfs_handle_struct *handle,
diff --git a/source3/modules/vfs_streams_xattr.c 
b/source3/modules/vfs_streams_xattr.c
index f0ab732..5c5a9a1 100644
--- a/source3/modules/vfs_streams_xattr.c
+++ b/source3/modules/vfs_streams_xattr.c
@@ -1103,11 +1103,12 @@ static int streams_xattr_fallocate(struct 
vfs_handle_struct *handle,
        }
 
        if (!streams_xattr_recheck(sio)) {
-               return errno;
+               return -1;
        }
 
        /* Let the pwrite code path handle it. */
-       return ENOSYS;
+       errno = ENOSYS;
+       return -1;
 }
 
 
diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 4ce9238..a1e825a 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -1216,18 +1216,24 @@ static int smb_time_audit_fallocate(vfs_handle_struct 
*handle,
                                    off_t len)
 {
        int result;
+       int saved_errno = 0;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
        result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
+       if (result == -1) {
+               saved_errno = errno;
+       }
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
                smb_time_audit_log_fsp("fallocate", timediff, fsp);
        }
-
+       if (result == -1) {
+               errno = saved_errno;
+       }
        return result;
 }
 
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 51362c3..d10e0d6 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -586,6 +586,10 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t 
len)
                return 0;
        }
 
+       if (ret == -1 && errno == ENOSPC) {
+               return -1;
+       }
+
        len -= fsp->fsp_name->st.st_ex_size;
        len /= 1024; /* Len is now number of 1k blocks needed. */
        space_avail = get_dfree_info(conn, fsp->fsp_name->base_name, false,
@@ -640,7 +644,7 @@ int vfs_set_filelen(files_struct *fsp, off_t len)
  fails. Needs to be outside of the default version of SMB_VFS_FALLOCATE
  as this is also called from the default SMB_VFS_FTRUNCATE code.
  Always extends the file size.
- Returns 0 on success, errno on failure.
+ Returns 0 on success, -1 on failure.
 ****************************************************************************/
 
 #define SPARSE_BUF_WRITE_SIZE (32*1024)
@@ -654,7 +658,7 @@ int vfs_slow_fallocate(files_struct *fsp, off_t offset, 
off_t len)
                sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
                if (!sparse_buf) {
                        errno = ENOMEM;
-                       return ENOMEM;
+                       return -1;
                }
        }
 
@@ -663,10 +667,12 @@ int vfs_slow_fallocate(files_struct *fsp, off_t offset, 
off_t len)
 
                pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, 
offset + total);
                if (pwrite_ret == -1) {
+                       int saved_errno = errno;
                        DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file "
                                  "%s failed with error %s\n",
-                                 fsp_str_dbg(fsp), strerror(errno)));
-                       return errno;
+                                 fsp_str_dbg(fsp), strerror(saved_errno)));
+                       errno = saved_errno;
+                       return -1;
                }
                total += pwrite_ret;
        }
@@ -724,9 +730,7 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
                 * return ENOTSUP or EINVAL in cases like that. */
                ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_EXTEND_SIZE,
                                offset, num_to_write);
-               if (ret == ENOSPC) {
-                       errno = ENOSPC;
-                       ret = -1;
+               if (ret == -1 && errno == ENOSPC) {
                        goto out;
                }
                if (ret == 0) {
@@ -737,10 +741,6 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
        }
 
        ret = vfs_slow_fallocate(fsp, offset, num_to_write);
-       if (ret != 0) {
-               errno = ret;
-               ret = -1;
-       }
 
  out:
 


-- 
Samba Shared Repository

Reply via email to