From owner-svn-src-stable@freebsd.org Sat Mar 12 19:07:23 2016 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0EF8BACCF0F; Sat, 12 Mar 2016 19:07:23 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C66B688B; Sat, 12 Mar 2016 19:07:22 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u2CJ7LVa073908; Sat, 12 Mar 2016 19:07:21 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u2CJ7LcM073904; Sat, 12 Mar 2016 19:07:21 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201603121907.u2CJ7LcM073904@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Sat, 12 Mar 2016 19:07:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r296752 - in stable/10: share/man/man4 sys/dev/filemon X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Mar 2016 19:07:23 -0000 Author: bdrewery Date: Sat Mar 12 19:07:21 2016 New Revision: 296752 URL: https://svnweb.freebsd.org/changeset/base/296752 Log: MFC r296286,r296470,r296472,r296473,r296575: r296286: Remove filemon->lock wrappers. r296470: Only call bwillwrite() for logging to vnodes, as other fo_write() calls do. r296472: Require kldunload -f to unload. r296473: Add missing break for r296472. r296575: FILEMON_SET_FD: Disallow changing the fd. Modified: stable/10/share/man/man4/filemon.4 stable/10/sys/dev/filemon/filemon.c stable/10/sys/dev/filemon/filemon_lock.c stable/10/sys/dev/filemon/filemon_wrapper.c Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man4/filemon.4 ============================================================================== --- stable/10/share/man/man4/filemon.4 Sat Mar 12 19:07:08 2016 (r296751) +++ stable/10/share/man/man4/filemon.4 Sat Mar 12 19:07:21 2016 (r296752) @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 28, 2016 +.Dd March 9, 2016 .Dt FILEMON 4 .Os .Sh NAME @@ -125,6 +125,19 @@ function returns the value 0 if successf otherwise the value \-1 is returned and the global variable .Va errno is set to indicate the error. +.Sh ERRORS +The +.Fn ioctl +system call +with +.Dv FILEMON_SET_FD +will fail if: +.Bl -tag -width Er +.It Bq Er EEXIST +The +.Nm +handle is already associated with a file descriptor. +.El .Sh FILES .Bl -tag -width ".Pa /dev/filemon" .It Pa /dev/filemon @@ -193,3 +206,6 @@ Only children of the set process are log Processes can escape being traced by double forking. This is not seen as a problem as the intended use is build monitoring, which does not make sense to have daemons for. +.Pp +Unloading the module may panic the system, thus requires using +.Ic kldunload -f . Modified: stable/10/sys/dev/filemon/filemon.c ============================================================================== --- stable/10/sys/dev/filemon/filemon.c Sat Mar 12 19:07:08 2016 (r296751) +++ stable/10/sys/dev/filemon/filemon.c Sat Mar 12 19:07:21 2016 (r296752) @@ -71,8 +71,6 @@ extern struct sysentvec elf64_freebsd_sy static d_close_t filemon_close; static d_ioctl_t filemon_ioctl; static d_open_t filemon_open; -static int filemon_unload(void); -static void filemon_load(void *); static struct cdevsw filemon_cdevsw = { .d_version = D_VERSION, @@ -130,7 +128,7 @@ filemon_dtr(void *data) /* Follow same locking order as filemon_pid_check. */ filemon_lock_write(); - filemon_filemon_lock(filemon); + sx_xlock(&filemon->lock); /* Remove from the in-use list. */ TAILQ_REMOVE(&filemons_inuse, filemon, link); @@ -143,7 +141,7 @@ filemon_dtr(void *data) TAILQ_INSERT_TAIL(&filemons_free, filemon, link); /* Give up write access. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); filemon_unlock_write(); if (fp != NULL) @@ -165,13 +163,15 @@ filemon_ioctl(struct cdev *dev, u_long c if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0) return (error); - filemon_filemon_lock(filemon); + sx_xlock(&filemon->lock); switch (cmd) { /* Set the output file descriptor. */ case FILEMON_SET_FD: - if (filemon->fp != NULL) - fdrop(filemon->fp, td); + if (filemon->fp != NULL) { + error = EEXIST; + break; + } error = fget_write(td, *(int *)data, #if __FreeBSD_version >= 900041 @@ -198,7 +198,7 @@ filemon_ioctl(struct cdev *dev, u_long c break; } - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); return (error); } @@ -308,6 +308,14 @@ filemon_modevent(module_t mod __unused, error = filemon_unload(); break; + case MOD_QUIESCE: + /* + * The wrapper implementation is unsafe for reliable unload. + * Require forcing an unload. + */ + error = EBUSY; + break; + case MOD_SHUTDOWN: break; Modified: stable/10/sys/dev/filemon/filemon_lock.c ============================================================================== --- stable/10/sys/dev/filemon/filemon_lock.c Sat Mar 12 19:07:08 2016 (r296751) +++ stable/10/sys/dev/filemon/filemon_lock.c Sat Mar 12 19:07:21 2016 (r296752) @@ -29,20 +29,6 @@ __FBSDID("$FreeBSD$"); static __inline void -filemon_filemon_lock(struct filemon *filemon) -{ - - sx_xlock(&filemon->lock); -} - -static __inline void -filemon_filemon_unlock(struct filemon *filemon) -{ - - sx_xunlock(&filemon->lock); -} - -static __inline void filemon_lock_read(void) { Modified: stable/10/sys/dev/filemon/filemon_wrapper.c ============================================================================== --- stable/10/sys/dev/filemon/filemon_wrapper.c Sat Mar 12 19:07:08 2016 (r296751) +++ stable/10/sys/dev/filemon/filemon_wrapper.c Sat Mar 12 19:07:21 2016 (r296752) @@ -80,7 +80,8 @@ filemon_output(struct filemon *filemon, auio.uio_td = curthread; auio.uio_offset = (off_t) -1; - bwillwrite(); + if (filemon->fp->f_type == DTYPE_VNODE) + bwillwrite(); fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); } @@ -100,7 +101,7 @@ filemon_pid_check(struct proc *p) TAILQ_FOREACH(filemon, &filemons_inuse, link) { if (p == filemon->p) { sx_sunlock(&proctree_lock); - filemon_filemon_lock(filemon); + sx_xlock(&filemon->lock); filemon_unlock_read(); return (filemon); } @@ -131,8 +132,7 @@ filemon_wrapper_chdir(struct thread *td, filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -160,8 +160,7 @@ filemon_event_process_exec(void *arg __u filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); free(freepath, M_TEMP); } @@ -199,8 +198,7 @@ filemon_wrapper_open(struct thread *td, curproc->p_pid, filemon->fname1); filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -252,8 +250,7 @@ filemon_wrapper_openat(struct thread *td curproc->p_pid, filemon->fname2, filemon->fname1); filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -281,8 +278,7 @@ filemon_wrapper_rename(struct thread *td filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -310,8 +306,7 @@ filemon_wrapper_link(struct thread *td, filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -339,8 +334,7 @@ filemon_wrapper_symlink(struct thread *t filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -369,8 +363,7 @@ filemon_wrapper_linkat(struct thread *td filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -397,8 +390,7 @@ filemon_wrapper_stat(struct thread *td, filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -426,8 +418,7 @@ filemon_wrapper_freebsd32_stat(struct th filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -462,8 +453,7 @@ filemon_event_process_exit(void *arg __u filemon->p = NULL; } - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -486,8 +476,7 @@ filemon_wrapper_unlink(struct thread *td filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } } @@ -508,8 +497,7 @@ filemon_event_process_fork(void *arg __u filemon_output(filemon, filemon->msgbufr, len); - /* Unlock the found filemon structure. */ - filemon_filemon_unlock(filemon); + sx_xunlock(&filemon->lock); } }