From patchwork Fri Nov 22 20:39:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrique Carvalho X-Patchwork-Id: 13883609 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4B6717B428 for ; Fri, 22 Nov 2024 20:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732308029; cv=none; b=EJ9i2sSRU3J880bQjHKddhlKF5tMQlV04onHI5aQzTMIgZk4vddfHdiQUAgsH8LIUpZL6lX89THJmwwiDQP7CnEC2qlke20JKbqVu8U7qrjkHBxx6dKb5Zl6KvMVq3XkdhgDiyYH6ueOvYOSupuYixGAY+5W6DMsIZEZgERzLLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732308029; c=relaxed/simple; bh=0PwJN3P6MSeos9IsDuxhVPjeVqsSGd7ZpcCxzxQM7q0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iJCJ8aFbzUiMOIMlE332HzseM7MUomn983BbbwUB15nH61hKHVhpf1MBNx7v/W3cnksz1E5UsLsPfZ5Dmot7unOqyLvLioQJRuL5XKjYdx8BWk/i3TzEqt0nndeMnaIM4zypdWEP6SGUF+jwAp40VhO4qYuamdFKq73M+mIe048= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=gddzncbG; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="gddzncbG" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-432d86a3085so22490165e9.2 for ; Fri, 22 Nov 2024 12:40:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1732308025; x=1732912825; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YnHKWcRlA0I2oh1wz02JZjMuVoTlgYEwJJfYf772VaM=; b=gddzncbGPthjPiC9boYK491rk3qx4ouubdU1iXRLN2t9QmimeHb2fY+oAox4nvY4Aj iMg7SDcxT+LEBO7yGFOPhL1bJ6uUSceIj7wqwUCp9Ha6Xm9doGGN47NYO6PJMxwL04X+ lE0UW4Mrgq6UdctbnsxRQNSseFfKuz/wPHHergm3u9Ykz8ggef99UXiXp9j9gZKLJO5X mEhUukdxul1EwtrsWY4MC1q2nl2UkpRCrjft1XtxozbHuoUJS6sAj11ITLx690fIg7j/ s52ibBCEW2JMjZseaQs/lWZt4Id4BfxrOSf2AJukaydxQST1V3nly8KKZwTtgtXvojoW oVMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732308025; x=1732912825; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YnHKWcRlA0I2oh1wz02JZjMuVoTlgYEwJJfYf772VaM=; b=wdWZpAhQ+qmnM2z1Jmp4WjwpX8gq85LXvmFyePMsWZLgmplyylI2PKD1Xj4ncAxwzH UAQp+ZXNNrGGIh4zmj/P38LcUzsI+eJumFoziCmktUp2ql7/CgQYn0IkxWWD3h3F03nb F1K1YnuiiKvxvkGvJC/661ukDIG5IywiaRvvG4bhFN+3HfNtgdSTPitgSye8WpKVfwEK /SShDxVp6VSrUmHJATKBnTelqqeIWIrgs46IJibr4lOhx8qmJJY08+rYsUADExGxeXg5 7To3rg0Z+mOPoMMOc4HkBdAEX9IxJeRJmxKPQZ6UDisSO6J7gkjsqZooSSMiQWFhphX0 m3yA== X-Forwarded-Encrypted: i=1; AJvYcCXuQR46fevoLKZVHTwuJetvS2TxnJ4B4SzwEzEgUIk2a7Hfvf8mG5V5k8H3T8isZJUuQFVoaXbfs/Db@vger.kernel.org X-Gm-Message-State: AOJu0YyKJT2fNbUfOoHv0GIVprH8FCQdzAo/iUmcey3nqpynohfkrHjd FkUZasIJUzJVN4MO5rbaZp7faqv0Ys7ItyvwmPchPfFtO7OVSYmmyb5fCrqRsZk= X-Gm-Gg: ASbGncuMJsoItS4ZRAXXnewp/i/npEwmdfoOKDboVSyvf9og+Y93Bs/vJuv10ycKINI VyuWpZq5e7BpkX56JMYmsQNZNSMvxK9OZ6eWhdRcM6Nl9ZIba/7WobmszsaOzidxjv5dXY0a0Re oQliKTR6Rt1WR/TrhjFJqN+3EF9v9tWk+vRCM2qtKtmVpl2NLPvPi5D0VIP61MmebfzrIXmQlFo D4UXHlstH6R5SkzwevPEUWIMSM5aK9Zb2hrByodlG7pYJxKspGGoibNilG3cbDt9fhcSg== X-Google-Smtp-Source: AGHT+IFHHBkYnA5nnrnO5MCxjX9DohUXcN8wRaS79IdTXulXBEJPliM+Cog8Hr2G1XQNNfXDGCtPCw== X-Received: by 2002:a05:6000:156b:b0:37d:461d:b1ea with SMTP id ffacd0b85a97d-38260be3c89mr4072336f8f.48.1732308025166; Fri, 22 Nov 2024 12:40:25 -0800 (PST) Received: from localhost.localdomain ([2800:810:5e9:f3c:e019:b39:5a90:cfe]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724de57a3d1sm2053423b3a.194.2024.11.22.12.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 12:40:24 -0800 (PST) From: Henrique Carvalho To: sfrench@samba.org Cc: ematsumiya@suse.de, pc@manguebit.com, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, linux-cifs@vger.kernel.org, Henrique Carvalho Subject: [PATCH 1/2] smb: client: disable directory caching when dir_cache_timeout is zero Date: Fri, 22 Nov 2024 17:39:00 -0300 Message-ID: <20241122203901.283703-1-henrique.carvalho@suse.com> X-Mailer: git-send-email 2.46.0 Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 According to the dir_cache_timeout description, setting it to zero should disable the caching of directory contents. However, even when dir_cache_timeout is zero, some caching related functions are still invoked, and the worker thread is initiated, which is unintended behavior. Fix the issue by setting tcon->nohandlecache to true when dir_cache_timeout is zero, ensuring that directory handle caching is properly disabled. Clean up the code to reflect this change, to improve consistency, and to remove other unnecessary checks. is_smb1_server() check inside open_cached_dir() can be removed because dir caching is only enabled for SMB versions >= 2.0. Signed-off-by: Henrique Carvalho --- fs/smb/client/cached_dir.c | 12 +++++++----- fs/smb/client/cifsproto.h | 2 +- fs/smb/client/connect.c | 10 +++++----- fs/smb/client/misc.c | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c index 8b510c858f4ff..d8b1cf1043c35 100644 --- a/fs/smb/client/cached_dir.c +++ b/fs/smb/client/cached_dir.c @@ -162,15 +162,17 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, const char *npath; int retries = 0, cur_sleep = 1; - if (tcon == NULL || tcon->cfids == NULL || tcon->nohandlecache || - is_smb1_server(tcon->ses->server) || (dir_cache_timeout == 0)) + if (cifs_sb->root == NULL) + return -ENOENT; + + if (tcon == NULL) return -EOPNOTSUPP; ses = tcon->ses; cfids = tcon->cfids; - if (cifs_sb->root == NULL) - return -ENOENT; + if (cfids == NULL) + return -EOPNOTSUPP; replay_again: /* reinitialize for possible replay */ @@ -394,7 +396,7 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon, struct cached_fids *cfids = tcon->cfids; if (cfids == NULL) - return -ENOENT; + return -EOPNOTSUPP; spin_lock(&cfids->cfid_list_lock); list_for_each_entry(cfid, &cfids->entries, entry) { diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index 075985bfb13a8..d89d31b6dd97a 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -530,7 +530,7 @@ extern int CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses); extern struct cifs_ses *sesInfoAlloc(void); extern void sesInfoFree(struct cifs_ses *); -extern struct cifs_tcon *tcon_info_alloc(bool dir_leases_enabled, +extern struct cifs_tcon *tcon_info_alloc(bool enable_dir_cache, enum smb3_tcon_ref_trace trace); extern void tconInfoFree(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace); diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index b227d61a6f205..f74e0b94f848c 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -2593,7 +2593,7 @@ static struct cifs_tcon * cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx) { struct cifs_tcon *tcon; - bool nohandlecache; + bool enable_dir_cache; int rc, xid; tcon = cifs_find_tcon(ses, ctx); @@ -2614,15 +2614,15 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx) if (ses->server->dialect >= SMB20_PROT_ID && (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING)) - nohandlecache = ctx->nohandlecache; + enable_dir_cache = !ctx->nohandlecache && (dir_cache_timeout != 0); else - nohandlecache = true; - tcon = tcon_info_alloc(!nohandlecache, netfs_trace_tcon_ref_new); + enable_dir_cache = false; + tcon = tcon_info_alloc(enable_dir_cache, netfs_trace_tcon_ref_new); if (tcon == NULL) { rc = -ENOMEM; goto out_fail; } - tcon->nohandlecache = nohandlecache; + tcon->nohandlecache = !enable_dir_cache; if (ctx->snapshot_time) { if (ses->server->vals->protocol_id == 0) { diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 4373dd64b66d4..60f35d827382c 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -111,7 +111,7 @@ sesInfoFree(struct cifs_ses *buf_to_free) } struct cifs_tcon * -tcon_info_alloc(bool dir_leases_enabled, enum smb3_tcon_ref_trace trace) +tcon_info_alloc(bool enable_dir_cache, enum smb3_tcon_ref_trace trace) { struct cifs_tcon *ret_buf; static atomic_t tcon_debug_id; @@ -120,7 +120,7 @@ tcon_info_alloc(bool dir_leases_enabled, enum smb3_tcon_ref_trace trace) if (!ret_buf) return NULL; - if (dir_leases_enabled == true) { + if (enable_dir_cache) { ret_buf->cfids = init_cached_dirs(); if (!ret_buf->cfids) { kfree(ret_buf); From patchwork Fri Nov 22 20:39:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrique Carvalho X-Patchwork-Id: 13883610 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1A8B17B428 for ; Fri, 22 Nov 2024 20:40:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732308031; cv=none; b=u1Bu3+ajntVP7MaXAgzvyFSbdcSOILFtTgWdX/AvfEtmftm5+2hXPt2KhITNl9nUu+sVprYa2Dm+PV4lfTXYwUhgGKeDwEp/qIjDhrI9zVJ9YbR1sJXGSNxjCZf6d3aOBEDG28KSIHMKeLcrc8Ix8DfBy98yuVVzOY1ur/f/r2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732308031; c=relaxed/simple; bh=/ezPXWpWVrulaooLZhCDml/9r9QLWHg93WkEDVEJgkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IPZ1kjgDfj9Vx/L3hwO8w2+rA/wk23vYZSMHBVhc1yOXrlMjrl5OC5qIhOF44HX5+2KdFczvR1frRIdM+xt1NqtssP+ejVaL+8YZZN3auWwS6rTyhoBYRObmi+si1vM+R8cu0yc5QlOcGuvg65J/paFjXPR+J0KH4C3BGhWZ9SA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=XVm0VmXI; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="XVm0VmXI" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-382325b0508so1684236f8f.3 for ; Fri, 22 Nov 2024 12:40:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1732308028; x=1732912828; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V2vnbMl/BWCcUYVePyPyKrpM5ozYiHydygp4Ra23Nvs=; b=XVm0VmXIbRWJrZ5plKF66Ps+x0jA1PIINg+tFX7awyVvNlrvM/JoVLP2de63Bc9395 j0nk8hHsnRTZj3NWp4xHzNlGaMBr85KYKcDoGJFEL4Jiyc72jP2l5yITyqhhYBpKyOwZ X/2ERQc5IE+eU9LQN++vbIXfRIQDNjICHkudhNZy7skGgbSsKUrXcT5U+2fAmAiA2KI/ GDNHeOU+T2VBnnVWqOOmy5lja8bgnecAfDxmmJqcMts07iWmNKXLABgHji2Df58bwz0O yU2TyicETikj2i8CD62uYnkqhTfs7uJQzUmwQzGjdQpPi6QwWv3rnQcvXjXCrYnprCxR YzxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732308028; x=1732912828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V2vnbMl/BWCcUYVePyPyKrpM5ozYiHydygp4Ra23Nvs=; b=Ryg2JFL4S8txCJbO6N+oNjL9Tw4ZrOniyf8AItOhGEZq1XTFaf6K0JGaJQi0AlqDuw i3RNibrqLzOLLuvnqD4lED29T5gX0xex0WIWR9rzrUzuqGeCSGP7ZGYuMbow9NN046CN ZylPOT4TriJhiUCxfFHSPlI/SzsGQ+yBzQilaZD+athwwQ7Bh+P0yiS1KvBuIUzab2WK 7O/4G4UaLWiCHDdqsH7h9NPUd4gAomQBDqN/3AV8Kb1aNmTXJzbTQ/bB+eXufBhKSfql o4GS/ydTYwhlUZ6p5EuBdv4aK6dUrH4Vi5sL41EIYvm7tHZ6OFOQisY2XCeqOVMx1nrT U9ZA== X-Forwarded-Encrypted: i=1; AJvYcCX2jc8INExFpdubl+8A7qpnKrSgpXa9Ahlhuxma9GwG94ht2yW130DzIIGVVNoLE1J9S/lvaTi3v61E@vger.kernel.org X-Gm-Message-State: AOJu0YwV3e9S/JbtvTKZrsreQ7KPL1qkgupP4rbPS/VzUFDJAZ8g97lt 2OF/ddA+ebyuSH0SX+Fk0at5LIQKCY/M4Oysu8w6R8A3zuP6E8ymEzULBLtW1kw= X-Gm-Gg: ASbGncuOIMSVcq/zkHTFGM68faZ0/BtNjNjyJ6PiZ6pyBfrDhA1Z8rYXfDnSJ7qufM2 28GLuDZDlT1eD6eH3zKVpll1f7OizUDJBq+Bxd2BkKAXQvDQNYLI0p+EiE+BVqCXjZdBCwC3KP8 8UDULIPiE1nYsFjKCyXUxD362JtWICt97K6p4uzF8N5flY0kDhtx4yZvskgQ6+BOT/+Zu1n/EcP SXPx8WPeKnvXXi3/AmysEFZNJoYi0T0w3+nKfYqufIAblFjx7KytpN4arlmbWfxrUY7cw== X-Google-Smtp-Source: AGHT+IGbGKhmXaj3W2bbHVCDovJ1ZZnY37b6q4Hug2hEj11SGKrb28nU+aSiB0Q6hKdZKg1fkUTAFw== X-Received: by 2002:a05:6000:2d0b:b0:382:4126:f182 with SMTP id ffacd0b85a97d-38260b6d7e9mr2882350f8f.25.1732308027984; Fri, 22 Nov 2024 12:40:27 -0800 (PST) Received: from localhost.localdomain ([2800:810:5e9:f3c:e019:b39:5a90:cfe]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724de57a3d1sm2053423b3a.194.2024.11.22.12.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 12:40:27 -0800 (PST) From: Henrique Carvalho To: sfrench@samba.org Cc: ematsumiya@suse.de, pc@manguebit.com, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, linux-cifs@vger.kernel.org, Henrique Carvalho Subject: [PATCH 2/2] smb: client: remove unnecessary NULL check in open_cached_dir_by_dentry() Date: Fri, 22 Nov 2024 17:39:01 -0300 Message-ID: <20241122203901.283703-2-henrique.carvalho@suse.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241122203901.283703-1-henrique.carvalho@suse.com> References: <20241122203901.283703-1-henrique.carvalho@suse.com> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function open_cached_dir_by_dentry() is only called by cifs_dentry_needs_reval(), and it always passes dentry->d_parent as the argument to dentry. Since dentry->d_parent cannot be NULL, the check for dentry == NULL is unnecessary and can be removed. Signed-off-by: Henrique Carvalho Acked-by: Paulo Alcantara (Red Hat) --- fs/smb/client/cached_dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c index d8b1cf1043c35..9ac503dee0793 100644 --- a/fs/smb/client/cached_dir.c +++ b/fs/smb/client/cached_dir.c @@ -400,7 +400,7 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon, spin_lock(&cfids->cfid_list_lock); list_for_each_entry(cfid, &cfids->entries, entry) { - if (dentry && cfid->dentry == dentry) { + if (cfid->dentry == dentry) { cifs_dbg(FYI, "found a cached file handle by dentry\n"); kref_get(&cfid->refcount); *ret_cfid = cfid;