From patchwork Thu Jan 4 17:20:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10145257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B0F96034B for ; Thu, 4 Jan 2018 17:21:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1298728761 for ; Thu, 4 Jan 2018 17:21:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07BD628791; Thu, 4 Jan 2018 17:21:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EE4628761 for ; Thu, 4 Jan 2018 17:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752368AbeADRVU (ORCPT ); Thu, 4 Jan 2018 12:21:20 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34364 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751957AbeADRUp (ORCPT ); Thu, 4 Jan 2018 12:20:45 -0500 Received: by mail-wr0-f196.google.com with SMTP id 36so2149336wrh.1; Thu, 04 Jan 2018 09:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s+4/iLEYfpFKhiX61T48+XqDj1rapVWl2io4Rl6mYcY=; b=AR6G7PrtFKkaHzogo0onjNvmoHu8G3et0RTUHY3+8g1rUt6DKntZk6jkoAEPx+6QR/ ULMEzGoIOTgBpOZQIvfBcjgveMFOnxWPDHeKEHbYLDDeMZdVvoIT6xHGESQ1hEAzGJIZ 05S0MmXBsayWdcxUAiSrVUvT9otsCbpTVtSAJwwg9UOCi3LTY+y85h98qds5UNMlhioe o1jCDnCf1I2JZmA0asGfSDhlEiH9G7jHDcZ3AinMqrd36tBeKBBebigSSUoFUbvCNBax 1wo9QluIb2JB3hVAqNT3AGbagDWq2Pvuy57laEzcCYx6PGJNKDWj1228KcaltbnGw9gR hwSw== 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=s+4/iLEYfpFKhiX61T48+XqDj1rapVWl2io4Rl6mYcY=; b=RgZoR6z1oF5rv7a8fuWBoIlrykm3k0yHKI0RXCDj1wbJacDHa7cbNDrnRZyEu5xl2s oNVfXqlQY46ZM/7ErSsRduNgdDtv3n9/uuK0VtrBVAqcIM1hdJ8VAuAZc+GmB7FnVofV IkYf+/QyeybeQ2X/gnI5w+vXceHcLHgasY/dIGzUW+e39APY1bWbfe7o4k7MLcDZH5Kw g2KGBko8dVRdkPYJEJiU45U5lHgft3zdF8pLrsM3M27+SdV6ZOHIbCM6wvMJP1kOERoo VuGjnSOg0lREhK/yAuaxPdEaa/zOo6079MMg6l9sGnlFMAo7w/RMD+No8uyzgUuH9vC5 xIQA== X-Gm-Message-State: AKGB3mL+ya1XGS1Amcf3W68ZsxS+zjxHdi9opcuXi0ZGFlj4SAH0gR7+ OMIgmJnKxwUY+Yp06HLUuO0= X-Google-Smtp-Source: ACJfBouMtmErtn90u05EVtx2P1EdA+6gejFsLuPuX1dp+4o4PwJmiQ2SU2jE4Y9R10W3pL0cVH6wuw== X-Received: by 10.223.192.76 with SMTP id c12mr245948wrf.260.1515086444145; Thu, 04 Jan 2018 09:20:44 -0800 (PST) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id c6sm2777750wmd.21.2018.01.04.09.20.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jan 2018 09:20:43 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Jeff Layton , "J . Bruce Fields" , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v2 06/17] ovl: copy up before encoding dir file handle when ofs->numlower > 1 Date: Thu, 4 Jan 2018 19:20:38 +0200 Message-Id: <1515086449-26563-7-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515086449-26563-1-git-send-email-amir73il@gmail.com> References: <1515086449-26563-1-git-send-email-amir73il@gmail.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 Decoding a merge dir, whose origin's parent may be on a different lower layer then the overlay parent's origin is not implemented. As a simple aproximation, we do not encode lower dir file handles when overlay has multiple lower layers. Instead, we copy up the lower dir first and then encode an upper dir file handle. Signed-off-by: Amir Goldstein --- fs/overlayfs/export.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c index 919d43aaa387..149cfb5c967e 100644 --- a/fs/overlayfs/export.c +++ b/fs/overlayfs/export.c @@ -26,13 +26,48 @@ * copied up before NFS export was enabled. In that case we don't need to worry * about staying consistent with pre copy up encoding and we encode an upper * file handle. + * + * The following table summarizes the different file handle encodings used for + * different overlay object types with overlay configuration of single and + * multiple lower layers: + * + * Object type | Single lower | Multiple lower + * -------------------------------------------------------- + * Pure upper | U | U + * Non-indexed upper | U | U + * Indexed non-dir | L | L + * Lower non-dir | L | L + * Indexed directory | L | U + * Lower directory | L | U (*) + * + * U = upper file handle + * L = lower file handle + * + * The important thing to note is that within the same overlay configuration + * an overlay object encoding is invariant to copy up (i.e. Lower->Indexed). + * + * (*) If decoding an overlay dir from origin is not implemented, we do not + * encode by lower inode, because if file gets copied up after we encoded it, + * we won't be able to decode the file handle. To mitigate this case, we copy + * up the lower dir first and then encode an upper dir file handle. */ static bool ovl_should_encode_origin(struct dentry *dentry) { + struct ovl_fs *ofs = dentry->d_sb->s_fs_info; + /* Root dentry was born upper */ if (dentry == dentry->d_sb->s_root) return false; + /* + * Decoding a merge dir, whose origin's parent may be on a different + * lower layer then the overlay parent's origin is not implemented. + * As a simple aproximation, we do not encode lower dir file handles + * when overlay has multiple lower layers. + */ + if (d_is_dir(dentry) && ofs->numlower > 1) + return false; + /* Decoding a non-indexed upper from origin is not implemented */ if (ovl_dentry_upper(dentry) && !ovl_test_flag(OVL_INDEX, d_inode(dentry))) @@ -41,16 +76,43 @@ static bool ovl_should_encode_origin(struct dentry *dentry) return true; } +static int ovl_encode_maybe_copy_up(struct dentry *dentry) +{ + int err; + + if (ovl_dentry_upper(dentry)) + return 0; + + err = ovl_want_write(dentry); + if (err) + return err; + + err = ovl_copy_up(dentry); + + ovl_drop_write(dentry); + return err; +} + int ovl_d_to_fh(struct dentry *dentry, char *buf, int buflen) { - struct dentry *upper = ovl_dentry_upper(dentry); + struct dentry *upper; struct dentry *origin = ovl_dentry_lower(dentry); struct ovl_fh *fh = NULL; int err; - if (!ovl_should_encode_origin(dentry)) + /* + * If we should not encode a lower dir file handle, copy up and encode + * an upper dir file handle. + */ + if (!ovl_should_encode_origin(dentry)) { + err = ovl_encode_maybe_copy_up(dentry); + if (err) + goto fail; + origin = NULL; + } + upper = ovl_dentry_upper(dentry); err = -EACCES; if (!upper || origin) goto fail;