From patchwork Wed Mar 23 20:18:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Becker X-Patchwork-Id: 12790093 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 773C0C433EF for ; Wed, 23 Mar 2022 20:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244795AbiCWUUm (ORCPT ); Wed, 23 Mar 2022 16:20:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230070AbiCWUUl (ORCPT ); Wed, 23 Mar 2022 16:20:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C5671CB3A for ; Wed, 23 Mar 2022 13:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648066750; h=from:from:reply-to:subject:subject: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=Am6lhT2qbsmRqVPaDfBrigBs2TIbVKCJe7CvKinIzaI=; b=dG7BRhywrYGAW/h36RvwgUNKCEZlxfeQLrVPFGfu4ZYv4gZpgb2VqfLj7i4el1SxJaSXSe yRsHAyoj5pVpF5ff+aWaiV0IjJjVfet8fLBG5fCenUFk0a3sX/IqagG/vuMWe4kdGYIUv2 EPAM5Arhfve3prJkLrwXN2aT9oM7SVY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-627-_zazaxjzMZakc6zFlgiwVg-1; Wed, 23 Mar 2022 16:18:59 -0400 X-MC-Unique: _zazaxjzMZakc6zFlgiwVg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B663E803D7A; Wed, 23 Mar 2022 20:18:58 +0000 (UTC) Received: from nyarly.redhat.com (ovpn-116-121.gru2.redhat.com [10.97.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44139401E24; Wed, 23 Mar 2022 20:18:54 +0000 (UTC) From: Thiago Becker To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, kolga@netapp.com, Thiago Becker Subject: [PATCH RFC v3 1/6] Create nfsrahead Date: Wed, 23 Mar 2022 17:18:36 -0300 Message-Id: <20220323201841.4166549-2-tbecker@redhat.com> In-Reply-To: <20220323201841.4166549-1-tbecker@redhat.com> References: <20220323201841.4166549-1-tbecker@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This tool is invoked by udev to find and set the readahead value to NFS mounts. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker --- .gitignore | 1 + configure.ac | 1 + tools/Makefile.am | 2 +- tools/nfsrahead/Makefile.am | 3 +++ tools/nfsrahead/main.c | 7 +++++++ 5 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tools/nfsrahead/Makefile.am create mode 100644 tools/nfsrahead/main.c diff --git a/.gitignore b/.gitignore index c89d1cd2..38ab1d39 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ utils/statd/statd tools/locktest/testlk tools/getiversion/getiversion tools/nfsconf/nfsconf +tools/nfsrahead/nfsrahead support/export/mount.h support/export/mount_clnt.c support/export/mount_xdr.c diff --git a/configure.ac b/configure.ac index e0f5a930..3e1c183b 100644 --- a/configure.ac +++ b/configure.ac @@ -737,6 +737,7 @@ AC_CONFIG_FILES([ tools/rpcgen/Makefile tools/mountstats/Makefile tools/nfs-iostat/Makefile + tools/nfsrahead/Makefile tools/rpcctl/Makefile tools/nfsdclnts/Makefile tools/nfsconf/Makefile diff --git a/tools/Makefile.am b/tools/Makefile.am index c3feabbe..40c17c37 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -12,6 +12,6 @@ if CONFIG_NFSDCLD OPTDIRS += nfsdclddb endif -SUBDIRS = locktest rpcdebug nlmtest mountstats nfs-iostat rpcctl nfsdclnts $(OPTDIRS) +SUBDIRS = locktest rpcdebug nlmtest mountstats nfs-iostat rpcctl nfsdclnts nfsrahead $(OPTDIRS) MAINTAINERCLEANFILES = Makefile.in diff --git a/tools/nfsrahead/Makefile.am b/tools/nfsrahead/Makefile.am new file mode 100644 index 00000000..edff7921 --- /dev/null +++ b/tools/nfsrahead/Makefile.am @@ -0,0 +1,3 @@ +libexec_PROGRAMS = nfsrahead +nfsrahead_SOURCES = main.c + diff --git a/tools/nfsrahead/main.c b/tools/nfsrahead/main.c new file mode 100644 index 00000000..e454108e --- /dev/null +++ b/tools/nfsrahead/main.c @@ -0,0 +1,7 @@ +#include + +int main(int argc, char **argv, char **envp) +{ + unsigned int readahead = 128; + printf("%d\n", readahead); +} From patchwork Wed Mar 23 20:18:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Becker X-Patchwork-Id: 12790092 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 0AC07C433F5 for ; Wed, 23 Mar 2022 20:19:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240576AbiCWUUk (ORCPT ); Wed, 23 Mar 2022 16:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240558AbiCWUUi (ORCPT ); Wed, 23 Mar 2022 16:20:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 277581D326 for ; Wed, 23 Mar 2022 13:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648066746; h=from:from:reply-to:subject:subject: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=bscHmgw0OZbi6DZ+A6tyxhJLvQ2/1p1aAPJTdVqgpDs=; b=EaN3hZ1rtIsQ/TdiZcAwaJcUBnIa8aSyexH0RpuDpUG++Qas/M72v5ovEzY44MGyEKy16D cbvuxY70A1yphrP3eUP6dEOFeEBXkT0Pb2DqeLZ5eqwqI2xd/nNAcqrbvX8a2fYpQtC2PN t+o7iXydwfENFWTtzelvPlyvRkcEQjE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-hnBsdI67PKmusLni_o_b2g-1; Wed, 23 Mar 2022 16:19:03 -0400 X-MC-Unique: hnBsdI67PKmusLni_o_b2g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E99621C0337C; Wed, 23 Mar 2022 20:19:02 +0000 (UTC) Received: from nyarly.redhat.com (ovpn-116-121.gru2.redhat.com [10.97.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89562401E24; Wed, 23 Mar 2022 20:18:59 +0000 (UTC) From: Thiago Becker To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, kolga@netapp.com, Thiago Becker Subject: [PATCH RFC v3 2/6] nfsrahead: configure udev Date: Wed, 23 Mar 2022 17:18:37 -0300 Message-Id: <20220323201841.4166549-3-tbecker@redhat.com> In-Reply-To: <20220323201841.4166549-1-tbecker@redhat.com> References: <20220323201841.4166549-1-tbecker@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Set the udev rule to call the readahead utility. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker --- .gitignore | 1 + tools/nfsrahead/99-nfs_bdi.rules.in | 1 + tools/nfsrahead/Makefile.am | 8 ++++++++ 3 files changed, 10 insertions(+) create mode 100644 tools/nfsrahead/99-nfs_bdi.rules.in diff --git a/.gitignore b/.gitignore index 38ab1d39..df791a83 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,7 @@ tools/locktest/testlk tools/getiversion/getiversion tools/nfsconf/nfsconf tools/nfsrahead/nfsrahead +tools/nfsrahead/99-nfs_bdi.rules support/export/mount.h support/export/mount_clnt.c support/export/mount_xdr.c diff --git a/tools/nfsrahead/99-nfs_bdi.rules.in b/tools/nfsrahead/99-nfs_bdi.rules.in new file mode 100644 index 00000000..7d55b407 --- /dev/null +++ b/tools/nfsrahead/99-nfs_bdi.rules.in @@ -0,0 +1 @@ +SUBSYSTEM=="bdi", ACTION=="add", PROGRAM="_libexecdir_/nfsrahead", ATTR{read_ahead_kb}="%c" diff --git a/tools/nfsrahead/Makefile.am b/tools/nfsrahead/Makefile.am index edff7921..b598bec3 100644 --- a/tools/nfsrahead/Makefile.am +++ b/tools/nfsrahead/Makefile.am @@ -1,3 +1,11 @@ libexec_PROGRAMS = nfsrahead nfsrahead_SOURCES = main.c +udev_rulesdir = /etc/udev/rules.d +udev_rules_DATA = 99-nfs_bdi.rules + +99-nfs_bdi.rules: 99-nfs_bdi.rules.in $(builddefs) + $(SED) "s|_libexecdir_|@libexecdir@|g" 99-nfs_bdi.rules.in > $@ + +clean-local: + $(RM) 99-nfs_bdi.rules From patchwork Wed Mar 23 20:18:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Becker X-Patchwork-Id: 12790094 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 E2498C433FE for ; Wed, 23 Mar 2022 20:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbiCWUUn (ORCPT ); Wed, 23 Mar 2022 16:20:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240558AbiCWUUm (ORCPT ); Wed, 23 Mar 2022 16:20:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E93071D326 for ; Wed, 23 Mar 2022 13:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648066751; h=from:from:reply-to:subject:subject: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=uveqk269buC83REhtEYbV8V7SeNs/Lmku709rCSUKxM=; b=UspclhEdVJXSjdHHa2bcc1/vWEiR6Kj+3XwsBfJV3/xsgHwSDvxQIQcgKQB5+qCW+BKjOf ve1yw2KLhLurJgFVqqAW97sKf3qoq5BwS2aUAW3DgT1lczQ6EVoiqtFYlH2C58RY/VPfjA lNzO0nnK1uotZRxxuxKmC2UeMwS6uow= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-Q_5xvPIDNIeYe2QfiRCsEg-1; Wed, 23 Mar 2022 16:19:08 -0400 X-MC-Unique: Q_5xvPIDNIeYe2QfiRCsEg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38D573803917; Wed, 23 Mar 2022 20:19:07 +0000 (UTC) Received: from nyarly.redhat.com (ovpn-116-121.gru2.redhat.com [10.97.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D48FC401E24; Wed, 23 Mar 2022 20:19:03 +0000 (UTC) From: Thiago Becker To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, kolga@netapp.com, Thiago Becker Subject: [PATCH RFC v3 3/6] nfsrahead: only set readahead for nfs devices. Date: Wed, 23 Mar 2022 17:18:38 -0300 Message-Id: <20220323201841.4166549-4-tbecker@redhat.com> In-Reply-To: <20220323201841.4166549-1-tbecker@redhat.com> References: <20220323201841.4166549-1-tbecker@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Limit setting the readahead for nfs devices. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker --- tools/nfsrahead/Makefile.am | 1 + tools/nfsrahead/main.c | 130 ++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/tools/nfsrahead/Makefile.am b/tools/nfsrahead/Makefile.am index b598bec3..afccc520 100644 --- a/tools/nfsrahead/Makefile.am +++ b/tools/nfsrahead/Makefile.am @@ -1,5 +1,6 @@ libexec_PROGRAMS = nfsrahead nfsrahead_SOURCES = main.c +nfsrahead_LDFLAGS= -lmount udev_rulesdir = /etc/udev/rules.d udev_rules_DATA = 99-nfs_bdi.rules diff --git a/tools/nfsrahead/main.c b/tools/nfsrahead/main.c index e454108e..2cf77424 100644 --- a/tools/nfsrahead/main.c +++ b/tools/nfsrahead/main.c @@ -1,7 +1,137 @@ #include +#include +#include +#include + +#include +#include + +#ifndef MOUNTINFO_PATH +#define MOUNTINFO_PATH "/proc/self/mountinfo" +#endif + +/* Device information from the system */ +struct device_info { + char *device_number; + dev_t dev; + char *mountpoint; + char *fstype; +}; + +/* Convert a string in the format n:m to a device number */ +static dev_t dev_from_arg(const char *device_number) +{ + char *s = strdup(device_number), *p; + char *maj_s, *min_s; + unsigned int maj, min; + dev_t dev; + + maj_s = p = s; + for ( ; *p != ':'; p++) + ; + + *p = '\0'; + min_s = p + 1; + + maj = strtol(maj_s, NULL, 10); + min = strtol(min_s, NULL, 10); + + dev = makedev(maj, min); + + free(s); + return dev; +} + +#define sfree(ptr) if (ptr) free(ptr) + +/* device_info maintenance */ +static void init_device_info(struct device_info *di, const char *device_number) +{ + di->device_number = strdup(device_number); + di->dev = dev_from_arg(device_number); + di->mountpoint = NULL; + di->fstype = NULL; +} + + +static void free_device_info(struct device_info *di) +{ + sfree(di->mountpoint); + sfree(di->fstype); + sfree(di->device_number); +} + +static int get_mountinfo(const char *device_number, struct device_info *device_info, const char *mountinfo_path) +{ + int ret = 0; + struct libmnt_table *mnttbl; + struct libmnt_fs *fs; + char *target; + + init_device_info(device_info, device_number); + + mnttbl = mnt_new_table(); + + if ((ret = mnt_table_parse_file(mnttbl, mountinfo_path)) < 0) + goto out_free_tbl; + + if ((fs = mnt_table_find_devno(mnttbl, device_info->dev, MNT_ITER_FORWARD)) == NULL) { + ret = ENOENT; + goto out_free_tbl; + } + + if ((target = (char *)mnt_fs_get_target(fs)) == NULL) { + ret = ENOENT; + goto out_free_fs; + } + + device_info->mountpoint = strdup(target); + target = (char *)mnt_fs_get_fstype(fs); + if (target) + device_info->fstype = strdup(target); + +out_free_fs: + mnt_free_fs(fs); +out_free_tbl: + mnt_free_table(mnttbl); + free(device_info->device_number); + device_info->device_number = NULL; + return ret; +} + +static int get_device_info(const char *device_number, struct device_info *device_info) +{ + int ret = ENOENT; + for (int retry_count = 0; retry_count < 10 && ret != 0; retry_count++) + ret = get_mountinfo(device_number, device_info, MOUNTINFO_PATH); + + return ret; +} int main(int argc, char **argv, char **envp) { + int ret = 0; + struct device_info device; unsigned int readahead = 128; + + if (argc != 2) { + return -EINVAL; + } + + if ((ret = get_device_info(argv[1], &device)) != 0) { + goto out; + } + + if (strncmp("nfs", device.fstype, 3) != 0) { + ret = -EINVAL; + goto out; + } + + info("Setting %s readahead to 128\n", device.mountpoint); + printf("%d\n", readahead); + +out: + free_device_info(&device); + return ret; } From patchwork Wed Mar 23 20:18:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Becker X-Patchwork-Id: 12790095 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 E65C5C433F5 for ; Wed, 23 Mar 2022 20:19:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240558AbiCWUUr (ORCPT ); Wed, 23 Mar 2022 16:20:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344602AbiCWUUq (ORCPT ); Wed, 23 Mar 2022 16:20:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31C7E1D328 for ; Wed, 23 Mar 2022 13:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648066755; h=from:from:reply-to:subject:subject: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=CxnKz8MXVcB+ULznW1aSErNm4XmV2M7ep1zvMLv3XrI=; b=AvmmjQyjrotJMYEPWxcGF3EnNf1XqgXkDQR9xC29zBRJiG7A6KedQE+JhUxbk21naacubP nKXZrQKjc1pl+tr+YwEABKWI3IBH8MGixMlZOgL+mw44ss5tuRyKSXVCCayHqT8QP4Cqph sojSecZfXNUBvQugvrdfS8bJ8lBk9N0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-660-UdnNw1FVM4WgwSC5V2Zq9Q-1; Wed, 23 Mar 2022 16:19:12 -0400 X-MC-Unique: UdnNw1FVM4WgwSC5V2Zq9Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89F6D3803917; Wed, 23 Mar 2022 20:19:11 +0000 (UTC) Received: from nyarly.redhat.com (ovpn-116-121.gru2.redhat.com [10.97.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 276A0401E2A; Wed, 23 Mar 2022 20:19:07 +0000 (UTC) From: Thiago Becker To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, kolga@netapp.com, Thiago Becker Subject: [PATCH RFC v3 4/6] nfsrahead: add logging Date: Wed, 23 Mar 2022 17:18:39 -0300 Message-Id: <20220323201841.4166549-5-tbecker@redhat.com> In-Reply-To: <20220323201841.4166549-1-tbecker@redhat.com> References: <20220323201841.4166549-1-tbecker@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker --- tools/nfsrahead/Makefile.am | 1 + tools/nfsrahead/main.c | 40 +++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/tools/nfsrahead/Makefile.am b/tools/nfsrahead/Makefile.am index afccc520..d0b5d170 100644 --- a/tools/nfsrahead/Makefile.am +++ b/tools/nfsrahead/Makefile.am @@ -1,6 +1,7 @@ libexec_PROGRAMS = nfsrahead nfsrahead_SOURCES = main.c nfsrahead_LDFLAGS= -lmount +nfsrahead_LDADD = ../../support/nfs/libnfsconf.la udev_rulesdir = /etc/udev/rules.d udev_rules_DATA = 99-nfs_bdi.rules diff --git a/tools/nfsrahead/main.c b/tools/nfsrahead/main.c index 2cf77424..86c71a67 100644 --- a/tools/nfsrahead/main.c +++ b/tools/nfsrahead/main.c @@ -2,14 +2,19 @@ #include #include #include +#include #include #include +#include "xlog.h" + #ifndef MOUNTINFO_PATH #define MOUNTINFO_PATH "/proc/self/mountinfo" #endif +#define CONF_NAME "nfsrahead" + /* Device information from the system */ struct device_info { char *device_number; @@ -108,26 +113,49 @@ static int get_device_info(const char *device_number, struct device_info *device return ret; } +#define L_DEFAULT (L_WARNING | L_ERROR | L_FATAL) + int main(int argc, char **argv, char **envp) { int ret = 0; struct device_info device; - unsigned int readahead = 128; - - if (argc != 2) { - return -EINVAL; + unsigned int readahead = 128, verbose = 0, log_stderr = 0; + char opt; + + while((opt = getopt(argc, argv, "dF")) != -1) { + switch (opt) { + case 'd': + verbose = 1; + break; + case 'F': + log_stderr = 1; + break; + } } - if ((ret = get_device_info(argv[1], &device)) != 0) { + xlog_stderr(log_stderr); + xlog_syslog(~log_stderr); + xlog_config(L_DEFAULT | (L_NOTICE & verbose), 1); + xlog_open(CONF_NAME); + + // xlog_err causes the system to exit + if ((argc - optind) != 1) + xlog_err("expected the device number of a BDI; is udev ok?"); + + if ((ret = get_device_info(argv[optind], &device)) != 0) { + xlog(L_ERROR, "unable to find device %s\n", argv[optind]); goto out; } if (strncmp("nfs", device.fstype, 3) != 0) { + xlog(L_NOTICE, + "not setting readahead for non supported fstype %s on device %s\n", + device.fstype, argv[optind]); ret = -EINVAL; goto out; } - info("Setting %s readahead to 128\n", device.mountpoint); + xlog(L_WARNING, "setting %s readahead to %d\n", device.mountpoint, readahead); printf("%d\n", readahead); From patchwork Wed Mar 23 20:18:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Becker X-Patchwork-Id: 12790096 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 8A499C433F5 for ; Wed, 23 Mar 2022 20:19:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344608AbiCWUUv (ORCPT ); Wed, 23 Mar 2022 16:20:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344336AbiCWUUu (ORCPT ); Wed, 23 Mar 2022 16:20:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 230161CB3A for ; Wed, 23 Mar 2022 13:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648066759; h=from:from:reply-to:subject:subject: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=GmpjH70Xsoa09i6Q8FK/McGA4ZVZb+tiUFW984XvYLE=; b=e05qGbKwTyWMFuxNi9fZr/A87y5Q5gX9UI81kaPmzUyCkIBOxELotrJk5A6iRd9B0LAbrz jqJZBJcrmug89j0JGkX2gagYmey/lR5jNInPG0vehFGKU+rWAgw9Moz0hr6ZnrVEiNScos 5bD6gtNUoJLcJcl0mTNNKmVaoNpiFrk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-j5d-ldpWNi-OtdWEIuePJw-1; Wed, 23 Mar 2022 16:19:16 -0400 X-MC-Unique: j5d-ldpWNi-OtdWEIuePJw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A1838185A7BA; Wed, 23 Mar 2022 20:19:15 +0000 (UTC) Received: from nyarly.redhat.com (ovpn-116-121.gru2.redhat.com [10.97.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5AB78401E8C; Wed, 23 Mar 2022 20:19:11 +0000 (UTC) From: Thiago Becker To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, kolga@netapp.com, Thiago Becker Subject: [PATCH RFC v3 5/6] hfsrahead: get the information from the config file. Date: Wed, 23 Mar 2022 17:18:40 -0300 Message-Id: <20220323201841.4166549-6-tbecker@redhat.com> In-Reply-To: <20220323201841.4166549-1-tbecker@redhat.com> References: <20220323201841.4166549-1-tbecker@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker --- tools/nfsrahead/main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/nfsrahead/main.c b/tools/nfsrahead/main.c index 86c71a67..bead9f5c 100644 --- a/tools/nfsrahead/main.c +++ b/tools/nfsrahead/main.c @@ -8,12 +8,14 @@ #include #include "xlog.h" +#include "conffile.h" #ifndef MOUNTINFO_PATH #define MOUNTINFO_PATH "/proc/self/mountinfo" #endif #define CONF_NAME "nfsrahead" +#define NFS_DEFAULT_READAHEAD 128 /* Device information from the system */ struct device_info { @@ -113,6 +115,14 @@ static int get_device_info(const char *device_number, struct device_info *device return ret; } +static int conf_get_readahead(const char *kind) { + int readahead = 0; + + if((readahead = conf_get_num(CONF_NAME, kind, -1)) == -1) + readahead = conf_get_num(CONF_NAME, "default", NFS_DEFAULT_READAHEAD); + + return readahead; +} #define L_DEFAULT (L_WARNING | L_ERROR | L_FATAL) int main(int argc, char **argv, char **envp) @@ -133,6 +143,8 @@ int main(int argc, char **argv, char **envp) } } + conf_init_file(NFS_CONFFILE); + xlog_stderr(log_stderr); xlog_syslog(~log_stderr); xlog_config(L_DEFAULT | (L_NOTICE & verbose), 1); @@ -155,6 +167,8 @@ int main(int argc, char **argv, char **envp) goto out; } + readahead = conf_get_readahead(device.fstype); + xlog(L_WARNING, "setting %s readahead to %d\n", device.mountpoint, readahead); printf("%d\n", readahead); From patchwork Wed Mar 23 20:18:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Becker X-Patchwork-Id: 12790097 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 9BC33C433EF for ; Wed, 23 Mar 2022 20:19:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344336AbiCWUUz (ORCPT ); Wed, 23 Mar 2022 16:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344602AbiCWUUy (ORCPT ); Wed, 23 Mar 2022 16:20:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA7B41F608 for ; Wed, 23 Mar 2022 13:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648066763; h=from:from:reply-to:subject:subject: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=A4WjIFYPYYr7HjXVjEDRv4oz08cl5gveTsATjw52Amg=; b=F0J4XMqmc/DhbMlgjbJNTD4OoX/d19LtJY5wWvoc945ZxaI8ucQ2skX8BX8krJiOay55D1 tUkAje1xW+ZM73UhLgJ1dII2KjTcwASmSGoX9N063Kwtj1MusOpJgVN40KCI+DGb/xdZer zYbNGFIqtMdcaliETjv7/Ff5IT8/qoA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-382-8TutiKXLMk-fcC3WlvWycA-1; Wed, 23 Mar 2022 16:19:20 -0400 X-MC-Unique: 8TutiKXLMk-fcC3WlvWycA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2799729ABA28; Wed, 23 Mar 2022 20:19:20 +0000 (UTC) Received: from nyarly.redhat.com (ovpn-116-121.gru2.redhat.com [10.97.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A42F1401E24; Wed, 23 Mar 2022 20:19:16 +0000 (UTC) From: Thiago Becker To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, kolga@netapp.com, Thiago Becker Subject: [PATCH RFC v3 6/6] nfsrahead: User documentation Date: Wed, 23 Mar 2022 17:18:41 -0300 Message-Id: <20220323201841.4166549-7-tbecker@redhat.com> In-Reply-To: <20220323201841.4166549-1-tbecker@redhat.com> References: <20220323201841.4166549-1-tbecker@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add the man page for nfsrahead, and add the new section to nfs.conf. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker --- systemd/nfs.conf.man | 11 ++++++ tools/nfsrahead/Makefile.am | 2 + tools/nfsrahead/nfsrahead.man | 72 +++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tools/nfsrahead/nfsrahead.man diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index be487a11..e74083e9 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -294,6 +294,17 @@ Only .B debug= is recognized. +.TP +.B nfsrahead +Recognized values: +.BR nfs , +.BR nfsv4 , +.BR default . + +See +.BR nfsrahead (5) +for deatils. + .SH FILES .TP 10n .I /etc/nfs.conf diff --git a/tools/nfsrahead/Makefile.am b/tools/nfsrahead/Makefile.am index d0b5d170..7342dcba 100644 --- a/tools/nfsrahead/Makefile.am +++ b/tools/nfsrahead/Makefile.am @@ -3,6 +3,8 @@ nfsrahead_SOURCES = main.c nfsrahead_LDFLAGS= -lmount nfsrahead_LDADD = ../../support/nfs/libnfsconf.la +man5_MANS = nfsrahead.man + udev_rulesdir = /etc/udev/rules.d udev_rules_DATA = 99-nfs_bdi.rules diff --git a/tools/nfsrahead/nfsrahead.man b/tools/nfsrahead/nfsrahead.man new file mode 100644 index 00000000..5488f633 --- /dev/null +++ b/tools/nfsrahead/nfsrahead.man @@ -0,0 +1,72 @@ +.\" Manpage for nfsrahead. +.nh +.ad l +.TH man 5 "08 Mar 2022" "1.0" "nfsrahead man page" +.SH NAME + +nfsrahead \- Configure the readahead for NFS mounts + +.SH SYNOPSIS + +nfsrahead [-F] [-d] + +.SH DESCRIPTION + +\fInfsrahead\fR is a tool intended to be used with udev to set the \fIread_ahead_kb\fR parameter of NFS mounts, according to the configuration file (see \fICONFIGURATION\fR). \fIdevice\fR is the device number for the NFS backing device as provided by the kernel. + +.SH OPTIONS +.TP +.B -F +Send messages to +.I stderr +instead of +.I syslog + +.TP +.B -d +Increase the debugging level. + +.SH CONFIGURATION +.I nfsrahead +is configured in +.IR /etc/nfs.conf , +in the section titled +.IR nfsrahead . +It accepts the following configurations. + +.TP +.B nfs= +The readahead value applied to NFSv3 mounts. + +.TP +.B nfs4= +The readahead value applied to NFSv4 mounts. + +.TP +.B default= +The default configuration when none of the configurations above is set. + +.SH EXAMPLE CONFIGURATION +[nfsrahead] +.br +nfs=15000 # readahead of 15000 for NFSv3 mounts +.br +nfs4=16000 # readahead of 16000 for NFSv4 mounts +.br +default=128 # default is 128 + +.SH SEE ALSO + +.BR mount.nfs (8), +.BR nfs (5), +.BR nfs.conf (5), +.BR udev (7), +.BR bcc-readahead (8) + +.SH BUGS + +No known bugs. + +.SH AUTHOR + +Thiago Rafael Becker