From patchwork Mon May 7 08:37:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10383619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6C3B860159 for ; Mon, 7 May 2018 08:48:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 627B728B60 for ; Mon, 7 May 2018 08:48:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57A9E28B64; Mon, 7 May 2018 08:48:49 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 17D6928B60 for ; Mon, 7 May 2018 08:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752364AbeEGIr1 (ORCPT ); Mon, 7 May 2018 04:47:27 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:55811 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752138AbeEGIia (ORCPT ); Mon, 7 May 2018 04:38:30 -0400 Received: by mail-wm0-f65.google.com with SMTP id a8so12017173wmg.5 for ; Mon, 07 May 2018 01:38:29 -0700 (PDT) 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=3z5BGnZ1dMsqKneG2l6CPh5OVWM/P4fbH813ml2k080=; b=SmysWKrwtzrryNkblNkvozUCysmVt4bekiv6mhHf5dwAjfj7ZGPKd1YI/BJptMQyvU L9s+Oij245kATag+L0fWlISXzYmZieLlWAvbePT/ZzIb4s07nVbEDMMGFBBScbxSgoGU OsLKhMvwlcSVa4oBvu3zo5D5R8NTV/BGaU4D8bWgd9rPdHzvcRryoSTv3bfT11x4zd7z ccF3DIMYXQ3gH0+Ps4NfVOzvgtZrSSTTyaksLBzE6CPXm6QJU1zJHHeAaQa0PTVQRjs7 tfv6EPlzfEICsx3vplBmMYKyRnKZ8UeiSrOSrn7ajzBBsrnJvH9FrtluPf0Acb1LV1ON 6uiA== X-Gm-Message-State: ALKqPwdmh3N4D1NuFbt+xSkJdq/Rnbbk89Efoakx0GeTQS/8DkGRIwsd XUgv03Okk466cBaFAS8N8g5Jkg== X-Google-Smtp-Source: AB8JxZoOy/UuLdqDP+Acx/VXTTkkbHgZT0k5iltTnetPjln2MSvUx1JwqWlOM/+d3QbAxAvFeCeEcA== X-Received: by 10.28.104.3 with SMTP id d3mr194538wmc.70.1525682309117; Mon, 07 May 2018 01:38:29 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (C2B0E321.catv.pool.telekom.hu. [194.176.227.33]) by smtp.gmail.com with ESMTPSA id h8-v6sm5908050wmc.16.2018.05.07.01.38.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 01:38:28 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 14/35] ovl: add ovl_write_iter() Date: Mon, 7 May 2018 10:37:46 +0200 Message-Id: <20180507083807.28792-15-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180507083807.28792-1-mszeredi@redhat.com> References: <20180507083807.28792-1-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement stacked writes. Signed-off-by: Miklos Szeredi --- fs/overlayfs/file.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index bbc40a14acf8..a7af56861aa5 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -195,9 +195,48 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) return ret; } +static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) +{ + struct file *file = iocb->ki_filp; + struct inode *inode = file_inode(file); + struct fd real; + const struct cred *old_cred; + ssize_t ret; + + if (!iov_iter_count(iter)) + return 0; + + inode_lock(inode); + /* Update mode */ + ovl_copyattr(ovl_inode_real(inode), inode); + ret = file_remove_privs(file); + if (ret) + goto out_unlock; + + ret = ovl_real_fdget(file, &real); + if (ret) + goto out_unlock; + + old_cred = ovl_override_creds(file_inode(file)->i_sb); + ret = vfs_iter_write(real.file, iter, &iocb->ki_pos, + ovl_iocb_to_rwf(iocb)); + revert_creds(old_cred); + + /* Update size */ + ovl_copyattr(ovl_inode_real(inode), inode); + + fdput(real); + +out_unlock: + inode_unlock(inode); + + return ret; +} + const struct file_operations ovl_file_operations = { .open = ovl_open, .release = ovl_release, .llseek = ovl_llseek, .read_iter = ovl_read_iter, + .write_iter = ovl_write_iter, };