From patchwork Sat Aug 29 09:51:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 11744319 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70634913 for ; Sat, 29 Aug 2020 09:52:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3E4B92075B for ; Sat, 29 Aug 2020 09:52:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mykernel.net header.i=cgxu519@mykernel.net header.b="VdCYBUiH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E4B92075B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mykernel.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5C2A26B0005; Sat, 29 Aug 2020 05:52:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 54A736B0006; Sat, 29 Aug 2020 05:52:00 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 412AB6B0007; Sat, 29 Aug 2020 05:52:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 2B3696B0005 for ; Sat, 29 Aug 2020 05:52:00 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EC9C112FB for ; Sat, 29 Aug 2020 09:51:59 +0000 (UTC) X-FDA: 77203139958.08.earth43_37014c82707d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id CCDF21819E626 for ; Sat, 29 Aug 2020 09:51:59 +0000 (UTC) X-Spam-Summary: 1,0,0,396d957ed67b15ac,d41d8cd98f00b204,cgxu519@mykernel.net,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1513:1515:1516:1518:1521:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3355:3867:3868:4117:4321:4385:4605:5007:6120:6261:6653:7903:9592:10004:10400:11026:11658:11914:12043:12291:12296:12297:12438:12555:12683:12895:12986:14096:14097:14110:14181:14721:21080:21444:21451:21627:21796:21987:21990:30036:30054,0,RBL:163.53.93.243:@mykernel.net:.lbl8.mailshell.net-62.2.2.100 64.100.201.201;04yrs3e6z3r3opos3m9cc4arbk8u3ypphyz7c3nitimrqbxh471unds8t84tyyp.cmeg7g3mjh1ihdi4epnpr1ydnispyetohtzpjiy1h6tbi48hroq7ibsws4cr9uh.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:282,LUA_SUMMARY:none X-HE-Tag: earth43_37014c82707d X-Filterd-Recvd-Size: 6219 Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Sat, 29 Aug 2020 09:51:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1598694693; cv=none; d=zoho.com.cn; s=zohoarc; b=YBE7Pv1efxlf1AAxaIoD3yTwlut8GbiWLhItLSzb75VKosrMcu8E+zxtkQCO0o1GEr1wmARPmUzNbnLMqnVp2IDVcWb3f1aN2VGkzSpXNEmZqXftIwZ3ObDt7rADXjMu0YjgijZDPZkB9pQGk625k7kft4O51oOzJOtXJuvpo+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1598694693; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=/mgZ6omCjLzte5zMdd9RURwLPDtaIIQG4E0QLcHBYCk=; b=YQfHeJhqjNXXYa/tyIjUkhnXypDPjyK6xn5+H0Rmh5tDYpJ1hufAtjxLCAkiaRTqKIxiR7PDzUiUllGO7fOL3wTouJje6JBMmq3l1be3nHee6+AhMipxMPeiw3cFYRtIuPLBMl8wd6NMT0gu0BDhS4/bBd5lC2UFjJAwQCnQi4k= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=mykernel.net; spf=pass smtp.mailfrom=cgxu519@mykernel.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1598694693; s=zohomail; d=mykernel.net; i=cgxu519@mykernel.net; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=/mgZ6omCjLzte5zMdd9RURwLPDtaIIQG4E0QLcHBYCk=; b=VdCYBUiH8r7HhyaUv/Lu4nc8lsMH0dwYTU1Ps2qELaHkJCW1mF+ZnH5Jm8++hkKX 7Fp6O3tLZAFn5ZU0QJQyGMuAlPj+VFC5f/DJH+57pksWtaPu4++RxzKyIyMJ/k9L2Iy 28ZebKeyHWHgB5KPswewZ3S+Md5P1VQdcV7uK2nA= Received: from localhost.localdomain (116.30.194.36 [116.30.194.36]) by mx.zoho.com.cn with SMTPS id 1598694691937238.97463573795892; Sat, 29 Aug 2020 17:51:31 +0800 (CST) From: Chengguang Xu To: linux-unionfs@vger.kernel.org, linux-mm@kvack.org Cc: miklos@szeredi.hu, akpm@linux-foundation.org, amir73il@gmail.com, riteshh@linux.ibm.com, Chengguang Xu Message-ID: <20200829095101.25350-3-cgxu519@mykernel.net> Subject: [RFC PATCH 2/3] ovl: introduce struct ovl_file_entry Date: Sat, 29 Aug 2020 17:51:00 +0800 X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200829095101.25350-1-cgxu519@mykernel.net> References: <20200829095101.25350-1-cgxu519@mykernel.net> MIME-Version: 1.0 X-ZohoCNMailClient: External X-Rspamd-Queue-Id: CCDF21819E626 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Introduce new struct ovl_file_entry to store real file and real vm_ops handler. Signed-off-by: Chengguang Xu --- fs/overlayfs/file.c | 64 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 0d940e29d62b..14ab5344a918 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -21,6 +21,39 @@ struct ovl_aio_req { struct fd fd; }; +struct ovl_file_entry { + struct file *realfile; + void *vm_ops; +}; + +struct file *ovl_get_realfile(struct file *file) +{ + struct ovl_file_entry *ofe = file->private_data; + + return ofe->realfile; +} + +void ovl_set_realfile(struct file *file, struct file *realfile) +{ + struct ovl_file_entry *ofe = file->private_data; + + ofe->realfile = realfile; +} + +void *ovl_get_real_vmops(struct file *file) +{ + struct ovl_file_entry *ofe = file->private_data; + + return ofe->vm_ops; +} + +void ovl_set_real_vmops(struct file *file, void *vm_ops) +{ + struct ovl_file_entry *ofe = file->private_data; + + ofe->vm_ops = vm_ops; +} + static struct kmem_cache *ovl_aio_request_cachep; static char ovl_whatisit(struct inode *inode, struct inode *realinode) @@ -105,14 +138,14 @@ static int ovl_change_flags(struct file *file, unsigned int flags) return 0; } -static int ovl_real_fdget_meta(const struct file *file, struct fd *real, +static int ovl_real_fdget_meta(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; + real->file = ovl_get_realfile(file); if (allow_meta) realinode = ovl_inode_real(inode); @@ -134,7 +167,7 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, return 0; } -static int ovl_real_fdget(const struct file *file, struct fd *real) +static int ovl_real_fdget(struct file *file, struct fd *real) { return ovl_real_fdget_meta(file, real, false); } @@ -144,25 +177,36 @@ static int ovl_open(struct inode *inode, struct file *file) struct file *realfile; int err; + file->private_data = kzalloc(sizeof(struct ovl_file_entry), GFP_KERNEL); + if (!file->private_data) + return -ENOMEM; + err = ovl_maybe_copy_up(file_dentry(file), file->f_flags); if (err) - return err; + goto out; /* 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, ovl_inode_realdata(inode)); - if (IS_ERR(realfile)) - return PTR_ERR(realfile); - - file->private_data = realfile; + if (IS_ERR(realfile)) { + err = PTR_ERR(realfile); + goto out; + } + ovl_set_realfile(file, realfile); return 0; +out: + kfree(file->private_data); + file->private_data = NULL; + return err; } static int ovl_release(struct inode *inode, struct file *file) { - fput(file->private_data); + fput(ovl_get_realfile(file)); + kfree(file->private_data); + file->private_data = NULL; return 0; } @@ -451,7 +495,7 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) static int ovl_mmap(struct file *file, struct vm_area_struct *vma) { - struct file *realfile = file->private_data; + struct file *realfile = ovl_get_realfile(file); const struct cred *old_cred; int ret;