From 9cf826f0f349d6fc163d6342eb8c54ac8d462d0c Mon Sep 17 00:00:00 2001 From: Olaf Flebbe Date: Tue, 8 Dec 2009 15:14:58 +0100 Subject: [PATCH] Use fallocate to handle strict allocate = partial in order not to fragment files for CIFS write ahead mode --- source3/include/local.h | 4 ++ source3/include/proto.h | 4 +- source3/include/smb.h | 6 ++ source3/include/vfs.h | 7 ++- source3/include/vfs_macros.h | 1 + source3/lib/system.c | 18 +++++++ source3/modules/vfs_default.c | 104 +++++++++++++++++++++++++++++++++++++- source3/modules/vfs_full_audit.c | 16 ++++++ source3/param/loadparm.c | 27 ++++++++-- source3/smbd/aio.c | 48 +++++++++++++++++- source3/smbd/fileio.c | 5 +- source3/smbd/globals.c | 1 - source3/smbd/globals.h | 1 - source3/smbd/vfs.c | 45 ++++------------ 14 files changed, 238 insertions(+), 49 deletions(-) diff --git a/source3/include/local.h b/source3/include/local.h index 45767ad..a27c258 100644 --- a/source3/include/local.h +++ b/source3/include/local.h @@ -253,6 +253,10 @@ /* Windows minimum lock resolution timeout in ms */ #define WINDOWS_MINIMUM_LOCK_TIMEOUT_MS 200 +/* When strict allocate = partial, define the limit on how far + * ahead we will write. */ +#define STRICT_ALLOCATE_PARTIAL_LIMIT 0x200000 + /* Maximum size of RPC data we will accept for one call. */ #define MAX_RPC_DATA_SIZE (15*1024*1024) diff --git a/source3/include/proto.h b/source3/include/proto.h index d2ae62c..305b6d8 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -4175,7 +4175,7 @@ bool lp_manglednames(const struct share_params *p ); bool lp_widelinks(int ); bool lp_symlinks(int ); bool lp_syncalways(int ); -bool lp_strict_allocate(int ); +int lp_strict_allocate(int ); bool lp_strict_sync(int ); bool lp_map_system(int ); bool lp_delete_readonly(int ); @@ -7131,7 +7131,7 @@ ssize_t vfs_pwrite_data(struct smb_request *req, SMB_OFF_T offset); int vfs_allocate_file_space(files_struct *fsp, uint64_t len); int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len); -int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len); +int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len, enum smb_strict_allocate_options sa_options); SMB_OFF_T vfs_transfer_file(files_struct *in, files_struct *out, SMB_OFF_T n); char *vfs_readdirname(connection_struct *conn, void *p, SMB_STRUCT_STAT *sbuf); int vfs_ChDir(connection_struct *conn, const char *path); diff --git a/source3/include/smb.h b/source3/include/smb.h index 2a3c455..bad6523 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -1933,6 +1933,12 @@ struct smb_extended_info { */ #define CFF_DOS_PATH 0x00000001 +enum smb_strict_allocate_options { + STRICT_ALLOCATE_OFF=0, + STRICT_ALLOCATE_ON=1, + STRICT_ALLOCATE_PARTIAL=2 +}; + /* time info */ struct smb_file_time { struct timespec mtime; diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 0c0e093..59ad609 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -117,8 +117,9 @@ /* Leave at 25 - not yet released. Add init_search_op call. - sdann */ /* Leave at 25 - not yet released. Add locking calls. -- zkirsch. */ /* Leave at 25 - not yet released. Add strict locking calls. -- drichards. */ +/* Changed to 26 - add fallocate: oflebbe */ -#define SMB_VFS_INTERFACE_VERSION 25 +#define SMB_VFS_INTERFACE_VERSION 26 /* to bug old modules which are trying to compile with the old functions */ @@ -207,6 +208,7 @@ typedef enum _vfs_op_type { SMB_VFS_OP_GETWD, SMB_VFS_OP_NTIMES, SMB_VFS_OP_FTRUNCATE, + SMB_VFS_OP_FALLOCATE, SMB_VFS_OP_LOCK, SMB_VFS_OP_KERNEL_FLOCK, SMB_VFS_OP_LINUX_SETLEASE, @@ -369,6 +371,8 @@ struct vfs_ops { char *(*getwd)(struct vfs_handle_struct *handle, char *buf); int (*ntimes)(struct vfs_handle_struct *handle, const char *path, struct smb_file_time *ft); int (*ftruncate)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_OFF_T offset); + int (*fallocate)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_OFF_T offset, + SMB_OFF_T len); bool (*lock)(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_OFF_T offset, SMB_OFF_T count, int type); int (*kernel_flock)(struct vfs_handle_struct *handle, struct files_struct *fsp, uint32 share_mode); int (*linux_setlease)(struct vfs_handle_struct *handle, struct files_struct *fsp, int leasetype); @@ -550,6 +554,7 @@ struct vfs_ops { struct vfs_handle_struct *getwd; struct vfs_handle_struct *ntimes; struct vfs_handle_struct *ftruncate; + struct vfs_handle_struct *fallocate; struct vfs_handle_struct *lock; struct vfs_handle_struct *kernel_flock; struct vfs_handle_struct *linux_setlease; diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h index acb158e..bbb2758 100644 --- a/source3/include/vfs_macros.h +++ b/source3/include/vfs_macros.h @@ -74,6 +74,7 @@ #define SMB_VFS_GETWD(conn, buf) ((conn)->vfs.ops.getwd((conn)->vfs.handles.getwd, (buf))) #define SMB_VFS_NTIMES(conn, path, ts) ((conn)->vfs.ops.ntimes((conn)->vfs.handles.ntimes, (path), (ts))) #define SMB_VFS_FTRUNCATE(fsp, offset) ((fsp)->conn->vfs.ops.ftruncate((fsp)->conn->vfs.handles.ftruncate, (fsp), (offset))) +#define SMB_VFS_FALLOCATE(fsp, offset, len) ((fsp)->conn->vfs.ops.fallocate((fsp)->conn->vfs_handles, (fsp), (offset), (len))) #define SMB_VFS_LOCK(fsp, op, offset, count, type) ((fsp)->conn->vfs.ops.lock((fsp)->conn->vfs.handles.lock, (fsp), (op), (offset), (count), (type))) #define SMB_VFS_KERNEL_FLOCK(fsp, share_mode) ((fsp)->conn->vfs.ops.kernel_flock((fsp)->conn->vfs.handles.kernel_flock, (fsp), (share_mode))) #define SMB_VFS_LINUX_SETLEASE(fsp, leasetype) ((fsp)->conn->vfs.ops.linux_setlease((fsp)->conn->vfs.handles.linux_setlease, (fsp), (leasetype))) diff --git a/source3/lib/system.c b/source3/lib/system.c index e815766..9346c3a 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -342,6 +342,24 @@ int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf) } /******************************************************************* + An posix_fallocate() wrapper that will deal with 64 bit filesizes. +********************************************************************/ +int sys_posix_fallocate(int fd, SMB_OFF_T offset, SMB_OFF_T len) +{ +#if (defined(HAVE_POSIX_FALLOCATE64) || defined(HAVE_POSIX_FALLOCATE)) && !defined(HAVE_BROKEN_POSIX_FALLOCATE) +#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_POSIX_FALLOCATE64) + return posix_fallocate64(fd, offset, len); +#else + return posix_fallocate(fd, offset, len); +#endif +#else + /* No posix_fallocate System Call */ + errno = ENOSYS; + return -1; +#endif +} + +/******************************************************************* An ftruncate() wrapper that will deal with 64 bit filesizes. ********************************************************************/ diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index f5cee4c..ff4f446 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -884,10 +884,14 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_O SMB_STRUCT_STAT st; char c = 0; SMB_OFF_T currpos; + enum smb_strict_allocate_options sa_options = lp_strict_allocate(SNUM(fsp->conn)); START_PROFILE(syscall_ftruncate); - if (lp_strict_allocate(SNUM(fsp->conn))) { + /* Only use allocation truncate if strict allocate + * is set "on", not off or partial. + */ + if (sa_options == STRICT_ALLOCATE_ON) { result = strict_allocate_ftruncate(handle, fsp, len); END_PROFILE(syscall_ftruncate); return result; @@ -915,7 +919,7 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_O size in which case the ftruncate above should have succeeded or shorter, in which case seek to len - 1 and write 1 byte of zero */ - if (SMB_VFS_FSTAT(fsp, &st) == -1) { + if (SMB_VFS_FSTAT(fsp, &st) == -1) { goto done; } @@ -953,6 +957,100 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_O return result; } +#define SPARSE_BUF_WRITE_SIZE (32*1024) +static char *sparse_buf = NULL; + +static int vfswrap_fallocate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T offset, SMB_OFF_T len) +{ + int result = -1; + SMB_STRUCT_STAT st; + char c = 0; + SMB_OFF_T currpos; + SMB_OFF_T total, pwrite_ret; + + START_PROFILE(syscall_fallocate); + + result = sys_posix_fallocate(fsp->fh->fd, offset, len); + if (result == 0) + goto done; + + /* double check for invalid parameters */ + if (len <= 0 || offset < 0) { + result = 0; + goto done; + } + + if (SMB_VFS_FSTAT(fsp, &st) == -1) { + goto done; + } + +#ifdef S_ISFIFO + if (S_ISFIFO(st.st_mode)) { + result = 0; + goto done; + } +#endif + + /* be cautious! if file already larger: NOP */ + if (st.st_size >= offset + len) { + result = 0; + goto done; + } + + if (!sparse_buf) { + sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE); + if (!sparse_buf) { + errno = ENOMEM; + result = -1; + goto done; + } + } + + /* check if offset is within the current file */ + if(st.st_size > offset) { + /* already checked, len could not be negative */ + len -= (st.st_size - offset) - 1; + /* position one byte behind eof */ + offset = st.st_size + 1; + } + + currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR); + if (currpos == -1) { + goto done; + } + + total = 0; + + while (total < len) { + size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (len - total)); + + pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total); + if (pwrite_ret == -1) { + DEBUG(10,("vfs_fill_sparse: SMB_VFS_PWRITE for file " + "failed with error %s\n", + strerror(errno))); + result = -1; + goto done; + } + if (pwrite_ret == 0) { + result = 0; + goto done; + } + + total += pwrite_ret; + } + + /* Seek to where we were */ + if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos) + goto done; + result = 0; + + done: + + END_PROFILE(syscall_ftruncate); + return result; +} + static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) { bool result; @@ -1654,6 +1752,8 @@ static vfs_op_tuple vfs_default_ops[] = { SMB_VFS_LAYER_OPAQUE}, {SMB_VFS_OP(vfswrap_ftruncate), SMB_VFS_OP_FTRUNCATE, SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fallocate), SMB_VFS_OP_FALLOCATE, + SMB_VFS_LAYER_OPAQUE}, {SMB_VFS_OP(vfswrap_lock), SMB_VFS_OP_LOCK, SMB_VFS_LAYER_OPAQUE}, {SMB_VFS_OP(vfswrap_kernel_flock), SMB_VFS_OP_KERNEL_FLOCK, diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c index ebe89ec..1a536d8 100644 --- a/source3/modules/vfs_full_audit.c +++ b/source3/modules/vfs_full_audit.c @@ -180,6 +180,8 @@ static int smb_full_audit_ntimes(vfs_handle_struct *handle, const char *path, struct smb_file_time *ft); static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len); +static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp, + SMB_OFF_T offset, SMB_OFF_T len); static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, int op, SMB_OFF_T offset, SMB_OFF_T count, int type); static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle, @@ -653,6 +655,7 @@ static struct { { SMB_VFS_OP_GETWD, "getwd" }, { SMB_VFS_OP_NTIMES, "ntimes" }, { SMB_VFS_OP_FTRUNCATE, "ftruncate" }, + { SMB_VFS_OP_FALLOCATE, "fallocate" }, { SMB_VFS_OP_LOCK, "lock" }, { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" }, { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" }, @@ -1533,6 +1536,19 @@ static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp return result; } +static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp, + SMB_OFF_T offset, SMB_OFF_T len) +{ + int result; + + result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, offset, len); + + do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle, + "%s", fsp->fsp_name); + + return result; +} + static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) { diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index cd27fe4..c69bc6b 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -457,7 +457,7 @@ struct service { bool bWidelinks; bool bSymlinks; bool bSyncAlways; - bool bStrictAllocate; + int iStrictAllocate; bool bStrictSync; char magic_char; struct bitmap *copymap; @@ -601,7 +601,7 @@ static struct service sDefault = { True, /* bWidelinks */ True, /* bSymlinks */ False, /* bSyncAlways */ - False, /* bStrictAllocate */ + STRICT_ALLOCATE_OFF, /* iStrictAllocate */ False, /* bStrictSync */ '~', /* magic char */ NULL, /* copymap */ @@ -882,6 +882,21 @@ static const struct enum_list enum_kerberos_method[] = { {-1, NULL} }; +static const struct enum_list enum_strict_allocate[] = { + {STRICT_ALLOCATE_OFF, "No"}, + {STRICT_ALLOCATE_OFF, "False"}, + {STRICT_ALLOCATE_OFF, "0"}, + {STRICT_ALLOCATE_OFF, "Off"}, + {STRICT_ALLOCATE_OFF, "disabled"}, + {STRICT_ALLOCATE_ON, "Yes"}, + {STRICT_ALLOCATE_ON, "True"}, + {STRICT_ALLOCATE_ON, "1"}, + {STRICT_ALLOCATE_ON, "On"}, + {STRICT_ALLOCATE_ON, "enabled"}, + {STRICT_ALLOCATE_PARTIAL, "partial"}, + {-1, NULL} +}; + /* Note: We do not initialise the defaults union - it is not allowed in ANSI C * * The FLAG_HIDE is explicit. Parameters set this way do NOT appear in any edit @@ -2434,11 +2449,11 @@ static struct parm_struct parm_table[] = { }, { .label = "strict allocate", - .type = P_BOOL, + .type = P_ENUM, .p_class = P_LOCAL, - .ptr = &sDefault.bStrictAllocate, + .ptr = &sDefault.iStrictAllocate, .special = NULL, - .enum_list = NULL, + .enum_list = enum_strict_allocate, .flags = FLAG_ADVANCED | FLAG_SHARE, }, { @@ -5548,7 +5563,7 @@ FN_LOCAL_PARM_BOOL(lp_manglednames, bMangledNames) FN_LOCAL_BOOL(lp_widelinks, bWidelinks) FN_LOCAL_BOOL(lp_symlinks, bSymlinks) FN_LOCAL_BOOL(lp_syncalways, bSyncAlways) -FN_LOCAL_BOOL(lp_strict_allocate, bStrictAllocate) +FN_LOCAL_INTEGER(lp_strict_allocate, iStrictAllocate) FN_LOCAL_BOOL(lp_strict_sync, bStrictSync) FN_LOCAL_BOOL(lp_map_system, bMap_system) FN_LOCAL_BOOL(lp_delete_readonly, bDeleteReadonly) diff --git a/source3/smbd/aio.c b/source3/smbd/aio.c index 406ec1b..18ac5fa 100644 --- a/source3/smbd/aio.c +++ b/source3/smbd/aio.c @@ -1,3 +1,4 @@ + /* Unix SMB/Netbios implementation. Version 3.0 @@ -211,8 +212,10 @@ bool schedule_aio_write_and_X(connection_struct *conn, { struct aio_extra *aio_ex; SMB_STRUCT_AIOCB *a; + SMB_STRUCT_STAT st; size_t bufsize; bool write_through = BITSETW(req->vwv+7,0); + bool other_aio_found; size_t min_aio_write_size = lp_aio_write_size(SNUM(conn)); int ret; @@ -233,7 +236,7 @@ bool schedule_aio_write_and_X(connection_struct *conn, } /* Only do this on non-chained and non-chaining reads not using the - * write cache. */ + write cache. */ if (req_is_in_chain(req) || (lp_write_cache_size(SNUM(conn)) != 0)) { return False; } @@ -251,6 +254,49 @@ bool schedule_aio_write_and_X(connection_struct *conn, return False; } + other_aio_found = false; + /* Make sure there are no outstanding aio writes on same fsp */ + for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) { + if (fsp == aio_ex->fsp) { + /* Don't do sparse file detection if other */ + /* aio statements are outstanding */ + /* this should not happen! */ + other_aio_found = true; + break; + } + } + + if (!other_aio_found) { + ret = SMB_VFS_FSTAT(fsp, &st); + if (ret == -1) { + /* This should not happen, fall back to synchronous */ + return False; + } + + if (startpos > st.st_size) { + /* Writing beyond end of file + potentially creating a gap */ + + enum smb_strict_allocate_options sa_options = + lp_strict_allocate(SNUM(fsp->conn)); + + /* let a synchronous write handle filling + the sparse file */ + if (sa_options == STRICT_ALLOCATE_ON) + return False; + + /* If strict allocate is set to "partial", + ignore all allocate requests over the + STRICT_ALLOCATE_PARTIAL_LIMIT. */ + + if ((sa_options == STRICT_ALLOCATE_PARTIAL) && + (startpos - st.st_size < + STRICT_ALLOCATE_PARTIAL_LIMIT)) { + return False; + } + } + } + bufsize = smb_size + 6*2; if (!(aio_ex = create_aio_extra(fsp, bufsize))) { diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index adf664b..73d70c6 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -125,9 +125,10 @@ static ssize_t real_write_file(struct smb_request *req, if (pos == -1) { ret = vfs_write_data(req, fsp, data, n); } else { + enum smb_strict_allocate_options sa_options = lp_strict_allocate(SNUM(fsp->conn)); fsp->fh->pos = pos; - if (pos && lp_strict_allocate(SNUM(fsp->conn))) { - if (vfs_fill_sparse(fsp, pos) == -1) { + if (pos && (sa_options != STRICT_ALLOCATE_OFF)) { + if (vfs_fill_sparse(fsp, pos, sa_options) == -1) { return -1; } } diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c index 9e7d103..82a0422 100644 --- a/source3/smbd/globals.c +++ b/source3/smbd/globals.c @@ -167,7 +167,6 @@ struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH]; int conn_ctx_stack_ndx = 0; struct vfs_init_function_entry *backends = NULL; -char *sparse_buf = NULL; char *LastDir = NULL; /* Current number of oplocks we have outstanding. */ diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index 6ac92ed..caddc92 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -178,7 +178,6 @@ extern int conn_ctx_stack_ndx; struct vfs_init_function_entry; extern struct vfs_init_function_entry *backends; -extern char *sparse_buf; extern char *LastDir; /* Current number of oplocks we have outstanding. */ diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 4267728..66e13b6 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -556,8 +556,9 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len) contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW); contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW); - if (!lp_strict_allocate(SNUM(fsp->conn))) + if (lp_strict_allocate(SNUM(fsp->conn)) == STRICT_ALLOCATE_OFF) { return 0; + } len -= st.st_size; len /= 1024; /* Len is now number of 1k blocks needed. */ @@ -611,9 +612,8 @@ int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len) Returns 0 on success, -1 on failure. ****************************************************************************/ -#define SPARSE_BUF_WRITE_SIZE (32*1024) -int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len) +int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len, enum smb_strict_allocate_options sa_options) { int ret; SMB_STRUCT_STAT st; @@ -631,6 +631,14 @@ int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len) return 0; } + /* If strict allocate is set to "partial", ignore all allocate + * requests over the STRICT_ALLOCATE_PARTIAL_LIMIT. */ + + if ((sa_options == STRICT_ALLOCATE_PARTIAL) && + (len - st.st_size > STRICT_ALLOCATE_PARTIAL_LIMIT)) { + return 0; + } + DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to len %.0f (%.0f bytes)\n", fsp->fsp_name, (double)st.st_size, (double)len, (double)(len - st.st_size))); @@ -638,36 +646,7 @@ int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len) flush_write_cache(fsp, SIZECHANGE_FLUSH); - if (!sparse_buf) { - sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE); - if (!sparse_buf) { - errno = ENOMEM; - ret = -1; - goto out; - } - } - - offset = st.st_size; - num_to_write = len - st.st_size; - total = 0; - - while (total < num_to_write) { - size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (num_to_write - total)); - - pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total); - if (pwrite_ret == -1) { - DEBUG(10,("vfs_fill_sparse: SMB_VFS_PWRITE for file %s failed with error %s\n", - fsp->fsp_name, strerror(errno) )); - ret = -1; - goto out; - } - if (pwrite_ret == 0) { - ret = 0; - goto out; - } - - total += pwrite_ret; - } + SMB_VFS_FALLOCATE( fsp, st.st_size, len); set_filelen_write_cache(fsp, len); -- 1.6.0.2