Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3474774imm; Tue, 29 May 2018 07:53:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp6KcUAzaRfm+pMjPlaiHOdC7BsHvKgCzdhvcznzsGD6TGRoe5SZkz7iXwxe1qpaFL1oHys X-Received: by 2002:a17:902:2983:: with SMTP id h3-v6mr18066846plb.232.1527605618848; Tue, 29 May 2018 07:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527605618; cv=none; d=google.com; s=arc-20160816; b=0uVQB3Lco4Cy3gsjka0PZUiLSMO8KUIS/eMzQtz5WJUKMnVpLSHa81xgfyvHyhbH9n /2VTac5YvwNTU/HtuQEqeXEMr+TpH00a8M8gPc6auoyyUmovRnxo3SltmSkMy/L4aXZ7 TmpTTyghAeCs+1T3Mw87RbYiZ40R/tus+MgvoEgWLaNEMEuiA8rrE+zg2B72toJxtLhT WWwZuUdeBCnVZIF3vGydsBhZnPHIxAAI6nPAvLJC51a5tGL7TYX7wBroZVVtjlhDjkP7 Egcp95hkUPJu/eUQg02TQ+Y5E0CtoalacCD+dSsSaNB6kl8RgsMF9TbFE+CmIqRlg6Rc 0LGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=lpElyWlYPaV+uaETjwf7sXlqefNYERcgxzZ+P3fJrM4=; b=EzbHQPWHQ8kRVeAnF7Iict0YzggK9WaecjhEug2yBRPuWTKeHm+mASQhD/pharC6+k rRN8B5Q9TCKR4++Xld0QOG/nKiF0RiFqizKSG/aksZsVQtcpXnyVVjRU+LK1MMVueElE fX1lk0KxVy5FXFwBW8yx3NTGalT6Gj/diMS11w/ikbt/uxfH9FeEq4EcnmQEzw/Da070 12InOkTaFiaRJPuOjkKlD1aaA1/tzj3Daje5f/ByDExv/MOJEusfztVpA4Mq+vUbo7FL CorolDExmrYPhSLUv4aNERMVI+z6HMttRxbYgSXf/EBF3zEdDWK0RzdQ8iInYm3mLCmZ cohQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d65-v6si33458385pfa.263.2018.05.29.07.53.24; Tue, 29 May 2018 07:53:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936752AbeE2Ov4 (ORCPT + 99 others); Tue, 29 May 2018 10:51:56 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:53618 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935452AbeE2Oqe (ORCPT ); Tue, 29 May 2018 10:46:34 -0400 Received: by mail-wm0-f67.google.com with SMTP id a67-v6so41217025wmf.3 for ; Tue, 29 May 2018 07:46:34 -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=lpElyWlYPaV+uaETjwf7sXlqefNYERcgxzZ+P3fJrM4=; b=r82/LLV9Afo4ZJUYpQ21NLpDDDjewoaEgoIKBCKWE0Ft2+G1DLV9gZ2lyesC9SmSVU SaR+9AteWYOArH5z/48z3kp1Oo++UkUU62MJVMk73usVw3wBpjrqN2FHamMcSDBh6fH/ netCq7e0xx4PPgdDO2VGhhyaUvjCxLduC+GeGMmsohT112VEeryuPym3g5ewC3nj86DG OgoPt17j1UwBRyHGzuCCfusn14chHGjTw8vF8bfMp8P4tNpluA8HM9veT16whUUba9DF txl3uuY6PlTCZva+k/dwo1WQ6HYkA33UhejKJ5GEBxHMJfwx83UO46uZHGT2EgmSCP8y TQng== X-Gm-Message-State: ALKqPweLiZV0m+c/R8bQChKQh38eHnKRhctyhB6fAsyd5HLwf0quLEjt XvJaME4TCbNNnn1s5IlLBA3jLHakprw= X-Received: by 2002:a1c:340f:: with SMTP id b15-v6mr10498192wma.129.1527605193517; Tue, 29 May 2018 07:46:33 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id n71-v6sm20942227wmi.14.2018.05.29.07.46.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 07:46:33 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/28] ovl: Open file with data except for the case of fsync Date: Tue, 29 May 2018 16:45:59 +0200 Message-Id: <20180529144612.16675-16-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180529144612.16675-1-mszeredi@redhat.com> References: <20180529144612.16675-1-mszeredi@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vivek Goyal ovl_open() should open file which contains data and not open metacopy inode. With the introduction of metacopy inodes, with current implementaion we will end up opening metacopy inode as well. But there can be certain circumstances like ovl_fsync() where we want to allow opening a metacopy inode instead. Hence, change ovl_open_realfile() and add _ovl_open_real() and add extra parameter which specifies whether to allow opening metacopy inode or not. If this parameter is false, we look for data inode and open that. This should allow covering both the cases. Signed-off-by: Vivek Goyal Reviewed-by: Amir Goldstein Signed-off-by: Miklos Szeredi --- fs/overlayfs/file.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 266692ce9a9a..c7738ef492c8 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -14,11 +14,20 @@ #include #include "overlayfs.h" -static struct file *ovl_open_realfile(const struct file *file) +static char ovl_whatisit(struct inode *inode, struct inode *realinode) +{ + if (realinode != ovl_inode_upper(inode)) + return 'l'; + if (ovl_has_upperdata(inode)) + return 'u'; + else + return 'm'; +} + +static struct file *ovl_open_realfile(const struct file *file, + struct inode *realinode) { struct inode *inode = file_inode(file); - struct inode *upperinode = ovl_inode_upper(inode); - struct inode *realinode = upperinode ?: ovl_inode_lower(inode); struct file *realfile; const struct cred *old_cred; @@ -28,7 +37,7 @@ static struct file *ovl_open_realfile(const struct file *file) revert_creds(old_cred); pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n", - file, file, upperinode ? 'u' : 'l', file->f_flags, + file, file, ovl_whatisit(inode, realinode), file->f_flags, realfile, IS_ERR(realfile) ? 0 : realfile->f_flags); return realfile; @@ -72,17 +81,24 @@ static int ovl_change_flags(struct file *file, unsigned int flags) return 0; } -static int ovl_real_fdget(const struct file *file, struct fd *real) +static int ovl_real_fdget_meta(const struct file *file, struct fd *real, + bool allow_meta) { struct inode *inode = file_inode(file); + struct inode *realinode; real->flags = 0; real->file = file->private_data; + if (allow_meta) + realinode = ovl_inode_real(inode); + else + realinode = ovl_inode_realdata(inode); + /* Has it been copied up since we'd opened it? */ - if (unlikely(file_inode(real->file) != ovl_inode_real(inode))) { + if (unlikely(file_inode(real->file) != realinode)) { real->flags = FDPUT_FPUT; - real->file = ovl_open_realfile(file); + real->file = ovl_open_realfile(file, realinode); return PTR_ERR_OR_ZERO(real->file); } @@ -94,6 +110,11 @@ static int ovl_real_fdget(const struct file *file, struct fd *real) return 0; } +static int ovl_real_fdget(const struct file *file, struct fd *real) +{ + return ovl_real_fdget_meta(file, real, false); +} + static int ovl_open(struct inode *inode, struct file *file) { struct dentry *dentry = file_dentry(file); @@ -107,7 +128,7 @@ static int ovl_open(struct inode *inode, struct file *file) /* No longer need these flags, so don't pass them on to underlying fs */ file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); - realfile = ovl_open_realfile(file); + realfile = ovl_open_realfile(file, ovl_inode_real(file_inode(file))); if (IS_ERR(realfile)) return PTR_ERR(realfile); @@ -244,7 +265,7 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) const struct cred *old_cred; int ret; - ret = ovl_real_fdget(file, &real); + ret = ovl_real_fdget_meta(file, &real, !datasync); if (ret) return ret; -- 2.14.3