From patchwork Mon Aug 3 21:27:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 6933291 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 480A89F358 for ; Mon, 3 Aug 2015 21:33:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6ABC820601 for ; Mon, 3 Aug 2015 21:33:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B686205FF for ; Mon, 3 Aug 2015 21:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932209AbbHCVdp (ORCPT ); Mon, 3 Aug 2015 17:33:45 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:35898 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932144AbbHCVdo (ORCPT ); Mon, 3 Aug 2015 17:33:44 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZMNMe-0008Hw-9x; Mon, 03 Aug 2015 15:33:44 -0600 Received: from 97-119-22-40.omah.qwest.net ([97.119.22.40] helo=x220.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1ZMNMd-000064-Ig; Mon, 03 Aug 2015 15:33:44 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linux Containers Cc: , Al Viro , Andy Lutomirski , "Serge E. Hallyn" , Richard Weinberger , Andrey Vagin , Jann Horn , Willy Tarreau , Omar Sandoval , Miklos Szeredi , Linus Torvalds , "J. Bruce Fields" References: <871tncuaf6.fsf@x220.int.ebiederm.org> <87mw5xq7lt.fsf@x220.int.ebiederm.org> <87a8yqou41.fsf_-_@x220.int.ebiederm.org> <874moq9oyb.fsf_-_@x220.int.ebiederm.org> <871tfkawu9.fsf_-_@x220.int.ebiederm.org> Date: Mon, 03 Aug 2015 16:27:03 -0500 In-Reply-To: <871tfkawu9.fsf_-_@x220.int.ebiederm.org> (Eric W. Biederman's message of "Mon, 03 Aug 2015 16:25:18 -0500") Message-ID: <87k2tc9i6w.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-XM-AID: U2FsdGVkX1+1yVaGOp9NdgiKqxMSiUld6ZtBK2fx+Wk= X-SA-Exim-Connect-IP: 97.119.22.40 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 273 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.8 (1.4%), b_tie_ro: 2.8 (1.0%), parse: 0.85 (0.3%), extract_message_metadata: 11 (4.1%), get_uri_detail_list: 1.34 (0.5%), tests_pri_-1000: 6 (2.2%), tests_pri_-950: 1.29 (0.5%), tests_pri_-900: 1.09 (0.4%), tests_pri_-400: 27 (9.8%), check_bayes: 26 (9.4%), b_tokenize: 7 (2.4%), b_tok_get_all: 8 (3.1%), b_comp_prob: 1.64 (0.6%), b_tok_touch_all: 6 (2.3%), b_finish: 0.71 (0.3%), tests_pri_0: 216 (78.9%), tests_pri_500: 3.9 (1.4%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH review 3/6] dcache: Implement d_common_ancestor X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If possible find the common ancestor of two dentries. This is necessary infrastructure for better handling the case when a dentry is moved out from under the root of a bind mount. Signed-off-by: "Eric W. Biederman" --- fs/dcache.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/dcache.h | 1 + 2 files changed, 38 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index d7fe995dd32d..9f4de1007a8d 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2472,6 +2472,43 @@ void dentry_update_name_case(struct dentry *dentry, struct qstr *name) } EXPORT_SYMBOL(dentry_update_name_case); +static unsigned long d_depth(const struct dentry *dentry) +{ + unsigned long depth = 0; + + while (!IS_ROOT(dentry)) { + dentry = dentry->d_parent; + depth++; + } + return depth; +} + +const struct dentry *d_common_ancestor(const struct dentry *left, + const struct dentry *right) +{ + unsigned long ldepth = d_depth(left); + unsigned long rdepth = d_depth(right); + + while (ldepth > rdepth) { + left = left->d_parent; + ldepth--; + } + + while (rdepth > ldepth) { + right = right->d_parent; + rdepth--; + } + + while (left != right) { + if (IS_ROOT(left)) + return NULL; + left = left->d_parent; + right = right->d_parent; + } + + return left; +} + static void swap_names(struct dentry *dentry, struct dentry *target) { if (unlikely(dname_external(target))) { diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 52a5e6915f58..56de8288cdee 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -313,6 +313,7 @@ extern void dentry_update_name_case(struct dentry *, struct qstr *); extern void d_move(struct dentry *, struct dentry *); extern void d_exchange(struct dentry *, struct dentry *); extern struct dentry *d_ancestor(struct dentry *, struct dentry *); +extern const struct dentry *d_common_ancestor(const struct dentry *, const struct dentry *); /* appendix may either be NULL or be used for transname suffixes */ extern struct dentry *d_lookup(const struct dentry *, const struct qstr *);