From patchwork Tue Oct 17 16:44:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10012459 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 29498600CC for ; Tue, 17 Oct 2017 16:44:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E1D027F94 for ; Tue, 17 Oct 2017 16:44:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12F7227FB7; Tue, 17 Oct 2017 16:44:19 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 813D327F94 for ; Tue, 17 Oct 2017 16:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937052AbdJQQoQ (ORCPT ); Tue, 17 Oct 2017 12:44:16 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:50095 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937059AbdJQQoN (ORCPT ); Tue, 17 Oct 2017 12:44:13 -0400 Received: by mail-wm0-f68.google.com with SMTP id b189so5052977wmd.4; Tue, 17 Oct 2017 09:44:11 -0700 (PDT) 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=doYTFjEInNVooc5jFHTvaMgfjDpkTw0IgCzEZz2XdzM=; b=vQXEM3Z6pTBI9g0LgnJi+GiSoABhyW61K4z4QmbZzzCW1WsCwisReeyQnd4IpZrtCH tsdCDuA3xFPSEo33R+oICnBcLpQVI0Gd6gC9kcnEZryoM56DTVB4JgeieTDQawnPE2th oDHbb91e4FDSWR98jQQ2hZYdU3JfSAvNevyr2DmAb67NCoImG/wsL8V6rVfGLASROX2n t+b1brlmrHvwo2ByvirBeMraXP8nGbD8PMXqwIYbsavTeHi+tz++uHYuVbyCNrBvjPuj VrN09bgAxHhqSYulOGiWRnKXR7tgdZRz8SCnWk7ZaFEW+69WpjqtjAFTOcUfG++Rmqt6 jzkg== 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=doYTFjEInNVooc5jFHTvaMgfjDpkTw0IgCzEZz2XdzM=; b=EMhHvLn06YkV98PrVQhBv3BkMo20Ovrc/87aTlRMAQj7PKhdeaWky+gylEpXsT66R/ MWSVyQKKldUVolUsZI07Mo+SKbbXWtwp60TXRE5wm58+lzhvVqQCRz2toD8tuRq0rbyB AyJWv/CtOXSImuoH9VQx+y0TjSBYG4NcqbmJaYj+CXRHCDSZTquX1H1C/uPkIjC9b4Sk SEyDW+6QFM9ngV4D5Dw9ISC+gzwDkq71Y4anxKzKn92O6Qfd9UeP30arG3O4fBvhW5Bm j6+fKOeGraMuArROtvALMkXqZuHXskW/E5UX5Kjyq03ewiVSczpIbP1V/yKekPgZJUti AjVw== X-Gm-Message-State: AMCzsaVDKmZGI2eiy/jKqfMd3VyHzMHwFx61uMVpQEH7GdwfstBDmTe/ qjSJA4aHcVT7Y4pWdbpydxc= X-Google-Smtp-Source: AOwi7QANXUUboq1kW3chXldBrQxSWnQwzd7PkbQP3eEy/yvZ/uAuYAde8DZm5lJMO8dfqvY43RwfJQ== X-Received: by 10.80.186.111 with SMTP id 44mr18291706eds.179.1508258650974; Tue, 17 Oct 2017 09:44:10 -0700 (PDT) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id c25sm8439979edb.28.2017.10.17.09.44.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Oct 2017 09:44:10 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi Cc: Jeff Layton , "J . Bruce Fields" , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 11/14] ovl: decode non-pure-upper non-connectable file handles Date: Tue, 17 Oct 2017 19:44:28 +0300 Message-Id: <1508258671-10800-12-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508258671-10800-1-git-send-email-amir73il@gmail.com> References: <1508258671-10800-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 When decoding an overlay inode that was encoded by real lower file handle, we first decode the lower file handle, then we check if that lower inode has been copied up and indexed. If index is not found, we try to obtain a non-upper overlay dentry. If index is found, we get the upper inode from index and try to obtain an upper overlay dentry with lower origin. If a whiteout index is found, overlay file handle is treated as stale. Signed-off-by: Amir Goldstein --- fs/overlayfs/export.c | 83 ++++++++++++++++++++++++++++++++++++++++-------- fs/overlayfs/namei.c | 21 ++++++++---- fs/overlayfs/overlayfs.h | 6 +++- 3 files changed, 88 insertions(+), 22 deletions(-) diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c index 476e2a74aca7..f97f68e92eba 100644 --- a/fs/overlayfs/export.c +++ b/fs/overlayfs/export.c @@ -241,25 +241,14 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb, } -static struct dentry *ovl_fh_to_d(struct super_block *sb, struct fid *fid, - int fh_len, int fh_type, bool to_parent) +static struct dentry *ovl_upper_fh_to_d(struct super_block *sb, + struct ovl_fh *fh, bool to_parent) { struct ovl_fs *ofs = sb->s_fs_info; struct vfsmount *mnt = ofs->upper_mnt; struct dentry *upper; - struct ovl_fh *fh = (struct ovl_fh *) fid; - int err; - - /* TODO: handle file handle with parent from different layer */ - if (fh_type != OVL_FILEID_WITHOUT_PARENT) - return ERR_PTR(-EINVAL); - - err = ovl_check_fh_len(fh, fh_len << 2); - if (err) - return ERR_PTR(err); - /* TODO: handle decoding of non pure upper */ - if (!mnt || !(fh->flags & OVL_FH_FLAG_PATH_UPPER)) + if (!mnt) return NULL; upper = ovl_decode_fh(fh, mnt); @@ -288,6 +277,72 @@ static struct dentry *ovl_fh_to_d(struct super_block *sb, struct fid *fid, return ovl_obtain_alias(sb, upper, NULL); } +static struct dentry *ovl_fh_to_d(struct super_block *sb, struct fid *fid, + int fh_len, int fh_type, bool to_parent) +{ + struct ovl_fs *ofs = sb->s_fs_info; + struct dentry *upper = NULL; + struct dentry *index = NULL; + struct dentry *origin = NULL; + struct dentry *dentry = NULL; + struct ovl_fh *fh = (struct ovl_fh *) fid; + int err, i; + + /* TODO: handle file handle with parent from different layer */ + if (fh_type != OVL_FILEID_WITHOUT_PARENT) + return ERR_PTR(-EINVAL); + + err = ovl_check_fh_len(fh, fh_len << 2); + if (err) + return ERR_PTR(err); + + if (fh->flags & OVL_FH_FLAG_PATH_UPPER) + return ovl_upper_fh_to_d(sb, fh, to_parent); + + /* TODO: decode parent from fh_type OVL_FILEID_WITH_PARENT */ + if (to_parent) + return ERR_PTR(-EINVAL); + + /* Find lower layer by UUID and decode */ + for (i = 0; i < ofs->numlower; i++) { + origin = ovl_decode_fh(fh, ofs->lower_mnt[i]); + if (origin) + break; + } + + if (IS_ERR_OR_NULL(origin)) + return origin; + + /* Lookup index by decoded origin */ + index = ovl_lookup_index(ofs->indexdir, NULL, origin); + if (IS_ERR(index)) { + dput(origin); + return index; + } + if (index) { + /* Get upper dentry from index */ + upper = ovl_index_upper(index, ofs->upper_mnt); + err = PTR_ERR(upper); + if (IS_ERR(upper)) + goto out_err; + + err = ovl_verify_origin(upper, origin, false, false); + if (err) + goto out_err; + } + + dentry = ovl_obtain_alias(sb, upper, origin); + +out: + dput(index); + dput(origin); + return dentry; + +out_err: + dentry = ERR_PTR(err); + goto out; +} + static struct dentry *ovl_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index 796c869559a9..0f19c2cf43fc 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -609,11 +609,9 @@ int ovl_get_index_name(struct dentry *origin, struct qstr *name) } -static struct dentry *ovl_lookup_index(struct dentry *dentry, - struct dentry *upper, - struct dentry *origin) +struct dentry *ovl_lookup_index(struct dentry *indexdir, struct dentry *upper, + struct dentry *origin) { - struct ovl_fs *ofs = dentry->d_sb->s_fs_info; struct dentry *index; struct inode *inode; struct qstr name; @@ -624,7 +622,7 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, if (err) return ERR_PTR(err); - index = lookup_one_len_unlocked(name.name, ofs->indexdir, name.len); + index = lookup_one_len_unlocked(name.name, indexdir, name.len); if (IS_ERR(index)) { err = PTR_ERR(index); if (err == -ENOENT) { @@ -645,6 +643,15 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, upper); } goto out_dput; + } else if (ovl_is_whiteout(index) && !upper) { + /* + * When index lookup is called with no upper for decoding an + * overlay file handle, a whiteout index implies that decode + * should treat file handle as stale. + */ + dput(index); + index = ERR_PTR(-ESTALE); + goto out; } else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) || ((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) { /* @@ -870,8 +877,8 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, * TODO: update origin and index in case lower dir has changed and * store new generation number xattr in index for NFS export. */ - if (ctr && ovl_indexdir(dentry->d_sb) && origin) { - index = ovl_lookup_index(dentry, upperdentry, origin); + if (ctr && ofs->indexdir && origin) { + index = ovl_lookup_index(ofs->indexdir, upperdentry, origin); if (IS_ERR(index)) { err = PTR_ERR(index); index = NULL; diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index ffc5a955478e..3a801511d163 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -279,11 +279,15 @@ int ovl_check_origin(struct dentry *upperdentry, struct path *lowerstack, unsigned int *ctrp); int ovl_verify_origin(struct dentry *dentry, struct dentry *origin, bool is_upper, bool set); +struct dentry *ovl_index_upper(struct dentry *index, struct vfsmount *mnt); int ovl_verify_index(struct dentry *index, struct vfsmount *mnt, struct path *lowerstack, unsigned int numlower); int ovl_get_index_name(struct dentry *origin, struct qstr *name); +struct dentry *ovl_lookup_index(struct dentry *indexdir, struct dentry *upper, + struct dentry *origin); int ovl_path_next(int idx, struct dentry *dentry, struct path *path, int *idxp); -struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags); +struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, + unsigned int flags); bool ovl_lower_positive(struct dentry *dentry); /* readdir.c */