From patchwork Wed Oct 12 11:16:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 1689101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=O0XUVelR; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4MnVVC49ytz23k1 for ; Wed, 12 Oct 2022 22:17:07 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229487AbiJLLRG (ORCPT ); Wed, 12 Oct 2022 07:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbiJLLRF (ORCPT ); Wed, 12 Oct 2022 07:17:05 -0400 Received: from mail-vs1-xe2c.google.com (mail-vs1-xe2c.google.com [IPv6:2607:f8b0:4864:20::e2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DA44C1DBD for ; Wed, 12 Oct 2022 04:17:04 -0700 (PDT) Received: by mail-vs1-xe2c.google.com with SMTP id a2so11413523vsc.13 for ; Wed, 12 Oct 2022 04:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=A/QAT4TehrQda82TJZR2XQc7myKiImj4ikJYX2w+0nY=; b=O0XUVelRQxhH9mhfoCV6H3L48ePVjoLA6p363wLOP+KZEEKoF5JLWkrAy1ScpW4kuW 8VoGmp9GFDV4U3Monhak3dT1c+odwYlvOWWHzTsM+ME3CVg78sNEfdWrIft9yGE5q1hi l+wzOFrR36n/wGmq6WZoI3CcRkPlKBUL3Mf9/YMOiXMeMcNnk/ij1INjmKi2Ed9eqxTo BXb93lcemHNxEGGWK0L3XgE3ZSfGpeFLEKMBbRLx0ysA2kHcJTkjsoqWAgeU7W59fam/ jNmVGB05gKOjHY27s1J8GBiIqOig5c82/es3ANkDzVi6c450Nl7QqjoczFTxPJ3rGgVK W/bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=A/QAT4TehrQda82TJZR2XQc7myKiImj4ikJYX2w+0nY=; b=VM/9ffY2OV8fo6Y7tYpKOicPypOn6Un9RoXQOZsGaOQY1vMBZ/gAhxR7YhAMP9Kz8N 1Rb67T+rrNaDh8+vTdgvvvyTgDEKmyQgAD8TB8JrqFO7J9Ub543PTXRK/UlOy08yUxqy EtS3CVm81janhddHllgVpglFluQ1fJp+0QS6Hb0/rj8Ibb4krE578LEAnrWwYDwI+cd8 2a63muxlfDuavyJe4HHJeo2JPpwn6QAo6OVk8k/VMkb4hEUZ2/xCoELn/QCLUsQ1h5wG wlBcZZTu8E4oXyIkXJfG85SL7hR7XAPrsVAbwAtFVTqtFcg4v/MuW43M47WoNgxaiGTx ASHw== X-Gm-Message-State: ACrzQf3ZJEl01h8wpr/1Xexhp4t+/1r0ZTCnH18sf68QGJYJ4N4tjgLy 3SeawREY5e6x40CSQTBIXoi2L+qvnUmyZXnf+PHlFOuY X-Google-Smtp-Source: AMsMyM7JqIo3DCxMqwmEci0dZOInJzSC00xRNHpPKbVLBHuDT6vMGzwqb7ozcgKTRv1teIIoKmv428eQ2R/Dx13eL3c= X-Received: by 2002:a05:6102:5cf:b0:3a7:95ac:fc04 with SMTP id v15-20020a05610205cf00b003a795acfc04mr6523652vsf.17.1665573423217; Wed, 12 Oct 2022 04:17:03 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Wed, 12 Oct 2022 06:16:50 -0500 Message-ID: Subject: patch 5 in dir lease series To: CIFS , ronnie sahlberg X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org I had a merge conflict with patch 5 of the dir lease series and fixed it Is the one attached current From f8590e1a2cb56880919f1a4bed20f6d161921b52 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 12 Oct 2022 06:13:03 -0500 Subject: [PATCH] cifs: find and use the dentry for cached non-root directories also This allows us to use cached attributes for the entries in a cached directory for as long as a lease is held on the directory itself. Previously we have always allowed "used cached attributes for 1 second" but this extends this to the lifetime of the lease as well as making the caching safer. Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French --- fs/cifs/cached_dir.c | 63 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/fs/cifs/cached_dir.c b/fs/cifs/cached_dir.c index e5573d4e2d83..fe88b67c863f 100644 --- a/fs/cifs/cached_dir.c +++ b/fs/cifs/cached_dir.c @@ -5,6 +5,7 @@ * Copyright (c) 2022, Ronnie Sahlberg */ +#include #include "cifsglob.h" #include "cifsproto.h" #include "cifs_debug.h" @@ -59,6 +60,44 @@ static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids, return cfid; } +static struct dentry * +path_to_dentry(struct cifs_sb_info *cifs_sb, const char *path) +{ + struct dentry *dentry; + const char *s, *p; + char sep; + + sep = CIFS_DIR_SEP(cifs_sb); + dentry = dget(cifs_sb->root); + s = path; + + do { + struct inode *dir = d_inode(dentry); + struct dentry *child; + + if (!S_ISDIR(dir->i_mode)) { + dput(dentry); + dentry = ERR_PTR(-ENOTDIR); + break; + } + + /* skip separators */ + while (*s == sep) + s++; + if (!*s) + break; + p = s++; + /* next separator */ + while (*s && *s != sep) + s++; + + child = lookup_positive_unlocked(p, dentry, s - p); + dput(dentry); + dentry = child; + } while (!IS_ERR(dentry)); + return dentry; +} + /* * Open the and cache a directory handle. * If error then *cfid is not initialized. @@ -86,7 +125,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, struct cached_fid *cfid; struct cached_fids *cfids; - if (tcon == NULL || tcon->cfids == NULL || tcon->nohandlecache || is_smb1_server(tcon->ses->server)) return -EOPNOTSUPP; @@ -101,13 +139,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, if (cifs_sb->root == NULL) return -ENOENT; - /* - * TODO: for better caching we need to find and use the dentry also - * for non-root directories. - */ - if (!path[0]) - dentry = cifs_sb->root; - utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); if (!utf16_path) return -ENOMEM; @@ -199,12 +230,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, oparms.fid->mid = le64_to_cpu(o_rsp->hdr.MessageId); #endif /* CIFS_DEBUG2 */ - cfid->tcon = tcon; - if (dentry) { - cfid->dentry = dentry; - dget(dentry); - } - /* BB TBD check to see if oplock level check can be removed below */ if (o_rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE) goto oshr_free; @@ -223,6 +248,16 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, &rsp_iov[1], sizeof(struct smb2_file_all_info), (char *)&cfid->file_all_info)) cfid->file_all_info_is_valid = true; + + if (!path[0]) + dentry = dget(cifs_sb->root); + else { + dentry = path_to_dentry(cifs_sb, path); + if (IS_ERR(dentry)) + goto oshr_free; + } + cfid->dentry = dentry; + cfid->tcon = tcon; cfid->time = jiffies; cfid->is_open = true; cfid->has_lease = true; -- 2.34.1