Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3471555imm; Tue, 29 May 2018 07:50:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIEvrv9f4EP4QcD487s7Brzxl1tUiT+C1hvZj9uG4K34SFHCGTu5nBhpfkpLDQ1Vpk4oRvP X-Received: by 2002:a17:902:b110:: with SMTP id q16-v6mr4771259plr.286.1527605412729; Tue, 29 May 2018 07:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527605412; cv=none; d=google.com; s=arc-20160816; b=fyLeZVZ6D9jG2+WXEKzYuMXeAp9QPRUB2D4rEXxV/u7bEaC4XsP+jcpvLlUK7rtBJW 0Uu0gxYN+DYdj6s2yCjaBYt1jETEX711VALOhbLZVawrIiJEANVuqR9jTn7wKHxhVsnv gH4ZiVVjbnKPxX2ltFYvFI4fam87iMCFb1Yq+aNg0soN+io60ZSod4VBLDp8M9tb7HtT +aX94l1PPFKikHkL8qqtAUaxoQDkRdiqY2NHir6RspubR9vv7h3FUADA3xEKdH9km0u8 bTJd5qENIMMlIhvyHjEHN1xc4opqogskzcAiJftS7pK5hASfO3B48/npEpOmmuNp5mfM fKCQ== 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=F527eWQ+7/1ZR5pSgHCOehipcknksX246tZ2xU0d26I=; b=UwTfwnKsjXnxewM0stHcymwy5f2TewNgjzSEBpa4ok/u0aZTPwBR0Mt6Ze35p+jwam pIpCWnDHVXkMdxQhUislbq/kY7LmdrnAviotBuTFe5NHOs1PDP9VCIhAGsBeNnG16oVE E2BZ9S3hJvLPxOmjP9voGMoDpFINlGCsThFBx11F3WxpHDrrk9anubvWldRruyCh+GV/ uh3io/fZXxPplj9AMQjj4X0oOz/ZYyt1nO3EhGdr0sJ7Ubp4ykLP1V3NPdeJCIxaYSjP 2oEj460bohTZrc9rnMFZPVB/xmiINXERi81t0bY4WyuWDKUW8ypKVLCFDIpl01BHbqYW s2Cg== 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 68-v6si32438640pfq.172.2018.05.29.07.49.58; Tue, 29 May 2018 07:50:12 -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 S936493AbeE2OrJ (ORCPT + 99 others); Tue, 29 May 2018 10:47:09 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:56234 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936662AbeE2Oqo (ORCPT ); Tue, 29 May 2018 10:46:44 -0400 Received: by mail-wm0-f50.google.com with SMTP id a8-v6so41346415wmg.5 for ; Tue, 29 May 2018 07:46:44 -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=F527eWQ+7/1ZR5pSgHCOehipcknksX246tZ2xU0d26I=; b=e/jFqiwJ6WvXD3G+PMTzsL+C5pxSn6FIpy74eLr+8i1Hl1gkNBzoKaLeSHRq7eKTrJ qC5/gACPednBeKlKHLVPV8ocIWUPouD5ivKZSUnS5I//L6gfHmzq0B5NS6VRNncV39Lt baYvTvLkcmyocuHroFzK/4q//KofWgylMqlmiIOmXhgaf1YBHzJUPXuZiE8wlqLv7Ebv /XDx5mGO4Xr7qkavSBcwS7TcE0PiD+RQ0Or2BFTdHwIfylnvZYve00Q1ufrg1NAbF+XU f8Zub2i3drgydom5GCXYubJSqxXJ1t73ouXWy+BhsHbMJhw0HB4g3w5Crv2sNdh8Ao1V zOyw== X-Gm-Message-State: ALKqPwe+bQIiQRu6M4DdwW8TDsKPAfJIl7nvRSG2XJt3qRovh9UobXZB 8HEBEKBLwTjEigIB3Z8CLI4/Jw== X-Received: by 2002:a1c:ee58:: with SMTP id m85-v6mr13034485wmh.44.1527605203359; Tue, 29 May 2018 07:46:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 07:46:42 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 23/28] ovl: Set redirect on upper inode when it is linked Date: Tue, 29 May 2018 16:46:07 +0200 Message-Id: <20180529144612.16675-24-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 When we create a hardlink to a metacopy upper file, first the redirect on that inode. Path based lookup will not work with newly created link and redirect will solve that issue. Also use absolute redirect as two hardlinks could be in different directores and relative redirect will not work. I have not put any additional locking around setting redirects while introducing redirects for non-dir files. For now it feels like existing locking is sufficient. If that's not the case, we will have add more locking. Following is my rationale about why do I think current locking seems ok. Basic problem for non-dir files is that more than on dentry could be pointing to same inode and in theory only relying on dentry based locks (d->d_lock) did not seem sufficient. We set redirect upon rename and upon link creation. In both the paths for non-dir file, VFS locks both source and target inodes (->i_rwsem). That means vfs rename and link operations on same source and target can't he happening in parallel (Even if there are multiple dentries pointing to same inode). So that probably means that at a time on an inode, only one call of ovl_set_redirect() could be working and we don't need additional locking in ovl_set_redirect(). ovl_inode->redirect is initialized only when inode is created new. That means it should not race with any other path and setting ovl_inode->redirect should be fine. Reading of ovl_inode->redirect happens in ovl_get_redirect() path. And this called only in ovl_set_redirect(). And ovl_set_redirect() already seemed to be protected using ->i_rwsem. That means ovl_set_redirect() and ovl_get_redirect() on source/target inode should not make progress in parallel and is mutually exclusive. Hence no additional locking required. Now, only case where ovl_set_redirect() and ovl_get_redirect() could race seems to be case of absolute redirects where ovl_get_redirect() has to travel up the tree. In that case we already take d->d_lock and that should be sufficient as directories will not have multiple dentries pointing to same inode. So given VFS locking and current usage of redirect, current locking around redirect seems to be ok for non-dir as well. Once we have the logic to remove redirect when metacopy file gets copied up, then we probably will need additional locking. Signed-off-by: Vivek Goyal Reviewed-by: Amir Goldstein Signed-off-by: Miklos Szeredi --- fs/overlayfs/dir.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 1658961a9762..7063e0f588cc 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -24,6 +24,8 @@ module_param_named(redirect_max, ovl_redirect_max, ushort, 0644); MODULE_PARM_DESC(ovl_redirect_max, "Maximum length of absolute redirect xattr value"); +static int ovl_set_redirect(struct dentry *dentry, bool samedir); + int ovl_cleanup(struct inode *wdir, struct dentry *wdentry) { int err; @@ -656,6 +658,12 @@ static int ovl_link(struct dentry *old, struct inode *newdir, if (err) goto out_drop_write; + if (ovl_is_metacopy_dentry(old)) { + err = ovl_set_redirect(old, false); + if (err) + goto out_drop_write; + } + err = ovl_nlink_start(old, &locked); if (err) goto out_drop_write; -- 2.14.3