From patchwork Fri Oct 19 15:28:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68631181D for ; Fri, 19 Oct 2018 15:29:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5670127F91 for ; Fri, 19 Oct 2018 15:29:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A8AB27F94; Fri, 19 Oct 2018 15:29:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C09D827F92 for ; Fri, 19 Oct 2018 15:29:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726465AbeJSXfq (ORCPT ); Fri, 19 Oct 2018 19:35:46 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:43079 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbeJSXfq (ORCPT ); Fri, 19 Oct 2018 19:35:46 -0400 Received: by mail-qt1-f194.google.com with SMTP id q41-v6so38695741qtq.10 for ; Fri, 19 Oct 2018 08:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JqSlx0NJttEt8iloB2oDoUtvtoMN/yM9tZtN1x5I2ls=; b=LVhwN7vRPy6T8BSSpR5eDTKQvbxUa+sRl+DgK0Eb41vQ2N9HKC9RX8sIVdWaX26ORX Wv/NmiYl7Zw5bNpwxxWQjLb7KQ9wWZIas8h68kkumcbhBKpC48pTrc8jnUTfOcqAevO8 5SGgC96PUPCG2JiGPTjM2YIrRWBWZHI6eTA1oFInTg7k4vs7NIL+rFul2nKcPKPBAOIa Zp4yAcNWN4iGtF8jCfCcHBHIO45CRthb8gDwjF/WQ7K18wzVkxEkmvO6PG8ijPZ70fLq KgurJqegi7k7XASQTaIcQBOI9aHlwQ7RJR1CGlBSK/yObxmbm0kZ2U2PaJAj6BueOSrj SG6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JqSlx0NJttEt8iloB2oDoUtvtoMN/yM9tZtN1x5I2ls=; b=SwnFLmovwuf0xAWvHDlmU4TRY95ajLCkaasSSGKp1ho36JX3v9Djak+kTMhIP6JW4J ikYW5miWYw+cOg17s+n6/Wz8zsa50OobP3H4CNoi5yZN+0DJisxPA250qYjVZyCrAcVh sdFPLKGVKUTKi/fmyYVcfEzGsGMphnIdrSI7xUFnRoxCMou8fzj5GmQ2IoyJslfccA4o 4H4vDX9RFXmXzUm+J0UoV18dY5axfCvqav4pNahZKdzmBlaEKz8Hzbi7iOQQMxlP8Cdf FK8gL6qGhMHF5VfHbQ/h+LQ7OqsUvUcT6B5ETBnp97vtXjiPR96toyM2iHMpypV/di8A h3VA== X-Gm-Message-State: ABuFfohLjk4u08DkBDeg2XLuhqGwrjOgFbkFM+2XJDZa6YtJo0nZU5j6 LFFg6YPG5LqymxbmkkvBA+4= X-Google-Smtp-Source: ACcGV61qnqYUmkASvc7DiX6fHfMkAuTLZhaQjUxmT25pjrVY/EKXiWbt1fEjMcqqQBj932zxb9pcyA== X-Received: by 2002:a0c:e70f:: with SMTP id d15mr16216118qvn.221.1539962951010; Fri, 19 Oct 2018 08:29:11 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.09 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:10 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 01/13] fs: Don't copy beyond the end of the file Date: Fri, 19 Oct 2018 11:28:53 -0400 Message-Id: <20181019152905.32418-2-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Anna Schumaker Signed-off-by: Anna Schumaker --- fs/read_write.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/read_write.c b/fs/read_write.c index 39b4a21..c60790f 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1570,6 +1570,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, if (unlikely(ret)) return ret; + if (pos_in >= i_size_read(inode_in)) + return -EINVAL; + if (!(file_in->f_mode & FMODE_READ) || !(file_out->f_mode & FMODE_WRITE) || (file_out->f_flags & O_APPEND)) From patchwork Fri Oct 19 15:28:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA96E109C for ; Fri, 19 Oct 2018 15:29:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B81B327F91 for ; Fri, 19 Oct 2018 15:29:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC6D427F93; Fri, 19 Oct 2018 15:29:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47D5427F92 for ; Fri, 19 Oct 2018 15:29:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbeJSXfs (ORCPT ); Fri, 19 Oct 2018 19:35:48 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:45461 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbeJSXfr (ORCPT ); Fri, 19 Oct 2018 19:35:47 -0400 Received: by mail-qt1-f193.google.com with SMTP id e10-v6so38706209qtq.12 for ; Fri, 19 Oct 2018 08:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bwnpzjEJDuRVSD8Zir+yppo6qbIf0giK1d8Vukajepo=; b=i5s/t68eSvLj9151gilP5AnllgIikAKvctPQA8ehTnBAMT2N5rK3RoJ2NAvGRInhuR pN5vbbFvhdAK1LRSmxgoHqNXAkrLRtk9M6LKPLhWH1huBoj+46ZQ3+XeEJjwJg4hmK++ Bvqq1ioS9VquE5jmqNl6fcZqK3+ZVby6AIRFpGyiZNx3FuAlv4q0kzH92sxxCA2DoZmj bt0WhTQCVJHg8HEDZxn7sXAJAid2nbB9HhrbTqNCX22Kq7UAARSzLbjR6xm7yVfijMqF KpcU61o87O0YPG/eTReBblyEzGUbjNUqa2zlG8QN5VMuSs60DnZQ8uIsDDtyahqJmN5T 35hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bwnpzjEJDuRVSD8Zir+yppo6qbIf0giK1d8Vukajepo=; b=P2aY2zeN8L8iAhasnE8Ga0eQVpmKJNgG9Ib/7xFaBXMMH345oZXgCONuiYcAyAtCJR I7xkDn/kfpiCKNvkDbwXKe6PMU0S8QUe1+d8pMTo1Ff32ILG/6gO/96OS/jkdFAhmv9G uZcXwbcgdjYoGzKwdIAGPECtFLAWHeTP3GxU6hGnlrKRaR8nMd77q+8UCcd5l2yiI1/A 4y85pVlWSQd6mi8FnlZXQ4FHF1K0q0gWDzdR/rtK0sD6FLuzLUhIM7eNHqD6mecfC4MW dpVh/75Ta0J6vt7JIpYmtHMh6wXftdL2wkLZbLVtrSP7LCuusWzFzuQ+cQcDIJzJDXG6 7nXA== X-Gm-Message-State: ABuFfoiXzvJw8S80gngkCbPmcVFzh1A7KEP0GuMWkexll0BVxBOFXIYH DXFFpdK/heStdkkp/sx4tzQ= X-Google-Smtp-Source: ACcGV635K8QJfRXDicoLddqD9OykgFv7NZMN4N6b6gRGrOq1VHZbRFt0U+tJQaMDEfGYa1KgwULc9w== X-Received: by 2002:ac8:6ca:: with SMTP id j10-v6mr33390433qth.84.1539962952209; Fri, 19 Oct 2018 08:29:12 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.11 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:11 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 02/13] VFS permit cross device vfs_copy_file_range Date: Fri, 19 Oct 2018 11:28:54 -0400 Message-Id: <20181019152905.32418-3-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Allow copy_file_range to copy between different superblocks but only of the same file system types. This feature was of interest to CIFS as well as NFS. This feature is needed by NFSv4.2 to perform file copy operation on the same server or file copy between different NFSv4.2 servers. If a file system's fileoperations copy_file_range operation prohibits cross-device copies, fall back to do_splice_direct. This would be needed for the NFS (destination) server side implementation of the file copy and currently for CIFS. Besides NFS, there is only 1 implementor of the copy_file_range FS operation -- CIFS. CIFS assumes incoming file descriptors are both CIFS but it will check if they are coming from different servers and return error code to fall back to do_splice_direct. NFS will allow for copies between different NFS servers. Adding to the vfs.txt documentation to explicitly warn about allowing for different superblocks of the same file type to be passed into the copy_file_range for the future users of copy_file_range method. Signed-off-by: Olga Kornievskaia --- Documentation/filesystems/vfs.txt | 4 +++- fs/read_write.c | 13 ++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index a6c6a8a..5e520de 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt @@ -958,7 +958,9 @@ otherwise noted. fallocate: called by the VFS to preallocate blocks or punch a hole. - copy_file_range: called by the copy_file_range(2) system call. + copy_file_range: called by copy_file_range(2) system call. This method + works on two file descriptors that might reside on + different superblocks of the same type of file system. clone_file_range: called by the ioctl(2) system call for FICLONERANGE and FICLONE commands. diff --git a/fs/read_write.c b/fs/read_write.c index c60790f..474e740 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1578,10 +1578,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, (file_out->f_flags & O_APPEND)) return -EBADF; - /* this could be relaxed once a method supports cross-fs copies */ - if (inode_in->i_sb != inode_out->i_sb) - return -EXDEV; - if (len == 0) return 0; @@ -1591,7 +1587,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, * Try cloning first, this is supported by more file systems, and * more efficient if both clone and copy are supported (e.g. NFS). */ - if (file_in->f_op->clone_file_range) { + if (inode_in->i_sb == inode_out->i_sb && + file_in->f_op->clone_file_range) { ret = file_in->f_op->clone_file_range(file_in, pos_in, file_out, pos_out, len); if (ret == 0) { @@ -1600,10 +1597,12 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, } } - if (file_out->f_op->copy_file_range) { + if (file_out->f_op->copy_file_range && + (file_in->f_op->copy_file_range == + file_out->f_op->copy_file_range)) { ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out, pos_out, len, flags); - if (ret != -EOPNOTSUPP) + if (ret != -EOPNOTSUPP && ret != -EXDEV) goto done; } From patchwork Fri Oct 19 15:28:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61924181D for ; Fri, 19 Oct 2018 15:29:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C70827F92 for ; Fri, 19 Oct 2018 15:29:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40C6E27F94; Fri, 19 Oct 2018 15:29:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8F8C27F92 for ; Fri, 19 Oct 2018 15:29:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726837AbeJSXfs (ORCPT ); Fri, 19 Oct 2018 19:35:48 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:42717 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbeJSXfs (ORCPT ); Fri, 19 Oct 2018 19:35:48 -0400 Received: by mail-qt1-f196.google.com with SMTP id j46-v6so38706675qtc.9 for ; Fri, 19 Oct 2018 08:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MFrexHXO7yQY1QRrDlhjfVTvrBtGmp73ZTx4Rn7FdtQ=; b=Rr2Lb0dLGxe4BIJnpD9QXhFqTqkEJPO/QvQOLGY1br/ignrmigle084TkchYRaCUVP b8nSnZkx3md/kbYuyY/MSdaFB7icCi9qBqtS5+49KbCdSEnOBnlkqODz2M5ynJD2E+Oz NV1Kxu4thZjpfZ421o8cRevuN0tHnOMZaXdARgVNAESQOZH/tXO+USo1bdUeDDEyIADj WGDykgABlz5rCARgiwOLsFel9b7Z7YDebJmyHTmtB6c2jvHmLw0kgytyYx5NBs5Olv1p xBgn4fHjfaFG2IRasXcxjp/avZtXtGbZoF6kKrrN6CrmtcsiCp6sYtodB3EduV+FttpI JbfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MFrexHXO7yQY1QRrDlhjfVTvrBtGmp73ZTx4Rn7FdtQ=; b=FL8niU6W7U5hgSXrU+MC6uJVbRJeAz1W5umiedsdrKN70a+WprEFcBK9xdXLtklfy+ Be5L1o15nFg/4Gy4Av/9JXtA6NJDbWCvVJJ4O6vzGnMeSofnmXbuu3hc/eENU7cZRbAt bwcAdItLe/2XOh577Y8ZJUpdSo4AOUL3pl6zvGeQU9iAyX/zKVa595QmtCWBtQOd0Yqx cncD4sZAq3FLBdG3lFp4Lckxuvm/YhYo/o6Xh4dY/KMlH3SBSRiNpH1v5C3I6tBJRgej cFYoL1UDp//unWun0i5YXjhqFU3s3jbwHQr1FkBCzoIpjHdVJRfwu0UmvSuRbxWH2l+O CjWg== X-Gm-Message-State: ABuFfojTqORQq5SDV+zqRyvVuoBoKlxm2N6AIgLreXjmG4irG/fO8Kpj kGgMt3WgRCvMyyQcl9HJvDgaYTSK X-Google-Smtp-Source: ACcGV612wQmkgwiV/EKNU7zQCy1y35VPRU0BR2udtHeAmVAWP+DN+iqW2S2n2+a14h+jwCn9p2ONYA== X-Received: by 2002:a0c:b751:: with SMTP id q17-v6mr33909667qve.145.1539962953284; Fri, 19 Oct 2018 08:29:13 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.12 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:12 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 03/13] NFS NFSD defining nl4_servers structure needed by both Date: Fri, 19 Oct 2018 11:28:55 -0400 Message-Id: <20181019152905.32418-4-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia These structures are needed by COPY_NOTIFY on the client and needed by the nfsd as well Signed-off-by: Olga Kornievskaia --- include/linux/nfs4.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 1b06f0b..4d76f87 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -16,6 +16,7 @@ #include #include #include +#include enum nfs4_acl_whotype { NFS4_ACL_WHO_NAMED = 0, @@ -672,4 +673,27 @@ struct nfs4_op_map { } u; }; +struct nfs42_netaddr { + char netid[RPCBIND_MAXNETIDLEN]; + char addr[RPCBIND_MAXUADDRLEN + 1]; + u32 netid_len; + u32 addr_len; +}; + +enum netloc_type4 { + NL4_NAME = 1, + NL4_URL = 2, + NL4_NETADDR = 3, +}; + +struct nl4_server { + enum netloc_type4 nl4_type; + union { + struct { /* NL4_NAME, NL4_URL */ + int nl4_str_sz; + char nl4_str[NFS4_OPAQUE_LIMIT + 1]; + }; + struct nfs42_netaddr nl4_addr; /* NL4_NETADDR */ + } u; +}; #endif From patchwork Fri Oct 19 15:28:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DB9C109C for ; Fri, 19 Oct 2018 15:29:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BAF127F91 for ; Fri, 19 Oct 2018 15:29:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6041927F93; Fri, 19 Oct 2018 15:29:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D104627F91 for ; Fri, 19 Oct 2018 15:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726967AbeJSXfu (ORCPT ); Fri, 19 Oct 2018 19:35:50 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:35184 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbeJSXfu (ORCPT ); Fri, 19 Oct 2018 19:35:50 -0400 Received: by mail-qt1-f196.google.com with SMTP id k3-v6so2851133qth.2 for ; Fri, 19 Oct 2018 08:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8vyS0tJdmKwZglRx09vs+0TrMcx5do5CSA1Ips36QEg=; b=D4AtrdV/bF5RjxXC+5br7ug0CuW9GNxJYmSwxuqZq77ToI9+o8TFA9na2rX5ih6NWH QLEVTJ00Xal6Jw7Q4JLeDRHjWkYgv+EvQ9SgKy7EruiaA2krIpbVALHOyBzQfeM6c6Tu CTpLjjfb4zJiq4Mlqvu+QSJfLdyxK36Zof13TRIFMdsGDmUFvVhELSdOGI9iiK4kX+MG 6Dck/sD5tPjx5x8jbSws1dJG61rJRFWvLuheXaDvE6Ze0drnLPlwvo/AijwHoqmtVlp8 R+x4+BTkK32/f9JOMQXhwG29sAVodPL2KA+WwSmbLpU58icuv1JWaF1ARTt5Jmxe2zqi FFpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8vyS0tJdmKwZglRx09vs+0TrMcx5do5CSA1Ips36QEg=; b=jWuCdDcHxQVYNPu6TOj/5NmuUBMr372fX/bti8drUKIRpB1MxlGWfEUE3cnyz2GJ6l ZFjy59hPg4jINt4xRdFEHoc/LP/ycFN3S02nP2F2ZDKm17T71cGIghQwlKgFVq+m9K6w cIHPxB3WZNAxjmNQpYS/OxfkKGzKMlo4QPoDXxcWQWnGXLNV9Wny7LW9rz6l62EVYw8Y qgDn2raB4LzReaK+Kae+fHI6kbVID/d4WkhrTX4G0ooG253VndKmNX3ZlYP0Tj3xgAab ZrBYJ8qaSVWMjobD4/uUJ2Owa0bCIPmh03ipap47xnsGSFJhaDk/28vWtk7aLnYchnxZ 6oUQ== X-Gm-Message-State: ABuFfogolM5Vk/xJ2ERPqovAGY3eSE18gOOq02QUjS+1mbIaBZ+9AbVC JVL5D2Lers1ktwsNdhz3VDhuDaKo X-Google-Smtp-Source: ACcGV63EBp0WBrPVt3rbq0guhyfXtQ5bSTUVhhvmolAZoJWP3DT/ECSCpACHH2jH6L+z7fCUg/UZFA== X-Received: by 2002:a0c:98d1:: with SMTP id g17-v6mr34768711qvd.13.1539962954642; Fri, 19 Oct 2018 08:29:14 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.13 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:13 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 04/13] NFS inter ssc open Date: Fri, 19 Oct 2018 11:28:56 -0400 Message-Id: <20181019152905.32418-5-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia NFSv4.2 inter server to server copy requires the destination server to READ the data from the source server using the provided stateid and file handle. Given an NFSv4 stateid and filehandle from the COPY operaion, provide the destination server with an NFS client function to create a struct file suitable for the destiniation server to READ the data to be copied. Signed-off-by: Andy Adamson Signed-off-by: Olga Kornievskaia --- fs/nfs/nfs4_fs.h | 7 ++++ fs/nfs/nfs4file.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 5 ++- 3 files changed, 107 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 8d59c96..f229864 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -307,6 +307,13 @@ extern int nfs4_set_rw_stateid(nfs4_stateid *stateid, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, fmode_t fmode); +extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, + struct nfs_fattr *fattr, struct nfs4_label *label, + struct inode *inode); +extern int update_open_stateid(struct nfs4_state *state, + const nfs4_stateid *open_stateid, + const nfs4_stateid *deleg_stateid, + fmode_t fmode); #if defined(CONFIG_NFS_V4_1) extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *); diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 4288a6e..f82cb05 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "delegation.h" #include "internal.h" #include "iostat.h" @@ -242,6 +243,103 @@ static int nfs42_clone_file_range(struct file *src_file, loff_t src_off, out: return ret; } + +static int read_name_gen = 1; +#define SSC_READ_NAME_BODY "ssc_read_%d" + +struct file * +nfs42_ssc_open(struct vfsmount *ss_mnt, struct nfs_fh *src_fh, + nfs4_stateid *stateid) +{ + struct nfs_fattr fattr; + struct file *filep, *res; + struct nfs_server *server; + struct inode *r_ino = NULL; + struct nfs_open_context *ctx; + struct nfs4_state_owner *sp; + char *read_name; + int len, status = 0; + + server = NFS_SERVER(ss_mnt->mnt_root->d_inode); + + nfs_fattr_init(&fattr); + + status = nfs4_proc_getattr(server, src_fh, &fattr, NULL, NULL); + if (status < 0) { + res = ERR_PTR(status); + goto out; + } + + res = ERR_PTR(-ENOMEM); + len = strlen(SSC_READ_NAME_BODY) + 16; + read_name = kzalloc(len, GFP_NOFS); + if (read_name == NULL) + goto out; + snprintf(read_name, len, SSC_READ_NAME_BODY, read_name_gen++); + dprintk("%s read_name %s\n", __func__, read_name); + + r_ino = nfs_fhget(ss_mnt->mnt_root->d_inode->i_sb, src_fh, &fattr, + NULL); + if (IS_ERR(r_ino)) { + res = ERR_CAST(r_ino); + goto out; + } + + filep = alloc_file_pseudo(r_ino, ss_mnt, read_name, FMODE_READ, + r_ino->i_fop); + if (IS_ERR(filep)) { + res = ERR_CAST(filep); + goto out; + } + filep->f_mode |= FMODE_READ; + + ctx = alloc_nfs_open_context(filep->f_path.dentry, filep->f_mode, + filep); + if (IS_ERR(ctx)) { + res = ERR_CAST(ctx); + goto out_filep; + } + + res = ERR_PTR(-EINVAL); + sp = nfs4_get_state_owner(server, ctx->cred, GFP_KERNEL); + if (sp == NULL) + goto out_ctx; + + ctx->state = nfs4_get_open_state(r_ino, sp); + if (ctx->state == NULL) + goto out_stateowner; + + set_bit(NFS_OPEN_STATE, &ctx->state->flags); + memcpy(&ctx->state->open_stateid.other, &stateid->other, + NFS4_STATEID_OTHER_SIZE); + update_open_stateid(ctx->state, stateid, NULL, filep->f_mode); + + nfs_file_set_open_context(filep, ctx); + put_nfs_open_context(ctx); + + file_ra_state_init(&filep->f_ra, filep->f_mapping->host->i_mapping); + res = filep; +out: + dprintk("<-- %s error %ld filep %p r_ino %p\n", + __func__, IS_ERR(res) ? PTR_ERR(res) : 0, res, r_ino); + + return res; +out_stateowner: + nfs4_put_state_owner(sp); +out_ctx: + put_nfs_open_context(ctx); +out_filep: + fput(filep); + goto out; +} +EXPORT_SYMBOL_GPL(nfs42_ssc_open); +void nfs42_ssc_close(struct file *filep) +{ + struct nfs_open_context *ctx = nfs_file_open_context(filep); + + ctx->state->flags = 0; +} +EXPORT_SYMBOL_GPL(nfs42_ssc_close); #endif /* CONFIG_NFS_V4_2 */ const struct file_operations nfs4_file_operations = { diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index db84b4a..1876456 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -91,7 +91,6 @@ static int _nfs4_recover_proc_open(struct nfs4_opendata *data); static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); -static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode); static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, struct nfs_fattr *fattr, struct iattr *sattr, @@ -1653,7 +1652,7 @@ static void nfs_state_clear_delegation(struct nfs4_state *state) write_sequnlock(&state->seqlock); } -static int update_open_stateid(struct nfs4_state *state, +int update_open_stateid(struct nfs4_state *state, const nfs4_stateid *open_stateid, const nfs4_stateid *delegation, fmode_t fmode) @@ -3936,7 +3935,7 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); } -static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, +int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode) { From patchwork Fri Oct 19 15:28:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E5E8181D for ; Fri, 19 Oct 2018 15:29:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D04027F92 for ; Fri, 19 Oct 2018 15:29:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7170727F94; Fri, 19 Oct 2018 15:29:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EF4F27F92 for ; Fri, 19 Oct 2018 15:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726976AbeJSXfv (ORCPT ); Fri, 19 Oct 2018 19:35:51 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:34556 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbeJSXfv (ORCPT ); Fri, 19 Oct 2018 19:35:51 -0400 Received: by mail-qk1-f194.google.com with SMTP id p6-v6so21260913qkg.1 for ; Fri, 19 Oct 2018 08:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AGZgyO5kJh0DiSIodRJJI3pe7WoZ/7FHwbOJ1hIFN+k=; b=ZS/oRth7iXqoX351JDVRqZWpOX4lvOBoBSamqIsNWHFtd/bL/s3L26bleRYcBAHirg /Rb/iDUWX36B0BwlDdJfP6CRFoFo1c/93AE95dL/34Czg1Guuw6KB0mH+K4EJCgC6pbD +hte0YHZ7ATLMxV52S5O7gGwXv4j9Dc+i1zhoaVHISusK3E3RWFaOP/YOiDPd/roSogk SXJQaRIgWzjFQeJXttSUeI5/Kobq/QId/81JOJEeSg1r1ELpcAwboomUWfUpFL+4Oo53 03QYKjyzHh7Sl9NE3GiUMSNVCtcohF+b4uvk2XEFG6rYStAoBRIFgwz1Di/cRqzzAvqx nZIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AGZgyO5kJh0DiSIodRJJI3pe7WoZ/7FHwbOJ1hIFN+k=; b=CKV3W81kmcQYlKLkRJjxQgCHGGnbnY5lLq9UWb73nIJ9KWrU4N80aMYoIKFfpNUi69 VdFR5qJ6f/r6E/7dhJqD0Quvo8T8IoaCFnBE6Q5vmSJEDGMrg3Or4Xa+U0DnVYLUyHdT dCrZZWViPilnH4WBA/FnjkFLse/CO98XR+qOS7xXHfeCiik0kyJTau2Gxh0vMuirDpml 7xeS6nWO/2PSiK/rHs17mN1uxhUt6q6CS45jWOqkBIIMnlOWkggO8YNs3//kBpohkqoY I7r7AeoKKMAl6ayO9UXLsQEDV7ho3CY0GmDgwZjp1ThFgM50TpwiuakTrI4qD2px0L4O XGNQ== X-Gm-Message-State: ABuFfojgYy4MSJgTjtvgFRljCApWaVoqEXPTBOPCFDiclv3f/oEpTmh4 xFhudizcAUsvykqtPsgQcLE= X-Google-Smtp-Source: ACcGV637/Pb2kgbVxK+u6amD5bVOzyl0NhF1rvhpIEtKjMFbgEujPe0Y2tbpNw88w7FzlOHSgfDukw== X-Received: by 2002:a37:1025:: with SMTP id a37-v6mr11808413qkh.299.1539962955736; Fri, 19 Oct 2018 08:29:15 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:15 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 05/13] NFS skip recovery of copy open on dest server Date: Fri, 19 Oct 2018 11:28:57 -0400 Message-Id: <20181019152905.32418-6-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Mark the open created for the source file on the destination server. Then if this open is going thru a recovery, then fail the recovery as we don't need to be recoving a "fake" open. We need to fail the ongoing READs and vfs_copy_file_range(). Signed-off-by: Olga Kornievskaia --- fs/nfs/nfs4_fs.h | 1 + fs/nfs/nfs4file.c | 1 + fs/nfs/nfs4state.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index f229864..8b00c90 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -165,6 +165,7 @@ enum { NFS_STATE_CHANGE_WAIT, /* A state changing operation is outstanding */ #ifdef CONFIG_NFS_V4_2 NFS_CLNT_DST_SSC_COPY_STATE, /* dst server open state on client*/ + NFS_SRV_SSC_COPY_STATE, /* ssc state on the dst server */ #endif /* CONFIG_NFS_V4_2 */ }; diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index f82cb05..7909cd4 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -309,6 +309,7 @@ struct file * if (ctx->state == NULL) goto out_stateowner; + set_bit(NFS_SRV_SSC_COPY_STATE, &ctx->state->flags); set_bit(NFS_OPEN_STATE, &ctx->state->flags); memcpy(&ctx->state->open_stateid.other, &stateid->other, NFS4_STATEID_OTHER_SIZE); diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 62ae0fd..b0b82c6 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1606,6 +1606,9 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs { struct nfs4_state *state; int status = 0; +#ifdef CONFIG_NFS_V4_2 + bool found_ssc_copy_state = false; +#endif /* CONFIG_NFS_V4_2 */ /* Note: we rely on the sp->so_states list being ordered * so that we always reclaim open(O_RDWR) and/or open(O_WRITE) @@ -1625,6 +1628,13 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs continue; if (state->state == 0) continue; +#ifdef CONFIG_NFS_V4_2 + if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) { + nfs4_state_mark_recovery_failed(state, -EIO); + found_ssc_copy_state = true; + continue; + } +#endif /* CONFIG_NFS_V4_2 */ refcount_inc(&state->count); spin_unlock(&sp->so_lock); status = __nfs4_reclaim_open_state(sp, state, ops); @@ -1671,6 +1681,10 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs } raw_write_seqcount_end(&sp->so_reclaim_seqcount); spin_unlock(&sp->so_lock); +#ifdef CONFIG_NFS_V4_2 + if (found_ssc_copy_state) + return -EIO; +#endif /* CONFIG_NFS_V4_2 */ return 0; out_err: nfs4_put_open_state(state); From patchwork Fri Oct 19 15:28:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC87B13A4 for ; Fri, 19 Oct 2018 15:29:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBFF627F91 for ; Fri, 19 Oct 2018 15:29:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0D4D27F93; Fri, 19 Oct 2018 15:29:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D3E827F91 for ; Fri, 19 Oct 2018 15:29:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbeJSXfx (ORCPT ); Fri, 19 Oct 2018 19:35:53 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:34558 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbeJSXfx (ORCPT ); Fri, 19 Oct 2018 19:35:53 -0400 Received: by mail-qk1-f194.google.com with SMTP id p6-v6so21260959qkg.1 for ; Fri, 19 Oct 2018 08:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7tGBnP9OD4IAqnLT64l4YNG1h5aS0qzF9cvZEfBXrBM=; b=Am/YRM4hRwlFOEGdAJaYdaJQ5iArh9gsWiPaf47jsYVIb3rI8yxjc7aphk4aW1dr4m uYSvZw1c3FpJ2POiEzz0dEjxo5gpcDfTapaKie8EndYLoL9+noBwTbyt0AtyccOxiNmk bpIcAUH3KdQVz3iaP/kjGbClhcsC0MxEWRnuyiWzSfVNf8RLO/GVaYfzSZXow1iQApDp dFx1n3u4U2waF+CQRMXyN85I7Kbr6BA5op2T1WlZscgll++XAR6C0TL1FqvwJynIW5E9 KGX1mFQc9AeEORJTciaM45p38rzDriXsItr4TTBPMxHYgwfLLoQkiVwSmIaMp7C9UaYZ ySXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7tGBnP9OD4IAqnLT64l4YNG1h5aS0qzF9cvZEfBXrBM=; b=h7GgiPimM/J4dtrxgw1/REtOCkm50E+CCRz14peKlVwO6DNf1Shm8A+3NWo6nHO0JR NCr7po6peGKCuZZYL03rVQGU0vFWVf+T4OkdVWZHk/4S9vyJeZEPak1x+27/Q1gQr9cI ZNLUigFrnAD6jews1oQCAWOq5Mng0IXlaf6Z3PHd/RTez+ql41MZv5k1YvABFkN+d56u RdGVYwrG/j3Ihr5oPoB6H+R/aOS6xkwEaKvVazwwhNxd3Lbk9X/k/9xTU0Q+aB7BoJv8 eKk8lL9SlMIU2/G7DwddN4LfyNBV1lukNNwYATHfFOsUoHDyIE3mbyUCLLBCM9R86oCZ JayQ== X-Gm-Message-State: ABuFfojze2nBFSgViopTZp3EXDUlu6MDbRroLSC1wGzyAYDfgB0s4JRi xk/6V25Y6dj/RjY+6Dt09YbURMWg X-Google-Smtp-Source: ACcGV61t7GYeQvUXG22QMGZTbB6oJslvv/JQNZXNtQ9z1v6xen6tuMBvRh9vUEpBewMpC1nw7CFDYw== X-Received: by 2002:a37:31cf:: with SMTP id x198-v6mr33047296qkx.206.1539962957191; Fri, 19 Oct 2018 08:29:17 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.15 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:16 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 06/13] NFSD fill-in netloc4 structure Date: Fri, 19 Oct 2018 11:28:58 -0400 Message-Id: <20181019152905.32418-7-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia nfs.4 defines nfs42_netaddr structure that represents netloc4. Populate needed fields from the sockaddr structure. This will be used by flexfiles and 4.2 inter copy Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfsd.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 0668999..030fccb 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -18,7 +18,7 @@ #include #include #include - +#include #include #include "stats.h" @@ -366,6 +366,35 @@ static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) extern const u32 nfsd_suppattrs[3][3]; +static inline u32 nfsd4_set_netaddr(struct sockaddr *addr, struct nfs42_netaddr *netaddr) +{ + struct sockaddr_in *sin = (struct sockaddr_in *)addr; + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; + unsigned int port; + size_t ret; + + switch (addr->sa_family) { + case AF_INET: + port = ntohs(sin->sin_port); + sprintf(netaddr->netid, "tcp"); + netaddr->netid_len = 3; + break; + case AF_INET6: + port = ntohs(sin6->sin6_port); + sprintf(netaddr->netid, "tcp6"); + netaddr->netid_len = 4; + break; + default: + return nfserrno(-EINVAL); + } + ret = rpc_ntop(addr, netaddr->addr, sizeof(netaddr->addr)); + netaddr->addr_len = ret + snprintf(netaddr->addr + ret, + RPCBIND_MAXUADDRLEN + 1, + ".%u.%u", port >> 8, port & 0xff); + + return 0; +} + static inline bool bmval_is_subset(const u32 *bm1, const u32 *bm2) { return !((bm1[0] & ~bm2[0]) || From patchwork Fri Oct 19 15:28:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D027613A4 for ; Fri, 19 Oct 2018 15:29:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF6D027F91 for ; Fri, 19 Oct 2018 15:29:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B408127F93; Fri, 19 Oct 2018 15:29:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E18627F91 for ; Fri, 19 Oct 2018 15:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbeJSXfy (ORCPT ); Fri, 19 Oct 2018 19:35:54 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:38499 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbeJSXfy (ORCPT ); Fri, 19 Oct 2018 19:35:54 -0400 Received: by mail-qt1-f196.google.com with SMTP id r22-v6so2160861qtm.5 for ; Fri, 19 Oct 2018 08:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MrfWI83dwuk5+P+ddPcjUo36DVq3EA6UNLgnKcNNlp4=; b=gKY1oFUewysSapgccbhu/6fKIWFeEeQCs/7SQ87ebCh1+nqERJLmPrSNEZ6VL0tGbp lz/xAtH/ZOW65YuoCEKICwsm0mwTSkkuGKMGLKExuLbzR5DNc7aDWI3RkAQEq5A/5+mm PLu62k9UwSE/4ZRsYVlRitp2IFgbvuS2hg9TGHlXUC+TnsYPTVc0dDmW6ob0wck2urtT HtorXQOil14qPiK4iM1yzi5G/xlB1ck2Vz2sResVm+s+UMPMbYZMfudhkZ65lQn9/AhP whErE0/iQmGpxB21uTZhymMV7+I/sJtJ2F3Ps1S1nyRX13GpFsGDIKLsDmul+OBJr1k5 dqgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MrfWI83dwuk5+P+ddPcjUo36DVq3EA6UNLgnKcNNlp4=; b=tg7KpS6nY8M0Jyt7dGnUEhpGmOahlnhyIhT80YcgjcxMuwuRuPD/cNu7diMyk5CWm3 PFItXd5XRs1cjlmWACUaa0snY1QtaIWDLGtsVID2tf9MwJxD4Ke74AFvQvB/5Xue5Ybo mhJgEiu+tiHuF3kFv5o4x+a+3MQYwldDrHyTLcVM7nZhKkJIQPRAx8Snj8EyOZCVddbC zKPbIXxu3A1660ct1pBv1mGTY+8dTka7lzd/ubKtB+Hgb7eHnL7SGu2vaqvZsOqLEbiO T8y5GuTWZVhOmAZiUC74Uly43NoekZlqjqebyr9lGApFpGp9oCfmEahZe876pDoLz1mC qxwQ== X-Gm-Message-State: ABuFfohxk7SsGpi1dIFkjj/eladJd7v5CarvF55VyjDjVWMeCfTyU3FF MMzZWBmq8UU9rW7rotxM9wM= X-Google-Smtp-Source: ACcGV61QD5b6CiR1j9pzANsbz1GoCVapVxGZF+ObszlE4TKxUkCAy2f1AxWZKX5ktvIPWin8E0czIQ== X-Received: by 2002:a0c:ac87:: with SMTP id m7mr30181334qvc.112.1539962958453; Fri, 19 Oct 2018 08:29:18 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.17 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:17 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 07/13] NFSD add ca_source_server<> to COPY Date: Fri, 19 Oct 2018 11:28:59 -0400 Message-Id: <20181019152905.32418-8-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Note: followed conventions and have struct nfsd4_compoundargs pointer as a parameter even though it is unused. Signed-off-by: Andy Adamson Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfs4xdr.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/nfsd/xdr4.h | 1 + 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 3de42a7..9f6886f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "idmap.h" #include "acl.h" @@ -1743,11 +1744,58 @@ static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, str DECODE_TAIL; } +static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, + struct nl4_server *ns) +{ + DECODE_HEAD; + struct nfs42_netaddr *naddr; + + READ_BUF(4); + ns->nl4_type = be32_to_cpup(p++); + + /* currently support for 1 inter-server source server */ + switch (ns->nl4_type) { + case NL4_NAME: + case NL4_URL: + READ_BUF(4); + ns->u.nl4_str_sz = be32_to_cpup(p++); + if (ns->u.nl4_str_sz > NFS4_OPAQUE_LIMIT) + goto xdr_error; + + READ_BUF(ns->u.nl4_str_sz); + COPYMEM(ns->u.nl4_str, + ns->u.nl4_str_sz); + break; + case NL4_NETADDR: + naddr = &ns->u.nl4_addr; + + READ_BUF(4); + naddr->netid_len = be32_to_cpup(p++); + if (naddr->netid_len > RPCBIND_MAXNETIDLEN) + goto xdr_error; + + READ_BUF(naddr->netid_len + 4); /* 4 for uaddr len */ + COPYMEM(naddr->netid, naddr->netid_len); + + naddr->addr_len = be32_to_cpup(p++); + if (naddr->addr_len > RPCBIND_MAXUADDRLEN) + goto xdr_error; + + READ_BUF(naddr->addr_len); + COPYMEM(naddr->addr, naddr->addr_len); + break; + default: + goto xdr_error; + } + DECODE_TAIL; +} + static __be32 nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) { DECODE_HEAD; - unsigned int tmp; + struct nl4_server *ns; + int i, count; status = nfsd4_decode_stateid(argp, ©->cp_src_stateid); if (status) @@ -1762,8 +1810,24 @@ static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, str p = xdr_decode_hyper(p, ©->cp_count); p++; /* ca_consecutive: we always do consecutive copies */ copy->cp_synchronous = be32_to_cpup(p++); - tmp = be32_to_cpup(p); /* Source server list not supported */ + count = be32_to_cpup(p++); + + if (count == 0) /* intra-server copy */ + goto intra; + /* decode all the supplied server addresses but use first */ + copy->cp_src = kmalloc(count * sizeof(struct nl4_server), GFP_KERNEL); + if (copy->cp_src == NULL) + return nfserrno(-ENOMEM); + + ns = copy->cp_src; + for (i = 0; i < count; i++) { + status = nfsd4_decode_nl4_server(argp, ns); + if (status) + return status; + ns++; + } +intra: DECODE_TAIL; } @@ -4273,6 +4337,9 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, p = xdr_reserve_space(&resp->xdr, 4 + 4); *p++ = xdr_one; /* cr_consecutive */ *p++ = cpu_to_be32(copy->cp_synchronous); + + /* allocated in nfsd4_decode_copy */ + kfree(copy->cp_src); return 0; } diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index feeb6d4..b4d1140 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -521,6 +521,7 @@ struct nfsd4_copy { u64 cp_src_pos; u64 cp_dst_pos; u64 cp_count; + struct nl4_server *cp_src; /* both */ bool cp_synchronous; From patchwork Fri Oct 19 15:29:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEA32109C for ; Fri, 19 Oct 2018 15:29:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD59C27F91 for ; Fri, 19 Oct 2018 15:29:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1F2D27F93; Fri, 19 Oct 2018 15:29:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F2A727F91 for ; Fri, 19 Oct 2018 15:29:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727042AbeJSXf4 (ORCPT ); Fri, 19 Oct 2018 19:35:56 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:43125 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbeJSXfz (ORCPT ); Fri, 19 Oct 2018 19:35:55 -0400 Received: by mail-qt1-f194.google.com with SMTP id q41-v6so38696470qtq.10 for ; Fri, 19 Oct 2018 08:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pjolo0Ff2Tw7IP3J4z5G/E98C2G22qygthnndgEGDP0=; b=KYG0cacQWyqIIp5BiEJ4v2MnL/p+8jMhwg+n11hv6JtKR2NmzwephSTKoHkmjmWoEF 5ha5EhLZotAP8XLWu9wPkAs77gLblFirkI8Ync8vW452ADh1hpjKZF/K+/N94rGC8Nw3 pFuflvj7+tyySfqmvvOeqzwYol3JVih5+dPYs9n+DOs7xRRGuZxB4IR3is8jZId7tWg8 KeCpMDp2nDiOhJUxu1iZkrRDtaFvUHxBtNZtpQZKEW4ZI9dn32DkoxWNFrpraNJX04Ve UVubeZzEI+vTk1KjkWCDvzjgXRK4I7D/5Gn7GMVtRKtsOK52oh2GiIeDbYd4/FBltiLu Y6CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pjolo0Ff2Tw7IP3J4z5G/E98C2G22qygthnndgEGDP0=; b=k+l6Y6JGKMR1TZpulfJt8JQ93zFKwy/lAznwtsAIoZMde4BVAL9QvbCx/5curEr7TP vq/Oq5og+B+Y10qh4u0mEeWbqIiYJzWzN46bl1D0qXAbdhKwUx7cH41MGc40M43hv+zz ++L5ftBBiYbinKW19mMG62DMxQVG5rSolgPIBq+oAFOFulnJ4/aNeFK0zKxJp1a8VhqR Zf+T2emQkjNP/hGG7MJ7Nmyde3v/4KWP7IM7Z8zzgPkeN1aXfc1Sa2wjtOGrRbjok00V 4akaM0vlcKbDLglKQWBKRB5sl1S7Wvmced27pviDpEGZdcVRc8QoS16U5An4toMkJuOo 0gbg== X-Gm-Message-State: ABuFfogzzKFEutOWhbZ35xOV1qIJnHLuXaGKh3svpR4vVliGOw75KiNS uQk2mCJPpyNGca357cGT4ykWVVWJ X-Google-Smtp-Source: ACcGV63mvSJhOKRcq+VF/spwG/uCc9Yae81LggFCaGx30ymROtBJgJSvMm2Bzi4TvJGf2lirjA+18g== X-Received: by 2002:ac8:17f9:: with SMTP id r54-v6mr33143408qtk.206.1539962960205; Fri, 19 Oct 2018 08:29:20 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.18 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:19 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 08/13] NFSD return nfs4_stid in nfs4_preprocess_stateid_op Date: Fri, 19 Oct 2018 11:29:00 -0400 Message-Id: <20181019152905.32418-9-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Needed for copy to add nfs4_cp_state to the nfs4_stid. Signed-off-by: Andy Adamson Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfs4proc.c | 17 ++++++++++------- fs/nfsd/nfs4state.c | 8 ++++++-- fs/nfsd/state.h | 3 ++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index edff074..29686df 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -781,7 +781,8 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) /* check stateid */ status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, &read->rd_stateid, RD_STATE, - &read->rd_filp, &read->rd_tmp_file); + &read->rd_filp, &read->rd_tmp_file, + NULL); if (status) { dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); goto out; @@ -954,7 +955,7 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, &setattr->sa_stateid, - WR_STATE, NULL, NULL); + WR_STATE, NULL, NULL, NULL); if (status) { dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); return status; @@ -1005,7 +1006,7 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) trace_nfsd_write_start(rqstp, &cstate->current_fh, write->wr_offset, cnt); status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, - stateid, WR_STATE, &filp, NULL); + stateid, WR_STATE, &filp, NULL, NULL); if (status) { dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); return status; @@ -1039,14 +1040,16 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) __be32 status; status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, - src_stateid, RD_STATE, src, NULL); + src_stateid, RD_STATE, src, NULL, + NULL); if (status) { dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); goto out; } status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, - dst_stateid, WR_STATE, dst, NULL); + dst_stateid, WR_STATE, dst, NULL, + NULL); if (status) { dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); goto out_put_src; @@ -1350,7 +1353,7 @@ struct nfsd4_copy * status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, &fallocate->falloc_stateid, - WR_STATE, &file, NULL); + WR_STATE, &file, NULL, NULL); if (status != nfs_ok) { dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); return status; @@ -1409,7 +1412,7 @@ struct nfsd4_copy * status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, &seek->seek_stateid, - RD_STATE, &file, NULL); + RD_STATE, &file, NULL, NULL); if (status) { dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); return status; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 07a57d0..e263fd0 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5159,7 +5159,8 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct svc_fh *fhp, - stateid_t *stateid, int flags, struct file **filpp, bool *tmp_file) + stateid_t *stateid, int flags, struct file **filpp, + bool *tmp_file, struct nfs4_stid **cstid) { struct inode *ino = d_inode(fhp->fh_dentry); struct net *net = SVC_NET(rqstp); @@ -5210,8 +5211,11 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) if (!status && filpp) status = nfs4_check_file(rqstp, fhp, s, filpp, tmp_file, flags); out: - if (s) + if (s) { + if (!status && cstid) + *cstid = s; nfs4_put_stid(s); + } return status; } diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 6aacb32..304de3b 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -606,7 +606,8 @@ struct nfsd4_blocked_lock { extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct svc_fh *fhp, - stateid_t *stateid, int flags, struct file **filp, bool *tmp_file); + stateid_t *stateid, int flags, struct file **filp, + bool *tmp_file, struct nfs4_stid **cstid); __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate, stateid_t *stateid, unsigned char typemask, struct nfs4_stid **s, struct nfsd_net *nn); From patchwork Fri Oct 19 15:29:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C10113A4 for ; Fri, 19 Oct 2018 15:29:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 386F027F91 for ; Fri, 19 Oct 2018 15:29:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CF0B27F98; Fri, 19 Oct 2018 15:29:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A36D27F92 for ; Fri, 19 Oct 2018 15:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbeJSXf6 (ORCPT ); Fri, 19 Oct 2018 19:35:58 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:42593 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbeJSXf5 (ORCPT ); Fri, 19 Oct 2018 19:35:57 -0400 Received: by mail-qk1-f193.google.com with SMTP id u20-v6so6640178qkk.9 for ; Fri, 19 Oct 2018 08:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xcChsMwjUD35C0VKsF49wtOKS+32UPR0EOuTfqE6X3Y=; b=SxZCrGDe5Z2pI1JyZiFikpVca58TBAX4CdPijYeswus3mkbhG988FpwaOyvjQqnpgS iP/DQnM7dpkvz+dyg+gpalfIuBMt58cvbDXKTrOMzOviatTDVbCh+ryuP6ZcH6bgV6Nv q3p1HTEr3sv+u1BtgQZ1bSWFVOKIizifPgHLCLkIt1PUUnWoHVaZrG4p+qMj9wqMGfDc XCTM497txMVvXaobB44wNzFGFBU8A5ehmV5oskhUAlEaV8BN+D7wHwiT5yqur4ytUJHK Hz87RqYusHlBE3/2LbHiQ1KbT5qoryppddbCeaA1Dz5yEumNyPgA+EnXQyiK3qx/WkfL dZig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xcChsMwjUD35C0VKsF49wtOKS+32UPR0EOuTfqE6X3Y=; b=Wsr9pMH+Kf61uLVjRoROR+Xi2TXi8s8Bn/UX1IUSjyjQ8Ea54nXZaigAmdArEFkrqN Gtg0bFwBHPyLN4JFvFbw+uPZfy+xZcwe6B9FSJJmm3E7Ro/N0sLgnC9D1jpcBiIm8SUr 8i4sN24sV5TEFiBUDrApDzgvzD3/M3gIhc0N1N2Q2jl6WRMNX/CKyxfpEJaZHCTCC/PK PKyORsl+cNw/MGfu04n5YOXV7zNpwhybJzRb5J/DoOangZABul6ifo/qyDUd0jycwkSt 4y1HfKQiL59Tf1jFGFVl+q3eF/V3lEtFaVaO2PNR7u1KtBnd0nIBKxrXH/v47lcCS/xL 5isg== X-Gm-Message-State: ABuFfojKf3uCOpttoxwiakSa9ylj21bPWn7hf9Us6vXv5tV8LmrHtIzy j4jIfjnUKUTp6lxzouMGIlcbWuC8 X-Google-Smtp-Source: ACcGV63KPInHeyXqf04oAiBqdlFUmU+ZyBjV38epXcbOMnm9aWXPJXaasLc7+Aa1PnP48LsAvaIFTw== X-Received: by 2002:a37:ec3:: with SMTP id 186-v6mr33148689qko.236.1539962961560; Fri, 19 Oct 2018 08:29:21 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.20 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:20 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 09/13] NFSD add COPY_NOTIFY operation Date: Fri, 19 Oct 2018 11:29:01 -0400 Message-Id: <20181019152905.32418-10-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Introducing the COPY_NOTIFY operation. Create a new unique stateid that will keep track of the copy state and the upcoming READs that will use that stateid. Keep it in the list associated with parent stateid. Return single netaddr to advertise to the copy. Signed-off-by: Andy Adamson Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfs4proc.c | 69 ++++++++++++++++++++++++++++++++++--- fs/nfsd/nfs4state.c | 70 +++++++++++++++++++++++++++++++++----- fs/nfsd/nfs4xdr.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/nfsd/state.h | 15 +++++++++ fs/nfsd/xdr4.h | 13 +++++++ 5 files changed, 250 insertions(+), 14 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 29686df..999c8cb 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "idmap.h" #include "cache.h" @@ -1035,7 +1036,8 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) static __be32 nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stateid_t *src_stateid, struct file **src, - stateid_t *dst_stateid, struct file **dst) + stateid_t *dst_stateid, struct file **dst, + struct nfs4_stid **stid) { __be32 status; @@ -1049,7 +1051,7 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, dst_stateid, WR_STATE, dst, NULL, - NULL); + stid); if (status) { dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); goto out_put_src; @@ -1080,7 +1082,7 @@ static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) __be32 status; status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, - &clone->cl_dst_stateid, &dst); + &clone->cl_dst_stateid, &dst, NULL); if (status) goto out; @@ -1267,7 +1269,7 @@ static int nfsd4_do_async_copy(void *data) status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, ©->file_src, ©->cp_dst_stateid, - ©->file_dst); + ©->file_dst, NULL); if (status) goto out; @@ -1345,6 +1347,44 @@ struct nfsd4_copy * } static __be32 +nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, + union nfsd4_op_u *u) +{ + struct nfsd4_copy_notify *cn = &u->copy_notify; + __be32 status; + struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); + struct nfs4_stid *stid; + struct nfs4_cpntf_state *cps; + + status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, + &cn->cpn_src_stateid, RD_STATE, NULL, + NULL, &stid); + if (status) + return status; + + cn->cpn_sec = nn->nfsd4_lease; + cn->cpn_nsec = 0; + + status = nfserrno(-ENOMEM); + cps = nfs4_alloc_init_cpntf_state(nn, stid); + if (!cps) + return status; + memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid, sizeof(stateid_t)); + + /** + * For now, only return one server address in cpn_src, the + * address used by the client to connect to this server. + */ + cn->cpn_src.nl4_type = NL4_NETADDR; + status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr, + &cn->cpn_src.u.nl4_addr); + if (status != 0) + nfs4_free_cpntf_state(cps); + + return status; +} + +static __be32 nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_fallocate *fallocate, int flags) { @@ -2296,6 +2336,21 @@ static inline u32 nfsd4_offload_status_rsize(struct svc_rqst *rqstp, 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32); } +static inline u32 nfsd4_copy_notify_rsize(struct svc_rqst *rqstp, + struct nfsd4_op *op) +{ + return (op_encode_hdr_size + + 3 /* cnr_lease_time */ + + 1 /* We support one cnr_source_server */ + + 1 /* cnr_stateid seq */ + + op_encode_stateid_maxsz /* cnr_stateid */ + + 1 /* num cnr_source_server*/ + + 1 /* nl4_type */ + + 1 /* nl4 size */ + + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */) + * sizeof(__be32); +} + #ifdef CONFIG_NFSD_PNFS static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) { @@ -2720,6 +2775,12 @@ static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) .op_name = "OP_OFFLOAD_CANCEL", .op_rsize_bop = nfsd4_only_status_rsize, }, + [OP_COPY_NOTIFY] = { + .op_func = nfsd4_copy_notify, + .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, + .op_name = "OP_COPY_NOTIFY", + .op_rsize_bop = nfsd4_copy_notify_rsize, + }, }; /** diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index e263fd0..7764a8b 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -697,6 +697,7 @@ struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *sla /* Will be incremented before return to client: */ refcount_set(&stid->sc_count, 1); spin_lock_init(&stid->sc_lock); + INIT_LIST_HEAD(&stid->sc_cp_list); /* * It shouldn't be a problem to reuse an opaque stateid value. @@ -716,33 +717,85 @@ struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *sla /* * Create a unique stateid_t to represent each COPY. */ -int nfs4_init_cp_state(struct nfsd_net *nn, struct nfsd4_copy *copy) +int _nfs4_init_state(struct nfsd_net *nn, void *ptr, stateid_t *stid) { int new_id; idr_preload(GFP_KERNEL); spin_lock(&nn->s2s_cp_lock); - new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, copy, 0, 0, GFP_NOWAIT); + new_id = idr_alloc_cyclic(&nn->s2s_cp_stateids, ptr, 0, 0, GFP_NOWAIT); spin_unlock(&nn->s2s_cp_lock); idr_preload_end(); if (new_id < 0) return 0; - copy->cp_stateid.si_opaque.so_id = new_id; - copy->cp_stateid.si_opaque.so_clid.cl_boot = nn->boot_time; - copy->cp_stateid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id; + stid->si_opaque.so_id = new_id; + stid->si_opaque.so_clid.cl_boot = nn->boot_time; + stid->si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id; return 1; } -void nfs4_free_cp_state(struct nfsd4_copy *copy) +int nfs4_init_cp_state(struct nfsd_net *nn, struct nfsd4_copy *copy) +{ + return _nfs4_init_state(nn, copy, ©->cp_stateid); +} + +struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn, + struct nfs4_stid *p_stid) +{ + struct nfs4_cpntf_state *cps; + + cps = kzalloc(sizeof(struct nfs4_cpntf_state), GFP_KERNEL); + if (!cps) + return NULL; + if (!_nfs4_init_state(nn, cps, &cps->cp_stateid)) + goto out_free; + cps->cp_p_stid = p_stid; + cps->cp_active = false; + cps->cp_timeout = jiffies + (nn->nfsd4_lease * HZ); + INIT_LIST_HEAD(&cps->cp_list); + list_add(&cps->cp_list, &p_stid->sc_cp_list); + + return cps; +out_free: + kfree(cps); + return NULL; +} + +void _nfs4_free_state(struct net *n, stateid_t *stid) { struct nfsd_net *nn; - nn = net_generic(copy->cp_clp->net, nfsd_net_id); + nn = net_generic(n, nfsd_net_id); spin_lock(&nn->s2s_cp_lock); - idr_remove(&nn->s2s_cp_stateids, copy->cp_stateid.si_opaque.so_id); + idr_remove(&nn->s2s_cp_stateids, stid->si_opaque.so_id); spin_unlock(&nn->s2s_cp_lock); } +void nfs4_free_cp_state(struct nfsd4_copy *copy) +{ + _nfs4_free_state(copy->cp_clp->net, ©->cp_stateid); +} + +void nfs4_free_cpntf_state(struct nfs4_cpntf_state *cps) +{ + _nfs4_free_state(cps->cp_p_stid->sc_client->net, &cps->cp_stateid); + kfree(cps); +} + +static void nfs4_free_cpntf_statelist(struct nfs4_stid *stid) +{ + struct nfs4_cpntf_state *cps; + + might_sleep(); + + while (!list_empty(&stid->sc_cp_list)) { + cps = list_first_entry(&stid->sc_cp_list, + struct nfs4_cpntf_state, cp_list); + list_del(&cps->cp_list); + nfs4_free_cpntf_state(cps); + } +} + static struct nfs4_ol_stateid * nfs4_alloc_open_stateid(struct nfs4_client *clp) { struct nfs4_stid *stid; @@ -891,6 +944,7 @@ static void block_delegations(struct knfsd_fh *fh) } idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); spin_unlock(&clp->cl_lock); + nfs4_free_cpntf_statelist(s); s->sc_free(s); if (fp) put_nfs4_file(fp); diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 9f6886f..d4945a8 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -1839,6 +1839,22 @@ static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, } static __be32 +nfsd4_decode_copy_notify(struct nfsd4_compoundargs *argp, + struct nfsd4_copy_notify *cn) +{ + int status; + + status = nfsd4_decode_stateid(argp, &cn->cpn_src_stateid); + if (status) + return status; + status = nfsd4_decode_nl4_server(argp, &cn->cpn_dst); + if (status) + return status; + + return status; +} + +static __be32 nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek) { DECODE_HEAD; @@ -1939,7 +1955,7 @@ static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, /* new operations for NFSv4.2 */ [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy, - [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_notsupp, + [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_copy_notify, [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp, [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp, @@ -4324,6 +4340,45 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, } static __be32 +nfsd42_encode_nl4_server(struct nfsd4_compoundres *resp, struct nl4_server *ns) +{ + struct xdr_stream *xdr = &resp->xdr; + struct nfs42_netaddr *addr; + __be32 *p; + + p = xdr_reserve_space(xdr, 4); + *p++ = cpu_to_be32(ns->nl4_type); + + switch (ns->nl4_type) { + case NL4_NETADDR: + addr = &ns->u.nl4_addr; + + /** netid_len, netid, uaddr_len, uaddr (port included + * in RPCBIND_MAXUADDRLEN) + */ + p = xdr_reserve_space(xdr, + 4 /* netid len */ + + (XDR_QUADLEN(addr->netid_len) * 4) + + 4 /* uaddr len */ + + (XDR_QUADLEN(addr->addr_len) * 4)); + if (!p) + return nfserr_resource; + + *p++ = cpu_to_be32(addr->netid_len); + p = xdr_encode_opaque_fixed(p, addr->netid, + addr->netid_len); + *p++ = cpu_to_be32(addr->addr_len); + p = xdr_encode_opaque_fixed(p, addr->addr, + addr->addr_len); + break; + default: + WARN_ON(ns->nl4_type != NL4_NETADDR); + } + + return 0; +} + +static __be32 nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_copy *copy) { @@ -4360,6 +4415,44 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, } static __be32 +nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr, + struct nfsd4_copy_notify *cn) +{ + struct xdr_stream *xdr = &resp->xdr; + __be32 *p; + + if (nfserr) + return nfserr; + + /* 8 sec, 4 nsec */ + p = xdr_reserve_space(xdr, 12); + if (!p) + return nfserr_resource; + + /* cnr_lease_time */ + p = xdr_encode_hyper(p, cn->cpn_sec); + *p++ = cpu_to_be32(cn->cpn_nsec); + + /* cnr_stateid */ + nfserr = nfsd4_encode_stateid(xdr, &cn->cpn_cnr_stateid); + if (nfserr) + return nfserr; + + /* cnr_src.nl_nsvr */ + p = xdr_reserve_space(xdr, 4); + if (!p) + return nfserr_resource; + + *p++ = cpu_to_be32(1); + + nfserr = nfsd42_encode_nl4_server(resp, &cn->cpn_src); + if (nfserr) + return nfserr; + + return nfserr; +} + +static __be32 nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_seek *seek) { @@ -4456,7 +4549,7 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, /* NFSv4.2 operations */ [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy, - [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_noop, + [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_copy_notify, [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop, [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop, diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 304de3b..6bfac6a 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -94,6 +94,7 @@ struct nfs4_stid { #define NFS4_REVOKED_DELEG_STID 16 #define NFS4_CLOSED_DELEG_STID 32 #define NFS4_LAYOUT_STID 64 + struct list_head sc_cp_list; unsigned char sc_type; stateid_t sc_stateid; spinlock_t sc_lock; @@ -102,6 +103,17 @@ struct nfs4_stid { void (*sc_free)(struct nfs4_stid *); }; +/* Keep a list of stateids issued by the COPY_NOTIFY, associate it with the + * parent OPEN/LOCK/DELEG stateid. + */ +struct nfs4_cpntf_state { + stateid_t cp_stateid; + struct list_head cp_list; /* per parent nfs4_stid */ + struct nfs4_stid *cp_p_stid; /* pointer to parent */ + bool cp_active; /* has the copy started */ + unsigned long cp_timeout; /* copy timeout */ +}; + /* * Represents a delegation stateid. The nfs4_client holds references to these * and they are put when it is being destroyed or when the delegation is @@ -615,6 +627,9 @@ struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *sla void (*sc_free)(struct nfs4_stid *)); int nfs4_init_cp_state(struct nfsd_net *nn, struct nfsd4_copy *copy); void nfs4_free_cp_state(struct nfsd4_copy *copy); +struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn, + struct nfs4_stid *p_stid); +void nfs4_free_cpntf_state(struct nfs4_cpntf_state *cps); void nfs4_unhash_stid(struct nfs4_stid *s); void nfs4_put_stid(struct nfs4_stid *s); void nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid); diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index b4d1140..4557f15 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -567,6 +567,18 @@ struct nfsd4_offload_status { u32 status; }; +struct nfsd4_copy_notify { + /* request */ + stateid_t cpn_src_stateid; + struct nl4_server cpn_dst; + + /* response */ + stateid_t cpn_cnr_stateid; + u64 cpn_sec; + u32 cpn_nsec; + struct nl4_server cpn_src; +}; + struct nfsd4_op { int opnum; const struct nfsd4_operation * opdesc; @@ -626,6 +638,7 @@ struct nfsd4_op { struct nfsd4_clone clone; struct nfsd4_copy copy; struct nfsd4_offload_status offload_status; + struct nfsd4_copy_notify copy_notify; struct nfsd4_seek seek; } u; struct nfs4_replay * replay; From patchwork Fri Oct 19 15:29:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A9BF13A4 for ; Fri, 19 Oct 2018 15:29:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A1C627F92 for ; Fri, 19 Oct 2018 15:29:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E96D27F93; Fri, 19 Oct 2018 15:29:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C307527F94 for ; Fri, 19 Oct 2018 15:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726860AbeJSXf6 (ORCPT ); Fri, 19 Oct 2018 19:35:58 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:39200 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbeJSXf6 (ORCPT ); Fri, 19 Oct 2018 19:35:58 -0400 Received: by mail-qt1-f195.google.com with SMTP id e21-v6so2520742qtp.6 for ; Fri, 19 Oct 2018 08:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KKq+uFwhLrZI0Vi9YIIJCW9jp1FWEeolO2gwCwk2llc=; b=dOIwMSR0gD0yPACyt30nlGAMyZarSXr7eUpbwuRwkoXBhJBR4IKaU0iBqWvwYYtchL OtylGjc1GVA8u2e+og8ahB7QkRpewfA0gMEdlyb+VRTUE3ZRauK0fSeC9kc66LkdwbR6 iwI0I00aFf59F9F7I83iCyk0nYcBJU/B4NJ/ogk6hsDUrK7fjQqVRH7tp/5AzP7paRjW WVukm7JpshJXlFcV8WQlbXOLHyt/HRutarce46/PDIVAzz6UOq7VoWv0FuCuP0cZ0h1i tUN7DXw3BT/epJQ4fN5lAR+b0cWPTvJACu6J5m3+7G8/7e23FzIXtSEzskL4Avv5phzE Yf3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KKq+uFwhLrZI0Vi9YIIJCW9jp1FWEeolO2gwCwk2llc=; b=ZRZysgFy900wGXNQzlbxrxlp0DEobEdpUtNj/DFOfCYex/2nAgUIsT26zIREzDwxxx inqt6YdUc5NjiKpcYhFPFaQykFahbuDGrbyw2KaOXaQ6vgY8GzR+ziqOn77GL9CeW9E5 NpZ9dhckwc9ZpLRsUNYTSp0iuZxW/8efM/65N7vPL8llP3EmzmNx6Xb6SZiuynJMHDf4 m+rKgtErTqY8sP4BHj0gxvxN37NUVUGJxD7sf7EIrMCqJ1hmpc2TAWYmSv3tGhT4c73t jWf52Pn/jd/ss0gr1iQRDkkuLd1BW69QKkikUZYAuc39VqVRHigIhJzKIUErcc3v/jcu IKBg== X-Gm-Message-State: ABuFfoikvX9uWqWaza7i9Rmp+xd+yy4hqlpKNCaRHoRsaumFMCcm32+j qkO1EaTLpJD/9P17n+RqXTY= X-Google-Smtp-Source: ACcGV62xSfXV0ASCpZ5uQcV7iEd7jcUiuYRPMw0ouML1UX5kX0/2Q9WGKZ3xX+cIBi3UX1Fcd6S3RQ== X-Received: by 2002:aed:25d1:: with SMTP id y17-v6mr33198369qtc.217.1539962962728; Fri, 19 Oct 2018 08:29:22 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.21 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:21 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 10/13] NFSD check stateids against copy stateids Date: Fri, 19 Oct 2018 11:29:02 -0400 Message-Id: <20181019152905.32418-11-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Incoming stateid (used by a READ) could be a saved copy stateid. On first use make it active and check that the copy has started within the allowable lease time. Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfs4state.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 7764a8b..16359de 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5206,6 +5206,47 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) return 0; } +/* + * A READ from an inter server to server COPY will have a + * copy stateid. Return the parent nfs4_stid. + */ +static __be32 _find_cpntf_state(struct nfsd_net *nn, stateid_t *st, + struct nfs4_cpntf_state **cps) +{ + struct nfs4_cpntf_state *state = NULL; + + if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id) + return nfserr_bad_stateid; + spin_lock(&nn->s2s_cp_lock); + state = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id); + spin_unlock(&nn->s2s_cp_lock); + if (!state) + return nfserr_bad_stateid; + *cps = state; + return 0; +} + +static __be32 find_cpntf_state(struct nfsd_net *nn, stateid_t *st, + struct nfs4_stid **stid) +{ + __be32 status; + struct nfs4_cpntf_state *cps = NULL; + + status = _find_cpntf_state(nn, st, &cps); + if (status) + return status; + + /* Did the inter server to server copy start in time? */ + if (cps->cp_active == false && !time_after(cps->cp_timeout, jiffies)) + return nfserr_partner_no_auth; + else + cps->cp_active = true; + + *stid = cps->cp_p_stid; + refcount_inc(&cps->cp_p_stid->sc_count); + + return nfs_ok; +} /* * Checks for stateid operations @@ -5238,6 +5279,8 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) status = nfsd4_lookup_stateid(cstate, stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID, &s, nn); + if (status == nfserr_bad_stateid) + status = find_cpntf_state(nn, stateid, &s); if (status) return status; status = nfsd4_stid_check_stateid_generation(stateid, s, From patchwork Fri Oct 19 15:29:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B0CC13A4 for ; Fri, 19 Oct 2018 15:29:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7994527F91 for ; Fri, 19 Oct 2018 15:29:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64A6D27F98; Fri, 19 Oct 2018 15:29:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0B1427F91 for ; Fri, 19 Oct 2018 15:29:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727081AbeJSXf7 (ORCPT ); Fri, 19 Oct 2018 19:35:59 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:38032 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbeJSXf7 (ORCPT ); Fri, 19 Oct 2018 19:35:59 -0400 Received: by mail-qk1-f195.google.com with SMTP id p3-v6so858822qkb.5 for ; Fri, 19 Oct 2018 08:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CCb67kIsyZRRvEcQdWDG9DSN55lGTaaO+OuYFSY9mlY=; b=aVxD69b2/X8kcRahWtBFZ8NYXFy0p7Zk0U4KliLqoN3wGFBBsMIM+H1h4TnE5NZEZk aF/HlAANUVBwZqs3RF9mooFKq0amB/pWEo+ZhQp4CqCBMt450MZ2smikOl44jiGepOTK 5H1sRB8GncigHE4h0MnyX25aXhy+oShINjNy0D4A4Ve6u1WBkJhFXKlr/wgi/LfruRYo ZAkb7qyv6gfnb3gaYV661HOzTat9yhKawPxC05EvoCGkOupF950dA46LWmfBoipprwEI QbONR+pXj7QZeg7SlQweErP+JbbNnSRuB1KKbhoPjt6rMBkfSuKxelatw1BmaHDACMCH yKwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CCb67kIsyZRRvEcQdWDG9DSN55lGTaaO+OuYFSY9mlY=; b=Jdmft692mQyOud8i/3MY2tUlKnov9qZNeP0tqU1wkyTmyA9607p/m2nDwuXQ5XUyPg b5pDKRykohwNm6WcyP1FV0Na78/cPCKFnKhBHmLpArewOAtZLuUWHy8dwFXTtF+vwVDo lOZ19ngdSPa7vsLBhw9N8nwfBH2ak7hksNC12qOROBQNDB9eSvhFrvps9m8Btv9BV9Qr EcwNjAuxfNt/z/8PMqVsupP6lYC8hExS2vG8bXQX/jPmgGhdQJ58zXYOiB8wA+UMPM9r 1h0a41KegrCVgw/vD5Ah0sQ6r5/ZFpg/Li10uM676WqhyxOLZsWMu84m9QyzQQRgOmgR mztg== X-Gm-Message-State: AGRZ1gK+5uaQRa/lALc1qCn+o1fLo0UbMjloKhqxnsautk4s23gFqjog VM9189WZKipH+zPnaEuedUCORyYX X-Google-Smtp-Source: AJdET5eaTOkc+EV6AaIKJU7AFR5qlMrQieHLq8J9zkX6OYBVjMqlSHSPJcBhtu83GfL3TNEpxSmbfQ== X-Received: by 2002:ae9:f211:: with SMTP id m17-v6mr1036468qkg.215.1539962964083; Fri, 19 Oct 2018 08:29:24 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.22 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:23 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 11/13] NFSD generalize nfsd4_compound_state flag names Date: Fri, 19 Oct 2018 11:29:03 -0400 Message-Id: <20181019152905.32418-12-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Allow for sid_flag field non-stateid use. Signed-off-by: Andy Adamson --- fs/nfsd/nfs4proc.c | 8 ++++---- fs/nfsd/nfs4state.c | 7 ++++--- fs/nfsd/xdr4.h | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 999c8cb..43a83c7 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -530,9 +530,9 @@ static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_stat return nfserr_restorefh; fh_dup2(&cstate->current_fh, &cstate->save_fh); - if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { + if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) { memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); - SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); + SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG); } return nfs_ok; } @@ -542,9 +542,9 @@ static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_stat union nfsd4_op_u *u) { fh_dup2(&cstate->save_fh, &cstate->current_fh); - if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { + if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) { memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); - SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); + SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG); } return nfs_ok; } diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 16359de..a39a581 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -7424,7 +7424,8 @@ static int nfs4_state_create_net(struct net *net) static void get_stateid(struct nfsd4_compound_state *cstate, stateid_t *stateid) { - if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG) && CURRENT_STATEID(stateid)) + if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG) && + CURRENT_STATEID(stateid)) memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t)); } @@ -7433,14 +7434,14 @@ static int nfs4_state_create_net(struct net *net) { if (cstate->minorversion) { memcpy(&cstate->current_stateid, stateid, sizeof(stateid_t)); - SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); + SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG); } } void clear_current_stateid(struct nfsd4_compound_state *cstate) { - CLEAR_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); + CLEAR_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG); } /* diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 4557f15..4a1e53d 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -46,9 +46,9 @@ #define CURRENT_STATE_ID_FLAG (1<<0) #define SAVED_STATE_ID_FLAG (1<<1) -#define SET_STATE_ID(c, f) ((c)->sid_flags |= (f)) -#define HAS_STATE_ID(c, f) ((c)->sid_flags & (f)) -#define CLEAR_STATE_ID(c, f) ((c)->sid_flags &= ~(f)) +#define SET_CSTATE_FLAG(c, f) ((c)->sid_flags |= (f)) +#define HAS_CSTATE_FLAG(c, f) ((c)->sid_flags & (f)) +#define CLEAR_CSTATE_FLAG(c, f) ((c)->sid_flags &= ~(f)) struct nfsd4_compound_state { struct svc_fh current_fh; From patchwork Fri Oct 19 15:29:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14888109C for ; Fri, 19 Oct 2018 15:29:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02B4627F92 for ; Fri, 19 Oct 2018 15:29:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB4F727F94; Fri, 19 Oct 2018 15:29:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78C5F27F92 for ; Fri, 19 Oct 2018 15:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbeJSXgB (ORCPT ); Fri, 19 Oct 2018 19:36:01 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:40827 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbeJSXgB (ORCPT ); Fri, 19 Oct 2018 19:36:01 -0400 Received: by mail-qt1-f195.google.com with SMTP id b4-v6so38686248qtc.7 for ; Fri, 19 Oct 2018 08:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WvD5uBmU2p/FzYjt2dQSF6KiIpeVpnRF9PAcH10tc58=; b=W7Dg/0XrwxZpMwWMUjHQTD6bGTOhpZ5m1b9PgetGgk0YMbpYiGBXQmAQf0F+zJNbei hOH7hBTJq0E0d9ubwK3ND08q6deg5/y7dBCd0sNLyhtv97NhS3gYrCN/B9ti5ETnIz6O cQ71XZzLzYjiP4+ajRvuBkYWV3LjXBCNVOFiQVkgRS+wgTX4ub2Dd7RRC+Zb1uhVWxnI 7pA7N7aLAYSaqlPkKk5eac4t1RvOP79PiFiX3Ln2hPDWOWGb2BKUMLIv2jsm0GcQZ9H9 7KEiGbfrQtZ0MvaKFmetqMOOa9+LEf0d8WSoutlkdmCfF4H4DemCKpu1tqaQK/CXgHkc Rd2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WvD5uBmU2p/FzYjt2dQSF6KiIpeVpnRF9PAcH10tc58=; b=O60tg/1NkayezijFb4a4X3tp/HxfpKvS5lf4Jij7uganFpjzSmeVvfuEdszSoToXxp 3BblDsGcg8ugmIFWhVk5akG2QtiSmcEroXeo/c+sk2JlG2ydanvgk/iWLnMQUj9jVS4q Bph0rdNqzx7KYWp/Un7k+073nM5oL4YKrjW8CY1vgN2w62/adtX3fMJHVsLatmbnGkXi cD2pUuAX0Id23qLMKVyKKtGoiSweUseSaHVGrWdgK1KWtyCD76QqIyTXQk10eUng2fHf EnCmStZJccunEU2yipCBToma0lrEqyk62ueAWy43fcYtTxHQ6uxKJoTLnQXJ4s5PrFj4 hxYA== X-Gm-Message-State: ABuFfoiEiYuDCyNoYTUE97P/lsGX98/iuUb4u6eXkIqw/hv7IwUz6RH6 wFbGcAYlb1Ky3irTeunAVgCozfa3 X-Google-Smtp-Source: ACcGV62UvP/8co0549ZQuz8yZqwwpUYtg4Rcw1+ZwoTSC7MHo872e8e6/vmxVKZIaT4lK/4YB1MlJA== X-Received: by 2002:a0c:8950:: with SMTP id 16mr29523528qvq.56.1539962965396; Fri, 19 Oct 2018 08:29:25 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.24 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:24 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 12/13] NFSD: allow inter server COPY to have a STALE source server fh Date: Fri, 19 Oct 2018 11:29:04 -0400 Message-Id: <20181019152905.32418-13-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia The inter server to server COPY source server filehandle is a foreign filehandle as the COPY is sent to the destination server. Signed-off-by: Olga Kornievskaia --- fs/nfsd/Kconfig | 10 ++++++++++ fs/nfsd/nfs4proc.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsfh.h | 5 ++++- fs/nfsd/xdr4.h | 1 + 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/Kconfig b/fs/nfsd/Kconfig index 20b1c17..37ff3d5 100644 --- a/fs/nfsd/Kconfig +++ b/fs/nfsd/Kconfig @@ -131,6 +131,16 @@ config NFSD_FLEXFILELAYOUT If unsure, say N. +config NFSD_V4_2_INTER_SSC + bool "NFSv4.2 inter server to server COPY" + depends on NFSD_V4 && NFS_V4_1 && NFS_V4_2 + help + This option enables support for NFSv4.2 inter server to + server copy where the destination server calls the NFSv4.2 + client to read the data to copy from the source server. + + If unsure, say N. + config NFSD_V4_SECURITY_LABEL bool "Provide Security Label support for NFSv4 server" depends on NFSD_V4 && SECURITY diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 43a83c7..59e9d0c 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -503,12 +503,21 @@ static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_stat union nfsd4_op_u *u) { struct nfsd4_putfh *putfh = &u->putfh; + __be32 ret; fh_put(&cstate->current_fh); cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, putfh->pf_fhlen); - return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); + ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); +#ifdef CONFIG_NFSD_V4_2_INTER_SSC + if (ret == nfserr_stale && HAS_CSTATE_FLAG(cstate, NO_VERIFY_FH)) { + CLEAR_CSTATE_FLAG(cstate, NO_VERIFY_FH); + SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN); + ret = 0; + } +#endif + return ret; } static __be32 @@ -1957,6 +1966,26 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp, - rqstp->rq_auth_slack; } +#ifdef CONFIG_NFSD_V4_2_INTER_SSC +static bool _compound_contains_inter_copy(struct nfsd4_op *ops, int start, + int end) +{ + bool found = false; + struct nfsd4_copy *copy; + int i; + + for (i = start; i < end; i++) { + if (ops[i].opnum == OP_COPY) { + copy = (struct nfsd4_copy *)&ops[i].u; + if (copy->cp_src) + found = true; + break; + } + } + return found; +} +#endif + /* * COMPOUND call. */ @@ -2019,13 +2048,23 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp, op->status = nfsd4_open_omfg(rqstp, cstate, op); goto encode_op; } +#ifdef CONFIG_NFSD_V4_2_INTER_SSC + if (op->opnum == OP_PUTFH && + args->ops[resp->opcnt].opnum == OP_SAVEFH && + args->ops[resp->opcnt+1].opnum == OP_PUTFH && + _compound_contains_inter_copy(args->ops, resp->opcnt+2, + args->opcnt)) + SET_CSTATE_FLAG(cstate, NO_VERIFY_FH); +#endif - if (!current_fh->fh_dentry) { + if (!current_fh->fh_dentry && + !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) { if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) { op->status = nfserr_nofilehandle; goto encode_op; } - } else if (current_fh->fh_export->ex_fslocs.migrated && + } else if (current_fh->fh_export && + current_fh->fh_export->ex_fslocs.migrated && !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { op->status = nfserr_moved; goto encode_op; diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h index 755e256..b9c7568 100644 --- a/fs/nfsd/nfsfh.h +++ b/fs/nfsd/nfsfh.h @@ -35,7 +35,7 @@ static inline ino_t u32_to_ino_t(__u32 uino) bool fh_locked; /* inode locked by us */ bool fh_want_write; /* remount protection taken */ - + int fh_flags; /* FH flags */ #ifdef CONFIG_NFSD_V3 bool fh_post_saved; /* post-op attrs saved */ bool fh_pre_saved; /* pre-op attrs saved */ @@ -56,6 +56,9 @@ static inline ino_t u32_to_ino_t(__u32 uino) #endif /* CONFIG_NFSD_V3 */ } svc_fh; +#define NFSD4_FH_FOREIGN (1<<0) +#define SET_FH_FLAG(c, f) ((c)->fh_flags |= (f)) +#define HAS_FH_FLAG(c, f) ((c)->fh_flags & (f)) enum nfsd_fsid { FSID_DEV = 0, diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 4a1e53d..c98ef64 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -45,6 +45,7 @@ #define CURRENT_STATE_ID_FLAG (1<<0) #define SAVED_STATE_ID_FLAG (1<<1) +#define NO_VERIFY_FH (1<<2) #define SET_CSTATE_FLAG(c, f) ((c)->sid_flags |= (f)) #define HAS_CSTATE_FLAG(c, f) ((c)->sid_flags & (f)) From patchwork Fri Oct 19 15:29:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E2F813A4 for ; Fri, 19 Oct 2018 15:29:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B52C27F91 for ; Fri, 19 Oct 2018 15:29:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F7FC27F93; Fri, 19 Oct 2018 15:29:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5443727F92 for ; Fri, 19 Oct 2018 15:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727110AbeJSXgD (ORCPT ); Fri, 19 Oct 2018 19:36:03 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33759 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbeJSXgD (ORCPT ); Fri, 19 Oct 2018 19:36:03 -0400 Received: by mail-qt1-f193.google.com with SMTP id q40-v6so38758189qte.0 for ; Fri, 19 Oct 2018 08:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=igWaAINr/s7NBzq2IaT5KJL+fKjDe870pb5qwTNngac=; b=IkDs++Rp8Y419kJ36PWgLvq9WZFI7GEzg0eqOhI4f5L2Mgtrs+MAXsPYY1vMQjec36 6WTu8VsoGaMQ3xyzIAGhk9b0I9ESt0vHtr29Yo/gVdUyaYu+942zzEC832vSFnvEFa7J q7z7yjVIY3HlMer9VuSvov0vegz8oIm/xpY6e1ZOUGLqBPKuD2NYlEri1HdkjZhkqSOl 4f31Mhzy3KqwNO6rEgL3+Xzu9FIW+PRfJezb4UD6+WTfEZhdhIoYHnzKqSFUhchN5m3N 7SbQCPTWdYiCieljN8P/7fsnwvLGKZYOD87SGMaa+NrfiKFdmXLCctONlURprwqxieZC D7IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=igWaAINr/s7NBzq2IaT5KJL+fKjDe870pb5qwTNngac=; b=hKcx4XGbmNF1kWudF2CHtvIBUM0r4i5sYdoXUEM1hxZMCXNdbKRoDJu6EVtXCLMs4S rgvRL8Ors023gOVaf53XSaTAk1n4FaQH5rwq+rGRr3IuEbjUqo/qQpbYoIbOkb7MGBS/ +OITTpq9UojNrZbWy+/Ml5uPBd0qX26Ia3+CrrSZsUcvRHZzBfVGAeo3yn4WL+NmaH4r TYbZLg2uNmbURETB+0R02iIT9FfX7BbI4QBB1MOgT33ewGnI0DkDFhusGfDPZrFWtFA7 MWrR6VUsZ3J5ze0nrvpZU25g1Akpbk9GaKHARORo8TUOMmy7K5YKEiSqI+3wslhAcrSR 5TyA== X-Gm-Message-State: ABuFfogRn54mZFERW+4QJD38zLVxaBgoqv0koAoWtqlCUkZvvdCWHVj+ 9pn1UBoTScbx37NFf5sHiso= X-Google-Smtp-Source: ACcGV61XQ7jIEm4rsmzmhgEn/pPTjddlSAWjjncgzWLm7A4iGHxV8WpfiMGC6mUbKmLWyovcS9PZAg== X-Received: by 2002:a0c:eccd:: with SMTP id o13mr26013542qvq.42.1539962966769; Fri, 19 Oct 2018 08:29:26 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.25 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:26 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 13/13] NFSD add nfs4 inter ssc to nfsd4_copy Date: Fri, 19 Oct 2018 11:29:05 -0400 Message-Id: <20181019152905.32418-14-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Given a universal address, mount the source server from the destination server. Use an internal mount. Call the NFS client nfs42_ssc_open to obtain the NFS struct file suitable for nfsd_copy_range. Ability to do "inter" server-to-server depends on the an nfsd kernel parameter "inter_copy_offload_enabled". Signed-off-by: Andy Adamson Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfs4proc.c | 298 ++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfssvc.c | 6 ++ fs/nfsd/xdr4.h | 5 + include/linux/nfs4.h | 1 + 4 files changed, 293 insertions(+), 17 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 59e9d0c..6dcd80c 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1153,6 +1153,229 @@ void nfsd4_shutdown_copy(struct nfs4_client *clp) while ((copy = nfsd4_get_copy(clp)) != NULL) nfsd4_stop_copy(copy); } +#ifdef CONFIG_NFSD_V4_2_INTER_SSC + +extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, + struct nfs_fh *src_fh, + nfs4_stateid *stateid); +extern void nfs42_ssc_close(struct file *filep); + +extern void nfs_sb_deactive(struct super_block *sb); + +#define NFSD42_INTERSSC_MOUNTOPS "minorversion=2,vers=4,addr=%s,clientaddr=%s" + +/** + * Support one copy source server for now. + */ +static struct vfsmount * +nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp) +{ + struct file_system_type *type; + struct vfsmount *ss_mnt; + struct nfs42_netaddr *naddr; + struct sockaddr_storage tmp_addr; + size_t tmp_addrlen, match_netid_len = 3; + char *startsep = "", *endsep = "", *match_netid = "tcp"; + char *ipaddr, *ipaddr2, *raw_data; + int len, raw_len, status = -EINVAL; + + /* Currently support only NL4_NETADDR source server */ + if (nss->nl4_type != NL4_NETADDR) { + WARN(nss->nl4_type != NL4_NETADDR, + "nfsd4_copy src server not NL4_NETADDR\n"); + goto out_err; + } + + naddr = &nss->u.nl4_addr; + + tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr, + naddr->addr_len, + (struct sockaddr *)&tmp_addr, + sizeof(tmp_addr)); + if (tmp_addrlen == 0) + goto out_err; + + if (tmp_addr.ss_family == AF_INET6) { + startsep = "["; + endsep = "]"; + match_netid = "tcp6"; + match_netid_len = 4; + } + + if (naddr->netid_len != match_netid_len || + strncmp(naddr->netid, match_netid, naddr->netid_len)) + goto out_err; + + /* Construct the raw data for the vfs_kern_mount call */ + len = RPC_MAX_ADDRBUFLEN + 1; + ipaddr = kzalloc(len, GFP_KERNEL); + if (!ipaddr) + goto out_err; + + rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len); + + /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/ + ipaddr2 = kzalloc(len + 5, GFP_KERNEL); + if (!ipaddr2) + goto out_free_ipaddr; + + rpc_ntop((struct sockaddr *)&rqstp->rq_daddr, ipaddr2, len + 5); + + raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr) + + strlen(ipaddr2); + raw_data = kzalloc(raw_len, GFP_KERNEL); + if (!raw_data) + goto out_free_ipaddr2; + + snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr, + ipaddr2); + + status = -ENODEV; + type = get_fs_type("nfs"); + if (!type) + goto out_free_rawdata; + + /* Set the server: for the vfs_kerne_mount call */ + memset(ipaddr2, 0, len + 5); + snprintf(ipaddr2, len + 5, "%s%s%s:/", startsep, ipaddr, endsep); + + dprintk("%s Raw mount data: %s server:export %s\n", __func__, + raw_data, ipaddr2); + + /* Use an 'internal' mount: MS_KERNMOUNT -> MNT_INTERNAL */ + ss_mnt = vfs_kern_mount(type, MS_KERNMOUNT, ipaddr2, raw_data); + if (IS_ERR(ss_mnt)) { + status = PTR_ERR(ss_mnt); + goto out_free_rawdata; + } + + kfree(raw_data); + kfree(ipaddr2); + kfree(ipaddr); + + return ss_mnt; + +out_free_rawdata: + kfree(raw_data); +out_free_ipaddr2: + kfree(ipaddr2); +out_free_ipaddr: + kfree(ipaddr); +out_err: + dprintk("--> %s ERROR %d\n", __func__, status); + return ERR_PTR(status); +} + +static void +nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) +{ + nfs_sb_deactive(ss_mnt->mnt_sb); + mntput(ss_mnt); +} + +/** + * nfsd4_setup_inter_ssc + * + * Verify COPY destination stateid. + * Connect to the source server with NFSv4.1. + * Create the source struct file for nfsd_copy_range. + * Called with COPY cstate: + * SAVED_FH: source filehandle + * CURRENT_FH: destination filehandle + * + * Returns errno (not nfserrxxx) + */ +static struct vfsmount * +nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, + struct nfsd4_compound_state *cstate, + struct nfsd4_copy *copy) +{ + struct svc_fh *s_fh = NULL; + stateid_t *s_stid = ©->cp_src_stateid; + struct vfsmount *ss_mnt; + __be32 status; + + /* Verify the destination stateid and set dst struct file*/ + status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, + ©->cp_dst_stateid, + WR_STATE, ©->file_dst, NULL, + NULL); + if (status) { + ss_mnt = ERR_PTR(be32_to_cpu(status)); + goto out; + } + + ss_mnt = nfsd4_interssc_connect(copy->cp_src, rqstp); + if (IS_ERR(ss_mnt)) + goto out; + + s_fh = &cstate->save_fh; + + copy->c_fh.size = s_fh->fh_handle.fh_size; + memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_base, copy->c_fh.size); + copy->stateid.seqid = s_stid->si_generation; + memcpy(copy->stateid.other, (void *)&s_stid->si_opaque, + sizeof(stateid_opaque_t)); + +out: + return ss_mnt; +} + +static void +nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *src, + struct file *dst) +{ + nfs42_ssc_close(src); + fput(src); + fput(dst); + mntput(ss_mnt); +} + +#else /* CONFIG_NFSD_V4_2_INTER_SSC */ + +static struct vfsmount * +nfsd4_setup_inter_ssc(struct svc_rqst *rqstp, + struct nfsd4_compound_state *cstate, + struct nfsd4_copy *copy) +{ + return ERR_PTR(-EINVAL); +} + +static void +nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *src, + struct file *dst) +{ +} + +static void +nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) +{ +} + +static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, + struct nfs_fh *src_fh, + nfs4_stateid *stateid) +{ + return NULL; +} +#endif /* CONFIG_NFSD_V4_2_INTER_SSC */ + +static __be32 +nfsd4_setup_intra_ssc(struct svc_rqst *rqstp, + struct nfsd4_compound_state *cstate, + struct nfsd4_copy *copy) +{ + return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, + ©->file_src, ©->cp_dst_stateid, + ©->file_dst, NULL); +} + +static void +nfsd4_cleanup_intra_ssc(struct file *src, struct file *dst) +{ + fput(src); + fput(dst); +} static void nfsd4_cb_offload_release(struct nfsd4_callback *cb) { @@ -1217,12 +1440,16 @@ static __be32 nfsd4_do_copy(struct nfsd4_copy *copy, bool sync) status = nfs_ok; } - fput(copy->file_src); - fput(copy->file_dst); + if (copy->cp_src) /* Inter server SSC */ + nfsd4_cleanup_inter_ssc(copy->ss_mnt, copy->file_src, + copy->file_dst); + else + nfsd4_cleanup_intra_ssc(copy->file_src, copy->file_dst); + return status; } -static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) +static int dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) { dst->cp_src_pos = src->cp_src_pos; dst->cp_dst_pos = src->cp_dst_pos; @@ -1232,8 +1459,21 @@ static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst) memcpy(&dst->fh, &src->fh, sizeof(src->fh)); dst->cp_clp = src->cp_clp; dst->file_dst = get_file(src->file_dst); - dst->file_src = get_file(src->file_src); + if (!src->cp_src) /* for inter, file_src doesnt exist yet */ + dst->file_src = get_file(src->file_src); memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid)); + if (src->cp_src) { + dst->cp_src = kmalloc(sizeof(struct nl4_server), GFP_KERNEL); + if (!dst->cp_src) + return -ENOMEM; + memcpy(dst->cp_src, src->cp_src, sizeof(struct nl4_server)); + } + memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid)); + memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh)); + dst->ss_mnt = src->ss_mnt; + + return 0; + } static void cleanup_async_copy(struct nfsd4_copy *copy) @@ -1244,6 +1484,7 @@ static void cleanup_async_copy(struct nfsd4_copy *copy) spin_lock(©->cp_clp->async_lock); list_del(©->copies); spin_unlock(©->cp_clp->async_lock); + kfree(copy->cp_src); nfs4_put_copy(copy); } @@ -1252,7 +1493,18 @@ static int nfsd4_do_async_copy(void *data) struct nfsd4_copy *copy = (struct nfsd4_copy *)data; struct nfsd4_copy *cb_copy; + if (copy->cp_src) { /* Inter server SSC */ + copy->file_src = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, + ©->stateid); + if (IS_ERR(copy->file_src)) { + copy->nfserr = nfserr_offload_denied; + nfsd4_interssc_disconnect(copy->ss_mnt); + goto do_callback; + } + } + copy->nfserr = nfsd4_do_copy(copy, 0); +do_callback: cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); if (!cb_copy) goto out; @@ -1276,11 +1528,19 @@ static int nfsd4_do_async_copy(void *data) __be32 status; struct nfsd4_copy *async_copy = NULL; - status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, - ©->file_src, ©->cp_dst_stateid, - ©->file_dst, NULL); - if (status) - goto out; + if (copy->cp_src) { /* Inter server SSC */ + if (!inter_copy_offload_enable || copy->cp_synchronous) { + status = nfserr_notsupp; + goto out; + } + copy->ss_mnt = nfsd4_setup_inter_ssc(rqstp, cstate, copy); + if (IS_ERR(copy->ss_mnt)) + return nfserr_offload_denied; + } else { + status = nfsd4_setup_intra_ssc(rqstp, cstate, copy); + if (status) + return status; + } copy->cp_clp = cstate->clp; memcpy(©->fh, &cstate->current_fh.fh_handle, @@ -1291,15 +1551,15 @@ static int nfsd4_do_async_copy(void *data) status = nfserrno(-ENOMEM); async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL); if (!async_copy) - goto out; - if (!nfs4_init_cp_state(nn, copy)) { - kfree(async_copy); - goto out; - } + goto out_err; + if (!nfs4_init_cp_state(nn, copy)) + goto out_err; refcount_set(&async_copy->refcount, 1); memcpy(©->cp_res.cb_stateid, ©->cp_stateid, sizeof(copy->cp_stateid)); - dup_copy_fields(copy, async_copy); + status = dup_copy_fields(copy, async_copy); + if (status) + goto out_err; async_copy->copy_task = kthread_create(nfsd4_do_async_copy, async_copy, "%s", "copy thread"); if (IS_ERR(async_copy->copy_task)) @@ -1310,13 +1570,17 @@ static int nfsd4_do_async_copy(void *data) spin_unlock(&async_copy->cp_clp->async_lock); wake_up_process(async_copy->copy_task); status = nfs_ok; - } else + } else { status = nfsd4_do_copy(copy, 1); + } out: return status; out_err: cleanup_async_copy(async_copy); - goto out; + status = nfserrno(-ENOMEM); + if (copy->cp_src) + nfsd4_interssc_disconnect(copy->ss_mnt); + goto out_err; } struct nfsd4_copy * diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index 89cb484..9d254e7 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -30,6 +30,12 @@ #define NFSDDBG_FACILITY NFSDDBG_SVC +bool inter_copy_offload_enable; +EXPORT_SYMBOL_GPL(inter_copy_offload_enable); +module_param(inter_copy_offload_enable, bool, 0644); +MODULE_PARM_DESC(inter_copy_offload_enable, + "Enable inter server to server copy offload. Default: false"); + extern struct svc_program nfsd_program; static int nfsd(void *vrqstp); diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index c98ef64..c7e3df1 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -546,7 +546,12 @@ struct nfsd4_copy { struct task_struct *copy_task; refcount_t refcount; bool stopped; + + struct vfsmount *ss_mnt; + struct nfs_fh c_fh; + nfs4_stateid stateid; }; +extern bool inter_copy_offload_enable; struct nfsd4_seek { /* request */ diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 4d76f87..e53a261 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -17,6 +17,7 @@ #include #include #include +#include enum nfs4_acl_whotype { NFS4_ACL_WHO_NAMED = 0,