Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp724617pxp; Wed, 9 Mar 2022 11:19:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRSTEVKG0alxTdKzezNb7A6a8XIWi9dCi7OxJlM4x3AfMFxCNonq3PL1hxNuI447NObdjh X-Received: by 2002:a17:902:e745:b0:151:5474:d3ed with SMTP id p5-20020a170902e74500b001515474d3edmr1001000plf.106.1646853555119; Wed, 09 Mar 2022 11:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646853555; cv=none; d=google.com; s=arc-20160816; b=gG1dtPvmpL1ti5C4kWamVjEghWPp+aGWLlNsfbGkVZIRZro7hjkkuJ9JGKWFxd6R66 2Uj1SlA5ZAR1EEVeRRXiGGk3VIB5lk6L+JFY0P01+o4cjwYrk9CUWZnDAMjS7hGbx1s8 na3hX+N8Ib8pBIrkPd2U567T1UBsBRkwzffaRxwkMSvnOkWHBEP+WQzFbcelADR2IG1Q 4xHsBJLO2GuK3CtDsIuT5uGBVZdpxqBP2+E2qlqxccicvj4RKu+jJH6yqNP3b3Ta9y5W mO9uLscu39HTYhuF5SNL+6YDfGUy/pfvc+9TztDYwd0dpzAHNHYUGyx6yb0HJXiOTE8V pl3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cw3iv6XGjibkRbBqnfX3hpJe85HzX3v3mvg/CBrmEqs=; b=bN0ZiPg/V2jX/MwTtVHSJSfW+tl1Qg7baxIBPeReRgDFSbwmeAYa+B92H09jMhToRv eYVjQ4s1YZXLF3lpwn1VbictZY8gVevZAkiihSYqGCbYGYQkT32J/eDpLs9dlwzuaJ8U 7lm9P+3ESwKnuEwMHg5v27ZP/ty8X3b5vb9gmvPTnYXAj1R+ddho/ss62ghxA+0SXMOW wj4pwCMGo/9VR9h5fugStEBtZm4GimJiYA1LRX3VxqUg7GzxdRM1MATBZdST8dfdBDAm w+kHBt+FW/0mcoyUMWj4ET1bHw6k/slesZqSV+qh7oqTJDJ2Ku7MsC91NiF6HgrGu0hy SWOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BXbId7WC; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d3-20020a056a00244300b004f771be132asi17055pfj.356.2022.03.09.11.18.40; Wed, 09 Mar 2022 11:19:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BXbId7WC; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235549AbiCIS2c (ORCPT + 99 others); Wed, 9 Mar 2022 13:28:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbiCIS2b (ORCPT ); Wed, 9 Mar 2022 13:28:31 -0500 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 681B631206 for ; Wed, 9 Mar 2022 10:27:32 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id 17-20020a9d0611000000b005b251571643so2381925otn.2 for ; Wed, 09 Mar 2022 10:27:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cw3iv6XGjibkRbBqnfX3hpJe85HzX3v3mvg/CBrmEqs=; b=BXbId7WCi0ZTqZRT7ETj4G0yxAwdMxv0IIN9TDIbxzISSgrPFwxyUGgAlD1NLWdH8/ vl/nx+OlE1+O6hjA0vNJNiAjbcfwbAQYYkW2BigBoV9CnOnAoayZ8/Fb2/nvBhsK8UQP hb9gve297DkAdGEEgdtTnXQXf8tM+5Me1p7OWPodfAmV0SWazJ1tXuTjXgDhXKfMwbB9 xYcUm14meLy2tsSZLcgp/0mx77LV63j0bx+ci/OQjnFk2qDJJwZOwaSdg/I2hftG2g8S UmJ3rw1mR1XgzDMCL+1Bm30Q+kYFcVnF4tuEU948xoPKNACqVxfwGqfXcw82bdGBlTQt g5zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cw3iv6XGjibkRbBqnfX3hpJe85HzX3v3mvg/CBrmEqs=; b=0GKSE4MYnb217F+ktJEvTFf33ZH+7OV2cGCkISx5rHsCPceOfLfKa+5CfLP0X811Uo AJp51e997myWc+BmYAhCzqZsflKopWdxCsLv1aOVjt9FcudjVJw6TATFtDV7xiVnxXbt pTCReNv7iZBoN5J3NrOhJkSu2CaLpRGWmYROKqUW9Exnylah11HHb6Iky7WSbrWMBIVT H2gCj1MEy1E/vjXuOoUS78McurjjlwvrYFxntg9rlR+fHwRPporu/9E/9PNpJl+kE26d rJ7rWqyP/ibBRpRZ8vJJ4+7eHnVW/+pHIgLF/AIGdmEmr08GojQZZq57re9wk8red1/y UZqg== X-Gm-Message-State: AOAM530t02+5e75rVI4fR6Hq8g1IbdlKfNVeP51kwhSPlHy4rbC6nsFM Wt39XEwUa+3wQGfv4nc04jQX+Q5E4jc= X-Received: by 2002:a9d:4686:0:b0:5ae:e472:2dda with SMTP id z6-20020a9d4686000000b005aee4722ddamr545117ote.317.1646850451534; Wed, 09 Mar 2022 10:27:31 -0800 (PST) Received: from nyarly.redhat.com ([179.233.246.234]) by smtp.gmail.com with ESMTPSA id k5-20020a056870a4c500b000d9c2216692sm1213270oal.24.2022.03.09.10.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Mar 2022 10:27:30 -0800 (PST) From: Thiago Rafael Becker To: linux-nfs@vger.kernel.org Cc: tbecker@redhat.com, steved@redhat.com, chuck.lever@oracle.com, Thiago Rafael Becker Subject: [RFC PATCH 4/7] readahead: only set readahead for nfs devices. Date: Wed, 9 Mar 2022 15:26:50 -0300 Message-Id: <20220309182653.1885252-5-trbecker@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220309182653.1885252-1-trbecker@gmail.com> References: <20220309182653.1885252-1-trbecker@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE 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-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 Rafael Becker --- tools/nfs-readahead-udev/99-nfs_bdi.rules.in | 2 +- tools/nfs-readahead-udev/Makefile.am | 1 + tools/nfs-readahead-udev/main.c | 132 ++++++++++++++++++- 3 files changed, 133 insertions(+), 2 deletions(-) diff --git a/tools/nfs-readahead-udev/99-nfs_bdi.rules.in b/tools/nfs-readahead-udev/99-nfs_bdi.rules.in index 15f8a995..744c59be 100644 --- a/tools/nfs-readahead-udev/99-nfs_bdi.rules.in +++ b/tools/nfs-readahead-udev/99-nfs_bdi.rules.in @@ -1 +1 @@ -SUBSYSTEM=="bdi", ACTION=="add", PROGRAM="_libexecdir_/nfs-readahead-udev", ATTR{read_ahead_kb}="%c" +SUBSYSTEM=="bdi", ACTION=="add", PROGRAM="_libexecdir_/nfs-readahead-udev %k", ATTR{read_ahead_kb}="%c" diff --git a/tools/nfs-readahead-udev/Makefile.am b/tools/nfs-readahead-udev/Makefile.am index 5078db9a..551d22e9 100644 --- a/tools/nfs-readahead-udev/Makefile.am +++ b/tools/nfs-readahead-udev/Makefile.am @@ -1,5 +1,6 @@ libexec_PROGRAMS = nfs-readahead-udev nfs_readahead_udev_SOURCES = main.c syslog.c +nfs_readahead_udev_LDFLAGS= -lmount udev_rulesdir = /etc/udev/rules.d udev_rules_DATA = 99-nfs_bdi.rules diff --git a/tools/nfs-readahead-udev/main.c b/tools/nfs-readahead-udev/main.c index dd2c9f8c..bbb408c0 100644 --- a/tools/nfs-readahead-udev/main.c +++ b/tools/nfs-readahead-udev/main.c @@ -1,15 +1,145 @@ #include +#include +#include +#include + +#include +#include #include "log.h" +#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; log_open(); - info("Setting the readahead to 128\n"); + if (argc != 2) { + err("Expected device number as argument, got none\n"); + return -EINVAL; + } + + if ((ret = get_device_info(argv[1], &device)) != 0) { + err("Failed to find device %s (%d)\n", argv[1], ret); + goto out; + } + + if (strncmp("nfs", device.fstype, 3) != 0) { + ret = -EINVAL; + info("Not setting the readahead for fstype %s\n", device.fstype); + goto out; + } + + info("Setting %s readahead to 128\n", device.mountpoint); log_close(); printf("%d\n", readahead); + +out: + free_device_info(&device); + return ret; } -- 2.35.1