From nobody Sat Jan 08 04:29:37 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A615B193233D; Sat, 8 Jan 2022 04:29:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JW6Yt2WyPz3DlT; Sat, 8 Jan 2022 04:29:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B719C1863A; Sat, 8 Jan 2022 04:29:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2084TbKq022369; Sat, 8 Jan 2022 04:29:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2084TbxM022368; Sat, 8 Jan 2022 04:29:37 GMT (envelope-from git) Date: Sat, 8 Jan 2022 04:29:37 GMT Message-Id: <202201080429.2084TbxM022368@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: b2e4b6358440 - main - msdosfs: add msdosfs_integrity_error() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b2e4b635844091de0601f5b7157d87115386b2a9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641616179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N5TPIEvK4w8MxsMP7LNJttdLdSfYL2qMhhcn3HQzheA=; b=kTeEq/Fq1W9U03faLLsnQa+hKVyWzjB07DRCgMOPPQCvmvc54gu7RGME3t8Ktbq52BCX/q 0WcV8cnL7ZLVRwkr65szZs57dLvTr+7rn/DFHaubesJeUheil6vDEZ1mnJ3tco96qi9KtT eUBL+I7Ot5Ek3ps3GBa1MmXZZ8f7B61Nb3Pwzq42YpnGpemXZ0goYPQwDdkMUIC4V0lqso Xcz/ZH1/HERUAgbNF0GIlC09uOH2h6eCcTeVDvtogBFcerVSYs1pQYa5VoszyccSWFMfwg BtZjkZKadSuCwlBPTWNn9NXW5Fjm4GlOWd7JMtgwT6rJlCj5FfooCiuoQB2W6g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641616179; a=rsa-sha256; cv=none; b=uFwmDfW48YT8G8tX74Rpw7b+eSV8SVfNL+qql8dmS6f6Z48EW9l0Mlr4oQLHnmtuVos7Lq yEzxiWZT8QdwxPEShTqxCkEY0/WieHHc1rPpR06+rJ7JxDXEiG8JGLCWEUJ5BZ3stQyv6s jmz2/52FMCp0ep8OCYcaja+fiz63nFkGxbpeHtYcUHZ2Or5GozXMLP8/xwoCfxmf4vRowF B1+xXGpW71Wt1nL1uhrT+btCZTlzWwr7eLwjEZ6BF4vbmvVRWdwa3XavYbUrHxAimC02yN iLPdiITCJXjQSuazMqrG96L59CReHPqVtqslS+EnElJYGgak3pJnp05Vrgr6Aw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b2e4b635844091de0601f5b7157d87115386b2a9 commit b2e4b635844091de0601f5b7157d87115386b2a9 Author: Konstantin Belousov AuthorDate: 2021-12-25 21:20:56 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-08 04:20:48 +0000 msdosfs: add msdosfs_integrity_error() A function to remount the filesystem from rw to ro on integrity error. The work is performed in taskqueue to allow the call to be done from almost arbitrary context where erronous state was detected. Tested by: pho Reviewed by: markj, mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33721 --- sys/fs/msdosfs/msdosfs_vfsops.c | 58 +++++++++++++++++++++++++++++++++++++++++ sys/fs/msdosfs/msdosfsmount.h | 7 +++++ 2 files changed, 65 insertions(+) diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c index 8ef46e063420..3c2606ab5a91 100644 --- a/sys/fs/msdosfs/msdosfs_vfsops.c +++ b/sys/fs/msdosfs/msdosfs_vfsops.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include @@ -112,6 +113,7 @@ struct iconv_functions *msdosfs_iconv; static int update_mp(struct mount *mp, struct thread *td); static int mountmsdosfs(struct vnode *devvp, struct mount *mp); +static void msdosfs_remount_ro(void *arg, int pending); static vfs_fhtovp_t msdosfs_fhtovp; static vfs_mount_t msdosfs_mount; static vfs_root_t msdosfs_root; @@ -337,6 +339,13 @@ msdosfs_mount(struct mount *mp) mp->mnt_flag &= ~MNT_RDONLY; MNT_IUNLOCK(mp); } + + /* + * Avoid namei() below. The "from" option is not set. + * Update of the devvp is pointless for this case. + */ + if ((pmp->pm_flags & MSDOSFS_ERR_RO) != 0) + return (0); } /* * Not an update, or updating the name: look up the name @@ -471,6 +480,8 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp) lockinit(&pmp->pm_fatlock, 0, msdosfs_lock_msg, 0, 0); lockinit(&pmp->pm_checkpath_lock, 0, "msdoscp", 0, 0); + TASK_INIT(&pmp->pm_rw2ro_task, 0, msdosfs_remount_ro, pmp); + /* * Initialize ownerships and permissions, since nothing else will * initialize them iff we are mounting root. @@ -847,6 +858,53 @@ msdosfs_unmount(struct mount *mp, int mntflags) return (error); } +static void +msdosfs_remount_ro(void *arg, int pending) +{ + struct msdosfsmount *pmp; + int error; + + pmp = arg; + + MSDOSFS_LOCK_MP(pmp); + if ((pmp->pm_flags & MSDOSFS_ERR_RO) != 0) { + while ((pmp->pm_flags & MSDOSFS_ERR_RO) != 0) + msleep(&pmp->pm_flags, &pmp->pm_fatlock, PVFS, + "msdoserrro", hz); + } else if ((pmp->pm_mountp->mnt_flag & MNT_RDONLY) == 0) { + pmp->pm_flags |= MSDOSFS_ERR_RO; + MSDOSFS_UNLOCK_MP(pmp); + printf("%s: remounting read-only due to corruption\n", + pmp->pm_mountp->mnt_stat.f_mntfromname); + error = vfs_remount_ro(pmp->pm_mountp); + if (error != 0) + printf("%s: remounting read-only failed: error %d\n", + pmp->pm_mountp->mnt_stat.f_mntfromname, error); + else + printf("remounted %s read-only\n", + pmp->pm_mountp->mnt_stat.f_mntfromname); + MSDOSFS_LOCK_MP(pmp); + pmp->pm_flags &= ~MSDOSFS_ERR_RO; + wakeup(&pmp->pm_flags); + } + MSDOSFS_UNLOCK_MP(pmp); + + vfs_unbusy(pmp->pm_mountp); +} + +void +msdosfs_integrity_error(struct msdosfsmount *pmp) +{ + int error; + + error = vfs_busy(pmp->pm_mountp, MBF_NOWAIT); + if (error == 0) + taskqueue_enqueue(taskqueue_thread, &pmp->pm_rw2ro_task); + else + printf("%s: integrity error busying failed, error %d\n", + pmp->pm_mountp->mnt_stat.f_mntfromname, error); +} + static int msdosfs_root(struct mount *mp, int flags, struct vnode **vpp) { diff --git a/sys/fs/msdosfs/msdosfsmount.h b/sys/fs/msdosfs/msdosfsmount.h index 46a02e611cf5..6a0ba896dff5 100644 --- a/sys/fs/msdosfs/msdosfsmount.h +++ b/sys/fs/msdosfs/msdosfsmount.h @@ -59,6 +59,7 @@ #ifndef MAKEFS #include #include +#include #endif #include @@ -115,6 +116,7 @@ struct msdosfsmount { #ifndef MAKEFS struct lock pm_fatlock; /* lockmgr protecting allocations */ struct lock pm_checkpath_lock; /* protects doscheckpath result */ + struct task pm_rw2ro_task; /* context for emergency remount ro */ #endif }; @@ -263,5 +265,10 @@ struct msdosfs_args { #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ #define MSDOSFS_FSIMOD 0x01000000 +#define MSDOSFS_ERR_RO 0x00800000 /* remouning ro due to error */ + +#ifdef _KERNEL +void msdosfs_integrity_error(struct msdosfsmount *pmp); +#endif #endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */