From patchwork Thu Sep 3 09:12:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xuw2015@gmail.com X-Patchwork-Id: 7115471 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 17DDF9F36E for ; Thu, 3 Sep 2015 09:12:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49A5E2080C for ; Thu, 3 Sep 2015 09:12:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58D692076B for ; Thu, 3 Sep 2015 09:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752934AbbICJMT (ORCPT ); Thu, 3 Sep 2015 05:12:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60683 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752922AbbICJMT (ORCPT ); Thu, 3 Sep 2015 05:12:19 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 1419CA19AD; Thu, 3 Sep 2015 09:12:19 +0000 (UTC) Received: from localhost (dhcp-12-175.nay.redhat.com [10.66.12.175]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t839CHU6013806; Thu, 3 Sep 2015 05:12:18 -0400 From: xuw2015@gmail.com To: linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: George Wang Subject: [PATCH 2/2] ovl: ovl_rename2 should do d_move by itself Date: Thu, 3 Sep 2015 17:12:12 +0800 Message-Id: <1441271532-10386-2-git-send-email-xuw2015@gmail.com> In-Reply-To: <1441271532-10386-1-git-send-email-xuw2015@gmail.com> References: <1441271532-10386-1-git-send-email-xuw2015@gmail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: George Wang ovl always creates new inode regardless of the fact that upper hardlink shares same inode. If we do rename with dentries shared inode, there is no real opertions, but vfs_rename will do the d_move after that. And an intersting result will appear. The following step will explain it: echo 1234 > src link src tgt rename(src, tgt) rm -f src rm -f tgt In upper level, src(upper) and tgt(upper) shares same inode; in ovl level, src(ovl) and tgt(ovl) uses different inode. vfs_rename did d_move, and dentry src(ovl) is renamed tgt, and dentry tgt(ovl) is released. When unlink src, a new dentry src(ovl) is created, and is removed, src(upper) is also removed; and then unlink tgt, renamed dentry src(ovl) is removed, src(upper) is also removed(but for upper fs, the src has already be removed). ovl should call d_move/d_exchange by itself, then it can control wether or not does it. Signed-off-by: George Wang --- fs/overlayfs/dir.c | 10 ++++++++++ fs/overlayfs/super.c | 1 + 2 files changed, 11 insertions(+) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 692ceda..1b02688 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -915,6 +915,16 @@ static int ovl_rename2(struct inode *olddir, struct dentry *old, ovl_dentry_version_inc(old->d_parent); ovl_dentry_version_inc(new->d_parent); + /* + *FS_RENAME_DOES_D_MOVE is set in fs_flags, we need to do d_move/d_exchange + *by ourselves. overwrite means no RENAME_EXCHANGE in flags, just do d_move; + *d_exchange otherwise. + */ + if (overwrite) + d_move(old, new); + else + d_exchange(old, new); + out_dput: dput(newdentry); out_unlock: diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 7466ff3..0395653 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -1097,6 +1097,7 @@ static struct file_system_type ovl_fs_type = { .name = "overlay", .mount = ovl_mount, .kill_sb = kill_anon_super, + .fs_flags = FS_RENAME_DOES_D_MOVE, }; MODULE_ALIAS_FS("overlay");