s3: allocate only "new" space, not "old" sparse space in the posix_fallocate path
authorBjörn Jacke <bj@sernet.de>
Tue, 8 Dec 2009 09:30:03 +0000 (10:30 +0100)
committerKarolin Seeger <kseeger@samba.org>
Mon, 14 Dec 2009 07:28:53 +0000 (08:28 +0100)
this makes the posix_fallocate path work analogous to the manual allocate path.
(cherry picked from commit e9fb2807037919a598e17d24def4897e0cbfe19c)

source3/modules/vfs_default.c

index 3691fb0e7e77c82ae5814c109088a9e70f37e2bd..9b842df93fa9c578f8e080f0282f128ea9cea454 100644 (file)
@@ -936,6 +936,8 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
        if (st.st_ex_size > len)
                return sys_ftruncate(fsp->fh->fd, len);
 
+       space_to_write = len - st.st_ex_size;
+
        /* for allocation try posix_fallocate first. This can fail on some
           platforms e.g. when the filesystem doesn't support it and no
           emulation is being done by the libc (like on AIX with JFS1). In that
@@ -943,7 +945,7 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
           return ENOTSUP or EINVAL in cases like that. */
 #if defined(HAVE_POSIX_FALLOCATE)
        {
-               int ret = sys_posix_fallocate(fsp->fh->fd, 0, len);
+               int ret = sys_posix_fallocate(fsp->fh->fd, st.st_ex_size, space_to_write);
                if (ret == ENOSPC) {
                        errno = ENOSPC;
                        return -1;
@@ -957,7 +959,6 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
        }
 #endif
        /* available disk space is enough or not? */
-       space_to_write = len - st.st_ex_size;
        space_avail = get_dfree_info(fsp->conn,
                                     fsp->fsp_name->base_name, false,
                                     &bsize,&dfree,&dsize);