From patchwork Mon Jun 24 19:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13710008 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 E8AEC1A01C7 for ; Mon, 24 Jun 2024 19:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258069; cv=none; b=pSvKlwJpTGjvjHJm/MI/EZmcGd2j5syN8mJL6JENtM4c6zcyXeDkxVD0WyBoCekhHTEWBYHkXHyrgjSre26ij2bmhqta3m94jxqkee78PtbyrvbfQmN6acdj17ldljWuLHnNLc5ie7uPNAWJWAONyvBhcoXWCzJnkpLFeYiLEJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258069; c=relaxed/simple; bh=uzxwDEpdZWbOlWe+EVCBC/uCl/ucKlhIkrhQYs8YMNQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HehP0ObcTqzXuXjLb2AXfAuw3mq5TDyeeQOIZE/BDaqzCJJvxgRw5RLZ6GFzI5aUJLXCShGYpuANbGQqwa2tDkjis1Enodt4giFaLcKbGKJHASbsAc8io5LB0nOzVcWXS2D+jXjcfZP13TVD8ICkxxseo/AxbjfVR85nI1tTwvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=FD9qguVQ; arc=none smtp.client-ip=209.85.210.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="FD9qguVQ" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-7008acebf3fso2095542a34.2 for ; Mon, 24 Jun 2024 12:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1719258067; x=1719862867; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HKDHOAdA7jAJSq+nL+j4X9y2JU2i+CxKLmyZslQ93Zk=; b=FD9qguVQ/1iknMSECgLkZVSBWEE2/Ygj/T518gElzvaQ9L3qan2Sb7dw7rmFPH4SYB vxCTeJqDpTPiqXju2+GhCkIrNZmkBzFHVYdKvxXY1MCiK1/LkYApJ+e+8RGHwAvYP+kf qWzjy9FEC9hPk9LfN5uZA2tCB0i4b+hgWf437n1Og6WYOLW2ITxu5NQ1sGhunVEruBN3 +qgMiMg8uYks7i8gE+7ufYgwTsTHEVFFYfEjfX+MQ8rkSI5Id2Xui8Kln0BHWw7R7jp2 2Ygu5IiX042uNwPdGwwtM1RetMc1NbSU0mSLmIqumNWOZg1yLJ0bnW+85UJ5t+2WbIHx mZyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719258067; x=1719862867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HKDHOAdA7jAJSq+nL+j4X9y2JU2i+CxKLmyZslQ93Zk=; b=syO2NOlMW7JXPWZaGIuegGn4cKrXSKrA0+OHQjHAL0Z92bbwDJVeIAwEtH1YTfFJq0 AwL/FEiuJsskiOUKFy7mvEBr5dBHplD8ZeVHVH4tlwwfeDIRdbyLhD3qBu5uQCQ2Ka13 HbHEX/YeWLIdP1/G0iHIY/CckUyWDzlS6PH8wDCZDB+PyhR8R8wegc0wPc4tdLKcyR9M Ffei8DDh4lGwKQuHPYaYBkLuK+2EFdQKIoQhcCsXmJcznFLiY9RuV4ighykeNVkjRGUq x/PW0z9+oUbeONG7dNh5A6hwmTX8hKFPXjE5oRKGoyh6qHADLq3f/MyEN75fhfuMsV9+ EjWQ== X-Gm-Message-State: AOJu0YwL0elUGfl8nEtUR03UhgHCYPC7udwfKeKSrtX9NLclm5Kxtgki siN45OJvDmjQY1NEWsOArbZq2pKigOadaFZ6HxkxNgvY5ETIvs/Qh4fKbEhNvh8nzeRqbMllCb4 g X-Google-Smtp-Source: AGHT+IFa3/tvXh8OckQVNoG+/SEBA5252iL4LtiV7YMybMMezqoS/Pe1/jTdxTmIpcRl3zQcoouiIw== X-Received: by 2002:a05:6870:b151:b0:254:77f7:7bdd with SMTP id 586e51a60fabf-25d0198d044mr6312396fac.50.1719258066883; Mon, 24 Jun 2024 12:41:06 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce89d612sm341032685a.5.2024.06.24.12.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 12:41:06 -0700 (PDT) From: Josef Bacik To: linux-fsdevel@vger.kernel.org, brauner@kernel.org, kernel-team@fb.com Subject: [PATCH 1/4] fs: rename show_mnt_opts -> show_vfsmnt_opts Date: Mon, 24 Jun 2024 15:40:50 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This name is more consistent with what the helper does, which is to just show the vfsmount options. Signed-off-by: Josef Bacik --- fs/proc_namespace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c index 0a808951b7d3..e133b507ddf3 100644 --- a/fs/proc_namespace.c +++ b/fs/proc_namespace.c @@ -61,7 +61,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb) return security_sb_show_options(m, sb); } -static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt) +static void show_vfsmnt_opts(struct seq_file *m, struct vfsmount *mnt) { static const struct proc_fs_opts mnt_opts[] = { { MNT_NOSUID, ",nosuid" }, @@ -124,7 +124,7 @@ static int show_vfsmnt(struct seq_file *m, struct vfsmount *mnt) err = show_sb_opts(m, sb); if (err) goto out; - show_mnt_opts(m, mnt); + show_vfsmnt_opts(m, mnt); if (sb->s_op->show_options) err = sb->s_op->show_options(m, mnt_path.dentry); seq_puts(m, " 0 0\n"); @@ -153,7 +153,7 @@ static int show_mountinfo(struct seq_file *m, struct vfsmount *mnt) goto out; seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw"); - show_mnt_opts(m, mnt); + show_vfsmnt_opts(m, mnt); /* Tagged fields ("foo:X" or "bar") */ if (IS_MNT_SHARED(r)) From patchwork Mon Jun 24 19:40:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13710009 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.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 0B6761A01C8 for ; Mon, 24 Jun 2024 19:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258071; cv=none; b=Xw1mxN0b1pZyLWCz+Ki5NIL5kodtitE0fu/LwcNmT9FxwnexfIkf9i7kfzRqRBg58pfTHKiwTmZwn5IdtTO1hZDbIV1MmxF5P2OcG9/8BAP7yE8LkrZ4KYva3o4h5/Lky0zPjMyXqickx5mNrZGDou+gvM43J62oY4zQMfQmAoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258071; c=relaxed/simple; bh=JY8desCnZGfGCcwAJYVAT/H3v4UHKfupLgaJk2Z97jI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NcxIXtzkfrVdMloSamt0Ud2JVjL4YBUfUDUeugeLcYE7yhzPGYWM5I5NdUObr5d1mc+ozin+gt98uGO8rmDmB7oxWzN72D2SJ/lKZ3tV9GbFPfrhMdxuqTj0p0mfG6IM5ojEHn9c3arK+WrZ/auhwntglbqJ1BZGee9sJIFQFdU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Jy8cDez/; arc=none smtp.client-ip=209.85.160.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Jy8cDez/" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-25d0d16e38eso839182fac.2 for ; Mon, 24 Jun 2024 12:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1719258068; x=1719862868; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7Mn4lrx/Zmh33vObbaTy4J8GMzf6Ir22NpWlaU7qZ+M=; b=Jy8cDez/JmrK+XYbmnsPYcNo8Qr3CNtwRDMyWAvuWZdxbg43vupElyGLhcPOjJwhQw ZGI9etkQDhDwhxbYNR4UI6Oul6OdpLnFpELi4pzXv9WEswU24qxnIaowjFjVWVNasmWX DqL/2N+8zU/CUvmJ7EOsTkDZ194xsjZEl/aeJkmWuKwl7zAVWLuUi2vsuNRkYaxRkESh EhwHZ/EPwgrM0bCoxzfCCnR3v2uMGWOx9amWDEzXLrjQmWj8oQGinoWNkNH9QwzjWdMd ohQQrEXuhQGW4Ylky2jz11wlgiVSdUpPC2o/JLD/TEq5lCsz5ZTkpdi9bIjl+OWRuCMp vnFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719258068; x=1719862868; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7Mn4lrx/Zmh33vObbaTy4J8GMzf6Ir22NpWlaU7qZ+M=; b=ujtA360slqEy1mr7XfwqFXVDZQZAirecVCNKB1QC1SHCHFNQgeVNb5/78IcujyqoFr 4oju8xrUnnyQrVd73wJ/T9tpcnlslD1XCQYtYBVjkSfS6k9s4qBj0fn0tDw7VBCP0twM 3xJI3MKGoCizzKul9U2rDJkGYpm7BvaMS5P9KcY4HaB9Ss3kKGhmjg3Ubzsa+DtuUcfa yGqCsWMi3cBuGXuGbpJ0kmrD1FIv64go5kg+vldR4SNYTEG/34DLmSwBCrzbOsqUqJLs YtGQLyN7mgD+X1imYUOT92Hl8EEKNue7HdYffLSrG8P0/JCIaP3f9e5aUdFSr8H1Kc2v zarQ== X-Gm-Message-State: AOJu0Yz2KiHN3QgszSqYvKhAGTCOTpQ+AUQDjP1ODA7qz2RJuKOps52G KIRdBrLo+Pgzb0Z47FUIyDm85/1i1LxcZNZ05qAPDZtWH0FQAlfJ1IVZB8myVTbOwnefI+4p1ES J X-Google-Smtp-Source: AGHT+IFhHtqnr4BvIholprKhwsCe6LjGyXizQ9Be97t+HwWgmHx+kgx0cXBu/JEeJwQKiaVKS//1XQ== X-Received: by 2002:a05:6870:e242:b0:254:783d:aeb4 with SMTP id 586e51a60fabf-25d06cad9a8mr5788510fac.35.1719258067909; Mon, 24 Jun 2024 12:41:07 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce931bf0sm341929085a.112.2024.06.24.12.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 12:41:07 -0700 (PDT) From: Josef Bacik To: linux-fsdevel@vger.kernel.org, brauner@kernel.org, kernel-team@fb.com Subject: [PATCH 2/4] fs: add a helper to show all the options for a mount Date: Mon, 24 Jun 2024 15:40:51 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to add the ability to export the mount options via statmount() we need a helper to combine all the various mount option things we do for /proc/mounts and /proc/$PID/mountinfo. The helper for /proc/mounts can use this helper, however mountinfo is slightly (and infuriatingly) different, so it can only be used in one place. This helper will be used in a followup patch to export mount options via statmount(). Signed-off-by: Josef Bacik --- fs/internal.h | 5 +++++ fs/proc_namespace.c | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 84f371193f74..dc40c9d4173f 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -321,3 +321,8 @@ struct stashed_operations { int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data, struct path *path); void stashed_dentry_prune(struct dentry *dentry); + +/* + * fs/proc_namespace.c + */ +int show_mount_opts(struct seq_file *seq, struct vfsmount *mnt); diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c index e133b507ddf3..19bffd9d80dc 100644 --- a/fs/proc_namespace.c +++ b/fs/proc_namespace.c @@ -84,6 +84,22 @@ static void show_vfsmnt_opts(struct seq_file *m, struct vfsmount *mnt) seq_puts(m, ",idmapped"); } +int show_mount_opts(struct seq_file *seq, struct vfsmount *mnt) +{ + struct dentry *dentry = mnt->mnt_root; + struct super_block *sb = dentry->d_sb; + int ret; + + seq_puts(seq, __mnt_is_readonly(mnt) ? "ro" : "rw"); + ret = show_sb_opts(seq, sb); + if (ret) + return ret; + show_vfsmnt_opts(seq, mnt); + if (sb->s_op->show_options) + ret = sb->s_op->show_options(seq, dentry); + return ret; +} + static inline void mangle(struct seq_file *m, const char *s) { seq_escape(m, s, " \t\n\\#"); @@ -120,13 +136,8 @@ static int show_vfsmnt(struct seq_file *m, struct vfsmount *mnt) goto out; seq_putc(m, ' '); show_type(m, sb); - seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); - err = show_sb_opts(m, sb); - if (err) - goto out; - show_vfsmnt_opts(m, mnt); - if (sb->s_op->show_options) - err = sb->s_op->show_options(m, mnt_path.dentry); + seq_putc(m, ' '); + err = show_mount_opts(m, mnt); seq_puts(m, " 0 0\n"); out: return err; From patchwork Mon Jun 24 19:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13710010 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (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 A7BFC1A0720 for ; Mon, 24 Jun 2024 19:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258072; cv=none; b=KzOWCEdQPy1oRK5felIRZgKrVMQuHt6UXXZiCDSQJ9GtkEeCe5aejoPZE67l07BsRWp6H8rmI5t4KJr7seO5tVh4RR8ff5uurd3d87ACFHtylI/5iEcBRzKWDiEZO2vKPVMy1mU5FArNDE4MTotKMeI5+F9dmKCPyNYrpGanaDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258072; c=relaxed/simple; bh=tOjcCnOLWKqoOb8eV5NCcTg0eL6gd30G4h4ZGS4h3bg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=piWjcCp02qmn/I3CqyDHkCxavTX5n/e9aPOV32XGoYUP7VCyZAs7utsJM+Abec2fevFFn4R+Em2cCS8Ksg/LV2MU9NEvtpwuUlQ1E05PKtc5fdm+VWbSRkv8WsKfkr9nojcrjp38Eu/DxPnVkznahflWKx9S0JGhbP+EhpjUHdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=DD3mue46; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="DD3mue46" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6b5031d696dso23095636d6.3 for ; Mon, 24 Jun 2024 12:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1719258069; x=1719862869; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wa6nsJIfWMaZ6hMNvJrCgTkmvIEPizWz1r158Y5fRPs=; b=DD3mue46vBimUWZlQ7ZzGEEfzarYQawEqVsHjbWyW+0JjMThX2lSHk2pcbvFSw9aLZ 7LmBYPyNOFW8sbO3HxdtMlF1RYfH/1zjK2WtlG1YlG+rNqutgOuYRopRMhyTcA6c8dRX d3TXLUzd2lm7ZfHGcpoBIE+bt6q2FoepwLOxsxzVv2I6WGpGGSCimQxmR+DGu/UziZzd WPBIZQ8xGhjynykzHXYB/2v7EE8S40U8UetQqVueVPHvQUvgA3dh5ntZbi+JoIAazVS3 3qcmA2zIvDLB6/F2qoGgIBQqhSOEc4nWvFpdlKd1m0DUpk1UAz6zoMdPYojewEH1/hAh 3TaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719258069; x=1719862869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wa6nsJIfWMaZ6hMNvJrCgTkmvIEPizWz1r158Y5fRPs=; b=bBa/DkDJpufkcM9SSfqANIWxUV/xJWYJ5FMMPXFTBjdL8Qv60IV1k0eKs50ul4Qb5z elxRtSeNGr2hMWPDeqKq2q2Lv9mBAUuxjmeNZig/xvlWIwmntLoRN52pEzcdy7HLJHyc JM7N7kn5wJ0oqydN6lvGbqI739eY4/kNiQ4gKU2jrZzzvZmSlJJraFRbhuQh63NuTB3Z HfGPcMjLKKAcC1BxIhxYYzQkIkLl8YYQvUECYHVGXWLuajBZ0lue4SgISVB92d7+6YfN v3+OKZYJ9dyqiWNsrQfQvd20QROymN4dW4wR1Fx/mC3ZbC+MYjgmxqosIsrLLzVoRr5r asIg== X-Gm-Message-State: AOJu0YwhnW0yRB3y9mxzxuyNjuFJ5LGQovtsVioc3OXEChWGh9qfrZn9 B8feSn+I78couh0p+Sahq2xhdtPfAOWCVJC/MzY58q8KS1UkHFrG/ksx3j3U2O0u/cYhnR5q2W8 3 X-Google-Smtp-Source: AGHT+IFFRe/FrKxDsDFAb01H5ntOS8Qt9g757y8jrvD+00Diw5Mjwnl7/BB5Twlvxy+YWl2g2qlJmQ== X-Received: by 2002:a0c:c988:0:b0:6b5:6f9:4846 with SMTP id 6a1803df08f44-6b540bf4a8emr56833896d6.53.1719258069176; Mon, 24 Jun 2024 12:41:09 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b51ef6b12fsm36944046d6.134.2024.06.24.12.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 12:41:08 -0700 (PDT) From: Josef Bacik To: linux-fsdevel@vger.kernel.org, brauner@kernel.org, kernel-team@fb.com Subject: [PATCH 3/4] fs: export mount options via statmount() Date: Mon, 24 Jun 2024 15:40:52 -0400 Message-ID: <3aa6bf8bd5d0a21df9ebd63813af8ab532c18276.1719257716.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 statmount() can export arbitrary strings, so utilize the __spare1 slot for a mnt_opts string pointer, and then support asking for and setting the mount options during statmount(). This calls into the helper for showing mount options, which already uses a seq_file, so fits in nicely with our existing mechanism for exporting strings via statmount(). Signed-off-by: Josef Bacik --- fs/namespace.c | 7 +++++++ include/uapi/linux/mount.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index 6d44537fd78c..2a6a8cbf5d0a 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -5003,6 +5003,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->mnt_point = seq->count; ret = statmount_mnt_point(s, seq); break; + case STATMOUNT_MNT_OPTS: + sm->mnt_opts = seq->count; + ret = show_mount_opts(seq, s->mnt); + break; default: WARN_ON_ONCE(true); return -EINVAL; @@ -5079,6 +5083,9 @@ static int do_statmount(struct kstatmount *s) if (!err && s->mask & STATMOUNT_MNT_POINT) err = statmount_string(s, STATMOUNT_MNT_POINT); + if (!err && s->mask & STATMOUNT_MNT_OPTS) + err = statmount_string(s, STATMOUNT_MNT_OPTS); + if (!err && s->mask & STATMOUNT_MNT_NS_ID) statmount_mnt_ns_id(s, ns); diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h index ee1559cd6764..225bc366ffcb 100644 --- a/include/uapi/linux/mount.h +++ b/include/uapi/linux/mount.h @@ -154,7 +154,7 @@ struct mount_attr { */ struct statmount { __u32 size; /* Total size, including strings */ - __u32 __spare1; + __u32 mnt_opts; /* [str] Mount options of the mount */ __u64 mask; /* What results were written */ __u32 sb_dev_major; /* Device ID */ __u32 sb_dev_minor; @@ -206,6 +206,7 @@ struct mnt_id_req { #define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */ #define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */ #define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */ +#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */ /* * Special @mnt_id values that can be passed to listmount From patchwork Mon Jun 24 19:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13710011 Received: from mail-vk1-f176.google.com (mail-vk1-f176.google.com [209.85.221.176]) (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 A56F91A072D for ; Mon, 24 Jun 2024 19:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258073; cv=none; b=at3/NqxWI8+W15RGM3ay1SAjWtTP22exfGchGmHwbcc5Wxet44yVUKNfNa8pVDISACS51pB8KT9zHFhlFgrlqubjJsh8krv50vnWmDccUNKW8QubV6e/Fr6tEMgu4glPgmuEy6eKFzZ9hMx+k8ehjlXqfpWBRdwayaBzTWW44B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719258073; c=relaxed/simple; bh=YSdpllJMtL3qq4g/8DhcpaxU5OyUxPFch0vjMfoWgLs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SXFxvki98yvtLjn8H4UIZa0xpdZekWGAA0qGBRZf5Ekc+L2aV62UfhSjSkW06vH8tnue0He0RnykFBGe/jF1HBZfPrOiPh/zPEbqE5TV61CaoRYELwGlU+By6P/6OOM454ik7dmE+eL90rjRSMzuN7NGWGmQ5C33PWbryAmkv1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=BVcPo0a7; arc=none smtp.client-ip=209.85.221.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="BVcPo0a7" Received: by mail-vk1-f176.google.com with SMTP id 71dfb90a1353d-4eb02c0c851so1500000e0c.0 for ; Mon, 24 Jun 2024 12:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1719258070; x=1719862870; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6B3HNmy01Oxg3r108cXAxfyeaHwUFHeuEPdI0tcKkLU=; b=BVcPo0a7HtMZes+DyeFQ5xnCwqK3Y4co9LyUJE++51IijUXtsj9y8CrKCjzMooLGlt j0f5XhReSfU6j0aDgFSNwik6JHSrWgwSCS1FZy8V7qnuVKwCjB1FbItylmN7WG4XlfMM M+UEcDv8m8o0f4Y5eD3BxHMQWV4VCryuqVVlbgTm2I88tBwlIBGvm8sOGYaUqtw+yEWo Cp9x8mPFuJ5uzhOmy3SwwSt9Y5ApglIsEJYPmv9hIWfnb2N3RU1aSXGBOlsjMz1u/wTa VPsNmha2HgWRHo31hFe9XKSZo4FaqIviTlYcwa7KFJwuKsBoTYTpjqsbq8WcbKqIbwGS txkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719258070; x=1719862870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6B3HNmy01Oxg3r108cXAxfyeaHwUFHeuEPdI0tcKkLU=; b=qBEf1pJLFeA3ixA4hRGk7k7lXFsVSdJNgz4XSOPbWwPlVvORWkONOeBKI2ZeCYxX7t 94JUmFXdnqqJpwJlfOhQ/KoG5OXUp9OH+AFkXrsKRurKfkRNONH+G9eQvI6HAdnHYfNG u1jEC+a4ESRakmmx73clomrjpkoJABmE5VnD4x3DwhdVVPZbdOSN7/ddNSBqBHDABe43 C6AAPvLW4XFcf4Qjaz076tTe6SIPAfdGMTwrKXVFYZq58E6jA6RlYCz00Tw4lru5laAN sJq2IdrU/8BE5tqz7OghtIinSh5q9WhDRpTeFTGx5PRWguJ2VV3io+f3TG4t0fVfDApq k42A== X-Gm-Message-State: AOJu0Yw+XDYcaV+WNIFrB9/ia7s7EePRUi5N7++tZxhH/JwS0hwXnLug z0DMFX1kS+nzaygSGiiSn4Bthz1mgTQcp3/BFvkUMVBWZu9YTFQrPnYeANmL7W3AypOZKueCun8 l X-Google-Smtp-Source: AGHT+IGpbYdNxBm5FoJaH9VzK0libR+U9HJFAHMKBSWVMsDRY11vQBLNK9Jp1vqMBrPPc2CAK0mJ/w== X-Received: by 2002:a05:6122:786:b0:4ec:f8b1:a34b with SMTP id 71dfb90a1353d-4ef663953b9mr4741911e0c.8.1719258070331; Mon, 24 Jun 2024 12:41:10 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b51ef6e795sm36594946d6.141.2024.06.24.12.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 12:41:10 -0700 (PDT) From: Josef Bacik To: linux-fsdevel@vger.kernel.org, brauner@kernel.org, kernel-team@fb.com Subject: [PATCH 4/4] sefltests: extend the statmount test for mount options Date: Mon, 24 Jun 2024 15:40:53 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we support exporting mount options, via statmount(), add a test to validate that it works. Signed-off-by: Josef Bacik --- .../filesystems/statmount/statmount_test.c | 131 +++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test.c b/tools/testing/selftests/filesystems/statmount/statmount_test.c index 4f7023c2de77..96696183d27b 100644 --- a/tools/testing/selftests/filesystems/statmount/statmount_test.c +++ b/tools/testing/selftests/filesystems/statmount/statmount_test.c @@ -64,6 +64,20 @@ static struct statmount *statmount_alloc(uint64_t mnt_id, uint64_t mask, unsigne return buf; } +static void read_file(const char *path, void *buf, size_t len) +{ + int fd = open(path, O_RDONLY); + ssize_t ret; + + if (fd < 0) + ksft_exit_fail_msg("opening %s for read: %s\n", path, strerror(errno)); + + ret = read(fd, buf, len); + if (ret < 0) + ksft_exit_fail_msg("reading from %s: %s\n", path, strerror(errno)); + close(fd); +} + static void write_file(const char *path, const char *val) { int fd = open(path, O_WRONLY); @@ -107,6 +121,8 @@ static char root_mntpoint[] = "/tmp/statmount_test_root.XXXXXX"; static int orig_root; static uint64_t root_id, parent_id; static uint32_t old_root_id, old_parent_id; +static char proc_mounts_buf[4096]; +static char proc_mountinfo_buf[4096]; static void cleanup_namespace(void) { @@ -134,6 +150,11 @@ static void setup_namespace(void) sprintf(buf, "0 %d 1", gid); write_file("/proc/self/gid_map", buf); + memset(proc_mounts_buf, 0, 4096); + memset(proc_mountinfo_buf, 0, 4096); + read_file("/proc/self/mounts", proc_mounts_buf, 4095); + read_file("/proc/self/mountinfo", proc_mountinfo_buf, 4095); + ret = mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL); if (ret == -1) ksft_exit_fail_msg("making mount tree private: %s\n", @@ -435,6 +456,113 @@ static void test_statmount_fs_type(void) free(sm); } +/* Search proc_mountinfo_buf for our mount point. */ +static char *find_mnt_point(void) +{ + char buf[256]; + char *cur, *end; + + snprintf(buf, 256, "%llu", (unsigned long long)old_parent_id); + cur = strstr(proc_mountinfo_buf, buf); + if (!cur) + ksft_exit_fail_msg("couldn't find %llu in /proc/self/mountinfo\n", + (unsigned long long)old_parent_id); + + /* + * The format is + * + * + * + * We are currently at , we must skip the next 4 columns. + */ + for (int i = 0; i < 4; i++) { + cur = strchr(cur, ' '); + if (!cur) + ksft_exit_fail_msg("/proc/self/mountinfo isn't formatted as expected\n"); + cur++; + } + + /* + * We are now positioned right at , find the next space and + * \0 it out so we have the mount point isolated. + */ + end = strchr(cur, ' '); + if (!end) + ksft_exit_fail_msg("/proc/self/mountinfo isn't formatted as expected\n"); + *end = '\0'; + return cur; +} + +static void test_statmount_mnt_opts(void) +{ + struct statmount *sm; + char search_buf[256]; + const char *opts; + const char *statmount_opts; + const char *mntpoint; + char *end; + + sm = statmount_alloc(root_id, STATMOUNT_MNT_OPTS, 0); + if (!sm) { + ksft_test_result_fail("statmount mnt opts: %s\n", + strerror(errno)); + return; + } + + mntpoint = find_mnt_point(); + snprintf(search_buf, 256, " %s ", mntpoint); + + /* + * This fun bit of string parsing is to extract out the mount options + * for our root id. Normally it would be the first entry but we don't + * want to rely on on that, so we're going to search for the path + * manually. The format is + * + * ... + * + * We start by searching for and then advancing along until + * we get the field. + */ + + /* Look for the root entry. */ + opts = strstr(proc_mounts_buf, search_buf); + if (!opts) + ksft_exit_fail_msg("no mount entry for / in /proc/mounts\n"); + + /* Now advance us past that chunk, and into the fstype. */ + opts += strlen(search_buf); + + /* Now find the next space. */ + opts = strchr(opts, ' '); + if (!opts) + ksft_exit_fail_msg("/proc/mounts isn't formatted as expected\n"); + + /* Now advance one to the start of where the mount options should be. */ + opts++; + + /* + * Now we go all the way to the end of opts and set that value to \0 so + * we can easily strcmp what we got from statmount(). + * + * If the mount options have a space in them this will mess up the test, + * but I don't know if that happens anywhere. If this fails on that + * then we need to update the test to handle that, but for now I'm going + * to pretend lik that never happens. + */ + end = strchr(opts, ' '); + if (!end) + ksft_exit_fail_msg("/proc/mounts isn't formatted as expected\n"); + *end = '\0'; + + statmount_opts = sm->str + sm->mnt_opts; + if (strcmp(statmount_opts, opts) != 0) + ksft_test_result_fail("unexpected mount options: '%s' != '%s'\n", + statmount_opts, opts); + else + ksft_test_result_pass("statmount mount options\n"); + free(sm); +} + static void test_statmount_string(uint64_t mask, size_t off, const char *name) { struct statmount *sm; @@ -561,7 +689,7 @@ int main(void) setup_namespace(); - ksft_set_plan(14); + ksft_set_plan(15); test_listmount_empty_root(); test_statmount_zero_mask(); test_statmount_mnt_basic(); @@ -569,6 +697,7 @@ int main(void) test_statmount_mnt_root(); test_statmount_mnt_point(); test_statmount_fs_type(); + test_statmount_mnt_opts(); test_statmount_string(STATMOUNT_MNT_ROOT, str_off(mnt_root), "mount root"); test_statmount_string(STATMOUNT_MNT_POINT, str_off(mnt_point), "mount point"); test_statmount_string(STATMOUNT_FS_TYPE, str_off(fs_type), "fs type");