From patchwork Fri Oct 4 10:23:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13822049 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E733155342; Fri, 4 Oct 2024 10:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037431; cv=none; b=E5NlbB3mpl34BhyYLwJB0jwjkUeLPSEZ5ujdEicTa5G6bjvC3C+zvB+YXh59zsUPuhEQUBYolu5qLuOJNsQ/fx/7UX1ybJ4p8fqeibKYuPN9N2jlyFEAIXb6VGhw4KdLH7I4i02DGLPOdMhddi3ERq+w9DIQpzFc68mf5uZlqw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037431; c=relaxed/simple; bh=TcNfKrdPqFXwPsjHjY6qHNaDVmBBoqwOiV/iY/JcQ+U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nC6TL8yHQAn90rcExi5OXZo2O3U7NvWug7EGlTBwyrecRCLY0DTMER0GaJFNnhQkPLASnZUJConOXTsfSQhZS85HaEwu5A3x6AYAUQpet4XjwxcdJISxaeGDvuVa7WwxBBMPdjbq0pARgFJzMhdD58b8WmRNaOiD6GP2yiDY0wI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JMEqnz4m; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JMEqnz4m" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5398b589032so3176998e87.1; Fri, 04 Oct 2024 03:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728037427; x=1728642227; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l40jdEEvhbgdYhgzNetRpuzwF5wi18ln2Cfcvfzr+lU=; b=JMEqnz4mmj4i4/051K9j+g3KXChZ0TApEc81GctjePBlUyJcr9AD82SvvHUKqkjbb6 xhNXKL8C1nOtwzSaAyX+YLKTKDabO7WldyyQ5vdVXbLtOjUDMPiC+BSsgsjHOGMMoAFR FDfV3ep183SzW/FHc1rqTUYQUHGu5crcNZD9/pSogQuBumAlbsfcCUAGW7ly3zSHl/4h 2mf2Wex6vchJz3TY7OPFoBAkRqjA+VnZ7V8KwYpxgpZi4oMGeaQQwdLsYb/TCY/m1BPn /S31clTBHY+QPi/+M3nSxIN/y/mIoDh4I0w7SPghRpAeT0ICly/TiO9O9C4QvzkRrKOV gMyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728037427; x=1728642227; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l40jdEEvhbgdYhgzNetRpuzwF5wi18ln2Cfcvfzr+lU=; b=DoE6TDHp3at8QN6fQkDDYMC3raWLfzVyBHbigh4ynhw0OJ+Oeot/Qd6kwEGoVza32U yZXYIM8hHZudkFbt1ET4xFd0EshqBETONLmYKu7cYI8IZkrj8hDEQWeEmfC2OD/ns+28 7j8QDbvZF3F+UStwZmQZcjUPWWyGzoXxaeBc+b6yHYoDy3iJ/gbF6aKsEb3IWCFAqjCY mPeeAZn2PoTbsBgjNdPqX+kDCwJeMVVz02dA6RGsakbncmCjQmzuyN7i+c4x6VY/1Fkg oGGf9vfll8tA7CWfO2ntjgErfVSrA7nQXjNngni7LFBiRDN0pSXCcn4ha3D0m6XohpuO d13Q== X-Forwarded-Encrypted: i=1; AJvYcCVvvR9zEFuQsXrTM9ttEoabdmpoWP31Vg9S+5o+LF29UVtpE1DnjbaWIe+sVlPh/jEj8MQGiSI2WOLrdBYV@vger.kernel.org, AJvYcCWyc/wFLrWazs3smTQuBhzHjsI6Ek/wMngaxtXkrSQnOdSnsXxlga44JOWcqYId4hj1/IuVYu0vwGNwLJQVcQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yw39INQ+FhXQ5yfgyxaZTkP7X4OaplSQXwQRYmVxOLEaQb+wKzO lFjr0+QIvUe5q+M0a4Vlqo9ErQM1KdXC+TjoeiXXlNRaxp203N3J X-Google-Smtp-Source: AGHT+IHPSYFEOYp0L/8lai/SrQvHB1cR2jSj0zB/qZ8RZMg1q8kWtmyrE+NWgASfsj3tmXGk40hj+g== X-Received: by 2002:a05:6512:1094:b0:539:9720:99dc with SMTP id 2adb3069b0e04-539ab9cf404mr1990287e87.46.1728037426876; Fri, 04 Oct 2024 03:23:46 -0700 (PDT) Received: from amir-ThinkPad-T480.arnhem.chello.nl (92-109-99-123.cable.dynamic.v4.ziggo.nl. [92.109.99.123]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99100a37cdsm207335066b.3.2024.10.04.03.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 03:23:46 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi , Al Viro Cc: Christian Brauner , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH 1/4] ovl: do not open non-data lower file for fsync Date: Fri, 4 Oct 2024 12:23:39 +0200 Message-Id: <20241004102342.179434-2-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241004102342.179434-1-amir73il@gmail.com> References: <20241004102342.179434-1-amir73il@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ovl_fsync() with !datasync opens a backing file from the top most dentry in the stack, checks if this dentry is non-upper and skips the fsync. In case of an overlay dentry stack with lower data and lower metadata above it, but without an upper metadata above it, the backing file is opened from the top most lower metadata dentry and never used. Fix the helper ovl_real_fdget_meta() to return an empty struct fd in that case to avoid the unneeded backing file open. Signed-off-by: Amir Goldstein --- fs/overlayfs/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 4504493b20be..3d64d00ef981 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -90,17 +90,19 @@ static int ovl_change_flags(struct file *file, unsigned int flags) } static int ovl_real_fdget_meta(const struct file *file, struct fd *real, - bool allow_meta) + bool upper_meta) { struct dentry *dentry = file_dentry(file); struct file *realfile = file->private_data; struct path realpath; int err; - real->word = (unsigned long)realfile; + real->word = 0; - if (allow_meta) { - ovl_path_real(dentry, &realpath); + if (upper_meta) { + ovl_path_upper(dentry, &realpath); + if (!realpath.dentry) + return 0; } else { /* lazy lookup and verify of lowerdata */ err = ovl_verify_lowerdata(dentry); @@ -395,7 +397,7 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) return ret; ret = ovl_real_fdget_meta(file, &real, !datasync); - if (ret) + if (ret || fd_empty(real)) return ret; /* Don't sync lower file for fear of receiving EROFS error */ From patchwork Fri Oct 4 10:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13822050 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E63C5155306; Fri, 4 Oct 2024 10:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037431; cv=none; b=d/ta9JUSbYwZR1IrH4Hw2gas/qkkTphVINFABQcMM7cKFiXdod5itn2aRd3ZymGl7A1hBbgaACV8vvYKTSajVLdf30ZZ0K2W15WB3DYmXjrWoh1UvI430qev1naPnPd00TobeRkYYDNCxAk8gD0nHKiGEuzrnfscyeL7U6k/OV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037431; c=relaxed/simple; bh=BXkzaglW4+jRuPwhZoh/aebYfKiekhmAu9qGUL7LW9o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MwpBHS3gIvOHaIUWLfmiTfx+LV8km0uijJnz39aiCjpE0/2Ev72HuUfO10Qft93lPaijh3yUKNadOwLctB2L9J/ZLEZMwDldg+Oyi2hMB/NK5jZS7p00XBDH7FSVBKyBvJ7psZPWCqQmpgp7rqM22hXjIKNoiY63oM9R9o+XFGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HUqTvUFf; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HUqTvUFf" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5c89e66012aso2361765a12.2; Fri, 04 Oct 2024 03:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728037428; x=1728642228; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BWP0jpAoiej3BcoDH86TODk7hrmTa/gBacoaHbjPjx4=; b=HUqTvUFfN/pYXZungZtexWgVCxqmdDwvh43Q6kWTBXN2fuLW6vvKCJVP5MZ2WOcOLH gFdXKieacgZUWAsx+QNisDzVtBXjdrd7N6dfYhIaOyPLhPGD+IWPQO/bsJsZF6Vu6B9z nwqOY71y2Q4A1O3Fa6lt6Eiv25zu+h6Y36zxXD/EBa37i5LCUo/AjZTF0cOFhEDhsOcp CIfTyj+r4Fcjbslgn0vJayPf3wBXhBUX73roblBkHnp7JbilUlJ+IpBXjxg4QHHn3azm lnxljwJk4GMrkILCNkpscrn9orJCtqvg+qdtOp25SjlLG9l/2JWITh+uIdZ4vUrv/qTy BqeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728037428; x=1728642228; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BWP0jpAoiej3BcoDH86TODk7hrmTa/gBacoaHbjPjx4=; b=ORoxzOTno4oBdXwzgklfU8orpcQ3HPYIr+PjHKKNuwTxesMpxxSj/e+FDjVEKl3KsY wilm58DUwMJWlmaogy7Klx8FE/7yzJhWWOMlxv0aMZM/Z6selCnM6/VwVvr0yveqfg6+ PzF2+xN0KCqFYFSm5Js80gE8TACB2Ez0EbELvlgi1hsysUNDXPSb/b30GdJG58bmTUdD uBaa+6Wzm7WhcIhryTIr2tnsu4OGFiy0UaVGvhNVEzxlXWAotqzmS5vlw/SPco5zoYiQ 3tbwtbOsGTXEahBCQVU+fJgrbiGneveRhBVN3utAEfJ//r/xJQiwAAJVjmH8h5h/RrLl eZ6g== X-Forwarded-Encrypted: i=1; AJvYcCUrIn4tE8a4sQJObxmAjCq3uj1kJhiovYZ8t6LjGpxsUY/j3PCRVSG4xZ8kRl/hmkLxTImf0EGnHnr/hykkvQ==@vger.kernel.org, AJvYcCXjsr/Wyelm9jTBKU8R6mswGe0cUa7ZycvBJMcxmi2/cGozeijI5m+XVZFLpoyaoihb9QliCwu8pmTDPb5D@vger.kernel.org X-Gm-Message-State: AOJu0Yxg1X92Nv1N+hAVsEg6kjhB4tOSR+YGrNif658TXXzyxVXnO77F YNuvUqbRXzo+32obhBY7jAWpoolZxLnC3aNrYJTksHfx9e6big5C X-Google-Smtp-Source: AGHT+IGqOQCnt2QrDxppRqjbEx4D/Npv0apCuoH4OR7s/N41fTbasVxZGDbiUaBYHZl8mbdyZFuySw== X-Received: by 2002:a17:907:9726:b0:a8d:5472:b591 with SMTP id a640c23a62f3a-a991bce5c40mr233674166b.5.1728037427655; Fri, 04 Oct 2024 03:23:47 -0700 (PDT) Received: from amir-ThinkPad-T480.arnhem.chello.nl (92-109-99-123.cable.dynamic.v4.ziggo.nl. [92.109.99.123]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99100a37cdsm207335066b.3.2024.10.04.03.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 03:23:47 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi , Al Viro Cc: Christian Brauner , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH 2/4] ovl: stash upper real file in backing_file struct Date: Fri, 4 Oct 2024 12:23:40 +0200 Message-Id: <20241004102342.179434-3-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241004102342.179434-1-amir73il@gmail.com> References: <20241004102342.179434-1-amir73il@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When an overlayfs file is opened as lower and then the file is copied up, every operation on the overlayfs open file will open a temporary backing file to the upper dentry and close it at the end of the operation. The original (lower) real file is stored in file->private_data pointer. We could have allocated a struct ovl_real_file to potentially store two backing files, the lower and the upper, but the original backing file struct is not very space optimized (it has no memcache pool), so add a private_data pointer to the backing_file struct and store the optional second backing upper file in there instead of opening a temporary upper file on every operation. Signed-off-by: Amir Goldstein --- fs/file_table.c | 7 +++++++ fs/internal.h | 6 ++++++ fs/overlayfs/file.c | 48 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index eed5ffad9997..1c2c08a5a66a 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -47,6 +47,7 @@ static struct percpu_counter nr_files __cacheline_aligned_in_smp; struct backing_file { struct file file; struct path user_path; + void *private_data; }; static inline struct backing_file *backing_file(struct file *f) @@ -60,6 +61,12 @@ struct path *backing_file_user_path(struct file *f) } EXPORT_SYMBOL_GPL(backing_file_user_path); +void **backing_file_private_ptr(struct file *f) +{ + return &backing_file(f)->private_data; +} +EXPORT_SYMBOL_GPL(backing_file_private_ptr); + static inline void file_free(struct file *f) { security_file_free(f); diff --git a/fs/internal.h b/fs/internal.h index 8c1b7acbbe8f..b1152a3e8ba2 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -100,6 +100,12 @@ extern void chroot_fs_refs(const struct path *, const struct path *); struct file *alloc_empty_file(int flags, const struct cred *cred); struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred); struct file *alloc_empty_backing_file(int flags, const struct cred *cred); +void **backing_file_private_ptr(struct file *f); + +static inline void *backing_file_private(struct file *f) +{ + return READ_ONCE(*backing_file_private_ptr(f)); +} static inline void file_put_write_access(struct file *file) { diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 3d64d00ef981..60a543b9a834 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -14,6 +14,8 @@ #include #include "overlayfs.h" +#include "../internal.h" /* for backing_file_private{,_ptr}() */ + static char ovl_whatisit(struct inode *inode, struct inode *realinode) { if (realinode != ovl_inode_upper(inode)) @@ -94,6 +96,7 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, { struct dentry *dentry = file_dentry(file); struct file *realfile = file->private_data; + struct file *upperfile = backing_file_private(realfile); struct path realpath; int err; @@ -114,15 +117,37 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, if (!realpath.dentry) return -EIO; - /* Has it been copied up since we'd opened it? */ +stashed_upper: + if (upperfile && file_inode(upperfile) == d_inode(realpath.dentry)) + realfile = upperfile; + + /* + * If realfile is lower and has been copied up since we'd opened it, + * open the real upper file and stash it in backing_file_private(). + */ if (unlikely(file_inode(realfile) != d_inode(realpath.dentry))) { - struct file *f = ovl_open_realfile(file, &realpath); - if (IS_ERR(f)) - return PTR_ERR(f); - real->word = (unsigned long)f | FDPUT_FPUT; - return 0; + struct file *old; + + /* Stashed upperfile has a mismatched inode */ + if (unlikely(upperfile)) + return -EIO; + + upperfile = ovl_open_realfile(file, &realpath); + if (IS_ERR(upperfile)) + return PTR_ERR(upperfile); + + old = cmpxchg_release(backing_file_private_ptr(realfile), NULL, + upperfile); + if (old) { + fput(upperfile); + upperfile = old; + } + + goto stashed_upper; } + real->word = (unsigned long)realfile; + /* Did the flags change since open? */ if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS)) return ovl_change_flags(realfile, file->f_flags); @@ -177,7 +202,16 @@ static int ovl_open(struct inode *inode, struct file *file) static int ovl_release(struct inode *inode, struct file *file) { - fput(file->private_data); + struct file *realfile = file->private_data; + struct file *upperfile = backing_file_private(realfile); + + fput(realfile); + /* + * If realfile is lower and file was copied up and accessed, we need + * to put reference also on the stashed real upperfile. + */ + if (upperfile) + fput(upperfile); return 0; } From patchwork Fri Oct 4 10:23:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13822051 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27F8B145B11; Fri, 4 Oct 2024 10:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037433; cv=none; b=qVuMo4QIOpKEW9olTQ1EbWe9wvrtMIYc2zqfjRENO69igsrI7bdM+zc8UlOdw+NZ/IyNN74B3HrRl8tDS0F+oyeUNqfZR8WkSHpu/A0Km8vrR+Ez9wRIBtDMfXlNRNkdAPrbYxr+arhSYWuMhsOAbdPQ9Y8at/9eLMxLBAOHsiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037433; c=relaxed/simple; bh=pmc6qVUuMt/Z2bdiNOPAxptw/xU6ldFSqxts+MtiBqw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BXritaMjQHLj9kb5O9DPFUEtn1x80c4+3Y9q9P2pOmybou+1bi7H1I9dDsSrcVChnIYUX81JCgqJN8K3vevv7y0dkBdH8XGha2aQ4N1eh5FA1nZG5QZ7FIbu2YCZ4h5KqRoRTXbo3nvweKJq3GFVOoyYBMBUdQKkqE58tqKFhiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nYNOm0hJ; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nYNOm0hJ" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5398ec2f3c3so2533023e87.1; Fri, 04 Oct 2024 03:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728037429; x=1728642229; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CFRCww6R0ZI7wB7Odoqmaxpyf51HejdOq9ZuRGiYTYA=; b=nYNOm0hJZu8rD3d6p9YN3WijmqBmzH86MJyvvWwTw0t9/PUjhKGkf7s5/mHYDUkpDH D1+yWGbfeSZ3Y+oSDUYcejJvVS8Etx7UyT/3lrTIztDXxxwzt1k6oAd7mtDo6kVypYpG miyyDrOKi5AHOdmpQe7J/H8MjdYwIqywOCqc4qai/dCvIvsuVioTZmLWliwsAsNR8nh5 fZA7U8HVMHHilVhZ4nWEOMu7mgrHv+wmIpgGpNGbAxN0jnPhhtVC6dYD0sXVxwf6axqr MHeo4+aLWkn6BupkXkUHKMgi2FNDzP11OhDWIOCqnFAqnzkvnK5QRb+yf3MmIUGiGR/o scLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728037429; x=1728642229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CFRCww6R0ZI7wB7Odoqmaxpyf51HejdOq9ZuRGiYTYA=; b=dLfG6GEHwweqXO0aPzdCFhufL6jLLuxO1gsCs2hHfF/0jlPGwP1f8Ukexk5VjXstkQ zo4AC8tSu1YgJo4AfZPFIiseaXWFE24B5Lw+4IPXkCtNIBIM+W4EOgP3/R8lPhAbsjv9 ehDhkuXSqsUA3t3WUvCvKnGckRfwtZ0bfXX679PEjyN+CIDF5T7OpdhY0DrtMnH4XP49 RqhLO6N58BZ1S9vXPtTku+u07QMl7mdBafU1kFtoqdl1Lf7Ocux0HiSKhSc0RjslX9Hz APyBvnbRl9APdNspKsZ2UkDJhkeGYwSRdzu4Oc/F7hRbYoiZEnnck6qUjG92zoQERxCj 5/yA== X-Forwarded-Encrypted: i=1; AJvYcCUKOu5pD8Hs0L7URMr5VPbHNv85t89on93xFCNNh+5NL/TyZUpZSAXG12QgfDaFeUq0faaEB5EeB9aY4GCE@vger.kernel.org, AJvYcCX9VF+86mdqXsoQinOxP1h0Hhs+V6uRt9k/rZlGJS/04eFNG9zKxmpjzUAiWbQWBQOC8kRzmK56rm+3+2KGnA==@vger.kernel.org X-Gm-Message-State: AOJu0Yxku/dLvqTtKN4d6xoTWQ6RpqVQuiJJX0DvFlQoxd/3v2p74IiP SRU8E1dwveCZNZpivYXPVacieauZFnC5Qi0H+kSuA50GA1ET5cqT X-Google-Smtp-Source: AGHT+IFmgnU6UxU+S8DwCSlcYkAC/+/F4OuiK10jHrCEX7FZ2FoLDvsdZTC3INRs9H4hBoIqQXmN4w== X-Received: by 2002:a05:6512:3089:b0:539:918c:5124 with SMTP id 2adb3069b0e04-539ab88d663mr1299098e87.31.1728037428420; Fri, 04 Oct 2024 03:23:48 -0700 (PDT) Received: from amir-ThinkPad-T480.arnhem.chello.nl (92-109-99-123.cable.dynamic.v4.ziggo.nl. [92.109.99.123]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99100a37cdsm207335066b.3.2024.10.04.03.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 03:23:48 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi , Al Viro Cc: Christian Brauner , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH 3/4] ovl: convert ovl_real_fdget_meta() callers to ovl_real_file_meta() Date: Fri, 4 Oct 2024 12:23:41 +0200 Message-Id: <20241004102342.179434-4-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241004102342.179434-1-amir73il@gmail.com> References: <20241004102342.179434-1-amir73il@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Stop using struct fd to return a real file from ovl_real_fdget_meta(), because we no longer return a temporary file object and the callers always get a borrowed file reference. Rename the helper to ovl_real_file_meta(), return a borrowed reference of the real file that is referenced from the overlayfs file or an error. Signed-off-by: Amir Goldstein --- fs/overlayfs/file.c | 62 ++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 60a543b9a834..d383ff22ccdb 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -91,8 +91,7 @@ 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, - bool upper_meta) +static struct file *ovl_real_file_meta(const struct file *file, bool upper_meta) { struct dentry *dentry = file_dentry(file); struct file *realfile = file->private_data; @@ -100,22 +99,20 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, struct path realpath; int err; - real->word = 0; - if (upper_meta) { ovl_path_upper(dentry, &realpath); if (!realpath.dentry) - return 0; + return NULL; } else { /* lazy lookup and verify of lowerdata */ err = ovl_verify_lowerdata(dentry); if (err) - return err; + return ERR_PTR(err); ovl_path_realdata(dentry, &realpath); } if (!realpath.dentry) - return -EIO; + return ERR_PTR(-EIO); stashed_upper: if (upperfile && file_inode(upperfile) == d_inode(realpath.dentry)) @@ -130,11 +127,11 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, /* Stashed upperfile has a mismatched inode */ if (unlikely(upperfile)) - return -EIO; + return ERR_PTR(-EIO); upperfile = ovl_open_realfile(file, &realpath); if (IS_ERR(upperfile)) - return PTR_ERR(upperfile); + return upperfile; old = cmpxchg_release(backing_file_private_ptr(realfile), NULL, upperfile); @@ -146,26 +143,31 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, goto stashed_upper; } - real->word = (unsigned long)realfile; - /* Did the flags change since open? */ - if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS)) - return ovl_change_flags(realfile, file->f_flags); + if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS)) { + err = ovl_change_flags(realfile, file->f_flags); + if (err) + return ERR_PTR(err); + } - return 0; + return realfile; } -static int ovl_real_fdget(const struct file *file, struct fd *real) +static struct file *ovl_real_file(const struct file *file) { - if (d_is_dir(file_dentry(file))) { - struct file *f = ovl_dir_real_file(file, false); - if (IS_ERR(f)) - return PTR_ERR(f); - real->word = (unsigned long)f; - return 0; - } + if (d_is_dir(file_dentry(file))) + return ovl_dir_real_file(file, false); - return ovl_real_fdget_meta(file, real, false); + return ovl_real_file_meta(file, false); +} + +static int ovl_real_fdget(const struct file *file, struct fd *real) +{ + struct file *f = ovl_real_file(file, false); + if (IS_ERR(f)) + return PTR_ERR(f); + real->word = (unsigned long)f; + return 0; } static int ovl_open(struct inode *inode, struct file *file) @@ -422,7 +424,7 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) { - struct fd real; + struct file *realfile; const struct cred *old_cred; int ret; @@ -430,19 +432,17 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) if (ret <= 0) return ret; - ret = ovl_real_fdget_meta(file, &real, !datasync); - if (ret || fd_empty(real)) - return ret; + realfile = ovl_real_file_meta(file, !datasync); + if (IS_ERR_OR_NULL(realfile)) + return PTR_ERR(realfile); /* Don't sync lower file for fear of receiving EROFS error */ - if (file_inode(fd_file(real)) == ovl_inode_upper(file_inode(file))) { + if (file_inode(realfile) == ovl_inode_upper(file_inode(file))) { old_cred = ovl_override_creds(file_inode(file)->i_sb); - ret = vfs_fsync_range(fd_file(real), start, end, datasync); + ret = vfs_fsync_range(realfile, start, end, datasync); revert_creds(old_cred); } - fdput(real); - return ret; } From patchwork Fri Oct 4 10:23:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 13822052 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05CE4145B11; Fri, 4 Oct 2024 10:24:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037444; cv=none; b=G40mnLCJ7oARK0Vmn8+fqZYGY/i8UV7x2yYc3tACiwpVng9ZeR6sc4XIAlUmntjxnJlO/R0ry/M8VDEZU2X/1nWcqM3C1488Stw8N2SgxkXbsYDSoP1I3RuJmtKp8eyHlmwWcpyaOmObrQ/7ryP0RXu95sDZtoY1z+qRxMwjvGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728037444; c=relaxed/simple; bh=mZkNETqk3L5qcV3oVOG2OSF89PmnYqWEQb+x8gdH1jw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fN2Fj590h0sxHlim4kn1HDPNrt12e9wCKVq5XcRWWnIO3k/8BAuKt18fMzrGW1427Rw0oHwPbpjVNz+covRFJNJ5obxN0+Ao0Ntwn8CNbsD0ztEBN5HF9j3PEZr2YWi3I0xUo7BUQtO+4q1/BY1UgSITAl8tHsZuCTU6cqdP+V0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lZxpNsfM; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lZxpNsfM" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5398e53ca28so2236613e87.3; Fri, 04 Oct 2024 03:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728037440; x=1728642240; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iQ51HK7ZBpY9mejueCfZmXcDg20vSQo6CoBW7kNlEiE=; b=lZxpNsfM8HCDm+VLKUVTNy/LCR6tQKlV0pb8dItDKO+9kDr/Ms3EPBbYVc/yt8TuM0 +UZC+V1GK/xtgmGeEDPMKzuPExyNSTOYIPMv8b+3RTjOTp4Sh6e+cKK7DKY2BrOcUpnK jnYL2mJRbPxYNv3hwWhROSE5ShhLcIvIwIjFbxagNQmj3NhEeBxkjReKyXCw4O1dyqpD i+izg2syeilBDG3lQzh0Bl4MOWkK9lJRvdNPKFFd+0sp7u0vZ8PyrrVmuKnuYQMbLvos miuM277MHEp+E7ycWpmCCQwDx8l36d4nTM1s729HJX/7r7PVYhTGceYqRF6vhv3MEwe0 zQDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728037440; x=1728642240; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iQ51HK7ZBpY9mejueCfZmXcDg20vSQo6CoBW7kNlEiE=; b=a8noejBDZXg5nmBXO7V4q7lAartMJ9xNYrz/dhv59LeyGSHdsJRhd4YiU5FTgVxtrz XdE7YoONUxg3wqUdw0FbB1crRmjqIWzugISDPh9nyGkk6NtrmDIig2BjMJyLWSI/QcQq C5146Mn/vXzemBaomHdL2L8FzI3b90IsMtYHtcKTxXPtcm0qJAZF3a1dWm5UyExejTqr lUYs4Z0NIwsdqUN4SJRn9+kNdAHEjeWZOKZ6d1BEpeuZu3d6RCrJ/QlNPiy5NQyfeSQe EJUdZUnnjJPUabKVUcnjEPyce1+tdWjGwVwDgxEsfh6DbowX1P21svEPRYH0hZQ+PihY jSUw== X-Forwarded-Encrypted: i=1; AJvYcCUAUIXkpv9Y+6gafsAW4q6+aE8OPPk4VAxw9G8CpHBvmifK1qpTuF+RcTcx9UFy+vJ9ti5j29ABkMrOr4E8@vger.kernel.org, AJvYcCUkuPrCciQHrzzVCyL38HXYop62G8NDQH5wE+KSX5an6s0AeD3giJBI+Uge6EhkJWRJG7oM3V/kCu9Q5TcK2w==@vger.kernel.org X-Gm-Message-State: AOJu0YyqnOALsWrlzTPUFH6a59ZyE7nG8I+fdrQ+cJBZ8uGyQ571hZ9/ fmm1EB1u1FMcXA235WUUi8LytmVxtRr4mDyLkl+yPYONPU7VLP2JQxXya5j/ X-Google-Smtp-Source: AGHT+IG15En7S3WYFXfhSjChlhSzHfeE82pRUDE6Gh7e3SVfbcfbHSLUn7/HINMyC9Dtzc8TJGZ7+Q== X-Received: by 2002:a17:906:dc93:b0:a99:bb:737b with SMTP id a640c23a62f3a-a991c077e09mr255393966b.55.1728037429199; Fri, 04 Oct 2024 03:23:49 -0700 (PDT) Received: from amir-ThinkPad-T480.arnhem.chello.nl (92-109-99-123.cable.dynamic.v4.ziggo.nl. [92.109.99.123]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99100a37cdsm207335066b.3.2024.10.04.03.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 03:23:48 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi , Al Viro Cc: Christian Brauner , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH 4/4] ovl: convert ovl_real_fdget() callers to ovl_real_file() Date: Fri, 4 Oct 2024 12:23:42 +0200 Message-Id: <20241004102342.179434-5-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241004102342.179434-1-amir73il@gmail.com> References: <20241004102342.179434-1-amir73il@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Stop using struct fd to return a real file from ovl_real_fdget(), because we no longer return a temporary file object and the callers always get a borrowed file reference. Rename the helper to ovl_real_file(), return a borrowed reference of the real file that is referenced from the overlayfs file or an error. Signed-off-by: Amir Goldstein --- fs/overlayfs/file.c | 142 ++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 84 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index d383ff22ccdb..b8581c253d45 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -161,15 +161,6 @@ static struct file *ovl_real_file(const struct file *file) return ovl_real_file_meta(file, false); } -static int ovl_real_fdget(const struct file *file, struct fd *real) -{ - struct file *f = ovl_real_file(file, false); - if (IS_ERR(f)) - return PTR_ERR(f); - real->word = (unsigned long)f; - return 0; -} - static int ovl_open(struct inode *inode, struct file *file) { struct dentry *dentry = file_dentry(file); @@ -221,7 +212,7 @@ static int ovl_release(struct inode *inode, struct file *file) static loff_t ovl_llseek(struct file *file, loff_t offset, int whence) { struct inode *inode = file_inode(file); - struct fd real; + struct file *realfile; const struct cred *old_cred; loff_t ret; @@ -237,9 +228,9 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence) return vfs_setpos(file, 0, 0); } - ret = ovl_real_fdget(file, &real); - if (ret) - return ret; + realfile = ovl_real_file(file); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); /* * Overlay file f_pos is the master copy that is preserved @@ -249,17 +240,15 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence) * files, so we use the real file to perform seeks. */ ovl_inode_lock(inode); - fd_file(real)->f_pos = file->f_pos; + realfile->f_pos = file->f_pos; old_cred = ovl_override_creds(inode->i_sb); - ret = vfs_llseek(fd_file(real), offset, whence); + ret = vfs_llseek(realfile, offset, whence); revert_creds(old_cred); - file->f_pos = fd_file(real)->f_pos; + file->f_pos = realfile->f_pos; ovl_inode_unlock(inode); - fdput(real); - return ret; } @@ -300,8 +289,7 @@ static void ovl_file_accessed(struct file *file) static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) { struct file *file = iocb->ki_filp; - struct fd real; - ssize_t ret; + struct file *realfile; struct backing_file_ctx ctx = { .cred = ovl_creds(file_inode(file)->i_sb), .user_file = file, @@ -311,22 +299,19 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) if (!iov_iter_count(iter)) return 0; - ret = ovl_real_fdget(file, &real); - if (ret) - return ret; - - ret = backing_file_read_iter(fd_file(real), iter, iocb, iocb->ki_flags, - &ctx); - fdput(real); + realfile = ovl_real_file(file); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); - return ret; + return backing_file_read_iter(realfile, iter, iocb, iocb->ki_flags, + &ctx); } 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; + struct file *realfile; ssize_t ret; int ifl = iocb->ki_flags; struct backing_file_ctx ctx = { @@ -342,8 +327,9 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) /* Update mode */ ovl_copyattr(inode); - ret = ovl_real_fdget(file, &real); - if (ret) + realfile = ovl_real_file(file); + ret = PTR_ERR(realfile); + if (IS_ERR(realfile)) goto out_unlock; if (!ovl_should_sync(OVL_FS(inode->i_sb))) @@ -354,8 +340,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) * this property in case it is set by the issuer. */ ifl &= ~IOCB_DIO_CALLER_COMP; - ret = backing_file_write_iter(fd_file(real), iter, iocb, ifl, &ctx); - fdput(real); + ret = backing_file_write_iter(realfile, iter, iocb, ifl, &ctx); out_unlock: inode_unlock(inode); @@ -367,28 +352,24 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { - struct fd real; - ssize_t ret; + struct file *realfile; struct backing_file_ctx ctx = { .cred = ovl_creds(file_inode(in)->i_sb), .user_file = in, .accessed = ovl_file_accessed, }; - ret = ovl_real_fdget(in, &real); - if (ret) - return ret; - - ret = backing_file_splice_read(fd_file(real), ppos, pipe, len, flags, &ctx); - fdput(real); + realfile = ovl_real_file(in); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); - return ret; + return backing_file_splice_read(realfile, ppos, pipe, len, flags, &ctx); } /* * Calling iter_file_splice_write() directly from overlay's f_op may deadlock * due to lock order inversion between pipe->mutex in iter_file_splice_write() - * and file_start_write(fd_file(real)) in ovl_write_iter(). + * and file_start_write(realfile) in ovl_write_iter(). * * So do everything ovl_write_iter() does and call iter_file_splice_write() on * the real file. @@ -396,7 +377,7 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, loff_t *ppos, size_t len, unsigned int flags) { - struct fd real; + struct file *realfile; struct inode *inode = file_inode(out); ssize_t ret; struct backing_file_ctx ctx = { @@ -409,12 +390,12 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, /* Update mode */ ovl_copyattr(inode); - ret = ovl_real_fdget(out, &real); - if (ret) + realfile = ovl_real_file(out); + ret = PTR_ERR(realfile); + if (IS_ERR(realfile)) goto out_unlock; - ret = backing_file_splice_write(pipe, fd_file(real), ppos, len, flags, &ctx); - fdput(real); + ret = backing_file_splice_write(pipe, realfile, ppos, len, flags, &ctx); out_unlock: inode_unlock(inode); @@ -461,7 +442,7 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma) static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len) { struct inode *inode = file_inode(file); - struct fd real; + struct file *realfile; const struct cred *old_cred; int ret; @@ -472,19 +453,18 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len if (ret) goto out_unlock; - ret = ovl_real_fdget(file, &real); - if (ret) + realfile = ovl_real_file(file); + ret = PTR_ERR(realfile); + if (IS_ERR(realfile)) goto out_unlock; old_cred = ovl_override_creds(file_inode(file)->i_sb); - ret = vfs_fallocate(fd_file(real), mode, offset, len); + ret = vfs_fallocate(realfile, mode, offset, len); revert_creds(old_cred); /* Update size */ ovl_file_modified(file); - fdput(real); - out_unlock: inode_unlock(inode); @@ -493,20 +473,18 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len static int ovl_fadvise(struct file *file, loff_t offset, loff_t len, int advice) { - struct fd real; + struct file *realfile; const struct cred *old_cred; int ret; - ret = ovl_real_fdget(file, &real); - if (ret) - return ret; + realfile = ovl_real_file(file); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); old_cred = ovl_override_creds(file_inode(file)->i_sb); - ret = vfs_fadvise(fd_file(real), offset, len, advice); + ret = vfs_fadvise(realfile, offset, len, advice); revert_creds(old_cred); - fdput(real); - return ret; } @@ -521,7 +499,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, loff_t len, unsigned int flags, enum ovl_copyop op) { struct inode *inode_out = file_inode(file_out); - struct fd real_in, real_out; + struct file *realfile_in, *realfile_out; const struct cred *old_cred; loff_t ret; @@ -534,31 +512,31 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, goto out_unlock; } - ret = ovl_real_fdget(file_out, &real_out); - if (ret) + realfile_out = ovl_real_file(file_out); + ret = PTR_ERR(realfile_out); + if (IS_ERR(realfile_out)) goto out_unlock; - ret = ovl_real_fdget(file_in, &real_in); - if (ret) { - fdput(real_out); + realfile_in = ovl_real_file(file_in); + ret = PTR_ERR(realfile_in); + if (IS_ERR(realfile_in)) goto out_unlock; - } old_cred = ovl_override_creds(file_inode(file_out)->i_sb); switch (op) { case OVL_COPY: - ret = vfs_copy_file_range(fd_file(real_in), pos_in, - fd_file(real_out), pos_out, len, flags); + ret = vfs_copy_file_range(realfile_in, pos_in, + realfile_out, pos_out, len, flags); break; case OVL_CLONE: - ret = vfs_clone_file_range(fd_file(real_in), pos_in, - fd_file(real_out), pos_out, len, flags); + ret = vfs_clone_file_range(realfile_in, pos_in, + realfile_out, pos_out, len, flags); break; case OVL_DEDUPE: - ret = vfs_dedupe_file_range_one(fd_file(real_in), pos_in, - fd_file(real_out), pos_out, len, + ret = vfs_dedupe_file_range_one(realfile_in, pos_in, + realfile_out, pos_out, len, flags); break; } @@ -567,9 +545,6 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, /* Update size */ ovl_file_modified(file_out); - fdput(real_in); - fdput(real_out); - out_unlock: inode_unlock(inode_out); @@ -613,20 +588,19 @@ static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in, static int ovl_flush(struct file *file, fl_owner_t id) { - struct fd real; + struct file *realfile; const struct cred *old_cred; int err; - err = ovl_real_fdget(file, &real); - if (err) - return err; + realfile = ovl_real_file(file); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); - if (fd_file(real)->f_op->flush) { + if (realfile->f_op->flush) { old_cred = ovl_override_creds(file_inode(file)->i_sb); - err = fd_file(real)->f_op->flush(fd_file(real), id); + err = realfile->f_op->flush(realfile, id); revert_creds(old_cred); } - fdput(real); return err; }