summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Disseldorp <ddiss@samba.org>2019-02-27 11:52:42 +0100
committerKarolin Seeger <kseeger@samba.org>2019-03-05 13:01:15 +0000
commit7c476487867e5dc83b9e844db7be4c3d358fc006 (patch)
tree513ffc759ed0015a85af0adfa96b1177536b5234
parentc539cf176a669e54ccddefa6b57a9285d12c93a9 (diff)
downloadsamba-7c476487867e5dc83b9e844db7be4c3d358fc006.tar.gz
vfs_ceph: remove ceph_fallocate/ceph_ftruncate fallback
Both libcephfs functions are supported and capable of extending files, so fallback can be dropped. Bug: https://bugzilla.samba.org/show_bug.cgi?id=13807 Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org> (cherry picked from commit 155f1289ba7a4802fbb99fbc9ea90d8bc6cff0c9) [ddiss@samba.org: rebase atop 48t without 532ff3a5b958] Autobuild-User(v4-8-test): Karolin Seeger <kseeger@samba.org> Autobuild-Date(v4-8-test): Tue Mar 5 13:01:15 UTC 2019 on sn-devel-144
-rw-r--r--source3/modules/vfs_ceph.c102
1 files changed, 8 insertions, 94 deletions
diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c
index c68a98f97e8..5d67142997d 100644
--- a/source3/modules/vfs_ceph.c
+++ b/source3/modules/vfs_ceph.c
@@ -1124,9 +1124,7 @@ static struct smb_filename *cephwrap_getwd(struct vfs_handle_struct *handle,
static int strict_allocate_ftruncate(struct vfs_handle_struct *handle, files_struct *fsp, off_t len)
{
off_t space_to_write;
- uint64_t space_avail;
- uint64_t bsize,dfree,dsize;
- int ret;
+ int result;
NTSTATUS status;
SMB_STRUCT_STAT *pst;
@@ -1146,112 +1144,28 @@ static int strict_allocate_ftruncate(struct vfs_handle_struct *handle, files_str
/* Shrink - just ftruncate. */
if (pst->st_ex_size > len) {
- ret = ceph_ftruncate(handle->data, fsp->fh->fd, len);
- WRAP_RETURN(ret);
+ result = ceph_ftruncate(handle->data, fsp->fh->fd, len);
+ WRAP_RETURN(result);
}
space_to_write = len - pst->st_ex_size;
-
- /* for allocation try 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
- case we do our own emulation. fallocate implementations can
- return ENOTSUP or EINVAL in cases like that. */
- ret = SMB_VFS_FALLOCATE(fsp, 0, pst->st_ex_size, space_to_write);
- 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", errno));
-
- /* available disk space is enough or not? */
- space_avail =
- get_dfree_info(fsp->conn, fsp->fsp_name, &bsize, &dfree, &dsize);
- /* space_avail is 1k blocks */
- if (space_avail == (uint64_t)-1 ||
- ((uint64_t)space_to_write/1024 > space_avail) ) {
- errno = ENOSPC;
- return -1;
- }
-
- /* Write out the real space on disk. */
- return vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
+ result = ceph_fallocate(handle->data, fsp->fh->fd, 0, pst->st_ex_size,
+ space_to_write);
+ WRAP_RETURN(result);
}
static int cephwrap_ftruncate(struct vfs_handle_struct *handle, files_struct *fsp, off_t len)
{
int result = -1;
- SMB_STRUCT_STAT st;
- char c = 0;
- off_t currpos;
DBG_DEBUG("[CEPH] ftruncate(%p, %p, %llu\n", handle, fsp, llu(len));
if (lp_strict_allocate(SNUM(fsp->conn))) {
- result = strict_allocate_ftruncate(handle, fsp, len);
- return result;
+ return strict_allocate_ftruncate(handle, fsp, len);
}
- /* we used to just check HAVE_FTRUNCATE_EXTEND and only use
- sys_ftruncate if the system supports it. Then I discovered that
- you can have some filesystems that support ftruncate
- expansion and some that don't! On Linux fat can't do
- ftruncate extend but ext2 can. */
-
result = ceph_ftruncate(handle->data, fsp->fh->fd, len);
- if (result == 0)
- goto done;
-
- /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
- extend a file with ftruncate. Provide alternate implementation
- for this */
- currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
- if (currpos == -1) {
- goto done;
- }
-
- /* Do an fstat to see if the file is longer than the requested
- 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) {
- goto done;
- }
-
-#ifdef S_ISFIFO
- if (S_ISFIFO(st.st_ex_mode)) {
- result = 0;
- goto done;
- }
-#endif
-
- if (st.st_ex_size == len) {
- result = 0;
- goto done;
- }
-
- if (st.st_ex_size > len) {
- /* the sys_ftruncate should have worked */
- goto done;
- }
-
- if (SMB_VFS_LSEEK(fsp, len-1, SEEK_SET) != len -1)
- goto done;
-
- if (SMB_VFS_WRITE(fsp, &c, 1)!=1)
- goto done;
-
- /* Seek to where we were */
- if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
- goto done;
- result = 0;
-
- done:
-
- return result;
+ WRAP_RETURN(result);
}
static int cephwrap_fallocate(struct vfs_handle_struct *handle,