From patchwork Thu Apr 1 18:30:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12179393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6A8FC433B4 for ; Thu, 1 Apr 2021 19:23:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9841D61001 for ; Thu, 1 Apr 2021 19:23:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234854AbhDATXy (ORCPT ); Thu, 1 Apr 2021 15:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234627AbhDATXs (ORCPT ); Thu, 1 Apr 2021 15:23:48 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97E55C08E750; Thu, 1 Apr 2021 11:30:41 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id m12so4215801lfq.10; Thu, 01 Apr 2021 11:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=40avOPfC1Fu2kiJ4DKn5f2Yq5VnQaYcTK2JOpGiRFtI=; b=CxJI/5fa6dOmTAGwQhm2K+hBDvY3NnHTHr65MjMPquJLssl0Uw/BqrsxMUVWrj3rmw zBtd9hzk+MQy1i286P2RUycp7wrHxjerTbBB/SVO9FGukZHUNUGxwpOmALWgSapTT4DP eMHVuXgm9+TLRE0jMS1hu+GxiQwMZBiIlpUg2eoDFflTP9Eul2DZt9iRcF748O2yRmkQ PFZ4iK6SmZre7ucUsSap5ZvMWoqwRX0HwRVh0+3B3ARsOdPgJaQLr46jfPJWYzfHtODp u6Ke8/9TizWScvYnWTUsH9ciIQNISpMZY4SyvOZ9dwof+ILehsnpf8R+LGsnomapqMr5 49zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=40avOPfC1Fu2kiJ4DKn5f2Yq5VnQaYcTK2JOpGiRFtI=; b=HrM3c3Is/9YMQFrVQa3KCjtpnWpI0FAhEAJyGFYBvVI5vcSmx/fX7bGzWDbvHZv5Ls qeII2qgyKTqD/E7hY69f6Y71xDW5tMtNsu1TWitphVNrix3CgLF2SVDqXZtdBMTA6WnE V2ZsEE8rgYFTsmJ7RguaiGzCf2Xyp7AGZBSoMFt2iygC0nNgpCQDmCHXREOiTPRBqmy2 cxyt8EIIJD+MsqDA2rATJTNEDd5W04fMcv5OoXgey0Z8Y7N/8dBDIde6g4kUrlo+qJpQ jwmX/3xbaMY9nLJKHwQiBIqxwTOYs/L4ZwohBkmjLd/lECVCyN0tySe+ITlnT3btvju/ HKaQ== X-Gm-Message-State: AOAM531+PYYacxNMQGHVpElW7U7lTIue7h2CouMgE2uLT7JzyBfRl0mh uMDo+vHLLtp82NYsG/D6gpszu+Nl6ddE2Sy15qb2vMigb7ZZDg== X-Google-Smtp-Source: ABdhPJwiPjSm+JOHwZBBmbAemlk6I7J45C87EFMTPGzCqw3S2jslS3d23j4ZeFqYGiJaC4Pao8Bifj5DBOPCoVLZemY= X-Received: by 2002:ac2:5f07:: with SMTP id 7mr6394916lfq.313.1617301839771; Thu, 01 Apr 2021 11:30:39 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Thu, 1 Apr 2021 13:30:28 -0500 Message-ID: Subject: [PATCH][CIFS] Insert and Collapse range To: CIFS Cc: samba-technical , linux-fsdevel Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Updated version of Ronnie's patch for FALLOC_FL_INSERT_RANGE and FALLOC_FL_COLLAPSE_RANGE attached (cleaned up the two redundant length checks noticed out by Aurelien, and fixed the endian check warnings pointed out by sparse). They fix at least six xfstests (but still more xfstests to work through that seem to have other new feature dependencies beyond fcollapse) # ./check -cifs generic/072 generic/145 generic/147 generic/153 generic/351 generic/458 FSTYP -- cifs PLATFORM -- Linux/x86_64 smfrench-Virtual-Machine 5.12.0-051200rc4-generic #202103212230 SMP Sun Mar 21 22:33:27 UTC 2021 generic/072 7s ... 6s generic/145 0s ... 1s generic/147 1s ... 0s generic/153 0s ... 1s generic/351 5s ... 3s generic/458 1s ... 1s Ran: generic/072 generic/145 generic/147 generic/153 generic/351 generic/458 Passed all 6 tests From e3cdd1c943e65c391af36f573599b69dde80fcb0 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 27 Mar 2021 06:31:30 +1000 Subject: [PATCH 2/2] cifs: add FALLOC_FL_INSERT_RANGE support Emulated via server side copy and setsize for SMB3 and later. In the future we could compound this (and/or optionally use DUPLICATE_EXTENTS if supported by the server). Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French --- fs/cifs/smb2ops.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index c6a49c31dc0e..4837ac9b4837 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3685,6 +3685,44 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, return rc; } +static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, + loff_t off, loff_t len) +{ + int rc; + unsigned int xid; + struct cifsFileInfo *cfile = file->private_data; + __le64 eof; + __u64 count; + + xid = get_xid(); + + if (off >= i_size_read(file->f_inode)) { + rc = -EINVAL; + goto out; + } + + count = i_size_read(file->f_inode) - off; + eof = cpu_to_le64(i_size_read(file->f_inode) + len); + + rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, &eof); + if (rc < 0) + goto out; + + rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len); + if (rc < 0) + goto out; + + rc = smb3_zero_range(file, tcon, off, len, 1); + if (rc < 0) + goto out; + + rc = 0; + out: + free_xid(xid); + return rc; +} + static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence) { struct cifsFileInfo *wrcfile, *cfile = file->private_data; @@ -3858,6 +3896,8 @@ static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, return smb3_simple_falloc(file, tcon, off, len, true); else if (mode == FALLOC_FL_COLLAPSE_RANGE) return smb3_collapse_range(file, tcon, off, len); + else if (mode == FALLOC_FL_INSERT_RANGE) + return smb3_insert_range(file, tcon, off, len); else if (mode == 0) return smb3_simple_falloc(file, tcon, off, len, false); -- 2.27.0