From patchwork Wed Jun 8 21:54:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Enzo Matsumiya X-Patchwork-Id: 12874689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93FF0C433EF for ; Wed, 8 Jun 2022 21:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232158AbiFHVzM (ORCPT ); Wed, 8 Jun 2022 17:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232340AbiFHVzL (ORCPT ); Wed, 8 Jun 2022 17:55:11 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A6C891562 for ; Wed, 8 Jun 2022 14:55:09 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B34F821B4F; Wed, 8 Jun 2022 21:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1654725307; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dTVhqk3+JWD/g1KjfWDNQ7hAxtkozHllEncsg3IBdSY=; b=rlSg+1DpX12AOjDggsVuLa3/0lC7cYffb86WN4cmcEoHRh6Otg0LY3vWB3z7V6stEvfjaY o7dv75u+19mpM7ERHAu5LiE8z7LhpNok7O/wrdZeLJnFBTuNHXyj6zXaW46K7x1SQTUaYl ruhR8Bbh1D23iQEOxXdfo7buBMlVVg4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1654725307; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dTVhqk3+JWD/g1KjfWDNQ7hAxtkozHllEncsg3IBdSY=; b=0fmzWaJpoxvzpHU7RxOWUDAjQdkgcTN8KFqt8dAjAR9GWpt1/Qk9NVBvc69Swiddz0L0/4 EyB2FBTlO0jmThAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 379A413AD9; Wed, 8 Jun 2022 21:55:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id DHH/OroaoWKlFwAAMHmgww (envelope-from ); Wed, 08 Jun 2022 21:55:06 +0000 From: Enzo Matsumiya To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, pc@cjr.nz, ronniesahlberg@gmail.com, nspmangalore@gmail.com, Enzo Matsumiya Subject: [PATCH 1/2] cifs: create procfs for dns_interval setting Date: Wed, 8 Jun 2022 18:54:43 -0300 Message-Id: <20220608215444.1216-2-ematsumiya@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608215444.1216-1-ematsumiya@suse.de> References: <20220608215444.1216-1-ematsumiya@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org This patch introduces the /proc/fs/cifs/dns_interval setting, used to configure the interval that DNS resolutions must be done. Enforces the minimum value SMB_DNS_RESOLVE_INTERVAL_MIN (currently 120), but allows it to be lower (10, arbitrarily chosen) when debugging (i.e. cifsFYI > 0). Signed-off-by: Enzo Matsumiya --- fs/cifs/cifs_debug.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/cifs_debug.h | 2 ++ fs/cifs/cifsfs.c | 1 + 3 files changed, 66 insertions(+) diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c index 1dd995efd5b8..96ff549a103e 100644 --- a/fs/cifs/cifs_debug.c +++ b/fs/cifs/cifs_debug.c @@ -695,6 +695,7 @@ PROC_FILE_DEFINE(smbd_receive_credit_max); static struct proc_dir_entry *proc_fs_cifs; static const struct proc_ops cifsFYI_proc_ops; +static const struct proc_ops cifs_dns_interval_proc_ops; static const struct proc_ops cifs_lookup_cache_proc_ops; static const struct proc_ops traceSMB_proc_ops; static const struct proc_ops cifs_security_flags_proc_ops; @@ -716,6 +717,7 @@ cifs_proc_init(void) proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops); proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops); + proc_create("dns_interval", 0644, proc_fs_cifs, &cifs_dns_interval_proc_ops); proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops); proc_create("LinuxExtensionsEnabled", 0644, proc_fs_cifs, &cifs_linux_ext_proc_ops); @@ -759,6 +761,7 @@ cifs_proc_clean(void) remove_proc_entry("DebugData", proc_fs_cifs); remove_proc_entry("open_files", proc_fs_cifs); remove_proc_entry("cifsFYI", proc_fs_cifs); + remove_proc_entry("dns_interval", proc_fs_cifs); remove_proc_entry("traceSMB", proc_fs_cifs); remove_proc_entry("Stats", proc_fs_cifs); remove_proc_entry("SecurityFlags", proc_fs_cifs); @@ -821,6 +824,66 @@ static const struct proc_ops cifsFYI_proc_ops = { .proc_write = cifsFYI_proc_write, }; +static int cifs_dns_interval_show(struct seq_file *m, void *v) +{ + seq_printf(m, "%u\n", dns_interval); + return 0; +} + +static int cifs_dns_interval_open(struct inode *inode, struct file *file) +{ + return single_open(file, cifs_dns_interval_show, NULL); +} + +static ssize_t cifs_dns_interval_write(struct file *file, const char __user *buffer, + size_t count, loff_t *ppos) +{ + int rc; + unsigned int interval; + char buf[12] = { 0 }; + /* allow the minimum interval to be 10 (arbritrary) when debugging */ + unsigned int min_interval = cifsFYI ? 10 : SMB_DNS_RESOLVE_INTERVAL_MIN; + + if ((count < 1) || (count > 11)) + return -EINVAL; + + if (copy_from_user(buf, buffer, count)) + return -EFAULT; + + if (count < 3) { + if (!isdigit(buf[0])) { + cifs_dbg(VFS, "Invalid value for dns_interval: %s\n", + buf); + return -EINVAL; + } + } + + rc = kstrtouint(buf, 0, &interval); + if (rc) { + cifs_dbg(VFS, "Invalid value for dns_interval: %s\n", + buf); + return rc; + } + + if (interval < min_interval) { + cifs_dbg(VFS, "minimum value for dns_interval is %u, default value is %u\n", + SMB_DNS_RESOLVE_INTERVAL_MIN, + SMB_DNS_RESOLVE_INTERVAL_DEFAULT); + return -EINVAL; + } + + dns_interval = interval; + return count; +} + +static const struct proc_ops cifs_dns_interval_proc_ops = { + .proc_open = cifs_dns_interval_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = single_release, + .proc_write = cifs_dns_interval_write, +}; + static int cifs_linux_ext_proc_show(struct seq_file *m, void *v) { seq_printf(m, "%d\n", linuxExtEnabled); diff --git a/fs/cifs/cifs_debug.h b/fs/cifs/cifs_debug.h index ee4ea2b60c0f..40ef322450a3 100644 --- a/fs/cifs/cifs_debug.h +++ b/fs/cifs/cifs_debug.h @@ -33,6 +33,8 @@ extern int cifsFYI; #endif #define ONCE 8 +extern unsigned int dns_interval; + /* * debug ON * -------- diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 325423180fd2..284645da8cd3 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -66,6 +66,7 @@ bool enable_gcm_256 = true; bool require_gcm_256; /* false by default */ bool enable_negotiate_signing; /* false by default */ unsigned int global_secflags = CIFSSEC_DEF; +unsigned int dns_interval = SMB_DNS_RESOLVE_INTERVAL_DEFAULT; /* unsigned int ntlmv2_support = 0; */ unsigned int sign_CIFS_PDUs = 1; static const struct super_operations cifs_super_ops; From patchwork Wed Jun 8 21:54:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Enzo Matsumiya X-Patchwork-Id: 12874690 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D574AC43334 for ; Wed, 8 Jun 2022 21:55:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232754AbiFHVzO (ORCPT ); Wed, 8 Jun 2022 17:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232340AbiFHVzN (ORCPT ); Wed, 8 Jun 2022 17:55:13 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CFE67CDD4 for ; Wed, 8 Jun 2022 14:55:12 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2AD1B1F460; Wed, 8 Jun 2022 21:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1654725311; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zbHMkHKx6aAOYrp+F+57t5Ha0/TI11vNRjjQnU9GEQY=; b=mlDD7rS0FVjn9fpBUqRoreFHHqP2OgBjs03gUtonSKu/86G9sEr+f/pGUXPaO08+aMmCUf Xh9tK8GoKxcf2jZlcm/pLMcAPQ5ICMfxlyaIN3HghSFLejRrh9B2vpc25UtsCQmr/bq+9v noRkLpGnFleu55X1oW2fm5CpdCV5TYw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1654725311; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zbHMkHKx6aAOYrp+F+57t5Ha0/TI11vNRjjQnU9GEQY=; b=BLYtSu1xR+FDt4csi5tEu/8YJo/7i1A9D8cQgA0el8iCP3+bEyPB8sVo5E/wUaI7XRFUUv Ch7tGXpQpgEn4rDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9D11D13AD9; Wed, 8 Jun 2022 21:55:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ryOFF74aoWKqFwAAMHmgww (envelope-from ); Wed, 08 Jun 2022 21:55:10 +0000 From: Enzo Matsumiya To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, pc@cjr.nz, ronniesahlberg@gmail.com, nspmangalore@gmail.com, Enzo Matsumiya Subject: [PATCH 2/2] cifs: reschedule DNS resolve worker based on dns_interval Date: Wed, 8 Jun 2022 18:54:44 -0300 Message-Id: <20220608215444.1216-3-ematsumiya@suse.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608215444.1216-1-ematsumiya@suse.de> References: <20220608215444.1216-1-ematsumiya@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org This patch makes use of the dns_interval introduced in the previous commit when re/scheduling the resolve worker. Signed-off-by: Enzo Matsumiya --- fs/cifs/connect.c | 4 ++-- fs/cifs/dns_resolve.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 06bafba9c3ff..edd4f0020f9c 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -92,7 +92,7 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server) int len; char *unc, *ipaddr = NULL; time64_t expiry, now; - unsigned long ttl = SMB_DNS_RESOLVE_INTERVAL_DEFAULT; + unsigned long ttl = dns_interval; if (!server->hostname || server->hostname[0] == '\0') @@ -130,7 +130,7 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server) * To make sure we don't use the cached entry, retry 1s * after expiry. */ - ttl = max_t(unsigned long, expiry - now, SMB_DNS_RESOLVE_INTERVAL_MIN) + 1; + ttl = max_t(unsigned long, expiry - now, dns_interval) + 1; } rc = !rc ? -1 : 0; diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c index 0458d28d71aa..eff1e61180ed 100644 --- a/fs/cifs/dns_resolve.c +++ b/fs/cifs/dns_resolve.c @@ -67,6 +67,14 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr, time64_t *expiry) /* Perform the upcall */ rc = dns_query(current->nsproxy->net_ns, NULL, hostname, len, NULL, ip_addr, expiry, false); + + /* + * If the upcall didn't get a TTL, we use the value from dns_interval + * procfs setting + */ + if (expiry && *expiry == 0) + *expiry = dns_interval; + if (rc < 0) cifs_dbg(FYI, "%s: unable to resolve: %*.*s\n", __func__, len, len, hostname);