From patchwork Fri Sep 22 04:12:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 143315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5446376vqi; Fri, 22 Sep 2023 03:02:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHe9UdNKMxG6aZ1s6c5Sh11SZhdyStI46w1Tl0zmfYyqXN9HI911Z80XK8mXwOVQCdWHFUm X-Received: by 2002:a05:6808:1304:b0:3ae:2850:b481 with SMTP id y4-20020a056808130400b003ae2850b481mr164737oiv.17.1695376960269; Fri, 22 Sep 2023 03:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695376960; cv=none; d=google.com; s=arc-20160816; b=XLLtGS89PjFIiiXB3PB8x9l6saM8EuPx6tplb2Kx1/Eo1w4LNYY49bYJ51tsrQr8Nl npIJ0CL2orGvkn4uHxtwwbtwPOkQ0bVF6tpVk6ciHjfJ0T52Sm7ll4BJmCKfUHrYh8Yb UKofCVrRjiL8olKhzwAtypsi+NUTjsWJvurHLc5SAclwvYhbyXVhpJKqqg91hkD/L80Z lXuTSpgHAnsd+XOiyycGVQEYGH9jP+PfqjYH8Sstl/jg4lrCHBcAqSfSbMfaI2u4x/d+ r1Qwd8OMUTVOPm6NnRvS4dgcSyAJh4hhQxj1H7r8Tww9jWt9zXwfy1aQeMii3dF3lPf8 dtpA== 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 :feedback-id:dkim-signature:dkim-signature; bh=F3KK0azHrvJ3S4DAAH+Vjr5j2tc3bC5JP4rnLJ/SSuQ=; fh=tOzwWtfY/Ihw0ZG9uDufqX7N1fYPvJMmg28cxm4BgX4=; b=AhUprIF152Pnai72DuPo6Z8scXX+lrGQWX2L+BflOKY5ZAYgUqDIrk6m4EWUEWxDEy 4rw+JyExu8r4M4Ergtg54OQmTFeRBhDbkPiiqwia08/1v/rMLc4aBxjlZXMnR75QMB1M AtQYeCJsgLaK53M4a1rjOaQhJnsKaRkZdxhtnH9mtnjZm+IKyVzw0/np1cbf9regqklb 4ndwnO0Mmd010JEOlQuYv32Pi3w3eS6tQgdSlrf7+VPdn/jymp7BwCBrpM0bY5ya2UBK H6SEroJEs13EB4+TWHS2HHs5WedEUBIKQm5fc7V5eICj8pvqhKuXND67LpeAexyE6mUN cT5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@themaw.net header.s=fm1 header.b=H81IOwlm; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=QB6lMBWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e191-20020a6369c8000000b00578b9314261si3310167pgc.437.2023.09.22.03.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 03:02:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@themaw.net header.s=fm1 header.b=H81IOwlm; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=QB6lMBWA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id CAAB682DDF93; Thu, 21 Sep 2023 21:13:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231129AbjIVENd (ORCPT + 30 others); Fri, 22 Sep 2023 00:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbjIVENG (ORCPT ); Fri, 22 Sep 2023 00:13:06 -0400 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47CA2100; Thu, 21 Sep 2023 21:12:54 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 979565C0232; Fri, 22 Sep 2023 00:12:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 22 Sep 2023 00:12:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=themaw.net; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1695355973; x= 1695442373; bh=F3KK0azHrvJ3S4DAAH+Vjr5j2tc3bC5JP4rnLJ/SSuQ=; b=H 81IOwlmkYtrJv8vDJiJPq3FUWLzvvHTxbiNPTDq0W7MLhClHzD0FDTF97QQ/hEa6 t6oMaretIz/pM5ahS1WPK6VzGXSnDaAd5qWKzvbxAUDqMGo9/abhpfkk8DGha1Vn zxQOY9wjBTWqt0ADZ2aXskleKXZkFaHHKRQb/zMvSstd1GFpskOjHQA786wCw3VE 4p0B+0tYXcYZF69lni/XJgfRMAFnSYkMpXAu69uxz3Do1G0jZp2AjV8hDfWKQ7fn D/DYYA06n/kasIUl/tkaY/xgdqWs5RuVEiNbs6/Sgz9V/gdAhq42UV17PZ5eGcZ2 WIdgwLiX5eW8NmkWlyG+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1695355973; x= 1695442373; bh=F3KK0azHrvJ3S4DAAH+Vjr5j2tc3bC5JP4rnLJ/SSuQ=; b=Q B6lMBWAVWbjSzSoaiiNPaalZYj62ulHn2Gxy2ayy0kW2PC1HKCEWiEXSYpl14UwQ hi+UChcd8IwnANXXsdUzYjnwyQv9iO/iAsgg2jDnxbLTzzja+n34VqPK3MNw1z5w 5mhkiAhiwL/UneFstCgPUH9hs86mh8F55ycx1ZAi2IEr8cAy1o0k2GugWSEOFO5I QmjRXGazQifIWXCGvu9S+S35PoFi1uStX8ATCEsX0DYcOnj0k+BS7xXcI0thN3LG avN1oowNGbdzTEuKGUnX9xXbJaztzBkwT2XLBoFboUfSjiejLgxKOzyMa5t5j4AV hDH0vhsA85vakhjTEzX3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekjedgjeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepkfgrnhcu mfgvnhhtuceorhgrvhgvnhesthhhvghmrgifrdhnvghtqeenucggtffrrghtthgvrhhnpe duleegueffgfehudeufedtffeiudfghfejgeehvdffgefgjeetvdfffeeihfdvveenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrrghvvghnse hthhgvmhgrfidrnhgvth X-ME-Proxy: Feedback-ID: i31e841b0:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Sep 2023 00:12:49 -0400 (EDT) From: Ian Kent To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells , Ian Kent Subject: [PATCH 5/8] autofs: refactor parse_options() Date: Fri, 22 Sep 2023 12:12:12 +0800 Message-ID: <20230922041215.13675-6-raven@themaw.net> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230922041215.13675-1-raven@themaw.net> References: <20230922041215.13675-1-raven@themaw.net> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 21:13:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777731591558385790 X-GMAIL-MSGID: 1777731591558385790 Seperate out parts of parse_options() that will match better the individual option processing used in the mount API to further simplify the upcoming conversion. Signed-off-by: Ian Kent --- fs/autofs/inode.c | 136 ++++++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 64 deletions(-) diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c index d2b333c0682a..5e061ce3ab8d 100644 --- a/fs/autofs/inode.c +++ b/fs/autofs/inode.c @@ -167,18 +167,84 @@ static int autofs_parse_fd(struct autofs_sb_info *sbi, int fd) return 0; } -static int parse_options(char *options, - struct inode *root, int *pgrp, bool *pgrp_set, - struct autofs_sb_info *sbi) +static int autofs_parse_param(char *optstr, struct inode *root, + int *pgrp, bool *pgrp_set, + struct autofs_sb_info *sbi) { - char *p; substring_t args[MAX_OPT_ARGS]; int option; int pipefd = -1; kuid_t uid; kgid_t gid; + int token; int ret; + token = match_token(optstr, tokens, args); + switch (token) { + case Opt_fd: + if (match_int(args, &pipefd)) + return 1; + ret = autofs_parse_fd(sbi, pipefd); + if (ret) + return 1; + break; + case Opt_uid: + if (match_int(args, &option)) + return 1; + uid = make_kuid(current_user_ns(), option); + if (!uid_valid(uid)) + return 1; + root->i_uid = uid; + break; + case Opt_gid: + if (match_int(args, &option)) + return 1; + gid = make_kgid(current_user_ns(), option); + if (!gid_valid(gid)) + return 1; + root->i_gid = gid; + break; + case Opt_pgrp: + if (match_int(args, &option)) + return 1; + *pgrp = option; + *pgrp_set = true; + break; + case Opt_minproto: + if (match_int(args, &option)) + return 1; + sbi->min_proto = option; + break; + case Opt_maxproto: + if (match_int(args, &option)) + return 1; + sbi->max_proto = option; + break; + case Opt_indirect: + set_autofs_type_indirect(&sbi->type); + break; + case Opt_direct: + set_autofs_type_direct(&sbi->type); + break; + case Opt_offset: + set_autofs_type_offset(&sbi->type); + break; + case Opt_strictexpire: + sbi->flags |= AUTOFS_SBI_STRICTEXPIRE; + break; + case Opt_ignore: + sbi->flags |= AUTOFS_SBI_IGNORE; + } + + return 0; +} + +static int parse_options(char *options, + struct inode *root, int *pgrp, bool *pgrp_set, + struct autofs_sb_info *sbi) +{ + char *p; + root->i_uid = current_uid(); root->i_gid = current_gid(); @@ -186,71 +252,13 @@ static int parse_options(char *options, return 1; while ((p = strsep(&options, ",")) != NULL) { - int token; - if (!*p) continue; - token = match_token(p, tokens, args); - switch (token) { - case Opt_fd: - if (match_int(args, &pipefd)) - return 1; - ret = autofs_parse_fd(sbi, pipefd); - if (ret) - return 1; - break; - case Opt_uid: - if (match_int(args, &option)) - return 1; - uid = make_kuid(current_user_ns(), option); - if (!uid_valid(uid)) - return 1; - root->i_uid = uid; - break; - case Opt_gid: - if (match_int(args, &option)) - return 1; - gid = make_kgid(current_user_ns(), option); - if (!gid_valid(gid)) - return 1; - root->i_gid = gid; - break; - case Opt_pgrp: - if (match_int(args, &option)) - return 1; - *pgrp = option; - *pgrp_set = true; - break; - case Opt_minproto: - if (match_int(args, &option)) - return 1; - sbi->min_proto = option; - break; - case Opt_maxproto: - if (match_int(args, &option)) - return 1; - sbi->max_proto = option; - break; - case Opt_indirect: - set_autofs_type_indirect(&sbi->type); - break; - case Opt_direct: - set_autofs_type_direct(&sbi->type); - break; - case Opt_offset: - set_autofs_type_offset(&sbi->type); - break; - case Opt_strictexpire: - sbi->flags |= AUTOFS_SBI_STRICTEXPIRE; - break; - case Opt_ignore: - sbi->flags |= AUTOFS_SBI_IGNORE; - break; - default: + if (autofs_parse_param(p, root, pgrp, pgrp_set, sbi)) return 1; - } } + return (sbi->pipefd < 0); }